1
0

onetimeauth7.c 886 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "crypto_onetimeauth_poly1305.h"
  4. #include "randombytes.h"
  5. unsigned char key[32];
  6. unsigned char c[10000];
  7. unsigned char a[16];
  8. int main()
  9. {
  10. int clen;
  11. int i;
  12. for (clen = 0;clen < 10000;++clen) {
  13. randombytes(key,sizeof key);
  14. randombytes(c,clen);
  15. crypto_onetimeauth_poly1305(a,c,clen,key);
  16. if (crypto_onetimeauth_poly1305_verify(a,c,clen,key) != 0) {
  17. printf("fail %d\n",clen);
  18. return 100;
  19. }
  20. if (clen > 0) {
  21. c[random() % clen] += 1 + (random() % 255);
  22. if (crypto_onetimeauth_poly1305_verify(a,c,clen,key) == 0) {
  23. printf("forgery %d\n",clen);
  24. return 100;
  25. }
  26. a[random() % sizeof a] += 1 + (random() % 255);
  27. if (crypto_onetimeauth_poly1305_verify(a,c,clen,key) == 0) {
  28. printf("forgery %d\n",clen);
  29. return 100;
  30. }
  31. }
  32. }
  33. return 0;
  34. }