Require an algorithm identifier in crypto_pwhash()
This commit is contained in:
parent
5d8c878ffb
commit
384e08b7f4
@ -1,6 +1,20 @@
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "crypto_pwhash.h"
|
||||
|
||||
int
|
||||
crypto_pwhash_alg_argon2i13(void)
|
||||
{
|
||||
return crypto_pwhash_ALG_ARGON2I13;
|
||||
}
|
||||
|
||||
int
|
||||
crypto_pwhash_alg_default(void)
|
||||
{
|
||||
return crypto_pwhash_ALG_ARGON2I13;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_saltbytes(void)
|
||||
{
|
||||
@ -59,10 +73,12 @@ int
|
||||
crypto_pwhash(unsigned char * const out, unsigned long long outlen,
|
||||
const char * const passwd, unsigned long long passwdlen,
|
||||
const unsigned char * const salt,
|
||||
unsigned long long opslimit, size_t memlimit,
|
||||
const struct crypto_pwhash_options *options)
|
||||
unsigned long long opslimit, size_t memlimit, int alg)
|
||||
{
|
||||
(void) options;
|
||||
if (alg != crypto_pwhash_ALG_ARGON2I13) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return crypto_pwhash_argon2i(out, outlen, passwd, passwdlen, salt,
|
||||
opslimit, memlimit);
|
||||
}
|
||||
|
@ -13,6 +13,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_pwhash_ALG_ARGON2I13 1
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_alg_argon2i13(void);
|
||||
|
||||
#define crypto_pwhash_ALG_DEFAULT crypto_pwhash_ALG_ARGON2I13
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_alg_default(void);
|
||||
|
||||
#define crypto_pwhash_SALTBYTES crypto_pwhash_argon2i_SALTBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_saltbytes(void);
|
||||
@ -49,14 +57,11 @@ size_t crypto_pwhash_opslimit_sensitive(void);
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_memlimit_sensitive(void);
|
||||
|
||||
typedef struct crypto_pwhash_options crypto_pwhash_options;
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash(unsigned char * const out, unsigned long long outlen,
|
||||
const char * const passwd, unsigned long long passwdlen,
|
||||
const unsigned char * const salt,
|
||||
unsigned long long opslimit, size_t memlimit,
|
||||
const crypto_pwhash_options *options)
|
||||
unsigned long long opslimit, size_t memlimit, int alg)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
|
@ -92,7 +92,7 @@ static void tv(void)
|
||||
if (crypto_pwhash(out, (unsigned long long) tests[i].outlen,
|
||||
passwd, tests[i].passwdlen,
|
||||
(const unsigned char *) salt, tests[i].opslimit,
|
||||
tests[i].memlimit, NULL) != 0) {
|
||||
tests[i].memlimit, crypto_pwhash_alg_default()) != 0) {
|
||||
printf("[tv] pwhash failure (maybe intentional): [%u]\n", (unsigned int) i);
|
||||
continue;
|
||||
}
|
||||
@ -142,7 +142,7 @@ static void tv2(void)
|
||||
if (crypto_pwhash(out, (unsigned long long) tests[i].outlen,
|
||||
passwd, tests[i].passwdlen,
|
||||
(const unsigned char *) salt, tests[i].opslimit,
|
||||
tests[i].memlimit, NULL) != 0) {
|
||||
tests[i].memlimit, crypto_pwhash_alg_default()) != 0) {
|
||||
printf("[tv2] pwhash failure: [%u]\n", (unsigned int) i);
|
||||
continue;
|
||||
}
|
||||
@ -151,23 +151,27 @@ static void tv2(void)
|
||||
} while (++i < (sizeof tests) / (sizeof tests[0]));
|
||||
|
||||
if (crypto_pwhash(out, sizeof out, "password", strlen("password"),
|
||||
salt, 3, 1, NULL) != -1) {
|
||||
salt, 3, 1ULL << 12, 0) != -1) {
|
||||
printf("[tv2] pwhash should have failed (0)\n");
|
||||
}
|
||||
if (crypto_pwhash(out, sizeof out, "password", strlen("password"),
|
||||
salt, 3, 1, crypto_pwhash_alg_default()) != -1) {
|
||||
printf("[tv2] pwhash should have failed (1)\n");
|
||||
}
|
||||
if (crypto_pwhash(out, sizeof out, "password", strlen("password"),
|
||||
salt, 3, 1ULL << 12, NULL) != -1) {
|
||||
salt, 3, 1ULL << 12, crypto_pwhash_alg_default()) != -1) {
|
||||
printf("[tv2] pwhash should have failed (2)\n");
|
||||
}
|
||||
if (crypto_pwhash(out, sizeof out, "password", strlen("password"),
|
||||
salt, 2, 1ULL << 12, NULL) != -1) {
|
||||
salt, 2, 1ULL << 12, crypto_pwhash_alg_default()) != -1) {
|
||||
printf("[tv2] pwhash should have failed (3)\n");
|
||||
}
|
||||
if (crypto_pwhash(out, 0x100000000ULL, "password", strlen("password"),
|
||||
salt, 3, 1ULL << 12, NULL) != -1) {
|
||||
salt, 3, 1ULL << 12, crypto_pwhash_alg_default()) != -1) {
|
||||
printf("[tv2] pwhash with a long output length should have failed\n");
|
||||
}
|
||||
if (crypto_pwhash(out, sizeof out, "password", 0x100000000ULL,
|
||||
salt, 3, 1ULL << 12, NULL) != -1) {
|
||||
salt, 3, 1ULL << 12, crypto_pwhash_alg_default()) != -1) {
|
||||
printf("[tv2] pwhash with a long password length should have failed\n");
|
||||
}
|
||||
}
|
||||
@ -349,6 +353,8 @@ int main(void)
|
||||
crypto_pwhash_memlimit_moderate());
|
||||
assert(crypto_pwhash_argon2i_memlimit_sensitive() ==
|
||||
crypto_pwhash_memlimit_sensitive());
|
||||
assert(crypto_pwhash_alg_argon2i13() == crypto_pwhash_ALG_ARGON2I13);
|
||||
assert(crypto_pwhash_alg_argon2i13() == crypto_pwhash_alg_default());
|
||||
|
||||
sodium_free(salt);
|
||||
sodium_free(str_out);
|
||||
|
Loading…
Reference in New Issue
Block a user