tomcrypt_test.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef __TEST_H_
  2. #define __TEST_H_
  3. #include <tomcrypt.h>
  4. #ifdef USE_LTM
  5. /* Use libtommath as MPI provider */
  6. #elif defined(USE_TFM)
  7. /* Use tomsfastmath as MPI provider */
  8. #elif defined(USE_GMP)
  9. /* Use GNU Multiple Precision Arithmetic Library as MPI provider */
  10. #else
  11. /* The user must define his own MPI provider! */
  12. #ifndef EXT_MATH_LIB
  13. /*
  14. * Yes, you're right, you could also name your instance of the MPI provider
  15. * "EXT_MATH_LIB" and you wouldn't need to define it, but most users won't do
  16. * this and so it's treated as an error and you have to comment out the
  17. * following statement :)
  18. */
  19. #error EXT_MATH_LIB is required to be defined
  20. #endif
  21. #endif
  22. /* enable stack testing */
  23. /* #define STACK_TEST */
  24. /* stack testing, define this if stack usage goes downwards [e.g. x86] */
  25. #define STACK_DOWN
  26. typedef struct {
  27. char *name, *prov, *req;
  28. int (*entry)(void);
  29. } test_entry;
  30. extern prng_state yarrow_prng;
  31. void run_cmd(int res, int line, char *file, char *cmd, const char *algorithm);
  32. #ifdef LTC_VERBOSE
  33. #define DO(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0)
  34. #define DOX(x, str) do { fprintf(stderr, "%s - %s:\n", #x, (str)); run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0)
  35. #else
  36. #define DO(x) do { run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0)
  37. #define DOX(x, str) do { run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0)
  38. #endif
  39. /* TESTS */
  40. int cipher_hash_test(void);
  41. int modes_test(void);
  42. int mac_test(void);
  43. int pkcs_1_test(void);
  44. int pkcs_1_pss_test(void);
  45. int pkcs_1_oaep_test(void);
  46. int pkcs_1_emsa_test(void);
  47. int pkcs_1_eme_test(void);
  48. int store_test(void);
  49. int rsa_test(void);
  50. int dh_test(void);
  51. int katja_test(void);
  52. int ecc_tests(void);
  53. int dsa_test(void);
  54. int der_tests(void);
  55. int misc_test(void);
  56. int base64_test(void);
  57. /* timing */
  58. #define KTIMES 25
  59. #define TIMES 100000
  60. extern struct list {
  61. int id;
  62. unsigned long spd1, spd2, avg;
  63. } results[];
  64. extern int no_results;
  65. #ifdef LTC_PKCS_1
  66. extern const struct ltc_prng_descriptor no_prng_desc;
  67. #endif
  68. void print_hex(const char* what, const unsigned char* p, const unsigned long l);
  69. int sorter(const void *a, const void *b);
  70. void tally_results(int type);
  71. ulong64 rdtsc (void);
  72. void t_start(void);
  73. ulong64 t_read(void);
  74. void init_timer(void);
  75. /* register default algs */
  76. void reg_algs(void);
  77. int time_keysched(void);
  78. int time_cipher(void);
  79. int time_cipher2(void);
  80. int time_cipher3(void);
  81. int time_cipher4(void);
  82. int time_hash(void);
  83. void time_mult(void);
  84. void time_sqr(void);
  85. void time_prng(void);
  86. void time_rsa(void);
  87. void time_dsa(void);
  88. void time_katja(void);
  89. void time_ecc(void);
  90. void time_macs_(unsigned long MAC_SIZE);
  91. void time_macs(void);
  92. void time_encmacs(void);
  93. #if defined(_WIN32)
  94. #define PRI64 "I64d"
  95. #else
  96. #define PRI64 "ll"
  97. #endif
  98. #endif
  99. /* $Source$ */
  100. /* $Revision$ */
  101. /* $Date$ */