int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen, argon2_type type) { argon2_context ctx; uint8_t *out; int ret; int decode_result; /* max values, to be updated in decode_string */ uint32_t encoded_len = strlen(encoded); ctx.adlen = encoded_len; ctx.saltlen = encoded_len; ctx.outlen = encoded_len; ctx.allocate_cbk = NULL; ctx.free_cbk = NULL; ctx.secret = NULL; ctx.secretlen = 0; ctx.ad = malloc(ctx.adlen); ctx.salt = malloc(ctx.saltlen); ctx.out = malloc(ctx.outlen); if (!ctx.out || !ctx.salt || !ctx.ad) { free(ctx.ad); free(ctx.salt); free(ctx.out); return ARGON2_MEMORY_ALLOCATION_ERROR; } out = malloc(ctx.outlen); if (!out) { free(ctx.ad); free(ctx.salt); free(ctx.out); return ARGON2_MEMORY_ALLOCATION_ERROR; } decode_result = decode_string(&ctx, encoded, type); if (decode_result != ARGON2_OK) { free(ctx.ad); free(ctx.salt); free(ctx.out); free(out); return decode_result; } ret = argon2_hash(ctx.t_cost, ctx.m_cost, ctx.threads, pwd, pwdlen, ctx.salt, ctx.saltlen, out, ctx.outlen, NULL, 0, type); free(ctx.ad); free(ctx.salt); if (ret == ARGON2_OK && argon2_compare(out, ctx.out, ctx.outlen)) { ret = ARGON2_VERIFY_MISMATCH; } free(out); free(ctx.out); return ret; }
int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen, argon2_type type) { argon2_context ctx; uint8_t *out; int ret; /* max values, to be updated in decode_string */ ctx.adlen = 512; ctx.saltlen = 512; ctx.outlen = 512; ctx.ad = malloc(ctx.adlen); ctx.salt = malloc(ctx.saltlen); ctx.out = malloc(ctx.outlen); if (!ctx.out || !ctx.salt || !ctx.ad) { free(ctx.ad); free(ctx.salt); free(ctx.out); return ARGON2_MEMORY_ALLOCATION_ERROR; } out = malloc(ctx.outlen); if (!out) { free(ctx.ad); free(ctx.salt); free(ctx.out); return ARGON2_MEMORY_ALLOCATION_ERROR; } if(decode_string(&ctx, encoded, type) != 1) { free(ctx.ad); free(ctx.salt); free(ctx.out); free(out); return ARGON2_DECODING_FAIL; } ret = argon2_hash(ctx.t_cost, ctx.m_cost, ctx.threads, pwd, pwdlen, ctx.salt, ctx.saltlen, out, ctx.outlen, NULL, 0, type); free(ctx.ad); free(ctx.salt); if (ret != ARGON2_OK || argon2_compare(out, ctx.out, ctx.outlen)) { free(out); free(ctx.out); return ARGON2_DECODING_FAIL; } free(out); free(ctx.out); return ARGON2_OK; }