cipher_hash_test.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* test the ciphers and hashes using their built-in self-tests */
  2. #include <tomcrypt_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((unsigned char *)"helloworld12", 12, &nprng));
  22. DO(prng_descriptor[x].ready(&nprng));
  23. n = sizeof(buf);
  24. DO(prng_descriptor[x].pexport(buf, &n, &nprng));
  25. prng_descriptor[x].done(&nprng);
  26. DO(prng_descriptor[x].pimport(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. }
  36. /* $Source$ */
  37. /* $Revision$ */
  38. /* $Date$ */