Skip to content

Commit

Permalink
allow building against tfm
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaeckel committed Nov 7, 2019
1 parent 0fa57df commit 55f7cdc
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions demos/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#define PRI64 "ll"
#endif

#ifdef TFM_DESC
#include <tfm.h>
#endif

#define DO(x) do{ \
int err; \
Expand Down Expand Up @@ -674,6 +677,16 @@ static void time_prng(void)
}
}

static int check_tfm_limit(unsigned long x)
{
#ifdef TFM_DESC
if (strcasecmp(ltc_mp.name, "tomsfastmath") == 0) {
if (x * 2 > FP_MAX_SIZE) return 1;
}
#endif
return 0;
}

#if defined(LTC_MDSA)
/* time various DSA operations */
static void time_dsa(void)
Expand All @@ -691,15 +704,14 @@ static void time_dsa(void)
{ 20, 128 },
{ 24, 192 },
{ 28, 256 },
#ifndef TFM_DESC
{ 32, 512 },
#endif
};

if (ltc_mp.name == NULL) return;

print_csv_header("group", "modulus");
for (x = 0; x < (sizeof(groups) / sizeof(groups[0])); x++) {
if (check_tfm_limit(groups[x].modulus * 8)) break;
t2 = 0;
for (y = 0; y < 4; y++) {
t_start();
Expand Down Expand Up @@ -735,7 +747,6 @@ static void time_dsa(void)
static void time_dsa(void) { fprintf(stderr, "NO DSA\n"); }
#endif


#if defined(LTC_MRSA)
/* time various RSA operations */
static void time_rsa(void)
Expand All @@ -751,6 +762,7 @@ static void time_rsa(void)

print_csv_header("keysize", NULL);
for (x = 2048; x <= 8192; x <<= 1) {
if (check_tfm_limit(x)) break;

#ifndef TIMING_DONT_MAKE_KEY
t2 = 0;
Expand Down Expand Up @@ -861,16 +873,15 @@ static void time_dh(void)
ulong64 t1, t2;
unsigned long i, x, y;
static unsigned long sizes[] = {768/8, 1024/8, 1536/8, 2048/8,
#ifndef TFM_DESC
3072/8, 4096/8, 6144/8, 8192/8,
#endif
100000
};

if (ltc_mp.name == NULL) return;

print_csv_header("keysize", NULL);
for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
if (check_tfm_limit(x)) break;
t2 = 0;
for (y = 0; y < 16; y++) {
DO(dh_set_pg_groupsize(x, &key));
Expand Down Expand Up @@ -932,6 +943,7 @@ static void time_ecc(void)

print_csv_header("keysize", NULL);
for (x = ecc_key_sizes[i=0]; x < 100000; x = ecc_key_sizes[++i]) {
if (check_tfm_limit(x)) break;

#ifndef TIMING_DONT_MAKE_KEY
t2 = 0;
Expand Down

0 comments on commit 55f7cdc

Please sign in to comment.