From 7cdf3f0e8419aa1be306effd11a20d980c118e04 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 22 Jul 2018 21:54:38 +0200 Subject: [PATCH] strnlen() may not be available everywhere --- .../pwhash_scryptsalsa208sha256.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c index 13b81895..b77588fa 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c @@ -52,6 +52,17 @@ pickparams(unsigned long long opslimit, const size_t memlimit, return 0; } +static size_t +sodium_strnlen(const char *str, size_t maxlen) +{ + size_t i = 0U; + + while (i < maxlen && str[i] != 0) { + i++; + } + return i; +} + size_t crypto_pwhash_scryptsalsa208sha256_bytes_min(void) { @@ -234,7 +245,7 @@ crypto_pwhash_scryptsalsa208sha256_str_verify( escrypt_local_t escrypt_local; int ret = -1; - if (strnlen(str, crypto_pwhash_scryptsalsa208sha256_STRBYTES) != + if (sodium_strnlen(str, crypto_pwhash_scryptsalsa208sha256_STRBYTES) != crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1U) { return -1; } @@ -268,7 +279,7 @@ crypto_pwhash_scryptsalsa208sha256_str_needs_rehash( errno = EINVAL; return -1; } - if (strnlen(str, crypto_pwhash_scryptsalsa208sha256_STRBYTES) != + if (sodium_strnlen(str, crypto_pwhash_scryptsalsa208sha256_STRBYTES) != crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1U) { errno = EINVAL; return -1;