mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
WIP: crypto_pwhash constants (#464)
* Test exposed constraint constants on crypto_pwhash This includes the following constants for crypto_pwhash, crypto_pwhash_argon2i, and crypto_pwhash_scryptsalsa208sha256: - crypto_pwhash_BYTES_MIN - crypto_pwhash_BYTES_MAX - crypto_pwhash_PASSWD_MIN - crypto_pwhash_PASSWD_MAX - crypto_pwhash_OPSLIMIT_MIN - crypto_pwhash_OPSLIMIT_MAX - crypto_pwhash_MEMLIMIT_MIN - crypto_pwhash_MEMLIMIT_MAX * Expose constraint constants for crypto_pwhash * Expose constant methods for crypto_pwhash
This commit is contained in:
@@ -19,6 +19,30 @@ crypto_pwhash_argon2i_alg_argon2i13(void)
|
||||
return crypto_pwhash_argon2i_ALG_ARGON2I13;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_bytes_min(void)
|
||||
{
|
||||
return crypto_pwhash_argon2i_BYTES_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_bytes_max(void)
|
||||
{
|
||||
return crypto_pwhash_argon2i_BYTES_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_passwd_min(void)
|
||||
{
|
||||
return crypto_pwhash_argon2i_PASSWD_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_passwd_max(void)
|
||||
{
|
||||
return crypto_pwhash_argon2i_PASSWD_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_saltbytes(void)
|
||||
{
|
||||
@@ -37,6 +61,30 @@ crypto_pwhash_argon2i_strprefix(void)
|
||||
return crypto_pwhash_argon2i_STRPREFIX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_opslimit_min(void)
|
||||
{
|
||||
return crypto_pwhash_argon2i_OPSLIMIT_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_opslimit_max(void)
|
||||
{
|
||||
return crypto_pwhash_argon2i_OPSLIMIT_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_memlimit_min(void)
|
||||
{
|
||||
return crypto_pwhash_argon2i_MEMLIMIT_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_memlimit_max(void)
|
||||
{
|
||||
return crypto_pwhash_argon2i_MEMLIMIT_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_argon2i_opslimit_interactive(void)
|
||||
{
|
||||
|
||||
@@ -15,6 +15,30 @@ crypto_pwhash_alg_default(void)
|
||||
return crypto_pwhash_ALG_ARGON2I13;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_bytes_min(void)
|
||||
{
|
||||
return crypto_pwhash_BYTES_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_bytes_max(void)
|
||||
{
|
||||
return crypto_pwhash_BYTES_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_passwd_min(void)
|
||||
{
|
||||
return crypto_pwhash_PASSWD_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_passwd_max(void)
|
||||
{
|
||||
return crypto_pwhash_PASSWD_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_saltbytes(void)
|
||||
{
|
||||
@@ -33,6 +57,30 @@ crypto_pwhash_strprefix(void)
|
||||
return crypto_pwhash_STRPREFIX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_opslimit_min(void)
|
||||
{
|
||||
return crypto_pwhash_OPSLIMIT_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_opslimit_max(void)
|
||||
{
|
||||
return crypto_pwhash_OPSLIMIT_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_memlimit_min(void)
|
||||
{
|
||||
return crypto_pwhash_MEMLIMIT_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_memlimit_max(void)
|
||||
{
|
||||
return crypto_pwhash_MEMLIMIT_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_opslimit_interactive(void)
|
||||
{
|
||||
|
||||
@@ -51,6 +51,30 @@ pickparams(unsigned long long opslimit, const size_t memlimit,
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_bytes_min(void)
|
||||
{
|
||||
return crypto_pwhash_scryptsalsa208sha256_BYTES_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_bytes_max(void)
|
||||
{
|
||||
return crypto_pwhash_scryptsalsa208sha256_BYTES_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_passwd_min(void)
|
||||
{
|
||||
return crypto_pwhash_scryptsalsa208sha256_PASSWD_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_passwd_max(void)
|
||||
{
|
||||
return crypto_pwhash_scryptsalsa208sha256_PASSWD_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_saltbytes(void)
|
||||
{
|
||||
@@ -69,6 +93,30 @@ crypto_pwhash_scryptsalsa208sha256_strprefix(void)
|
||||
return crypto_pwhash_scryptsalsa208sha256_STRPREFIX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_opslimit_min(void)
|
||||
{
|
||||
return crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_opslimit_max(void)
|
||||
{
|
||||
return crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_memlimit_min(void)
|
||||
{
|
||||
return crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_memlimit_max(void)
|
||||
{
|
||||
return crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_pwhash_scryptsalsa208sha256_opslimit_interactive(void)
|
||||
{
|
||||
|
||||
@@ -21,6 +21,22 @@ int crypto_pwhash_alg_argon2i13(void);
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_alg_default(void);
|
||||
|
||||
#define crypto_pwhash_BYTES_MIN crypto_pwhash_argon2i_BYTES_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_bytes_min(void);
|
||||
|
||||
#define crypto_pwhash_BYTES_MAX crypto_pwhash_argon2i_BYTES_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_bytes_max(void);
|
||||
|
||||
#define crypto_pwhash_PASSWD_MIN crypto_pwhash_argon2i_PASSWD_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_passwd_min(void);
|
||||
|
||||
#define crypto_pwhash_PASSWD_MAX crypto_pwhash_argon2i_PASSWD_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_passwd_max(void);
|
||||
|
||||
#define crypto_pwhash_SALTBYTES crypto_pwhash_argon2i_SALTBYTES
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_saltbytes(void);
|
||||
@@ -33,6 +49,22 @@ size_t crypto_pwhash_strbytes(void);
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_pwhash_strprefix(void);
|
||||
|
||||
#define crypto_pwhash_OPSLIMIT_MIN crypto_pwhash_argon2i_OPSLIMIT_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_opslimit_min(void);
|
||||
|
||||
#define crypto_pwhash_OPSLIMIT_MAX crypto_pwhash_argon2i_OPSLIMIT_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_opslimit_max(void);
|
||||
|
||||
#define crypto_pwhash_MEMLIMIT_MIN crypto_pwhash_argon2i_MEMLIMIT_MIN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_memlimit_min(void);
|
||||
|
||||
#define crypto_pwhash_MEMLIMIT_MAX crypto_pwhash_argon2i_MEMLIMIT_MAX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_memlimit_max(void);
|
||||
|
||||
#define crypto_pwhash_OPSLIMIT_INTERACTIVE crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_opslimit_interactive(void);
|
||||
|
||||
@@ -16,6 +16,22 @@ extern "C" {
|
||||
SODIUM_EXPORT
|
||||
int crypto_pwhash_argon2i_alg_argon2i13(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_BYTES_MIN ARGON2_MIN_OUTLEN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_bytes_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_BYTES_MAX ARGON2_MAX_OUTLEN
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_bytes_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_PASSWD_MIN ARGON2_MIN_PWD_LENGTH
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_passwd_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_PASSWD_MAX ARGON2_MAX_PWD_LENGTH
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_passwd_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_SALTBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_saltbytes(void);
|
||||
@@ -28,6 +44,22 @@ size_t crypto_pwhash_argon2i_strbytes(void);
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_pwhash_argon2i_strprefix(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_OPSLIMIT_MIN ARGON2_MIN_TIME
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_opslimit_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_OPSLIMIT_MAX ARGON2_MAX_TIME
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_opslimit_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_MEMLIMIT_MIN ARGON2_MIN_MEMORY
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_memlimit_min(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_MEMLIMIT_MAX ARGON2_MAX_MEMORY
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_memlimit_max(void);
|
||||
|
||||
#define crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE 4ULL
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_argon2i_opslimit_interactive(void);
|
||||
|
||||
@@ -13,6 +13,22 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_BYTES_MIN // XXX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_bytes_min(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_BYTES_MAX // XXX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_bytes_max(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_PASSWD_MIN // XXX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_passwd_min(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_PASSWD_MAX // XXX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_passwd_max(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_SALTBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_saltbytes(void);
|
||||
@@ -25,6 +41,22 @@ size_t crypto_pwhash_scryptsalsa208sha256_strbytes(void);
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_pwhash_scryptsalsa208sha256_strprefix(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN 32768
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_opslimit_min(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX // XXX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_opslimit_max(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN // XXX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_memlimit_min(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX // XXX
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_memlimit_max(void);
|
||||
|
||||
#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE 524288ULL
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_pwhash_scryptsalsa208sha256_opslimit_interactive(void);
|
||||
|
||||
@@ -320,9 +320,18 @@ int main(void)
|
||||
"password", strlen("password")) != -1) {
|
||||
printf("pwhash_str_verify(invalid(9)) failure\n");
|
||||
}
|
||||
assert(crypto_pwhash_bytes_min() > 0U);
|
||||
assert(crypto_pwhash_bytes_max() > 0U);
|
||||
assert(crypto_pwhash_passwd_min() > 0U);
|
||||
assert(crypto_pwhash_passwd_max() > 0U);
|
||||
assert(crypto_pwhash_saltbytes() > 0U);
|
||||
assert(crypto_pwhash_strbytes() > 1U);
|
||||
assert(crypto_pwhash_strbytes() > strlen(crypto_pwhash_strprefix()));
|
||||
|
||||
assert(crypto_pwhash_opslimit_min() > 0U);
|
||||
assert(crypto_pwhash_opslimit_max() > 0U);
|
||||
assert(crypto_pwhash_memlimit_min() > 0U);
|
||||
assert(crypto_pwhash_memlimit_max() > 0U);
|
||||
assert(crypto_pwhash_opslimit_interactive() > 0U);
|
||||
assert(crypto_pwhash_memlimit_interactive() > 0U);
|
||||
assert(crypto_pwhash_opslimit_moderate() > 0U);
|
||||
@@ -331,6 +340,17 @@ int main(void)
|
||||
assert(crypto_pwhash_memlimit_sensitive() > 0U);
|
||||
assert(strcmp(crypto_pwhash_primitive(), "argon2i") == 0);
|
||||
|
||||
assert(crypto_pwhash_bytes_min() == crypto_pwhash_BYTES_MIN);
|
||||
assert(crypto_pwhash_bytes_max() == crypto_pwhash_BYTES_MAX);
|
||||
assert(crypto_pwhash_passwd_min() == crypto_pwhash_PASSWD_MIN);
|
||||
assert(crypto_pwhash_passwd_max() == crypto_pwhash_PASSWD_MAX);
|
||||
assert(crypto_pwhash_saltbytes() == crypto_pwhash_SALTBYTES);
|
||||
assert(crypto_pwhash_strbytes() == crypto_pwhash_STRBYTES);
|
||||
|
||||
assert(crypto_pwhash_opslimit_min() == crypto_pwhash_OPSLIMIT_MIN);
|
||||
assert(crypto_pwhash_opslimit_max() == crypto_pwhash_OPSLIMIT_MAX);
|
||||
assert(crypto_pwhash_memlimit_min() == crypto_pwhash_MEMLIMIT_MIN);
|
||||
assert(crypto_pwhash_memlimit_max() == crypto_pwhash_MEMLIMIT_MAX);
|
||||
assert(crypto_pwhash_opslimit_interactive() == crypto_pwhash_OPSLIMIT_INTERACTIVE);
|
||||
assert(crypto_pwhash_memlimit_interactive() == crypto_pwhash_MEMLIMIT_INTERACTIVE);
|
||||
assert(crypto_pwhash_opslimit_moderate() == crypto_pwhash_OPSLIMIT_MODERATE);
|
||||
@@ -338,9 +358,17 @@ int main(void)
|
||||
assert(crypto_pwhash_opslimit_sensitive() == crypto_pwhash_OPSLIMIT_SENSITIVE);
|
||||
assert(crypto_pwhash_memlimit_sensitive() == crypto_pwhash_MEMLIMIT_SENSITIVE);
|
||||
|
||||
assert(crypto_pwhash_argon2i_bytes_min() == crypto_pwhash_bytes_min());
|
||||
assert(crypto_pwhash_argon2i_bytes_max() == crypto_pwhash_bytes_max());
|
||||
assert(crypto_pwhash_argon2i_passwd_min() == crypto_pwhash_passwd_min());
|
||||
assert(crypto_pwhash_argon2i_passwd_max() == crypto_pwhash_passwd_max());
|
||||
assert(crypto_pwhash_argon2i_saltbytes() == crypto_pwhash_saltbytes());
|
||||
assert(crypto_pwhash_argon2i_strbytes() == crypto_pwhash_strbytes());
|
||||
assert(strcmp(crypto_pwhash_argon2i_strprefix(), crypto_pwhash_strprefix()) == 0);
|
||||
assert(crypto_pwhash_argon2i_opslimit_min() == crypto_pwhash_opslimit_min());
|
||||
assert(crypto_pwhash_argon2i_opslimit_max() == crypto_pwhash_opslimit_max());
|
||||
assert(crypto_pwhash_argon2i_memlimit_min() == crypto_pwhash_memlimit_min());
|
||||
assert(crypto_pwhash_argon2i_memlimit_max() == crypto_pwhash_memlimit_max());
|
||||
assert(crypto_pwhash_argon2i_opslimit_interactive() ==
|
||||
crypto_pwhash_opslimit_interactive());
|
||||
assert(crypto_pwhash_argon2i_opslimit_moderate() ==
|
||||
|
||||
@@ -330,10 +330,19 @@ int main(void)
|
||||
str_out[14]--;
|
||||
|
||||
assert(str_out[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1U] == 0);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_bytes_min() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_bytes_max() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_passwd_min() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_passwd_max() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_saltbytes() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_strbytes() > 1U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_strbytes() >
|
||||
strlen(crypto_pwhash_scryptsalsa208sha256_strprefix()));
|
||||
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_min() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_max() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_min() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_max() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_interactive() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_interactive() > 0U);
|
||||
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() > 0U);
|
||||
|
||||
Reference in New Issue
Block a user