stream2.c (1622B)
1 2 #define TEST_NAME "stream2" 3 #include "cmptest.h" 4 5 static const unsigned char secondkey[32] = { 6 0xdc, 0x90, 0x8d, 0xda, 0x0b, 0x93, 0x44, 7 0xa9, 0x53, 0x62, 0x9b, 0x73, 0x38, 0x20, 8 0x77, 0x88, 0x80, 0xf3, 0xce, 0xb4, 0x21, 9 0xbb, 0x61, 0xb9, 0x1c, 0xbd, 0x4c, 0x3e, 10 0x66, 0x25, 0x6c, 0xe4 11 }; 12 13 static const unsigned char noncesuffix[8] = { 14 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 15 }; 16 17 18 19 int 20 main(void) 21 { 22 unsigned char *output; 23 char *hex; 24 unsigned char h[32]; 25 size_t sizeof_hex = 32 * 2 + 1; 26 size_t sizeof_output = 4194304; 27 int i; 28 29 output = (unsigned char *) sodium_malloc(sizeof_output); 30 hex = (char *) sodium_malloc(sizeof_hex); 31 32 crypto_stream_salsa20(output, sizeof_output, noncesuffix, secondkey); 33 crypto_hash_sha256(h, output, sizeof_output); 34 sodium_bin2hex(hex, sizeof_hex, h, sizeof h); 35 printf("%s\n", hex); 36 37 assert(sizeof_output > 4000); 38 39 crypto_stream_salsa20_xor_ic(output, output, 4000, noncesuffix, 0U, 40 secondkey); 41 for (i = 0; i < 4000; i++) { 42 assert(output[i] == 0); 43 } 44 45 crypto_stream_salsa20_xor_ic(output, output, 4000, noncesuffix, 1U, 46 secondkey); 47 crypto_hash_sha256(h, output, sizeof_output); 48 sodium_bin2hex(hex, sizeof_hex, h, sizeof h); 49 printf("%s\n", hex); 50 51 sodium_free(hex); 52 sodium_free(output); 53 54 assert(crypto_stream_salsa20_keybytes() > 0U); 55 assert(crypto_stream_salsa20_noncebytes() > 0U); 56 assert(crypto_stream_salsa20_messagebytes_max() > 0U); 57 58 return 0; 59 }