Just use some test vectors around the counter overflow

This commit is contained in:
Frank Denis
2019-03-21 03:08:40 +01:00
parent 9218397375
commit 773a94d70b
2 changed files with 25 additions and 20 deletions
+9 -20
View File
@@ -16,7 +16,7 @@ static unsigned char nonce[24] = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6,
static unsigned char output[4194304];
static unsigned char h[32];
static char hex[2 * 192 + 1];
static char hex[4096];
int
main(void)
@@ -53,25 +53,14 @@ main(void)
sodium_bin2hex(hex, 192 * 2 + 1, output, 192);
printf("%s\n", hex);
assert(memcmp(output, output + 64, 64) != 0);
assert(memcmp(output, output + 128, 64) != 0);
assert(memcmp(output + 64, output + 128, 64) != 0);
memset(output + 192, 0, 64);
crypto_stream_xsalsa20_xor_ic(output, output, 64, nonce,
0ULL, firstkey);
assert(memcmp(output + 192, output, 64) != 0);
assert(memcmp(output + 192, output + 64, 64) != 0);
assert(memcmp(output + 192, output + 128, 64) != 0);
memset(output, 0, 64);
crypto_stream_xsalsa20_xor_ic(output, output, 128, nonce,
1ULL << 32, firstkey);
assert(memcmp(output, output + 192, 64) != 0);
assert(memcmp(output, output + 128, 64) != 0);
assert(memcmp(output, output + 64, 64) != 0);
assert(memcmp(output + 64, output + 192, 64) != 0);
assert(memcmp(output + 128, output + 192, 64) != 0);
for (i = -16; i < 0; i++) {
memset(output, 0, 17 * 64);
crypto_stream_xsalsa20_xor_ic(output, output, 17 * 64, nonce,
(1ULL << 32) + (unsigned long long) i,
firstkey);
sodium_bin2hex(hex, 2 * 17 * 64 + 1, output, 17 * 64);
printf("%s\n", hex);
}
assert(crypto_stream_keybytes() > 0U);
assert(crypto_stream_noncebytes() > 0U);