From 9def4d9a8a5ca6ec1309d44612a224305d16b7a7 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 17 Jul 2017 00:36:55 +0200 Subject: [PATCH] Add tests for crypto_kx_*() when a single key is required --- test/default/kx.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/default/kx.c b/test/default/kx.c index dcc247f5..1950a6af 100644 --- a/test/default/kx.c +++ b/test/default/kx.c @@ -91,6 +91,24 @@ tv_kx(void) sodium_bin2hex(hex, sizeof hex, client_tx, crypto_kx_SESSIONKEYBYTES); printf("client_tx: [%s]\n", hex); + randombytes_buf(client_rx, crypto_kx_SESSIONKEYBYTES); + randombytes_buf(client_tx, crypto_kx_SESSIONKEYBYTES); + randombytes_buf(server_rx, crypto_kx_SESSIONKEYBYTES); + randombytes_buf(server_tx, crypto_kx_SESSIONKEYBYTES); + if (crypto_kx_client_session_keys(client_rx, NULL, + client_pk, client_sk, server_pk) != 0 || + crypto_kx_client_session_keys(NULL, client_tx, + client_pk, client_sk, server_pk) != 0 || + crypto_kx_server_session_keys(server_rx, NULL, + server_pk, server_sk, client_pk) != 0 || + crypto_kx_server_session_keys(NULL, server_tx, + server_pk, server_sk, client_pk) != 0) { + printf("failure when one of the pointers happens to be NULL"); + } + assert(memcmp(client_rx, client_tx, crypto_kx_SESSIONKEYBYTES) == 0); + assert(memcmp(client_tx, server_rx, crypto_kx_SESSIONKEYBYTES) == 0); + assert(memcmp(server_rx, server_tx, crypto_kx_SESSIONKEYBYTES) == 0); + sodium_free(client_rx); sodium_free(client_tx); sodium_free(server_rx);