2
0
Fork 0
mirror of https://git.sr.ht/~sircmpwn/mkproof synced 2024-06-08 12:26:09 +02:00

Decoding change

This commit is contained in:
khovratovich 2016-03-10 15:50:17 +01:00
parent 0505ac7cb0
commit a06b3e4d52
6 changed files with 27 additions and 15 deletions

View File

@ -178,6 +178,8 @@ typedef struct Argon2_Context {
uint8_t *out; /* output array */
uint32_t outlen; /* digest length */
uint32_t version; /*version number*/
uint8_t *pwd; /* password array */
uint32_t pwdlen; /* password length */
@ -275,7 +277,8 @@ ARGON2_PUBLIC int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
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);
const size_t encodedlen, argon2_type type,
const uint32_t version);
/**
* Verifies a password against an encoded string

View File

@ -46,6 +46,7 @@ int argon2_ctx(argon2_context *context, argon2_type type) {
/* Ensure that all segments have equal length */
memory_blocks = segment_length * (context->lanes * ARGON2_SYNC_POINTS);
instance.version = context->version;
instance.memory = NULL;
instance.passes = context->t_cost;
instance.memory_blocks = memory_blocks;
@ -80,7 +81,8 @@ 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) {
const size_t encodedlen, argon2_type type,
const uint32_t version){
argon2_context context;
int result;
@ -122,6 +124,7 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
context.allocate_cbk = NULL;
context.free_cbk = NULL;
context.flags = ARGON2_DEFAULT_FLAGS;
context.version = version;
result = argon2_ctx(&context, type);
@ -158,7 +161,7 @@ int argon2i_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
char *encoded, const size_t encodedlen) {
return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
NULL, hashlen, encoded, encodedlen, Argon2_i);
NULL, hashlen, encoded, encodedlen, Argon2_i, ARGON2_VERSION_NUMBER);
}
int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
@ -167,7 +170,7 @@ int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
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);
hash, hashlen, NULL, 0, Argon2_i, ARGON2_VERSION_NUMBER);
}
int argon2d_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
@ -177,7 +180,7 @@ int argon2d_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
char *encoded, const size_t encodedlen) {
return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
NULL, hashlen, encoded, encodedlen, Argon2_d);
NULL, hashlen, encoded, encodedlen, Argon2_d, ARGON2_VERSION_NUMBER);
}
int argon2d_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
@ -186,7 +189,7 @@ int argon2d_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
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);
hash, hashlen, NULL, 0, Argon2_d, ARGON2_VERSION_NUMBER);
}
static int argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len) {
@ -242,7 +245,7 @@ int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
}
ret = argon2_hash(ctx.t_cost, ctx.m_cost, ctx.threads, pwd, pwdlen,
ctx.salt, ctx.saltlen, out, ctx.outlen, NULL, 0, type);
ctx.salt, ctx.saltlen, out, ctx.outlen, NULL, 0, type, ctx.version);
free(ctx.ad);
free(ctx.salt);

View File

@ -508,7 +508,7 @@ void initial_hash(uint8_t *blockhash, argon2_context *context,
store32(&value, context->t_cost);
blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
store32(&value, ARGON2_VERSION_NUMBER);
store32(&value, context->version);
blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
store32(&value, (uint32_t)type);

View File

@ -31,6 +31,7 @@
enum argon2_core_constants {
/* Version of the algorithm */
ARGON2_OLD_VERSION_NUMBER = 0x10,
ARGON2_VERSION_NUMBER = 0x13,
/* Memory block size in bytes */
@ -77,6 +78,7 @@ void xor_block(block *dst, const block *src);
*/
typedef struct Argon2_instance_t {
block *memory; /* Memory pointer */
uint32_t version;
uint32_t passes; /* Number of passes */
uint32_t memory_blocks; /* Number of blocks in memory */
uint32_t segment_length;

View File

@ -229,7 +229,7 @@ static const char *decode_decimal(const char *str, unsigned long *v) {
*
* The code below applies the following format:
*
* $argon2<T>$m=<num>,t=<num>,p=<num>[,keyid=<bin>][,data=<bin>][$<bin>[$<bin>]]
* $argon2<T>[$v=<num>]$m=<num>,t=<num>,p=<num>[,keyid=<bin>][,data=<bin>][$<bin>[$<bin>]]
*
* where <T> is either 'd' or 'i', <num> is a decimal integer (positive, fits in
* an 'unsigned long'), and <bin> is Base64-encoded data (no '=' padding
@ -303,6 +303,8 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
CC("$argon2d");
else
return ARGON2_INCORRECT_TYPE;
ctx->version = ARGON2_OLD_VERSION_NUMBER;
CC_opt("$v=", DECIMAL(ctx->version)); /*Reading the version number if the default is suppressed */
CC("$m=");
DECIMAL(ctx->m_cost);
CC(",t=");
@ -368,15 +370,17 @@ int encode_string(char *dst, size_t dst_len, argon2_context *ctx,
} while ((void)0, 0)
if (type == Argon2_i)
SS("$argon2i$m=");
SS("$argon2i$v=");
else if (type == Argon2_d)
SS("$argon2d$m=");
SS("$argon2d$v=");
else
return ARGON2_ENCODING_FAIL;
if (validate_inputs(ctx) != ARGON2_OK) {
return validate_inputs(ctx);
}
SX(ctx->version);
SS("$m=");
SX(ctx->m_cost);
SS(",t=");
SX(ctx->t_cost);

View File

@ -68,8 +68,8 @@ static uint32_t numlen(uint32_t num) {
}
static uint32_t enclen(uint32_t outlen, uint32_t saltlen, uint32_t t_cost,
uint32_t m_cost, uint32_t lanes) {
return strlen("$argon2x$m=,t=,p=$$") + numlen(t_cost) + numlen(m_cost)
uint32_t m_cost, uint32_t lanes, uint32_t version) {
return strlen("$argon2x$v=$m=,t=,p=$$") + numlen(t_cost) + numlen(m_cost) + numlen(version)
+ numlen(lanes) + b64len(saltlen) + b64len(outlen);
}
@ -116,7 +116,7 @@ static void run(uint32_t outlen, char *pwd, char *salt, uint32_t t_cost,
fatal("could not allocate memory for output");
}
encodedlen = enclen(outlen, saltlen, t_cost, m_cost, lanes);
encodedlen = enclen(outlen, saltlen, t_cost, m_cost, lanes, ARGON2_VERSION_NUMBER);
char* encoded = malloc(encodedlen + 1);
if (!encoded) {
secure_wipe_memory(pwd, strlen(pwd));
@ -124,7 +124,7 @@ static void run(uint32_t outlen, char *pwd, char *salt, uint32_t t_cost,
}
result = argon2_hash(t_cost, m_cost, threads, pwd, pwdlen, salt, saltlen,
out, outlen, encoded, encodedlen, type);
out, outlen, encoded, encodedlen, type, ARGON2_VERSION_NUMBER);
if (result != ARGON2_OK)
fatal(argon2_error_message(result));