More checks for sodium_add() (overlaps) and sodium_increment()

This commit is contained in:
Frank Denis 2015-12-06 19:06:27 +01:00
parent a65484a7e5
commit ec6b86611f
2 changed files with 43 additions and 0 deletions

View File

@ -141,5 +141,42 @@ int main(void)
if (sodium_compare(buf1, buf2, bin_len) != 0) { if (sodium_compare(buf1, buf2, bin_len) != 0) {
printf("sodium_add() failed\n"); 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; return 0;
} }

View File

@ -16,3 +16,9 @@ dt5: 11
010100000000000000000000000000000000000000000000 010100000000000000000000000000000000000000000000
020000000000000000000000000000000000000000000000 020000000000000000000000000000000000000000000000
0001ff000000000000000000000000000000000000000000 0001ff000000000000000000000000000000000000000000
000000000000fffefefefefefefefefefefefefefefefefe
00000000000000000000fffefefefefefefefefefefefefe
00000000000000000000000000000000000000000000fffe
fcfffffffffffbfdfefefefefefefefefefefefefefefefe
fcfffffffffffffffffffbfdfefefefefefefefefefefefe
fcfffffffffffffffffffffffffffffffffffffffffffbfd