diff --git a/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c b/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c index 1809a9ca..4ab6eb8c 100644 --- a/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +++ b/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c @@ -229,7 +229,7 @@ static const char *decode_decimal(const char *str, unsigned long *v) { * * The code below applies the following format: * - * $argon2$m=,t=,p=[,keyid=][,data=][$[$]] + * $argon2$v=,m=,t=,p=[,keyid=][,data=][$[$]] * * where is either 'd' or 'i', is a decimal integer (positive, fits in an 'unsigned long') * and 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); diff --git a/test/default/pwhash_argon2i.c b/test/default/pwhash_argon2i.c index e64abbee..0c1e9838 100644 --- a/test/default/pwhash_argon2i.c +++ b/test/default/pwhash_argon2i.c @@ -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;