Skip to content

Commit 55f7cdc

Browse files
committed
allow building against tfm
1 parent 0fa57df commit 55f7cdc

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

demos/timing.c

+17-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#define PRI64 "ll"
1919
#endif
2020

21+
#ifdef TFM_DESC
22+
#include <tfm.h>
23+
#endif
2124

2225
#define DO(x) do{ \
2326
int err; \
@@ -674,6 +677,16 @@ static void time_prng(void)
674677
}
675678
}
676679

680+
static int check_tfm_limit(unsigned long x)
681+
{
682+
#ifdef TFM_DESC
683+
if (strcasecmp(ltc_mp.name, "tomsfastmath") == 0) {
684+
if (x * 2 > FP_MAX_SIZE) return 1;
685+
}
686+
#endif
687+
return 0;
688+
}
689+
677690
#if defined(LTC_MDSA)
678691
/* time various DSA operations */
679692
static void time_dsa(void)
@@ -691,15 +704,14 @@ static void time_dsa(void)
691704
{ 20, 128 },
692705
{ 24, 192 },
693706
{ 28, 256 },
694-
#ifndef TFM_DESC
695707
{ 32, 512 },
696-
#endif
697708
};
698709

699710
if (ltc_mp.name == NULL) return;
700711

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

738-
739750
#if defined(LTC_MRSA)
740751
/* time various RSA operations */
741752
static void time_rsa(void)
@@ -751,6 +762,7 @@ static void time_rsa(void)
751762

752763
print_csv_header("keysize", NULL);
753764
for (x = 2048; x <= 8192; x <<= 1) {
765+
if (check_tfm_limit(x)) break;
754766

755767
#ifndef TIMING_DONT_MAKE_KEY
756768
t2 = 0;
@@ -861,16 +873,15 @@ static void time_dh(void)
861873
ulong64 t1, t2;
862874
unsigned long i, x, y;
863875
static unsigned long sizes[] = {768/8, 1024/8, 1536/8, 2048/8,
864-
#ifndef TFM_DESC
865876
3072/8, 4096/8, 6144/8, 8192/8,
866-
#endif
867877
100000
868878
};
869879

870880
if (ltc_mp.name == NULL) return;
871881

872882
print_csv_header("keysize", NULL);
873883
for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
884+
if (check_tfm_limit(x)) break;
874885
t2 = 0;
875886
for (y = 0; y < 16; y++) {
876887
DO(dh_set_pg_groupsize(x, &key));
@@ -932,6 +943,7 @@ static void time_ecc(void)
932943

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

936948
#ifndef TIMING_DONT_MAKE_KEY
937949
t2 = 0;

0 commit comments

Comments
 (0)