stream2.c 1.5 KB

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