vendor/libsodium/test/default/sodium_utils.c in rbnacl-libsodium-1.0.6 vs vendor/libsodium/test/default/sodium_utils.c in rbnacl-libsodium-1.0.7
- old
+ new
@@ -1,10 +1,11 @@
#define TEST_NAME "sodium_utils"
#include "cmptest.h"
int main(void)
{
+ unsigned char buf_add[1000];
unsigned char buf1[1000];
unsigned char buf2[1000];
unsigned char buf1_rev[1000];
unsigned char buf2_rev[1000];
char buf3[33];
@@ -103,7 +104,79 @@
if (sodium_compare(buf1, buf2, bin_len)) {
printf("sodium_compare() equality failure with length=%u\n",
(unsigned int) bin_len);
}
}
+ memset(buf1, 0, sizeof buf1);
+ if (sodium_is_zero(buf1, sizeof buf1) != 1) {
+ printf("sodium_is_zero() failed\n");
+ }
+ for (i = 0U; i < sizeof buf1; i++) {
+ buf1[i]++;
+ if (sodium_is_zero(buf1, sizeof buf1) != 0) {
+ printf("sodium_is_zero() failed\n");
+ }
+ buf1[i]--;
+ }
+ bin_len = randombytes_uniform(sizeof buf1);
+ randombytes_buf(buf1, bin_len);
+ memcpy(buf2, buf1, bin_len);
+ memset(buf_add, 0, bin_len);
+ j = randombytes_uniform(10000);
+ for (i = 0U; i < j; i++) {
+ sodium_increment(buf1, bin_len);
+ sodium_increment(buf_add, bin_len);
+ }
+ sodium_add(buf2, buf_add, bin_len);
+ if (sodium_compare(buf1, buf2, bin_len) != 0) {
+ printf("sodium_add() failed\n");
+ }
+ bin_len = randombytes_uniform(sizeof buf1);
+ randombytes_buf(buf1, bin_len);
+ memcpy(buf2, buf1, bin_len);
+ memset(buf_add, 0xff, bin_len);
+ sodium_increment(buf2, bin_len);
+ sodium_increment(buf2, 0U);
+ sodium_add(buf2, buf_add, bin_len);
+ sodium_add(buf2, buf_add, 0U);
+ 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;
}