1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 18:15:18 -07:00

Check what the implications of versioned Argon2 strings will be

This commit is contained in:
Frank Denis 2016-03-10 12:25:21 +01:00
parent 805fd3589d
commit 7597b7cc13
2 changed files with 15 additions and 7 deletions

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 characters, no newline
@ -293,6 +293,7 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
size_t maxadlen = ctx->adlen;
size_t maxsaltlen = ctx->saltlen;
size_t maxoutlen = ctx->outlen;
unsigned long version = 0;
ctx->adlen = 0;
ctx->saltlen = 0;
@ -303,7 +304,12 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) {
} else {
return 0;
}
CC("$m=");
CC("$v=");
DECIMAL(version);
if (version != ARGON2_VERSION_NUMBER) {
return 1;
}
CC(",m=");
DECIMAL(ctx->m_cost);
CC(",t=");
DECIMAL(ctx->t_cost);
@ -391,13 +397,15 @@ 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 {
return 0;
}
if (validate_inputs(ctx) != ARGON2_OK) {
return 0;
}
SX(ARGON2_VERSION_NUMBER);
SS(",m=");
SX(ctx->m_cost);
SS(",t=");
SX(ctx->t_cost);

View File

@ -160,13 +160,13 @@ static void tv3(void)
const char *out;
} tests[] = {
{ "",
"$argon2i$m=4096,t=1,p=1$X1NhbHQAAAAAAAAAAAAAAA$bWh++MKN1OiFHKgIWTLvIi1iHicmHH7+Fv3K88ifFfI" },
"$argon2i$v=19,m=4096,t=1,p=1$X1NhbHQAAAAAAAAAAAAAAA$bWh++MKN1OiFHKgIWTLvIi1iHicmHH7+Fv3K88ifFfI" },
{ "",
"$argon2i$m=2048,t=4,p=1$SWkxaUhpY21ISDcrRnYzSw$Mbg/Eck1kpZir5T9io7C64cpffdTBaORgyriLQFgQj8" },
"$argon2i$v=19,m=2048,t=4,p=1$SWkxaUhpY21ISDcrRnYzSw$Mbg/Eck1kpZir5T9io7C64cpffdTBaORgyriLQFgQj8" },
{ "^T5H$JYt39n%K*j:W]!1s?vg!:jGi]Ax?..l7[p0v:1jHTpla9;]bUN;?bWyCbtqg ",
"$argon2i$m=4096,t=3,p=2$X1NhbHQAAAAAAAAAAAAAAA$z/QMiU4lQxGsYNc/+K/bizwsA1P11UG2dj/7+aILJ4I" },
"$argon2i$v=19,m=4096,t=3,p=2$X1NhbHQAAAAAAAAAAAAAAA$z/QMiU4lQxGsYNc/+K/bizwsA1P11UG2dj/7+aILJ4I" },
{ "K3S=KyH#)36_?]LxeR8QNKw6X=gFbxai$C%29V*",
"$argon2i$m=4096,t=3,p=1$X1NhbHQAAAAAAAAAAAAAAA$fu2Wsecyt+yPnBvSvYN16oP5ozRmkp0ixJ1YL19V3Uo" }
"$argon2i$v=19,m=4096,t=3,p=1$X1NhbHQAAAAAAAAAAAAAAA$fu2Wsecyt+yPnBvSvYN16oP5ozRmkp0ixJ1YL19V3Uo" }
};
char *out;
char *passwd;