From 9a386d0a6dafc630b324f1b238ce1781483e85cb Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 15 Jan 2015 14:37:26 +0100 Subject: [PATCH] Test crypto_box[_open]_easy_afternm() with short and overflowing lengths --- test/default/box_easy2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/default/box_easy2.c b/test/default/box_easy2.c index ba63e588..f4f1ff53 100644 --- a/test/default/box_easy2.c +++ b/test/default/box_easy2.c @@ -63,12 +63,19 @@ int main(void) crypto_box_beforenm(k2, bobpk, alicesk); memset(m2, 0, sizeof m2); + + if (crypto_box_easy_afternm(c, m, SIZE_MAX - 1U, nonce, k1) == 0) { + printf("crypto_box_easy_afternm() with a short ciphertext should have failed\n"); + } crypto_box_easy_afternm(c, m, (unsigned long long) mlen, nonce, k1); crypto_box_open_easy_afternm(m2, c, (unsigned long long) mlen + crypto_box_MACBYTES, nonce, k2); printf("%d\n", memcmp(m, m2, mlen)); - + if (crypto_box_open_easy_afternm(m2, c, crypto_box_MACBYTES - 1U, + nonce, k2) == 0) { + printf("crypto_box_open_easy_afternm() with a huge ciphertext should have failed\n"); + } memset(m2, 0, sizeof m2); crypto_box_detached(c, mac, m, (unsigned long long) mlen, nonce, alicepk, bobsk);