2020-06-17 10:15:27 +02:00
|
|
|
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
|
|
|
|
/* SPDX-License-Identifier: Unlicense */
|
2005-04-17 11:37:13 +00:00
|
|
|
#include <tomcrypt_test.h>
|
|
|
|
|
|
2017-05-02 10:35:00 +02:00
|
|
|
#ifndef GIT_VERSION
|
|
|
|
|
#define GIT_VERSION "Undefined version"
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-05-11 11:34:54 +02:00
|
|
|
#define LTC_TEST_FN(f) { f ## _test, #f }
|
2017-03-01 15:00:04 +01:00
|
|
|
|
2017-05-11 14:49:57 +02:00
|
|
|
typedef struct {
|
2017-03-01 15:00:04 +01:00
|
|
|
int (*fn)(void);
|
|
|
|
|
const char* name;
|
2017-05-11 14:49:57 +02:00
|
|
|
} test_function;
|
|
|
|
|
|
|
|
|
|
static const test_function test_functions[] =
|
2017-03-01 15:00:04 +01:00
|
|
|
{
|
2026-05-11 11:34:54 +02:00
|
|
|
LTC_TEST_FN(store),
|
|
|
|
|
LTC_TEST_FN(rotate),
|
|
|
|
|
LTC_TEST_FN(cipher_hash),
|
|
|
|
|
LTC_TEST_FN(misc),
|
|
|
|
|
LTC_TEST_FN(mpi),
|
|
|
|
|
LTC_TEST_FN(mac),
|
|
|
|
|
LTC_TEST_FN(modes),
|
|
|
|
|
LTC_TEST_FN(der),
|
|
|
|
|
LTC_TEST_FN(pkcs_1),
|
|
|
|
|
LTC_TEST_FN(pkcs_1_pss),
|
|
|
|
|
LTC_TEST_FN(pkcs_1_oaep),
|
|
|
|
|
LTC_TEST_FN(pkcs_1_emsa),
|
|
|
|
|
LTC_TEST_FN(pkcs_1_eme),
|
|
|
|
|
LTC_TEST_FN(rsa),
|
|
|
|
|
LTC_TEST_FN(dh),
|
|
|
|
|
LTC_TEST_FN(ecc),
|
|
|
|
|
LTC_TEST_FN(dsa),
|
|
|
|
|
LTC_TEST_FN(ed25519),
|
|
|
|
|
LTC_TEST_FN(ed25519_mpi),
|
|
|
|
|
LTC_TEST_FN(x25519),
|
|
|
|
|
LTC_TEST_FN(x25519_mpi),
|
|
|
|
|
LTC_TEST_FN(ed448),
|
|
|
|
|
LTC_TEST_FN(ed448_mpi),
|
|
|
|
|
LTC_TEST_FN(x448),
|
|
|
|
|
LTC_TEST_FN(x448_mpi),
|
|
|
|
|
LTC_TEST_FN(file),
|
|
|
|
|
LTC_TEST_FN(multi),
|
|
|
|
|
LTC_TEST_FN(pem),
|
|
|
|
|
LTC_TEST_FN(deprecated),
|
|
|
|
|
LTC_TEST_FN(nop),
|
2017-06-09 13:34:26 +02:00
|
|
|
/* keep the prng_test always at the end as
|
|
|
|
|
* it has to be handled specially when
|
|
|
|
|
* testing with LTC_PTHREAD enabled
|
|
|
|
|
*/
|
2026-05-11 11:34:54 +02:00
|
|
|
LTC_TEST_FN(prng),
|
2017-03-01 15:00:04 +01:00
|
|
|
};
|
|
|
|
|
|
2017-05-11 14:49:57 +02:00
|
|
|
|
2017-05-24 21:16:43 +02:00
|
|
|
#if defined(_WIN32)
|
|
|
|
|
#include <windows.h> /* GetSystemTimeAsFileTime */
|
|
|
|
|
#else
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* microseconds since 1970 (UNIX epoch) */
|
|
|
|
|
static ulong64 epoch_usec(void)
|
|
|
|
|
{
|
|
|
|
|
#if defined(LTC_NO_TEST_TIMING)
|
|
|
|
|
return 0;
|
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
|
FILETIME CurrentTime;
|
|
|
|
|
ulong64 cur_time;
|
|
|
|
|
ULARGE_INTEGER ul;
|
|
|
|
|
GetSystemTimeAsFileTime(&CurrentTime);
|
|
|
|
|
ul.LowPart = CurrentTime.dwLowDateTime;
|
|
|
|
|
ul.HighPart = CurrentTime.dwHighDateTime;
|
2018-05-04 07:41:02 +02:00
|
|
|
cur_time = ul.QuadPart; /* now we have 100ns intervals since 1 January 1601 */
|
|
|
|
|
cur_time -= CONST64(116444736000000000); /* subtract 100ns intervals between 1601-1970 */
|
|
|
|
|
cur_time /= 10; /* 100ns intervals > microseconds */
|
2017-05-24 21:16:43 +02:00
|
|
|
return cur_time;
|
2018-05-04 07:41:02 +02:00
|
|
|
#elif defined(LTC_CLOCK_GETTIME)
|
2017-12-07 13:23:38 +01:00
|
|
|
struct timespec ts;
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
|
return (ulong64)(ts.tv_sec) * 1000000 + (ulong64)(ts.tv_nsec) / 1000; /* get microseconds */
|
2018-05-04 07:41:02 +02:00
|
|
|
#else
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
|
return (ulong64)(tv.tv_sec) * 1000000 + (ulong64)(tv.tv_usec); /* get microseconds */
|
2017-05-24 21:16:43 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 14:49:57 +02:00
|
|
|
#ifdef LTC_PTHREAD
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
pthread_t thread_id;
|
|
|
|
|
const test_function* t;
|
|
|
|
|
int err;
|
2017-06-09 13:34:26 +02:00
|
|
|
ulong64 delta;
|
2017-05-11 14:49:57 +02:00
|
|
|
} thread_info;
|
|
|
|
|
|
|
|
|
|
static void *run(void *arg)
|
|
|
|
|
{
|
|
|
|
|
thread_info *tinfo = arg;
|
|
|
|
|
ulong64 ts;
|
|
|
|
|
|
|
|
|
|
ts = epoch_usec();
|
|
|
|
|
tinfo->err = tinfo->t->fn();
|
2017-06-09 13:34:26 +02:00
|
|
|
tinfo->delta = epoch_usec() - ts;
|
2017-05-11 14:49:57 +02:00
|
|
|
|
|
|
|
|
return arg;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-06-08 11:51:36 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* unregister ciphers, hashes & prngs
|
|
|
|
|
*/
|
2020-07-14 19:02:48 +02:00
|
|
|
static void s_unregister_all(void)
|
2017-06-08 11:51:36 +02:00
|
|
|
{
|
|
|
|
|
#ifdef LTC_RIJNDAEL
|
2021-09-30 14:49:26 +02:00
|
|
|
/* `aesni_desc` is not registered, i.e. also shouldn't be unregistered */
|
2017-06-09 12:46:41 +02:00
|
|
|
#ifdef ENCRYPT_ONLY
|
|
|
|
|
/* alternative would be
|
|
|
|
|
* unregister_cipher(&rijndael_enc_desc);
|
|
|
|
|
*/
|
|
|
|
|
unregister_cipher(&aes_enc_desc);
|
|
|
|
|
#else
|
|
|
|
|
/* alternative would be
|
|
|
|
|
* unregister_cipher(&rijndael_desc);
|
|
|
|
|
*/
|
|
|
|
|
unregister_cipher(&aes_desc);
|
|
|
|
|
#endif
|
2017-06-08 11:51:36 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_BLOWFISH
|
|
|
|
|
unregister_cipher(&blowfish_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_XTEA
|
|
|
|
|
unregister_cipher(&xtea_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_RC5
|
|
|
|
|
unregister_cipher(&rc5_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_RC6
|
|
|
|
|
unregister_cipher(&rc6_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SAFERP
|
|
|
|
|
unregister_cipher(&saferp_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_TWOFISH
|
|
|
|
|
unregister_cipher(&twofish_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SAFER
|
|
|
|
|
unregister_cipher(&safer_k64_desc);
|
|
|
|
|
unregister_cipher(&safer_sk64_desc);
|
|
|
|
|
unregister_cipher(&safer_k128_desc);
|
|
|
|
|
unregister_cipher(&safer_sk128_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_RC2
|
|
|
|
|
unregister_cipher(&rc2_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_DES
|
|
|
|
|
unregister_cipher(&des_desc);
|
2024-02-28 22:26:39 +01:00
|
|
|
unregister_cipher(&desx_desc);
|
2017-06-08 11:51:36 +02:00
|
|
|
unregister_cipher(&des3_desc);
|
|
|
|
|
#endif
|
2018-10-25 16:33:29 +08:00
|
|
|
#ifdef LTC_SM4
|
|
|
|
|
unregister_cipher(&sm4_desc);
|
|
|
|
|
#endif
|
2017-06-08 11:51:36 +02:00
|
|
|
#ifdef LTC_CAST5
|
|
|
|
|
unregister_cipher(&cast5_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_NOEKEON
|
|
|
|
|
unregister_cipher(&noekeon_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SKIPJACK
|
|
|
|
|
unregister_cipher(&skipjack_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_KHAZAD
|
|
|
|
|
unregister_cipher(&khazad_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_ANUBIS
|
|
|
|
|
unregister_cipher(&anubis_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_KSEED
|
|
|
|
|
unregister_cipher(&kseed_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_KASUMI
|
|
|
|
|
unregister_cipher(&kasumi_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_MULTI2
|
|
|
|
|
unregister_cipher(&multi2_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_CAMELLIA
|
|
|
|
|
unregister_cipher(&camellia_desc);
|
|
|
|
|
#endif
|
2017-10-16 21:20:33 +02:00
|
|
|
#ifdef LTC_IDEA
|
|
|
|
|
unregister_cipher(&idea_desc);
|
|
|
|
|
#endif
|
2017-10-17 12:55:14 +02:00
|
|
|
#ifdef LTC_SERPENT
|
|
|
|
|
unregister_cipher(&serpent_desc);
|
|
|
|
|
#endif
|
2026-05-16 11:38:38 +02:00
|
|
|
#ifdef LTC_ARIA
|
|
|
|
|
unregister_cipher(&aria_desc);
|
|
|
|
|
#endif
|
2017-06-08 11:51:36 +02:00
|
|
|
|
|
|
|
|
#ifdef LTC_TIGER
|
2024-02-25 23:51:59 +01:00
|
|
|
unregister_hash(&tiger2_desc);
|
2017-06-08 11:51:36 +02:00
|
|
|
unregister_hash(&tiger_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_MD2
|
|
|
|
|
unregister_hash(&md2_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_MD4
|
|
|
|
|
unregister_hash(&md4_desc);
|
|
|
|
|
#endif
|
2026-04-19 23:31:06 +02:00
|
|
|
#ifdef LTC_SM3
|
|
|
|
|
unregister_hash(&sm3_desc);
|
|
|
|
|
#endif
|
2017-06-08 11:51:36 +02:00
|
|
|
#ifdef LTC_MD5
|
|
|
|
|
unregister_hash(&md5_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SHA1
|
2026-04-10 21:45:00 +02:00
|
|
|
/* `register_all_hashes()` does not register
|
|
|
|
|
* - `sha1_portable_desc`
|
|
|
|
|
* - `sha1_x86_desc`
|
|
|
|
|
* so we don't have to unregister them */
|
2017-06-08 11:51:36 +02:00
|
|
|
unregister_hash(&sha1_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SHA224
|
2026-04-13 17:04:54 +02:00
|
|
|
/* `register_all_hashes()` does not register
|
|
|
|
|
* - `sha224_portable_desc`
|
|
|
|
|
* - `sha224_x86_desc`
|
|
|
|
|
* so we don't have to unregister them */
|
2017-06-08 11:51:36 +02:00
|
|
|
unregister_hash(&sha224_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SHA256
|
2026-04-13 17:04:54 +02:00
|
|
|
/* `register_all_hashes()` does not register
|
|
|
|
|
* - `sha256_portable_desc`
|
|
|
|
|
* - `sha256_x86_desc`
|
|
|
|
|
* so we don't have to unregister them */
|
2017-06-08 11:51:36 +02:00
|
|
|
unregister_hash(&sha256_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SHA384
|
2026-08-01 10:50:04 +02:00
|
|
|
/* `register_all_hashes()` does not register `sha384_portable_desc` nor `sha384_x86_desc`, so we don't have to unregister them */
|
2017-06-08 11:51:36 +02:00
|
|
|
unregister_hash(&sha384_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SHA512
|
2026-08-01 10:50:04 +02:00
|
|
|
/* `register_all_hashes()` does not register `sha512_portable_desc` nor `sha512_x86_desc`, so we don't have to unregister them */
|
2017-06-08 11:51:36 +02:00
|
|
|
unregister_hash(&sha512_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SHA512_224
|
2026-08-01 10:50:04 +02:00
|
|
|
/* `register_all_hashes()` does not register `sha512_224_portable_desc` nor `sha512_224_x86_desc`, so we don't have to unregister them */
|
2017-06-08 11:51:36 +02:00
|
|
|
unregister_hash(&sha512_224_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SHA512_256
|
2026-08-01 10:50:04 +02:00
|
|
|
/* `register_all_hashes()` does not register `sha512_256_portable_desc` nor `sha512_256_x86_desc`, so we don't have to unregister them */
|
2017-06-08 11:51:36 +02:00
|
|
|
unregister_hash(&sha512_256_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SHA3
|
|
|
|
|
unregister_hash(&sha3_224_desc);
|
|
|
|
|
unregister_hash(&sha3_256_desc);
|
|
|
|
|
unregister_hash(&sha3_384_desc);
|
|
|
|
|
unregister_hash(&sha3_512_desc);
|
2026-05-03 17:04:58 +02:00
|
|
|
unregister_hash(&shake128_desc);
|
|
|
|
|
unregister_hash(&shake256_desc);
|
2017-06-08 11:51:36 +02:00
|
|
|
#endif
|
2018-03-07 14:55:10 +01:00
|
|
|
#ifdef LTC_KECCAK
|
2026-05-04 16:27:33 +02:00
|
|
|
unregister_hash(&keccak224_desc);
|
|
|
|
|
unregister_hash(&keccak256_desc);
|
|
|
|
|
unregister_hash(&keccak384_desc);
|
|
|
|
|
unregister_hash(&keccak512_desc);
|
2018-03-07 14:55:10 +01:00
|
|
|
#endif
|
2017-06-08 11:51:36 +02:00
|
|
|
#ifdef LTC_RIPEMD128
|
|
|
|
|
unregister_hash(&rmd128_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_RIPEMD160
|
|
|
|
|
unregister_hash(&rmd160_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_RIPEMD256
|
|
|
|
|
unregister_hash(&rmd256_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_RIPEMD320
|
|
|
|
|
unregister_hash(&rmd320_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_WHIRLPOOL
|
|
|
|
|
unregister_hash(&whirlpool_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_BLAKE2S
|
|
|
|
|
unregister_hash(&blake2s_128_desc);
|
|
|
|
|
unregister_hash(&blake2s_160_desc);
|
|
|
|
|
unregister_hash(&blake2s_224_desc);
|
|
|
|
|
unregister_hash(&blake2s_256_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_BLAKE2B
|
|
|
|
|
unregister_hash(&blake2b_160_desc);
|
|
|
|
|
unregister_hash(&blake2b_256_desc);
|
|
|
|
|
unregister_hash(&blake2b_384_desc);
|
|
|
|
|
unregister_hash(&blake2b_512_desc);
|
|
|
|
|
#endif
|
2026-08-02 09:23:43 +02:00
|
|
|
#ifdef LTC_BLAKE3
|
|
|
|
|
unregister_hash(&blake3_desc);
|
|
|
|
|
#endif
|
2017-06-08 11:51:36 +02:00
|
|
|
#ifdef LTC_CHC_HASH
|
|
|
|
|
unregister_hash(&chc_desc);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
unregister_prng(&yarrow_desc);
|
|
|
|
|
#ifdef LTC_FORTUNA
|
|
|
|
|
unregister_prng(&fortuna_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_RC4
|
|
|
|
|
unregister_prng(&rc4_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_CHACHA20_PRNG
|
|
|
|
|
unregister_prng(&chacha20_prng_desc);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_SOBER128
|
|
|
|
|
unregister_prng(&sober128_desc);
|
|
|
|
|
#endif
|
2017-06-09 12:46:41 +02:00
|
|
|
#ifdef LTC_SPRNG
|
|
|
|
|
unregister_prng(&sprng_desc);
|
|
|
|
|
#endif
|
2020-07-14 19:02:48 +02:00
|
|
|
} /* s_cleanup() */
|
2017-06-08 11:51:36 +02:00
|
|
|
|
|
|
|
|
static void register_algs(void)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2020-07-14 19:02:48 +02:00
|
|
|
atexit(s_unregister_all);
|
2017-06-08 11:51:36 +02:00
|
|
|
|
|
|
|
|
#ifndef LTC_YARROW
|
|
|
|
|
#error This demo requires Yarrow.
|
|
|
|
|
#endif
|
2017-10-18 22:35:16 +02:00
|
|
|
if ((err = register_all_ciphers()) != CRYPT_OK) {
|
|
|
|
|
fprintf(stderr, "register_all_ciphers err=%s\n", error_to_string(err));
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
if ((err = register_all_hashes()) != CRYPT_OK) {
|
|
|
|
|
fprintf(stderr, "register_all_hashes err=%s\n", error_to_string(err));
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
if ((err = register_all_prngs()) != CRYPT_OK) {
|
|
|
|
|
fprintf(stderr, "register_all_prngs err=%s\n", error_to_string(err));
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
2017-06-08 11:51:36 +02:00
|
|
|
|
|
|
|
|
if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) {
|
|
|
|
|
fprintf(stderr, "rng_make_prng failed: %s\n", error_to_string(err));
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp("CRYPT_OK", error_to_string(err))) {
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-11 11:34:54 +02:00
|
|
|
static void LTC_NORETURN die(int status)
|
|
|
|
|
{
|
|
|
|
|
FILE* o = status == EXIT_SUCCESS ? stdout : stderr;
|
|
|
|
|
fprintf(o,
|
|
|
|
|
"Usage: test [<-h|-l|case>] [mpi]\n\n"
|
|
|
|
|
"Run all built-in tests, or only the one given in <case>.\n\n"
|
|
|
|
|
"\tcase\tThe algorithms to test. Use the '-l' option to check for valid values.\n"
|
|
|
|
|
"\tmpi\tThe MPI provider to use.\n"
|
|
|
|
|
"\t-l\tList all tests that can be executed.\n"
|
|
|
|
|
"\t-h\tThe help you're looking at.\n\n"
|
|
|
|
|
"Examples:\n"
|
|
|
|
|
"\ttest rsa tfm\t\tWill run only the RSA tests with TomsFastMath as MPI provider.\n"
|
|
|
|
|
);
|
|
|
|
|
exit(status);
|
|
|
|
|
}
|
2017-06-08 11:51:36 +02:00
|
|
|
|
2017-03-29 20:52:30 +02:00
|
|
|
int main(int argc, char **argv)
|
2005-04-17 11:37:13 +00:00
|
|
|
{
|
2017-05-11 14:49:57 +02:00
|
|
|
#ifdef LTC_PTHREAD
|
|
|
|
|
thread_info *tinfo, *res;
|
|
|
|
|
#endif
|
2017-03-29 20:52:30 +02:00
|
|
|
int x, pass = 0, fail = 0, nop = 0;
|
2017-03-01 15:00:04 +01:00
|
|
|
size_t fn_len, i, dots;
|
2017-09-22 16:24:33 +02:00
|
|
|
const char* mpi_provider = NULL;
|
2017-03-29 20:52:30 +02:00
|
|
|
char *single_test = NULL;
|
2017-05-09 18:31:14 +02:00
|
|
|
ulong64 ts;
|
2017-05-11 14:49:57 +02:00
|
|
|
long delta, dur, real = 0;
|
2026-05-11 11:34:54 +02:00
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
if (strstr(argv[1], "-h")) {
|
|
|
|
|
die(EXIT_SUCCESS);
|
|
|
|
|
} else if (strstr(argv[1], "-l")) {
|
|
|
|
|
printf("The following tests are available:\n");
|
|
|
|
|
for (i = 0; i < LTC_ARRAY_SIZE(test_functions); ++i) {
|
|
|
|
|
if (i % 4 == 0)
|
|
|
|
|
putchar('\n');
|
|
|
|
|
printf(" %-13s", test_functions[i].name);
|
|
|
|
|
}
|
|
|
|
|
putchar('\n');
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-05 13:52:39 +02:00
|
|
|
register_algs();
|
2005-08-01 16:36:47 +00:00
|
|
|
|
2017-09-19 18:51:47 +02:00
|
|
|
printf("LTC_VERSION = %s\n%s\n\n", GIT_VERSION, crypt_build_settings);
|
2017-03-26 15:46:41 +02:00
|
|
|
|
2026-04-14 16:50:55 +02:00
|
|
|
printf("AES-NI CPU support = %d\n", aesni_is_supported());
|
2026-05-04 10:07:32 +02:00
|
|
|
printf("SHA-NI CPU support = %d\n", shani_is_supported());
|
2026-08-01 10:50:04 +02:00
|
|
|
printf("SHA512-NI CPU support = %d\n", sha512ni_is_supported());
|
2026-05-04 10:07:32 +02:00
|
|
|
printf("PMUL CPU support = %d\n", gcm_hw_pmul_is_supported());
|
|
|
|
|
putchar('\n');
|
2026-04-14 16:50:55 +02:00
|
|
|
|
2005-08-01 16:36:47 +00:00
|
|
|
#ifdef USE_LTM
|
2017-09-22 16:24:33 +02:00
|
|
|
mpi_provider = "ltm";
|
2005-08-01 16:36:47 +00:00
|
|
|
#elif defined(USE_TFM)
|
2017-09-22 16:24:33 +02:00
|
|
|
mpi_provider = "tfm";
|
2006-04-06 19:48:32 +00:00
|
|
|
#elif defined(USE_GMP)
|
2017-09-22 16:24:33 +02:00
|
|
|
mpi_provider = "gmp";
|
2017-08-07 21:11:42 +02:00
|
|
|
#elif defined(EXT_MATH_LIB)
|
2017-09-22 16:24:33 +02:00
|
|
|
mpi_provider = "ext";
|
|
|
|
|
#endif
|
2017-08-07 21:11:42 +02:00
|
|
|
|
2017-09-22 16:24:33 +02:00
|
|
|
if (argc > 2) {
|
|
|
|
|
mpi_provider = argv[2];
|
|
|
|
|
}
|
2017-08-07 21:11:42 +02:00
|
|
|
|
2017-10-12 10:20:43 +02:00
|
|
|
crypt_mp_init(mpi_provider);
|
2017-03-01 15:00:04 +01:00
|
|
|
|
2017-09-22 16:24:33 +02:00
|
|
|
if (ltc_mp.name != NULL) {
|
|
|
|
|
printf("MP_PROVIDER = %s\n", ltc_mp.name);
|
2022-08-05 16:52:17 +02:00
|
|
|
printf("MP_DIGIT_BIT = %d\n", LTC_MP_DIGIT_BIT);
|
2017-09-22 16:24:33 +02:00
|
|
|
printf("sizeof(ltc_mp_digit) = %d\n", (int)sizeof(ltc_mp_digit));
|
|
|
|
|
} else {
|
|
|
|
|
printf("NO math provider selected, all tests requiring MPI will 'nop'\n");
|
|
|
|
|
}
|
2017-05-11 14:49:57 +02:00
|
|
|
|
|
|
|
|
#ifdef LTC_PTHREAD
|
2025-09-05 10:49:28 +02:00
|
|
|
tinfo = XCALLOC(LTC_ARRAY_SIZE(test_functions), sizeof(thread_info));
|
2017-05-11 14:49:57 +02:00
|
|
|
if (tinfo == NULL) {
|
|
|
|
|
printf("\n\nFAILURE: XCALLOC\n");
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-03-01 15:00:04 +01:00
|
|
|
fn_len = 0;
|
2017-05-11 14:49:57 +02:00
|
|
|
for (i = 0; i < sizeof(test_functions) / sizeof(test_functions[0]); ++i) {
|
2019-10-03 15:18:25 +02:00
|
|
|
size_t len = XSTRLEN(test_functions[i].name);
|
2017-03-01 15:00:04 +01:00
|
|
|
if (fn_len < len) fn_len = len;
|
2017-05-11 14:49:57 +02:00
|
|
|
|
|
|
|
|
#ifdef LTC_PTHREAD
|
2017-06-09 13:34:26 +02:00
|
|
|
if(test_functions[i].fn == prng_test) continue;
|
2017-05-11 14:49:57 +02:00
|
|
|
tinfo[i].t = &test_functions[i];
|
|
|
|
|
x = pthread_create(&tinfo[i].thread_id, NULL, run, &tinfo[i]);
|
|
|
|
|
if (x != 0) {
|
|
|
|
|
printf("\n\nFAILURE: pthread_create\n");
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2017-03-01 15:00:04 +01:00
|
|
|
}
|
|
|
|
|
|
2026-05-11 11:34:54 +02:00
|
|
|
fn_len = fn_len + (8 - (fn_len % 8));
|
2017-03-01 15:00:04 +01:00
|
|
|
|
2017-03-29 20:52:30 +02:00
|
|
|
/* single test name from commandline */
|
|
|
|
|
if (argc > 1) single_test = argv[1];
|
|
|
|
|
|
2017-05-11 14:49:57 +02:00
|
|
|
dur = epoch_usec();
|
2025-09-05 10:49:28 +02:00
|
|
|
for (i = 0; i < LTC_ARRAY_SIZE(test_functions); ++i) {
|
2017-06-20 12:11:16 +02:00
|
|
|
if (single_test && strstr(test_functions[i].name, single_test) == NULL) {
|
2017-03-29 20:52:30 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2019-10-03 15:18:25 +02:00
|
|
|
dots = fn_len - XSTRLEN(test_functions[i].name);
|
2017-03-01 15:00:04 +01:00
|
|
|
|
|
|
|
|
printf("\n%s", test_functions[i].name);
|
|
|
|
|
while(dots--) printf(".");
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
2017-05-11 14:49:57 +02:00
|
|
|
#ifdef LTC_PTHREAD
|
2017-06-09 13:34:26 +02:00
|
|
|
if(test_functions[i].fn != prng_test) {
|
|
|
|
|
x = pthread_join(tinfo[i].thread_id, (void**)&res);
|
|
|
|
|
if (x != 0){
|
|
|
|
|
printf("\n\nFAILURE: pthread_join\n");
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
x = res->err;
|
|
|
|
|
delta = res->delta;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ts = epoch_usec();
|
|
|
|
|
x = test_functions[i].fn();
|
|
|
|
|
delta = (long)(epoch_usec() - ts);
|
2017-05-11 14:49:57 +02:00
|
|
|
}
|
|
|
|
|
#else
|
2017-03-29 20:52:30 +02:00
|
|
|
ts = epoch_usec();
|
2017-03-01 15:00:04 +01:00
|
|
|
x = test_functions[i].fn();
|
2017-05-09 18:31:14 +02:00
|
|
|
delta = (long)(epoch_usec() - ts);
|
2017-05-11 14:49:57 +02:00
|
|
|
#endif
|
2017-06-09 13:34:26 +02:00
|
|
|
real += delta;
|
2017-03-01 15:00:04 +01:00
|
|
|
|
2017-03-29 20:52:30 +02:00
|
|
|
if (x == CRYPT_OK) {
|
2017-05-09 18:31:14 +02:00
|
|
|
printf("passed %10.3fms", (double)(delta)/1000);
|
2017-03-29 20:52:30 +02:00
|
|
|
pass++;
|
|
|
|
|
}
|
|
|
|
|
else if (x == CRYPT_NOP) {
|
|
|
|
|
printf("nop");
|
|
|
|
|
nop++;
|
2017-03-01 15:00:04 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2017-08-07 16:33:38 +02:00
|
|
|
printf("failed (%s) %10.3fms", error_to_string(x), (double)(delta)/1000);
|
2017-03-29 20:52:30 +02:00
|
|
|
fail++;
|
2017-03-01 15:00:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-05-11 14:49:57 +02:00
|
|
|
dur = epoch_usec() - dur;
|
2017-03-01 15:00:04 +01:00
|
|
|
|
2017-05-11 14:49:57 +02:00
|
|
|
#ifdef LTC_PTHREAD
|
|
|
|
|
XFREE(tinfo);
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-05-19 11:38:53 +02:00
|
|
|
if (cipher_descriptor[TAB_SIZE - 1].name != NULL)
|
|
|
|
|
printf("cipher_descriptor Table full\n");
|
|
|
|
|
if (hash_descriptor[TAB_SIZE - 1].name != NULL)
|
|
|
|
|
printf("hash_descriptor Table full\n");
|
|
|
|
|
if (prng_descriptor[TAB_SIZE - 1].name != NULL)
|
|
|
|
|
printf("prng_descriptor Table full\n");
|
2017-05-11 14:49:57 +02:00
|
|
|
x = (fail > 0 || fail+pass+nop == 0) ? EXIT_FAILURE : EXIT_SUCCESS;
|
|
|
|
|
printf("\n\n%s: passed=%d failed=%d nop=%d duration=%.1fsec real=%.1fsec\n", x ? "FAILURE" : "SUCCESS", pass, fail, nop, (double)(dur)/(1000*1000), (double)(real)/(1000*1000));
|
|
|
|
|
return x;
|
2005-04-17 11:37:13 +00:00
|
|
|
}
|