From 6104af118929c02e22166c7b72a225f6e4a6e812 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 6 Jan 2015 21:18:36 +0100 Subject: [PATCH] Add new tests for the crypto_box_*() precomputed interface --- test/default/box_easy2.c | 33 +++++++++++++++++++++++++++++---- test/default/box_easy2.exp | 2 ++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/test/default/box_easy2.c b/test/default/box_easy2.c index 2e366bf8..ba63e588 100644 --- a/test/default/box_easy2.c +++ b/test/default/box_easy2.c @@ -14,6 +14,8 @@ int main(void) unsigned char *bobsk; unsigned char *mac; unsigned char *nonce; + unsigned char *k1; + unsigned char *k2; size_t mlen; size_t i; @@ -23,6 +25,8 @@ int main(void) bobsk = (unsigned char *) sodium_malloc(crypto_box_SECRETKEYBYTES); mac = (unsigned char *) sodium_malloc(crypto_box_MACBYTES); nonce = (unsigned char *) sodium_malloc(crypto_box_NONCEBYTES); + k1 = (unsigned char *) sodium_malloc(crypto_box_BEFORENMBYTES); + k2 = (unsigned char *) sodium_malloc(crypto_box_BEFORENMBYTES); crypto_box_keypair(alicepk, alicesk); crypto_box_keypair(bobpk, bobsk); mlen = (size_t) randombytes_uniform((uint32_t)sizeof m); @@ -55,17 +59,38 @@ int main(void) printf("crypto_box_open_easy() failed\n"); } - crypto_box_detached(c, mac, m, (unsigned long long) mlen, - nonce, bobsk, alicepk); - crypto_box_open_detached(m2, c, mac, (unsigned long long) mlen, - nonce, alicepk, bobsk); + crypto_box_beforenm(k1, alicepk, bobsk); + crypto_box_beforenm(k2, bobpk, alicesk); + + memset(m2, 0, sizeof m2); + 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)); + + memset(m2, 0, sizeof m2); + crypto_box_detached(c, mac, m, (unsigned long long) mlen, + nonce, alicepk, bobsk); + crypto_box_open_detached(m2, c, mac, (unsigned long long) mlen, + nonce, bobpk, alicesk); + printf("%d\n", memcmp(m, m2, mlen)); + + memset(m2, 0, sizeof m2); + crypto_box_detached_afternm(c, mac, m, (unsigned long long) mlen, + nonce, k1); + crypto_box_open_detached_afternm(m2, c, mac, (unsigned long long) mlen, + nonce, k2); + printf("%d\n", memcmp(m, m2, mlen)); + sodium_free(alicepk); sodium_free(alicesk); sodium_free(bobpk); sodium_free(bobsk); sodium_free(mac); sodium_free(nonce); + sodium_free(k1); + sodium_free(k2); printf("OK\n"); return 0; diff --git a/test/default/box_easy2.exp b/test/default/box_easy2.exp index 524cb98e..9a8dd6c6 100644 --- a/test/default/box_easy2.exp +++ b/test/default/box_easy2.exp @@ -2,4 +2,6 @@ 0 0 0 +0 +0 OK