You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

  1. #include "windows/windows-quirks.h"
  2. #define TEST_NAME "secretbox8"
  3. #include "cmptest.h"
  4. unsigned char k[crypto_secretbox_KEYBYTES];
  5. unsigned char n[crypto_secretbox_NONCEBYTES];
  6. unsigned char m[10000];
  7. unsigned char c[10000];
  8. unsigned char m2[10000];
  9. int main(void)
  10. {
  11. size_t mlen;
  12. size_t i;
  13. int caught;
  14. for (mlen = 0; mlen < 1000 && mlen + crypto_secretbox_ZEROBYTES < sizeof m;
  15. ++mlen) {
  16. randombytes_buf(k, crypto_secretbox_KEYBYTES);
  17. randombytes_buf(n, crypto_secretbox_NONCEBYTES);
  18. randombytes_buf(m + crypto_secretbox_ZEROBYTES, mlen);
  19. crypto_secretbox(c, m, mlen + crypto_secretbox_ZEROBYTES, n, k);
  20. caught = 0;
  21. while (caught < 10) {
  22. c[rand() % (mlen + crypto_secretbox_ZEROBYTES)] = rand();
  23. if (crypto_secretbox_open(m2, c, mlen + crypto_secretbox_ZEROBYTES,
  24. n, k) == 0) {
  25. for (i = 0; i < mlen + crypto_secretbox_ZEROBYTES; ++i) {
  26. if (m2[i] != m[i]) {
  27. printf("forgery\n");
  28. return 100;
  29. }
  30. }
  31. } else {
  32. ++caught;
  33. }
  34. }
  35. }
  36. return 0;
  37. }