1 1.1 riastrad 2 1.1 riastrad #define TEST_NAME "stream" 3 1.1 riastrad #include "cmptest.h" 4 1.1 riastrad 5 1.1 riastrad static unsigned char firstkey[32] = { 0x1b, 0x27, 0x55, 0x64, 0x73, 0xe9, 0x85, 6 1.1 riastrad 0xd4, 0x62, 0xcd, 0x51, 0x19, 0x7a, 0x9a, 7 1.1 riastrad 0x46, 0xc7, 0x60, 0x09, 0x54, 0x9e, 0xac, 8 1.1 riastrad 0x64, 0x74, 0xf2, 0x06, 0xc4, 0xee, 0x08, 9 1.1 riastrad 0x44, 0xf6, 0x83, 0x89 }; 10 1.1 riastrad 11 1.1 riastrad static unsigned char nonce[24] = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 12 1.1 riastrad 0x2b, 0x73, 0xcd, 0x62, 0xbd, 0xa8, 13 1.1 riastrad 0x75, 0xfc, 0x73, 0xd6, 0x82, 0x19, 14 1.1 riastrad 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 }; 15 1.1 riastrad 16 1.1 riastrad static unsigned char output[4194304]; 17 1.1 riastrad 18 1.1 riastrad static unsigned char h[32]; 19 1.1 riastrad static char hex[2 * 192 + 1]; 20 1.1 riastrad 21 1.1 riastrad int 22 1.1 riastrad main(void) 23 1.1 riastrad { 24 1.1 riastrad int i; 25 1.1 riastrad 26 1.1 riastrad randombytes_buf(output, sizeof output); 27 1.1 riastrad crypto_stream(output, sizeof output, nonce, firstkey); 28 1.1 riastrad crypto_hash_sha256(h, output, sizeof output); 29 1.1 riastrad sodium_bin2hex(hex, sizeof hex, h, sizeof h); 30 1.1 riastrad printf("%s\n", hex); 31 1.1 riastrad 32 1.1 riastrad assert(sizeof output > 4000); 33 1.1 riastrad 34 1.1 riastrad crypto_stream_xsalsa20_xor_ic(output, output, 4000, nonce, 0U, firstkey); 35 1.1 riastrad for (i = 0; i < 4000; i++) { 36 1.1 riastrad assert(output[i] == 0); 37 1.1 riastrad } 38 1.1 riastrad crypto_stream_xsalsa20_xor_ic(output, output, 4000, nonce, 1U, firstkey); 39 1.1 riastrad crypto_hash_sha256(h, output, sizeof output); 40 1.1 riastrad sodium_bin2hex(hex, sizeof hex, h, sizeof h); 41 1.1 riastrad printf("%s\n", hex); 42 1.1 riastrad 43 1.1 riastrad for (i = 0; i < 64; i++) { 44 1.1 riastrad memset(output, i, 64); 45 1.1 riastrad crypto_stream(output, (int) (i & 0xff), nonce, firstkey); 46 1.1 riastrad sodium_bin2hex(hex, sizeof hex, output, 64); 47 1.1 riastrad printf("%s\n", hex); 48 1.1 riastrad } 49 1.1 riastrad 50 1.1 riastrad memset(output, 0, 192); 51 1.1 riastrad crypto_stream_xsalsa20_xor_ic(output, output, 192, nonce, 52 1.1 riastrad (1ULL << 32) - 1ULL, firstkey); 53 1.1 riastrad sodium_bin2hex(hex, 192 * 2 + 1, output, 192); 54 1.1 riastrad printf("%s\n", hex); 55 1.1 riastrad 56 1.1 riastrad assert(crypto_stream_keybytes() > 0U); 57 1.1 riastrad assert(crypto_stream_noncebytes() > 0U); 58 1.1 riastrad assert(crypto_stream_messagebytes_max() > 0U); 59 1.1 riastrad assert(strcmp(crypto_stream_primitive(), "xsalsa20") == 0); 60 1.1 riastrad assert(crypto_stream_keybytes() == crypto_stream_xsalsa20_keybytes()); 61 1.1 riastrad assert(crypto_stream_noncebytes() == crypto_stream_xsalsa20_noncebytes()); 62 1.1 riastrad assert(crypto_stream_messagebytes_max() == crypto_stream_xsalsa20_messagebytes_max()); 63 1.1 riastrad 64 1.1 riastrad return 0; 65 1.1 riastrad } 66