Merge pull request #341 from libtom/improve-tests Improve tests
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
diff --git a/.travis.yml b/.travis.yml
index dba45d4..37b0d9d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -90,6 +90,9 @@ matrix:
- libc6-dev-i386
- gcc-multilib
+ # RSA superclass with tests (no sanitizer, but debug info)
+ - env: COMPILE_DEBUG=1 BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --cflags=-DLTM_NOTHING --cflags=-DSC_RSA_1_WITH_TESTS --with-travis-valgrind'
+
# Test "autotuning", the automatic evaluation and setting of the Toom-Cook cut-offs.
#- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_8BIT --with-travis-valgrind --make-option=tune'
#- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_16BIT --with-travis-valgrind --make-option=tune'
diff --git a/bn_s_mp_rand_platform.c b/bn_s_mp_rand_platform.c
index 950faed..07555db 100644
--- a/bn_s_mp_rand_platform.c
+++ b/bn_s_mp_rand_platform.c
@@ -121,7 +121,7 @@ static mp_err s_read_urandom(void *p, size_t n)
#endif
#if defined(MP_PRNG_ENABLE_LTM_RNG)
-#define B_S_READ_LTM_RNG
+#define BN_S_READ_LTM_RNG
unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void));
void (*ltm_rng_callback)(void);
diff --git a/demo/opponent.c b/demo/opponent.c
index 69c1c85..dc0893c 100644
--- a/demo/opponent.c
+++ b/demo/opponent.c
@@ -35,9 +35,11 @@ int mtest_opponent(void)
div2_n = mul2_n = inv_n = expt_n = lcm_n = gcd_n = add_n =
sub_n = mul_n = div_n = sqr_n = mul2d_n = div2d_n = add_d_n = sub_d_n = 0;
+#ifndef MP_FIXED_CUTOFFS
/* force KARA and TOOM to enable despite cutoffs */
KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;
TOOM_SQR_CUTOFF = TOOM_MUL_CUTOFF = 16;
+#endif
for (;;) {
/* randomly clear and re-init one variable, this has the affect of triming the alloc space */
diff --git a/demo/test.c b/demo/test.c
index 390d32d..79cfb38 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -1,3 +1,4 @@
+#include <inttypes.h>
#include "shared.h"
static long rand_long(void)
@@ -976,7 +977,7 @@ static int test_mp_prime_is_prime(void)
printf("A certified prime is a prime but mp_prime_is_prime says it is not.\n");
}
if ((err != MP_OKAY) || (cnt == MP_NO)) {
- printf("prime tested was: ");
+ printf("prime tested was: 0x");
mp_fwrite(&a,16,stdout);
putchar('\n');
goto LBL_ERR;
@@ -1010,10 +1011,10 @@ static int test_mp_prime_is_prime(void)
printf("\nfrobenius-underwood says sub is not prime!\n");
}
if ((err != MP_OKAY) || (cnt == MP_NO)) {
- printf("prime tested was: ");
+ printf("prime tested was: 0x");
mp_fwrite(&a,16,stdout);
putchar('\n');
- printf("sub tested was: ");
+ printf("sub tested was: 0x");
mp_fwrite(&b,16,stdout);
putchar('\n');
goto LBL_ERR;
@@ -1035,7 +1036,7 @@ static int test_mp_prime_is_prime(void)
printf("\n\nissue #143 - mp_prime_strong_lucas_selfridge FAILED!\n");
}
if ((err != MP_OKAY) || (cnt == MP_NO)) {
- printf("prime tested was: ");
+ printf("prime tested was: 0x");
mp_fwrite(&a,16,stdout);
putchar('\n');
goto LBL_ERR;
@@ -2219,54 +2220,62 @@ int unit_tests(int argc, char **argv)
const char *name;
int (*fn)(void);
} test[] = {
-#define T(n) { #n, test_##n }
- T(feature_detection),
- T(trivial_stuff),
- T(mp_get_set_i32),
- T(mp_get_set_i64),
- T(mp_and),
- T(mp_cnt_lsb),
- T(mp_complement),
- T(mp_decr),
- T(mp_div_3),
- T(mp_dr_reduce),
- T(mp_fread_fwrite),
- T(mp_get_u32),
- T(mp_get_u64),
- T(mp_get_ul),
- T(mp_ilogb),
- T(mp_incr),
- T(mp_invmod),
- T(mp_is_square),
- T(mp_kronecker),
- T(mp_montgomery_reduce),
- T(mp_root_u32),
- T(mp_or),
- T(mp_prime_is_prime),
- T(mp_prime_next_prime),
- T(mp_prime_rand),
- T(mp_rand),
- T(mp_read_radix),
- T(mp_reduce_2k),
- T(mp_reduce_2k_l),
+#define T0(n) { #n, test_##n }
+#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
+#define T2(n, o1, o2) { #n, MP_HAS(o1) && MP_HAS(o2) ? test_##n : NULL }
+ T0(feature_detection),
+ T0(trivial_stuff),
+ T2(mp_get_set_i32, MP_GET_I32, MP_GET_MAG_U32),
+ T2(mp_get_set_i64, MP_GET_I64, MP_GET_MAG_U64),
+ T1(mp_and, MP_AND),
+ T1(mp_cnt_lsb, MP_CNT_LSB),
+ T1(mp_complement, MP_COMPLEMENT),
+ T1(mp_decr, MP_DECR),
+ T1(mp_div_3, MP_DIV_3),
+ T1(mp_dr_reduce, MP_DR_REDUCE),
+ T2(mp_fread_fwrite, MP_FREAD, MP_FWRITE),
+ T1(mp_get_u32, MP_GET_I32),
+ T1(mp_get_u64, MP_GET_I64),
+ T1(mp_get_ul, MP_GET_L),
+ T1(mp_ilogb, MP_ILOGB),
+ T1(mp_incr, MP_INCR),
+ T1(mp_invmod, MP_INVMOD),
+ T1(mp_is_square, MP_IS_SQUARE),
+ T1(mp_kronecker, MP_KRONECKER),
+ T1(mp_montgomery_reduce, MP_MONTGOMERY_REDUCE),
+ T1(mp_root_u32, MP_ROOT_U32),
+ T1(mp_or, MP_OR),
+ T1(mp_prime_is_prime, MP_PRIME_IS_PRIME),
+ T1(mp_prime_next_prime, MP_PRIME_NEXT_PRIME),
+ T1(mp_prime_rand, MP_PRIME_RAND),
+ T1(mp_rand, MP_RAND),
+ T1(mp_read_radix, MP_READ_RADIX),
+ T1(mp_reduce_2k, MP_REDUCE_2K),
+ T1(mp_reduce_2k_l, MP_REDUCE_2K_L),
#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
- T(mp_set_double),
+ T1(mp_set_double, MP_SET_DOUBLE),
#endif
- T(mp_signed_rsh),
- T(mp_sqrt),
- T(mp_sqrtmod_prime),
- T(mp_xor),
- T(s_mp_balance_mul),
- T(s_mp_karatsuba_mul),
- T(s_mp_karatsuba_sqr),
- T(s_mp_toom_mul),
- T(s_mp_toom_sqr)
-#undef T
+ T1(mp_signed_rsh, MP_SIGNED_RSH),
+ T1(mp_sqrt, MP_SQRT),
+ T1(mp_sqrtmod_prime, MP_SQRTMOD_PRIME),
+ T1(mp_xor, MP_XOR),
+ T1(s_mp_balance_mul, S_MP_BALANCE_MUL),
+ T1(s_mp_karatsuba_mul, S_MP_KARATSUBA_MUL),
+ T1(s_mp_karatsuba_sqr, S_MP_KARATSUBA_SQR),
+ T1(s_mp_toom_mul, S_MP_TOOM_MUL),
+ T1(s_mp_toom_sqr, S_MP_TOOM_SQR),
+#undef T2
+#undef T1
};
- unsigned long i;
- int res = EXIT_SUCCESS, j;
+ unsigned long i, ok, fail, nop;
+ uint64_t t;
+ int j;
- s_mp_rand_jenkins_init((uint64_t)time(NULL));
+ ok = fail = nop = 0;
+
+ t = (uint64_t)time(NULL);
+ printf("SEED: 0x%"PRIx64"\n\n", t);
+ s_mp_rand_jenkins_init(t);
mp_rand_source(s_mp_rand_jenkins);
for (i = 0; i < sizeof(test) / sizeof(test[0]); ++i) {
@@ -2279,13 +2288,19 @@ int unit_tests(int argc, char **argv)
if (j == argc) continue;
}
printf("TEST %s\n\n", test[i].name);
- if (test[i].fn() != EXIT_SUCCESS) {
+ if (test[i].fn == NULL) {
+ nop++;
+ printf("NOP %s\n\n", test[i].name);
+ } else if (test[i].fn() == EXIT_SUCCESS) {
+ ok++;
+ printf("\n\n");
+ } else {
+ fail++;
printf("\n\nFAIL %s\n\n", test[i].name);
- res = EXIT_FAILURE;
- break;
}
- printf("\n\n");
}
+ printf("Tests OK/NOP/FAIL: %lu/%lu/%lu\n", ok, nop, fail);
- return res;
+ if (fail != 0) return EXIT_FAILURE;
+ else return EXIT_SUCCESS;
}
diff --git a/etc/makefile b/etc/makefile
index ce9cf06..bad1741 100644
--- a/etc/makefile
+++ b/etc/makefile
@@ -1,4 +1,5 @@
-CFLAGS += -Wall -W -Wextra -Wshadow -O3 -I../
+LTM_CFLAGS += -Wall -W -Wextra -Wshadow -O3 -I../
+LTM_CFLAGS += $(CFLAGS)
# default lib name (requires install with root)
# LIBNAME=-ltommath
@@ -8,31 +9,31 @@ LIBNAME=../libtommath.a
#provable primes
pprime: pprime.o
- $(CC) $(CFLAGS) pprime.o $(LIBNAME) -o pprime
+ $(CC) $(LTM_CFLAGS) pprime.o $(LIBNAME) -o pprime
# portable [well requires clock()] tuning app
tune: tune.o
- $(CC) $(CFLAGS) tune.o $(LIBNAME) -o tune
+ $(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o tune
./tune_it.sh
test_standalone: tune.o
# The benchmark program works as a testtool, too
- $(CC) $(CFLAGS) tune.o $(LIBNAME) -o test
+ $(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o test
# spits out mersenne primes
mersenne: mersenne.o
- $(CC) $(CFLAGS) mersenne.o $(LIBNAME) -o mersenne
+ $(CC) $(LTM_CFLAGS) mersenne.o $(LIBNAME) -o mersenne
# finds DR safe primes for the given config
drprime: drprime.o
- $(CC) $(CFLAGS) drprime.o $(LIBNAME) -o drprime
+ $(CC) $(LTM_CFLAGS) drprime.o $(LIBNAME) -o drprime
# finds 2k safe primes for the given config
2kprime: 2kprime.o
- $(CC) $(CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
+ $(CC) $(LTM_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
mont: mont.o
- $(CC) $(CFLAGS) mont.o $(LIBNAME) -o mont
+ $(CC) $(LTM_CFLAGS) mont.o $(LIBNAME) -o mont
clean:
diff --git a/helper.pl b/helper.pl
index bde8cdf..e60c1a7 100755
--- a/helper.pl
+++ b/helper.pl
@@ -381,7 +381,7 @@ EOS
# scan for mp_* and make classes
my @deps = ();
foreach my $line (split /\n/, $content) {
- while ($line =~ /(fast_)?(s_)?mp\_[a-z_0-9]*(?=\()|(?<=\()mp\_[a-z_0-9]*(?=,)/g) {
+ while ($line =~ /(fast_)?(s_)?mp\_[a-z_0-9]*((?=\;)|(?=\())|(?<=\()mp\_[a-z_0-9]*(?=\()/g) {
my $a = $&;
next if $a eq "mp_err";
$a =~ tr/[a-z]/[A-Z]/;
diff --git a/makefile b/makefile
index beab4fc..89d2b3b 100644
--- a/makefile
+++ b/makefile
@@ -17,11 +17,11 @@ coverage: LIBNAME:=-Wl,--whole-archive $(LIBNAME) -Wl,--no-whole-archive
include makefile_include.mk
-%.o: %.c
+%.o: %.c $(HEADERS)
ifneq ($V,1)
@echo " * ${CC} $@"
endif
- ${silent} ${CC} -c ${CFLAGS} $< -o $@
+ ${silent} ${CC} -c ${LTM_CFLAGS} $< -o $@
LCOV_ARGS=--directory .
@@ -58,8 +58,6 @@ bn_s_mp_sqr.o bn_s_mp_sqr_fast.o bn_s_mp_sub.o bn_s_mp_toom_mul.o bn_s_mp_toom_s
#END_INS
-$(OBJECTS): $(HEADERS)
-
$(LIBNAME): $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS)
$(RANLIB) $@
@@ -79,11 +77,11 @@ profiled:
#make a single object profiled library
profiled_single:
perl gen.pl
- $(CC) $(CFLAGS) -fprofile-arcs -DTESTING -c mpi.c -o mpi.o
- $(CC) $(CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o timing
+ $(CC) $(LTM_CFLAGS) -fprofile-arcs -DTESTING -c mpi.c -o mpi.o
+ $(CC) $(LTM_CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o timing
./timing
rm -f *.o timing
- $(CC) $(CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o
+ $(CC) $(LTM_CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o
$(AR) $(ARFLAGS) $(LIBNAME) mpi.o
ranlib $(LIBNAME)
@@ -97,21 +95,18 @@ uninstall:
rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
-test: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
- $(CC) $(CFLAGS) $^ $(LFLAGS) -o test
-
-test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
- $(CC) $(CFLAGS) $^ $(LFLAGS) -o test
+test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
+ $(CC) $(LTM_CFLAGS) $^ $(LTM_LFLAGS) -o test
.PHONY: mtest
mtest:
- cd mtest ; $(CC) $(CFLAGS) -O0 mtest.c $(LFLAGS) -o mtest
+ cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LFLAGS) -o mtest
timing: $(LIBNAME) demo/timing.c
- $(CC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LFLAGS) -o timing
+ $(CC) $(LTM_CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LTM_LFLAGS) -o timing
tune: $(LIBNAME)
- $(MAKE) -C etc tune
+ $(MAKE) -C etc tune CFLAGS="$(LTM_CFLAGS)"
$(MAKE)
# You have to create a file .coveralls.yml with the content "repo_token: <the token>"
diff --git a/makefile.shared b/makefile.shared
index 25e2fe5..f77b5e5 100644
--- a/makefile.shared
+++ b/makefile.shared
@@ -57,13 +57,13 @@ bn_s_mp_sqr.o bn_s_mp_sqr_fast.o bn_s_mp_sub.o bn_s_mp_toom_mul.o bn_s_mp_toom_s
objs: $(OBJECTS)
-.c.o:
- $(LTCOMPILE) $(CFLAGS) $(LDFLAGS) -o $@ -c $<
+.c.o: $(HEADERS)
+ $(LTCOMPILE) $(LTM_CFLAGS) $(LTM_LDFLAGS) -o $@ -c $<
LOBJECTS = $(OBJECTS:.o=.lo)
$(LIBNAME): $(OBJECTS)
- $(LTLINK) $(LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_SO) $(LIBTOOLFLAGS)
+ $(LTLINK) $(LTM_LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_SO) $(LTM_LIBTOOLFLAGS)
install: $(LIBNAME)
install -d $(DESTDIR)$(LIBPATH)
@@ -79,27 +79,18 @@ uninstall:
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
-test: $(LIBNAME)
- $(LTCOMPILE) $(CFLAGS) -c demo/main.c -o demo/main.o
- $(LTCOMPILE) $(CFLAGS) -c demo/opponent.c -o demo/opponent.o
- $(LTCOMPILE) $(CFLAGS) -c demo/test.c -o demo/test.o
- $(LTLINK) $(LDFLAGS) -o test demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
-
-test_standalone: $(LIBNAME)
- $(LTCOMPILE) $(CFLAGS) -c demo/main.c -o demo/main.o
- $(LTCOMPILE) $(CFLAGS) -c demo/opponent.c -o demo/opponent.o
- $(LTCOMPILE) $(CFLAGS) -c demo/test.c -o demo/test.o
- $(LTLINK) $(LDFLAGS) -o test demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
+test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
+ $(LTLINK) $(LTM_LDFLAGS) $^ -o test
.PHONY: mtest
mtest:
- cd mtest ; $(CC) $(CFLAGS) -O0 mtest.c $(LDFLAGS) -o mtest
+ cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LDFLAGS) -o mtest
timing: $(LIBNAME) demo/timing.c
- $(LTLINK) $(CFLAGS) $(LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o timing
+ $(LTLINK) $(LTM_CFLAGS) $(LTM_LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o timing
tune: $(LIBNAME)
- $(LTCOMPILE) $(CFLAGS) -c etc/tune.c -o etc/tune.o
- $(LTLINK) $(LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
+ $(LTCOMPILE) $(LTM_CFLAGS) -c etc/tune.c -o etc/tune.o
+ $(LTLINK) $(LTM_LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
cd etc/; /bin/sh tune_it.sh; cd ..
$(MAKE) -f makefile.shared
diff --git a/makefile_include.mk b/makefile_include.mk
index 9303ffc..a766343 100644
--- a/makefile_include.mk
+++ b/makefile_include.mk
@@ -47,60 +47,67 @@ else
endif
endif
-CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
+LTM_CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
ifdef SANITIZER
-CFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero
+LTM_CFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero
endif
ifndef NO_ADDTL_WARNINGS
# additional warnings
-CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
-CFLAGS += -Wstrict-prototypes -Wpointer-arith
+LTM_CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
+LTM_CFLAGS += -Wstrict-prototypes -Wpointer-arith
endif
ifdef CONV_WARNINGS
-CFLAGS += -std=c89 -Wconversion -Wsign-conversion
+LTM_CFLAGS += -std=c89 -Wconversion -Wsign-conversion
ifeq ($(CONV_WARNINGS), strict)
-CFLAGS += -DMP_USE_ENUMS -Wc++-compat
+LTM_CFLAGS += -DMP_USE_ENUMS -Wc++-compat
endif
else
-CFLAGS += -Wsystem-headers
+LTM_CFLAGS += -Wsystem-headers
endif
ifdef COMPILE_DEBUG
#debug
-CFLAGS += -g3
+LTM_CFLAGS += -g3
endif
ifdef COMPILE_SIZE
#for size
-CFLAGS += -Os
+LTM_CFLAGS += -Os
else
ifndef IGNORE_SPEED
#for speed
-CFLAGS += -O3 -funroll-loops
+LTM_CFLAGS += -O3 -funroll-loops
#x86 optimizations [should be valid for any GCC install though]
-CFLAGS += -fomit-frame-pointer
+LTM_CFLAGS += -fomit-frame-pointer
endif
endif # COMPILE_SIZE
ifneq ($(findstring clang,$(CC)),)
-CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
+LTM_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
endif
ifneq ($(findstring mingw,$(CC)),)
-CFLAGS += -Wno-shadow
+LTM_CFLAGS += -Wno-shadow
endif
ifeq ($(PLATFORM), Darwin)
-CFLAGS += -Wno-nullability-completeness
+LTM_CFLAGS += -Wno-nullability-completeness
endif
ifeq ($(PLATFORM), CYGWIN)
LIBTOOLFLAGS += -no-undefined
endif
+# add in the standard FLAGS
+LTM_CFLAGS += $(CFLAGS)
+LTM_LFLAGS += $(LFLAGS)
+LTM_LDFLAGS += $(LDFLAGS)
+LTM_LIBTOOLFLAGS += $(LIBTOOLFLAGS)
+
+
ifeq ($(PLATFORM),FreeBSD)
_ARCH := $(shell sysctl -b hw.machine_arch)
else
@@ -119,7 +126,7 @@ endif
HEADERS_PUB=tommath.h
HEADERS=tommath_private.h tommath_class.h tommath_superclass.h $(HEADERS_PUB)
-test_standalone: CFLAGS+=-DLTM_DEMO_TEST_VS_MTEST=0
+test_standalone: LTM_CFLAGS+=-DLTM_DEMO_TEST_VS_MTEST=0
#LIBPATH The directory for libtommath to be installed to.
#INCPATH The directory to install the header files for libtommath.
@@ -132,9 +139,9 @@ DATAPATH ?= $(PREFIX)/share/doc/libtommath/pdf
#make the code coverage of the library
#
-coverage: CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS
-coverage: LFLAGS += -lgcov
-coverage: LDFLAGS += -lgcov
+coverage: LTM_CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS
+coverage: LTM_LFLAGS += -lgcov
+coverage: LTM_LDFLAGS += -lgcov
coverage: $(COVERAGE)
$(COVERAGE_APP)
diff --git a/tommath_class.h b/tommath_class.h
index 24122d1..32d1b2d 100644
--- a/tommath_class.h
+++ b/tommath_class.h
@@ -827,6 +827,7 @@
# define BN_MP_GROW_C
# define BN_MP_RAND_SOURCE_C
# define BN_MP_ZERO_C
+# define BN_S_MP_RAND_PLATFORM_C
# define BN_S_MP_RAND_SOURCE_C
#endif
@@ -1118,7 +1119,9 @@
# define BN_MP_INIT_C
# define BN_MP_MOD_C
# define BN_MP_MUL_C
+# define BN_MP_REDUCE_2K_L_C
# define BN_MP_REDUCE_2K_SETUP_L_C
+# define BN_MP_REDUCE_C
# define BN_MP_REDUCE_SETUP_C
# define BN_MP_SET_C
# define BN_MP_SQR_C
@@ -1128,17 +1131,21 @@
# define BN_MP_CLEAR_C
# define BN_MP_COPY_C
# define BN_MP_COUNT_BITS_C
+# define BN_MP_DR_REDUCE_C
# define BN_MP_DR_SETUP_C
# define BN_MP_EXCH_C
# define BN_MP_INIT_SIZE_C
# define BN_MP_MOD_C
# define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
+# define BN_MP_MONTGOMERY_REDUCE_C
# define BN_MP_MONTGOMERY_SETUP_C
# define BN_MP_MULMOD_C
# define BN_MP_MUL_C
+# define BN_MP_REDUCE_2K_C
# define BN_MP_REDUCE_2K_SETUP_C
# define BN_MP_SET_C
# define BN_MP_SQR_C
+# define BN_S_MP_MONTGOMERY_REDUCE_FAST_C
#endif
#if defined(BN_S_MP_GET_BIT_C)
diff --git a/tommath_superclass.h b/tommath_superclass.h
index cf17866..b007c24 100644
--- a/tommath_superclass.h
+++ b/tommath_superclass.h
@@ -4,10 +4,13 @@
/* super class file for PK algos */
/* default ... include all MPI */
+#ifndef LTM_NOTHING
#define LTM_ALL
+#endif
/* RSA only (does not support DH/DSA/ECC) */
/* #define SC_RSA_1 */
+/* #define SC_RSA_1_WITH_TESTS */
/* For reference.... On an Athlon64 optimizing for speed...
@@ -15,61 +18,93 @@
*/
+#ifdef SC_RSA_1_WITH_TESTS
+# define BN_MP_ERROR_TO_STRING_C
+# define BN_MP_FREAD_C
+# define BN_MP_FWRITE_C
+# define BN_MP_INCR_C
+# define BN_MP_ISEVEN_C
+# define BN_MP_ISODD_C
+# define BN_MP_NEG_C
+# define BN_MP_PRIME_FROBENIUS_UNDERWOOD_C
+# define BN_MP_RADIX_SIZE_C
+# define BN_MP_RAND_C
+# define BN_MP_REDUCE_C
+# define BN_MP_REDUCE_2K_L_C
+# define BN_MP_READ_SIGNED_BIN_C
+# define BN_MP_ROOT_U32_C
+# define BN_MP_SET_L_C
+# define BN_MP_SET_UL_C
+# define BN_MP_SIGNED_BIN_SIZE_C
+# define BN_MP_TO_RADIX_C
+# define BN_MP_TO_SIGNED_BIN_C
+# define BN_S_MP_RAND_JENKINS_C
+# define BN_S_MP_RAND_PLATFORM_C
+#endif
+
/* Works for RSA only, mpi.o is 68KiB */
-#ifdef SC_RSA_1
-# define BN_MP_SHRINK_C
-# define BN_MP_LCM_C
-# define BN_MP_PRIME_RANDOM_EX_C
-# define BN_MP_INVMOD_C
-# define BN_MP_GCD_C
-# define BN_MP_MOD_C
-# define BN_MP_MULMOD_C
+#if defined(SC_RSA_1) || defined (SC_RSA_1_WITH_TESTS)
+# define BN_CUTOFFS_C
# define BN_MP_ADDMOD_C
+# define BN_MP_CLEAR_MULTI_C
# define BN_MP_EXPTMOD_C
-# define BN_MP_SET_INT_C
+# define BN_MP_GCD_C
# define BN_MP_INIT_MULTI_C
-# define BN_MP_CLEAR_MULTI_C
-# define BN_MP_UNSIGNED_BIN_SIZE_C
-# define BN_MP_TO_UNSIGNED_BIN_C
+# define BN_MP_INVMOD_C
+# define BN_MP_LCM_C
+# define BN_MP_MOD_C
# define BN_MP_MOD_D_C
+# define BN_MP_MULMOD_C
+# define BN_MP_PRIME_IS_PRIME_C
# define BN_MP_PRIME_RABIN_MILLER_TRIALS_C
-# define BN_S_MP_REVERSE_C
+# define BN_MP_PRIME_RAND_C
+# define BN_MP_RADIX_SMAP_C
+# define BN_MP_SET_INT_C
+# define BN_MP_SHRINK_C
+# define BN_MP_TO_UNSIGNED_BIN_C
+# define BN_MP_UNSIGNED_BIN_SIZE_C
# define BN_PRIME_TAB_C
+# define BN_S_MP_REVERSE_C
/* other modifiers */
# define BN_MP_DIV_SMALL /* Slower division, not critical */
+
/* here we are on the last pass so we turn things off. The functions classes are still there
* but we remove them specifically from the build. This also invokes tweaks in functions
* like removing support for even moduli, etc...
*/
# ifdef LTM_LAST
-# undef BN_S_MP_TOOM_MUL_C
-# undef BN_S_MP_TOOM_SQR_C
-# undef BN_S_MP_KARATSUBA_MUL_C
-# undef BN_S_MP_KARATSUBA_SQR_C
-# undef BN_MP_REDUCE_C
-# undef BN_MP_REDUCE_SETUP_C
# undef BN_MP_DR_IS_MODULUS_C
# undef BN_MP_DR_SETUP_C
# undef BN_MP_DR_REDUCE_C
-# undef BN_MP_REDUCE_IS_2K_C
+# undef BN_MP_DIV_3_C
# undef BN_MP_REDUCE_2K_SETUP_C
# undef BN_MP_REDUCE_2K_C
+# undef BN_MP_REDUCE_IS_2K_C
+# undef BN_MP_REDUCE_SETUP_C
+# undef BN_S_MP_BALANCE_MUL_C
# undef BN_S_MP_EXPTMOD_C
-# undef BN_MP_DIV_3_C
+# undef BN_S_MP_INVMOD_FAST_C
+# undef BN_S_MP_KARATSUBA_MUL_C
+# undef BN_S_MP_KARATSUBA_SQR_C
# undef BN_S_MP_MUL_HIGH_DIGS_C
# undef BN_S_MP_MUL_HIGH_DIGS_FAST_C
-# undef BN_S_MP_INVMOD_FAST_C
+# undef BN_S_MP_TOOM_MUL_C
+# undef BN_S_MP_TOOM_SQR_C
+
+# ifndef SC_RSA_1_WITH_TESTS
+# undef BN_MP_REDUCE_C
+# endif
/* To safely undefine these you have to make sure your RSA key won't exceed the Comba threshold
* which is roughly 255 digits [7140 bits for 32-bit machines, 15300 bits for 64-bit machines]
* which means roughly speaking you can handle upto 2536-bit RSA keys with these defined without
* trouble.
*/
+# undef BN_MP_MONTGOMERY_REDUCE_C
# undef BN_S_MP_MUL_DIGS_C
# undef BN_S_MP_SQR_C
-# undef BN_MP_MONTGOMERY_REDUCE_C
# endif
#endif