More crypto_pwhash() tests

This commit is contained in:
Frank Denis 2014-09-16 15:07:42 -07:00
parent a721543b58
commit fe4bbdc5ca
3 changed files with 17 additions and 8 deletions

View File

@ -171,7 +171,7 @@ escrypt_r(escrypt_local_t * local, const uint8_t * passwd, size_t passwdlen,
dst = encode64(dst, buflen - (dst - buf), hash, sizeof(hash));
sodium_memzero(hash, sizeof hash);
if (!dst || dst >= buf + buflen) { /* Can't happen */
if (!dst || dst >= buf + buflen) { /* Can't happen LCOV_EXCL_LINE */
return NULL;
}
*dst = 0; /* NUL termination */
@ -205,15 +205,15 @@ escrypt_gensalt_r(uint32_t N_log2, uint32_t r, uint32_t p,
*dst++ = itoa64[N_log2];
dst = encode64_uint32(dst, buflen - (dst - buf), r, 30);
if (!dst) { /* Can't happen */
if (!dst) { /* Can't happen LCOV_EXCL_LINE */
return NULL;
}
dst = encode64_uint32(dst, buflen - (dst - buf), p, 30);
if (!dst) { /* Can't happen */
if (!dst) { /* Can't happen LCOV_EXCL_LINE */
return NULL;
}
dst = encode64(dst, buflen - (dst - buf), src, srclen);
if (!dst || dst >= buf + buflen) { /* Can't happen */
if (!dst || dst >= buf + buflen) { /* Can't happen LCOV_EXCL_LINE */
return NULL;
}
*dst = 0; /* NUL termination */

View File

@ -106,8 +106,8 @@ crypto_pwhash_scryptsalsa208sha256(unsigned char * const out,
memset(out, 0, outlen);
if (passwdlen > SIZE_MAX || outlen > SIZE_MAX) {
errno = EFBIG;
return -1;
errno = EFBIG; /* LCOV_EXCL_LINE */
return -1; /* LCOV_EXCL_LINE */
}
if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) {
errno = EINVAL;
@ -137,8 +137,8 @@ crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha2
memset(out, 0, crypto_pwhash_scryptsalsa208sha256_STRBYTES);
if (passwdlen > SIZE_MAX) {
errno = EFBIG;
return -1;
errno = EFBIG; /* LCOV_EXCL_LINE */
return -1; /* LCOV_EXCL_LINE */
}
if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) {
errno = EINVAL;

View File

@ -212,5 +212,14 @@ int main(void)
}
printf("OK\n");
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_interactive() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_interactive() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive() > 0U);
return 0;
}