From ec6b86611f4106f04da597087fe296923c0b8bd2 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 6 Dec 2015 19:06:27 +0100 Subject: [PATCH] More checks for sodium_add() (overlaps) and sodium_increment() --- test/default/sodium_utils.c | 37 +++++++++++++++++++++++++++++++++++ test/default/sodium_utils.exp | 6 ++++++ 2 files changed, 43 insertions(+) diff --git a/test/default/sodium_utils.c b/test/default/sodium_utils.c index 39f8127a..1583d204 100644 --- a/test/default/sodium_utils.c +++ b/test/default/sodium_utils.c @@ -141,5 +141,42 @@ int main(void) if (sodium_compare(buf1, buf2, bin_len) != 0) { printf("sodium_add() failed\n"); } + + assert(sizeof nonce >= 24U); + memset(nonce, 0xfe, 24U); + memset(nonce, 0xff, 6U); + sodium_increment(nonce, 8U); + printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, + nonce, sizeof nonce)); + memset(nonce, 0xfe, 24U); + memset(nonce, 0xff, 10U); + sodium_increment(nonce, 12U); + printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, + nonce, sizeof nonce)); + memset(nonce, 0xff, 22U); + sodium_increment(nonce, 24U); + printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, + nonce, sizeof nonce)); + + + assert(sizeof nonce >= 24U); + memset(nonce, 0xfe, 24U); + memset(nonce, 0xff, 6U); + sodium_add(nonce, nonce, 7U); + sodium_add(nonce, nonce, 8U); + printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, + nonce, sizeof nonce)); + memset(nonce, 0xfe, 24U); + memset(nonce, 0xff, 10U); + sodium_add(nonce, nonce, 11U); + sodium_add(nonce, nonce, 12U); + printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, + nonce, sizeof nonce)); + memset(nonce, 0xff, 22U); + sodium_add(nonce, nonce, 23U); + sodium_add(nonce, nonce, 24U); + printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, + nonce, sizeof nonce)); + return 0; } diff --git a/test/default/sodium_utils.exp b/test/default/sodium_utils.exp index 661e6570..030a1cb3 100644 --- a/test/default/sodium_utils.exp +++ b/test/default/sodium_utils.exp @@ -16,3 +16,9 @@ dt5: 11 010100000000000000000000000000000000000000000000 020000000000000000000000000000000000000000000000 0001ff000000000000000000000000000000000000000000 +000000000000fffefefefefefefefefefefefefefefefefe +00000000000000000000fffefefefefefefefefefefefefe +00000000000000000000000000000000000000000000fffe +fcfffffffffffbfdfefefefefefefefefefefefefefefefe +fcfffffffffffffffffffbfdfefefefefefefefefefefefe +fcfffffffffffffffffffffffffffffffffffffffffffbfd