From 74703c63a6ba3aaa540b0567d192786e0a3ad827 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 16 Jul 2017 20:03:03 +0200 Subject: [PATCH] More abort() -> sodium_misuse() --- .../crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c | 5 +++-- .../crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c | 3 ++- .../randombytes/nativeclient/randombytes_nativeclient.c | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c b/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c index d21f3173..e3d37a74 100644 --- a/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +++ b/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c @@ -10,6 +10,7 @@ #include #include +#include "core.h" #include "crypto_aead_aes256gcm.h" #include "export.h" #include "private/common.h" @@ -524,7 +525,7 @@ crypto_aead_aes256gcm_encrypt_detached_afternm(unsigned char *c, (void) nsec; memcpy(H, ctx->H, sizeof H); if (mlen > 16ULL * ((1ULL << 32) - 2)) { - abort(); /* LCOV_EXCL_LINE */ + sodium_misuse("crypto_aead_aes256gcm_encrypt_detached_afternm(): message too long"); /* LCOV_EXCL_LINE */ } memcpy(&n2[0], npub, 3 * 4); n2[3] = 0x01000000; @@ -662,7 +663,7 @@ crypto_aead_aes256gcm_decrypt_detached_afternm(unsigned char *m, unsigned char * (void) nsec; if (clen > 16ULL * (1ULL << 32)) { - abort(); /* LCOV_EXCL_LINE */ + sodium_misuse("crypto_aead_aes256gcm_decrypt_detached_afternm(): ciphertext too long"); /* LCOV_EXCL_LINE */ } mlen = clen; diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c index 25fa3811..df890f6b 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c @@ -31,6 +31,7 @@ #include +#include "core.h" #include "crypto_auth_hmacsha256.h" #include "pbkdf2-sha256.h" #include "private/common.h" @@ -56,7 +57,7 @@ PBKDF2_SHA256(const uint8_t *passwd, size_t passwdlen, const uint8_t *salt, #if SIZE_MAX > 0x1fffffffe0ULL if (dkLen > 0x1fffffffe0ULL) { - abort(); + sodium_misuse("PBKDF2_SHA256(): derived key length is too large"); /* LCOV_EXCL_LINE */ } #endif crypto_auth_hmacsha256_init(&PShctx, passwd, passwdlen); diff --git a/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c b/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c index 468cd653..bd1e8a94 100644 --- a/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c +++ b/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c @@ -6,6 +6,7 @@ #ifdef __native_client__ # include +# include "core.h" # include "utils.h" # include "randombytes.h" # include "randombytes_nativeclient.h" @@ -20,12 +21,12 @@ randombytes_nativeclient_buf(void * const buf, const size_t size) if (nacl_interface_query(NACL_IRT_RANDOM_v0_1, &rand_intf, sizeof rand_intf) != sizeof rand_intf) { - abort(); + sodium_misuse("randombytes_nativeclient_buf(): NaCl IRT_RANDOM API failed"); } while (toread > (size_t) 0U) { if (rand_intf.get_random_bytes(buf_, size, &readnb) != 0 || readnb > size) { - abort(); + sodium_misuse("randombytes_nativeclient_buf(): NaCl IRT_RANDOM API didn't return the correct amount of bytes"); } toread -= readnb; buf_ += readnb;