More abort() -> sodium_misuse()

This commit is contained in:
Frank Denis 2017-07-16 20:03:03 +02:00
parent a0e997b8ae
commit 74703c63a6
3 changed files with 8 additions and 5 deletions

View File

@ -10,6 +10,7 @@
#include <stdlib.h>
#include <string.h>
#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;

View File

@ -31,6 +31,7 @@
#include <sys/types.h>
#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);

View File

@ -6,6 +6,7 @@
#ifdef __native_client__
# include <irt.h>
# 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;