From 30c1e13f2a288146aa7195b5d046743427ca4df2 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 12 May 2014 12:34:41 -0700 Subject: [PATCH] Switch opslimit and memlimit in pwhash, to be closer to PHC's proposed API. --- README.markdown | 8 ++++---- .../pwhash_scryptxsalsa208sha256.c | 14 +++++++------- .../sodium/crypto_pwhash_scryptxsalsa208sha256.h | 8 ++++---- test/default/pwhash.c | 8 ++++---- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.markdown b/README.markdown index 2799d02c..8235f12f 100644 --- a/README.markdown +++ b/README.markdown @@ -284,8 +284,8 @@ in the library even after the PHC. const char *passwd, unsigned long long passwdlen, const unsigned char *salt, - size_t memlimit, - unsigned long long opslimit); + unsigned long long opslimit, + size_t memlimit); This function derives `outlen` bytes from a password `passwd` and a salt `salt` that has to be `crypto_pwhash_scryptxsalsa208sha256_SALTBYTES` @@ -303,8 +303,8 @@ function, it can still be used for this purpose: (char out[crypto_pwhash_scryptxsalsa208sha256_STRBYTES], const char *passwd, unsigned long long passwdlen, - size_t memlimit, - unsigned long long opslimit); + unsigned long long opslimit, + size_t memlimit); This function returns a `crypto_pwhash_scryptxsalsa208sha256_STRBYTES` bytes C string (the length includes the final `\0`) suitable for storage. diff --git a/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/pwhash_scryptxsalsa208sha256.c b/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/pwhash_scryptxsalsa208sha256.c index de33dd99..57f40ca0 100644 --- a/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/pwhash_scryptxsalsa208sha256.c +++ b/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/pwhash_scryptxsalsa208sha256.c @@ -15,7 +15,7 @@ (1U /* N_log2 */) + (5U /* r */) + (5U /* p */) + BYTES2CHARS(saltbytes) static int -pickparams(const size_t memlimit, unsigned long long opslimit, +pickparams(unsigned long long opslimit, const size_t memlimit, uint32_t * const N_log2, uint32_t * const p, uint32_t * const r) { unsigned long long maxN; @@ -67,8 +67,8 @@ crypto_pwhash_scryptxsalsa208sha256(unsigned char * const out, const char * const passwd, unsigned long long passwdlen, const unsigned char * const salt, - size_t memlimit, - unsigned long long opslimit) + unsigned long long opslimit, + size_t memlimit) { uint32_t N_log2; uint32_t p; @@ -79,7 +79,7 @@ crypto_pwhash_scryptxsalsa208sha256(unsigned char * const out, errno = EFBIG; return -1; } - if (pickparams(memlimit, opslimit, &N_log2, &p, &r) != 0) { + if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) { errno = EINVAL; return -1; } @@ -94,8 +94,8 @@ int crypto_pwhash_scryptxsalsa208sha256_str(char out[crypto_pwhash_scryptxsalsa208sha256_STRBYTES], const char * const passwd, unsigned long long passwdlen, - size_t memlimit, - unsigned long long opslimit) + unsigned long long opslimit, + size_t memlimit) { uint8_t salt[crypto_pwhash_scryptxsalsa208sha256_STRSALTBYTES]; char setting[crypto_pwhash_scryptxsalsa208sha256_STRSETTINGBYTES + 1U]; @@ -109,7 +109,7 @@ crypto_pwhash_scryptxsalsa208sha256_str(char out[crypto_pwhash_scryptxsalsa208sh errno = EFBIG; return -1; } - if (pickparams(memlimit, opslimit, &N_log2, &p, &r) != 0) { + if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) { errno = EINVAL; return -1; } diff --git a/src/libsodium/include/sodium/crypto_pwhash_scryptxsalsa208sha256.h b/src/libsodium/include/sodium/crypto_pwhash_scryptxsalsa208sha256.h index 3eca3cb6..606bab66 100644 --- a/src/libsodium/include/sodium/crypto_pwhash_scryptxsalsa208sha256.h +++ b/src/libsodium/include/sodium/crypto_pwhash_scryptxsalsa208sha256.h @@ -27,15 +27,15 @@ int crypto_pwhash_scryptxsalsa208sha256(unsigned char * const out, const char * const passwd, unsigned long long passwdlen, const unsigned char * const salt, - size_t memlimit, - unsigned long long opslimit); + unsigned long long opslimit, + size_t memlimit); SODIUM_EXPORT int crypto_pwhash_scryptxsalsa208sha256_str(char out[crypto_pwhash_scryptxsalsa208sha256_STRBYTES], const char * const passwd, unsigned long long passwdlen, - size_t memlimit, - unsigned long long opslimit); + unsigned long long opslimit, + size_t memlimit); SODIUM_EXPORT int crypto_pwhash_scryptxsalsa208sha256_str_verify(const char str[crypto_pwhash_scryptxsalsa208sha256_STRBYTES], diff --git a/test/default/pwhash.c b/test/default/pwhash.c index b90063fa..367a88ec 100644 --- a/test/default/pwhash.c +++ b/test/default/pwhash.c @@ -5,8 +5,8 @@ #include "cmptest.h" #define OUT_LEN 128 -#define MEMLIMIT 10000000 #define OPSLIMIT 1000000 +#define MEMLIMIT 10000000 int main(void) { @@ -21,17 +21,17 @@ int main(void) if (crypto_pwhash_scryptxsalsa208sha256(out, sizeof out, passwd, strlen(passwd), (const unsigned char *) salt, - MEMLIMIT, OPSLIMIT) != 0) { + OPSLIMIT, MEMLIMIT) != 0) { printf("pwhash failure\n"); } sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out); printf("out_hex: [%s]\n", out_hex); if (crypto_pwhash_scryptxsalsa208sha256_str(str_out, passwd, strlen(passwd), - MEMLIMIT, OPSLIMIT) != 0) { + OPSLIMIT, MEMLIMIT) != 0) { printf("pwhash_str failure\n"); } if (crypto_pwhash_scryptxsalsa208sha256_str(str_out2, passwd, strlen(passwd), - MEMLIMIT, OPSLIMIT) != 0) { + OPSLIMIT, MEMLIMIT) != 0) { printf("pwhash_str(2) failure\n"); } if (strcmp(str_out, str_out2) == 0) {