xref: /freebsd/sys/contrib/libsodium/test/default/stream2.c (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 
2 #define TEST_NAME "stream2"
3 #include "cmptest.h"
4 
5 static unsigned char secondkey[32] = { 0xdc, 0x90, 0x8d, 0xda, 0x0b, 0x93, 0x44,
6                                        0xa9, 0x53, 0x62, 0x9b, 0x73, 0x38, 0x20,
7                                        0x77, 0x88, 0x80, 0xf3, 0xce, 0xb4, 0x21,
8                                        0xbb, 0x61, 0xb9, 0x1c, 0xbd, 0x4c, 0x3e,
9                                        0x66, 0x25, 0x6c, 0xe4 };
10 
11 static unsigned char noncesuffix[8] = { 0x82, 0x19, 0xe0, 0x03,
12                                         0x6b, 0x7a, 0x0b, 0x37 };
13 
14 static unsigned char output[4194304];
15 
16 static unsigned char h[32];
17 
18 int
19 main(void)
20 {
21     int i;
22     crypto_stream_salsa20(output, sizeof output, noncesuffix, secondkey);
23     crypto_hash_sha256(h, output, sizeof output);
24     for (i = 0; i < 32; ++i)
25         printf("%02x", h[i]);
26     printf("\n");
27 
28     assert(sizeof output > 4000);
29 
30     crypto_stream_salsa20_xor_ic(output, output, 4000, noncesuffix, 0U,
31                                  secondkey);
32     for (i = 0; i < 4000; ++i)
33         assert(output[i] == 0);
34 
35     crypto_stream_salsa20_xor_ic(output, output, 4000, noncesuffix, 1U,
36                                  secondkey);
37     crypto_hash_sha256(h, output, sizeof output);
38     for (i = 0; i < 32; ++i)
39         printf("%02x", h[i]);
40     printf("\n");
41 
42     assert(crypto_stream_salsa20_keybytes() > 0U);
43     assert(crypto_stream_salsa20_noncebytes() > 0U);
44     assert(crypto_stream_salsa20_messagebytes_max() > 0U);
45 
46     return 0;
47 }
48