common.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* LibTomCrypt, modular cryptographic library -- Tom St Denis
  2. *
  3. * LibTomCrypt is a library that provides various cryptographic
  4. * algorithms in a highly modular and flexible manner.
  5. *
  6. * The library is free for all purposes without any express
  7. * guarantee it works.
  8. */
  9. #ifndef DEMOS_COMMON_H_
  10. #define DEMOS_COMMON_H_
  11. #include <tomcrypt.h>
  12. extern prng_state yarrow_prng;
  13. #ifdef LTC_VERBOSE
  14. #define DO(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0)
  15. #define DOX(x, str) do { fprintf(stderr, "%s - %s:\n", #x, (str)); run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0)
  16. #define SHOULD_FAIL(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x) != CRYPT_OK ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, NULL); } while (0)
  17. #else
  18. #define DO(x) do { run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0)
  19. #define DOX(x, str) do { run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0)
  20. #define SHOULD_FAIL(x) do { run_cmd((x) != CRYPT_OK ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, NULL); } while (0)
  21. #endif
  22. #define COMPARE_TESTVECTOR(i, il, s, sl, wa, wi) do { DO(do_compare_testvector((i), (il), (s), (sl), (wa), (wi))); } while(0)
  23. #if !((defined(_WIN32) || defined(_WIN32_WCE)) && !defined(__GNUC__))
  24. #define LTC_TEST_READDIR
  25. typedef int (*dir_iter_cb)(const void *d, unsigned long l, void* ctx);
  26. typedef void (*dir_cleanup_cb)(void* ctx);
  27. int test_process_dir(const char *path, void *ctx, dir_iter_cb iter, dir_cleanup_cb cleanup, const char *test);
  28. #endif
  29. void run_cmd(int res, int line, const char *file, const char *cmd, const char *algorithm);
  30. void print_hex(const char* what, const void* v, const unsigned long l);
  31. int do_compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which);
  32. #endif /* DEMOS_COMMON_H_ */
  33. /* ref: $Format:%D$ */
  34. /* git commit: $Format:%H$ */
  35. /* commit time: $Format:%ai$ */