From 6b04bd386fc752ee7860367e877aa76f0184f283 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 29 Mar 2024 13:20:06 +0000 Subject: Remove libtommath/makefile* and related: Those files suggest anything can be built in this directory, it cannot. Allow mp_expt_n to be used in extensions in stead of mp_expt_d (following rename in libtommath 1.2 -> 1.3) Remove some libtommath C-files, which are not used at all. --- generic/tclExecute.c | 2 +- generic/tclTomMathDecls.h | 1 + libtommath/appveyor.yml | 20 - libtommath/bn_mp_get_ll.c | 7 - libtommath/bn_mp_get_mag_ull.c | 7 - libtommath/bn_mp_init_ll.c | 7 - libtommath/demo/shared.c | 42 - libtommath/demo/shared.h | 21 - libtommath/demo/test.c | 2522 ----------------------------------- libtommath/helper.pl | 482 ------- libtommath/libtommath_VS2008.sln | 29 - libtommath/libtommath_VS2008.vcproj | 966 -------------- libtommath/makefile | 165 --- libtommath/makefile.mingw | 109 -- libtommath/makefile.msvc | 93 -- libtommath/makefile.shared | 99 -- libtommath/makefile.unix | 106 -- libtommath/makefile_include.mk | 166 --- libtommath/tommath.def | 15 + libtommath/tommath.h | 15 +- libtommath/tommath_private.h | 7 + unix/Makefile.in | 6 - 22 files changed, 27 insertions(+), 4860 deletions(-) delete mode 100644 libtommath/appveyor.yml delete mode 100644 libtommath/bn_mp_get_ll.c delete mode 100644 libtommath/bn_mp_get_mag_ull.c delete mode 100644 libtommath/bn_mp_init_ll.c delete mode 100644 libtommath/demo/shared.c delete mode 100644 libtommath/demo/shared.h delete mode 100644 libtommath/demo/test.c delete mode 100755 libtommath/helper.pl delete mode 100644 libtommath/libtommath_VS2008.sln delete mode 100644 libtommath/libtommath_VS2008.vcproj delete mode 100644 libtommath/makefile delete mode 100644 libtommath/makefile.mingw delete mode 100644 libtommath/makefile.msvc delete mode 100644 libtommath/makefile.shared delete mode 100644 libtommath/makefile.unix delete mode 100644 libtommath/makefile_include.mk diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 0b25113..4072781 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -9082,7 +9082,7 @@ ExecuteExtendedBinaryMathOp( } Tcl_TakeBignumFromObj(NULL, valuePtr, &big1); mp_init(&bigResult); - mp_expt_u32(&big1, (unsigned int)w2, &bigResult); + TclBN_mp_expt_d(&big1, (unsigned int)w2, &bigResult); mp_clear(&big1); BIG_RESULT(&bigResult); } diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h index e6f23aa..550283d 100644 --- a/generic/tclTomMathDecls.h +++ b/generic/tclTomMathDecls.h @@ -71,6 +71,7 @@ #define mp_exch TclBN_mp_exch #define mp_expt_d TclBN_mp_expt_d #define mp_expt_d_ex TclBN_mp_expt_d_ex +#define mp_expt_n TclBN_mp_expt_d #define mp_expt_u32 TclBN_mp_expt_d #define mp_get_mag_ull TclBN_mp_get_mag_ull #define mp_grow TclBN_mp_grow diff --git a/libtommath/appveyor.yml b/libtommath/appveyor.yml deleted file mode 100644 index 0a8e075..0000000 --- a/libtommath/appveyor.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: 1.2.1-{build} -branches: - only: - - master - - develop - - /^release/ - - /^travis/ -image: -- Visual Studio 2019 -- Visual Studio 2017 -- Visual Studio 2015 -build_script: -- cmd: >- - if "Visual Studio 2019"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" - if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" - if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 - if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 - nmake -f makefile.msvc all -test_script: -- cmd: test.exe diff --git a/libtommath/bn_mp_get_ll.c b/libtommath/bn_mp_get_ll.c deleted file mode 100644 index 2687534..0000000 --- a/libtommath/bn_mp_get_ll.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "tommath_private.h" -#ifdef BN_MP_GET_LL_C -/* LibTomMath, multiple-precision integer library -- Tom St Denis */ -/* SPDX-License-Identifier: Unlicense */ - -MP_GET_SIGNED(mp_get_ll, mp_get_mag_ull, long long, unsigned long long) -#endif diff --git a/libtommath/bn_mp_get_mag_ull.c b/libtommath/bn_mp_get_mag_ull.c deleted file mode 100644 index 63a2741..0000000 --- a/libtommath/bn_mp_get_mag_ull.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "tommath_private.h" -#ifdef BN_MP_GET_MAG_ULL_C -/* LibTomMath, multiple-precision integer library -- Tom St Denis */ -/* SPDX-License-Identifier: Unlicense */ - -MP_GET_MAG(mp_get_mag_ull, unsigned long long) -#endif diff --git a/libtommath/bn_mp_init_ll.c b/libtommath/bn_mp_init_ll.c deleted file mode 100644 index dc7c4a4..0000000 --- a/libtommath/bn_mp_init_ll.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "tommath_private.h" -#ifdef BN_MP_INIT_LL_C -/* LibTomMath, multiple-precision integer library -- Tom St Denis */ -/* SPDX-License-Identifier: Unlicense */ - -MP_INIT_INT(mp_init_ll, mp_set_ll, long long) -#endif diff --git a/libtommath/demo/shared.c b/libtommath/demo/shared.c deleted file mode 100644 index dc8e05a..0000000 --- a/libtommath/demo/shared.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "shared.h" - -void ndraw(mp_int *a, const char *name) -{ - char *buf = NULL; - int size; - - mp_radix_size(a, 10, &size); - buf = (char *)malloc((size_t) size); - if (buf == NULL) { - fprintf(stderr, "\nndraw: malloc(%d) failed\n", size); - exit(EXIT_FAILURE); - } - - printf("%s: ", name); - mp_to_decimal(a, buf, (size_t) size); - printf("%s\n", buf); - mp_to_hex(a, buf, (size_t) size); - printf("0x%s\n", buf); - - free(buf); -} - -void print_header(void) -{ -#ifdef MP_8BIT - printf("Digit size 8 Bit \n"); -#endif -#ifdef MP_16BIT - printf("Digit size 16 Bit \n"); -#endif -#ifdef MP_32BIT - printf("Digit size 32 Bit \n"); -#endif -#ifdef MP_64BIT - printf("Digit size 64 Bit \n"); -#endif - printf("Size of mp_digit: %u\n", (unsigned int)sizeof(mp_digit)); - printf("Size of mp_word: %u\n", (unsigned int)sizeof(mp_word)); - printf("MP_DIGIT_BIT: %d\n", MP_DIGIT_BIT); - printf("MP_PREC: %d\n", MP_PREC); -} diff --git a/libtommath/demo/shared.h b/libtommath/demo/shared.h deleted file mode 100644 index 4d5eb53..0000000 --- a/libtommath/demo/shared.h +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include - -/* - * Configuration - */ -#ifndef LTM_DEMO_TEST_REDUCE_2K_L -/* This test takes a moment so we disable it by default, but it can be: - * 0 to disable testing - * 1 to make the test with P = 2^1024 - 0x2A434 B9FDEC95 D8F9D550 FFFFFFFF FFFFFFFF - * 2 to make the test with P = 2^2048 - 0x1 00000000 00000000 00000000 00000000 4945DDBF 8EA2A91D 5776399B B83E188F - */ -#define LTM_DEMO_TEST_REDUCE_2K_L 0 -#endif - -#define MP_WUR /* TODO: result checks disabled for now */ -#include "tommath_private.h" - -extern void ndraw(mp_int* a, const char* name); -extern void print_header(void); diff --git a/libtommath/demo/test.c b/libtommath/demo/test.c deleted file mode 100644 index 14b0c58..0000000 --- a/libtommath/demo/test.c +++ /dev/null @@ -1,2522 +0,0 @@ -#include -#include "shared.h" - -static long rand_long(void) -{ - long x; - if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) { - fprintf(stderr, "s_mp_rand_source failed\n"); - exit(EXIT_FAILURE); - } - return x; -} - -static int rand_int(void) -{ - int x; - if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) { - fprintf(stderr, "s_mp_rand_source failed\n"); - exit(EXIT_FAILURE); - } - return x; -} - -static int32_t rand_int32(void) -{ - int32_t x; - if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) { - fprintf(stderr, "s_mp_rand_source failed\n"); - exit(EXIT_FAILURE); - } - return x; -} - -static int64_t rand_int64(void) -{ - int64_t x; - if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) { - fprintf(stderr, "s_mp_rand_source failed\n"); - exit(EXIT_FAILURE); - } - return x; -} - -static uint32_t uabs32(int32_t x) -{ - return x > 0 ? (uint32_t)x : -(uint32_t)x; -} - -static uint64_t uabs64(int64_t x) -{ - return x > 0 ? (uint64_t)x : -(uint64_t)x; -} - -/* This function prototype is needed - * to test dead code elimination - * which is used for feature detection. - * - * If the feature detection does not - * work as desired we will get a linker error. - */ -void does_not_exist(void); - -static int test_feature_detection(void) -{ -#define BN_TEST_FEATURE1_C - if (!MP_HAS(TEST_FEATURE1)) { - does_not_exist(); - return EXIT_FAILURE; - } - -#define BN_TEST_FEATURE2_C 1 - if (MP_HAS(TEST_FEATURE2)) { - does_not_exist(); - return EXIT_FAILURE; - } - -#define BN_TEST_FEATURE3_C 0 - if (MP_HAS(TEST_FEATURE3)) { - does_not_exist(); - return EXIT_FAILURE; - } - -#define BN_TEST_FEATURE4_C something - if (MP_HAS(TEST_FEATURE4)) { - does_not_exist(); - return EXIT_FAILURE; - } - - if (MP_HAS(TEST_FEATURE5)) { - does_not_exist(); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} - -static int test_trivial_stuff(void) -{ - mp_int a, b, c, d; - mp_err e; - if ((e = mp_init_multi(&a, &b, &c, &d, NULL)) != MP_OKAY) { - return EXIT_FAILURE; - } - (void)mp_error_to_string(e); - - /* a: 0->5 */ - mp_set(&a, 5u); - /* a: 5-> b: -5 */ - mp_neg(&a, &b); - if (mp_cmp(&a, &b) != MP_GT) { - goto LBL_ERR; - } - if (mp_cmp(&b, &a) != MP_LT) { - goto LBL_ERR; - } - /* a: 5-> a: -5 */ - mp_neg(&a, &a); - if (mp_cmp(&b, &a) != MP_EQ) { - goto LBL_ERR; - } - /* a: -5-> b: 5 */ - mp_abs(&a, &b); - if (mp_isneg(&b) != MP_NO) { - goto LBL_ERR; - } - /* a: -5-> b: -4 */ - mp_add_d(&a, 1uL, &b); - if (mp_isneg(&b) != MP_YES) { - goto LBL_ERR; - } - if (mp_get_i32(&b) != -4) { - goto LBL_ERR; - } - if (mp_get_u32(&b) != (uint32_t)-4) { - goto LBL_ERR; - } - if (mp_get_mag_u32(&b) != 4) { - goto LBL_ERR; - } - /* a: -5-> b: 1 */ - mp_add_d(&a, 6uL, &b); - if (mp_get_u32(&b) != 1) { - goto LBL_ERR; - } - /* a: -5-> a: 1 */ - mp_add_d(&a, 6uL, &a); - if (mp_get_u32(&a) != 1) { - goto LBL_ERR; - } - mp_zero(&a); - /* a: 0-> a: 6 */ - mp_add_d(&a, 6uL, &a); - if (mp_get_u32(&a) != 6) { - goto LBL_ERR; - } - - mp_set(&a, 42u); - mp_set(&b, 1u); - mp_neg(&b, &b); - mp_set(&c, 1u); - mp_exptmod(&a, &b, &c, &d); - - mp_set(&c, 7u); - mp_exptmod(&a, &b, &c, &d); - - if (mp_iseven(&a) == mp_isodd(&a)) { - goto LBL_ERR; - } - - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_FAILURE; -} - -static int check_get_set_i32(mp_int *a, int32_t b) -{ - mp_clear(a); - if (mp_shrink(a) != MP_OKAY) return EXIT_FAILURE; - - mp_set_i32(a, b); - if (mp_shrink(a) != MP_OKAY) return EXIT_FAILURE; - if (mp_get_i32(a) != b) return EXIT_FAILURE; - if (mp_get_u32(a) != (uint32_t)b) return EXIT_FAILURE; - if (mp_get_mag_u32(a) != uabs32(b)) return EXIT_FAILURE; - - mp_set_u32(a, (uint32_t)b); - if (mp_get_u32(a) != (uint32_t)b) return EXIT_FAILURE; - if (mp_get_i32(a) != (int32_t)(uint32_t)b) return EXIT_FAILURE; - - return EXIT_SUCCESS; -} - -static int test_mp_get_set_i32(void) -{ - int i; - mp_int a; - - if (mp_init(&a) != MP_OKAY) { - return EXIT_FAILURE; - } - - check_get_set_i32(&a, 0); - check_get_set_i32(&a, -1); - check_get_set_i32(&a, 1); - check_get_set_i32(&a, INT32_MIN); - check_get_set_i32(&a, INT32_MAX); - - for (i = 0; i < 1000; ++i) { - int32_t b = rand_int32(); - if (check_get_set_i32(&a, b) != EXIT_SUCCESS) { - goto LBL_ERR; - } - } - - mp_clear(&a); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear(&a); - return EXIT_FAILURE; -} - -static int check_get_set_i64(mp_int *a, int64_t b) -{ - mp_clear(a); - if (mp_shrink(a) != MP_OKAY) return EXIT_FAILURE; - - mp_set_i64(a, b); - if (mp_shrink(a) != MP_OKAY) return EXIT_FAILURE; - if (mp_get_i64(a) != b) return EXIT_FAILURE; - if (mp_get_u64(a) != (uint64_t)b) return EXIT_FAILURE; - if (mp_get_mag_u64(a) != uabs64(b)) return EXIT_FAILURE; - - mp_set_u64(a, (uint64_t)b); - if (mp_get_u64(a) != (uint64_t)b) return EXIT_FAILURE; - if (mp_get_i64(a) != (int64_t)(uint64_t)b) return EXIT_FAILURE; - - return EXIT_SUCCESS; -} - -static int test_mp_get_set_i64(void) -{ - int i; - mp_int a; - - if (mp_init(&a) != MP_OKAY) { - return EXIT_FAILURE; - } - - check_get_set_i64(&a, 0); - check_get_set_i64(&a, -1); - check_get_set_i64(&a, 1); - check_get_set_i64(&a, INT64_MIN); - check_get_set_i64(&a, INT64_MAX); - - for (i = 0; i < 1000; ++i) { - int64_t b = rand_int64(); - if (check_get_set_i64(&a, b) != EXIT_SUCCESS) { - goto LBL_ERR; - } - } - - mp_clear(&a); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear(&a); - return EXIT_FAILURE; -} - -static int test_mp_fread_fwrite(void) -{ - mp_int a, b; - mp_err e; - FILE *tmp = NULL; - if ((e = mp_init_multi(&a, &b, NULL)) != MP_OKAY) { - return EXIT_FAILURE; - } - - mp_set_ul(&a, 123456uL); - tmp = tmpfile(); - if ((e = mp_fwrite(&a, 64, tmp)) != MP_OKAY) { - goto LBL_ERR; - } - rewind(tmp); - if ((e = mp_fread(&b, 64, tmp)) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_get_u32(&b) != 123456uL) { - goto LBL_ERR; - } - fclose(tmp); - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - if (tmp != NULL) fclose(tmp); - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -} - -static mp_err very_random_source(void *out, size_t size) -{ - memset(out, 0xff, size); - return MP_OKAY; -} - -static int test_mp_rand(void) -{ - mp_int a, b; - int n; - mp_err err; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - mp_rand_source(very_random_source); - for (n = 1; n < 1024; ++n) { - if ((err = mp_rand(&a, n)) != MP_OKAY) { - printf("Failed mp_rand() %s.\n", mp_error_to_string(err)); - break; - } - if ((err = mp_incr(&a)) != MP_OKAY) { - printf("Failed mp_incr() %s.\n", mp_error_to_string(err)); - break; - } - if ((err = mp_div_2d(&a, n * MP_DIGIT_BIT, &b, NULL)) != MP_OKAY) { - printf("Failed mp_div_2d() %s.\n", mp_error_to_string(err)); - break; - } - if (mp_cmp_d(&b, 1) != MP_EQ) { - ndraw(&a, "mp_rand() a"); - ndraw(&b, "mp_rand() b"); - err = MP_ERR; - break; - } - } - mp_rand_source(s_mp_rand_jenkins); - mp_clear_multi(&a, &b, NULL); - return err == MP_OKAY ? EXIT_SUCCESS : EXIT_FAILURE; -} - -static int test_mp_kronecker(void) -{ - struct mp_kronecker_st { - long n; - int c[21]; - }; - static struct mp_kronecker_st kronecker[] = { - /*-10, -9, -8, -7,-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10*/ - { -10, { 0, -1, 0, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, -1, 0, 0, 0, 1, 0, 1, 0 } }, - { -9, { -1, 0, -1, 1, 0, -1, -1, 0, -1, -1, 0, 1, 1, 0, 1, 1, 0, -1, 1, 0, 1 } }, - { -8, { 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0 } }, - { -7, { 1, -1, -1, 0, 1, 1, -1, 1, -1, -1, 0, 1, 1, -1, 1, -1, -1, 0, 1, 1, -1 } }, - { -6, { 0, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0 } }, - { -5, { 0, -1, 1, -1, 1, 0, -1, -1, 1, -1, 0, 1, -1, 1, 1, 0, -1, 1, -1, 1, 0 } }, - { -4, { 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0 } }, - { -3, { -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1 } }, - { -2, { 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0 } }, - { -1, { -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1 } }, - { 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { 1, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }, - { 2, { 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1, 0 } }, - { 3, { 1, 0, -1, -1, 0, -1, 1, 0, -1, 1, 0, 1, -1, 0, 1, -1, 0, -1, -1, 0, 1 } }, - { 4, { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 } }, - { 5, { 0, 1, -1, -1, 1, 0, 1, -1, -1, 1, 0, 1, -1, -1, 1, 0, 1, -1, -1, 1, 0 } }, - { 6, { 0, 0, 0, -1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, -1, 0, 0, 0 } }, - { 7, { -1, 1, 1, 0, 1, -1, 1, 1, 1, 1, 0, 1, 1, 1, 1, -1, 1, 0, 1, 1, -1 } }, - { 8, { 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1, 0 } }, - { 9, { 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 } }, - { 10, { 0, 1, 0, -1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, -1, 0, 1, 0 } } - }; - - long k, m; - int i, cnt; - mp_err err; - mp_int a, b; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - mp_set_ul(&a, 0uL); - mp_set_ul(&b, 1uL); - if ((err = mp_kronecker(&a, &b, &i)) != MP_OKAY) { - printf("Failed executing mp_kronecker(0 | 1) %s.\n", mp_error_to_string(err)); - goto LBL_ERR; - } - if (i != 1) { - printf("Failed trivial mp_kronecker(0 | 1) %d != 1\n", i); - goto LBL_ERR; - } - for (cnt = 0; cnt < (int)(sizeof(kronecker)/sizeof(kronecker[0])); ++cnt) { - k = kronecker[cnt].n; - mp_set_l(&a, k); - /* only test positive values of a */ - for (m = -10; m <= 10; m++) { - mp_set_l(&b, m); - if ((err = mp_kronecker(&a, &b, &i)) != MP_OKAY) { - printf("Failed executing mp_kronecker(%ld | %ld) %s.\n", kronecker[cnt].n, m, mp_error_to_string(err)); - goto LBL_ERR; - } - if ((err == MP_OKAY) && (i != kronecker[cnt].c[m + 10])) { - printf("Failed trivial mp_kronecker(%ld | %ld) %d != %d\n", kronecker[cnt].n, m, i, kronecker[cnt].c[m + 10]); - goto LBL_ERR; - } - } - } - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -} - -static int test_mp_complement(void) -{ - int i; - - mp_int a, b, c; - if (mp_init_multi(&a, &b, &c, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < 1000; ++i) { - long l = rand_long(); - mp_set_l(&a, l); - mp_complement(&a, &b); - - l = ~l; - mp_set_l(&c, l); - - if (mp_cmp(&b, &c) != MP_EQ) { - printf("\nmp_complement() bad result!"); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -static int test_mp_signed_rsh(void) -{ - int i; - - mp_int a, b, d; - if (mp_init_multi(&a, &b, &d, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < 1000; ++i) { - long l; - int em; - - l = rand_long(); - mp_set_l(&a, l); - - em = abs(rand_int()) % 32; - - mp_set_l(&d, l >> em); - - mp_signed_rsh(&a, em, &b); - if (mp_cmp(&b, &d) != MP_EQ) { - printf("\nmp_signed_rsh() bad result!"); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, &d, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &d, NULL); - return EXIT_FAILURE; - -} - -static int test_mp_xor(void) -{ - int i; - - mp_int a, b, c, d; - if (mp_init_multi(&a, &b, &c, &d, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < 1000; ++i) { - long l, em; - - l = rand_long(); - mp_set_l(&a,l); - - em = rand_long(); - mp_set_l(&b, em); - - mp_set_l(&d, l ^ em); - - mp_xor(&a, &b, &c); - if (mp_cmp(&c, &d) != MP_EQ) { - printf("\nmp_xor() bad result!"); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_FAILURE; - -} - -static int test_mp_or(void) -{ - int i; - - mp_int a, b, c, d; - if (mp_init_multi(&a, &b, &c, &d, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < 1000; ++i) { - long l, em; - - l = rand_long(); - mp_set_l(&a, l); - - em = rand_long(); - mp_set_l(&b, em); - - mp_set_l(&d, l | em); - - mp_or(&a, &b, &c); - if (mp_cmp(&c, &d) != MP_EQ) { - printf("\nmp_or() bad result!"); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_FAILURE; -} - -static int test_mp_and(void) -{ - int i; - - mp_int a, b, c, d; - if (mp_init_multi(&a, &b, &c, &d, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < 1000; ++i) { - long l, em; - - l = rand_long(); - mp_set_l(&a, l); - - em = rand_long(); - mp_set_l(&b, em); - - mp_set_l(&d, l & em); - - mp_and(&a, &b, &c); - if (mp_cmp(&c, &d) != MP_EQ) { - printf("\nmp_and() bad result!"); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_FAILURE; -} - -static int test_mp_invmod(void) -{ - mp_int a, b, c, d; - if (mp_init_multi(&a, &b, &c, &d, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - /* mp_invmod corner-case of https://github.com/libtom/libtommath/issues/118 */ - { - const char *a_ = "47182BB8DF0FFE9F61B1F269BACC066B48BA145D35137D426328DC3F88A5EA44"; - const char *b_ = "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF"; - const char *should_ = "0521A82E10376F8E4FDEF9A32A427AC2A0FFF686E00290D39E3E4B5522409596"; - - if (mp_read_radix(&a, a_, 16) != MP_OKAY) { - printf("\nmp_read_radix(a) failed!"); - goto LBL_ERR; - } - if (mp_read_radix(&b, b_, 16) != MP_OKAY) { - printf("\nmp_read_radix(b) failed!"); - goto LBL_ERR; - } - if (mp_read_radix(&c, should_, 16) != MP_OKAY) { - printf("\nmp_read_radix(should) failed!"); - goto LBL_ERR; - } - - if (mp_invmod(&a, &b, &d) != MP_OKAY) { - printf("\nmp_invmod() failed!"); - goto LBL_ERR; - } - - if (mp_cmp(&c, &d) != MP_EQ) { - printf("\nmp_invmod() bad result!"); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_FAILURE; - -} - -#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) -static int test_mp_set_double(void) -{ - int i; - - mp_int a, b; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - /* test mp_get_double/mp_set_double */ - if (mp_set_double(&a, +1.0/0.0) != MP_VAL) { - printf("\nmp_set_double should return MP_VAL for +inf"); - goto LBL_ERR; - } - if (mp_set_double(&a, -1.0/0.0) != MP_VAL) { - printf("\nmp_set_double should return MP_VAL for -inf"); - goto LBL_ERR; - } - if (mp_set_double(&a, +0.0/0.0) != MP_VAL) { - printf("\nmp_set_double should return MP_VAL for NaN"); - goto LBL_ERR; - } - if (mp_set_double(&a, -0.0/0.0) != MP_VAL) { - printf("\nmp_set_double should return MP_VAL for NaN"); - goto LBL_ERR; - } - - for (i = 0; i < 1000; ++i) { - int tmp = rand_int(); - double dbl = (double)tmp * rand_int() + 1; - if (mp_set_double(&a, dbl) != MP_OKAY) { - printf("\nmp_set_double() failed"); - goto LBL_ERR; - } - if (dbl != mp_get_double(&a)) { - printf("\nmp_get_double() bad result!"); - goto LBL_ERR; - } - if (mp_set_double(&a, -dbl) != MP_OKAY) { - printf("\nmp_set_double() failed"); - goto LBL_ERR; - } - if (-dbl != mp_get_double(&a)) { - printf("\nmp_get_double() bad result!"); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; - -} -#endif - -static int test_mp_get_u32(void) -{ - unsigned long t; - int i; - - mp_int a, b; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < 1000; ++i) { - t = (unsigned long)rand_long() & 0xFFFFFFFFuL; - mp_set_ul(&a, t); - if (t != mp_get_u32(&a)) { - printf("\nmp_get_u32() bad result!"); - goto LBL_ERR; - } - } - mp_set_ul(&a, 0uL); - if (mp_get_u32(&a) != 0) { - printf("\nmp_get_u32() bad result!"); - goto LBL_ERR; - } - mp_set_ul(&a, 0xFFFFFFFFuL); - if (mp_get_u32(&a) != 0xFFFFFFFFuL) { - printf("\nmp_get_u32() bad result!"); - goto LBL_ERR; - } - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -} - -static int test_mp_get_ul(void) -{ - unsigned long s, t; - int i; - - mp_int a, b; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < ((int)MP_SIZEOF_BITS(unsigned long) - 1); ++i) { - t = (1UL << (i+1)) - 1; - if (!t) - t = ~0UL; - printf(" t = 0x%lx i = %d\r", t, i); - do { - mp_set_ul(&a, t); - s = mp_get_ul(&a); - if (s != t) { - printf("\nmp_get_ul() bad result! 0x%lx != 0x%lx", s, t); - goto LBL_ERR; - } - t <<= 1; - } while (t != 0uL); - } - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -} - -static int test_mp_get_u64(void) -{ - uint64_t q, r; - int i; - - mp_int a, b; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < (int)(MP_SIZEOF_BITS(uint64_t) - 1); ++i) { - r = ((uint64_t)1 << (i+1)) - 1; - if (!r) - r = UINT64_MAX; - printf(" r = 0x%" PRIx64 " i = %d\r", r, i); - do { - mp_set_u64(&a, r); - q = mp_get_u64(&a); - if (q != r) { - printf("\nmp_get_u64() bad result! 0x%" PRIx64 " != 0x%" PRIx64, q, r); - goto LBL_ERR; - } - r <<= 1; - } while (r != 0u); - } - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; - -} - -static int test_mp_sqrt(void) -{ - int i, n; - - mp_int a, b, c; - if (mp_init_multi(&a, &b, &c, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < 1000; ++i) { - printf("%6d\r", i); - fflush(stdout); - n = (rand_int() & 15) + 1; - mp_rand(&a, n); - if (mp_sqrt(&a, &b) != MP_OKAY) { - printf("\nmp_sqrt() error!"); - goto LBL_ERR; - } - mp_root_u32(&a, 2uL, &c); - if (mp_cmp_mag(&b, &c) != MP_EQ) { - printf("mp_sqrt() bad result!\n"); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -static int test_mp_is_square(void) -{ - int i, n; - - mp_int a, b; - mp_bool res; - - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - for (i = 0; i < 1000; ++i) { - printf("%6d\r", i); - fflush(stdout); - - /* test mp_is_square false negatives */ - n = (rand_int() & 7) + 1; - mp_rand(&a, n); - mp_sqr(&a, &a); - if (mp_is_square(&a, &res) != MP_OKAY) { - printf("\nfn:mp_is_square() error!"); - goto LBL_ERR; - } - if (res == MP_NO) { - printf("\nfn:mp_is_square() bad result!"); - goto LBL_ERR; - } - - /* test for false positives */ - mp_add_d(&a, 1uL, &a); - if (mp_is_square(&a, &res) != MP_OKAY) { - printf("\nfp:mp_is_square() error!"); - goto LBL_ERR; - } - if (res == MP_YES) { - printf("\nfp:mp_is_square() bad result!"); - goto LBL_ERR; - } - - } - printf("\n\n"); - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -} - -static int test_mp_sqrtmod_prime(void) -{ - struct mp_sqrtmod_prime_st { - unsigned long p; - unsigned long n; - mp_digit r; - }; - - static struct mp_sqrtmod_prime_st sqrtmod_prime[] = { - { 5, 14, 3 }, - { 7, 9, 4 }, - { 113, 2, 62 } - }; - int i; - - mp_int a, b, c; - if (mp_init_multi(&a, &b, &c, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - /* r^2 = n (mod p) */ - for (i = 0; i < (int)(sizeof(sqrtmod_prime)/sizeof(sqrtmod_prime[0])); ++i) { - mp_set_ul(&a, sqrtmod_prime[i].p); - mp_set_ul(&b, sqrtmod_prime[i].n); - if (mp_sqrtmod_prime(&b, &a, &c) != MP_OKAY) { - printf("Failed executing %d. mp_sqrtmod_prime\n", (i+1)); - goto LBL_ERR; - } - if (mp_cmp_d(&c, sqrtmod_prime[i].r) != MP_EQ) { - printf("Failed %d. trivial mp_sqrtmod_prime\n", (i+1)); - ndraw(&c, "r"); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -static int test_mp_prime_rand(void) -{ - int ix; - mp_err err; - mp_int a, b; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - /* test for size */ - for (ix = 10; ix < 128; ix++) { - printf("Testing (not safe-prime): %9d bits \r", ix); - fflush(stdout); - err = mp_prime_rand(&a, 8, ix, (rand_int() & 1) ? 0 : MP_PRIME_2MSB_ON); - if (err != MP_OKAY) { - printf("\nfailed with error: %s\n", mp_error_to_string(err)); - goto LBL_ERR; - } - if (mp_count_bits(&a) != ix) { - printf("Prime is %d not %d bits!!!\n", mp_count_bits(&a), ix); - goto LBL_ERR; - } - } - printf("\n"); - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -} - -static int test_mp_prime_is_prime(void) -{ - int ix; - mp_err err; - mp_bool cnt, fu; - - mp_int a, b; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - /* strong Miller-Rabin pseudoprime to the first 200 primes (F. Arnault) */ - puts("Testing mp_prime_is_prime() with Arnault's pseudoprime 803...901 \n"); - mp_read_radix(&a, - "91xLNF3roobhzgTzoFIG6P13ZqhOVYSN60Fa7Cj2jVR1g0k89zdahO9/kAiRprpfO1VAp1aBHucLFV/qLKLFb+zonV7R2Vxp1K13ClwUXStpV0oxTNQVjwybmFb5NBEHImZ6V7P6+udRJuH8VbMEnS0H8/pSqQrg82OoQQ2fPpAk6G1hkjqoCv5s/Yr", - 64); - mp_prime_is_prime(&a, mp_prime_rabin_miller_trials(mp_count_bits(&a)), &cnt); - if (cnt == MP_YES) { - printf("Arnault's pseudoprime is not prime but mp_prime_is_prime says it is.\n"); - goto LBL_ERR; - } - /* About the same size as Arnault's pseudoprime */ - puts("Testing mp_prime_is_prime() with certified prime 2^1119 + 53\n"); - mp_set(&a, 1uL); - mp_mul_2d(&a,1119,&a); - mp_add_d(&a, 53uL, &a); - err = mp_prime_is_prime(&a, mp_prime_rabin_miller_trials(mp_count_bits(&a)), &cnt); - /* small problem */ - if (err != MP_OKAY) { - printf("\nfailed with error: %s\n", mp_error_to_string(err)); - } - /* large problem */ - if (cnt == MP_NO) { - 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: 0x"); - mp_fwrite(&a,16,stdout); - putchar('\n'); - goto LBL_ERR; - } - for (ix = 16; ix < 128; ix++) { - printf("Testing ( safe-prime): %9d bits \r", ix); - fflush(stdout); - err = mp_prime_rand(&a, 8, ix, ((rand_int() & 1) ? 0 : MP_PRIME_2MSB_ON) | MP_PRIME_SAFE); - if (err != MP_OKAY) { - printf("\nfailed with error: %s\n", mp_error_to_string(err)); - goto LBL_ERR; - } - if (mp_count_bits(&a) != ix) { - printf("Prime is %d not %d bits!!!\n", mp_count_bits(&a), ix); - goto LBL_ERR; - } - /* let's see if it's really a safe prime */ - mp_sub_d(&a, 1uL, &b); - mp_div_2(&b, &b); - err = mp_prime_is_prime(&b, mp_prime_rabin_miller_trials(mp_count_bits(&b)), &cnt); - /* small problem */ - if (err != MP_OKAY) { - printf("\nfailed with error: %s\n", mp_error_to_string(err)); - } - /* large problem */ - if (cnt == MP_NO) { - printf("\nsub is not prime!\n"); - } - mp_prime_frobenius_underwood(&b, &fu); - if (fu == MP_NO) { - printf("\nfrobenius-underwood says sub is not prime!\n"); - } - if ((err != MP_OKAY) || (cnt == MP_NO)) { - printf("prime tested was: 0x"); - mp_fwrite(&a,16,stdout); - putchar('\n'); - printf("sub tested was: 0x"); - mp_fwrite(&b,16,stdout); - putchar('\n'); - goto LBL_ERR; - } - - } - /* Check regarding problem #143 */ -#ifndef MP_8BIT - mp_read_radix(&a, - "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A63A3620FFFFFFFFFFFFFFFF", - 16); - err = mp_prime_strong_lucas_selfridge(&a, &cnt); - /* small problem */ - if (err != MP_OKAY) { - printf("\nmp_prime_strong_lucas_selfridge failed with error: %s\n", mp_error_to_string(err)); - } - /* large problem */ - if (cnt == MP_NO) { - printf("\n\nissue #143 - mp_prime_strong_lucas_selfridge FAILED!\n"); - } - if ((err != MP_OKAY) || (cnt == MP_NO)) { - printf("prime tested was: 0x"); - mp_fwrite(&a,16,stdout); - putchar('\n'); - goto LBL_ERR; - } -#endif - - printf("\n\n"); - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; - -} - - -static int test_mp_prime_next_prime(void) -{ - mp_err err; - mp_int a, b, c; - - mp_init_multi(&a, &b, &c, NULL); - - - /* edge cases */ - mp_set(&a, 0u); - if ((err = mp_prime_next_prime(&a, 5, 0)) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_cmp_d(&a, 2u) != MP_EQ) { - printf("mp_prime_next_prime: output should have been 2 but was: "); - mp_fwrite(&a,10,stdout); - putchar('\n'); - goto LBL_ERR; - } - - mp_set(&a, 0u); - if ((err = mp_prime_next_prime(&a, 5, 1)) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_cmp_d(&a, 3u) != MP_EQ) { - printf("mp_prime_next_prime: output should have been 3 but was: "); - mp_fwrite(&a,10,stdout); - putchar('\n'); - goto LBL_ERR; - } - - mp_set(&a, 2u); - if ((err = mp_prime_next_prime(&a, 5, 0)) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_cmp_d(&a, 3u) != MP_EQ) { - printf("mp_prime_next_prime: output should have been 3 but was: "); - mp_fwrite(&a,10,stdout); - putchar('\n'); - goto LBL_ERR; - } - - mp_set(&a, 2u); - if ((err = mp_prime_next_prime(&a, 5, 1)) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_cmp_d(&a, 3u) != MP_EQ) { - printf("mp_prime_next_prime: output should have been 3 but was: "); - mp_fwrite(&a,10,stdout); - putchar('\n'); - goto LBL_ERR; - } - mp_set(&a, 8); - if ((err = mp_prime_next_prime(&a, 5, 1)) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_cmp_d(&a, 11u) != MP_EQ) { - printf("mp_prime_next_prime: output should have been 11 but was: "); - mp_fwrite(&a,10,stdout); - putchar('\n'); - goto LBL_ERR; - } - /* 2^300 + 157 is a 300 bit large prime to guarantee a multi-limb bigint */ - if ((err = mp_2expt(&a, 300)) != MP_OKAY) { - goto LBL_ERR; - } - mp_set_u32(&b, 157); - if ((err = mp_add(&a, &b, &a)) != MP_OKAY) { - goto LBL_ERR; - } - if ((err = mp_copy(&a, &b)) != MP_OKAY) { - goto LBL_ERR; - } - - /* 2^300 + 385 is the next prime */ - mp_set_u32(&c, 228); - if ((err = mp_add(&b, &c, &b)) != MP_OKAY) { - goto LBL_ERR; - } - if ((err = mp_prime_next_prime(&a, 5, 0)) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_cmp(&a, &b) != MP_EQ) { - printf("mp_prime_next_prime: output should have been\n"); - mp_fwrite(&b,10,stdout); - putchar('\n'); - printf("but was:\n"); - mp_fwrite(&a,10,stdout); - putchar('\n'); - goto LBL_ERR; - } - - /* Use another temporary variable or recompute? Mmh... */ - if ((err = mp_2expt(&a, 300)) != MP_OKAY) { - goto LBL_ERR; - } - mp_set_u32(&b, 157); - if ((err = mp_add(&a, &b, &a)) != MP_OKAY) { - goto LBL_ERR; - } - if ((err = mp_copy(&a, &b)) != MP_OKAY) { - goto LBL_ERR; - } - - /* 2^300 + 631 is the next prime congruent to 3 mod 4*/ - mp_set_u32(&c, 474); - if ((err = mp_add(&b, &c, &b)) != MP_OKAY) { - goto LBL_ERR; - } - if ((err = mp_prime_next_prime(&a, 5, 1)) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_cmp(&a, &b) != MP_EQ) { - printf("mp_prime_next_prime (bbs): output should have been\n"); - mp_fwrite(&b,10,stdout); - putchar('\n'); - printf("but was:\n"); - mp_fwrite(&a,10,stdout); - putchar('\n'); - goto LBL_ERR; - } - - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -static int test_mp_montgomery_reduce(void) -{ - mp_digit mp; - int ix, i, n; - char buf[4096]; - - /* size_t written; */ - - mp_int a, b, c, d, e; - if (mp_init_multi(&a, &b, &c, &d, &e, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - /* test montgomery */ - for (i = 1; i <= 10; i++) { - if (i == 10) - i = 1000; - printf(" digit size: %2d\r", i); - fflush(stdout); - for (n = 0; n < 1000; n++) { - mp_rand(&a, i); - a.dp[0] |= 1; - - /* let's see if R is right */ - mp_montgomery_calc_normalization(&b, &a); - mp_montgomery_setup(&a, &mp); - - /* now test a random reduction */ - for (ix = 0; ix < 100; ix++) { - mp_rand(&c, 1 + abs(rand_int()) % (2*i)); - mp_copy(&c, &d); - mp_copy(&c, &e); - - mp_mod(&d, &a, &d); - mp_montgomery_reduce(&c, &a, mp); - mp_mulmod(&c, &b, &a, &c); - - if (mp_cmp(&c, &d) != MP_EQ) { -/* *INDENT-OFF* */ - printf("d = e mod a, c = e MOD a\n"); - mp_to_decimal(&a, buf, sizeof(buf)); printf("a = %s\n", buf); - mp_to_decimal(&e, buf, sizeof(buf)); printf("e = %s\n", buf); - mp_to_decimal(&d, buf, sizeof(buf)); printf("d = %s\n", buf); - mp_to_decimal(&c, buf, sizeof(buf)); printf("c = %s\n", buf); - - printf("compare no compare!\n"); goto LBL_ERR; -/* *INDENT-ON* */ - } - /* only one big montgomery reduction */ - if (i > 10) { - n = 1000; - ix = 100; - } - } - } - } - - printf("\n\n"); - - mp_clear_multi(&a, &b, &c, &d, &e, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, &d, &e, NULL); - return EXIT_FAILURE; - -} - -static int test_mp_read_radix(void) -{ - char buf[4096]; - size_t written; - mp_err err; - - mp_int a; - if (mp_init_multi(&a, NULL)!= MP_OKAY) goto LTM_ERR; - - if ((err = mp_read_radix(&a, "123456", 10)) != MP_OKAY) goto LTM_ERR; - - if ((err = mp_to_radix(&a, buf, SIZE_MAX, &written, 10)) != MP_OKAY) goto LTM_ERR; - printf(" '123456' a == %s, length = %zu\n", buf, written); - - /* See comment in bn_mp_to_radix.c */ - /* - if( (err = mp_to_radix(&a, buf, 3u, &written, 10) ) != MP_OKAY) goto LTM_ERR; - printf(" '56' a == %s, length = %zu\n", buf, written); - - if( (err = mp_to_radix(&a, buf, 4u, &written, 10) ) != MP_OKAY) goto LTM_ERR; - printf(" '456' a == %s, length = %zu\n", buf, written); - if( (err = mp_to_radix(&a, buf, 30u, &written, 10) ) != MP_OKAY) goto LTM_ERR; - printf(" '123456' a == %s, length = %zu, error = %s\n", - buf, written, mp_error_to_string(err)); - */ - if ((err = mp_read_radix(&a, "-123456", 10)) != MP_OKAY) goto LTM_ERR; - if ((err = mp_to_radix(&a, buf, SIZE_MAX, &written, 10)) != MP_OKAY) goto LTM_ERR; - printf(" '-123456' a == %s, length = %zu\n", buf, written); - - if ((err = mp_read_radix(&a, "0", 10)) != MP_OKAY) goto LTM_ERR; - if ((err = mp_to_radix(&a, buf, SIZE_MAX, &written, 10)) != MP_OKAY) goto LTM_ERR; - printf(" '0' a == %s, length = %zu\n", buf, written); - - - - /* Although deprecated it needs to function as long as it isn't dropped */ - /* - printf("Testing deprecated mp_toradix_n\n"); - if( (err = mp_read_radix(&a, "-123456", 10) ) != MP_OKAY) goto LTM_ERR; - if( (err = mp_toradix_n(&a, buf, 10, 3) ) != MP_OKAY) goto LTM_ERR; - printf("a == %s\n", buf); - if( (err = mp_toradix_n(&a, buf, 10, 4) ) != MP_OKAY) goto LTM_ERR; - printf("a == %s\n", buf); - if( (err = mp_toradix_n(&a, buf, 10, 30) ) != MP_OKAY) goto LTM_ERR; - printf("a == %s\n", buf); - */ - - - while (0) { - char *s = fgets(buf, sizeof(buf), stdin); - if (s != buf) break; - mp_read_radix(&a, buf, 10); - mp_prime_next_prime(&a, 5, 1); - mp_to_radix(&a, buf, sizeof(buf), NULL, 10); - printf("%s, %lu\n", buf, (unsigned long)a.dp[0] & 3uL); - } - - mp_clear(&a); - return EXIT_SUCCESS; -LTM_ERR: - mp_clear(&a); - return EXIT_FAILURE; -} - -static int test_mp_cnt_lsb(void) -{ - int ix; - - mp_int a, b; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - mp_set(&a, 1uL); - for (ix = 0; ix < 1024; ix++) { - if (mp_cnt_lsb(&a) != ix) { - printf("Failed at %d, %d\n", ix, mp_cnt_lsb(&a)); - goto LBL_ERR; - } - mp_mul_2(&a, &a); - } - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; - -} - -static int test_mp_reduce_2k(void) -{ - int ix, cnt; - - mp_int a, b, c, d; - if (mp_init_multi(&a, &b, &c, &d, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - /* test mp_reduce_2k */ - for (cnt = 3; cnt <= 128; ++cnt) { - mp_digit tmp; - - mp_2expt(&a, cnt); - mp_sub_d(&a, 2uL, &a); /* a = 2**cnt - 2 */ - - printf("\r %4d bits", cnt); - printf("(%d)", mp_reduce_is_2k(&a)); - mp_reduce_2k_setup(&a, &tmp); - printf("(%lu)", (unsigned long) tmp); - for (ix = 0; ix < 1000; ix++) { - if (!(ix & 127)) { - printf("."); - fflush(stdout); - } - mp_rand(&b, (cnt / MP_DIGIT_BIT + 1) * 2); - mp_copy(&c, &b); - mp_mod(&c, &a, &c); - mp_reduce_2k(&b, &a, 2uL); - if (mp_cmp(&c, &b) != MP_EQ) { - printf("FAILED\n"); - goto LBL_ERR; - } - } - } - - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_FAILURE; -} - -static int test_mp_div_3(void) -{ - int cnt; - - mp_int a, b, c, d, e; - if (mp_init_multi(&a, &b, &c, &d, &e, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - /* test mp_div_3 */ - mp_set(&d, 3uL); - for (cnt = 0; cnt < 10000;) { - mp_digit r2; - - if (!(++cnt & 127)) { - printf("%9d\r", cnt); - fflush(stdout); - } - mp_rand(&a, abs(rand_int()) % 128 + 1); - mp_div(&a, &d, &b, &e); - mp_div_3(&a, &c, &r2); - - if (mp_cmp(&b, &c) || mp_cmp_d(&e, r2)) { - printf("\nmp_div_3 => Failure\n"); - goto LBL_ERR; - } - } - printf("\nPassed div_3 testing"); - - mp_clear_multi(&a, &b, &c, &d, &e, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, &d, &e, NULL); - return EXIT_FAILURE; -} - -static int test_mp_dr_reduce(void) -{ - mp_digit mp; - int cnt; - unsigned rr; - int ix; - - mp_int a, b, c; - if (mp_init_multi(&a, &b, &c, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - - /* test the DR reduction */ - for (cnt = 2; cnt < 32; cnt++) { - printf("\r%d digit modulus", cnt); - mp_grow(&a, cnt); - mp_zero(&a); - for (ix = 1; ix < cnt; ix++) { - a.dp[ix] = MP_MASK; - } - a.used = cnt; - a.dp[0] = 3; - - mp_rand(&b, cnt - 1); - mp_copy(&b, &c); - - rr = 0; - do { - if (!(rr & 127)) { - printf("."); - fflush(stdout); - } - mp_sqr(&b, &b); - mp_add_d(&b, 1uL, &b); - mp_copy(&b, &c); - - mp_mod(&b, &a, &b); - mp_dr_setup(&a, &mp); - mp_dr_reduce(&c, &a, mp); - - if (mp_cmp(&b, &c) != MP_EQ) { - printf("Failed on trial %u\n", rr); - goto LBL_ERR; - } - } while (++rr < 500); - printf(" passed"); - fflush(stdout); - } - - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -static int test_mp_reduce_2k_l(void) -{ -# if LTM_DEMO_TEST_REDUCE_2K_L - mp_int a, b, c, d; - int cnt; - char buf[4096]; - size_t length[1]; - if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) { - return EXIT_FAILURE; - } - /* test the mp_reduce_2k_l code */ -# if LTM_DEMO_TEST_REDUCE_2K_L == 1 - /* first load P with 2^1024 - 0x2A434 B9FDEC95 D8F9D550 FFFFFFFF FFFFFFFF */ - mp_2expt(&a, 1024); - mp_read_radix(&b, "2A434B9FDEC95D8F9D550FFFFFFFFFFFFFFFF", 16); - mp_sub(&a, &b, &a); -# elif LTM_DEMO_TEST_REDUCE_2K_L == 2 - /* p = 2^2048 - 0x1 00000000 00000000 00000000 00000000 4945DDBF 8EA2A91D 5776399B B83E188F */ - mp_2expt(&a, 2048); - mp_read_radix(&b, - "1000000000000000000000000000000004945DDBF8EA2A91D5776399BB83E188F", - 16); - mp_sub(&a, &b, &a); -# else -# error oops -# endif - *length = sizeof(buf); - mp_to_radix(&a, buf, length, 10); - printf("\n\np==%s, length = %zu\n", buf, *length); - /* now mp_reduce_is_2k_l() should return */ - if (mp_reduce_is_2k_l(&a) != 1) { - printf("mp_reduce_is_2k_l() return 0, should be 1\n"); - goto LBL_ERR; - } - mp_reduce_2k_setup_l(&a, &d); - /* now do a million square+1 to see if it varies */ - mp_rand(&b, 64); - mp_mod(&b, &a, &b); - mp_copy(&b, &c); - printf("Testing: mp_reduce_2k_l..."); - fflush(stdout); - for (cnt = 0; cnt < (int)(1uL << 20); cnt++) { - mp_sqr(&b, &b); - mp_add_d(&b, 1uL, &b); - mp_reduce_2k_l(&b, &a, &d); - mp_sqr(&c, &c); - mp_add_d(&c, 1uL, &c); - mp_mod(&c, &a, &c); - if (mp_cmp(&b, &c) != MP_EQ) { - printf("mp_reduce_2k_l() failed at step %d\n", cnt); - mp_to_hex(&b, buf, sizeof(buf)); - printf("b == %s\n", buf); - mp_to_hex(&c, buf, sizeof(buf)); - printf("c == %s\n", buf); - goto LBL_ERR; - } - } - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -#else - return EXIT_SUCCESS; -# endif /* LTM_DEMO_TEST_REDUCE_2K_L */ -} -/* stripped down version of mp_radix_size. The faster version can be off by up t -o +3 */ -/* TODO: This function should be removed, replaced by mp_radix_size, mp_radix_size_overestimate in 2.0 */ -static mp_err s_rs(const mp_int *a, int radix, uint32_t *size) -{ - mp_err res; - uint32_t digs = 0u; - mp_int t; - mp_digit d; - *size = 0u; - if (mp_iszero(a) == MP_YES) { - *size = 2u; - return MP_OKAY; - } - if (radix == 2) { - *size = (uint32_t)mp_count_bits(a) + 1u; - return MP_OKAY; - } - if ((res = mp_init_copy(&t, a)) != MP_OKAY) { - return res; - } - t.sign = MP_ZPOS; - while (mp_iszero(&t) == MP_NO) { - if ((res = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) { - mp_clear(&t); - return res; - } - ++digs; - } - mp_clear(&t); - *size = digs + 1; - return MP_OKAY; -} -static int test_mp_log_u32(void) -{ - mp_int a; - mp_digit d; - uint32_t base, lb, size; - const uint32_t max_base = MP_MIN(UINT32_MAX, MP_DIGIT_MAX); - - if (mp_init(&a) != MP_OKAY) { - goto LBL_ERR; - } - - /* - base a result - 0 x MP_VAL - 1 x MP_VAL - */ - mp_set(&a, 42uL); - base = 0u; - if (mp_log_u32(&a, base, &lb) != MP_VAL) { - goto LBL_ERR; - } - base = 1u; - if (mp_log_u32(&a, base, &lb) != MP_VAL) { - goto LBL_ERR; - } - /* - base a result - 2 0 MP_VAL - 2 1 0 - 2 2 1 - 2 3 1 - */ - base = 2u; - mp_zero(&a); - if (mp_log_u32(&a, base, &lb) != MP_VAL) { - goto LBL_ERR; - } - - for (d = 1; d < 4; d++) { - mp_set(&a, d); - if (mp_log_u32(&a, base, &lb) != MP_OKAY) { - goto LBL_ERR; - } - if (lb != ((d == 1)?0uL:1uL)) { - goto LBL_ERR; - } - } - /* - base a result - 3 0 MP_VAL - 3 1 0 - 3 2 0 - 3 3 1 - */ - base = 3u; - mp_zero(&a); - if (mp_log_u32(&a, base, &lb) != MP_VAL) { - goto LBL_ERR; - } - for (d = 1; d < 4; d++) { - mp_set(&a, d); - if (mp_log_u32(&a, base, &lb) != MP_OKAY) { - goto LBL_ERR; - } - if (lb != ((d < base)?0uL:1uL)) { - goto LBL_ERR; - } - } - - /* - bases 2..64 with "a" a random large constant. - The range of bases tested allows to check with - radix_size. - */ - if (mp_rand(&a, 10) != MP_OKAY) { - goto LBL_ERR; - } - for (base = 2u; base < 65u; base++) { - if (mp_log_u32(&a, base, &lb) != MP_OKAY) { - goto LBL_ERR; - } - if (s_rs(&a,(int)base, &size) != MP_OKAY) { - goto LBL_ERR; - } - /* radix_size includes the memory needed for '\0', too*/ - size -= 2; - if (lb != size) { - goto LBL_ERR; - } - } - - /* - bases 2..64 with "a" a random small constant to - test the part of mp_ilogb that uses native types. - */ - if (mp_rand(&a, 1) != MP_OKAY) { - goto LBL_ERR; - } - for (base = 2u; base < 65u; base++) { - if (mp_log_u32(&a, base, &lb) != MP_OKAY) { - goto LBL_ERR; - } - if (s_rs(&a,(int)base, &size) != MP_OKAY) { - goto LBL_ERR; - } - size -= 2; - if (lb != size) { - goto LBL_ERR; - } - } - - /*Test upper edgecase with base UINT32_MAX and number (UINT32_MAX/2)*UINT32_MAX^10 */ - mp_set(&a, max_base); - if (mp_expt_u32(&a, 10uL, &a) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_add_d(&a, max_base / 2, &a) != MP_OKAY) { - goto LBL_ERR; - } - if (mp_log_u32(&a, max_base, &lb) != MP_OKAY) { - goto LBL_ERR; - } - if (lb != 10u) { - goto LBL_ERR; - } - - mp_clear(&a); - return EXIT_SUCCESS; -LBL_ERR: - mp_clear(&a); - return EXIT_FAILURE; -} - -static int test_mp_incr(void) -{ - mp_int a, b; - mp_err e = MP_OKAY; - - if ((e = mp_init_multi(&a, &b, NULL)) != MP_OKAY) { - goto LTM_ERR; - } - - /* Does it increment inside the limits of a MP_xBIT limb? */ - mp_set(&a, MP_MASK/2); - if ((e = mp_incr(&a)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp_d(&a, (MP_MASK/2uL) + 1uL) != MP_EQ) { - goto LTM_ERR; - } - - /* Does it increment outside of the limits of a MP_xBIT limb? */ - mp_set(&a, MP_MASK); - mp_set(&b, MP_MASK); - if ((e = mp_incr(&a)) != MP_OKAY) { - goto LTM_ERR; - } - if ((e = mp_add_d(&b, 1uL, &b)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp(&a, &b) != MP_EQ) { - goto LTM_ERR; - } - - /* Does it increment from -1 to 0? */ - mp_set(&a, 1uL); - a.sign = MP_NEG; - if ((e = mp_incr(&a)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp_d(&a, 0uL) != MP_EQ) { - goto LTM_ERR; - } - - /* Does it increment from -(MP_MASK + 1) to -MP_MASK? */ - mp_set(&a, MP_MASK); - if ((e = mp_add_d(&a, 1uL, &a)) != MP_OKAY) { - goto LTM_ERR; - } - a.sign = MP_NEG; - if ((e = mp_incr(&a)) != MP_OKAY) { - goto LTM_ERR; - } - if (a.sign != MP_NEG) { - goto LTM_ERR; - } - a.sign = MP_ZPOS; - if (mp_cmp_d(&a, MP_MASK) != MP_EQ) { - goto LTM_ERR; - } - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LTM_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -} - -static int test_mp_decr(void) -{ - mp_int a, b; - mp_err e = MP_OKAY; - - if ((e = mp_init_multi(&a, &b, NULL)) != MP_OKAY) { - goto LTM_ERR; - } - - /* Does it decrement inside the limits of a MP_xBIT limb? */ - mp_set(&a, MP_MASK/2); - if ((e = mp_decr(&a)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp_d(&a, (MP_MASK/2uL) - 1uL) != MP_EQ) { - goto LTM_ERR; - } - - /* Does it decrement outside of the limits of a MP_xBIT limb? */ - mp_set(&a, MP_MASK); - if ((e = mp_add_d(&a, 1uL, &a)) != MP_OKAY) { - goto LTM_ERR; - } - if ((e = mp_decr(&a)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp_d(&a, MP_MASK) != MP_EQ) { - goto LTM_ERR; - } - - /* Does it decrement from 0 to -1? */ - mp_zero(&a); - if ((e = mp_decr(&a)) != MP_OKAY) { - goto LTM_ERR; - } - if (a.sign == MP_NEG) { - a.sign = MP_ZPOS; - if (mp_cmp_d(&a, 1uL) != MP_EQ) { - goto LTM_ERR; - } - } else { - goto LTM_ERR; - } - - - /* Does it decrement from -MP_MASK to -(MP_MASK + 1)? */ - mp_set(&a, MP_MASK); - a.sign = MP_NEG; - mp_set(&b, MP_MASK); - b.sign = MP_NEG; - if ((e = mp_sub_d(&b, 1uL, &b)) != MP_OKAY) { - goto LTM_ERR; - } - if ((e = mp_decr(&a)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp(&a, &b) != MP_EQ) { - goto LTM_ERR; - } - - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LTM_ERR: - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -} - -/* - Cannot test mp_exp(_d) without mp_root and vice versa. - So one of the two has to be tested from scratch. - - Numbers generated by - for i in {1..10} - do - seed=$(head -c 10000 /dev/urandom | tr -dc '[:digit:]' | head -c 120); - echo $seed; - convertbase $seed 10 64; - done - - (The program "convertbase" uses libtommath's to/from_radix functions) - - Roots were precalculated with Pari/GP - - default(realprecision,1000); - for(n=3,100,r = floor(a^(1/n));printf("\"" r "\", ")) - - All numbers as strings to simplifiy things, especially for the - low-mp branch. -*/ - -static int test_mp_root_u32(void) -{ - mp_int a, c, r; - mp_err e; - int i, j; - - const char *input[] = { - "4n9cbk886QtLQmofprid3l2Q0GD8Yv979Lh8BdZkFE8g2pDUUSMBET/+M/YFyVZ3mBp", - "5NlgzHhmIX05O5YoW5yW5reAlVNtRAlIcN2dfoATnNdc1Cw5lHZUTwNthmK6/ZLKfY6", - "3gweiHDX+ji5utraSe46IJX+uuh7iggs63xIpMP5MriU4Np+LpHI5are8RzS9pKh9xP", - "5QOJUSKMrfe7LkeyJOlupS8h7bjT+TXmZkDzOjZtfj7mdA7cbg0lRX3CuafhjIrpK8S", - "4HtYFldVkyVbrlg/s7kmaA7j45PvLQm+1bbn6ehgP8tVoBmGbv2yDQI1iQQze4AlHyN", - "3bwCUx79NAR7c68OPSp5ZabhZ9aBEr7rWNTO2oMY7zhbbbw7p6shSMxqE9K9nrTNucf", - "4j5RGb78TfuYSzrXn0z6tiAoWiRI81hGY3el9AEa9S+gN4x/AmzotHT2Hvj6lyBpE7q", - "4lwg30SXqZhEHNsl5LIXdyu7UNt0VTWebP3m7+WUL+hsnFW9xJe7UnzYngZsvWh14IE", - "1+tcqFeRuGqjRADRoRUJ8gL4UUSFQVrVVoV6JpwVcKsuBq5G0pABn0dLcQQQMViiVRj", - "hXwxuFySNSFcmbrs/coz4FUAaUYaOEt+l4V5V8vY71KyBvQPxRq/6lsSrG2FHvWDax" - }; - /* roots 3-100 of the above */ - const char *root[10][100] = { - { - "9163694094944489658600517465135586130944", - "936597377180979771960755204040", "948947857956884030956907", - "95727185767390496595", "133844854039712620", "967779611885360", - "20926191452627", "974139547476", "79203891950", "9784027073", - "1667309744", "365848129", "98268452", "31109156", "11275351", - "4574515", "2040800", "986985", "511525", "281431", "163096", - "98914", "62437", "40832", "27556", "19127", "13614", "9913", - "7367", "5577", "4294", "3357", "2662", "2138", "1738", "1428", - "1185", "993", "839", "715", "613", "530", "461", "403", "355", - "314", "279", "249", "224", "202", "182", "166", "151", "138", - "126", "116", "107", "99", "92", "85", "79", "74", "69", "65", "61", - "57", "54", "51", "48", "46", "43", "41", "39", "37", "36", "34", - "32", "31", "30", "28", "27", "26", "25", "24", "23", "23", "22", - "21", "20", "20", "19", "18", "18", "17", "17", "16", "16", "15" - }, { - "9534798256755061606359588498764080011382", - "964902943621813525741417593772", "971822399862464674540423", - "97646291566833512831", "136141536090599560", "982294733581430", - "21204945933335", "985810529393", "80066084985", "9881613813", - "1682654547", "368973625", "99051783", "31341581", "11354620", - "4604882", "2053633", "992879", "514434", "282959", "163942", - "99406", "62736", "41020", "27678", "19208", "13670", "9952", - "7395", "5598", "4310", "3369", "2671", "2145", "1744", "1433", - "1189", "996", "842", "717", "615", "531", "462", "404", "356", - "315", "280", "250", "224", "202", "183", "166", "151", "138", - "127", "116", "107", "99", "92", "85", "80", "74", "70", "65", "61", - "58", "54", "51", "48", "46", "43", "41", "39", "37", "36", "34", - "32", "31", "30", "29", "27", "26", "25", "24", "23", "23", "22", - "21", "20", "20", "19", "18", "18", "17", "17", "16", "16", "15" - }, { - "8398539113202579297642815367509019445624", - "877309458945432597462853440936", "900579899458998599215071", - "91643543761699761637", "128935656335800903", "936647990947203", - "20326748623514", "948988882684", "77342677787", "9573063447", - "1634096832", "359076114", "96569670", "30604705", "11103188", - "4508519", "2012897", "974160", "505193", "278105", "161251", - "97842", "61788", "40423", "27291", "18949", "13492", "9826", - "7305", "5532", "4260", "3332", "2642", "2123", "1726", "1418", - "1177", "986", "834", "710", "610", "527", "458", "401", "353", - "312", "278", "248", "223", "201", "181", "165", "150", "137", - "126", "116", "107", "99", "91", "85", "79", "74", "69", "65", "61", - "57", "54", "51", "48", "46", "43", "41", "39", "37", "35", "34", - "32", "31", "30", "28", "27", "26", "25", "24", "23", "22", "22", - "21", "20", "20", "19", "18", "18", "17", "17", "16", "16", "15" - }, { - "9559098494021810340217797724866627755195", - "966746709063325235560830083787", "973307706084821682248292", - "97770642291138756434", "136290128605981259", "983232784778520", - "21222944848922", "986563584410", "80121684894", "9887903837", - "1683643206", "369174929", "99102220", "31356542", "11359721", - "4606836", "2054458", "993259", "514621", "283057", "163997", - "99437", "62755", "41032", "27686", "19213", "13674", "9955", - "7397", "5599", "4311", "3370", "2672", "2146", "1744", "1433", - "1189", "996", "842", "717", "615", "532", "462", "404", "356", - "315", "280", "250", "224", "202", "183", "166", "151", "138", - "127", "116", "107", "99", "92", "86", "80", "74", "70", "65", "61", - "58", "54", "51", "48", "46", "43", "41", "39", "37", "36", "34", - "32", "31", "30", "29", "27", "26", "25", "24", "23", "23", "22", - "21", "20", "20", "19", "18", "18", "17", "17", "16", "16", "15" - }, { - "8839202025813295923132694443541993309220", - "911611499784863252820288596270", "928640961450376817534853", - "94017030509441723821", "131792686685970629", "954783483196511", - "20676214073400", "963660189823", "78428929840", "9696237956", - "1653495486", "363032624", "97562430", "30899570", "11203842", - "4547110", "2029216", "981661", "508897", "280051", "162331", - "98469", "62168", "40663", "27446", "19053", "13563", "9877", - "7341", "5558", "4280", "3347", "2654", "2132", "1733", "1424", - "1182", "990", "837", "713", "612", "529", "460", "402", "354", - "313", "279", "249", "223", "201", "182", "165", "150", "138", - "126", "116", "107", "99", "92", "85", "79", "74", "69", "65", "61", - "57", "54", "51", "48", "46", "43", "41", "39", "37", "36", "34", - "32", "31", "30", "28", "27", "26", "25", "24", "23", "23", "22", - "21", "20", "20", "19", "18", "18", "17", "17", "16", "16", "15" - }, { - "8338442683973420410660145045849076963795", - "872596990706967613912664152945", "896707843885562730147307", - "91315073695274540969", "128539440806486007", "934129001105825", - "20278149285734", "946946589774", "77191347471", "9555892093", - "1631391010", "358523975", "96431070", "30563524", "11089126", - "4503126", "2010616", "973111", "504675", "277833", "161100", - "97754", "61734", "40390", "27269", "18934", "13482", "9819", - "7300", "5528", "4257", "3330", "2641", "2122", "1725", "1417", - "1177", "986", "833", "710", "609", "527", "458", "401", "353", - "312", "278", "248", "222", "200", "181", "165", "150", "137", - "126", "116", "107", "99", "91", "85", "79", "74", "69", "65", "61", - "57", "54", "51", "48", "46", "43", "41", "39", "37", "35", "34", - "32", "31", "30", "28", "27", "26", "25", "24", "23", "22", "22", - "21", "20", "20", "19", "18", "18", "17", "17", "16", "16", "15" - }, { - "9122818552483814953977703257848970704164", - "933462289569511464780529972314", "946405863353935713909178", - "95513446972056321834", "133588658082928446", - "966158521967027", "20895030642048", "972833934108", - "79107381638", "9773098125", "1665590516", "365497822", - "98180628", "31083090", "11266459", "4571108", "2039360", - "986323", "511198", "281260", "163001", "98858", - "62404", "40811", "27543", "19117", "13608", "9908", - "7363", "5575", "4292", "3356", "2661", "2138", - "1737", "1428", "1185", "993", "839", "714", "613", - "530", "461", "403", "355", "314", "279", "249", - "224", "202", "182", "165", "151", "138", "126", - "116", "107", "99", "92", "85", "79", "74", "69", - "65", "61", "57", "54", "51", "48", "46", "43", - "41", "39", "37", "36", "34", "32", "31", "30", - "28", "27", "26", "25", "24", "23", "23", "22", - "21", "20", "20", "19", "18", "18", "17", "17", - "16", "16", "15" - }, { - "9151329724083804100369546479681933027521", - "935649419557299174433860420387", "948179413831316112751907", - "95662582675170358900", "133767426788182384", - "967289728859610", "20916775466497", "973745045600", - "79174731802", "9780725058", "1666790321", "365742295", - "98241919", "31101281", "11272665", "4573486", "2040365", - "986785", "511426", "281380", "163067", "98897", - "62427", "40826", "27552", "19124", "13612", "9911", - "7366", "5576", "4294", "3357", "2662", "2138", - "1738", "1428", "1185", "993", "839", "715", "613", - "530", "461", "403", "355", "314", "279", "249", - "224", "202", "182", "165", "151", "138", "126", - "116", "107", "99", "92", "85", "79", "74", "69", - "65", "61", "57", "54", "51", "48", "46", "43", - "41", "39", "37", "36", "34", "32", "31", "30", - "28", "27", "26", "25", "24", "23", "23", "22", - "21", "20", "20", "19", "18", "18", "17", "17", - "16", "16", "15" - }, { - "6839396355168045468586008471269923213531", - "752078770083218822016981965090", "796178899357307807726034", - "82700643015444840424", "118072966296549115", - "867224751770392", "18981881485802", "892288574037", - "73130030771", "9093989389", "1558462688", "343617470", - "92683740", "29448679", "10708016", "4356820", "1948676", - "944610", "490587", "270425", "156989", "95362", - "60284", "39477", "26675", "18536", "13208", "9627", - "7161", "5426", "4181", "3272", "2596", "2087", - "1697", "1395", "1159", "971", "821", "700", "601", - "520", "452", "396", "348", "308", "274", "245", - "220", "198", "179", "163", "148", "136", "124", - "114", "106", "98", "91", "84", "78", "73", "68", - "64", "60", "57", "53", "50", "48", "45", "43", - "41", "39", "37", "35", "34", "32", "31", "29", - "28", "27", "26", "25", "24", "23", "22", "22", - "21", "20", "19", "19", "18", "18", "17", "17", - "16", "16", "15" - }, { - "4788090721380022347683138981782307670424", - "575601315594614059890185238256", "642831903229558719812840", - "69196031110028430211", "101340693763170691", - "758683936560287", "16854690815260", "801767985909", - "66353290503", "8318415180", "1435359033", "318340531", - "86304307", "27544217", "10054988", "4105446", "1841996", - "895414", "466223", "257591", "149855", "91205", - "57758", "37886", "25639", "17842", "12730", "9290", - "6918", "5248", "4048", "3170", "2518", "2026", - "1649", "1357", "1128", "946", "800", "682", "586", - "507", "441", "387", "341", "302", "268", "240", - "215", "194", "176", "160", "146", "133", "122", - "112", "104", "96", "89", "83", "77", "72", "67", - "63", "59", "56", "53", "50", "47", "45", "42", - "40", "38", "36", "35", "33", "32", "30", "29", - "28", "27", "26", "25", "24", "23", "22", "21", - "21", "20", "19", "19", "18", "17", "17", "16", - "16", "15", "15" - } - }; - - if ((e = mp_init_multi(&a, &c, &r, NULL)) != MP_OKAY) { - return EXIT_FAILURE; - } -#ifdef MP_8BIT - for (i = 0; i < 1; i++) { -#else - for (i = 0; i < 10; i++) { -#endif - mp_read_radix(&a, input[i], 64); -#ifdef MP_8BIT - for (j = 3; j < 10; j++) { -#else - for (j = 3; j < 100; j++) { -#endif - mp_root_u32(&a, (uint32_t)j, &c); - mp_read_radix(&r, root[i][j-3], 10); - if (mp_cmp(&r, &c) != MP_EQ) { - fprintf(stderr, "mp_root_u32 failed at input #%d, root #%d\n", i, j); - goto LTM_ERR; - } - } - } - mp_clear_multi(&a, &c, &r, NULL); - return EXIT_SUCCESS; -LTM_ERR: - mp_clear_multi(&a, &c, &r, NULL); - return EXIT_FAILURE; -} - -static int test_s_mp_balance_mul(void) -{ - mp_int a, b, c; - mp_err e = MP_OKAY; - - const char *na = - "4b0I5uMTujCysw+1OOuOyH2FX2WymrHUqi8BBDb7XpkV/4i7vXTbEYUy/kdIfCKu5jT5JEqYkdmnn3jAYo8XShPzNLxZx9yoLjxYRyptSuOI2B1DspvbIVYXY12sxPZ4/HCJ4Usm2MU5lO/006KnDMxuxiv1rm6YZJZ0eZU"; - const char *nb = "3x9vs0yVi4hIq7poAeVcggC3WoRt0zRLKO"; - const char *nc = - "HzrSq9WVt1jDTVlwUxSKqxctu2GVD+N8+SVGaPFRqdxyld6IxDBbj27BPJzYUdR96k3sWpkO8XnDBvupGPnehpQe4KlO/KmN1PjFov/UTZYM+LYzkFcBPyV6hkkL8ePC1rlFLAHzgJMBCXVp4mRqtkQrDsZXXlcqlbTFu69wF6zDEysiX2cAtn/kP9ldblJiwYPCD8hG"; - - if ((e = mp_init_multi(&a, &b, &c, NULL)) != MP_OKAY) { - goto LTM_ERR; - } - - if ((e = mp_read_radix(&a, na, 64)) != MP_OKAY) { - goto LTM_ERR; - } - if ((e = mp_read_radix(&b, nb, 64)) != MP_OKAY) { - goto LTM_ERR; - } - - if ((e = s_mp_balance_mul(&a, &b, &c)) != MP_OKAY) { - goto LTM_ERR; - } - - if ((e = mp_read_radix(&b, nc, 64)) != MP_OKAY) { - goto LTM_ERR; - } - - if (mp_cmp(&b, &c) != MP_EQ) { - goto LTM_ERR; - } - - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LTM_ERR: - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1) -static int test_s_mp_karatsuba_mul(void) -{ - mp_int a, b, c, d; - int size, err; - - if ((err = mp_init_multi(&a, &b, &c, &d, NULL)) != MP_OKAY) { - goto LTM_ERR; - } - for (size = MP_KARATSUBA_MUL_CUTOFF; size < MP_KARATSUBA_MUL_CUTOFF + 20; size++) { - if ((err = mp_rand(&a, size)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = mp_rand(&b, size)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = s_mp_karatsuba_mul(&a, &b, &c)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = s_mp_mul(&a,&b,&d)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp(&c, &d) != MP_EQ) { - fprintf(stderr, "Karatsuba multiplication failed at size %d\n", size); - goto LTM_ERR; - } - } - - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_SUCCESS; -LTM_ERR: - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_FAILURE; -} - -static int test_s_mp_karatsuba_sqr(void) -{ - mp_int a, b, c; - int size, err; - - if ((err = mp_init_multi(&a, &b, &c, NULL)) != MP_OKAY) { - goto LTM_ERR; - } - for (size = MP_KARATSUBA_SQR_CUTOFF; size < MP_KARATSUBA_SQR_CUTOFF + 20; size++) { - if ((err = mp_rand(&a, size)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = s_mp_karatsuba_sqr(&a, &b)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = s_mp_sqr(&a, &c)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp(&b, &c) != MP_EQ) { - fprintf(stderr, "Karatsuba squaring failed at size %d\n", size); - goto LTM_ERR; - } - } - - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LTM_ERR: - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -static int test_s_mp_toom_mul(void) -{ - mp_int a, b, c, d; - int size, err; - -#if (MP_DIGIT_BIT == 60) - int tc_cutoff; -#endif - - if ((err = mp_init_multi(&a, &b, &c, &d, NULL)) != MP_OKAY) { - goto LTM_ERR; - } - /* This number construction is limb-size specific */ -#if (MP_DIGIT_BIT == 60) - if ((err = mp_rand(&a, 1196)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = mp_mul_2d(&a,71787 - mp_count_bits(&a), &a)) != MP_OKAY) { - goto LTM_ERR; - } - - if ((err = mp_rand(&b, 1338)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = mp_mul_2d(&b, 80318 - mp_count_bits(&b), &b)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = mp_mul_2d(&b, 6310, &b)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = mp_2expt(&c, 99000 - 1000)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = mp_add(&b, &c, &b)) != MP_OKAY) { - goto LTM_ERR; - } - - tc_cutoff = TOOM_MUL_CUTOFF; - TOOM_MUL_CUTOFF = INT_MAX; - if ((err = mp_mul(&a, &b, &c)) != MP_OKAY) { - goto LTM_ERR; - } - TOOM_MUL_CUTOFF = tc_cutoff; - if ((err = mp_mul(&a, &b, &d)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp(&c, &d) != MP_EQ) { - fprintf(stderr, "Toom-Cook 3-way multiplication failed for edgecase f1 * f2\n"); - goto LTM_ERR; - } -#endif - - for (size = MP_TOOM_MUL_CUTOFF; size < MP_TOOM_MUL_CUTOFF + 20; size++) { - if ((err = mp_rand(&a, size)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = mp_rand(&b, size)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = s_mp_toom_mul(&a, &b, &c)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = s_mp_mul(&a,&b,&d)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp(&c, &d) != MP_EQ) { - fprintf(stderr, "Toom-Cook 3-way multiplication failed at size %d\n", size); - goto LTM_ERR; - } - } - - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_SUCCESS; -LTM_ERR: - mp_clear_multi(&a, &b, &c, &d, NULL); - return EXIT_FAILURE; -} - -static int test_s_mp_toom_sqr(void) -{ - mp_int a, b, c; - int size, err; - - if ((err = mp_init_multi(&a, &b, &c, NULL)) != MP_OKAY) { - goto LTM_ERR; - } - for (size = MP_TOOM_SQR_CUTOFF; size < MP_TOOM_SQR_CUTOFF + 20; size++) { - if ((err = mp_rand(&a, size)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = s_mp_toom_sqr(&a, &b)) != MP_OKAY) { - goto LTM_ERR; - } - if ((err = s_mp_sqr(&a, &c)) != MP_OKAY) { - goto LTM_ERR; - } - if (mp_cmp(&b, &c) != MP_EQ) { - fprintf(stderr, "Toom-Cook 3-way squaring failed at size %d\n", size); - goto LTM_ERR; - } - } - - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LTM_ERR: - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -static int test_mp_read_write_ubin(void) -{ - mp_int a, b, c; - int err; - size_t size, len; - unsigned char *buf = NULL; - - if ((err = mp_init_multi(&a, &b, &c, NULL)) != MP_OKAY) { - goto LTM_ERR; - } - - if ((err = mp_rand(&a, 15)) != MP_OKAY) goto LTM_ERR; - if ((err = mp_neg(&a, &b)) != MP_OKAY) goto LTM_ERR; - - size = mp_ubin_size(&a); - printf("mp_to_ubin_size %zu\n", size); - buf = (unsigned char *)malloc(sizeof(*buf) * size); - if (buf == NULL) { - fprintf(stderr, "test_read_write_binaries (u) failed to allocate %zu bytes\n", - sizeof(*buf) * size); - goto LTM_ERR; - } - - if ((err = mp_to_ubin(&a, buf, size, &len)) != MP_OKAY) goto LTM_ERR; - printf("mp_to_ubin len = %zu\n", len); - - if ((err = mp_from_ubin(&c, buf, len)) != MP_OKAY) goto LTM_ERR; - - if (mp_cmp(&a, &c) != MP_EQ) { - fprintf(stderr, "to/from ubin cycle failed\n"); - goto LTM_ERR; - } - free(buf); - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LTM_ERR: - free(buf); - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -static int test_mp_read_write_sbin(void) -{ - mp_int a, b, c; - int err; - size_t size, len; - unsigned char *buf = NULL; - - if ((err = mp_init_multi(&a, &b, &c, NULL)) != MP_OKAY) { - goto LTM_ERR; - } - - if ((err = mp_rand(&a, 15)) != MP_OKAY) goto LTM_ERR; - if ((err = mp_neg(&a, &b)) != MP_OKAY) goto LTM_ERR; - - size = mp_sbin_size(&a); - printf("mp_to_sbin_size %zu\n", size); - buf = (unsigned char *)malloc(sizeof(*buf) * size); - if (buf == NULL) { - fprintf(stderr, "test_read_write_binaries (s) failed to allocate %zu bytes\n", - sizeof(*buf) * size); - goto LTM_ERR; - } - - if ((err = mp_to_sbin(&b, buf, size, &len)) != MP_OKAY) goto LTM_ERR; - printf("mp_to_sbin len = %zu\n", len); - - if ((err = mp_from_sbin(&c, buf, len)) != MP_OKAY) goto LTM_ERR; - - if (mp_cmp(&b, &c) != MP_EQ) { - fprintf(stderr, "to/from ubin cycle failed\n"); - goto LTM_ERR; - } - - free(buf); - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_SUCCESS; -LTM_ERR: - free(buf); - mp_clear_multi(&a, &b, &c, NULL); - return EXIT_FAILURE; -} - -static int test_mp_pack_unpack(void) -{ - mp_int a, b; - int err; - size_t written, count; - unsigned char *buf = NULL; - - mp_order order = MP_LSB_FIRST; - mp_endian endianess = MP_NATIVE_ENDIAN; - - if ((err = mp_init_multi(&a, &b, NULL)) != MP_OKAY) goto LTM_ERR; - if ((err = mp_rand(&a, 15)) != MP_OKAY) goto LTM_ERR; - - count = mp_pack_count(&a, 0, 1); - - buf = (unsigned char *)malloc(count); - if (buf == NULL) { - fprintf(stderr, "test_pack_unpack failed to allocate\n"); - goto LTM_ERR; - } - - if ((err = mp_pack((void *)buf, count, &written, order, 1, - endianess, 0, &a)) != MP_OKAY) goto LTM_ERR; - if ((err = mp_unpack(&b, count, order, 1, - endianess, 0, (const void *)buf)) != MP_OKAY) goto LTM_ERR; - - if (mp_cmp(&a, &b) != MP_EQ) { - fprintf(stderr, "pack/unpack cycle failed\n"); - goto LTM_ERR; - } - - free(buf); - mp_clear_multi(&a, &b, NULL); - return EXIT_SUCCESS; -LTM_ERR: - free(buf); - mp_clear_multi(&a, &b, NULL); - return EXIT_FAILURE; -} - -static int unit_tests(int argc, char **argv) -{ - static const struct { - const char *name; - int (*fn)(void); - } test[] = { -#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_pack_unpack,MP_PACK, MP_UNPACK), - 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_log_u32, MP_LOG_U32), - 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_read_write_ubin, MP_TO_UBIN), - T1(mp_read_write_sbin, MP_TO_SBIN), - 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) - T1(mp_set_double, MP_SET_DOUBLE), -#endif - 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, ok, fail, nop; - uint64_t t; - int j; - - 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) { - if (argc > 1) { - for (j = 1; j < argc; ++j) { - if (strstr(test[i].name, argv[j]) != NULL) { - break; - } - } - if (j == argc) continue; - } - printf("TEST %s\n\n", test[i].name); - 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); - } - } - printf("Tests OK/NOP/FAIL: %lu/%lu/%lu\n", ok, nop, fail); - - if (fail != 0) return EXIT_FAILURE; - else return EXIT_SUCCESS; -} - -int main(int argc, char **argv) -{ - print_header(); - - return unit_tests(argc, argv); -} diff --git a/libtommath/helper.pl b/libtommath/helper.pl deleted file mode 100755 index c624b7c..0000000 --- a/libtommath/helper.pl +++ /dev/null @@ -1,482 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -use Getopt::Long; -use File::Find 'find'; -use File::Basename 'basename'; -use File::Glob 'bsd_glob'; - -sub read_file { - my $f = shift; - open my $fh, "<", $f or die "FATAL: read_rawfile() cannot open file '$f': $!"; - binmode $fh; - return do { local $/; <$fh> }; -} - -sub write_file { - my ($f, $data) = @_; - die "FATAL: write_file() no data" unless defined $data; - open my $fh, ">", $f or die "FATAL: write_file() cannot open file '$f': $!"; - binmode $fh; - print $fh $data or die "FATAL: write_file() cannot write to '$f': $!"; - close $fh or die "FATAL: write_file() cannot close '$f': $!"; - return; -} - -sub sanitize_comments { - my($content) = @_; - $content =~ s{/\*(.*?)\*/}{my $x=$1; $x =~ s/\w/x/g; "/*$x*/";}egs; - return $content; -} - -sub check_source { - my @all_files = ( - bsd_glob("makefile*"), - bsd_glob("*.{h,c,sh,pl}"), - bsd_glob("*/*.{h,c,sh,pl}"), - ); - - my $fails = 0; - for my $file (sort @all_files) { - my $troubles = {}; - my $lineno = 1; - my $content = read_file($file); - $content = sanitize_comments $content; - push @{$troubles->{crlf_line_end}}, '?' if $content =~ /\r/; - for my $l (split /\n/, $content) { - push @{$troubles->{merge_conflict}}, $lineno if $l =~ /^(<<<<<<<|=======|>>>>>>>)([^<=>]|$)/; - push @{$troubles->{trailing_space}}, $lineno if $l =~ / $/; - push @{$troubles->{tab}}, $lineno if $l =~ /\t/ && basename($file) !~ /^makefile/i; - push @{$troubles->{non_ascii_char}}, $lineno if $l =~ /[^[:ascii:]]/; - push @{$troubles->{cpp_comment}}, $lineno if $file =~ /\.(c|h)$/ && ($l =~ /\s\/\// || $l =~ /\/\/\s/); - # we prefer using MP_MALLOC, MP_FREE, MP_REALLOC, MP_CALLOC ... - push @{$troubles->{unwanted_malloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmalloc\s*\(/; - push @{$troubles->{unwanted_realloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\brealloc\s*\(/; - push @{$troubles->{unwanted_calloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bcalloc\s*\(/; - push @{$troubles->{unwanted_free}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bfree\s*\(/; - # and we probably want to also avoid the following - push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcpy\s*\(/; - push @{$troubles->{unwanted_memset}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemset\s*\(/; - push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcpy\s*\(/; - push @{$troubles->{unwanted_memmove}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemmove\s*\(/; - push @{$troubles->{unwanted_memcmp}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcmp\s*\(/; - push @{$troubles->{unwanted_strcmp}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrcmp\s*\(/; - push @{$troubles->{unwanted_strcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrcpy\s*\(/; - push @{$troubles->{unwanted_strncpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrncpy\s*\(/; - push @{$troubles->{unwanted_clock}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bclock\s*\(/; - push @{$troubles->{unwanted_qsort}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bqsort\s*\(/; - push @{$troubles->{sizeof_no_brackets}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bsizeof\s*[^\(]/; - if ($file =~ m|^[^\/]+\.c$| && $l =~ /^static(\s+[a-zA-Z0-9_]+)+\s+([a-zA-Z0-9_]+)\s*\(/) { - my $funcname = $2; - # static functions should start with s_ - push @{$troubles->{staticfunc_name}}, "$lineno($funcname)" if $funcname !~ /^s_/; - } - $lineno++; - } - for my $k (sort keys %$troubles) { - warn "[$k] $file line:" . join(",", @{$troubles->{$k}}) . "\n"; - $fails++; - } - } - - warn( $fails > 0 ? "check-source: FAIL $fails\n" : "check-source: PASS\n" ); - return $fails; -} - -sub check_comments { - my $fails = 0; - my $first_comment = <<'MARKER'; -/* LibTomMath, multiple-precision integer library -- Tom St Denis */ -/* SPDX-License-Identifier: Unlicense */ -MARKER - #my @all_files = (bsd_glob("*.{h,c}"), bsd_glob("*/*.{h,c}")); - my @all_files = (bsd_glob("*.{h,c}")); - for my $f (@all_files) { - my $txt = read_file($f); - if ($txt !~ /\Q$first_comment\E/s) { - warn "[first_comment] $f\n"; - $fails++; - } - } - warn( $fails > 0 ? "check-comments: FAIL $fails\n" : "check-comments: PASS\n" ); - return $fails; -} - -sub check_doc { - my $fails = 0; - my $tex = read_file('doc/bn.tex'); - my $tmh = read_file('tommath.h'); - my @functions = $tmh =~ /\n\s*[a-zA-Z0-9_* ]+?(mp_[a-z0-9_]+)\s*\([^\)]+\)\s*;/sg; - my @macros = $tmh =~ /\n\s*#define\s+([a-z0-9_]+)\s*\([^\)]+\)/sg; - for my $n (sort @functions) { - (my $nn = $n) =~ s/_/\\_/g; # mp_sub_d >> mp\_sub\_d - if ($tex !~ /index\Q{$nn}\E/) { - warn "[missing_doc_for_function] $n\n"; - $fails++ - } - } - for my $n (sort @macros) { - (my $nn = $n) =~ s/_/\\_/g; # mp_iszero >> mp\_iszero - if ($tex !~ /index\Q{$nn}\E/) { - warn "[missing_doc_for_macro] $n\n"; - $fails++ - } - } - warn( $fails > 0 ? "check_doc: FAIL $fails\n" : "check-doc: PASS\n" ); - return $fails; -} - -sub prepare_variable { - my ($varname, @list) = @_; - my $output = "$varname="; - my $len = length($output); - foreach my $obj (sort @list) { - $len = $len + length $obj; - $obj =~ s/\*/\$/; - if ($len > 100) { - $output .= "\\\n"; - $len = length $obj; - } - $output .= $obj . ' '; - } - $output =~ s/ $//; - return $output; -} - -sub prepare_msvc_files_xml { - my ($all, $exclude_re, $targets) = @_; - my $last = []; - my $depth = 2; - - # sort files in the same order as visual studio (ugly, I know) - my @parts = (); - for my $orig (@$all) { - my $p = $orig; - $p =~ s|/|/~|g; - $p =~ s|/~([^/]+)$|/$1|g; - my @l = map { sprintf "% -99s", $_ } split /\//, $p; - push @parts, [ $orig, join(':', @l) ]; - } - my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } @parts; - - my $files = "\r\n"; - for my $full (@sorted) { - my @items = split /\//, $full; # split by '/' - $full =~ s|/|\\|g; # replace '/' bt '\' - shift @items; # drop first one (src) - pop @items; # drop last one (filename.ext) - my $current = \@items; - if (join(':', @$current) ne join(':', @$last)) { - my $common = 0; - $common++ while ($last->[$common] && $current->[$common] && $last->[$common] eq $current->[$common]); - my $back = @$last - $common; - if ($back > 0) { - $files .= ("\t" x --$depth) . "\r\n" for (1..$back); - } - my $fwd = [ @$current ]; splice(@$fwd, 0, $common); - for my $i (0..scalar(@$fwd) - 1) { - $files .= ("\t" x $depth) . "[$i]\"\r\n"; - $files .= ("\t" x $depth) . "\t>\r\n"; - $depth++; - } - $last = $current; - } - $files .= ("\t" x $depth) . "\r\n"; - if ($full =~ $exclude_re) { - for (@$targets) { - $files .= ("\t" x $depth) . "\t\r\n"; - $files .= ("\t" x $depth) . "\t\t\r\n"; - $files .= ("\t" x $depth) . "\t\r\n"; - } - } - $files .= ("\t" x $depth) . "\r\n"; - } - $files .= ("\t" x --$depth) . "\r\n" for (@$last); - $files .= "\t"; - return $files; -} - -sub patch_file { - my ($content, @variables) = @_; - for my $v (@variables) { - if ($v =~ /^([A-Z0-9_]+)\s*=.*$/si) { - my $name = $1; - $content =~ s/\n\Q$name\E\b.*?[^\\]\n/\n$v\n/s; - } - else { - die "patch_file failed: " . substr($v, 0, 30) . ".."; - } - } - return $content; -} - -sub process_makefiles { - my $write = shift; - my $changed_count = 0; - my @o = map { my $x = $_; $x =~ s/\.c$/.o/; $x } bsd_glob("*.c"); - my @all = bsd_glob("*.{c,h}"); - - my $var_o = prepare_variable("OBJECTS", @o); - (my $var_obj = $var_o) =~ s/\.o\b/.obj/sg; - - # update MSVC project files - my $msvc_files = prepare_msvc_files_xml(\@all, qr/NOT_USED_HERE/, ['Debug|Win32', 'Release|Win32', 'Debug|x64', 'Release|x64']); - for my $m (qw/libtommath_VS2008.vcproj/) { - my $old = read_file($m); - my $new = $old; - $new =~ s|.*|$msvc_files|s; - if ($old ne $new) { - write_file($m, $new) if $write; - warn "changed: $m\n"; - $changed_count++; - } - } - - # update OBJECTS + HEADERS in makefile* - for my $m (qw/ makefile makefile.shared makefile_include.mk makefile.msvc makefile.unix makefile.mingw /) { - my $old = read_file($m); - my $new = $m eq 'makefile.msvc' ? patch_file($old, $var_obj) - : patch_file($old, $var_o); - if ($old ne $new) { - write_file($m, $new) if $write; - warn "changed: $m\n"; - $changed_count++; - } - } - - if ($write) { - return 0; # no failures - } - else { - warn( $changed_count > 0 ? "check-makefiles: FAIL $changed_count\n" : "check-makefiles: PASS\n" ); - return $changed_count; - } -} - -sub draw_func -{ - my ($deplist, $depmap, $out, $indent, $funcslist) = @_; - my @funcs = split ',', $funcslist; - # try this if you want to have a look at a minimized version of the callgraph without all the trivial functions - #if ($deplist =~ /$funcs[0]/ || $funcs[0] =~ /BN_MP_(ADD|SUB|CLEAR|CLEAR_\S+|DIV|MUL|COPY|ZERO|GROW|CLAMP|INIT|INIT_\S+|SET|ABS|CMP|CMP_D|EXCH)_C/) { - if ($deplist =~ /$funcs[0]/) { - return $deplist; - } else { - $deplist = $deplist . $funcs[0]; - } - if ($indent == 0) { - } elsif ($indent >= 1) { - print {$out} '| ' x ($indent - 1) . '+--->'; - } - print {$out} $funcs[0] . "\n"; - shift @funcs; - my $olddeplist = $deplist; - foreach my $i (@funcs) { - $deplist = draw_func($deplist, $depmap, $out, $indent + 1, ${$depmap}{$i}) if exists ${$depmap}{$i}; - } - return $olddeplist; -} - -sub update_dep -{ - #open class file and write preamble - open(my $class, '>', 'tommath_class.h') or die "Couldn't open tommath_class.h for writing\n"; - print {$class} << 'EOS'; -/* LibTomMath, multiple-precision integer library -- Tom St Denis */ -/* SPDX-License-Identifier: Unlicense */ - -#if !(defined(LTM1) && defined(LTM2) && defined(LTM3)) -#define LTM_INSIDE -#if defined(LTM2) -# define LTM3 -#endif -#if defined(LTM1) -# define LTM2 -#endif -#define LTM1 -#if defined(LTM_ALL) -EOS - - foreach my $filename (glob 'bn*.c') { - my $define = $filename; - - print "Processing $filename\n"; - - # convert filename to upper case so we can use it as a define - $define =~ tr/[a-z]/[A-Z]/; - $define =~ tr/\./_/; - print {$class} "# define $define\n"; - - # now copy text and apply #ifdef as required - my $apply = 0; - open(my $src, '<', $filename); - open(my $out, '>', 'tmp'); - - # first line will be the #ifdef - my $line = <$src>; - if ($line =~ /include/) { - print {$out} $line; - } else { - print {$out} << "EOS"; -#include "tommath_private.h" -#ifdef $define -/* LibTomMath, multiple-precision integer library -- Tom St Denis */ -/* SPDX-License-Identifier: Unlicense */ -$line -EOS - $apply = 1; - } - while (<$src>) { - if ($_ !~ /tommath\.h/) { - print {$out} $_; - } - } - if ($apply == 1) { - print {$out} "#endif\n"; - } - close $src; - close $out; - - unlink $filename; - rename 'tmp', $filename; - } - print {$class} "#endif\n#endif\n"; - - # now do classes - my %depmap; - foreach my $filename (glob 'bn*.c') { - my $content; - if ($filename =~ "bn_deprecated.c") { - open(my $src, '<', $filename) or die "Can't open source file!\n"; - read $src, $content, -s $src; - close $src; - } else { - my $cc = $ENV{'CC'} || 'gcc'; - $content = `$cc -E -x c -DLTM_ALL $filename`; - $content =~ s/^# 1 "$filename".*?^# 2 "$filename"//ms; - } - - # convert filename to upper case so we can use it as a define - $filename =~ tr/[a-z]/[A-Z]/; - $filename =~ tr/\./_/; - - print {$class} "#if defined($filename)\n"; - my $list = $filename; - - # strip comments - $content =~ s{/\*.*?\*/}{}gs; - - # 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) { - my $a = $&; - next if $a eq "mp_err"; - $a =~ tr/[a-z]/[A-Z]/; - $a = 'BN_' . $a . '_C'; - push @deps, $a; - } - } - @deps = sort(@deps); - foreach my $a (@deps) { - if ($list !~ /$a/) { - print {$class} "# define $a\n"; - } - $list = $list . ',' . $a; - } - $depmap{$filename} = $list; - - print {$class} "#endif\n\n"; - } - - print {$class} << 'EOS'; -#ifdef LTM_INSIDE -#undef LTM_INSIDE -#ifdef LTM3 -# define LTM_LAST -#endif - -#include "tommath_superclass.h" -#include "tommath_class.h" -#else -# define LTM_LAST -#endif -EOS - close $class; - - #now let's make a cool call graph... - - open(my $out, '>', 'callgraph.txt'); - foreach (sort keys %depmap) { - draw_func("", \%depmap, $out, 0, $depmap{$_}); - print {$out} "\n\n"; - } - close $out; - - return 0; -} - -sub generate_def { - my @files = split /\n/, `git ls-files`; - @files = grep(/\.c/, @files); - @files = map { my $x = $_; $x =~ s/^bn_|\.c$//g; $x; } @files; - @files = grep(!/mp_radix_smap/, @files); - - push(@files, qw(mp_set_int mp_set_long mp_set_long_long mp_get_int mp_get_long mp_get_long_long mp_init_set_int)); - - my $files = join("\n ", sort(grep(/^mp_/, @files))); - write_file "tommath.def", "; libtommath -; -; Use this command to produce a 32-bit .lib file, for use in any MSVC version -; lib -machine:X86 -name:libtommath.dll -def:tommath.def -out:tommath.lib -; Use this command to produce a 64-bit .lib file, for use in any MSVC version -; lib -machine:X64 -name:libtommath.dll -def:tommath.def -out:tommath.lib -; -EXPORTS - $files -"; - return 0; -} - -sub die_usage { - die <<"MARKER"; -usage: $0 -s OR $0 --check-source - $0 -o OR $0 --check-comments - $0 -m OR $0 --check-makefiles - $0 -a OR $0 --check-all - $0 -u OR $0 --update-files -MARKER -} - -GetOptions( "s|check-source" => \my $check_source, - "o|check-comments" => \my $check_comments, - "m|check-makefiles" => \my $check_makefiles, - "d|check-doc" => \my $check_doc, - "a|check-all" => \my $check_all, - "u|update-files" => \my $update_files, - "h|help" => \my $help - ) or die_usage; - -my $failure; -$failure ||= check_source() if $check_all || $check_source; -$failure ||= check_comments() if $check_all || $check_comments; -$failure ||= check_doc() if $check_doc; # temporarily excluded from --check-all -$failure ||= process_makefiles(0) if $check_all || $check_makefiles; -$failure ||= process_makefiles(1) if $update_files; -$failure ||= update_dep() if $update_files; -$failure ||= generate_def() if $update_files; - -die_usage unless defined $failure; -exit $failure ? 1 : 0; diff --git a/libtommath/libtommath_VS2008.sln b/libtommath/libtommath_VS2008.sln deleted file mode 100644 index 3bd6688..0000000 --- a/libtommath/libtommath_VS2008.sln +++ /dev/null @@ -1,29 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tommath", "libtommath_VS2008.vcproj", "{42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|Win32.ActiveCfg = Debug|Win32 - {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|Win32.Build.0 = Debug|Win32 - {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|x64.ActiveCfg = Debug|x64 - {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|x64.Build.0 = Debug|x64 - {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|Win32.ActiveCfg = Release|Win32 - {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|Win32.Build.0 = Release|Win32 - {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|x64.ActiveCfg = Release|x64 - {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {83B84178-7B4F-4B78-9C5D-17B8201D5B61} - EndGlobalSection -EndGlobal diff --git a/libtommath/libtommath_VS2008.vcproj b/libtommath/libtommath_VS2008.vcproj deleted file mode 100644 index 67cc89b..0000000 --- a/libtommath/libtommath_VS2008.vcproj +++ /dev/null @@ -1,966 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libtommath/makefile b/libtommath/makefile deleted file mode 100644 index be9fac6..0000000 --- a/libtommath/makefile +++ /dev/null @@ -1,165 +0,0 @@ -#Makefile for GCC -# -#Tom St Denis - -ifeq ($V,1) -silent= -else -silent=@ -endif - -#default files to install -ifndef LIBNAME - LIBNAME=libtommath.a -endif - -coverage: LIBNAME:=-Wl,--whole-archive $(LIBNAME) -Wl,--no-whole-archive - -include makefile_include.mk - -%.o: %.c $(HEADERS) -ifneq ($V,1) - @echo " * ${CC} $@" -endif - ${silent} ${CC} -c ${LTM_CFLAGS} $< -o $@ - -LCOV_ARGS=--directory . - -#START_INS -OBJECTS=bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o bn_mp_addmod.o \ -bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \ -bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_decr.o bn_mp_div.o bn_mp_div_2.o \ -bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o \ -bn_mp_error_to_string.o bn_mp_exch.o bn_mp_expt_u32.o bn_mp_exptmod.o bn_mp_exteuclid.o bn_mp_fread.o \ -bn_mp_from_sbin.o bn_mp_from_ubin.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_i32.o \ -bn_mp_get_i64.o bn_mp_get_l.o bn_mp_get_ll.o bn_mp_get_mag_u32.o bn_mp_get_mag_u64.o bn_mp_get_mag_ul.o \ -bn_mp_get_mag_ull.o bn_mp_grow.o bn_mp_incr.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_i32.o \ -bn_mp_init_i64.o bn_mp_init_l.o bn_mp_init_ll.o bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_size.o \ -bn_mp_init_u32.o bn_mp_init_u64.o bn_mp_init_ul.o bn_mp_init_ull.o bn_mp_invmod.o bn_mp_is_square.o \ -bn_mp_iseven.o bn_mp_isodd.o bn_mp_kronecker.o bn_mp_lcm.o bn_mp_log_u32.o bn_mp_lshd.o bn_mp_mod.o \ -bn_mp_mod_2d.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \ -bn_mp_montgomery_setup.o bn_mp_mul.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_mulmod.o bn_mp_neg.o \ -bn_mp_or.o bn_mp_pack.o bn_mp_pack_count.o bn_mp_prime_fermat.o bn_mp_prime_frobenius_underwood.o \ -bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ -bn_mp_prime_rabin_miller_trials.o bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o \ -bn_mp_radix_size.o bn_mp_radix_smap.o bn_mp_rand.o bn_mp_read_radix.o bn_mp_reduce.o bn_mp_reduce_2k.o \ -bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o bn_mp_reduce_is_2k.o \ -bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_root_u32.o bn_mp_rshd.o bn_mp_sbin_size.o bn_mp_set.o \ -bn_mp_set_double.o bn_mp_set_i32.o bn_mp_set_i64.o bn_mp_set_l.o bn_mp_set_ll.o bn_mp_set_u32.o \ -bn_mp_set_u64.o bn_mp_set_ul.o bn_mp_set_ull.o bn_mp_shrink.o bn_mp_signed_rsh.o bn_mp_sqr.o \ -bn_mp_sqrmod.o bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o \ -bn_mp_to_radix.o bn_mp_to_sbin.o bn_mp_to_ubin.o bn_mp_ubin_size.o bn_mp_unpack.o bn_mp_xor.o bn_mp_zero.o \ -bn_prime_tab.o bn_s_mp_add.o bn_s_mp_balance_mul.o bn_s_mp_exptmod.o bn_s_mp_exptmod_fast.o \ -bn_s_mp_get_bit.o bn_s_mp_invmod_fast.o bn_s_mp_invmod_slow.o bn_s_mp_karatsuba_mul.o \ -bn_s_mp_karatsuba_sqr.o bn_s_mp_montgomery_reduce_fast.o bn_s_mp_mul_digs.o bn_s_mp_mul_digs_fast.o \ -bn_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs_fast.o bn_s_mp_prime_is_divisible.o \ -bn_s_mp_rand_jenkins.o bn_s_mp_rand_platform.o bn_s_mp_reverse.o 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_sqr.o - -#END_INS - -$(LIBNAME): $(OBJECTS) - $(AR) $(ARFLAGS) $@ $(OBJECTS) - $(RANLIB) $@ - -#make a profiled library (takes a while!!!) -# -# This will build the library with profile generation -# then run the test demo and rebuild the library. -# -# So far I've seen improvements in the MP math -profiled: - make CFLAGS="$(CFLAGS) -fprofile-arcs -DTESTING" timing - ./timing - rm -f *.a *.o timing - make CFLAGS="$(CFLAGS) -fbranch-probabilities" - -#make a single object profiled library -profiled_single: - perl gen.pl - $(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) $(LTM_CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o - $(AR) $(ARFLAGS) $(LIBNAME) mpi.o - ranlib $(LIBNAME) - -install: $(LIBNAME) - install -d $(DESTDIR)$(LIBPATH) - install -d $(DESTDIR)$(INCPATH) - install -m 644 $(LIBNAME) $(DESTDIR)$(LIBPATH) - install -m 644 $(HEADERS_PUB) $(DESTDIR)$(INCPATH) - -uninstall: - rm $(DESTDIR)$(LIBPATH)/$(LIBNAME) - rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%) - -test_standalone: test - @echo "test_standalone is deprecated, please use make-target 'test'" - -DEMOS=test mtest_opponent - -define DEMO_template -$(1): demo/$(1).o demo/shared.o $$(LIBNAME) - $$(CC) $$(LTM_CFLAGS) $$(LTM_LFLAGS) $$^ -o $$@ -endef - -$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) - -.PHONY: mtest -mtest: - cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LFLAGS) -o mtest - -timing: $(LIBNAME) demo/timing.c - $(CC) $(LTM_CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LTM_LFLAGS) -o timing - -tune: $(LIBNAME) - $(MAKE) -C etc tune CFLAGS="$(LTM_CFLAGS)" - $(MAKE) - -# You have to create a file .coveralls.yml with the content "repo_token: " -# in the base folder to be able to submit to coveralls -coveralls: lcov - coveralls-lcov - -docs manual: - $(MAKE) -C doc/ $@ V=$(V) - -.PHONY: pre_gen -pre_gen: - mkdir -p pre_gen - perl gen.pl - sed -e 's/[[:blank:]]*$$//' mpi.c > pre_gen/mpi.c - rm mpi.c - -zipup: clean astyle new_file docs - @# Update the index, so diff-index won't fail in case the pdf has been created. - @# As the pdf creation modifies the tex files, git sometimes detects the - @# modified files, but misses that it's put back to its original version. - @git update-index --refresh - @git diff-index --quiet HEAD -- || ( echo "FAILURE: uncommited changes or not a git" && exit 1 ) - rm -rf libtommath-$(VERSION) ltm-$(VERSION).* - @# files/dirs excluded from "git archive" are defined in .gitattributes - git archive --format=tar --prefix=libtommath-$(VERSION)/ HEAD | tar x - @echo 'fixme check' - -@(find libtommath-$(VERSION)/ -type f | xargs grep 'FIXM[E]') && echo '############## BEWARE: the "fixme" marker was found !!! ##############' || true - mkdir -p libtommath-$(VERSION)/doc - cp doc/bn.pdf libtommath-$(VERSION)/doc/ - $(MAKE) -C libtommath-$(VERSION)/ pre_gen - tar -c libtommath-$(VERSION)/ | xz -6e -c - > ltm-$(VERSION).tar.xz - zip -9rq ltm-$(VERSION).zip libtommath-$(VERSION) - cp doc/bn.pdf bn-$(VERSION).pdf - rm -rf libtommath-$(VERSION) - gpg -b -a ltm-$(VERSION).tar.xz - gpg -b -a ltm-$(VERSION).zip - -new_file: - perl helper.pl --update-files - -perlcritic: - perlcritic *.pl doc/*.pl - -astyle: - @echo " * run astyle on all sources" - @astyle --options=astylerc --formatted $(OBJECTS:.o=.c) tommath*.h demo/*.c etc/*.c mtest/mtest.c diff --git a/libtommath/makefile.mingw b/libtommath/makefile.mingw deleted file mode 100644 index 7eee57d..0000000 --- a/libtommath/makefile.mingw +++ /dev/null @@ -1,109 +0,0 @@ -# MAKEFILE for MS Windows (mingw + gcc + gmake) -# -# BEWARE: variable OBJECTS is updated via helper.pl - -### USAGE: -# Open a command prompt with gcc + gmake in PATH and start: -# -# gmake -f makefile.mingw all -# test.exe -# gmake -f makefile.mingw PREFIX=c:\devel\libtom install - -#The following can be overridden from command line e.g. make -f makefile.mingw CC=gcc ARFLAGS=rcs -PREFIX = c:\mingw -CC = gcc -AR = ar -ARFLAGS = r -RANLIB = ranlib -STRIP = strip -CFLAGS = -O2 -LDFLAGS = - -#Compilation flags -LTM_CFLAGS = -I. $(CFLAGS) -LTM_LDFLAGS = $(LDFLAGS) -static-libgcc - -#Libraries to be created -LIBMAIN_S =libtommath.a -LIBMAIN_I =libtommath.dll.a -LIBMAIN_D =libtommath.dll - -#List of objects to compile (all goes to libtommath.a) -OBJECTS=bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o bn_mp_addmod.o \ -bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \ -bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_decr.o bn_mp_div.o bn_mp_div_2.o \ -bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o \ -bn_mp_error_to_string.o bn_mp_exch.o bn_mp_expt_u32.o bn_mp_exptmod.o bn_mp_exteuclid.o bn_mp_fread.o \ -bn_mp_from_sbin.o bn_mp_from_ubin.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_i32.o \ -bn_mp_get_i64.o bn_mp_get_l.o bn_mp_get_ll.o bn_mp_get_mag_u32.o bn_mp_get_mag_u64.o bn_mp_get_mag_ul.o \ -bn_mp_get_mag_ull.o bn_mp_grow.o bn_mp_incr.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_i32.o \ -bn_mp_init_i64.o bn_mp_init_l.o bn_mp_init_ll.o bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_size.o \ -bn_mp_init_u32.o bn_mp_init_u64.o bn_mp_init_ul.o bn_mp_init_ull.o bn_mp_invmod.o bn_mp_is_square.o \ -bn_mp_iseven.o bn_mp_isodd.o bn_mp_kronecker.o bn_mp_lcm.o bn_mp_log_u32.o bn_mp_lshd.o bn_mp_mod.o \ -bn_mp_mod_2d.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \ -bn_mp_montgomery_setup.o bn_mp_mul.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_mulmod.o bn_mp_neg.o \ -bn_mp_or.o bn_mp_pack.o bn_mp_pack_count.o bn_mp_prime_fermat.o bn_mp_prime_frobenius_underwood.o \ -bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ -bn_mp_prime_rabin_miller_trials.o bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o \ -bn_mp_radix_size.o bn_mp_radix_smap.o bn_mp_rand.o bn_mp_read_radix.o bn_mp_reduce.o bn_mp_reduce_2k.o \ -bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o bn_mp_reduce_is_2k.o \ -bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_root_u32.o bn_mp_rshd.o bn_mp_sbin_size.o bn_mp_set.o \ -bn_mp_set_double.o bn_mp_set_i32.o bn_mp_set_i64.o bn_mp_set_l.o bn_mp_set_ll.o bn_mp_set_u32.o \ -bn_mp_set_u64.o bn_mp_set_ul.o bn_mp_set_ull.o bn_mp_shrink.o bn_mp_signed_rsh.o bn_mp_sqr.o \ -bn_mp_sqrmod.o bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o \ -bn_mp_to_radix.o bn_mp_to_sbin.o bn_mp_to_ubin.o bn_mp_ubin_size.o bn_mp_unpack.o bn_mp_xor.o bn_mp_zero.o \ -bn_prime_tab.o bn_s_mp_add.o bn_s_mp_balance_mul.o bn_s_mp_exptmod.o bn_s_mp_exptmod_fast.o \ -bn_s_mp_get_bit.o bn_s_mp_invmod_fast.o bn_s_mp_invmod_slow.o bn_s_mp_karatsuba_mul.o \ -bn_s_mp_karatsuba_sqr.o bn_s_mp_montgomery_reduce_fast.o bn_s_mp_mul_digs.o bn_s_mp_mul_digs_fast.o \ -bn_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs_fast.o bn_s_mp_prime_is_divisible.o \ -bn_s_mp_rand_jenkins.o bn_s_mp_rand_platform.o bn_s_mp_reverse.o 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_sqr.o - -HEADERS_PUB=tommath.h -HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB) - -#The default rule for make builds the libtommath.a library (static) -default: $(LIBMAIN_S) - -#Dependencies on *.h -$(OBJECTS): $(HEADERS) - -.c.o: - $(CC) $(LTM_CFLAGS) -c $< -o $@ - -#Create libtommath.a -$(LIBMAIN_S): $(OBJECTS) - $(AR) $(ARFLAGS) $@ $(OBJECTS) - $(RANLIB) $@ - -#Create DLL + import library libtommath.dll.a -$(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS) - $(CC) -s -shared -o $(LIBMAIN_D) $^ -Wl,--enable-auto-import,--export-all -Wl,--out-implib=$(LIBMAIN_I) $(LTM_LDFLAGS) - $(STRIP) -S $(LIBMAIN_D) - -#Build test suite -test.exe: demo/shared.o demo/test.o $(LIBMAIN_S) - $(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -o $@ - @echo NOTICE: start the tests by launching test.exe - -test_standalone: test.exe - @echo test_standalone is deprecated, please use make-target 'test.exe' - -all: $(LIBMAIN_S) test.exe - -tune: $(LIBNAME_S) - $(MAKE) -C etc tune - $(MAKE) - -clean: - @-cmd /c del /Q /S *.o *.a *.exe *.dll 2>nul - -#Install the library + headers -install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D) - cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin" - cmd /c if not exist "$(PREFIX)\lib" mkdir "$(PREFIX)\lib" - cmd /c if not exist "$(PREFIX)\include" mkdir "$(PREFIX)\include" - copy /Y $(LIBMAIN_S) "$(PREFIX)\lib" - copy /Y $(LIBMAIN_I) "$(PREFIX)\lib" - copy /Y $(LIBMAIN_D) "$(PREFIX)\bin" - copy /Y tommath*.h "$(PREFIX)\include" diff --git a/libtommath/makefile.msvc b/libtommath/makefile.msvc deleted file mode 100644 index aa8d8be..0000000 --- a/libtommath/makefile.msvc +++ /dev/null @@ -1,93 +0,0 @@ -# MAKEFILE for MS Windows (nmake + Windows SDK) -# -# BEWARE: variable OBJECTS is updated via helper.pl - -### USAGE: -# Open a command prompt with WinSDK variables set and start: -# -# nmake -f makefile.msvc all -# test.exe -# nmake -f makefile.msvc PREFIX=c:\devel\libtom install - -#The following can be overridden from command line e.g. make -f makefile.msvc CC=gcc ARFLAGS=rcs -PREFIX = c:\devel -CFLAGS = /Ox - -#Compilation flags -LTM_CFLAGS = /nologo /I./ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /D__STDC_WANT_SECURE_LIB__=1 /D_CRT_HAS_CXX17=0 /Wall /wd4146 /wd4127 /wd4668 /wd4710 /wd4711 /wd4820 /wd5045 /WX $(CFLAGS) -LTM_LDFLAGS = advapi32.lib - -#Libraries to be created (this makefile builds only static libraries) -LIBMAIN_S =tommath.lib - -#List of objects to compile (all goes to tommath.lib) -OBJECTS=bn_cutoffs.obj bn_deprecated.obj bn_mp_2expt.obj bn_mp_abs.obj bn_mp_add.obj bn_mp_add_d.obj bn_mp_addmod.obj \ -bn_mp_and.obj bn_mp_clamp.obj bn_mp_clear.obj bn_mp_clear_multi.obj bn_mp_cmp.obj bn_mp_cmp_d.obj bn_mp_cmp_mag.obj \ -bn_mp_cnt_lsb.obj bn_mp_complement.obj bn_mp_copy.obj bn_mp_count_bits.obj bn_mp_decr.obj bn_mp_div.obj bn_mp_div_2.obj \ -bn_mp_div_2d.obj bn_mp_div_3.obj bn_mp_div_d.obj bn_mp_dr_is_modulus.obj bn_mp_dr_reduce.obj bn_mp_dr_setup.obj \ -bn_mp_error_to_string.obj bn_mp_exch.obj bn_mp_expt_u32.obj bn_mp_exptmod.obj bn_mp_exteuclid.obj bn_mp_fread.obj \ -bn_mp_from_sbin.obj bn_mp_from_ubin.obj bn_mp_fwrite.obj bn_mp_gcd.obj bn_mp_get_double.obj bn_mp_get_i32.obj \ -bn_mp_get_i64.obj bn_mp_get_l.obj bn_mp_get_ll.obj bn_mp_get_mag_u32.obj bn_mp_get_mag_u64.obj bn_mp_get_mag_ul.obj \ -bn_mp_get_mag_ull.obj bn_mp_grow.obj bn_mp_incr.obj bn_mp_init.obj bn_mp_init_copy.obj bn_mp_init_i32.obj \ -bn_mp_init_i64.obj bn_mp_init_l.obj bn_mp_init_ll.obj bn_mp_init_multi.obj bn_mp_init_set.obj bn_mp_init_size.obj \ -bn_mp_init_u32.obj bn_mp_init_u64.obj bn_mp_init_ul.obj bn_mp_init_ull.obj bn_mp_invmod.obj bn_mp_is_square.obj \ -bn_mp_iseven.obj bn_mp_isodd.obj bn_mp_kronecker.obj bn_mp_lcm.obj bn_mp_log_u32.obj bn_mp_lshd.obj bn_mp_mod.obj \ -bn_mp_mod_2d.obj bn_mp_mod_d.obj bn_mp_montgomery_calc_normalization.obj bn_mp_montgomery_reduce.obj \ -bn_mp_montgomery_setup.obj bn_mp_mul.obj bn_mp_mul_2.obj bn_mp_mul_2d.obj bn_mp_mul_d.obj bn_mp_mulmod.obj bn_mp_neg.obj \ -bn_mp_or.obj bn_mp_pack.obj bn_mp_pack_count.obj bn_mp_prime_fermat.obj bn_mp_prime_frobenius_underwood.obj \ -bn_mp_prime_is_prime.obj bn_mp_prime_miller_rabin.obj bn_mp_prime_next_prime.obj \ -bn_mp_prime_rabin_miller_trials.obj bn_mp_prime_rand.obj bn_mp_prime_strong_lucas_selfridge.obj \ -bn_mp_radix_size.obj bn_mp_radix_smap.obj bn_mp_rand.obj bn_mp_read_radix.obj bn_mp_reduce.obj bn_mp_reduce_2k.obj \ -bn_mp_reduce_2k_l.obj bn_mp_reduce_2k_setup.obj bn_mp_reduce_2k_setup_l.obj bn_mp_reduce_is_2k.obj \ -bn_mp_reduce_is_2k_l.obj bn_mp_reduce_setup.obj bn_mp_root_u32.obj bn_mp_rshd.obj bn_mp_sbin_size.obj bn_mp_set.obj \ -bn_mp_set_double.obj bn_mp_set_i32.obj bn_mp_set_i64.obj bn_mp_set_l.obj bn_mp_set_ll.obj bn_mp_set_u32.obj \ -bn_mp_set_u64.obj bn_mp_set_ul.obj bn_mp_set_ull.obj bn_mp_shrink.obj bn_mp_signed_rsh.obj bn_mp_sqr.obj \ -bn_mp_sqrmod.obj bn_mp_sqrt.obj bn_mp_sqrtmod_prime.obj bn_mp_sub.obj bn_mp_sub_d.obj bn_mp_submod.obj \ -bn_mp_to_radix.obj bn_mp_to_sbin.obj bn_mp_to_ubin.obj bn_mp_ubin_size.obj bn_mp_unpack.obj bn_mp_xor.obj bn_mp_zero.obj \ -bn_prime_tab.obj bn_s_mp_add.obj bn_s_mp_balance_mul.obj bn_s_mp_exptmod.obj bn_s_mp_exptmod_fast.obj \ -bn_s_mp_get_bit.obj bn_s_mp_invmod_fast.obj bn_s_mp_invmod_slow.obj bn_s_mp_karatsuba_mul.obj \ -bn_s_mp_karatsuba_sqr.obj bn_s_mp_montgomery_reduce_fast.obj bn_s_mp_mul_digs.obj bn_s_mp_mul_digs_fast.obj \ -bn_s_mp_mul_high_digs.obj bn_s_mp_mul_high_digs_fast.obj bn_s_mp_prime_is_divisible.obj \ -bn_s_mp_rand_jenkins.obj bn_s_mp_rand_platform.obj bn_s_mp_reverse.obj bn_s_mp_sqr.obj bn_s_mp_sqr_fast.obj \ -bn_s_mp_sub.obj bn_s_mp_toom_mul.obj bn_s_mp_toom_sqr.obj - -HEADERS_PUB=tommath.h -HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB) - -#The default rule for make builds the tommath.lib library (static) -default: $(LIBMAIN_S) - -#Dependencies on *.h -$(OBJECTS): $(HEADERS) - -.c.obj: - $(CC) $(LTM_CFLAGS) /c $< /Fo$@ - -#Create tommath.lib -$(LIBMAIN_S): $(OBJECTS) - lib /out:$(LIBMAIN_S) $(OBJECTS) - -#Build test suite -test.exe: $(LIBMAIN_S) demo/shared.obj demo/test.obj - cl $(LTM_CFLAGS) $(TOBJECTS) $(LIBMAIN_S) $(LTM_LDFLAGS) demo/shared.c demo/test.c /Fe$@ - @echo NOTICE: start the tests by launching test.exe - -test_standalone: test.exe - @echo test_standalone is deprecated, please use make-target 'test.exe' - -all: $(LIBMAIN_S) test.exe - -tune: $(LIBMAIN_S) - $(MAKE) -C etc tune - $(MAKE) - -clean: - @-cmd /c del /Q /S *.OBJ *.LIB *.EXE *.DLL 2>nul - -#Install the library + headers -install: $(LIBMAIN_S) - cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin" - cmd /c if not exist "$(PREFIX)\lib" mkdir "$(PREFIX)\lib" - cmd /c if not exist "$(PREFIX)\include" mkdir "$(PREFIX)\include" - copy /Y $(LIBMAIN_S) "$(PREFIX)\lib" - copy /Y tommath*.h "$(PREFIX)\include" diff --git a/libtommath/makefile.shared b/libtommath/makefile.shared deleted file mode 100644 index 6802107..0000000 --- a/libtommath/makefile.shared +++ /dev/null @@ -1,99 +0,0 @@ -#Makefile for GCC -# -#Tom St Denis - -#default files to install -ifndef LIBNAME - LIBNAME=libtommath.la -endif - -include makefile_include.mk - - -ifndef LIBTOOL - ifeq ($(PLATFORM), Darwin) - LIBTOOL:=glibtool - else - LIBTOOL:=libtool - endif -endif -LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(CC) -LTLINK = $(LIBTOOL) --mode=link --tag=CC $(CC) - -LCOV_ARGS=--directory .libs --directory . - -#START_INS -OBJECTS=bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o bn_mp_addmod.o \ -bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \ -bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_decr.o bn_mp_div.o bn_mp_div_2.o \ -bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o \ -bn_mp_error_to_string.o bn_mp_exch.o bn_mp_expt_u32.o bn_mp_exptmod.o bn_mp_exteuclid.o bn_mp_fread.o \ -bn_mp_from_sbin.o bn_mp_from_ubin.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_i32.o \ -bn_mp_get_i64.o bn_mp_get_l.o bn_mp_get_ll.o bn_mp_get_mag_u32.o bn_mp_get_mag_u64.o bn_mp_get_mag_ul.o \ -bn_mp_get_mag_ull.o bn_mp_grow.o bn_mp_incr.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_i32.o \ -bn_mp_init_i64.o bn_mp_init_l.o bn_mp_init_ll.o bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_size.o \ -bn_mp_init_u32.o bn_mp_init_u64.o bn_mp_init_ul.o bn_mp_init_ull.o bn_mp_invmod.o bn_mp_is_square.o \ -bn_mp_iseven.o bn_mp_isodd.o bn_mp_kronecker.o bn_mp_lcm.o bn_mp_log_u32.o bn_mp_lshd.o bn_mp_mod.o \ -bn_mp_mod_2d.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \ -bn_mp_montgomery_setup.o bn_mp_mul.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_mulmod.o bn_mp_neg.o \ -bn_mp_or.o bn_mp_pack.o bn_mp_pack_count.o bn_mp_prime_fermat.o bn_mp_prime_frobenius_underwood.o \ -bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ -bn_mp_prime_rabin_miller_trials.o bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o \ -bn_mp_radix_size.o bn_mp_radix_smap.o bn_mp_rand.o bn_mp_read_radix.o bn_mp_reduce.o bn_mp_reduce_2k.o \ -bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o bn_mp_reduce_is_2k.o \ -bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_root_u32.o bn_mp_rshd.o bn_mp_sbin_size.o bn_mp_set.o \ -bn_mp_set_double.o bn_mp_set_i32.o bn_mp_set_i64.o bn_mp_set_l.o bn_mp_set_ll.o bn_mp_set_u32.o \ -bn_mp_set_u64.o bn_mp_set_ul.o bn_mp_set_ull.o bn_mp_shrink.o bn_mp_signed_rsh.o bn_mp_sqr.o \ -bn_mp_sqrmod.o bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o \ -bn_mp_to_radix.o bn_mp_to_sbin.o bn_mp_to_ubin.o bn_mp_ubin_size.o bn_mp_unpack.o bn_mp_xor.o bn_mp_zero.o \ -bn_prime_tab.o bn_s_mp_add.o bn_s_mp_balance_mul.o bn_s_mp_exptmod.o bn_s_mp_exptmod_fast.o \ -bn_s_mp_get_bit.o bn_s_mp_invmod_fast.o bn_s_mp_invmod_slow.o bn_s_mp_karatsuba_mul.o \ -bn_s_mp_karatsuba_sqr.o bn_s_mp_montgomery_reduce_fast.o bn_s_mp_mul_digs.o bn_s_mp_mul_digs_fast.o \ -bn_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs_fast.o bn_s_mp_prime_is_divisible.o \ -bn_s_mp_rand_jenkins.o bn_s_mp_rand_platform.o bn_s_mp_reverse.o 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_sqr.o - -#END_INS - -objs: $(OBJECTS) - -.c.o: $(HEADERS) - $(LTCOMPILE) $(LTM_CFLAGS) $(LTM_LDFLAGS) -o $@ -c $< - -LOBJECTS = $(OBJECTS:.o=.lo) - -$(LIBNAME): $(OBJECTS) - $(LTLINK) $(LTM_LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_SO) $(LTM_LIBTOOLFLAGS) - -install: $(LIBNAME) - install -d $(DESTDIR)$(LIBPATH) - install -d $(DESTDIR)$(INCPATH) - $(LIBTOOL) --mode=install install -m 644 $(LIBNAME) $(DESTDIR)$(LIBPATH)/$(LIBNAME) - install -m 644 $(HEADERS_PUB) $(DESTDIR)$(INCPATH) - sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' libtommath.pc.in > libtommath.pc - install -d $(DESTDIR)$(LIBPATH)/pkgconfig - install -m 644 libtommath.pc $(DESTDIR)$(LIBPATH)/pkgconfig/ - -uninstall: - $(LIBTOOL) --mode=uninstall rm $(DESTDIR)$(LIBPATH)/$(LIBNAME) - rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%) - rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc - -test_standalone: test - @echo "test_standalone is deprecated, please use make-target 'test'" - -test mtest_opponent: demo/shared.o $(LIBNAME) | demo/test.o demo/mtest_opponent.o - $(LTLINK) $(LTM_LDFLAGS) demo/$@.o $^ -o $@ - -.PHONY: mtest -mtest: - cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LDFLAGS) -o mtest - -timing: $(LIBNAME) demo/timing.c - $(LTLINK) $(LTM_CFLAGS) $(LTM_LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o timing - -tune: $(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/libtommath/makefile.unix b/libtommath/makefile.unix deleted file mode 100644 index 9336da0..0000000 --- a/libtommath/makefile.unix +++ /dev/null @@ -1,106 +0,0 @@ -# MAKEFILE that is intended to be compatible with any kind of make (GNU make, BSD make, ...) -# works on: Linux, *BSD, Cygwin, AIX, HP-UX and hopefully other UNIX systems -# -# Please do not use here neither any special make syntax nor any unusual tools/utilities! - -# using ICC compiler: -# make -f makefile.unix CC=icc CFLAGS="-O3 -xP -ip" - -# using Borland C++Builder: -# make -f makefile.unix CC=bcc32 - -#The following can be overridden from command line e.g. "make -f makefile.unix CC=gcc ARFLAGS=rcs" -DESTDIR = -PREFIX = /usr/local -LIBPATH = $(PREFIX)/lib -INCPATH = $(PREFIX)/include -CC = cc -AR = ar -ARFLAGS = r -RANLIB = ranlib -CFLAGS = -O2 -LDFLAGS = - -VERSION = 1.2.1 - -#Compilation flags -LTM_CFLAGS = -I. $(CFLAGS) -LTM_LDFLAGS = $(LDFLAGS) - -#Library to be created (this makefile builds only static library) -LIBMAIN_S = libtommath.a - -OBJECTS=bn_cutoffs.o bn_deprecated.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o bn_mp_addmod.o \ -bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \ -bn_mp_cnt_lsb.o bn_mp_complement.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_decr.o bn_mp_div.o bn_mp_div_2.o \ -bn_mp_div_2d.o bn_mp_div_3.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o \ -bn_mp_error_to_string.o bn_mp_exch.o bn_mp_expt_u32.o bn_mp_exptmod.o bn_mp_exteuclid.o bn_mp_fread.o \ -bn_mp_from_sbin.o bn_mp_from_ubin.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_double.o bn_mp_get_i32.o \ -bn_mp_get_i64.o bn_mp_get_l.o bn_mp_get_ll.o bn_mp_get_mag_u32.o bn_mp_get_mag_u64.o bn_mp_get_mag_ul.o \ -bn_mp_get_mag_ull.o bn_mp_grow.o bn_mp_incr.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_i32.o \ -bn_mp_init_i64.o bn_mp_init_l.o bn_mp_init_ll.o bn_mp_init_multi.o bn_mp_init_set.o bn_mp_init_size.o \ -bn_mp_init_u32.o bn_mp_init_u64.o bn_mp_init_ul.o bn_mp_init_ull.o bn_mp_invmod.o bn_mp_is_square.o \ -bn_mp_iseven.o bn_mp_isodd.o bn_mp_kronecker.o bn_mp_lcm.o bn_mp_log_u32.o bn_mp_lshd.o bn_mp_mod.o \ -bn_mp_mod_2d.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \ -bn_mp_montgomery_setup.o bn_mp_mul.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_mulmod.o bn_mp_neg.o \ -bn_mp_or.o bn_mp_pack.o bn_mp_pack_count.o bn_mp_prime_fermat.o bn_mp_prime_frobenius_underwood.o \ -bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \ -bn_mp_prime_rabin_miller_trials.o bn_mp_prime_rand.o bn_mp_prime_strong_lucas_selfridge.o \ -bn_mp_radix_size.o bn_mp_radix_smap.o bn_mp_rand.o bn_mp_read_radix.o bn_mp_reduce.o bn_mp_reduce_2k.o \ -bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o bn_mp_reduce_is_2k.o \ -bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_root_u32.o bn_mp_rshd.o bn_mp_sbin_size.o bn_mp_set.o \ -bn_mp_set_double.o bn_mp_set_i32.o bn_mp_set_i64.o bn_mp_set_l.o bn_mp_set_ll.o bn_mp_set_u32.o \ -bn_mp_set_u64.o bn_mp_set_ul.o bn_mp_set_ull.o bn_mp_shrink.o bn_mp_signed_rsh.o bn_mp_sqr.o \ -bn_mp_sqrmod.o bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o \ -bn_mp_to_radix.o bn_mp_to_sbin.o bn_mp_to_ubin.o bn_mp_ubin_size.o bn_mp_unpack.o bn_mp_xor.o bn_mp_zero.o \ -bn_prime_tab.o bn_s_mp_add.o bn_s_mp_balance_mul.o bn_s_mp_exptmod.o bn_s_mp_exptmod_fast.o \ -bn_s_mp_get_bit.o bn_s_mp_invmod_fast.o bn_s_mp_invmod_slow.o bn_s_mp_karatsuba_mul.o \ -bn_s_mp_karatsuba_sqr.o bn_s_mp_montgomery_reduce_fast.o bn_s_mp_mul_digs.o bn_s_mp_mul_digs_fast.o \ -bn_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs_fast.o bn_s_mp_prime_is_divisible.o \ -bn_s_mp_rand_jenkins.o bn_s_mp_rand_platform.o bn_s_mp_reverse.o 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_sqr.o - -HEADERS_PUB=tommath.h -HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB) - -#The default rule for make builds the libtommath.a library (static) -default: $(LIBMAIN_S) - -#Dependencies on *.h -$(OBJECTS): $(HEADERS) - -#This is necessary for compatibility with BSD make (namely on OpenBSD) -.SUFFIXES: .o .c -.c.o: - $(CC) $(LTM_CFLAGS) -c $< -o $@ - -#Create libtommath.a -$(LIBMAIN_S): $(OBJECTS) - $(AR) $(ARFLAGS) $@ $(OBJECTS) - $(RANLIB) $@ - -#Build test_standalone suite -test: demo/shared.o demo/test.o $(LIBMAIN_S) - $(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -o $@ - @echo "NOTICE: start the tests by: ./test" - -test_standalone: test - @echo "test_standalone is deprecated, please use make-target 'test'" - -all: $(LIBMAIN_S) test - -tune: $(LIBMAIN_S) - $(MAKE) -C etc tune - $(MAKE) - -#NOTE: this makefile works also on cygwin, thus we need to delete *.exe -clean: - -@rm -f $(OBJECTS) $(LIBMAIN_S) - -@rm -f demo/main.o demo/opponent.o demo/test.o test test.exe - -#Install the library + headers -install: $(LIBMAIN_S) - @mkdir -p $(DESTDIR)$(INCPATH) $(DESTDIR)$(LIBPATH)/pkgconfig - @cp $(LIBMAIN_S) $(DESTDIR)$(LIBPATH)/ - @cp $(HEADERS_PUB) $(DESTDIR)$(INCPATH)/ - @sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtommath.pc.in > $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc diff --git a/libtommath/makefile_include.mk b/libtommath/makefile_include.mk deleted file mode 100644 index 71f04dd..0000000 --- a/libtommath/makefile_include.mk +++ /dev/null @@ -1,166 +0,0 @@ -# -# Include makefile for libtommath -# - -#version of library -VERSION=1.2.1 -VERSION_PC=1.2.1 -VERSION_SO=3:1:2 - -PLATFORM := $(shell uname | sed -e 's/_.*//') - -# default make target -default: ${LIBNAME} - -# Compiler and Linker Names -ifndef CROSS_COMPILE - CROSS_COMPILE= -endif - -# We only need to go through this dance of determining the right compiler if we're using -# cross compilation, otherwise $(CC) is fine as-is. -ifneq (,$(CROSS_COMPILE)) -ifeq ($(origin CC),default) -CSTR := "\#ifdef __clang__\nCLANG\n\#endif\n" -ifeq ($(PLATFORM),FreeBSD) - # XXX: FreeBSD needs extra escaping for some reason - CSTR := $$$(CSTR) -endif -ifneq (,$(shell echo $(CSTR) | $(CC) -E - | grep CLANG)) - CC := $(CROSS_COMPILE)clang -else - CC := $(CROSS_COMPILE)gcc -endif # Clang -endif # cc is Make's default -endif # CROSS_COMPILE non-empty - -LD=$(CROSS_COMPILE)ld -AR=$(CROSS_COMPILE)ar -RANLIB=$(CROSS_COMPILE)ranlib - -ifndef MAKE -# BSDs refer to GNU Make as gmake -ifneq (,$(findstring $(PLATFORM),FreeBSD OpenBSD DragonFly NetBSD)) - MAKE=gmake -else - MAKE=make -endif -endif - -LTM_CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow - -ifdef SANITIZER -LTM_CFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero -endif - -ifndef NO_ADDTL_WARNINGS -# additional warnings -LTM_CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align -LTM_CFLAGS += -Wstrict-prototypes -Wpointer-arith -endif - -ifdef CONV_WARNINGS -LTM_CFLAGS += -std=c89 -Wconversion -Wsign-conversion -ifeq ($(CONV_WARNINGS), strict) -LTM_CFLAGS += -DMP_USE_ENUMS -Wc++-compat -endif -else -LTM_CFLAGS += -Wsystem-headers -endif - -ifdef COMPILE_DEBUG -#debug -LTM_CFLAGS += -g3 -endif - -ifdef COMPILE_SIZE -#for size -LTM_CFLAGS += -Os -else - -ifndef IGNORE_SPEED -#for speed -LTM_CFLAGS += -O3 -funroll-loops - -#x86 optimizations [should be valid for any GCC install though] -LTM_CFLAGS += -fomit-frame-pointer -endif - -endif # COMPILE_SIZE - -ifneq ($(findstring clang,$(CC)),) -LTM_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header -endif -ifneq ($(findstring mingw,$(CC)),) -LTM_CFLAGS += -Wno-shadow -endif -ifeq ($(PLATFORM), Darwin) -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 - _ARCH := $(shell uname -m) -endif - -# adjust coverage set -ifneq ($(filter $(_ARCH), i386 i686 x86_64 amd64 ia64),) - COVERAGE = test_standalone timing - COVERAGE_APP = ./test && ./timing -else - COVERAGE = test_standalone - COVERAGE_APP = ./test -endif - -HEADERS_PUB=tommath.h -HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB) - -#LIBPATH The directory for libtommath to be installed to. -#INCPATH The directory to install the header files for libtommath. -#DATAPATH The directory to install the pdf docs. -DESTDIR ?= -PREFIX ?= /usr/local -LIBPATH ?= $(PREFIX)/lib -INCPATH ?= $(PREFIX)/include -DATAPATH ?= $(PREFIX)/share/doc/libtommath/pdf - -#make the code coverage of the library -# -coverage: LTM_CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS -coverage: LTM_LFLAGS += -lgcov -coverage: LTM_LDFLAGS += -lgcov - -coverage: $(COVERAGE) - $(COVERAGE_APP) - -lcov: coverage - rm -f coverage.info - lcov --capture --no-external --no-recursion $(LCOV_ARGS) --output-file coverage.info -q - genhtml coverage.info --output-directory coverage -q - -# target that removes all coverage output -cleancov-clean: - rm -f `find . -type f -name "*.info" | xargs` - rm -rf coverage/ - -# cleans everything - coverage output and standard 'clean' -cleancov: cleancov-clean clean - -clean: - rm -f *.gcda *.gcno *.gcov *.bat *.o *.a *.obj *.lib *.exe *.dll etclib/*.o \ - demo/*.o test timing mtest_opponent mtest/mtest mtest/mtest.exe tuning_list \ - *.s mpi.c *.da *.dyn *.dpi tommath.tex `find . -type f | grep [~] | xargs` *.lo *.la - rm -rf .libs/ demo/.libs - ${MAKE} -C etc/ clean MAKE=${MAKE} - ${MAKE} -C doc/ clean MAKE=${MAKE} diff --git a/libtommath/tommath.def b/libtommath/tommath.def index 229fae4..cc6a9f1 100644 --- a/libtommath/tommath.def +++ b/libtommath/tommath.def @@ -33,6 +33,7 @@ EXPORTS mp_dr_setup mp_error_to_string mp_exch + mp_expt_n mp_expt_u32 mp_exptmod mp_exteuclid @@ -75,6 +76,7 @@ EXPORTS mp_isodd mp_kronecker mp_lcm + mp_log_n mp_log_u32 mp_lshd mp_mod @@ -111,6 +113,7 @@ EXPORTS mp_reduce_is_2k mp_reduce_is_2k_l mp_reduce_setup + mp_root_n mp_root_u32 mp_rshd mp_sbin_size @@ -143,3 +146,15 @@ EXPORTS mp_unpack mp_xor mp_zero + s_mp_add + s_mp_balance_mul + s_mp_karatsuba_mul + s_mp_karatsuba_sqr + s_mp_mul_digs + s_mp_mul_digs_fast + s_mp_reverse + s_mp_sqr + s_mp_sqr_fast + s_mp_sub + s_mp_toom_mul + s_mp_toom_sqr diff --git a/libtommath/tommath.h b/libtommath/tommath.h index fe26962..8ccbb89 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -236,22 +236,13 @@ TOOM_SQR_CUTOFF; #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 405) # define MP_DEPRECATED(x) __attribute__((deprecated("replaced by " #x))) -#elif defined(_MSC_VER) && _MSC_VER >= 1500 -# define MP_DEPRECATED(x) __declspec(deprecated("replaced by " #x)) -#else -# define MP_DEPRECATED(x) -#endif - -#ifndef MP_NO_DEPRECATED_PRAGMA -#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 301) # define PRIVATE_MP_DEPRECATED_PRAGMA(s) _Pragma(#s) # define MP_DEPRECATED_PRAGMA(s) PRIVATE_MP_DEPRECATED_PRAGMA(GCC warning s) #elif defined(_MSC_VER) && _MSC_VER >= 1500 +# define MP_DEPRECATED(x) __declspec(deprecated("replaced by " #x)) # define MP_DEPRECATED_PRAGMA(s) __pragma(message(s)) -#endif -#endif - -#ifndef MP_DEPRECATED_PRAGMA +#else +# define MP_DEPRECATED(s) # define MP_DEPRECATED_PRAGMA(s) #endif diff --git a/libtommath/tommath_private.h b/libtommath/tommath_private.h index 41d1ea2..96ff41f 100644 --- a/libtommath/tommath_private.h +++ b/libtommath/tommath_private.h @@ -185,6 +185,9 @@ MP_STATIC_ASSERT(prec_geq_min_prec, MP_PREC >= MP_MIN_PREC) /* random number source */ extern MP_PRIVATE mp_err(*s_mp_rand_source)(void *out, size_t size); +#ifdef __cplusplus +extern "C" { +#endif /* lowlevel functions, do not call! */ MP_PRIVATE mp_bool s_mp_get_bit(const mp_int *a, unsigned int b); MP_PRIVATE mp_err s_mp_add(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; @@ -242,6 +245,10 @@ MP_DEPRECATED(s_mp_karatsuba_sqr) mp_err mp_karatsuba_sqr(const mp_int *a, mp_in MP_DEPRECATED(s_mp_toom_mul) mp_err mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c); MP_DEPRECATED(s_mp_toom_sqr) mp_err mp_toom_sqr(const mp_int *a, mp_int *b); MP_DEPRECATED(s_mp_reverse) void bn_reverse(unsigned char *s, int len); + +#ifdef __cplusplus +} +#endif #endif #define MP_GET_ENDIANNESS(x) \ diff --git a/unix/Makefile.in b/unix/Makefile.in index eb63b6e..ce07a6a 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -530,11 +530,9 @@ TOMMATH_SRCS = \ $(TOMMATH_DIR)/bn_mp_get_i32.c \ $(TOMMATH_DIR)/bn_mp_get_i64.c \ $(TOMMATH_DIR)/bn_mp_get_l.c \ - $(TOMMATH_DIR)/bn_mp_get_ll.c \ $(TOMMATH_DIR)/bn_mp_get_mag_u32.c \ $(TOMMATH_DIR)/bn_mp_get_mag_u64.c \ $(TOMMATH_DIR)/bn_mp_get_mag_ul.c \ - $(TOMMATH_DIR)/bn_mp_get_mag_ull.c \ $(TOMMATH_DIR)/bn_mp_grow.c \ $(TOMMATH_DIR)/bn_mp_incr.c \ $(TOMMATH_DIR)/bn_mp_init.c \ @@ -542,14 +540,12 @@ TOMMATH_SRCS = \ $(TOMMATH_DIR)/bn_mp_init_i32.c \ $(TOMMATH_DIR)/bn_mp_init_i64.c \ $(TOMMATH_DIR)/bn_mp_init_l.c \ - $(TOMMATH_DIR)/bn_mp_init_ll.c \ $(TOMMATH_DIR)/bn_mp_init_multi.c \ $(TOMMATH_DIR)/bn_mp_init_set.c \ $(TOMMATH_DIR)/bn_mp_init_size.c \ $(TOMMATH_DIR)/bn_mp_init_u32.c \ $(TOMMATH_DIR)/bn_mp_init_u64.c \ $(TOMMATH_DIR)/bn_mp_init_ul.c \ - $(TOMMATH_DIR)/bn_mp_init_ull.c \ $(TOMMATH_DIR)/bn_mp_invmod.c \ $(TOMMATH_DIR)/bn_mp_is_square.c \ $(TOMMATH_DIR)/bn_mp_iseven.c \ @@ -601,11 +597,9 @@ TOMMATH_SRCS = \ $(TOMMATH_DIR)/bn_mp_set_i32.c \ $(TOMMATH_DIR)/bn_mp_set_i64.c \ $(TOMMATH_DIR)/bn_mp_set_l.c \ - $(TOMMATH_DIR)/bn_mp_set_ll.c \ $(TOMMATH_DIR)/bn_mp_set_u32.c \ $(TOMMATH_DIR)/bn_mp_set_u64.c \ $(TOMMATH_DIR)/bn_mp_set_ul.c \ - $(TOMMATH_DIR)/bn_mp_set_ull.c \ $(TOMMATH_DIR)/bn_mp_shrink.c \ $(TOMMATH_DIR)/bn_mp_signed_rsh.c \ $(TOMMATH_DIR)/bn_mp_sqr.c \ -- cgit v0.12 From 429c699cbbaa338b22d5c82067686a9179631688 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 29 Mar 2024 13:22:41 +0000 Subject: (cherry-pick) Added minor detail to file attr -shortname handling docs. --- doc/file.n | 6 ++++-- generic/tclInt.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/file.n b/doc/file.n index 0ea53f4..baaee6d 100644 --- a/doc/file.n +++ b/doc/file.n @@ -71,8 +71,10 @@ expand each path element to its long version. This attribute cannot be set. \fB\-readonly\fR gives the value or sets or clears the readonly attribute of the file. \fB\-shortname\fR gives a string where every path element is replaced with its short (8.3) version of the -name. This attribute cannot be set. \fB\-system\fR gives or sets or -clears the value of the system attribute of the file. +name if possible. For path elements that cannot be mapped to short +names, the long name is retained. This attribute cannot be set. +\fB\-system\fR gives or sets or clears the value of the system +attribute of the file. .PP On Mac OS X and Darwin, \fB\-creator\fR gives or sets the Finder creator type of the file. \fB\-hidden\fR gives or sets or clears diff --git a/generic/tclInt.h b/generic/tclInt.h index 7efaf80..a6e8dfd 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4007,7 +4007,7 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file, #define TclUtfToUCS4(src, ucs4Ptr) \ (((UCHAR(*(src))) < 0x80) ? \ ((*(ucs4Ptr) = UCHAR(*(src))), 1) \ - : TclpUtfToUCS4(src, ucs4Ptr)) + : TclpUtfToUCS4(src, ucs4Ptr)) /* *---------------------------------------------------------------- -- cgit v0.12