|
@@ -23,7 +23,7 @@
|
|
|
#include "encoding.h"
|
|
#include "encoding.h"
|
|
|
#include "core.h"
|
|
#include "core.h"
|
|
|
|
|
|
|
|
-const char *argon2_type2string(argon2_type type, int uppercase) {
|
|
|
|
|
|
|
+const char *kp_argon2_type2string(argon2_type_t type, int uppercase) {
|
|
|
switch (type) {
|
|
switch (type) {
|
|
|
case Argon2_d:
|
|
case Argon2_d:
|
|
|
return uppercase ? "Argon2d" : "argon2d";
|
|
return uppercase ? "Argon2d" : "argon2d";
|
|
@@ -36,7 +36,7 @@ const char *argon2_type2string(argon2_type type, int uppercase) {
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2_ctx(argon2_context *context, argon2_type type) {
|
|
|
|
|
|
|
+int kp_argon2_ctx(argon2_context_t *context, argon2_type_t type) {
|
|
|
/* 1. Validate all inputs */
|
|
/* 1. Validate all inputs */
|
|
|
int result = validate_inputs(context);
|
|
int result = validate_inputs(context);
|
|
|
uint32_t memory_blocks, segment_length;
|
|
uint32_t memory_blocks, segment_length;
|
|
@@ -97,14 +97,14 @@ int argon2_ctx(argon2_context *context, argon2_type type) {
|
|
|
return ARGON2_OK;
|
|
return ARGON2_OK;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
|
|
|
|
|
+int kp_argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
|
const uint32_t parallelism, const void *pwd,
|
|
const uint32_t parallelism, const void *pwd,
|
|
|
const size_t pwdlen, const void *salt, const size_t saltlen,
|
|
const size_t pwdlen, const void *salt, const size_t saltlen,
|
|
|
void *hash, const size_t hashlen, char *encoded,
|
|
void *hash, const size_t hashlen, char *encoded,
|
|
|
- const size_t encodedlen, argon2_type type,
|
|
|
|
|
|
|
+ const size_t encodedlen, argon2_type_t type,
|
|
|
const uint32_t version){
|
|
const uint32_t version){
|
|
|
|
|
|
|
|
- argon2_context context;
|
|
|
|
|
|
|
+ argon2_context_t context;
|
|
|
int result;
|
|
int result;
|
|
|
uint8_t *out;
|
|
uint8_t *out;
|
|
|
|
|
|
|
@@ -148,7 +148,7 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
|
context.flags = ARGON2_DEFAULT_FLAGS;
|
|
context.flags = ARGON2_DEFAULT_FLAGS;
|
|
|
context.version = version;
|
|
context.version = version;
|
|
|
|
|
|
|
|
- result = argon2_ctx(&context, type);
|
|
|
|
|
|
|
+ result = kp_argon2_ctx(&context, type);
|
|
|
|
|
|
|
|
if (result != ARGON2_OK) {
|
|
if (result != ARGON2_OK) {
|
|
|
clear_internal_memory(out, hashlen);
|
|
clear_internal_memory(out, hashlen);
|
|
@@ -176,67 +176,67 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
|
|
return ARGON2_OK;
|
|
return ARGON2_OK;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2i_hash_encoded(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, const size_t hashlen,
|
|
|
|
|
- char *encoded, const size_t encodedlen) {
|
|
|
|
|
|
|
+int kp_argon2i_hash_encoded(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, const size_t hashlen,
|
|
|
|
|
+ char *encoded, const size_t encodedlen) {
|
|
|
|
|
|
|
|
- return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
- NULL, hashlen, encoded, encodedlen, Argon2_i,
|
|
|
|
|
- ARGON2_VERSION_NUMBER);
|
|
|
|
|
|
|
+ return kp_argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
+ NULL, hashlen, encoded, encodedlen, Argon2_i,
|
|
|
|
|
+ ARGON2_VERSION_NUMBER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2i_hash_raw(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) {
|
|
|
|
|
|
|
+int kp_argon2i_hash_raw(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) {
|
|
|
|
|
|
|
|
- return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
- hash, hashlen, NULL, 0, Argon2_i, ARGON2_VERSION_NUMBER);
|
|
|
|
|
|
|
+ return kp_argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
+ hash, hashlen, NULL, 0, Argon2_i, ARGON2_VERSION_NUMBER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2d_hash_encoded(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, const size_t hashlen,
|
|
|
|
|
- char *encoded, const size_t encodedlen) {
|
|
|
|
|
|
|
+int kp_argon2d_hash_encoded(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, const size_t hashlen,
|
|
|
|
|
+ char *encoded, const size_t encodedlen) {
|
|
|
|
|
|
|
|
- return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
- NULL, hashlen, encoded, encodedlen, Argon2_d,
|
|
|
|
|
- ARGON2_VERSION_NUMBER);
|
|
|
|
|
|
|
+ return kp_argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
+ NULL, hashlen, encoded, encodedlen, Argon2_d,
|
|
|
|
|
+ ARGON2_VERSION_NUMBER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2d_hash_raw(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) {
|
|
|
|
|
|
|
+int kp_argon2d_hash_raw(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) {
|
|
|
|
|
|
|
|
- return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
- hash, hashlen, NULL, 0, Argon2_d, ARGON2_VERSION_NUMBER);
|
|
|
|
|
|
|
+ return kp_argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
+ hash, hashlen, NULL, 0, Argon2_d, ARGON2_VERSION_NUMBER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2id_hash_encoded(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, const size_t hashlen,
|
|
|
|
|
- char *encoded, const size_t encodedlen) {
|
|
|
|
|
|
|
+int kp_argon2id_hash_encoded(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, const size_t hashlen,
|
|
|
|
|
+ char *encoded, const size_t encodedlen) {
|
|
|
|
|
|
|
|
- return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
- NULL, hashlen, encoded, encodedlen, Argon2_id,
|
|
|
|
|
- ARGON2_VERSION_NUMBER);
|
|
|
|
|
|
|
+ return kp_argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
+ NULL, hashlen, encoded, encodedlen, Argon2_id,
|
|
|
|
|
+ ARGON2_VERSION_NUMBER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2id_hash_raw(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) {
|
|
|
|
|
- return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
- hash, hashlen, NULL, 0, Argon2_id,
|
|
|
|
|
- ARGON2_VERSION_NUMBER);
|
|
|
|
|
|
|
+int kp_argon2id_hash_raw(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) {
|
|
|
|
|
+ return kp_argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
|
|
|
|
+ hash, hashlen, NULL, 0, Argon2_id,
|
|
|
|
|
+ ARGON2_VERSION_NUMBER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len) {
|
|
|
|
|
|
|
+static int kp_argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len) {
|
|
|
size_t i;
|
|
size_t i;
|
|
|
uint8_t d = 0U;
|
|
uint8_t d = 0U;
|
|
|
|
|
|
|
@@ -246,10 +246,10 @@ static int argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len) {
|
|
|
return (int)((1 & ((d - 1) >> 8)) - 1);
|
|
return (int)((1 & ((d - 1) >> 8)) - 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
|
|
|
|
|
- argon2_type type) {
|
|
|
|
|
|
|
+int kp_argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
|
|
|
|
|
+ argon2_type_t type) {
|
|
|
|
|
|
|
|
- argon2_context ctx;
|
|
|
|
|
|
|
+ argon2_context_t ctx;
|
|
|
uint8_t *desired_result = NULL;
|
|
uint8_t *desired_result = NULL;
|
|
|
|
|
|
|
|
int ret = ARGON2_OK;
|
|
int ret = ARGON2_OK;
|
|
@@ -299,7 +299,7 @@ int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ret = argon2_verify_ctx(&ctx, (char *)desired_result, type);
|
|
|
|
|
|
|
+ ret = kp_argon2_verify_ctx(&ctx, (char *)desired_result, type);
|
|
|
if (ret != ARGON2_OK) {
|
|
if (ret != ARGON2_OK) {
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -312,57 +312,54 @@ fail:
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2i_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
|
|
|
|
-
|
|
|
|
|
- return argon2_verify(encoded, pwd, pwdlen, Argon2_i);
|
|
|
|
|
|
|
+int kp_argon2i_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
|
|
|
|
+ return kp_argon2_verify(encoded, pwd, pwdlen, Argon2_i);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2d_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
|
|
|
|
-
|
|
|
|
|
- return argon2_verify(encoded, pwd, pwdlen, Argon2_d);
|
|
|
|
|
|
|
+int kp_argon2d_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
|
|
|
|
+ return kp_argon2_verify(encoded, pwd, pwdlen, Argon2_d);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2id_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
|
|
|
|
-
|
|
|
|
|
- return argon2_verify(encoded, pwd, pwdlen, Argon2_id);
|
|
|
|
|
|
|
+int kp_argon2id_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
|
|
|
|
+ return kp_argon2_verify(encoded, pwd, pwdlen, Argon2_id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2d_ctx(argon2_context *context) {
|
|
|
|
|
- return argon2_ctx(context, Argon2_d);
|
|
|
|
|
|
|
+int kp_argon2d_ctx(argon2_context_t *context) {
|
|
|
|
|
+ return kp_argon2_ctx(context, Argon2_d);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2i_ctx(argon2_context *context) {
|
|
|
|
|
- return argon2_ctx(context, Argon2_i);
|
|
|
|
|
|
|
+int kp_argon2i_ctx(argon2_context_t *context) {
|
|
|
|
|
+ return kp_argon2_ctx(context, Argon2_i);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2id_ctx(argon2_context *context) {
|
|
|
|
|
- return argon2_ctx(context, Argon2_id);
|
|
|
|
|
|
|
+int kp_argon2id_ctx(argon2_context_t *context) {
|
|
|
|
|
+ return kp_argon2_ctx(context, Argon2_id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2_verify_ctx(argon2_context *context, const char *hash,
|
|
|
|
|
- argon2_type type) {
|
|
|
|
|
- int ret = argon2_ctx(context, type);
|
|
|
|
|
|
|
+int kp_argon2_verify_ctx(argon2_context_t *context, const char *hash,
|
|
|
|
|
+ argon2_type_t type) {
|
|
|
|
|
+ int ret = kp_argon2_ctx(context, type);
|
|
|
if (ret != ARGON2_OK) {
|
|
if (ret != ARGON2_OK) {
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (argon2_compare((uint8_t *)hash, context->out, context->outlen)) {
|
|
|
|
|
|
|
+ if (kp_argon2_compare((uint8_t *)hash, context->out, context->outlen)) {
|
|
|
return ARGON2_VERIFY_MISMATCH;
|
|
return ARGON2_VERIFY_MISMATCH;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return ARGON2_OK;
|
|
return ARGON2_OK;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2d_verify_ctx(argon2_context *context, const char *hash) {
|
|
|
|
|
- return argon2_verify_ctx(context, hash, Argon2_d);
|
|
|
|
|
|
|
+int kp_argon2d_verify_ctx(argon2_context_t *context, const char *hash) {
|
|
|
|
|
+ return kp_argon2_verify_ctx(context, hash, Argon2_d);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2i_verify_ctx(argon2_context *context, const char *hash) {
|
|
|
|
|
- return argon2_verify_ctx(context, hash, Argon2_i);
|
|
|
|
|
|
|
+int kp_argon2i_verify_ctx(argon2_context_t *context, const char *hash) {
|
|
|
|
|
+ return kp_argon2_verify_ctx(context, hash, Argon2_i);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int argon2id_verify_ctx(argon2_context *context, const char *hash) {
|
|
|
|
|
- return argon2_verify_ctx(context, hash, Argon2_id);
|
|
|
|
|
|
|
+int kp_argon2id_verify_ctx(argon2_context_t *context, const char *hash) {
|
|
|
|
|
+ return kp_argon2_verify_ctx(context, hash, Argon2_id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const char *argon2_error_message(int error_code) {
|
|
const char *argon2_error_message(int error_code) {
|
|
@@ -445,8 +442,8 @@ const char *argon2_error_message(int error_code) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost, uint32_t parallelism,
|
|
size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost, uint32_t parallelism,
|
|
|
- uint32_t saltlen, uint32_t hashlen, argon2_type type) {
|
|
|
|
|
- return strlen("$$v=$m=,t=,p=$$") + strlen(argon2_type2string(type, 0)) +
|
|
|
|
|
|
|
+ uint32_t saltlen, uint32_t hashlen, argon2_type_t type) {
|
|
|
|
|
+ return strlen("$$v=$m=,t=,p=$$") + strlen(kp_argon2_type2string(type, 0)) +
|
|
|
numlen(t_cost) + numlen(m_cost) + numlen(parallelism) +
|
|
numlen(t_cost) + numlen(m_cost) + numlen(parallelism) +
|
|
|
b64len(saltlen) + b64len(hashlen) + numlen(ARGON2_VERSION_NUMBER) + 1;
|
|
b64len(saltlen) + b64len(hashlen) + numlen(ARGON2_VERSION_NUMBER) + 1;
|
|
|
}
|
|
}
|