cipher_hash_test.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* test the ciphers and hashes using their built-in self-tests */
  2. #include "test.h"
  3. int cipher_hash_test(void)
  4. {
  5. int x;
  6. unsigned char buf[4096];
  7. unsigned long n;
  8. prng_state nprng;
  9. /* test ciphers */
  10. for (x = 0; cipher_descriptor[x].name != NULL; x++) {
  11. DO(cipher_descriptor[x].test());
  12. }
  13. /* test hashes */
  14. for (x = 0; hash_descriptor[x].name != NULL; x++) {
  15. DO(hash_descriptor[x].test());
  16. }
  17. /* test prngs (test, import/export */
  18. for (x = 0; prng_descriptor[x].name != NULL; x++) {
  19. DO(prng_descriptor[x].test());
  20. DO(prng_descriptor[x].start(&nprng));
  21. DO(prng_descriptor[x].add_entropy("helloworld12", 12, &nprng));
  22. DO(prng_descriptor[x].ready(&nprng));
  23. n = sizeof(buf);
  24. DO(prng_descriptor[x].export(buf, &n, &nprng));
  25. prng_descriptor[x].done(&nprng);
  26. DO(prng_descriptor[x].import(buf, n, &nprng));
  27. DO(prng_descriptor[x].ready(&nprng));
  28. if (prng_descriptor[x].read(buf, 100, &nprng) != 100) {
  29. fprintf(stderr, "Error reading from imported PRNG!\n");
  30. exit(EXIT_FAILURE);
  31. }
  32. prng_descriptor[x].done(&nprng);
  33. }
  34. return 0;
  35. }