Skip to content

Commit 168f3bd

Browse files
authored
Merge pull request #421 from libtom/pr/tests-cosmetics
fix "make test" built with no math provider or multiple providers
2 parents 3fb0eea + fc056a6 commit 168f3bd

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/headers/tomcrypt_custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@
417417
#define LTC_DH1536
418418
#define LTC_DH2048
419419

420-
#ifndef TFM_DESC
420+
#if defined(LTM_DESC) || defined(GMP_DESC)
421421
/* tfm has a problem in fp_isprime for larger key sizes */
422422
#define LTC_DH3072
423423
#define LTC_DH4096

tests/dh_test.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010

1111
#if defined(LTC_MDH)
1212

13-
#ifdef LTC_DH4096
14-
#define KEYSIZE 4096
15-
#else
16-
#define KEYSIZE 2048
17-
#endif
18-
1913
static int _prime_test(void)
2014
{
2115
void *p, *g, *tmp;
@@ -24,6 +18,9 @@ static int _prime_test(void)
2418
if ((err = mp_init_multi(&p, &g, &tmp, NULL)) != CRYPT_OK) { goto error; }
2519

2620
for (x = 0; ltc_dh_sets[x].size != 0; x++) {
21+
/* tfm has a problem with larger sizes */
22+
if ((strcmp(ltc_mp.name, "TomsFastMath") == 0) && (ltc_dh_sets[x].size > 256)) break;
23+
2724
if ((err = mp_read_radix(g, ltc_dh_sets[x].base, 16)) != CRYPT_OK) { goto error; }
2825
if ((err = mp_read_radix(p, ltc_dh_sets[x].prime, 16)) != CRYPT_OK) { goto error; }
2926

@@ -321,9 +318,12 @@ static int _basic_test(void)
321318
{
322319
unsigned char buf[3][4096];
323320
unsigned long x, y, z;
324-
int size;
321+
int size, KEYSIZE;
325322
dh_key usera, userb;
326323

324+
/* tfm has a problem with larger sizes */
325+
KEYSIZE = (strcmp(ltc_mp.name, "TomsFastMath") == 0) ? 2048 : 4096;
326+
327327
/* make up two keys */
328328
DO(dh_set_pg_groupsize(KEYSIZE/8, &usera));
329329
DO(dh_generate_key(&yarrow_prng, find_prng ("yarrow"), &usera));
@@ -372,6 +372,9 @@ static int _basic_test(void)
372372
}
373373

374374
for (x = 0; ltc_dh_sets[x].size != 0; x++) {
375+
/* tfm has a problem with larger sizes */
376+
if ((strcmp(ltc_mp.name, "TomsFastMath") == 0) && (ltc_dh_sets[x].size > 256)) break;
377+
375378
DO(dh_set_pg_groupsize(ltc_dh_sets[x].size, &usera));
376379
DO(dh_generate_key(&yarrow_prng, find_prng ("yarrow"), &usera));
377380
size = dh_get_groupsize(&usera);

tests/ecc_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,6 @@ int _ecc_new_api(void)
445445
unsigned char data16[16] = { 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1 };
446446
unsigned long len16;
447447

448-
if (ltc_mp.name == NULL) return CRYPT_NOP;
449-
450448
for (i = 0; i < (int)(sizeof(names)/sizeof(names[0])); i++) {
451449
DO(ecc_get_curve(names[i], &dp));
452450
/* make new key */
@@ -900,6 +898,8 @@ int _ecc_import_export(void) {
900898

901899
int ecc_tests(void)
902900
{
901+
if (ltc_mp.name == NULL) return CRYPT_NOP;
902+
903903
DO(_ecc_old_api()); /* up to 1.18 */
904904
DO(_ecc_new_api());
905905
DO(_ecc_import_export());

0 commit comments

Comments
 (0)