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

+ _crypto_pwhash_scryptsalsa208sha256_str_needs_rehash()

This commit is contained in:
Frank Denis 2017-09-13 00:36:29 +02:00
parent 6dcba550c2
commit d0a418a863
7 changed files with 72 additions and 18 deletions

View File

@ -332,6 +332,7 @@ _crypto_pwhash_scryptsalsa208sha256_passwd_max 0 1
_crypto_pwhash_scryptsalsa208sha256_passwd_min 0 1 _crypto_pwhash_scryptsalsa208sha256_passwd_min 0 1
_crypto_pwhash_scryptsalsa208sha256_saltbytes 0 1 _crypto_pwhash_scryptsalsa208sha256_saltbytes 0 1
_crypto_pwhash_scryptsalsa208sha256_str 0 1 _crypto_pwhash_scryptsalsa208sha256_str 0 1
_crypto_pwhash_scryptsalsa208sha256_str_needs_rehash 0 1
_crypto_pwhash_scryptsalsa208sha256_str_verify 0 1 _crypto_pwhash_scryptsalsa208sha256_str_verify 0 1
_crypto_pwhash_scryptsalsa208sha256_strbytes 0 1 _crypto_pwhash_scryptsalsa208sha256_strbytes 0 1
_crypto_pwhash_scryptsalsa208sha256_strprefix 0 1 _crypto_pwhash_scryptsalsa208sha256_strprefix 0 1

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -105,6 +105,34 @@ decode64_uint32(uint32_t *dst, uint32_t dstbits, const uint8_t *src)
return src; return src;
} }
const uint8_t *
escrypt_parse_setting(const uint8_t *setting,
uint32_t *N_log2_p, uint32_t *r_p, uint32_t *p_p)
{
const uint8_t *src;
if (setting[0] != '$' || setting[1] != '7' || setting[2] != '$') {
return NULL;
}
src = setting + 3;
if (decode64_one(N_log2_p, *src)) {
return NULL;
}
src++;
src = decode64_uint32(r_p, 30, src);
if (!src) {
return NULL;
}
src = decode64_uint32(p_p, 30, src);
if (!src) {
return NULL;
}
return src;
}
uint8_t * uint8_t *
escrypt_r(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen, escrypt_r(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen,
const uint8_t *setting, uint8_t *buf, size_t buflen) const uint8_t *setting, uint8_t *buf, size_t buflen)
@ -122,25 +150,11 @@ escrypt_r(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen,
uint32_t r; uint32_t r;
uint32_t p; uint32_t p;
if (setting[0] != '$' || setting[1] != '7' || setting[2] != '$') { src = escrypt_parse_setting(setting, &N_log2, &r, &p);
if (!src) {
return NULL; return NULL;
} }
src = setting + 3;
if (decode64_one(&N_log2, *src)) {
return NULL;
}
src++;
N = (uint64_t) 1 << N_log2; N = (uint64_t) 1 << N_log2;
src = decode64_uint32(&r, 30, src);
if (!src) {
return NULL;
}
src = decode64_uint32(&p, 30, src);
if (!src) {
return NULL;
}
prefixlen = src - setting; prefixlen = src - setting;
salt = src; salt = src;

View File

@ -91,4 +91,8 @@ extern uint8_t *escrypt_gensalt_r(uint32_t __N_log2, uint32_t __r, uint32_t __p,
const uint8_t *__src, size_t __srclen, const uint8_t *__src, size_t __srclen,
uint8_t *__buf, size_t __buflen); uint8_t *__buf, size_t __buflen);
extern const uint8_t *escrypt_parse_setting(const uint8_t *setting,
uint32_t *N_log2_p, uint32_t *r_p,
uint32_t *p_p);
#endif /* !_CRYPTO_SCRYPT_H_ */ #endif /* !_CRYPTO_SCRYPT_H_ */

View File

@ -254,3 +254,32 @@ crypto_pwhash_scryptsalsa208sha256_str_verify(
return ret; return ret;
} }
int
crypto_pwhash_scryptsalsa208sha256_str_needs_rehash(
const char str[crypto_pwhash_scryptsalsa208sha256_STRBYTES],
unsigned long long opslimit, size_t memlimit)
{
uint32_t N_log2, N_log2_;
uint32_t p, p_;
uint32_t r, r_;
if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) {
errno = EINVAL;
return -1;
}
if (memchr(str, 0, crypto_pwhash_scryptsalsa208sha256_STRBYTES) !=
&str[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1U]) {
errno = EINVAL;
return -1;
}
if (escrypt_parse_setting((const uint8_t *) str,
&N_log2_, &r_, &p_) == NULL) {
errno = EINVAL;
return -1;
}
if (N_log2 != N_log2_ || r != r_ || p != p_) {
return 1;
}
return 0;
}

View File

@ -107,6 +107,12 @@ int crypto_pwhash_scryptsalsa208sha256_ll(const uint8_t * passwd, size_t passwdl
uint8_t * buf, size_t buflen) uint8_t * buf, size_t buflen)
__attribute__ ((warn_unused_result)); __attribute__ ((warn_unused_result));
SODIUM_EXPORT
int crypto_pwhash_scryptsalsa208sha256_str_needs_rehash(const char str[crypto_pwhash_scryptsalsa208sha256_STRBYTES],
unsigned long long opslimit,
size_t memlimit)
__attribute__ ((warn_unused_result));
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif