Merge pull request #198 from libtom/test/pthread
Travis-CI: a new build with -DLTC_PTHREAD [skip ci]
This commit is contained in:
commit
a4671110d5
@ -90,6 +90,14 @@ env:
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="CLEANSTACK+NOTABLES+SMALL+NO_ASM+NO_TIMING_RESISTANCE"
|
||||
BUILDOPTIONS="-DLTC_CLEAN_STACK -DLTC_NO_TABLES -DLTC_SMALL_CODE -DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="PTHREAD"
|
||||
BUILDOPTIONS="-DLTC_PTHREAD"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="CLEANSTACK+NOTABLES+SMALL+NO_ASM+NO_TIMING_RESISTANCE+PTHREAD"
|
||||
BUILDOPTIONS="-DLTC_CLEAN_STACK -DLTC_NO_TABLES -DLTC_SMALL_CODE -DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING -DLTC_PTHREAD"
|
||||
- |
|
||||
BUILDSCRIPT="testbuild.sh"
|
||||
BUILDNAME="NOTEST"
|
||||
|
@ -98,6 +98,12 @@ sub check_descriptor {
|
||||
warn "$d missing in $f\n" and $fails++ if $txt !~ /\Q$d\E/;
|
||||
}
|
||||
}
|
||||
for my $d (@descriptors) {
|
||||
for my $f ("./tests/test.c") {
|
||||
my $txt = read_file($f);
|
||||
warn "$d missing in $f\n" and $fails++ if $txt !~ /\Q$d\E/;
|
||||
}
|
||||
}
|
||||
my $name = sprintf("%-17s", "check-${which}:");
|
||||
warn( $fails > 0 ? "${name}FAIL $fails\n" : "${name}PASS\n" );
|
||||
return $fails;
|
||||
|
@ -42,8 +42,9 @@ endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
#
|
||||
# Compilation flags. Note the += does not write over the user's CFLAGS!
|
||||
#
|
||||
CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow -DLTC_SOURCE
|
||||
|
||||
ifdef OLD_GCC
|
||||
@ -89,7 +90,7 @@ endif # COMPILE_DEBUG
|
||||
|
||||
|
||||
ifneq ($(findstring clang,$(CC)),)
|
||||
CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare
|
||||
CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
|
||||
endif
|
||||
|
||||
|
||||
@ -99,6 +100,10 @@ CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
|
||||
endif
|
||||
|
||||
|
||||
ifneq ($(findstring -DLTC_PTHREAD,$(CFLAGS)),)
|
||||
LDFLAGS += -pthread
|
||||
endif
|
||||
|
||||
#List of demo objects
|
||||
DSOURCES = $(wildcard demos/*.c)
|
||||
DOBJECTS = $(DSOURCES:.c=.o)
|
||||
|
@ -549,9 +549,9 @@
|
||||
#define LTC_MUTEX_GLOBAL(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define LTC_MUTEX_PROTO(x) extern pthread_mutex_t x;
|
||||
#define LTC_MUTEX_TYPE(x) pthread_mutex_t x;
|
||||
#define LTC_MUTEX_INIT(x) pthread_mutex_init(x, NULL);
|
||||
#define LTC_MUTEX_LOCK(x) pthread_mutex_lock(x);
|
||||
#define LTC_MUTEX_UNLOCK(x) pthread_mutex_unlock(x);
|
||||
#define LTC_MUTEX_INIT(x) LTC_ARGCHK(pthread_mutex_init(x, NULL) == 0);
|
||||
#define LTC_MUTEX_LOCK(x) LTC_ARGCHK(pthread_mutex_lock(x) == 0);
|
||||
#define LTC_MUTEX_UNLOCK(x) LTC_ARGCHK(pthread_mutex_unlock(x) == 0);
|
||||
|
||||
#else
|
||||
|
||||
|
@ -5,9 +5,6 @@
|
||||
int cipher_hash_test(void)
|
||||
{
|
||||
int x;
|
||||
unsigned char buf[4096];
|
||||
unsigned long n, one;
|
||||
prng_state nprng;
|
||||
|
||||
/* test ciphers */
|
||||
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
||||
@ -33,32 +30,6 @@ int cipher_hash_test(void)
|
||||
/* SHAKE128 + SHAKE256 tests are a bit special */
|
||||
DOX(sha3_shake_test(), "sha3_shake");
|
||||
|
||||
/* test prngs (test, import/export */
|
||||
for (x = 0; prng_descriptor[x].name != NULL; x++) {
|
||||
DOX(prng_descriptor[x].test(), prng_descriptor[x].name);
|
||||
DOX(prng_descriptor[x].start(&nprng), prng_descriptor[x].name);
|
||||
DOX(prng_descriptor[x].add_entropy((unsigned char *)"helloworld12", 12, &nprng), prng_descriptor[x].name);
|
||||
DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name);
|
||||
n = sizeof(buf);
|
||||
if (strcmp(prng_descriptor[x].name, "sprng")) {
|
||||
one = 1;
|
||||
if (prng_descriptor[x].pexport(buf, &one, &nprng) != CRYPT_BUFFER_OVERFLOW) {
|
||||
fprintf(stderr, "Error testing pexport with a short buffer (%s)\n", prng_descriptor[x].name);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
}
|
||||
DOX(prng_descriptor[x].pexport(buf, &n, &nprng), prng_descriptor[x].name);
|
||||
prng_descriptor[x].done(&nprng);
|
||||
DOX(prng_descriptor[x].pimport(buf, n, &nprng), prng_descriptor[x].name);
|
||||
DOX(prng_descriptor[x].pimport(buf, 4096, &nprng), prng_descriptor[x].name); /* try to import larger data */
|
||||
DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name);
|
||||
if (prng_descriptor[x].read(buf, 100, &nprng) != 100) {
|
||||
fprintf(stderr, "Error reading from imported PRNG (%s)!\n", prng_descriptor[x].name);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
prng_descriptor[x].done(&nprng);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,8 @@
|
||||
|
||||
int multi_test(void)
|
||||
{
|
||||
unsigned char key[32], buf[2][MAXBLOCKSIZE];
|
||||
unsigned char key[32] = { 0 };
|
||||
unsigned char buf[2][MAXBLOCKSIZE];
|
||||
unsigned long len, len2;
|
||||
|
||||
/* register algos */
|
||||
|
@ -17,9 +17,14 @@
|
||||
|
||||
#ifdef LTC_PKCS_1
|
||||
|
||||
static unsigned char no_prng_entropy[1024];
|
||||
static unsigned long no_prng_len = 0;
|
||||
static unsigned long no_prng_offset = 0;
|
||||
typedef struct
|
||||
{
|
||||
struct ltc_prng_descriptor desc;
|
||||
char name[64];
|
||||
unsigned char entropy[1024];
|
||||
unsigned long len;
|
||||
unsigned long offset;
|
||||
} no_prng_desc_t;
|
||||
|
||||
/**
|
||||
Start the PRNG
|
||||
@ -28,11 +33,13 @@ static unsigned long no_prng_offset = 0;
|
||||
*/
|
||||
int no_prng_start(prng_state *prng)
|
||||
{
|
||||
LTC_UNUSED_PARAM(prng);
|
||||
no_prng_len = 0;
|
||||
no_prng_offset = 0;
|
||||
no_prng_desc_t *no_prng = (no_prng_desc_t*) prng;
|
||||
LTC_ARGCHK(no_prng != NULL);
|
||||
LTC_ARGCHK(no_prng->name == (char*)no_prng + offsetof(no_prng_desc_t, name));
|
||||
no_prng->len = 0;
|
||||
no_prng->offset = 0;
|
||||
|
||||
return CRYPT_OK;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,15 +51,17 @@ int no_prng_start(prng_state *prng)
|
||||
*/
|
||||
int no_prng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
|
||||
{
|
||||
LTC_UNUSED_PARAM(prng);
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(inlen <= sizeof(no_prng_entropy));
|
||||
no_prng_desc_t *no_prng = (no_prng_desc_t*) prng;
|
||||
LTC_ARGCHK(no_prng != NULL);
|
||||
LTC_ARGCHK(no_prng->name == (char*)no_prng + offsetof(no_prng_desc_t, name));
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(inlen <= sizeof(no_prng->entropy));
|
||||
|
||||
no_prng_len = MIN(inlen, sizeof(no_prng_entropy));
|
||||
memcpy(no_prng_entropy, in, no_prng_len);
|
||||
no_prng_offset = 0;
|
||||
no_prng->len = MIN(inlen, sizeof(no_prng->entropy));
|
||||
memcpy(no_prng->entropy, in, no_prng->len);
|
||||
no_prng->offset = 0;
|
||||
|
||||
return CRYPT_OK;
|
||||
return CRYPT_OK;
|
||||
|
||||
}
|
||||
|
||||
@ -77,12 +86,14 @@ int no_prng_ready(prng_state *prng)
|
||||
*/
|
||||
unsigned long no_prng_read(unsigned char *out, unsigned long outlen, prng_state *prng)
|
||||
{
|
||||
LTC_UNUSED_PARAM(prng);
|
||||
no_prng_desc_t *no_prng = (no_prng_desc_t*) prng;
|
||||
LTC_ARGCHK(no_prng != NULL);
|
||||
LTC_ARGCHK(no_prng->name == (char*)no_prng + offsetof(no_prng_desc_t, name));
|
||||
LTC_ARGCHK(out != NULL);
|
||||
|
||||
outlen = MIN(outlen, no_prng_len - no_prng_offset);
|
||||
memcpy(out, &no_prng_entropy[no_prng_offset], outlen);
|
||||
no_prng_offset += outlen;
|
||||
outlen = MIN(outlen, no_prng->len - no_prng->offset);
|
||||
memcpy(out, &no_prng->entropy[no_prng->offset], outlen);
|
||||
no_prng->offset += outlen;
|
||||
|
||||
return outlen;
|
||||
}
|
||||
@ -137,9 +148,9 @@ int no_prng_test(void)
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
const struct ltc_prng_descriptor no_prng_desc =
|
||||
static const struct ltc_prng_descriptor no_prng_desc =
|
||||
{
|
||||
"no_prng", 0,
|
||||
NULL, 0,
|
||||
&no_prng_start,
|
||||
&no_prng_add_entropy,
|
||||
&no_prng_ready,
|
||||
@ -150,6 +161,24 @@ const struct ltc_prng_descriptor no_prng_desc =
|
||||
&no_prng_test
|
||||
};
|
||||
|
||||
struct ltc_prng_descriptor* no_prng_desc_get(void)
|
||||
{
|
||||
no_prng_desc_t* no_prng = XMALLOC(sizeof(*no_prng));
|
||||
LTC_ARGCHK(no_prng != NULL);
|
||||
XMEMCPY(&no_prng->desc, &no_prng_desc, sizeof(no_prng_desc));
|
||||
LTC_ARGCHK(snprintf(no_prng->name, sizeof(no_prng->name), "no_prng@%p", no_prng) < (int)sizeof(no_prng->name));
|
||||
no_prng->desc.name = no_prng->name;
|
||||
return &no_prng->desc;
|
||||
}
|
||||
|
||||
void no_prng_desc_free(struct ltc_prng_descriptor* prng)
|
||||
{
|
||||
no_prng_desc_t *no_prng = (no_prng_desc_t*) prng;
|
||||
LTC_ARGCHK(no_prng != NULL);
|
||||
LTC_ARGCHK(no_prng->name == (char*)no_prng + offsetof(no_prng_desc_t, name));
|
||||
XFREE(no_prng);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
int pkcs_1_eme_test(void)
|
||||
{
|
||||
int prng_idx = register_prng(&no_prng_desc);
|
||||
struct ltc_prng_descriptor* no_prng_desc = no_prng_desc_get();
|
||||
int prng_idx = register_prng(no_prng_desc);
|
||||
int hash_idx = find_hash("sha1");
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
@ -37,8 +38,8 @@ int pkcs_1_eme_test(void)
|
||||
unsigned char buf[256], obuf[256];
|
||||
unsigned long buflen = sizeof(buf), obuflen = sizeof(obuf);
|
||||
int stat;
|
||||
prng_descriptor[prng_idx].add_entropy(s->o2, s->o2_l, NULL);
|
||||
DOX(rsa_encrypt_key_ex(s->o1, s->o1_l, obuf, &obuflen, NULL, 0, NULL, prng_idx, -1, LTC_PKCS_1_V1_5, key), s->name);
|
||||
prng_descriptor[prng_idx].add_entropy(s->o2, s->o2_l, (prng_state*)no_prng_desc);
|
||||
DOX(rsa_encrypt_key_ex(s->o1, s->o1_l, obuf, &obuflen, NULL, 0, (prng_state*)no_prng_desc, prng_idx, -1, LTC_PKCS_1_V1_5, key), s->name);
|
||||
DOX(obuflen == (unsigned long)s->o3_l?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name);
|
||||
DOX(memcmp(s->o3, obuf, s->o3_l)==0?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name);
|
||||
DOX(rsa_decrypt_key_ex(obuf, obuflen, buf, &buflen, NULL, 0, -1, LTC_PKCS_1_V1_5, &stat, key), s->name);
|
||||
@ -48,7 +49,8 @@ int pkcs_1_eme_test(void)
|
||||
mp_clear_multi(key->d, key->e, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL);
|
||||
} /* for */
|
||||
|
||||
unregister_prng(&no_prng_desc);
|
||||
unregister_prng(no_prng_desc);
|
||||
no_prng_desc_free(no_prng_desc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
int pkcs_1_oaep_test(void)
|
||||
{
|
||||
int prng_idx = register_prng(&no_prng_desc);
|
||||
struct ltc_prng_descriptor* no_prng_desc = no_prng_desc_get();
|
||||
int prng_idx = register_prng(no_prng_desc);
|
||||
int hash_idx = find_hash("sha1");
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
@ -37,8 +38,8 @@ int pkcs_1_oaep_test(void)
|
||||
unsigned char buf[256], obuf[256];
|
||||
unsigned long buflen = sizeof(buf), obuflen = sizeof(obuf);
|
||||
int stat;
|
||||
prng_descriptor[prng_idx].add_entropy(s->o2, s->o2_l, NULL);
|
||||
DOX(rsa_encrypt_key(s->o1, s->o1_l, obuf, &obuflen, NULL, 0, NULL, prng_idx, hash_idx, key), s->name);
|
||||
prng_descriptor[prng_idx].add_entropy(s->o2, s->o2_l, (prng_state*)no_prng_desc);
|
||||
DOX(rsa_encrypt_key(s->o1, s->o1_l, obuf, &obuflen, NULL, 0, (prng_state*)no_prng_desc, prng_idx, hash_idx, key), s->name);
|
||||
DOX(obuflen == (unsigned long)s->o3_l?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name);
|
||||
DOX(memcmp(s->o3, obuf, s->o3_l)==0?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name);
|
||||
DOX(rsa_decrypt_key(obuf, obuflen, buf, &buflen, NULL, 0, hash_idx, &stat, key), s->name);
|
||||
@ -48,7 +49,8 @@ int pkcs_1_oaep_test(void)
|
||||
mp_clear_multi(key->d, key->e, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL);
|
||||
} /* for */
|
||||
|
||||
unregister_prng(&no_prng_desc);
|
||||
unregister_prng(no_prng_desc);
|
||||
no_prng_desc_free(no_prng_desc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
int pkcs_1_pss_test(void)
|
||||
{
|
||||
int prng_idx = register_prng(&no_prng_desc);
|
||||
struct ltc_prng_descriptor* no_prng_desc = no_prng_desc_get();
|
||||
int prng_idx = register_prng(no_prng_desc);
|
||||
int hash_idx = find_hash("sha1");
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
@ -37,9 +38,9 @@ int pkcs_1_pss_test(void)
|
||||
unsigned char buf[20], obuf[256];
|
||||
unsigned long buflen = sizeof(buf), obuflen = sizeof(obuf);
|
||||
int stat;
|
||||
prng_descriptor[prng_idx].add_entropy(s->o2, s->o2_l, NULL);
|
||||
prng_descriptor[prng_idx].add_entropy(s->o2, s->o2_l, (prng_state*)no_prng_desc);
|
||||
DOX(hash_memory(hash_idx, s->o1, s->o1_l, buf, &buflen), s->name);
|
||||
DOX(rsa_sign_hash(buf, buflen, obuf, &obuflen, NULL, prng_idx, hash_idx, s->o2_l, key), s->name);
|
||||
DOX(rsa_sign_hash(buf, buflen, obuf, &obuflen, (prng_state*)no_prng_desc, prng_idx, hash_idx, s->o2_l, key), s->name);
|
||||
DOX(obuflen == (unsigned long)s->o3_l?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name);
|
||||
DOX(memcmp(s->o3, obuf, s->o3_l)==0?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name);
|
||||
DOX(rsa_verify_hash(obuf, obuflen, buf, buflen, hash_idx, s->o2_l, &stat, key), s->name);
|
||||
@ -49,7 +50,8 @@ int pkcs_1_pss_test(void)
|
||||
mp_clear_multi(key->d, key->e, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL);
|
||||
} /* for */
|
||||
|
||||
unregister_prng(&no_prng_desc);
|
||||
unregister_prng(no_prng_desc);
|
||||
no_prng_desc_free(no_prng_desc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -20,7 +20,12 @@ static unsigned long my_test_rng(unsigned char *buf, unsigned long len,
|
||||
|
||||
int prng_test(void)
|
||||
{
|
||||
int err = CRYPT_NOP;
|
||||
int err = CRYPT_NOP;
|
||||
int x;
|
||||
unsigned char buf[4096];
|
||||
unsigned long n, one;
|
||||
prng_state nprng;
|
||||
|
||||
#ifdef LTC_PRNG_ENABLE_LTC_RNG
|
||||
unsigned long before;
|
||||
|
||||
@ -41,5 +46,33 @@ int prng_test(void)
|
||||
|
||||
ltc_rng = previous;
|
||||
#endif
|
||||
|
||||
/* test prngs (test, import/export) */
|
||||
for (x = 0; prng_descriptor[x].name != NULL; x++) {
|
||||
if(strstr(prng_descriptor[x].name, "no_prng") == prng_descriptor[x].name) continue;
|
||||
err = CRYPT_OK;
|
||||
DOX(prng_descriptor[x].test(), prng_descriptor[x].name);
|
||||
DOX(prng_descriptor[x].start(&nprng), prng_descriptor[x].name);
|
||||
DOX(prng_descriptor[x].add_entropy((unsigned char *)"helloworld12", 12, &nprng), prng_descriptor[x].name);
|
||||
DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name);
|
||||
n = sizeof(buf);
|
||||
if (strcmp(prng_descriptor[x].name, "sprng")) {
|
||||
one = 1;
|
||||
if (prng_descriptor[x].pexport(buf, &one, &nprng) != CRYPT_BUFFER_OVERFLOW) {
|
||||
fprintf(stderr, "Error testing pexport with a short buffer (%s)\n", prng_descriptor[x].name);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
}
|
||||
DOX(prng_descriptor[x].pexport(buf, &n, &nprng), prng_descriptor[x].name);
|
||||
prng_descriptor[x].done(&nprng);
|
||||
DOX(prng_descriptor[x].pimport(buf, n, &nprng), prng_descriptor[x].name);
|
||||
DOX(prng_descriptor[x].pimport(buf, 4096, &nprng), prng_descriptor[x].name); /* try to import larger data */
|
||||
DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name);
|
||||
if (prng_descriptor[x].read(buf, 100, &nprng) != 100) {
|
||||
fprintf(stderr, "Error reading from imported PRNG (%s)!\n", prng_descriptor[x].name);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
prng_descriptor[x].done(&nprng);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
110
tests/test.c
110
tests/test.c
@ -6,10 +6,12 @@
|
||||
|
||||
#define LTC_TEST_FN(f) { f, #f }
|
||||
|
||||
static const struct {
|
||||
typedef struct {
|
||||
int (*fn)(void);
|
||||
const char* name;
|
||||
} test_functions[] =
|
||||
} test_function;
|
||||
|
||||
static const test_function test_functions[] =
|
||||
{
|
||||
LTC_TEST_FN(store_test),
|
||||
LTC_TEST_FN(rotate_test),
|
||||
@ -30,9 +32,14 @@ static const struct {
|
||||
LTC_TEST_FN(katja_test),
|
||||
LTC_TEST_FN(file_test),
|
||||
LTC_TEST_FN(multi_test),
|
||||
/* keep the prng_test always at the end as
|
||||
* it has to be handled specially when
|
||||
* testing with LTC_PTHREAD enabled
|
||||
*/
|
||||
LTC_TEST_FN(prng_test),
|
||||
};
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h> /* GetSystemTimeAsFileTime */
|
||||
#else
|
||||
@ -63,6 +70,28 @@ static ulong64 epoch_usec(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef LTC_PTHREAD
|
||||
typedef struct
|
||||
{
|
||||
pthread_t thread_id;
|
||||
const test_function* t;
|
||||
int err;
|
||||
ulong64 delta;
|
||||
} thread_info;
|
||||
|
||||
static void *run(void *arg)
|
||||
{
|
||||
thread_info *tinfo = arg;
|
||||
ulong64 ts;
|
||||
|
||||
ts = epoch_usec();
|
||||
tinfo->err = tinfo->t->fn();
|
||||
tinfo->delta = epoch_usec() - ts;
|
||||
|
||||
return arg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* unregister ciphers, hashes & prngs
|
||||
@ -70,7 +99,17 @@ static ulong64 epoch_usec(void)
|
||||
static void _unregister_all(void)
|
||||
{
|
||||
#ifdef LTC_RIJNDAEL
|
||||
unregister_cipher(&aes_desc);
|
||||
#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
|
||||
#endif
|
||||
#ifdef LTC_BLOWFISH
|
||||
unregister_cipher(&blowfish_desc);
|
||||
@ -214,6 +253,9 @@ static void _unregister_all(void)
|
||||
#ifdef LTC_SOBER128
|
||||
unregister_prng(&sober128_desc);
|
||||
#endif
|
||||
#ifdef LTC_SPRNG
|
||||
unregister_prng(&sprng_desc);
|
||||
#endif
|
||||
} /* _cleanup() */
|
||||
|
||||
static void register_algs(void)
|
||||
@ -241,11 +283,14 @@ static void register_algs(void)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef LTC_PTHREAD
|
||||
thread_info *tinfo, *res;
|
||||
#endif
|
||||
int x, pass = 0, fail = 0, nop = 0;
|
||||
size_t fn_len, i, dots;
|
||||
char *single_test = NULL;
|
||||
ulong64 ts;
|
||||
long delta, dur = 0;
|
||||
long delta, dur, real = 0;
|
||||
register_algs();
|
||||
|
||||
printf("build == %s\n%s\n", GIT_VERSION, crypt_build_settings);
|
||||
@ -266,10 +311,29 @@ int main(int argc, char **argv)
|
||||
#endif
|
||||
printf("MP_DIGIT_BIT = %d\n", MP_DIGIT_BIT);
|
||||
|
||||
|
||||
#ifdef LTC_PTHREAD
|
||||
tinfo = XCALLOC(sizeof(test_functions)/sizeof(test_functions[0]), sizeof(thread_info));
|
||||
if (tinfo == NULL) {
|
||||
printf("\n\nFAILURE: XCALLOC\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
fn_len = 0;
|
||||
for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) {
|
||||
for (i = 0; i < sizeof(test_functions) / sizeof(test_functions[0]); ++i) {
|
||||
size_t len = strlen(test_functions[i].name);
|
||||
if (fn_len < len) fn_len = len;
|
||||
|
||||
#ifdef LTC_PTHREAD
|
||||
if(test_functions[i].fn == prng_test) continue;
|
||||
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
|
||||
}
|
||||
|
||||
fn_len = fn_len + (4 - (fn_len % 4));
|
||||
@ -277,6 +341,7 @@ int main(int argc, char **argv)
|
||||
/* single test name from commandline */
|
||||
if (argc > 1) single_test = argv[1];
|
||||
|
||||
dur = epoch_usec();
|
||||
for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) {
|
||||
if (single_test && strcmp(test_functions[i].name, single_test)) {
|
||||
continue;
|
||||
@ -287,10 +352,27 @@ int main(int argc, char **argv)
|
||||
while(dots--) printf(".");
|
||||
fflush(stdout);
|
||||
|
||||
#ifdef LTC_PTHREAD
|
||||
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);
|
||||
}
|
||||
#else
|
||||
ts = epoch_usec();
|
||||
x = test_functions[i].fn();
|
||||
delta = (long)(epoch_usec() - ts);
|
||||
dur += delta;
|
||||
#endif
|
||||
real += delta;
|
||||
|
||||
if (x == CRYPT_OK) {
|
||||
printf("passed %10.3fms", (double)(delta)/1000);
|
||||
@ -305,15 +387,15 @@ int main(int argc, char **argv)
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
dur = epoch_usec() - dur;
|
||||
|
||||
if (fail > 0 || fail+pass+nop == 0) {
|
||||
printf("\n\nFAILURE: passed=%d failed=%d nop=%d duration=%.1fsec\n", pass, fail, nop, (double)(dur)/(1000*1000));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
printf("\n\nSUCCESS: passed=%d failed=%d nop=%d duration=%.1fsec\n", pass, fail, nop, (double)(dur)/(1000*1000));
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#ifdef LTC_PTHREAD
|
||||
XFREE(tinfo);
|
||||
#endif
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
|
@ -54,7 +54,8 @@ int multi_test(void);
|
||||
int prng_test(void);
|
||||
|
||||
#ifdef LTC_PKCS_1
|
||||
extern const struct ltc_prng_descriptor no_prng_desc;
|
||||
struct ltc_prng_descriptor* no_prng_desc_get(void);
|
||||
void no_prng_desc_free(struct ltc_prng_descriptor*);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user