From 8a70f258fdbf5287ccda5b99e43f8622602dba70 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 16 Jul 2017 23:11:36 +0200 Subject: [PATCH] No more abort() calls! --- .../chacha20poly1305/sodium/aead_chacha20poly1305.c | 5 +++-- .../xchacha20poly1305/sodium/aead_xchacha20poly1305.c | 3 ++- .../crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c | 3 ++- .../crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c | 3 ++- src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c b/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c index 406dcf25..f2359462 100644 --- a/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +++ b/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c @@ -4,6 +4,7 @@ #include #include +#include "core.h" #include "crypto_aead_chacha20poly1305.h" #include "crypto_onetimeauth_poly1305.h" #include "crypto_stream_chacha20.h" @@ -70,7 +71,7 @@ crypto_aead_chacha20poly1305_encrypt(unsigned char *c, int ret; if (mlen > UINT64_MAX - crypto_aead_chacha20poly1305_ABYTES) { - abort(); /* LCOV_EXCL_LINE */ + sodium_misuse("crypto_aead_chacha20poly1305_encrypt(): message too long"); } ret = crypto_aead_chacha20poly1305_encrypt_detached(c, c + mlen, NULL, @@ -145,7 +146,7 @@ crypto_aead_chacha20poly1305_ietf_encrypt(unsigned char *c, int ret; if (mlen > UINT64_MAX - crypto_aead_chacha20poly1305_ietf_ABYTES) { - abort(); /* LCOV_EXCL_LINE */ + sodium_misuse("crypto_aead_chacha20poly1305_ietf_encrypt(): message too long"); } ret = crypto_aead_chacha20poly1305_ietf_encrypt_detached(c, c + mlen, NULL, diff --git a/src/libsodium/crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c b/src/libsodium/crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c index 38385c84..50ba88a2 100644 --- a/src/libsodium/crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c +++ b/src/libsodium/crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c @@ -4,6 +4,7 @@ #include #include +#include "core.h" #include "crypto_aead_xchacha20poly1305.h" #include "crypto_aead_chacha20poly1305.h" #include "crypto_core_hchacha20.h" @@ -53,7 +54,7 @@ crypto_aead_xchacha20poly1305_ietf_encrypt(unsigned char *c, int ret; if (mlen > UINT64_MAX - crypto_aead_xchacha20poly1305_ietf_ABYTES) { - abort(); /* LCOV_EXCL_LINE */ + sodium_misuse("crypto_aead_xchacha20poly1305_ietf_encrypt(): message too long"); } ret = crypto_aead_xchacha20poly1305_ietf_encrypt_detached (c, c + mlen, NULL, m, mlen, ad, adlen, nsec, npub, k); diff --git a/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c b/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c index c8cdff37..467870bb 100644 --- a/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c +++ b/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c @@ -3,6 +3,7 @@ #include #include +#include "core.h" #include "crypto_stream_chacha20.h" #include "private/common.h" #include "private/sse2_64_32.h" @@ -77,7 +78,7 @@ chacha20_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c, return; /* LCOV_EXCL_LINE */ } if (bytes > 64ULL * (1ULL << 32) - 64ULL) { - abort(); + sodium_misuse("chacha20_encrypt_bytes(): message too long"); } # include "u8.h" # include "u4.h" diff --git a/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c b/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c index 06895932..f2f21a08 100644 --- a/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c +++ b/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c @@ -3,6 +3,7 @@ #include #include +#include "core.h" #include "crypto_stream_chacha20.h" #include "private/common.h" #include "private/sse2_64_32.h" @@ -72,7 +73,7 @@ chacha20_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c, return; /* LCOV_EXCL_LINE */ } if (bytes > 64ULL * (1ULL << 32) - 64ULL) { - abort(); + sodium_misuse("chacha20_encrypt_bytes(): message too long"); } # include "u4.h" # include "u1.h" diff --git a/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c b/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c index 7a19cebb..150c68fa 100644 --- a/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c +++ b/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c @@ -9,6 +9,7 @@ #include #include +#include "core.h" #include "crypto_stream_chacha20.h" #include "private/common.h" #include "utils.h" @@ -92,7 +93,7 @@ chacha20_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c, return; /* LCOV_EXCL_LINE */ } if (bytes > 64ULL * (1ULL << 32) - 64ULL) { - abort(); + sodium_misuse("chacha20_encrypt_bytes(): message too long"); } j0 = ctx->input[0]; j1 = ctx->input[1];