1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 10:05:05 -07:00

Switch opslimit and memlimit in pwhash, to be closer to PHC's proposed API.

This commit is contained in:
Frank Denis 2014-05-12 12:34:41 -07:00
parent 37d73684b8
commit 30c1e13f2a
4 changed files with 19 additions and 19 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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],

View File

@ -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) {