From d7f5877df56998b6de83f0e3d11e3483da498ae6 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 1 Apr 2016 20:48:34 +0200 Subject: [PATCH] Add crypto_pwhash_argon2i_ALG_ARGON2I13 --- src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c | 11 ++++++++++- src/libsodium/crypto_pwhash/crypto_pwhash.c | 2 +- src/libsodium/include/sodium/crypto_pwhash.h | 2 +- src/libsodium/include/sodium/crypto_pwhash_argon2i.h | 6 +++++- test/default/pwhash.c | 1 + 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c b/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c index b4d21770..6665d2fb 100644 --- a/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +++ b/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c @@ -13,6 +13,12 @@ #define STR_HASHBYTES 32U +int +crypto_pwhash_argon2i_alg_argon2i13(void) +{ + return crypto_pwhash_argon2i_ALG_ARGON2I13; +} + size_t crypto_pwhash_argon2i_saltbytes(void) { @@ -74,8 +80,11 @@ crypto_pwhash_argon2i(unsigned char * const out, unsigned long long passwdlen, const unsigned char * const salt, unsigned long long opslimit, - size_t memlimit) + size_t memlimit, int alg) { + if (alg != crypto_pwhash_argon2i_ALG_ARGON2I13) { + return -1; + } memlimit /= 1024U; if (outlen > ARGON2_MAX_OUTLEN || passwdlen > ARGON2_MAX_PWD_LENGTH || opslimit > ARGON2_MAX_TIME || memlimit > ARGON2_MAX_MEMORY) { diff --git a/src/libsodium/crypto_pwhash/crypto_pwhash.c b/src/libsodium/crypto_pwhash/crypto_pwhash.c index c2e7b22c..d6227f87 100644 --- a/src/libsodium/crypto_pwhash/crypto_pwhash.c +++ b/src/libsodium/crypto_pwhash/crypto_pwhash.c @@ -80,7 +80,7 @@ crypto_pwhash(unsigned char * const out, unsigned long long outlen, return -1; } return crypto_pwhash_argon2i(out, outlen, passwd, passwdlen, salt, - opslimit, memlimit); + opslimit, memlimit, alg); } int diff --git a/src/libsodium/include/sodium/crypto_pwhash.h b/src/libsodium/include/sodium/crypto_pwhash.h index a5048d8c..30d38e87 100644 --- a/src/libsodium/include/sodium/crypto_pwhash.h +++ b/src/libsodium/include/sodium/crypto_pwhash.h @@ -13,7 +13,7 @@ extern "C" { #endif -#define crypto_pwhash_ALG_ARGON2I13 1 +#define crypto_pwhash_ALG_ARGON2I13 crypto_pwhash_argon2i_ALG_ARGON2I13 SODIUM_EXPORT int crypto_pwhash_alg_argon2i13(void); diff --git a/src/libsodium/include/sodium/crypto_pwhash_argon2i.h b/src/libsodium/include/sodium/crypto_pwhash_argon2i.h index 6a6f155c..e0ca287c 100644 --- a/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +++ b/src/libsodium/include/sodium/crypto_pwhash_argon2i.h @@ -12,6 +12,10 @@ extern "C" { #endif +#define crypto_pwhash_argon2i_ALG_ARGON2I13 1 +SODIUM_EXPORT +int crypto_pwhash_argon2i_alg_argon2i13(void); + #define crypto_pwhash_argon2i_SALTBYTES 16U SODIUM_EXPORT size_t crypto_pwhash_argon2i_saltbytes(void); @@ -55,7 +59,7 @@ int crypto_pwhash_argon2i(unsigned char * const out, unsigned long long passwdlen, const unsigned char * const salt, unsigned long long opslimit, - size_t memlimit) + size_t memlimit, int alg) __attribute__ ((warn_unused_result)); SODIUM_EXPORT diff --git a/test/default/pwhash.c b/test/default/pwhash.c index 708c09db..4b16a33f 100644 --- a/test/default/pwhash.c +++ b/test/default/pwhash.c @@ -353,6 +353,7 @@ int main(void) crypto_pwhash_memlimit_moderate()); assert(crypto_pwhash_argon2i_memlimit_sensitive() == crypto_pwhash_memlimit_sensitive()); + assert(crypto_pwhash_alg_argon2i13() == crypto_pwhash_argon2i_alg_argon2i13()); assert(crypto_pwhash_alg_argon2i13() == crypto_pwhash_ALG_ARGON2I13); assert(crypto_pwhash_alg_argon2i13() == crypto_pwhash_alg_default());