TestPRF.java 993 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package crypto;
  2. import java.math.BigInteger;
  3. public class TestPRF {
  4. public static void main(String[] args) {
  5. try {
  6. for (int l = 1; l < 5000; l++) {
  7. System.out.println("Round: l=" + l);
  8. PRF f1 = new PRF(l);
  9. PRF f2 = new PRF(l);
  10. byte[] k = new byte[16];
  11. Crypto.sr.nextBytes(k);
  12. byte[] input = new byte[Crypto.sr.nextInt(12) + 1];
  13. Crypto.sr.nextBytes(input);
  14. f1.init(k);
  15. f2.init(k);
  16. byte[] output1 = f1.compute(input);
  17. byte[] output2 = f2.compute(input);
  18. for (int i = 0; i < output2.length; i++)
  19. System.out.print(String.format("%02X", output2[i]));
  20. System.out.println("");
  21. boolean test1 = new BigInteger(1, output1).compareTo(new BigInteger(1, output2)) == 0;
  22. boolean test2 = output1.length == (l + 7) / 8;
  23. if (!test1 || !test2) {
  24. System.out.println("Fail: l=" + l + " " + test1 + " " + test2);
  25. break;
  26. }
  27. }
  28. System.out.println("done");
  29. } catch (Exception e) {
  30. e.printStackTrace();
  31. }
  32. }
  33. }