2020-06-17 10:15:27 +02:00
|
|
|
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
|
|
|
|
/* SPDX-License-Identifier: Unlicense */
|
2017-05-05 13:52:39 +02:00
|
|
|
#ifndef DEMOS_COMMON_H_
|
|
|
|
|
#define DEMOS_COMMON_H_
|
|
|
|
|
|
|
|
|
|
#include <tomcrypt.h>
|
|
|
|
|
|
|
|
|
|
extern prng_state yarrow_prng;
|
2022-01-16 12:39:55 +01:00
|
|
|
#if defined(LTC_MDSA)
|
|
|
|
|
extern const unsigned char ltc_dsa_private_test_key[];
|
|
|
|
|
extern const unsigned long ltc_dsa_private_test_key_sz;
|
|
|
|
|
int dsa_key_cmp(const int should_type, const dsa_key *should, const dsa_key *is);
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(LTC_MRSA)
|
|
|
|
|
extern const unsigned char ltc_rsa_private_test_key[];
|
|
|
|
|
extern const unsigned long ltc_rsa_private_test_key_sz;
|
|
|
|
|
int rsa_key_cmp(const int should_type, const rsa_key *should, const rsa_key *is);
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(LTC_MECC)
|
|
|
|
|
extern const unsigned char ltc_ecc_long_pri_test_key[];
|
|
|
|
|
extern const unsigned long ltc_ecc_long_pri_test_key_sz;
|
|
|
|
|
int ecc_key_cmp(const int should_type, const ecc_key *should, const ecc_key *is);
|
|
|
|
|
#endif
|
2017-05-05 13:52:39 +02:00
|
|
|
|
2017-05-24 21:06:40 +02:00
|
|
|
#ifdef LTC_VERBOSE
|
|
|
|
|
#define DO(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0)
|
|
|
|
|
#define DOX(x, str) do { fprintf(stderr, "%s - %s:\n", #x, (str)); run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0)
|
2018-04-10 04:38:58 +02:00
|
|
|
#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)
|
2019-10-14 12:42:59 +02:00
|
|
|
#define SHOULD_FAIL_WITH(x, e) do { fprintf(stderr, "%s:\n", #x); run_cmd((x) == (e) ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, NULL); } while (0)
|
2019-09-27 14:58:05 +02:00
|
|
|
#define ENSURE(x) do { fprintf(stderr, "%s:\n", #x); run_cmd(((x)) ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, NULL); } while (0)
|
2020-03-27 10:54:03 +01:00
|
|
|
#define ENSUREX(x, str) do { fprintf(stderr, "%s:\n", #x); run_cmd(((x)) ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, (str)); } while (0)
|
2017-05-24 21:06:40 +02:00
|
|
|
#else
|
|
|
|
|
#define DO(x) do { run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0)
|
|
|
|
|
#define DOX(x, str) do { run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0)
|
2018-04-10 04:38:58 +02:00
|
|
|
#define SHOULD_FAIL(x) do { run_cmd((x) != CRYPT_OK ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, NULL); } while (0)
|
2019-10-14 12:42:59 +02:00
|
|
|
#define SHOULD_FAIL_WITH(x, e) do { run_cmd((x) == (e) ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, NULL); } while (0)
|
2019-09-27 14:58:05 +02:00
|
|
|
#define ENSURE(x) do { run_cmd(((x)) ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, NULL); } while (0)
|
2020-03-27 10:54:03 +01:00
|
|
|
#define ENSUREX(x, str) do { run_cmd(((x)) ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, (str)); } while (0)
|
2017-05-24 21:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
2025-11-24 12:43:38 +01:00
|
|
|
#define COMPARE_TESTVECTOR(i, il, s, sl, wa, wi) do { DO(ltc_do_compare_testvector((i), (il), (s), (sl), (wa), (wi))); } while(0)
|
2018-05-09 23:50:44 +02:00
|
|
|
|
2022-01-16 16:21:44 +01:00
|
|
|
#if !((defined(_WIN32) || defined(_WIN32_WCE)) && !defined(__GNUC__)) && !defined(LTC_NO_FILE)
|
2018-05-09 23:50:44 +02:00
|
|
|
#define LTC_TEST_READDIR
|
|
|
|
|
|
|
|
|
|
typedef int (*dir_iter_cb)(const void *d, unsigned long l, void* ctx);
|
2022-01-16 16:21:44 +01:00
|
|
|
typedef int (*dir_fiter_cb)(FILE *f, void* ctx);
|
2018-05-09 23:50:44 +02:00
|
|
|
typedef void (*dir_cleanup_cb)(void* ctx);
|
|
|
|
|
|
2022-01-16 16:21:44 +01:00
|
|
|
int test_process_dir(const char *path, void *ctx, dir_iter_cb iter, dir_fiter_cb fiter, dir_cleanup_cb cleanup, const char *test);
|
2018-05-09 23:50:44 +02:00
|
|
|
#endif
|
|
|
|
|
|
2026-04-24 13:37:01 +02:00
|
|
|
int ltc_test_nop(void);
|
2026-05-03 19:12:00 +02:00
|
|
|
int nop_test(void);
|
2026-04-24 13:37:01 +02:00
|
|
|
#define LTC_NOP_TEST(n) int n(void) { return CRYPT_NOP; }
|
|
|
|
|
|
2017-09-18 09:24:19 +02:00
|
|
|
void run_cmd(int res, int line, const char *file, const char *cmd, const char *algorithm);
|
2017-05-24 21:06:40 +02:00
|
|
|
|
2017-05-05 13:52:39 +02:00
|
|
|
void print_hex(const char* what, const void* v, const unsigned long l);
|
|
|
|
|
|
|
|
|
|
#endif /* DEMOS_COMMON_H_ */
|