From 82526917e5b9fe31e6fd152119e155a8ad878568 Mon Sep 17 00:00:00 2001 From: czurnieden Date: Wed, 27 Nov 2019 16:35:10 +0100 Subject: [PATCH 1/3] made reduce helpers private --- tommath.h | 37 ------------------------------------- tommath_private.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/tommath.h b/tommath.h index 95f7127b4..0bab7b21d 100644 --- a/tommath.h +++ b/tommath.h @@ -436,16 +436,6 @@ mp_err mp_is_square(const mp_int *arg, bool *ret) MP_WUR; /* computes the Kronecker symbol c = (a | p) (like jacobi() but with {a,p} in Z */ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c) MP_WUR; -/* used to setup the Barrett reduction for a given modulus b */ -mp_err mp_reduce_setup(mp_int *a, const mp_int *b) MP_WUR; - -/* Barrett Reduction, computes a (mod b) with a precomputed value c - * - * Assumes that 0 < x <= m*m, note if 0 > x > -(m*m) then you can merely - * compute the reduction as -1 * mp_reduce(mp_abs(x)) [pseudo code]. - */ -mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) MP_WUR; - /* setups the montgomery reduction */ mp_err mp_montgomery_setup(const mp_int *n, mp_digit *rho) MP_WUR; @@ -457,33 +447,6 @@ mp_err mp_montgomery_calc_normalization(mp_int *a, const mp_int *b) MP_WUR; /* computes x/R == x (mod N) via Montgomery Reduction */ mp_err mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) MP_WUR; -/* returns 1 if a is a valid DR modulus */ -bool mp_dr_is_modulus(const mp_int *a) MP_WUR; - -/* sets the value of "d" required for mp_dr_reduce */ -void mp_dr_setup(const mp_int *a, mp_digit *d); - -/* reduces a modulo n using the Diminished Radix method */ -mp_err mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k) MP_WUR; - -/* returns true if a can be reduced with mp_reduce_2k */ -bool mp_reduce_is_2k(const mp_int *a) MP_WUR; - -/* determines k value for 2k reduction */ -mp_err mp_reduce_2k_setup(const mp_int *a, mp_digit *d) MP_WUR; - -/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */ -mp_err mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) MP_WUR; - -/* returns true if a can be reduced with mp_reduce_2k_l */ -bool mp_reduce_is_2k_l(const mp_int *a) MP_WUR; - -/* determines k value for 2k reduction */ -mp_err mp_reduce_2k_setup_l(const mp_int *a, mp_int *d) MP_WUR; - -/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */ -mp_err mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) MP_WUR; - /* Y = G**X (mod P) */ mp_err mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y) MP_WUR; diff --git a/tommath_private.h b/tommath_private.h index eb566dd58..52095edda 100644 --- a/tommath_private.h +++ b/tommath_private.h @@ -171,6 +171,44 @@ MP_PRIVATE mp_err s_mp_div_school(const mp_int *a, const mp_int *b, mp_int *c, m MP_PRIVATE mp_err s_mp_div_small(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) MP_WUR; MP_PRIVATE mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR; MP_PRIVATE mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR; + +/* used to setup the Barrett reduction for a given modulus b */ +MP_PRIVATE mp_err mp_reduce_setup(mp_int *a, const mp_int *b) MP_WUR; + +/* Barrett Reduction, computes a (mod b) with a precomputed value c + * + * Assumes that 0 < x <= m*m, note if 0 > x > -(m*m) then you can merely + * compute the reduction as -1 * mp_reduce(mp_abs(x)) [pseudo code]. + */ +MP_PRIVATE mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) MP_WUR; + +/* returns 1 if a is a valid DR modulus */ +MP_PRIVATE bool mp_dr_is_modulus(const mp_int *a) MP_WUR; + +/* sets the value of "d" required for mp_dr_reduce */ +MP_PRIVATE void mp_dr_setup(const mp_int *a, mp_digit *d); + +/* reduces a modulo n using the Diminished Radix method */ +MP_PRIVATE mp_err mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k) MP_WUR; + +/* returns true if a can be reduced with mp_reduce_2k */ +MP_PRIVATE bool mp_reduce_is_2k(const mp_int *a) MP_WUR; + +/* determines k value for 2k reduction */ +MP_PRIVATE mp_err mp_reduce_2k_setup(const mp_int *a, mp_digit *d) MP_WUR; + +/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */ +MP_PRIVATE mp_err mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) MP_WUR; + +/* returns true if a can be reduced with mp_reduce_2k_l */ +MP_PRIVATE bool mp_reduce_is_2k_l(const mp_int *a) MP_WUR; + +/* determines k value for 2k reduction */ +MP_PRIVATE mp_err mp_reduce_2k_setup_l(const mp_int *a, mp_int *d) MP_WUR; + +/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */ +MP_PRIVATE mp_err mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) MP_WUR; + MP_PRIVATE mp_err s_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; MP_PRIVATE mp_err s_mp_invmod_odd(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; MP_PRIVATE mp_err s_mp_log(const mp_int *a, mp_digit base, int *c) MP_WUR; From 14dec0693bebcf06c0c840bd33009638c3839e24 Mon Sep 17 00:00:00 2001 From: czurnieden Date: Wed, 27 Nov 2019 17:27:32 +0100 Subject: [PATCH 2/3] changed function- and filenames --- demo/test.c | 16 +- libtommath_VS2008.vcproj | 88 ++++----- makefile | 36 ++-- makefile.mingw | 36 ++-- makefile.msvc | 36 ++-- makefile.shared | 36 ++-- makefile.unix | 36 ++-- mp_exptmod.c | 10 +- mp_dr_is_modulus.c => s_mp_dr_is_modulus.c | 7 +- mp_dr_reduce.c => s_mp_dr_reduce.c | 8 +- mp_dr_setup.c => s_mp_dr_setup.c | 6 +- s_mp_exptmod.c | 8 +- s_mp_exptmod_fast.c | 12 +- mp_reduce.c => s_mp_reduce.c | 8 +- mp_reduce_2k.c => s_mp_reduce_2k.c | 7 +- mp_reduce_2k_l.c => s_mp_reduce_2k_l.c | 7 +- ...educe_2k_setup.c => s_mp_reduce_2k_setup.c | 8 +- ...e_2k_setup_l.c => s_mp_reduce_2k_setup_l.c | 8 +- mp_reduce_is_2k.c => s_mp_reduce_is_2k.c | 7 +- mp_reduce_is_2k_l.c => s_mp_reduce_is_2k_l.c | 7 +- mp_reduce_setup.c => s_mp_reduce_setup.c | 8 +- tommath_class.h | 186 +++++++++--------- tommath_private.h | 22 +-- 23 files changed, 320 insertions(+), 283 deletions(-) rename mp_dr_is_modulus.c => s_mp_dr_is_modulus.c (88%) rename mp_dr_reduce.c => s_mp_dr_reduce.c (95%) rename mp_dr_setup.c => s_mp_dr_setup.c (84%) rename mp_reduce.c => s_mp_reduce.c (95%) rename mp_reduce_2k.c => s_mp_reduce_2k.c (91%) rename mp_reduce_2k_l.c => s_mp_reduce_2k_l.c (90%) rename mp_reduce_2k_setup.c => s_mp_reduce_2k_setup.c (84%) rename mp_reduce_2k_setup_l.c => s_mp_reduce_2k_setup_l.c (83%) rename mp_reduce_is_2k.c => s_mp_reduce_is_2k.c (91%) rename mp_reduce_is_2k_l.c => s_mp_reduce_is_2k_l.c (88%) rename mp_reduce_setup.c => s_mp_reduce_setup.c (83%) diff --git a/demo/test.c b/demo/test.c index e1b6f0fa6..7e7d67a5c 100644 --- a/demo/test.c +++ b/demo/test.c @@ -1215,8 +1215,8 @@ static int test_mp_reduce_2k(void) DO(mp_sub_d(&a, 2u, &a)); /* a = 2**cnt - 2 */ printf("\r %4d bits", cnt); - printf("(%d)", mp_reduce_is_2k(&a)); - DO(mp_reduce_2k_setup(&a, &tmp)); + printf("(%d)", s_mp_reduce_is_2k(&a)); + DO(s_mp_reduce_2k_setup(&a, &tmp)); printf("(%lu)", (unsigned long) tmp); for (ix = 0; ix < 1000; ix++) { if (!(ix & 127)) { @@ -1226,7 +1226,7 @@ static int test_mp_reduce_2k(void) DO(mp_rand(&b, ((cnt / MP_DIGIT_BIT) + 1) * 2)); DO(mp_copy(&c, &b)); DO(mp_mod(&c, &a, &c)); - DO(mp_reduce_2k(&b, &a, 2u)); + DO(s_mp_reduce_2k(&b, &a, 2u)); if (mp_cmp(&c, &b) != MP_EQ) { printf("FAILED\n"); goto LBL_ERR; @@ -1310,8 +1310,8 @@ static int test_mp_dr_reduce(void) DO(mp_copy(&b, &c)); DO(mp_mod(&b, &a, &b)); - mp_dr_setup(&a, &mp); - DO(mp_dr_reduce(&c, &a, mp)); + s_mp_dr_setup(&a, &mp); + DO(s_mp_dr_reduce(&c, &a, mp)); if (mp_cmp(&b, &c) != MP_EQ) { printf("Failed on trial %u\n", rr); @@ -2335,7 +2335,7 @@ static int unit_tests(int argc, char **argv) T1(mp_complement, MP_COMPLEMENT), T1(mp_decr, MP_SUB_D), T1(s_mp_div_3, S_MP_DIV_3), - T1(mp_dr_reduce, MP_DR_REDUCE), + T1(mp_dr_reduce, S_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), @@ -2356,8 +2356,8 @@ static int unit_tests(int argc, char **argv) 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), + T1(mp_reduce_2k, S_MP_REDUCE_2K), + T1(mp_reduce_2k_l, S_MP_REDUCE_2K_L), T1(mp_radix_size, MP_RADIX_SIZE), #if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) T1(mp_set_double, MP_SET_DOUBLE), diff --git a/libtommath_VS2008.vcproj b/libtommath_VS2008.vcproj index 6f1a42355..90260afdb 100644 --- a/libtommath_VS2008.vcproj +++ b/libtommath_VS2008.vcproj @@ -396,18 +396,6 @@ RelativePath="mp_div_d.c" > - - - - - - @@ -648,38 +636,6 @@ RelativePath="mp_read_radix.c" > - - - - - - - - - - - - - - - - @@ -808,6 +764,18 @@ RelativePath="s_mp_div_small.c" > + + + + + + @@ -892,6 +860,38 @@ RelativePath="s_mp_rand_platform.c" > + + + + + + + + + + + + + + + + diff --git a/makefile b/makefile index 63930bc97..8c099eeb8 100644 --- a/makefile +++ b/makefile @@ -28,27 +28,27 @@ LCOV_ARGS=--directory . #START_INS OBJECTS=mp_2expt.o mp_abs.o mp_add.o mp_add_d.o mp_addmod.o mp_and.o mp_clamp.o mp_clear.o mp_clear_multi.o \ mp_cmp.o mp_cmp_d.o mp_cmp_mag.o mp_cnt_lsb.o mp_complement.o mp_copy.o mp_count_bits.o mp_cutoffs.o \ -mp_div.o mp_div_2.o mp_div_2d.o mp_div_d.o mp_dr_is_modulus.o mp_dr_reduce.o mp_dr_setup.o \ -mp_error_to_string.o mp_exch.o mp_expt_n.o mp_exptmod.o mp_exteuclid.o mp_fread.o mp_from_sbin.o \ -mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o mp_get_i64.o mp_get_l.o mp_get_mag_u32.o \ -mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_init.o mp_init_copy.o mp_init_i32.o mp_init_i64.o mp_init_l.o \ -mp_init_multi.o mp_init_set.o mp_init_size.o mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_invmod.o \ -mp_is_square.o mp_kronecker.o mp_lcm.o mp_log_n.o mp_lshd.o mp_mod.o mp_mod_2d.o \ -mp_montgomery_calc_normalization.o mp_montgomery_reduce.o mp_montgomery_setup.o mp_mul.o mp_mul_2.o \ -mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_fermat.o \ -mp_prime_frobenius_underwood.o mp_prime_is_prime.o mp_prime_miller_rabin.o mp_prime_next_prime.o \ -mp_prime_rabin_miller_trials.o mp_prime_rand.o mp_prime_strong_lucas_selfridge.o mp_radix_size.o \ -mp_rand.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o mp_reduce_2k_l.o mp_reduce_2k_setup.o \ -mp_reduce_2k_setup_l.o mp_reduce_is_2k.o mp_reduce_is_2k_l.o mp_reduce_setup.o mp_root_n.o mp_rshd.o \ +mp_div.o mp_div_2.o mp_div_2d.o mp_div_d.o mp_error_to_string.o mp_exch.o mp_expt_n.o mp_exptmod.o \ +mp_exteuclid.o mp_fread.o mp_from_sbin.o mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o \ +mp_get_i64.o mp_get_l.o mp_get_mag_u32.o mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_init.o \ +mp_init_copy.o mp_init_i32.o mp_init_i64.o mp_init_l.o mp_init_multi.o mp_init_set.o mp_init_size.o \ +mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_invmod.o mp_is_square.o mp_kronecker.o mp_lcm.o mp_log_n.o \ +mp_lshd.o mp_mod.o mp_mod_2d.o mp_montgomery_calc_normalization.o mp_montgomery_reduce.o \ +mp_montgomery_setup.o mp_mul.o mp_mul_2.o mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o \ +mp_pack_count.o mp_prime_fermat.o mp_prime_frobenius_underwood.o mp_prime_is_prime.o \ +mp_prime_miller_rabin.o mp_prime_next_prime.o mp_prime_rabin_miller_trials.o mp_prime_rand.o \ +mp_prime_strong_lucas_selfridge.o mp_radix_size.o mp_rand.o mp_read_radix.o mp_root_n.o mp_rshd.o \ mp_sbin_size.o mp_set.o mp_set_double.o mp_set_i32.o mp_set_i64.o mp_set_l.o mp_set_u32.o mp_set_u64.o \ mp_set_ul.o mp_shrink.o mp_signed_rsh.o mp_sqrmod.o mp_sqrt.o mp_sqrtmod_prime.o mp_sub.o mp_sub_d.o \ mp_submod.o mp_to_radix.o mp_to_sbin.o mp_to_ubin.o mp_ubin_size.o mp_unpack.o mp_xor.o mp_zero.o s_mp_add.o \ -s_mp_copy_digs.o s_mp_div_3.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o \ -s_mp_exptmod_fast.o s_mp_get_bit.o s_mp_invmod.o s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o \ -s_mp_log_d.o s_mp_montgomery_reduce_comba.o s_mp_mul.o s_mp_mul_balance.o s_mp_mul_comba.o \ -s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o s_mp_mul_toom.o s_mp_prime_is_divisible.o \ -s_mp_prime_tab.o s_mp_radix_map.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o \ -s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o +s_mp_copy_digs.o s_mp_div_3.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o \ +s_mp_dr_is_modulus.o s_mp_dr_reduce.o s_mp_dr_setup.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_bit.o \ +s_mp_invmod.o s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o s_mp_log_d.o s_mp_montgomery_reduce_comba.o \ +s_mp_mul.o s_mp_mul_balance.o s_mp_mul_comba.o s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o \ +s_mp_mul_toom.o s_mp_prime_is_divisible.o s_mp_prime_tab.o s_mp_radix_map.o s_mp_rand_jenkins.o \ +s_mp_rand_platform.o s_mp_reduce.o s_mp_reduce_2k.o s_mp_reduce_2k_l.o s_mp_reduce_2k_setup.o \ +s_mp_reduce_2k_setup_l.o s_mp_reduce_is_2k.o s_mp_reduce_is_2k_l.o s_mp_reduce_setup.o s_mp_sqr.o \ +s_mp_sqr_comba.o s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o #END_INS diff --git a/makefile.mingw b/makefile.mingw index ae98a5c86..52459f00c 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -30,27 +30,27 @@ LIBMAIN_D =libtommath.dll #List of objects to compile (all goes to libtommath.a) OBJECTS=mp_2expt.o mp_abs.o mp_add.o mp_add_d.o mp_addmod.o mp_and.o mp_clamp.o mp_clear.o mp_clear_multi.o \ mp_cmp.o mp_cmp_d.o mp_cmp_mag.o mp_cnt_lsb.o mp_complement.o mp_copy.o mp_count_bits.o mp_cutoffs.o \ -mp_div.o mp_div_2.o mp_div_2d.o mp_div_d.o mp_dr_is_modulus.o mp_dr_reduce.o mp_dr_setup.o \ -mp_error_to_string.o mp_exch.o mp_expt_n.o mp_exptmod.o mp_exteuclid.o mp_fread.o mp_from_sbin.o \ -mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o mp_get_i64.o mp_get_l.o mp_get_mag_u32.o \ -mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_init.o mp_init_copy.o mp_init_i32.o mp_init_i64.o mp_init_l.o \ -mp_init_multi.o mp_init_set.o mp_init_size.o mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_invmod.o \ -mp_is_square.o mp_kronecker.o mp_lcm.o mp_log_n.o mp_lshd.o mp_mod.o mp_mod_2d.o \ -mp_montgomery_calc_normalization.o mp_montgomery_reduce.o mp_montgomery_setup.o mp_mul.o mp_mul_2.o \ -mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_fermat.o \ -mp_prime_frobenius_underwood.o mp_prime_is_prime.o mp_prime_miller_rabin.o mp_prime_next_prime.o \ -mp_prime_rabin_miller_trials.o mp_prime_rand.o mp_prime_strong_lucas_selfridge.o mp_radix_size.o \ -mp_rand.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o mp_reduce_2k_l.o mp_reduce_2k_setup.o \ -mp_reduce_2k_setup_l.o mp_reduce_is_2k.o mp_reduce_is_2k_l.o mp_reduce_setup.o mp_root_n.o mp_rshd.o \ +mp_div.o mp_div_2.o mp_div_2d.o mp_div_d.o mp_error_to_string.o mp_exch.o mp_expt_n.o mp_exptmod.o \ +mp_exteuclid.o mp_fread.o mp_from_sbin.o mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o \ +mp_get_i64.o mp_get_l.o mp_get_mag_u32.o mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_init.o \ +mp_init_copy.o mp_init_i32.o mp_init_i64.o mp_init_l.o mp_init_multi.o mp_init_set.o mp_init_size.o \ +mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_invmod.o mp_is_square.o mp_kronecker.o mp_lcm.o mp_log_n.o \ +mp_lshd.o mp_mod.o mp_mod_2d.o mp_montgomery_calc_normalization.o mp_montgomery_reduce.o \ +mp_montgomery_setup.o mp_mul.o mp_mul_2.o mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o \ +mp_pack_count.o mp_prime_fermat.o mp_prime_frobenius_underwood.o mp_prime_is_prime.o \ +mp_prime_miller_rabin.o mp_prime_next_prime.o mp_prime_rabin_miller_trials.o mp_prime_rand.o \ +mp_prime_strong_lucas_selfridge.o mp_radix_size.o mp_rand.o mp_read_radix.o mp_root_n.o mp_rshd.o \ mp_sbin_size.o mp_set.o mp_set_double.o mp_set_i32.o mp_set_i64.o mp_set_l.o mp_set_u32.o mp_set_u64.o \ mp_set_ul.o mp_shrink.o mp_signed_rsh.o mp_sqrmod.o mp_sqrt.o mp_sqrtmod_prime.o mp_sub.o mp_sub_d.o \ mp_submod.o mp_to_radix.o mp_to_sbin.o mp_to_ubin.o mp_ubin_size.o mp_unpack.o mp_xor.o mp_zero.o s_mp_add.o \ -s_mp_copy_digs.o s_mp_div_3.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o \ -s_mp_exptmod_fast.o s_mp_get_bit.o s_mp_invmod.o s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o \ -s_mp_log_d.o s_mp_montgomery_reduce_comba.o s_mp_mul.o s_mp_mul_balance.o s_mp_mul_comba.o \ -s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o s_mp_mul_toom.o s_mp_prime_is_divisible.o \ -s_mp_prime_tab.o s_mp_radix_map.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o \ -s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o +s_mp_copy_digs.o s_mp_div_3.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o \ +s_mp_dr_is_modulus.o s_mp_dr_reduce.o s_mp_dr_setup.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_bit.o \ +s_mp_invmod.o s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o s_mp_log_d.o s_mp_montgomery_reduce_comba.o \ +s_mp_mul.o s_mp_mul_balance.o s_mp_mul_comba.o s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o \ +s_mp_mul_toom.o s_mp_prime_is_divisible.o s_mp_prime_tab.o s_mp_radix_map.o s_mp_rand_jenkins.o \ +s_mp_rand_platform.o s_mp_reduce.o s_mp_reduce_2k.o s_mp_reduce_2k_l.o s_mp_reduce_2k_setup.o \ +s_mp_reduce_2k_setup_l.o s_mp_reduce_is_2k.o s_mp_reduce_is_2k_l.o s_mp_reduce_setup.o s_mp_sqr.o \ +s_mp_sqr_comba.o s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o HEADERS_PUB=tommath.h HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB) diff --git a/makefile.msvc b/makefile.msvc index 7dcbf3df1..e869ab88b 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -23,27 +23,27 @@ LIBMAIN_S =tommath.lib #List of objects to compile (all goes to tommath.lib) OBJECTS=mp_2expt.obj mp_abs.obj mp_add.obj mp_add_d.obj mp_addmod.obj mp_and.obj mp_clamp.obj mp_clear.obj mp_clear_multi.obj \ mp_cmp.obj mp_cmp_d.obj mp_cmp_mag.obj mp_cnt_lsb.obj mp_complement.obj mp_copy.obj mp_count_bits.obj mp_cutoffs.obj \ -mp_div.obj mp_div_2.obj mp_div_2d.obj mp_div_d.obj mp_dr_is_modulus.obj mp_dr_reduce.obj mp_dr_setup.obj \ -mp_error_to_string.obj mp_exch.obj mp_expt_n.obj mp_exptmod.obj mp_exteuclid.obj mp_fread.obj mp_from_sbin.obj \ -mp_from_ubin.obj mp_fwrite.obj mp_gcd.obj mp_get_double.obj mp_get_i32.obj mp_get_i64.obj mp_get_l.obj mp_get_mag_u32.obj \ -mp_get_mag_u64.obj mp_get_mag_ul.obj mp_grow.obj mp_init.obj mp_init_copy.obj mp_init_i32.obj mp_init_i64.obj mp_init_l.obj \ -mp_init_multi.obj mp_init_set.obj mp_init_size.obj mp_init_u32.obj mp_init_u64.obj mp_init_ul.obj mp_invmod.obj \ -mp_is_square.obj mp_kronecker.obj mp_lcm.obj mp_log_n.obj mp_lshd.obj mp_mod.obj mp_mod_2d.obj \ -mp_montgomery_calc_normalization.obj mp_montgomery_reduce.obj mp_montgomery_setup.obj mp_mul.obj mp_mul_2.obj \ -mp_mul_2d.obj mp_mul_d.obj mp_mulmod.obj mp_neg.obj mp_or.obj mp_pack.obj mp_pack_count.obj mp_prime_fermat.obj \ -mp_prime_frobenius_underwood.obj mp_prime_is_prime.obj mp_prime_miller_rabin.obj mp_prime_next_prime.obj \ -mp_prime_rabin_miller_trials.obj mp_prime_rand.obj mp_prime_strong_lucas_selfridge.obj mp_radix_size.obj \ -mp_rand.obj mp_read_radix.obj mp_reduce.obj mp_reduce_2k.obj mp_reduce_2k_l.obj mp_reduce_2k_setup.obj \ -mp_reduce_2k_setup_l.obj mp_reduce_is_2k.obj mp_reduce_is_2k_l.obj mp_reduce_setup.obj mp_root_n.obj mp_rshd.obj \ +mp_div.obj mp_div_2.obj mp_div_2d.obj mp_div_d.obj mp_error_to_string.obj mp_exch.obj mp_expt_n.obj mp_exptmod.obj \ +mp_exteuclid.obj mp_fread.obj mp_from_sbin.obj mp_from_ubin.obj mp_fwrite.obj mp_gcd.obj mp_get_double.obj mp_get_i32.obj \ +mp_get_i64.obj mp_get_l.obj mp_get_mag_u32.obj mp_get_mag_u64.obj mp_get_mag_ul.obj mp_grow.obj mp_init.obj \ +mp_init_copy.obj mp_init_i32.obj mp_init_i64.obj mp_init_l.obj mp_init_multi.obj mp_init_set.obj mp_init_size.obj \ +mp_init_u32.obj mp_init_u64.obj mp_init_ul.obj mp_invmod.obj mp_is_square.obj mp_kronecker.obj mp_lcm.obj mp_log_n.obj \ +mp_lshd.obj mp_mod.obj mp_mod_2d.obj mp_montgomery_calc_normalization.obj mp_montgomery_reduce.obj \ +mp_montgomery_setup.obj mp_mul.obj mp_mul_2.obj mp_mul_2d.obj mp_mul_d.obj mp_mulmod.obj mp_neg.obj mp_or.obj mp_pack.obj \ +mp_pack_count.obj mp_prime_fermat.obj mp_prime_frobenius_underwood.obj mp_prime_is_prime.obj \ +mp_prime_miller_rabin.obj mp_prime_next_prime.obj mp_prime_rabin_miller_trials.obj mp_prime_rand.obj \ +mp_prime_strong_lucas_selfridge.obj mp_radix_size.obj mp_rand.obj mp_read_radix.obj mp_root_n.obj mp_rshd.obj \ mp_sbin_size.obj mp_set.obj mp_set_double.obj mp_set_i32.obj mp_set_i64.obj mp_set_l.obj mp_set_u32.obj mp_set_u64.obj \ mp_set_ul.obj mp_shrink.obj mp_signed_rsh.obj mp_sqrmod.obj mp_sqrt.obj mp_sqrtmod_prime.obj mp_sub.obj mp_sub_d.obj \ mp_submod.obj mp_to_radix.obj mp_to_sbin.obj mp_to_ubin.obj mp_ubin_size.obj mp_unpack.obj mp_xor.obj mp_zero.obj s_mp_add.obj \ -s_mp_copy_digs.obj s_mp_div_3.obj s_mp_div_recursive.obj s_mp_div_school.obj s_mp_div_small.obj s_mp_exptmod.obj \ -s_mp_exptmod_fast.obj s_mp_get_bit.obj s_mp_invmod.obj s_mp_invmod_odd.obj s_mp_log.obj s_mp_log_2expt.obj \ -s_mp_log_d.obj s_mp_montgomery_reduce_comba.obj s_mp_mul.obj s_mp_mul_balance.obj s_mp_mul_comba.obj \ -s_mp_mul_high.obj s_mp_mul_high_comba.obj s_mp_mul_karatsuba.obj s_mp_mul_toom.obj s_mp_prime_is_divisible.obj \ -s_mp_prime_tab.obj s_mp_radix_map.obj s_mp_rand_jenkins.obj s_mp_rand_platform.obj s_mp_sqr.obj s_mp_sqr_comba.obj \ -s_mp_sqr_karatsuba.obj s_mp_sqr_toom.obj s_mp_sub.obj s_mp_zero_buf.obj s_mp_zero_digs.obj +s_mp_copy_digs.obj s_mp_div_3.obj s_mp_div_recursive.obj s_mp_div_school.obj s_mp_div_small.obj \ +s_mp_dr_is_modulus.obj s_mp_dr_reduce.obj s_mp_dr_setup.obj s_mp_exptmod.obj s_mp_exptmod_fast.obj s_mp_get_bit.obj \ +s_mp_invmod.obj s_mp_invmod_odd.obj s_mp_log.obj s_mp_log_2expt.obj s_mp_log_d.obj s_mp_montgomery_reduce_comba.obj \ +s_mp_mul.obj s_mp_mul_balance.obj s_mp_mul_comba.obj s_mp_mul_high.obj s_mp_mul_high_comba.obj s_mp_mul_karatsuba.obj \ +s_mp_mul_toom.obj s_mp_prime_is_divisible.obj s_mp_prime_tab.obj s_mp_radix_map.obj s_mp_rand_jenkins.obj \ +s_mp_rand_platform.obj s_mp_reduce.obj s_mp_reduce_2k.obj s_mp_reduce_2k_l.obj s_mp_reduce_2k_setup.obj \ +s_mp_reduce_2k_setup_l.obj s_mp_reduce_is_2k.obj s_mp_reduce_is_2k_l.obj s_mp_reduce_setup.obj s_mp_sqr.obj \ +s_mp_sqr_comba.obj s_mp_sqr_karatsuba.obj s_mp_sqr_toom.obj s_mp_sub.obj s_mp_zero_buf.obj s_mp_zero_digs.obj HEADERS_PUB=tommath.h HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB) diff --git a/makefile.shared b/makefile.shared index 2e24a43fb..33c82f205 100644 --- a/makefile.shared +++ b/makefile.shared @@ -25,27 +25,27 @@ LCOV_ARGS=--directory .libs --directory . #START_INS OBJECTS=mp_2expt.o mp_abs.o mp_add.o mp_add_d.o mp_addmod.o mp_and.o mp_clamp.o mp_clear.o mp_clear_multi.o \ mp_cmp.o mp_cmp_d.o mp_cmp_mag.o mp_cnt_lsb.o mp_complement.o mp_copy.o mp_count_bits.o mp_cutoffs.o \ -mp_div.o mp_div_2.o mp_div_2d.o mp_div_d.o mp_dr_is_modulus.o mp_dr_reduce.o mp_dr_setup.o \ -mp_error_to_string.o mp_exch.o mp_expt_n.o mp_exptmod.o mp_exteuclid.o mp_fread.o mp_from_sbin.o \ -mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o mp_get_i64.o mp_get_l.o mp_get_mag_u32.o \ -mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_init.o mp_init_copy.o mp_init_i32.o mp_init_i64.o mp_init_l.o \ -mp_init_multi.o mp_init_set.o mp_init_size.o mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_invmod.o \ -mp_is_square.o mp_kronecker.o mp_lcm.o mp_log_n.o mp_lshd.o mp_mod.o mp_mod_2d.o \ -mp_montgomery_calc_normalization.o mp_montgomery_reduce.o mp_montgomery_setup.o mp_mul.o mp_mul_2.o \ -mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_fermat.o \ -mp_prime_frobenius_underwood.o mp_prime_is_prime.o mp_prime_miller_rabin.o mp_prime_next_prime.o \ -mp_prime_rabin_miller_trials.o mp_prime_rand.o mp_prime_strong_lucas_selfridge.o mp_radix_size.o \ -mp_rand.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o mp_reduce_2k_l.o mp_reduce_2k_setup.o \ -mp_reduce_2k_setup_l.o mp_reduce_is_2k.o mp_reduce_is_2k_l.o mp_reduce_setup.o mp_root_n.o mp_rshd.o \ +mp_div.o mp_div_2.o mp_div_2d.o mp_div_d.o mp_error_to_string.o mp_exch.o mp_expt_n.o mp_exptmod.o \ +mp_exteuclid.o mp_fread.o mp_from_sbin.o mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o \ +mp_get_i64.o mp_get_l.o mp_get_mag_u32.o mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_init.o \ +mp_init_copy.o mp_init_i32.o mp_init_i64.o mp_init_l.o mp_init_multi.o mp_init_set.o mp_init_size.o \ +mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_invmod.o mp_is_square.o mp_kronecker.o mp_lcm.o mp_log_n.o \ +mp_lshd.o mp_mod.o mp_mod_2d.o mp_montgomery_calc_normalization.o mp_montgomery_reduce.o \ +mp_montgomery_setup.o mp_mul.o mp_mul_2.o mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o \ +mp_pack_count.o mp_prime_fermat.o mp_prime_frobenius_underwood.o mp_prime_is_prime.o \ +mp_prime_miller_rabin.o mp_prime_next_prime.o mp_prime_rabin_miller_trials.o mp_prime_rand.o \ +mp_prime_strong_lucas_selfridge.o mp_radix_size.o mp_rand.o mp_read_radix.o mp_root_n.o mp_rshd.o \ mp_sbin_size.o mp_set.o mp_set_double.o mp_set_i32.o mp_set_i64.o mp_set_l.o mp_set_u32.o mp_set_u64.o \ mp_set_ul.o mp_shrink.o mp_signed_rsh.o mp_sqrmod.o mp_sqrt.o mp_sqrtmod_prime.o mp_sub.o mp_sub_d.o \ mp_submod.o mp_to_radix.o mp_to_sbin.o mp_to_ubin.o mp_ubin_size.o mp_unpack.o mp_xor.o mp_zero.o s_mp_add.o \ -s_mp_copy_digs.o s_mp_div_3.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o \ -s_mp_exptmod_fast.o s_mp_get_bit.o s_mp_invmod.o s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o \ -s_mp_log_d.o s_mp_montgomery_reduce_comba.o s_mp_mul.o s_mp_mul_balance.o s_mp_mul_comba.o \ -s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o s_mp_mul_toom.o s_mp_prime_is_divisible.o \ -s_mp_prime_tab.o s_mp_radix_map.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o \ -s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o +s_mp_copy_digs.o s_mp_div_3.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o \ +s_mp_dr_is_modulus.o s_mp_dr_reduce.o s_mp_dr_setup.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_bit.o \ +s_mp_invmod.o s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o s_mp_log_d.o s_mp_montgomery_reduce_comba.o \ +s_mp_mul.o s_mp_mul_balance.o s_mp_mul_comba.o s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o \ +s_mp_mul_toom.o s_mp_prime_is_divisible.o s_mp_prime_tab.o s_mp_radix_map.o s_mp_rand_jenkins.o \ +s_mp_rand_platform.o s_mp_reduce.o s_mp_reduce_2k.o s_mp_reduce_2k_l.o s_mp_reduce_2k_setup.o \ +s_mp_reduce_2k_setup_l.o s_mp_reduce_is_2k.o s_mp_reduce_is_2k_l.o s_mp_reduce_setup.o s_mp_sqr.o \ +s_mp_sqr_comba.o s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o #END_INS diff --git a/makefile.unix b/makefile.unix index 2b2589c98..30725d051 100644 --- a/makefile.unix +++ b/makefile.unix @@ -31,27 +31,27 @@ LIBMAIN_S = libtommath.a OBJECTS=mp_2expt.o mp_abs.o mp_add.o mp_add_d.o mp_addmod.o mp_and.o mp_clamp.o mp_clear.o mp_clear_multi.o \ mp_cmp.o mp_cmp_d.o mp_cmp_mag.o mp_cnt_lsb.o mp_complement.o mp_copy.o mp_count_bits.o mp_cutoffs.o \ -mp_div.o mp_div_2.o mp_div_2d.o mp_div_d.o mp_dr_is_modulus.o mp_dr_reduce.o mp_dr_setup.o \ -mp_error_to_string.o mp_exch.o mp_expt_n.o mp_exptmod.o mp_exteuclid.o mp_fread.o mp_from_sbin.o \ -mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o mp_get_i64.o mp_get_l.o mp_get_mag_u32.o \ -mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_init.o mp_init_copy.o mp_init_i32.o mp_init_i64.o mp_init_l.o \ -mp_init_multi.o mp_init_set.o mp_init_size.o mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_invmod.o \ -mp_is_square.o mp_kronecker.o mp_lcm.o mp_log_n.o mp_lshd.o mp_mod.o mp_mod_2d.o \ -mp_montgomery_calc_normalization.o mp_montgomery_reduce.o mp_montgomery_setup.o mp_mul.o mp_mul_2.o \ -mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_fermat.o \ -mp_prime_frobenius_underwood.o mp_prime_is_prime.o mp_prime_miller_rabin.o mp_prime_next_prime.o \ -mp_prime_rabin_miller_trials.o mp_prime_rand.o mp_prime_strong_lucas_selfridge.o mp_radix_size.o \ -mp_rand.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o mp_reduce_2k_l.o mp_reduce_2k_setup.o \ -mp_reduce_2k_setup_l.o mp_reduce_is_2k.o mp_reduce_is_2k_l.o mp_reduce_setup.o mp_root_n.o mp_rshd.o \ +mp_div.o mp_div_2.o mp_div_2d.o mp_div_d.o mp_error_to_string.o mp_exch.o mp_expt_n.o mp_exptmod.o \ +mp_exteuclid.o mp_fread.o mp_from_sbin.o mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o \ +mp_get_i64.o mp_get_l.o mp_get_mag_u32.o mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_init.o \ +mp_init_copy.o mp_init_i32.o mp_init_i64.o mp_init_l.o mp_init_multi.o mp_init_set.o mp_init_size.o \ +mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_invmod.o mp_is_square.o mp_kronecker.o mp_lcm.o mp_log_n.o \ +mp_lshd.o mp_mod.o mp_mod_2d.o mp_montgomery_calc_normalization.o mp_montgomery_reduce.o \ +mp_montgomery_setup.o mp_mul.o mp_mul_2.o mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o \ +mp_pack_count.o mp_prime_fermat.o mp_prime_frobenius_underwood.o mp_prime_is_prime.o \ +mp_prime_miller_rabin.o mp_prime_next_prime.o mp_prime_rabin_miller_trials.o mp_prime_rand.o \ +mp_prime_strong_lucas_selfridge.o mp_radix_size.o mp_rand.o mp_read_radix.o mp_root_n.o mp_rshd.o \ mp_sbin_size.o mp_set.o mp_set_double.o mp_set_i32.o mp_set_i64.o mp_set_l.o mp_set_u32.o mp_set_u64.o \ mp_set_ul.o mp_shrink.o mp_signed_rsh.o mp_sqrmod.o mp_sqrt.o mp_sqrtmod_prime.o mp_sub.o mp_sub_d.o \ mp_submod.o mp_to_radix.o mp_to_sbin.o mp_to_ubin.o mp_ubin_size.o mp_unpack.o mp_xor.o mp_zero.o s_mp_add.o \ -s_mp_copy_digs.o s_mp_div_3.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o \ -s_mp_exptmod_fast.o s_mp_get_bit.o s_mp_invmod.o s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o \ -s_mp_log_d.o s_mp_montgomery_reduce_comba.o s_mp_mul.o s_mp_mul_balance.o s_mp_mul_comba.o \ -s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o s_mp_mul_toom.o s_mp_prime_is_divisible.o \ -s_mp_prime_tab.o s_mp_radix_map.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o \ -s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o +s_mp_copy_digs.o s_mp_div_3.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o \ +s_mp_dr_is_modulus.o s_mp_dr_reduce.o s_mp_dr_setup.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_bit.o \ +s_mp_invmod.o s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o s_mp_log_d.o s_mp_montgomery_reduce_comba.o \ +s_mp_mul.o s_mp_mul_balance.o s_mp_mul_comba.o s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o \ +s_mp_mul_toom.o s_mp_prime_is_divisible.o s_mp_prime_tab.o s_mp_radix_map.o s_mp_rand_jenkins.o \ +s_mp_rand_platform.o s_mp_reduce.o s_mp_reduce_2k.o s_mp_reduce_2k_l.o s_mp_reduce_2k_setup.o \ +s_mp_reduce_2k_setup_l.o s_mp_reduce_is_2k.o s_mp_reduce_is_2k_l.o s_mp_reduce_setup.o s_mp_sqr.o \ +s_mp_sqr_comba.o s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o s_mp_zero_buf.o s_mp_zero_digs.o HEADERS_PUB=tommath.h HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB) diff --git a/mp_exptmod.c b/mp_exptmod.c index b8a5dccc2..cea43e2bb 100644 --- a/mp_exptmod.c +++ b/mp_exptmod.c @@ -48,17 +48,17 @@ mp_err mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y) } /* modified diminished radix reduction */ - if (MP_HAS(MP_REDUCE_IS_2K_L) && MP_HAS(MP_REDUCE_2K_L) && MP_HAS(S_MP_EXPTMOD) && - mp_reduce_is_2k_l(P)) { + if (MP_HAS(S_MP_REDUCE_IS_2K_L) && MP_HAS(S_MP_REDUCE_2K_L) && MP_HAS(S_MP_EXPTMOD) && + s_mp_reduce_is_2k_l(P)) { return s_mp_exptmod(G, X, P, Y, 1); } /* is it a DR modulus? default to no */ - dr = (MP_HAS(MP_DR_IS_MODULUS) && mp_dr_is_modulus(P)) ? 1 : 0; + dr = (MP_HAS(S_MP_DR_IS_MODULUS) && s_mp_dr_is_modulus(P)) ? 1 : 0; /* if not, is it a unrestricted DR modulus? */ - if (MP_HAS(MP_REDUCE_IS_2K) && (dr == 0)) { - dr = (mp_reduce_is_2k(P)) ? 2 : 0; + if (MP_HAS(S_MP_REDUCE_IS_2K) && (dr == 0)) { + dr = (s_mp_reduce_is_2k(P)) ? 2 : 0; } /* if the modulus is odd or dr != 0 use the montgomery method */ diff --git a/mp_dr_is_modulus.c b/s_mp_dr_is_modulus.c similarity index 88% rename from mp_dr_is_modulus.c rename to s_mp_dr_is_modulus.c index 72b3c9681..a29e1599c 100644 --- a/mp_dr_is_modulus.c +++ b/s_mp_dr_is_modulus.c @@ -1,10 +1,12 @@ #include "tommath_private.h" -#ifdef MP_DR_IS_MODULUS_C +#ifdef S_MP_DR_IS_MODULUS_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* determines if a number is a valid DR modulus */ -bool mp_dr_is_modulus(const mp_int *a) +bool s_mp_dr_is_modulus(const mp_int *a) { int ix; @@ -24,4 +26,5 @@ bool mp_dr_is_modulus(const mp_int *a) return true; } + #endif diff --git a/mp_dr_reduce.c b/s_mp_dr_reduce.c similarity index 95% rename from mp_dr_reduce.c rename to s_mp_dr_reduce.c index f0f6f35e6..34b828e07 100644 --- a/mp_dr_reduce.c +++ b/s_mp_dr_reduce.c @@ -1,8 +1,10 @@ #include "tommath_private.h" -#ifdef MP_DR_REDUCE_C +#ifdef S_MP_DR_REDUCE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* reduce "x" in place modulo "n" using the Diminished Radix algorithm. * * Based on algorithm from the paper @@ -17,7 +19,7 @@ * * Input x must be in the range 0 <= x <= (n-1)**2 */ -mp_err mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k) +mp_err s_mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k) { mp_err err; @@ -65,4 +67,6 @@ mp_err mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k) } return MP_OKAY; } + + #endif diff --git a/mp_dr_setup.c b/s_mp_dr_setup.c similarity index 84% rename from mp_dr_setup.c rename to s_mp_dr_setup.c index c5bb359a3..d931660cd 100644 --- a/mp_dr_setup.c +++ b/s_mp_dr_setup.c @@ -1,10 +1,11 @@ #include "tommath_private.h" -#ifdef MP_DR_SETUP_C +#ifdef S_MP_DR_SETUP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + /* determines the setup value */ -void mp_dr_setup(const mp_int *a, mp_digit *d) +void s_mp_dr_setup(const mp_int *a, mp_digit *d) { /* the casts are required if MP_DIGIT_BIT is one less than * the number of bits in a mp_digit [e.g. MP_DIGIT_BIT==31] @@ -12,4 +13,5 @@ void mp_dr_setup(const mp_int *a, mp_digit *d) *d = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - (mp_word)a->dp[0]); } + #endif diff --git a/s_mp_exptmod.c b/s_mp_exptmod.c index 2a89a2cbf..58ddda007 100644 --- a/s_mp_exptmod.c +++ b/s_mp_exptmod.c @@ -60,11 +60,11 @@ mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y if ((err = mp_init(&mu)) != MP_OKAY) goto LBL_M; if (redmode == 0) { - if ((err = mp_reduce_setup(&mu, P)) != MP_OKAY) goto LBL_MU; - redux = mp_reduce; + if ((err = s_mp_reduce_setup(&mu, P)) != MP_OKAY) goto LBL_MU; + redux = s_mp_reduce; } else { - if ((err = mp_reduce_2k_setup_l(P, &mu)) != MP_OKAY) goto LBL_MU; - redux = mp_reduce_2k_l; + if ((err = s_mp_reduce_2k_setup_l(P, &mu)) != MP_OKAY) goto LBL_MU; + redux = s_mp_reduce_2k_l; } /* create M table diff --git a/s_mp_exptmod_fast.c b/s_mp_exptmod_fast.c index e7729f49d..89efefc9e 100644 --- a/s_mp_exptmod_fast.c +++ b/s_mp_exptmod_fast.c @@ -92,18 +92,18 @@ mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_i goto LBL_M; } } else if (redmode == 1) { - if (MP_HAS(MP_DR_SETUP) && MP_HAS(MP_DR_REDUCE)) { + if (MP_HAS(S_MP_DR_SETUP) && MP_HAS(S_MP_DR_REDUCE)) { /* setup DR reduction for moduli of the form B**k - b */ - mp_dr_setup(P, &mp); - redux = mp_dr_reduce; + s_mp_dr_setup(P, &mp); + redux = s_mp_dr_reduce; } else { err = MP_VAL; goto LBL_M; } - } else if (MP_HAS(MP_REDUCE_2K_SETUP) && MP_HAS(MP_REDUCE_2K)) { + } else if (MP_HAS(S_MP_REDUCE_2K_SETUP) && MP_HAS(S_MP_REDUCE_2K)) { /* setup DR reduction for moduli of the form 2**k - b */ - if ((err = mp_reduce_2k_setup(P, &mp)) != MP_OKAY) goto LBL_M; - redux = mp_reduce_2k; + if ((err = s_mp_reduce_2k_setup(P, &mp)) != MP_OKAY) goto LBL_M; + redux = s_mp_reduce_2k; } else { err = MP_VAL; goto LBL_M; diff --git a/mp_reduce.c b/s_mp_reduce.c similarity index 95% rename from mp_reduce.c rename to s_mp_reduce.c index b6fae55cc..3b4b03c7d 100644 --- a/mp_reduce.c +++ b/s_mp_reduce.c @@ -1,13 +1,15 @@ #include "tommath_private.h" -#ifdef MP_REDUCE_C +#ifdef S_MP_REDUCE_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* reduces x mod m, assumes 0 < x < m**2, mu is * precomputed via mp_reduce_setup. * From HAC pp.604 Algorithm 14.42 */ -mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) +mp_err s_mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) { mp_int q; mp_err err; @@ -80,4 +82,6 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) return err; } + + #endif diff --git a/mp_reduce_2k.c b/s_mp_reduce_2k.c similarity index 91% rename from mp_reduce_2k.c rename to s_mp_reduce_2k.c index e635f5b90..01af44c82 100644 --- a/mp_reduce_2k.c +++ b/s_mp_reduce_2k.c @@ -1,10 +1,12 @@ #include "tommath_private.h" -#ifdef MP_REDUCE_2K_C +#ifdef S_MP_REDUCE_2K_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* reduces a modulo n where n is of the form 2**p - d */ -mp_err mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) +mp_err s_mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) { mp_int q; mp_err err; @@ -46,4 +48,5 @@ mp_err mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) return err; } + #endif diff --git a/mp_reduce_2k_l.c b/s_mp_reduce_2k_l.c similarity index 90% rename from mp_reduce_2k_l.c rename to s_mp_reduce_2k_l.c index 31d9a1882..1f400de0d 100644 --- a/mp_reduce_2k_l.c +++ b/s_mp_reduce_2k_l.c @@ -1,13 +1,15 @@ #include "tommath_private.h" -#ifdef MP_REDUCE_2K_L_C +#ifdef S_MP_REDUCE_2K_L_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* reduces a modulo n where n is of the form 2**p - d This differs from reduce_2k since "d" can be larger than a single digit. */ -mp_err mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) +mp_err s_mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) { mp_int q; mp_err err; @@ -49,4 +51,5 @@ mp_err mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) return err; } + #endif diff --git a/mp_reduce_2k_setup.c b/s_mp_reduce_2k_setup.c similarity index 84% rename from mp_reduce_2k_setup.c rename to s_mp_reduce_2k_setup.c index 51f884134..70ea9592b 100644 --- a/mp_reduce_2k_setup.c +++ b/s_mp_reduce_2k_setup.c @@ -1,10 +1,12 @@ #include "tommath_private.h" -#ifdef MP_REDUCE_2K_SETUP_C +#ifdef S_MP_REDUCE_2K_SETUP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* determines the setup value */ -mp_err mp_reduce_2k_setup(const mp_int *a, mp_digit *d) +mp_err s_mp_reduce_2k_setup(const mp_int *a, mp_digit *d) { mp_err err; mp_int tmp; @@ -27,4 +29,6 @@ mp_err mp_reduce_2k_setup(const mp_int *a, mp_digit *d) mp_clear(&tmp); return err; } + + #endif diff --git a/mp_reduce_2k_setup_l.c b/s_mp_reduce_2k_setup_l.c similarity index 83% rename from mp_reduce_2k_setup_l.c rename to s_mp_reduce_2k_setup_l.c index b647c9d88..5cfe45202 100644 --- a/mp_reduce_2k_setup_l.c +++ b/s_mp_reduce_2k_setup_l.c @@ -1,10 +1,12 @@ #include "tommath_private.h" -#ifdef MP_REDUCE_2K_SETUP_L_C +#ifdef S_MP_REDUCE_2K_SETUP_L_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* determines the setup value */ -mp_err mp_reduce_2k_setup_l(const mp_int *a, mp_int *d) +mp_err s_mp_reduce_2k_setup_l(const mp_int *a, mp_int *d) { mp_err err; mp_int tmp; @@ -25,4 +27,6 @@ mp_err mp_reduce_2k_setup_l(const mp_int *a, mp_int *d) mp_clear(&tmp); return err; } + + #endif diff --git a/mp_reduce_is_2k.c b/s_mp_reduce_is_2k.c similarity index 91% rename from mp_reduce_is_2k.c rename to s_mp_reduce_is_2k.c index 9774f96e9..f383ce3f0 100644 --- a/mp_reduce_is_2k.c +++ b/s_mp_reduce_is_2k.c @@ -1,10 +1,12 @@ #include "tommath_private.h" -#ifdef MP_REDUCE_IS_2K_C +#ifdef S_MP_REDUCE_IS_2K_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* determines if mp_reduce_2k can be used */ -bool mp_reduce_is_2k(const mp_int *a) +bool s_mp_reduce_is_2k(const mp_int *a) { if (mp_iszero(a)) { return false; @@ -31,4 +33,5 @@ bool mp_reduce_is_2k(const mp_int *a) } } + #endif diff --git a/mp_reduce_is_2k_l.c b/s_mp_reduce_is_2k_l.c similarity index 88% rename from mp_reduce_is_2k_l.c rename to s_mp_reduce_is_2k_l.c index 101b4a185..2d3c253dc 100644 --- a/mp_reduce_is_2k_l.c +++ b/s_mp_reduce_is_2k_l.c @@ -1,10 +1,12 @@ #include "tommath_private.h" -#ifdef MP_REDUCE_IS_2K_L_C +#ifdef S_MP_REDUCE_IS_2K_L_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* determines if reduce_2k_l can be used */ -bool mp_reduce_is_2k_l(const mp_int *a) +bool s_mp_reduce_is_2k_l(const mp_int *a) { if (mp_iszero(a)) { return false; @@ -24,4 +26,5 @@ bool mp_reduce_is_2k_l(const mp_int *a) } } + #endif diff --git a/mp_reduce_setup.c b/s_mp_reduce_setup.c similarity index 83% rename from mp_reduce_setup.c rename to s_mp_reduce_setup.c index e12056e1e..fb363213d 100644 --- a/mp_reduce_setup.c +++ b/s_mp_reduce_setup.c @@ -1,12 +1,14 @@ #include "tommath_private.h" -#ifdef MP_REDUCE_SETUP_C +#ifdef S_MP_REDUCE_SETUP_C /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + + /* pre-calculate the value required for Barrett reduction * For a given modulus "b" it calulates the value required in "a" */ -mp_err mp_reduce_setup(mp_int *a, const mp_int *b) +mp_err s_mp_reduce_setup(mp_int *a, const mp_int *b) { mp_err err; if ((err = mp_2expt(a, b->used * 2 * MP_DIGIT_BIT)) != MP_OKAY) { @@ -14,4 +16,6 @@ mp_err mp_reduce_setup(mp_int *a, const mp_int *b) } return mp_div(a, b, a, NULL); } + + #endif diff --git a/tommath_class.h b/tommath_class.h index 936a17e46..e4ec35e56 100644 --- a/tommath_class.h +++ b/tommath_class.h @@ -32,9 +32,6 @@ # define MP_DIV_2_C # define MP_DIV_2D_C # define MP_DIV_D_C -# define MP_DR_IS_MODULUS_C -# define MP_DR_REDUCE_C -# define MP_DR_SETUP_C # define MP_ERROR_TO_STRING_C # define MP_EXCH_C # define MP_EXPT_N_C @@ -95,14 +92,6 @@ # define MP_RADIX_SIZE_C # define MP_RAND_C # define MP_READ_RADIX_C -# define MP_REDUCE_C -# define MP_REDUCE_2K_C -# define MP_REDUCE_2K_L_C -# define MP_REDUCE_2K_SETUP_C -# define MP_REDUCE_2K_SETUP_L_C -# define MP_REDUCE_IS_2K_C -# define MP_REDUCE_IS_2K_L_C -# define MP_REDUCE_SETUP_C # define MP_ROOT_N_C # define MP_RSHD_C # define MP_SBIN_SIZE_C @@ -135,6 +124,9 @@ # define S_MP_DIV_RECURSIVE_C # define S_MP_DIV_SCHOOL_C # define S_MP_DIV_SMALL_C +# define S_MP_DR_IS_MODULUS_C +# define S_MP_DR_REDUCE_C +# define S_MP_DR_SETUP_C # define S_MP_EXPTMOD_C # define S_MP_EXPTMOD_FAST_C # define S_MP_GET_BIT_C @@ -156,6 +148,14 @@ # define S_MP_RADIX_MAP_C # define S_MP_RAND_JENKINS_C # define S_MP_RAND_PLATFORM_C +# define S_MP_REDUCE_C +# define S_MP_REDUCE_2K_C +# define S_MP_REDUCE_2K_L_C +# define S_MP_REDUCE_2K_SETUP_C +# define S_MP_REDUCE_2K_SETUP_L_C +# define S_MP_REDUCE_IS_2K_C +# define S_MP_REDUCE_IS_2K_L_C +# define S_MP_REDUCE_SETUP_C # define S_MP_SQR_C # define S_MP_SQR_COMBA_C # define S_MP_SQR_KARATSUBA_C @@ -270,20 +270,6 @@ # define S_MP_DIV_3_C #endif -#if defined(MP_DR_IS_MODULUS_C) -#endif - -#if defined(MP_DR_REDUCE_C) -# define MP_CLAMP_C -# define MP_CMP_MAG_C -# define MP_GROW_C -# define S_MP_SUB_C -# define S_MP_ZERO_DIGS_C -#endif - -#if defined(MP_DR_SETUP_C) -#endif - #if defined(MP_ERROR_TO_STRING_C) #endif @@ -702,74 +688,6 @@ # define MP_ZERO_C #endif -#if defined(MP_REDUCE_C) -# define MP_ADD_C -# define MP_CLEAR_C -# define MP_CMP_C -# define MP_CMP_D_C -# define MP_INIT_COPY_C -# define MP_LSHD_C -# define MP_MOD_2D_C -# define MP_MUL_C -# define MP_RSHD_C -# define MP_SET_C -# define MP_SUB_C -# define S_MP_MUL_C -# define S_MP_MUL_HIGH_C -# define S_MP_MUL_HIGH_COMBA_C -# define S_MP_SUB_C -#endif - -#if defined(MP_REDUCE_2K_C) -# define MP_CLEAR_C -# define MP_CMP_MAG_C -# define MP_COUNT_BITS_C -# define MP_DIV_2D_C -# define MP_INIT_C -# define MP_MUL_D_C -# define S_MP_ADD_C -# define S_MP_SUB_C -#endif - -#if defined(MP_REDUCE_2K_L_C) -# define MP_CLEAR_C -# define MP_CMP_MAG_C -# define MP_COUNT_BITS_C -# define MP_DIV_2D_C -# define MP_INIT_C -# define MP_MUL_C -# define S_MP_ADD_C -# define S_MP_SUB_C -#endif - -#if defined(MP_REDUCE_2K_SETUP_C) -# define MP_2EXPT_C -# define MP_CLEAR_C -# define MP_COUNT_BITS_C -# define MP_INIT_C -# define S_MP_SUB_C -#endif - -#if defined(MP_REDUCE_2K_SETUP_L_C) -# define MP_2EXPT_C -# define MP_CLEAR_C -# define MP_COUNT_BITS_C -# define MP_INIT_C -# define S_MP_SUB_C -#endif - -#if defined(MP_REDUCE_IS_2K_C) -# define MP_COUNT_BITS_C -#endif - -#if defined(MP_REDUCE_IS_2K_L_C) -#endif - -#if defined(MP_REDUCE_SETUP_C) -# define MP_2EXPT_C -# define MP_DIV_C -#endif - #if defined(MP_ROOT_N_C) # define MP_2EXPT_C # define MP_ADD_D_C @@ -997,6 +915,20 @@ # define MP_SUB_C #endif +#if defined(S_MP_DR_IS_MODULUS_C) +#endif + +#if defined(S_MP_DR_REDUCE_C) +# define MP_CLAMP_C +# define MP_CMP_MAG_C +# define MP_GROW_C +# define S_MP_SUB_C +# define S_MP_ZERO_DIGS_C +#endif + +#if defined(S_MP_DR_SETUP_C) +#endif + #if defined(S_MP_EXPTMOD_C) # define MP_CLEAR_C # define MP_COPY_C @@ -1179,6 +1111,74 @@ #if defined(S_MP_RAND_PLATFORM_C) #endif +#if defined(S_MP_REDUCE_C) +# define MP_ADD_C +# define MP_CLEAR_C +# define MP_CMP_C +# define MP_CMP_D_C +# define MP_INIT_COPY_C +# define MP_LSHD_C +# define MP_MOD_2D_C +# define MP_MUL_C +# define MP_RSHD_C +# define MP_SET_C +# define MP_SUB_C +# define S_MP_MUL_C +# define S_MP_MUL_HIGH_C +# define S_MP_MUL_HIGH_COMBA_C +# define S_MP_SUB_C +#endif + +#if defined(S_MP_REDUCE_2K_C) +# define MP_CLEAR_C +# define MP_CMP_MAG_C +# define MP_COUNT_BITS_C +# define MP_DIV_2D_C +# define MP_INIT_C +# define MP_MUL_D_C +# define S_MP_ADD_C +# define S_MP_SUB_C +#endif + +#if defined(S_MP_REDUCE_2K_L_C) +# define MP_CLEAR_C +# define MP_CMP_MAG_C +# define MP_COUNT_BITS_C +# define MP_DIV_2D_C +# define MP_INIT_C +# define MP_MUL_C +# define S_MP_ADD_C +# define S_MP_SUB_C +#endif + +#if defined(S_MP_REDUCE_2K_SETUP_C) +# define MP_2EXPT_C +# define MP_CLEAR_C +# define MP_COUNT_BITS_C +# define MP_INIT_C +# define S_MP_SUB_C +#endif + +#if defined(S_MP_REDUCE_2K_SETUP_L_C) +# define MP_2EXPT_C +# define MP_CLEAR_C +# define MP_COUNT_BITS_C +# define MP_INIT_C +# define S_MP_SUB_C +#endif + +#if defined(S_MP_REDUCE_IS_2K_C) +# define MP_COUNT_BITS_C +#endif + +#if defined(S_MP_REDUCE_IS_2K_L_C) +#endif + +#if defined(S_MP_REDUCE_SETUP_C) +# define MP_2EXPT_C +# define MP_DIV_C +#endif + #if defined(S_MP_SQR_C) # define MP_CLAMP_C # define MP_CLEAR_C diff --git a/tommath_private.h b/tommath_private.h index 52095edda..e4d2c621d 100644 --- a/tommath_private.h +++ b/tommath_private.h @@ -173,41 +173,41 @@ MP_PRIVATE mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P MP_PRIVATE mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR; /* used to setup the Barrett reduction for a given modulus b */ -MP_PRIVATE mp_err mp_reduce_setup(mp_int *a, const mp_int *b) MP_WUR; +MP_PRIVATE mp_err s_mp_reduce_setup(mp_int *a, const mp_int *b) MP_WUR; /* Barrett Reduction, computes a (mod b) with a precomputed value c * * Assumes that 0 < x <= m*m, note if 0 > x > -(m*m) then you can merely * compute the reduction as -1 * mp_reduce(mp_abs(x)) [pseudo code]. */ -MP_PRIVATE mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) MP_WUR; +MP_PRIVATE mp_err s_mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) MP_WUR; /* returns 1 if a is a valid DR modulus */ -MP_PRIVATE bool mp_dr_is_modulus(const mp_int *a) MP_WUR; +MP_PRIVATE bool s_mp_dr_is_modulus(const mp_int *a) MP_WUR; /* sets the value of "d" required for mp_dr_reduce */ -MP_PRIVATE void mp_dr_setup(const mp_int *a, mp_digit *d); +MP_PRIVATE void s_mp_dr_setup(const mp_int *a, mp_digit *d); /* reduces a modulo n using the Diminished Radix method */ -MP_PRIVATE mp_err mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k) MP_WUR; +MP_PRIVATE mp_err s_mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k) MP_WUR; /* returns true if a can be reduced with mp_reduce_2k */ -MP_PRIVATE bool mp_reduce_is_2k(const mp_int *a) MP_WUR; +MP_PRIVATE bool s_mp_reduce_is_2k(const mp_int *a) MP_WUR; /* determines k value for 2k reduction */ -MP_PRIVATE mp_err mp_reduce_2k_setup(const mp_int *a, mp_digit *d) MP_WUR; +MP_PRIVATE mp_err s_mp_reduce_2k_setup(const mp_int *a, mp_digit *d) MP_WUR; /* reduces a modulo b where b is of the form 2**p - k [0 <= a] */ -MP_PRIVATE mp_err mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) MP_WUR; +MP_PRIVATE mp_err s_mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) MP_WUR; /* returns true if a can be reduced with mp_reduce_2k_l */ -MP_PRIVATE bool mp_reduce_is_2k_l(const mp_int *a) MP_WUR; +MP_PRIVATE bool s_mp_reduce_is_2k_l(const mp_int *a) MP_WUR; /* determines k value for 2k reduction */ -MP_PRIVATE mp_err mp_reduce_2k_setup_l(const mp_int *a, mp_int *d) MP_WUR; +MP_PRIVATE mp_err s_mp_reduce_2k_setup_l(const mp_int *a, mp_int *d) MP_WUR; /* reduces a modulo b where b is of the form 2**p - k [0 <= a] */ -MP_PRIVATE mp_err mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) MP_WUR; +MP_PRIVATE mp_err s_mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) MP_WUR; MP_PRIVATE mp_err s_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; MP_PRIVATE mp_err s_mp_invmod_odd(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; From 62e0919652140650a55ee0ff809ff7d219380a20 Mon Sep 17 00:00:00 2001 From: czurnieden Date: Wed, 27 Nov 2019 17:42:20 +0100 Subject: [PATCH 3/3] Adapted tommath_superclass.h --- tommath.def | 11 ----------- tommath_class.h | 22 +++++++++++----------- tommath_superclass.h | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/tommath.def b/tommath.def index 88733ca2a..a4f20d288 100644 --- a/tommath.def +++ b/tommath.def @@ -26,9 +26,6 @@ EXPORTS mp_div_2 mp_div_2d mp_div_d - mp_dr_is_modulus - mp_dr_reduce - mp_dr_setup mp_error_to_string mp_exch mp_expt_n @@ -89,14 +86,6 @@ EXPORTS mp_radix_size mp_rand mp_read_radix - mp_reduce - mp_reduce_2k - mp_reduce_2k_l - mp_reduce_2k_setup - mp_reduce_2k_setup_l - mp_reduce_is_2k - mp_reduce_is_2k_l - mp_reduce_setup mp_root_n mp_rshd mp_sbin_size diff --git a/tommath_class.h b/tommath_class.h index e4ec35e56..e03f8975a 100644 --- a/tommath_class.h +++ b/tommath_class.h @@ -286,13 +286,13 @@ #if defined(MP_EXPTMOD_C) # define MP_ABS_C # define MP_CLEAR_MULTI_C -# define MP_DR_IS_MODULUS_C # define MP_INIT_MULTI_C # define MP_INVMOD_C -# define MP_REDUCE_IS_2K_C -# define MP_REDUCE_IS_2K_L_C +# define S_MP_DR_IS_MODULUS_C # define S_MP_EXPTMOD_C # define S_MP_EXPTMOD_FAST_C +# define S_MP_REDUCE_IS_2K_C +# define S_MP_REDUCE_IS_2K_L_C #endif #if defined(MP_EXTEUCLID_C) @@ -937,19 +937,17 @@ # define MP_INIT_C # define MP_MOD_C # define MP_MUL_C -# define MP_REDUCE_2K_L_C -# define MP_REDUCE_2K_SETUP_L_C -# define MP_REDUCE_C -# define MP_REDUCE_SETUP_C # define MP_SET_C +# define S_MP_REDUCE_2K_L_C +# define S_MP_REDUCE_2K_SETUP_L_C +# define S_MP_REDUCE_C +# define S_MP_REDUCE_SETUP_C #endif #if defined(S_MP_EXPTMOD_FAST_C) # define MP_CLEAR_C # define MP_COPY_C # define MP_COUNT_BITS_C -# define MP_DR_REDUCE_C -# define MP_DR_SETUP_C # define MP_EXCH_C # define MP_INIT_SIZE_C # define MP_MOD_C @@ -958,10 +956,12 @@ # define MP_MONTGOMERY_SETUP_C # define MP_MULMOD_C # define MP_MUL_C -# define MP_REDUCE_2K_C -# define MP_REDUCE_2K_SETUP_C # define MP_SET_C +# define S_MP_DR_REDUCE_C +# define S_MP_DR_SETUP_C # define S_MP_MONTGOMERY_REDUCE_COMBA_C +# define S_MP_REDUCE_2K_C +# define S_MP_REDUCE_2K_SETUP_C #endif #if defined(S_MP_GET_BIT_C) diff --git a/tommath_superclass.h b/tommath_superclass.h index 9e85d9865..2901f1881 100644 --- a/tommath_superclass.h +++ b/tommath_superclass.h @@ -30,8 +30,8 @@ # define MP_RADIX_SIZE_C # define MP_LOG_N_C # define MP_RAND_C -# define MP_REDUCE_C -# define MP_REDUCE_2K_L_C +# define S_MP_REDUCE_C +# define S_MP_REDUCE_2K_L_C # define MP_FROM_SBIN_C # define MP_ROOT_N_C # define MP_SET_L_C @@ -75,13 +75,13 @@ * like removing support for even moduli, etc... */ # ifdef LTM_LAST -# undef MP_DR_IS_MODULUS_C -# undef MP_DR_REDUCE_C -# undef MP_DR_SETUP_C -# undef MP_REDUCE_2K_C -# undef MP_REDUCE_2K_SETUP_C -# undef MP_REDUCE_IS_2K_C -# undef MP_REDUCE_SETUP_C +# undef S_MP_DR_IS_MODULUS_C +# undef S_MP_DR_REDUCE_C +# undef S_MP_DR_SETUP_C +# undef S_MP_REDUCE_2K_C +# undef S_MP_REDUCE_2K_SETUP_C +# undef S_MP_REDUCE_IS_2K_C +# undef S_MP_REDUCE_SETUP_C # undef S_MP_DIV_3_C # undef S_MP_EXPTMOD_C # undef S_MP_INVMOD_ODD_C @@ -94,7 +94,7 @@ # undef S_MP_SQR_TOOM_C # ifndef SC_RSA_1_WITH_TESTS -# undef MP_REDUCE_C +# undef S_MP_REDUCE_C # endif /* To safely undefine these you have to make sure your RSA key won't exceed the Comba threshold