From 9154d7416e443423cc565ef03ff3707587930ef5 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 30 Jun 2014 16:23:34 -0700 Subject: [PATCH] Add a test for crypto_aead without any additional data --- test/default/aead_chacha20poly1305.c | 26 ++++++++++++++++++++++++++ test/default/aead_chacha20poly1305.exp | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/test/default/aead_chacha20poly1305.c b/test/default/aead_chacha20poly1305.c index 31d17863..036d0014 100644 --- a/test/default/aead_chacha20poly1305.c +++ b/test/default/aead_chacha20poly1305.c @@ -67,5 +67,31 @@ int main(void) } c[i] ^= (i + 1U); } + + crypto_aead_chacha20poly1305_encrypt(c, &clen, m, 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(m2, &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, m2, sizeof m) != 0) { + printf("m != m2 (adlen=0)\n"); + } + return 0; } diff --git a/test/default/aead_chacha20poly1305.exp b/test/default/aead_chacha20poly1305.exp index a846fe0e..14355fa7 100644 --- a/test/default/aead_chacha20poly1305.exp +++ b/test/default/aead_chacha20poly1305.exp @@ -2,3 +2,7 @@ ,0x62,0xa4,0x67,0x7d,0xab,0xf4,0xe3,0xd2 ,0x4b,0x87,0x6b,0xb2,0x84,0x75,0x38,0x96 ,0xe1,0xd6 +,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