From 71b5184224f5f4307fbadcc770bfa24150c9da6a Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 5 Oct 2014 00:02:45 -0700 Subject: [PATCH] Add a test for chacha20poly1305 with overlapping pointers --- test/default/aead_chacha20poly1305.c | 25 +++++++++++++++++++++++++ test/default/aead_chacha20poly1305.exp | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/test/default/aead_chacha20poly1305.c b/test/default/aead_chacha20poly1305.c index c587e96c..83374b20 100644 --- a/test/default/aead_chacha20poly1305.c +++ b/test/default/aead_chacha20poly1305.c @@ -95,6 +95,31 @@ int main(void) "ciphertext\n"); } + memcpy(c, m, sizeof m); + crypto_aead_chacha20poly1305_encrypt(c, &clen, c, sizeof m, NULL, 0U, NULL, + nonce, firstkey); + if (clen != sizeof m + crypto_aead_chacha20poly1305_abytes()) { + printf("clen is not properly set (adlen=0)\n"); + } + for (i = 0U; i < sizeof c; ++i) { + printf(",0x%02x", (unsigned int)c[i]); + if (i % 8 == 7) { + printf("\n"); + } + } + printf("\n"); + + if (crypto_aead_chacha20poly1305_decrypt(c, &m2len, NULL, c, sizeof c, + NULL, 0U, nonce, firstkey) != 0) { + printf("crypto_aead_chacha20poly1305_decrypt() failed (adlen=0)\n"); + } + if (m2len != sizeof c - crypto_aead_chacha20poly1305_abytes()) { + printf("m2len is not properly set (adlen=0)\n"); + } + if (memcmp(m, c, sizeof m) != 0) { + printf("m != c (adlen=0)\n"); + } + assert(crypto_aead_chacha20poly1305_keybytes() > 0U); assert(crypto_aead_chacha20poly1305_npubbytes() > 0U); assert(crypto_aead_chacha20poly1305_nsecbytes() == 0U); diff --git a/test/default/aead_chacha20poly1305.exp b/test/default/aead_chacha20poly1305.exp index 14355fa7..9f90a523 100644 --- a/test/default/aead_chacha20poly1305.exp +++ b/test/default/aead_chacha20poly1305.exp @@ -6,3 +6,7 @@ ,0x62,0xa4,0x69,0xe7,0x78,0x9b,0xcd,0x95 ,0x4e,0x65,0x8e,0xd3,0x84,0x23,0xe2,0x31 ,0x61,0xdc +,0xe3,0xe4,0x46,0xf7,0xed,0xe9,0xa1,0x9b +,0x62,0xa4,0x69,0xe7,0x78,0x9b,0xcd,0x95 +,0x4e,0x65,0x8e,0xd3,0x84,0x23,0xe2,0x31 +,0x61,0xdc