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.

46 lines
1.4 KiB

  1. #include "windows/windows-quirks.h"
  2. #define TEST_NAME "box8"
  3. #include "cmptest.h"
  4. unsigned char alicesk[crypto_box_SECRETKEYBYTES];
  5. unsigned char alicepk[crypto_box_PUBLICKEYBYTES];
  6. unsigned char bobsk[crypto_box_SECRETKEYBYTES];
  7. unsigned char bobpk[crypto_box_PUBLICKEYBYTES];
  8. unsigned char n[crypto_box_NONCEBYTES];
  9. unsigned char m[10000];
  10. unsigned char c[10000];
  11. unsigned char m2[10000];
  12. int main(void)
  13. {
  14. size_t mlen;
  15. size_t i;
  16. int caught;
  17. for (mlen = 0; mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;
  18. ++mlen) {
  19. crypto_box_keypair(alicepk, alicesk);
  20. crypto_box_keypair(bobpk, bobsk);
  21. randombytes_buf(n, crypto_box_NONCEBYTES);
  22. randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
  23. crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
  24. caught = 0;
  25. while (caught < 10) {
  26. c[rand() % (mlen + crypto_box_ZEROBYTES)] = rand();
  27. if (crypto_box_open(m2, c, mlen + crypto_box_ZEROBYTES, n, alicepk,
  28. bobsk) == 0) {
  29. for (i = 0; i < mlen + crypto_box_ZEROBYTES; ++i) {
  30. if (m2[i] != m[i]) {
  31. printf("forgery\n");
  32. return 100;
  33. }
  34. }
  35. } else {
  36. ++caught;
  37. }
  38. }
  39. }
  40. return 0;
  41. }