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.

39 lines
1.2 KiB

  1. #define TEST_NAME "box7"
  2. #include "cmptest.h"
  3. unsigned char alicesk[crypto_box_SECRETKEYBYTES];
  4. unsigned char alicepk[crypto_box_PUBLICKEYBYTES];
  5. unsigned char bobsk[crypto_box_SECRETKEYBYTES];
  6. unsigned char bobpk[crypto_box_PUBLICKEYBYTES];
  7. unsigned char n[crypto_box_NONCEBYTES];
  8. unsigned char m[10000];
  9. unsigned char c[10000];
  10. unsigned char m2[10000];
  11. int main(void)
  12. {
  13. size_t mlen;
  14. size_t i;
  15. for (mlen = 0; mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;
  16. ++mlen) {
  17. crypto_box_keypair(alicepk, alicesk);
  18. crypto_box_keypair(bobpk, bobsk);
  19. randombytes_buf(n, crypto_box_NONCEBYTES);
  20. randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
  21. crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
  22. if (crypto_box_open(m2, c, mlen + crypto_box_ZEROBYTES, n, alicepk,
  23. bobsk) == 0) {
  24. for (i = 0; i < mlen + crypto_box_ZEROBYTES; ++i) {
  25. if (m2[i] != m[i]) {
  26. printf("bad decryption\n");
  27. break;
  28. }
  29. }
  30. } else {
  31. printf("ciphertext fails verification\n");
  32. }
  33. }
  34. return 0;
  35. }