int verify_i(argon2_context *context, const char *hash) { int result; if (0 == context->outlen || NULL == hash) { return ARGON2_OUT_PTR_MISMATCH; } result = argon2_core(context, Argon2_i); if (ARGON2_OK != result) { return result; } return 0 == memcmp(hash, context->out, context->outlen); }
int hash_argon2i(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, unsigned int t_cost, unsigned int m_cost) { argon2_context context; /* Detect and reject overflowing sizes */ /* TODO: This should probably be fixed in the function signature */ if (inlen > UINT32_MAX) { return ARGON2_PWD_TOO_LONG; } if (outlen > UINT32_MAX) { return ARGON2_OUTPUT_TOO_LONG; } if (saltlen > UINT32_MAX) { return ARGON2_SALT_TOO_LONG; } context.out = (uint8_t *)out; context.outlen = (uint32_t)outlen; context.pwd = (uint8_t *)in; context.pwdlen = (uint32_t)inlen; context.salt = (uint8_t *)salt; context.saltlen = (uint32_t)saltlen; context.secret = NULL; context.secretlen = 0; context.ad = NULL; context.adlen = 0; context.t_cost = t_cost; context.m_cost = m_cost; context.lanes = 1; context.threads = 1; context.allocate_cbk = NULL; context.free_cbk = NULL; context.flags = ARGON2_DEFAULT_FLAGS; return argon2_core(&context, Argon2_i); }
int argon2i(argon2_context *context) { return argon2_core(context, Argon2_i); }
int argon2d(argon2_context *context) { return argon2_core(context, Argon2_d); }
int argon2_hash(const uint32_t t_cost, const uint32_t m_cost, const uint32_t parallelism, const void *pwd, const size_t pwdlen, const void *salt, const size_t saltlen, void *hash, const size_t hashlen, char *encoded, const size_t encodedlen, argon2_type type) { argon2_context context; int result; uint8_t *out; /* Detect and reject overflowing sizes */ /* TODO: This should probably be fixed in the function signature */ if (pwdlen > ARGON2_MAX_PWD_LENGTH) { return ARGON2_PWD_TOO_LONG; } if (hashlen > ARGON2_MAX_OUTLEN) { return ARGON2_OUTPUT_TOO_LONG; } if (saltlen > ARGON2_MAX_SALT_LENGTH) { return ARGON2_SALT_TOO_LONG; } out = malloc(hashlen); if (!out) { return ARGON2_MEMORY_ALLOCATION_ERROR; } context.out = (uint8_t *)out; context.outlen = (uint32_t)hashlen; context.pwd = CONST_CAST(uint8_t *)pwd; context.pwdlen = (uint32_t)pwdlen; context.salt = CONST_CAST(uint8_t *)salt; context.saltlen = (uint32_t)saltlen; context.secret = NULL; context.secretlen = 0; context.ad = NULL; context.adlen = 0; context.t_cost = t_cost; context.m_cost = m_cost; context.lanes = parallelism; context.threads = parallelism; context.allocate_cbk = NULL; context.free_cbk = NULL; context.flags = ARGON2_DEFAULT_FLAGS; result = argon2_core(&context, type); if (result != ARGON2_OK) { secure_wipe_memory(out, hashlen); free(out); return result; } /* if raw hash requested, write it */ if (hash) { memcpy(hash, out, hashlen); } /* if encoding requested, write it */ if (encoded && encodedlen) { if (!encode_string(encoded, encodedlen, &context, type)) { secure_wipe_memory(out, hashlen); /* wipe buffers if error */ secure_wipe_memory(encoded, encodedlen); free(out); return ARGON2_ENCODING_FAIL; } } secure_wipe_memory(out, hashlen); free(out); return ARGON2_OK; }