From 9eefb2e487fc7441b50d6c8e094fd805eef1521b Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 18 Sep 2014 22:02:25 -0700 Subject: [PATCH] More test + lcov exclusions --- .../scryptsalsa208sha256/pbkdf2-sha256.c | 3 ++- .../scryptsalsa208sha256/scrypt_platform.c | 4 ++-- test/default/sign.c | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c index ac426d37..6096cf32 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c @@ -63,7 +63,7 @@ PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, crypto_auth_hmacsha256_final(&hctx, U); memcpy(T, U, 32); - +/* LCOV_EXCL_START */ for (j = 2; j <= c; j++) { crypto_auth_hmacsha256_init(&hctx, passwd, passwdlen); crypto_auth_hmacsha256_update(&hctx, U, 32); @@ -73,6 +73,7 @@ PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, T[k] ^= U[k]; } } +/* LCOV_EXCL_STOP */ clen = dkLen - i * 32; if (clen > 32) { diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c index cddf964f..da8b4330 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c @@ -43,7 +43,7 @@ alloc_region(escrypt_region_t * region, size_t size) MAP_ANON | MAP_PRIVATE, #endif -1, 0)) == MAP_FAILED) - base = NULL; + base = NULL; /* LCOV_EXCL_LINE */ aligned = base; #elif defined(HAVE_POSIX_MEMALIGN) if ((errno = posix_memalign((void **) &base, 64, size)) != 0) @@ -77,7 +77,7 @@ free_region(escrypt_region_t * region) if (region->base) { #ifdef MAP_ANON if (munmap(region->base, region->size)) - return -1; + return -1; /* LCOV_EXCL_LINE */ #else free(region->base); #endif diff --git a/test/default/sign.c b/test/default/sign.c index 9eebc5a3..3bcde4d4 100644 --- a/test/default/sign.c +++ b/test/default/sign.c @@ -1057,6 +1057,7 @@ int main(void) unsigned long long smlen; unsigned long long mlen; unsigned int i; + unsigned int j; for (i = 0U; i < (sizeof test_data) / (sizeof test_data[0]); i++) { memcpy(skpk, test_data[i].sk, crypto_sign_SEEDBYTES); @@ -1113,6 +1114,25 @@ int main(void) } printf("%u tests\n", i); + i--; + for (j = 1U; j < 8U; j++) { + sig[63] ^= (j << 5); + if (crypto_sign_verify_detached(sig, + (const unsigned char *)test_data[i].m, + i, test_data[i].pk) != -1) { + printf("detached signature verification should have failed\n"); + continue; + } + sig[63] ^= (j << 5); + } + + memset(pk, 0, sizeof pk); + if (crypto_sign_verify_detached(sig, + (const unsigned char *)test_data[i].m, + i, pk) != -1) { + printf("detached signature verification should have failed\n"); + } + if (crypto_sign_keypair(pk, sk) != 0) { printf("crypto_sign_keypair() failure\n"); }