2013-04-26 01:37:15 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define TEST_NAME "sodium_utils"
|
|
|
|
#include "cmptest.h"
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2013-04-27 00:51:59 -04:00
|
|
|
unsigned char buf1[1000];
|
|
|
|
unsigned char buf2[1000];
|
2013-07-08 02:38:14 -04:00
|
|
|
char buf3[33];
|
2014-04-15 03:39:14 -04:00
|
|
|
unsigned char buf4[4];
|
|
|
|
const char *hex;
|
|
|
|
size_t bin_len;
|
2013-04-26 01:37:15 -04:00
|
|
|
|
|
|
|
randombytes(buf1, sizeof buf1);
|
|
|
|
memcpy(buf2, buf1, sizeof buf2);
|
2013-07-08 02:38:14 -04:00
|
|
|
printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
|
2013-04-26 01:37:15 -04:00
|
|
|
sodium_memzero(buf1, 0U);
|
2013-07-08 02:38:14 -04:00
|
|
|
printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
|
2013-04-26 01:37:15 -04:00
|
|
|
sodium_memzero(buf1, sizeof buf1 / 2);
|
2013-07-08 02:38:14 -04:00
|
|
|
printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
|
|
|
|
printf("%d\n", sodium_memcmp(buf1, buf2, 0U));
|
2013-04-26 01:37:15 -04:00
|
|
|
sodium_memzero(buf2, sizeof buf2 / 2);
|
2013-07-08 02:38:14 -04:00
|
|
|
printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
|
|
|
|
printf("%s\n", sodium_bin2hex(buf3, 33U,
|
|
|
|
(const unsigned char *)
|
|
|
|
"0123456789ABCDEF", 16U));
|
2014-04-15 03:39:14 -04:00
|
|
|
hex = "Cafe : 6942";
|
|
|
|
sodium_hex2bin(buf4, sizeof buf4, hex, strlen(hex), ": ", &bin_len, NULL);
|
|
|
|
printf("%zu:%02x%02x%02x%02x\n", bin_len,
|
|
|
|
buf4[0], buf4[1], buf4[2], buf4[3]);
|
|
|
|
|
2013-04-26 01:37:15 -04:00
|
|
|
return 0;
|
|
|
|
}
|