mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-23 20:15:19 -07:00
Add crypto_pwhash_str_alg()
This commit is contained in:
parent
9d03fbb38c
commit
a894ec93f2
@ -2,6 +2,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "crypto_pwhash.h"
|
||||
|
||||
int
|
||||
@ -150,6 +151,23 @@ crypto_pwhash_str(char out[crypto_pwhash_STRBYTES],
|
||||
opslimit, memlimit);
|
||||
}
|
||||
|
||||
int
|
||||
crypto_pwhash_str_alg(char out[crypto_pwhash_STRBYTES],
|
||||
const char * const passwd, unsigned long long passwdlen,
|
||||
unsigned long long opslimit, size_t memlimit, int alg)
|
||||
{
|
||||
switch (alg) {
|
||||
case crypto_pwhash_ALG_ARGON2I13:
|
||||
return crypto_pwhash_argon2i_str(out, passwd, passwdlen,
|
||||
opslimit, memlimit);
|
||||
case crypto_pwhash_ALG_ARGON2ID13:
|
||||
return crypto_pwhash_argon2id_str(out, passwd, passwdlen,
|
||||
opslimit, memlimit);
|
||||
default:
|
||||
sodium_misuse();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES],
|
||||
const char * const passwd,
|
||||
|
@ -107,6 +107,12 @@ int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES],
|
||||
unsigned long long opslimit, size_t memlimit)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_str_alg(char out[crypto_pwhash_STRBYTES],
|
||||
const char * const passwd, unsigned long long passwdlen,
|
||||
unsigned long long opslimit, size_t memlimit, int alg)
|
||||
__attribute__ ((warn_unused_result));
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES],
|
||||
const char * const passwd,
|
||||
|
@ -349,6 +349,14 @@ main(void)
|
||||
"password", strlen("password")) != -1 || errno != EINVAL) {
|
||||
printf("pwhash_str_verify(invalid(11)) failure\n");
|
||||
}
|
||||
|
||||
assert(crypto_pwhash_str_alg(str_out, "test", 4, OPSLIMIT, MEMLIMIT,
|
||||
crypto_pwhash_ALG_ARGON2I13) == 0);
|
||||
assert(crypto_pwhash_argon2i_str_verify(str_out, "test", 4) == 0);
|
||||
assert(crypto_pwhash_str_alg(str_out, "test", 4, OPSLIMIT, MEMLIMIT,
|
||||
crypto_pwhash_ALG_ARGON2ID13) == 0);
|
||||
assert(crypto_pwhash_argon2id_str_verify(str_out, "test", 4) == 0);
|
||||
|
||||
assert(crypto_pwhash_bytes_min() > 0U);
|
||||
assert(crypto_pwhash_bytes_max() > crypto_pwhash_bytes_min());
|
||||
assert(crypto_pwhash_passwd_max() > crypto_pwhash_passwd_min());
|
||||
|
Loading…
Reference in New Issue
Block a user