diff options
-rw-r--r-- | generic/regcomp.c | 1 | ||||
-rw-r--r-- | generic/tclStubInit.c | 6 | ||||
-rw-r--r-- | generic/tclTomMath.decls | 116 | ||||
-rw-r--r-- | generic/tclTomMath.h | 293 | ||||
-rw-r--r-- | generic/tclTomMathDecls.h | 235 | ||||
-rw-r--r-- | libtommath/bn_mp_error_to_string.c | 2 | ||||
-rw-r--r-- | libtommath/bn_mp_prime_next_prime.c | 7 | ||||
-rw-r--r-- | libtommath/bn_s_mp_toom_mul.c | 3 | ||||
-rw-r--r-- | libtommath/bn_s_mp_toom_sqr.c | 3 | ||||
-rw-r--r-- | libtommath/changes.txt | 2 | ||||
-rw-r--r-- | libtommath/makefile | 6 | ||||
-rw-r--r-- | libtommath/makefile_include.mk | 2 | ||||
-rw-r--r-- | libtommath/tommath.h | 2 |
13 files changed, 428 insertions, 250 deletions
diff --git a/generic/regcomp.c b/generic/regcomp.c index 3051446..219c16a 100644 --- a/generic/regcomp.c +++ b/generic/regcomp.c @@ -243,6 +243,7 @@ struct vars { #define EMPTYARC(x, y) newarc(v->nfa, EMPTY, 0, x, y) /* token type codes, some also used as NFA arc types */ +#undef DIGIT /* prevent conflict with libtommath */ #define EMPTY 'n' /* no token present */ #define EOS 'e' /* end of string */ #define PLAIN 'p' /* ordinary character */ diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 0a1cea3..2df2aae 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -73,18 +73,18 @@ static int TclSockMinimumBuffersOld(int sock, int size) static MP_SET_UNSIGNED(bn_mp_set_ull, Tcl_WideUInt) -int TclBN_mp_set_long(mp_int *a, unsigned long i) +mp_err TclBN_mp_set_long(mp_int *a, unsigned long i) { bn_mp_set_ull(a, i); return MP_OKAY; } -int TclBN_mp_set_int(mp_int *a, unsigned long i) +mp_err TclBN_mp_set_int(mp_int *a, unsigned long i) { return TclBN_mp_set_long(a, i); } -int TclBN_mp_init_set_int(mp_int *a, unsigned long i) +mp_err TclBN_mp_init_set_int(mp_int *a, unsigned long i) { mp_init(a); return TclBN_mp_set_long(a, i); diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls index a73dc2d..1ac1cb9 100644 --- a/generic/tclTomMath.decls +++ b/generic/tclTomMath.decls @@ -30,13 +30,13 @@ declare 1 { } declare 2 { - int TclBN_mp_add(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_add(const mp_int *a, const mp_int *b, mp_int *c) } declare 3 { - int TclBN_mp_add_d(const mp_int *a, mp_digit b, mp_int *c) + mp_err TclBN_mp_add_d(const mp_int *a, mp_digit b, mp_int *c) } declare 4 { - int TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c) } declare 5 { void TclBN_mp_clamp(mp_int *a) @@ -48,128 +48,128 @@ declare 7 { void TclBN_mp_clear_multi(mp_int *a, ...) } declare 8 { - int TclBN_mp_cmp(const mp_int *a, const mp_int *b) + mp_ord TclBN_mp_cmp(const mp_int *a, const mp_int *b) } declare 9 { - int TclBN_mp_cmp_d(const mp_int *a, mp_digit b) + mp_ord TclBN_mp_cmp_d(const mp_int *a, mp_digit b) } declare 10 { - int TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b) + mp_ord TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b) } declare 11 { - int TclBN_mp_copy(const mp_int *a, mp_int *b) + mp_err TclBN_mp_copy(const mp_int *a, mp_int *b) } declare 12 { int TclBN_mp_count_bits(const mp_int *a) } declare 13 { - int TclBN_mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r) + mp_err TclBN_mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r) } declare 14 { - int TclBN_mp_div_d(const mp_int *a, mp_digit b, mp_int *q, mp_digit *r) + mp_err TclBN_mp_div_d(const mp_int *a, mp_digit b, mp_int *q, mp_digit *r) } declare 15 { - int TclBN_mp_div_2(const mp_int *a, mp_int *q) + mp_err TclBN_mp_div_2(const mp_int *a, mp_int *q) } declare 16 { - int TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q, mp_int *r) + mp_err TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q, mp_int *r) } declare 17 { - int TclBN_mp_div_3(const mp_int *a, mp_int *q, mp_digit *r) + mp_err TclBN_mp_div_3(const mp_int *a, mp_int *q, mp_digit *r) } declare 18 { void TclBN_mp_exch(mp_int *a, mp_int *b) } declare 19 { - int TclBN_mp_expt_d(const mp_int *a, unsigned int b, mp_int *c) + mp_err TclBN_mp_expt_d(const mp_int *a, unsigned int b, mp_int *c) } declare 20 { - int TclBN_mp_grow(mp_int *a, int size) + mp_err TclBN_mp_grow(mp_int *a, int size) } declare 21 { - int TclBN_mp_init(mp_int *a) + mp_err TclBN_mp_init(mp_int *a) } declare 22 { - int TclBN_mp_init_copy(mp_int *a, const mp_int *b) + mp_err TclBN_mp_init_copy(mp_int *a, const mp_int *b) } declare 23 { - int TclBN_mp_init_multi(mp_int *a, ...) + mp_err TclBN_mp_init_multi(mp_int *a, ...) } declare 24 { - int TclBN_mp_init_set(mp_int *a, mp_digit b) + mp_err TclBN_mp_init_set(mp_int *a, mp_digit b) } declare 25 { - int TclBN_mp_init_size(mp_int *a, int size) + mp_err TclBN_mp_init_size(mp_int *a, int size) } declare 26 { - int TclBN_mp_lshd(mp_int *a, int shift) + mp_err TclBN_mp_lshd(mp_int *a, int shift) } declare 27 { - int TclBN_mp_mod(const mp_int *a, const mp_int *b, mp_int *r) + mp_err TclBN_mp_mod(const mp_int *a, const mp_int *b, mp_int *r) } declare 28 { - int TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r) + mp_err TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r) } declare 29 { - int TclBN_mp_mul(const mp_int *a, const mp_int *b, mp_int *p) + mp_err TclBN_mp_mul(const mp_int *a, const mp_int *b, mp_int *p) } declare 30 { - int TclBN_mp_mul_d(const mp_int *a, mp_digit b, mp_int *p) + mp_err TclBN_mp_mul_d(const mp_int *a, mp_digit b, mp_int *p) } declare 31 { - int TclBN_mp_mul_2(const mp_int *a, mp_int *p) + mp_err TclBN_mp_mul_2(const mp_int *a, mp_int *p) } declare 32 { - int TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p) + mp_err TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p) } declare 33 { - int TclBN_mp_neg(const mp_int *a, mp_int *b) + mp_err TclBN_mp_neg(const mp_int *a, mp_int *b) } declare 34 { - int TclBN_mp_or(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_or(const mp_int *a, const mp_int *b, mp_int *c) } declare 35 { - int TclBN_mp_radix_size(const mp_int *a, int radix, int *size) + mp_err TclBN_mp_radix_size(const mp_int *a, int radix, int *size) } declare 36 { - int TclBN_mp_read_radix(mp_int *a, const char *str, int radix) + mp_err TclBN_mp_read_radix(mp_int *a, const char *str, int radix) } declare 37 { void TclBN_mp_rshd(mp_int *a, int shift) } declare 38 { - int TclBN_mp_shrink(mp_int *a) + mp_err TclBN_mp_shrink(mp_int *a) } declare 39 { void TclBN_mp_set(mp_int *a, mp_digit b) } declare 40 { - int TclBN_mp_sqr(const mp_int *a, mp_int *b) + mp_err TclBN_mp_sqr(const mp_int *a, mp_int *b) } declare 41 { - int TclBN_mp_sqrt(const mp_int *a, mp_int *b) + mp_err TclBN_mp_sqrt(const mp_int *a, mp_int *b) } declare 42 { - int TclBN_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) } declare 43 { - int TclBN_mp_sub_d(const mp_int *a, mp_digit b, mp_int *c) + mp_err TclBN_mp_sub_d(const mp_int *a, mp_digit b, mp_int *c) } declare 44 { - int TclBN_mp_to_unsigned_bin(const mp_int *a, unsigned char *b) + mp_err TclBN_mp_to_unsigned_bin(const mp_int *a, unsigned char *b) } declare 45 { - int TclBN_mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, + mp_err TclBN_mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) } declare 46 { - int TclBN_mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen) + mp_err TclBN_mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen) } declare 47 { int TclBN_mp_unsigned_bin_size(const mp_int *a) } declare 48 { - int TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c) } declare 49 { void TclBN_mp_zero(mp_int *a) @@ -182,40 +182,40 @@ declare 50 { void TclBN_reverse(unsigned char *s, int len) } declare 51 { - int TclBN_fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) + mp_err TclBN_fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) } declare 52 { - int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b) + mp_err TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b) } declare 53 { - int TclBN_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c) } declare 54 { - int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b) + mp_err TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b) } declare 55 { - int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) } declare 56 { - int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b) + mp_err TclBN_mp_toom_sqr(const mp_int *a, mp_int *b) } declare 57 { - int TclBN_s_mp_add(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_s_mp_add(const mp_int *a, const mp_int *b, mp_int *c) } declare 58 { - int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) + mp_err TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) } declare 59 { - int TclBN_s_mp_sqr(const mp_int *a, mp_int *b) + mp_err TclBN_s_mp_sqr(const mp_int *a, mp_int *b) } declare 60 { - int TclBN_s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) } declare 61 { - int TclBN_mp_init_set_int(mp_int *a, unsigned long i) + mp_err TclBN_mp_init_set_int(mp_int *a, unsigned long i) } declare 62 { - int TclBN_mp_set_int(mp_int *a, unsigned long i) + mp_err TclBN_mp_set_int(mp_int *a, unsigned long i) } declare 63 { int TclBN_mp_cnt_lsb(const mp_int *a) @@ -235,28 +235,28 @@ declare 66 { # Added in libtommath 1.0 declare 67 { - int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) + mp_err TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) } declare 70 { - int TclBN_mp_set_long(mp_int *a, unsigned long i) + mp_err TclBN_mp_set_long(mp_int *a, unsigned long i) } # Added in libtommath 1.1.0 declare 73 { - int TclBN_mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) } declare 74 { - int TclBN_mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) } declare 75 { - int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) + mp_err TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) } declare 76 { - int TclBN_mp_signed_rsh(const mp_int *a, int b, mp_int *c) + mp_err TclBN_mp_signed_rsh(const mp_int *a, int b, mp_int *c) } declare 77 { - int TclBN_mp_get_bit(const mp_int *a, unsigned int b) + mp_bool TclBN_mp_get_bit(const mp_int *a, unsigned int b) } diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h index 20b4dfe..83a31d6 100644 --- a/generic/tclTomMath.h +++ b/generic/tclTomMath.h @@ -4,7 +4,6 @@ #ifndef BN_H_ #define BN_H_ -#include "tclTomMathDecls.h" #ifndef MODULE_SCOPE #define MODULE_SCOPE extern #endif @@ -149,7 +148,7 @@ typedef enum { MP_MEM = -2, /* out of mem */ MP_VAL = -3, /* invalid input */ MP_ITER = -4, /* maximum iterations reached */ - MP_BUF = -5, /* buffer overflow, supplied buffer too small */ + MP_BUF = -5 /* buffer overflow, supplied buffer too small */ } mp_err; typedef enum { MP_LSB_FIRST = -1, @@ -341,59 +340,133 @@ double mp_get_double(const mp_int *a) MP_WUR; mp_err mp_set_double(mp_int *a, double b) MP_WUR; */ -/* get integer, set integer and init with integer () */ +/* get integer, set integer and init with integer (int32_t) */ +#ifndef MP_NO_STDINT /* -int mp_get_i32(const mp_int *a) MP_WUR; +int32_t mp_get_i32(const mp_int *a) MP_WUR; */ /* -void mp_set_i32(mp_int *a, int b); +void mp_set_i32(mp_int *a, int32_t b); */ /* -mp_err mp_init_i32(mp_int *a, int b) MP_WUR; +mp_err mp_init_i32(mp_int *a, int32_t b) MP_WUR; */ -/* get integer, set integer and init with integer, behaves like two complement for negative numbers (unsigned int) */ -#define mp_get_u32(a) ((unsigned int)mp_get_i32(a)) +/* get integer, set integer and init with integer, behaves like two complement for negative numbers (uint32_t) */ +#define mp_get_u32(a) ((uint32_t)mp_get_i32(a)) /* -void mp_set_u32(mp_int *a, unsigned int b); +void mp_set_u32(mp_int *a, uint32_t b); */ /* -mp_err mp_init_u32(mp_int *a, unsigned int b) MP_WUR; +mp_err mp_init_u32(mp_int *a, uint32_t b) MP_WUR; */ -/* set to a digit */ +/* get integer, set integer and init with integer (int64_t) */ /* -void mp_set(mp_int *a, mp_digit b); +int64_t mp_get_i64(const mp_int *a) MP_WUR; +*/ +/* +void mp_set_i64(mp_int *a, int64_t b); +*/ +/* +mp_err mp_init_i64(mp_int *a, int64_t b) MP_WUR; +*/ + +/* get integer, set integer and init with integer, behaves like two complement for negative numbers (uint64_t) */ +#define mp_get_u64(a) ((uint64_t)mp_get_i64(a)) +/* +void mp_set_u64(mp_int *a, uint64_t b); +*/ +/* +mp_err mp_init_u64(mp_int *a, uint64_t b) MP_WUR; */ -/* set a 32-bit const */ +/* get magnitude */ +/* +uint32_t mp_get_mag_u32(const mp_int *a) MP_WUR; +*/ +/* +uint64_t mp_get_mag_u64(const mp_int *a) MP_WUR; +*/ +#endif +/* +unsigned long mp_get_mag_ul(const mp_int *a) MP_WUR; +*/ /* -int mp_set_int(mp_int *a, unsigned long b); +Tcl_WideUInt mp_get_mag_ull(const mp_int *a) MP_WUR; */ -/* set a platform dependent unsigned long value */ +/* get integer, set integer (long) */ +/* +long mp_get_l(const mp_int *a) MP_WUR; +*/ +/* +void mp_set_l(mp_int *a, long b); +*/ /* -int mp_set_long(mp_int *a, unsigned long b); +mp_err mp_init_l(mp_int *a, long b) MP_WUR; */ -/* set a platform dependent unsigned long long value */ +/* get integer, set integer (unsigned long) */ +#define mp_get_ul(a) ((unsigned long)mp_get_l(a)) +/* +void mp_set_ul(mp_int *a, unsigned long b); +*/ /* -int mp_set_long_long(mp_int *a, unsigned long long b); +mp_err mp_init_ul(mp_int *a, unsigned long b) MP_WUR; */ -/* get magnitude */ +/* get integer, set integer (Tcl_WideInt) */ +/* +Tcl_WideInt mp_get_ll(const mp_int *a) MP_WUR; +*/ +/* +void mp_set_ll(mp_int *a, Tcl_WideInt b); +*/ +/* +mp_err mp_init_ll(mp_int *a, Tcl_WideInt b) MP_WUR; +*/ + +/* get integer, set integer (Tcl_WideUInt) */ +#define mp_get_ull(a) ((Tcl_WideUInt)mp_get_ll(a)) /* -unsigned int mp_get_mag32(const mp_int *a) MP_WUR; +void mp_set_ull(mp_int *a, Tcl_WideUInt b); */ /* -unsigned long long mp_get_mag64(const mp_int *a) MP_WUR; +mp_err mp_init_ull(mp_int *a, Tcl_WideUInt b) MP_WUR; */ /* set to single unsigned digit, up to MP_DIGIT_MAX */ /* +void mp_set(mp_int *a, mp_digit b); +*/ +/* mp_err mp_init_set(mp_int *a, mp_digit b) MP_WUR; */ +/* get integer, set integer and init with integer (deprecated) */ +/* +MP_DEPRECATED(mp_get_mag_u32/mp_get_u32) unsigned long mp_get_int(const mp_int *a) MP_WUR; +*/ +/* +MP_DEPRECATED(mp_get_mag_ul/mp_get_ul) unsigned long mp_get_long(const mp_int *a) MP_WUR; +*/ +/* +MP_DEPRECATED(mp_get_mag_ull/mp_get_ull) Tcl_WideUInt mp_get_long_long(const mp_int *a) MP_WUR; +*/ +/* +MP_DEPRECATED(mp_set_ul) mp_err mp_set_int(mp_int *a, unsigned long b); +*/ +/* +MP_DEPRECATED(mp_set_ul) mp_err mp_set_long(mp_int *a, unsigned long b); +*/ +/* +MP_DEPRECATED(mp_set_ull) mp_err mp_set_long_long(mp_int *a, Tcl_WideUInt b); +*/ +/* +MP_DEPRECATED(mp_init_ul) mp_err mp_init_set_int(mp_int *a, unsigned long b) MP_WUR; +*/ + /* copy, b = a */ /* mp_err mp_copy(const mp_int *a, mp_int *b) MP_WUR; @@ -409,14 +482,32 @@ mp_err mp_init_copy(mp_int *a, const mp_int *b) MP_WUR; void mp_clamp(mp_int *a); */ +/* export binary data */ +/* +MP_DEPRECATED(mp_pack) mp_err mp_export(void *rop, size_t *countp, int order, size_t size, + int endian, size_t nails, const mp_int *op) MP_WUR; +*/ + /* import binary data */ /* -mp_err mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails, const void *op); +MP_DEPRECATED(mp_unpack) mp_err mp_import(mp_int *rop, size_t count, int order, + size_t size, int endian, size_t nails, + const void *op) MP_WUR; */ -/* export binary data */ +/* unpack binary data */ /* -mp_err mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, const mp_int *op); +mp_err mp_unpack(mp_int *rop, size_t count, mp_order order, size_t size, mp_endian endian, + size_t nails, const void *op) MP_WUR; +*/ + +/* pack binary data */ +/* +size_t mp_pack_count(const mp_int *a, size_t nails, size_t size) MP_WUR; +*/ +/* +mp_err mp_pack(void *rop, size_t maxcount, size_t *written, mp_order order, size_t size, + mp_endian endian, size_t nails, const mp_int *op) MP_WUR; */ /* ---> digit manipulation <--- */ @@ -496,32 +587,53 @@ extern void (*ltm_rng_callback)(void); #endif /* ---> binary operations <--- */ -/* c = a XOR b */ + +/* Checks the bit at position b and returns MP_YES + * if the bit is 1, MP_NO if it is 0 and MP_VAL + * in case of error + */ /* -int mp_xor(const mp_int *a, const mp_int *b, mp_int *c); +MP_DEPRECATED(s_mp_get_bit) int mp_get_bit(const mp_int *a, int b) MP_WUR; */ -/* c = a OR b */ +/* c = a XOR b (two complement) */ +/* +MP_DEPRECATED(mp_xor) mp_err mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; +*/ /* -int mp_or(const mp_int *a, const mp_int *b, mp_int *c); +mp_err mp_xor(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; */ -/* c = a AND b */ +/* c = a OR b (two complement) */ +/* +MP_DEPRECATED(mp_or) mp_err mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; +*/ /* -int mp_and(const mp_int *a, const mp_int *b, mp_int *c); +mp_err mp_or(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; */ -/* right shift (two complement) */ +/* c = a AND b (two complement) */ +/* +MP_DEPRECATED(mp_and) mp_err mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; +*/ /* -mp_err mp_signed_rsh(const mp_int *a, int b, mp_int *c); +mp_err mp_and(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; */ -/* ---> Basic arithmetic <--- */ +/* b = ~a (bitwise not, two complement) */ +/* +mp_err mp_complement(const mp_int *a, mp_int *b) MP_WUR; +*/ -/* b = ~a */ +/* right shift with sign extension */ /* -mp_err mp_complement(const mp_int *a, mp_int *b); +MP_DEPRECATED(mp_signed_rsh) mp_err mp_tc_div_2d(const mp_int *a, int b, mp_int *c) MP_WUR; */ +/* +mp_err mp_signed_rsh(const mp_int *a, int b, mp_int *c) MP_WUR; +*/ + +/* ---> Basic arithmetic <--- */ /* b = -a */ /* @@ -573,6 +685,16 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) MP_WUR; mp_err mp_mod(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; */ +/* Increment "a" by one like "a++". Changes input! */ +/* +mp_err mp_incr(mp_int *a) MP_WUR; +*/ + +/* Decrement "a" by one like "a--". Changes input! */ +/* +mp_err mp_decr(mp_int *a) MP_WUR; +*/ + /* ---> single digit functions <--- */ /* compare against a single digit */ @@ -600,16 +722,6 @@ mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c) MP_WUR; mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d) MP_WUR; */ -/* a/3 => 3c + d == a */ -/* -mp_err mp_div_3(const mp_int *a, mp_int *c, mp_digit *d) MP_WUR; -*/ - -/* c = a**b */ -/* -mp_err mp_expt_d(const mp_int *a, mp_digit b, mp_int *c) MP_WUR; -*/ - /* c = a mod b, 0 <= c < b */ /* mp_err mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c) MP_WUR; @@ -662,10 +774,13 @@ mp_err mp_lcm(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; * returns error if a < 0 and b is even */ /* -mp_err mp_n_root(const mp_int *a, mp_digit b, mp_int *c) MP_WUR; +mp_err mp_root_u32(const mp_int *a, unsigned int b, mp_int *c) MP_WUR; +*/ +/* +MP_DEPRECATED(mp_root_u32) mp_err mp_n_root(const mp_int *a, mp_digit b, mp_int *c) MP_WUR; */ /* -MP_DEPRECATED(mp_n_root_ex) mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) MP_WUR; +MP_DEPRECATED(mp_root_u32) mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) MP_WUR; */ /* special sqrt algo */ @@ -680,12 +795,17 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret) MP_WU /* is number a square? */ /* -mp_err mp_is_square(const mp_int *arg, int *ret) MP_WUR; +mp_err mp_is_square(const mp_int *arg, mp_bool *ret) MP_WUR; */ /* computes the jacobi c = (a | n) (or Legendre if b is prime) */ /* -mp_err mp_jacobi(const mp_int *a, const mp_int *n, int *c) MP_WUR; +MP_DEPRECATED(mp_kronecker) mp_err mp_jacobi(const mp_int *a, const mp_int *n, int *c) 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 */ @@ -773,14 +893,15 @@ mp_err mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y) /* number of primes */ #ifdef MP_8BIT -# define PRIME_SIZE 31 +# define PRIVATE_MP_PRIME_TAB_SIZE 31 #else -# define PRIME_SIZE 256 +# define PRIVATE_MP_PRIME_TAB_SIZE 256 #endif +#define PRIME_SIZE (MP_DEPRECATED_PRAGMA("PRIME_SIZE has been made internal") PRIVATE_MP_PRIME_TAB_SIZE) /* table of first PRIME_SIZE primes */ #if defined(BUILD_tcl) || !defined(_WIN32) -MODULE_SCOPE const mp_digit ltm_prime_tab[PRIME_SIZE]; +MODULE_SCOPE const mp_digit ltm_prime_tab[PRIVATE_MP_PRIME_TAB_SIZE]; #endif /* result=1 if a is divisible by one of the first PRIME_SIZE primes */ @@ -875,7 +996,27 @@ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style) MP_WUR; * */ /* -int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat); +MP_DEPRECATED(mp_prime_rand) mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags, + private_mp_prime_callback cb, void *dat) MP_WUR; +*/ +/* +mp_err mp_prime_rand(mp_int *a, int t, int size, int flags) MP_WUR; +*/ + +/* Integer logarithm to integer base */ +/* +mp_err mp_log_u32(const mp_int *a, unsigned int base, unsigned int *c) MP_WUR; +*/ + +/* c = a**b */ +/* +mp_err mp_expt_u32(const mp_int *a, unsigned int b, mp_int *c) MP_WUR; +*/ +/* +MP_DEPRECATED(mp_expt_u32) mp_err mp_expt_d(const mp_int *a, mp_digit b, mp_int *c) MP_WUR; +*/ +/* +MP_DEPRECATED(mp_expt_u32) mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) MP_WUR; */ /* ---> radix conversion <--- */ @@ -883,40 +1024,64 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback int mp_count_bits(const mp_int *a) MP_WUR; */ + +/* +MP_DEPRECATED(mp_ubin_size) int mp_unsigned_bin_size(const mp_int *a) MP_WUR; +*/ +/* +MP_DEPRECATED(mp_from_ubin) mp_err mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c) MP_WUR; +*/ +/* +MP_DEPRECATED(mp_to_ubin) mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b) MP_WUR; +*/ +/* +MP_DEPRECATED(mp_to_ubin) mp_err mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) MP_WUR; +*/ + /* -int mp_unsigned_bin_size(const mp_int *a) MP_WUR; +MP_DEPRECATED(mp_sbin_size) int mp_signed_bin_size(const mp_int *a) MP_WUR; */ /* -mp_err mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c) MP_WUR; +MP_DEPRECATED(mp_from_sbin) mp_err mp_read_signed_bin(mp_int *a, const unsigned char *b, int c) MP_WUR; */ /* -mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b) MP_WUR; +MP_DEPRECATED(mp_to_sbin) mp_err mp_to_signed_bin(const mp_int *a, unsigned char *b) MP_WUR; */ /* -mp_err mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) MP_WUR; +MP_DEPRECATED(mp_to_sbin) mp_err mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) MP_WUR; */ /* -int mp_signed_bin_size(const mp_int *a) MP_WUR; +size_t mp_ubin_size(const mp_int *a) MP_WUR; +*/ +/* +mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size) MP_WUR; +*/ +/* +mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written) MP_WUR; */ + /* -mp_err mp_read_signed_bin(mp_int *a, const unsigned char *b, int c) MP_WUR; +size_t mp_sbin_size(const mp_int *a) MP_WUR; */ /* -mp_err mp_to_signed_bin(const mp_int *a, unsigned char *b) MP_WUR; +mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size) MP_WUR; */ /* -mp_err mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) MP_WUR; +mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written) MP_WUR; */ /* mp_err mp_read_radix(mp_int *a, const char *str, int radix) MP_WUR; */ /* -mp_err mp_toradix(const mp_int *a, char *str, int radix) MP_WUR; +MP_DEPRECATED(mp_to_radix) mp_err mp_toradix(const mp_int *a, char *str, int radix) MP_WUR; */ /* -mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen) MP_WUR; +MP_DEPRECATED(mp_to_radix) mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen) MP_WUR; +*/ +/* +mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, int radix) MP_WUR; */ /* mp_err mp_radix_size(const mp_int *a, int radix, int *size) MP_WUR; @@ -952,4 +1117,6 @@ mp_err mp_fwrite(const mp_int *a, int radix, FILE *stream) MP_WUR; } #endif +#include "tclTomMathDecls.h" + #endif diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h index 1756863..be9d28e 100644 --- a/generic/tclTomMathDecls.h +++ b/generic/tclTomMathDecls.h @@ -16,6 +16,9 @@ #define _TCLTOMMATHDECLS #include "tcl.h" +#ifndef BN_H_ +#include "tclTomMath.h" +#endif /* * Define the version of the Stubs table that's exported for tommath @@ -163,13 +166,13 @@ EXTERN int TclBN_epoch(void); /* 1 */ EXTERN int TclBN_revision(void); /* 2 */ -EXTERN int TclBN_mp_add(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_add(const mp_int *a, const mp_int *b, mp_int *c); /* 3 */ -EXTERN int TclBN_mp_add_d(const mp_int *a, mp_digit b, +EXTERN mp_err TclBN_mp_add_d(const mp_int *a, mp_digit b, mp_int *c); /* 4 */ -EXTERN int TclBN_mp_and(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c); /* 5 */ EXTERN void TclBN_mp_clamp(mp_int *a); @@ -178,138 +181,138 @@ EXTERN void TclBN_mp_clear(mp_int *a); /* 7 */ EXTERN void TclBN_mp_clear_multi(mp_int *a, ...); /* 8 */ -EXTERN int TclBN_mp_cmp(const mp_int *a, const mp_int *b); +EXTERN mp_ord TclBN_mp_cmp(const mp_int *a, const mp_int *b); /* 9 */ -EXTERN int TclBN_mp_cmp_d(const mp_int *a, mp_digit b); +EXTERN mp_ord TclBN_mp_cmp_d(const mp_int *a, mp_digit b); /* 10 */ -EXTERN int TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b); +EXTERN mp_ord TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b); /* 11 */ -EXTERN int TclBN_mp_copy(const mp_int *a, mp_int *b); +EXTERN mp_err TclBN_mp_copy(const mp_int *a, mp_int *b); /* 12 */ EXTERN int TclBN_mp_count_bits(const mp_int *a); /* 13 */ -EXTERN int TclBN_mp_div(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r); /* 14 */ -EXTERN int TclBN_mp_div_d(const mp_int *a, mp_digit b, +EXTERN mp_err TclBN_mp_div_d(const mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 15 */ -EXTERN int TclBN_mp_div_2(const mp_int *a, mp_int *q); +EXTERN mp_err TclBN_mp_div_2(const mp_int *a, mp_int *q); /* 16 */ -EXTERN int TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q, +EXTERN mp_err TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q, mp_int *r); /* 17 */ -EXTERN int TclBN_mp_div_3(const mp_int *a, mp_int *q, +EXTERN mp_err TclBN_mp_div_3(const mp_int *a, mp_int *q, mp_digit *r); /* 18 */ EXTERN void TclBN_mp_exch(mp_int *a, mp_int *b); /* 19 */ -EXTERN int TclBN_mp_expt_d(const mp_int *a, unsigned int b, +EXTERN mp_err TclBN_mp_expt_d(const mp_int *a, unsigned int b, mp_int *c); /* 20 */ -EXTERN int TclBN_mp_grow(mp_int *a, int size); +EXTERN mp_err TclBN_mp_grow(mp_int *a, int size); /* 21 */ -EXTERN int TclBN_mp_init(mp_int *a); +EXTERN mp_err TclBN_mp_init(mp_int *a); /* 22 */ -EXTERN int TclBN_mp_init_copy(mp_int *a, const mp_int *b); +EXTERN mp_err TclBN_mp_init_copy(mp_int *a, const mp_int *b); /* 23 */ -EXTERN int TclBN_mp_init_multi(mp_int *a, ...); +EXTERN mp_err TclBN_mp_init_multi(mp_int *a, ...); /* 24 */ -EXTERN int TclBN_mp_init_set(mp_int *a, mp_digit b); +EXTERN mp_err TclBN_mp_init_set(mp_int *a, mp_digit b); /* 25 */ -EXTERN int TclBN_mp_init_size(mp_int *a, int size); +EXTERN mp_err TclBN_mp_init_size(mp_int *a, int size); /* 26 */ -EXTERN int TclBN_mp_lshd(mp_int *a, int shift); +EXTERN mp_err TclBN_mp_lshd(mp_int *a, int shift); /* 27 */ -EXTERN int TclBN_mp_mod(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_mod(const mp_int *a, const mp_int *b, mp_int *r); /* 28 */ -EXTERN int TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r); +EXTERN mp_err TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r); /* 29 */ -EXTERN int TclBN_mp_mul(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_mul(const mp_int *a, const mp_int *b, mp_int *p); /* 30 */ -EXTERN int TclBN_mp_mul_d(const mp_int *a, mp_digit b, +EXTERN mp_err TclBN_mp_mul_d(const mp_int *a, mp_digit b, mp_int *p); /* 31 */ -EXTERN int TclBN_mp_mul_2(const mp_int *a, mp_int *p); +EXTERN mp_err TclBN_mp_mul_2(const mp_int *a, mp_int *p); /* 32 */ -EXTERN int TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p); +EXTERN mp_err TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p); /* 33 */ -EXTERN int TclBN_mp_neg(const mp_int *a, mp_int *b); +EXTERN mp_err TclBN_mp_neg(const mp_int *a, mp_int *b); /* 34 */ -EXTERN int TclBN_mp_or(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_or(const mp_int *a, const mp_int *b, mp_int *c); /* 35 */ -EXTERN int TclBN_mp_radix_size(const mp_int *a, int radix, +EXTERN mp_err TclBN_mp_radix_size(const mp_int *a, int radix, int *size); /* 36 */ -EXTERN int TclBN_mp_read_radix(mp_int *a, const char *str, +EXTERN mp_err TclBN_mp_read_radix(mp_int *a, const char *str, int radix); /* 37 */ EXTERN void TclBN_mp_rshd(mp_int *a, int shift); /* 38 */ -EXTERN int TclBN_mp_shrink(mp_int *a); +EXTERN mp_err TclBN_mp_shrink(mp_int *a); /* 39 */ EXTERN void TclBN_mp_set(mp_int *a, mp_digit b); /* 40 */ -EXTERN int TclBN_mp_sqr(const mp_int *a, mp_int *b); +EXTERN mp_err TclBN_mp_sqr(const mp_int *a, mp_int *b); /* 41 */ -EXTERN int TclBN_mp_sqrt(const mp_int *a, mp_int *b); +EXTERN mp_err TclBN_mp_sqrt(const mp_int *a, mp_int *b); /* 42 */ -EXTERN int TclBN_mp_sub(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_sub(const mp_int *a, const mp_int *b, mp_int *c); /* 43 */ -EXTERN int TclBN_mp_sub_d(const mp_int *a, mp_digit b, +EXTERN mp_err TclBN_mp_sub_d(const mp_int *a, mp_digit b, mp_int *c); /* 44 */ -EXTERN int TclBN_mp_to_unsigned_bin(const mp_int *a, +EXTERN mp_err TclBN_mp_to_unsigned_bin(const mp_int *a, unsigned char *b); /* 45 */ -EXTERN int TclBN_mp_to_unsigned_bin_n(const mp_int *a, +EXTERN mp_err TclBN_mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen); /* 46 */ -EXTERN int TclBN_mp_toradix_n(const mp_int *a, char *str, +EXTERN mp_err TclBN_mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen); /* 47 */ EXTERN int TclBN_mp_unsigned_bin_size(const mp_int *a); /* 48 */ -EXTERN int TclBN_mp_xor(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c); /* 49 */ EXTERN void TclBN_mp_zero(mp_int *a); /* 50 */ EXTERN void TclBN_reverse(unsigned char *s, int len); /* 51 */ -EXTERN int TclBN_fast_s_mp_mul_digs(const mp_int *a, +EXTERN mp_err TclBN_fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 52 */ -EXTERN int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b); +EXTERN mp_err TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b); /* 53 */ -EXTERN int TclBN_mp_karatsuba_mul(const mp_int *a, +EXTERN mp_err TclBN_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c); /* 54 */ -EXTERN int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b); +EXTERN mp_err TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b); /* 55 */ -EXTERN int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c); /* 56 */ -EXTERN int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b); +EXTERN mp_err TclBN_mp_toom_sqr(const mp_int *a, mp_int *b); /* 57 */ -EXTERN int TclBN_s_mp_add(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_s_mp_add(const mp_int *a, const mp_int *b, mp_int *c); /* 58 */ -EXTERN int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 59 */ -EXTERN int TclBN_s_mp_sqr(const mp_int *a, mp_int *b); +EXTERN mp_err TclBN_s_mp_sqr(const mp_int *a, mp_int *b); /* 60 */ -EXTERN int TclBN_s_mp_sub(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c); /* 61 */ -EXTERN int TclBN_mp_init_set_int(mp_int *a, unsigned long i); +EXTERN mp_err TclBN_mp_init_set_int(mp_int *a, unsigned long i); /* 62 */ -EXTERN int TclBN_mp_set_int(mp_int *a, unsigned long i); +EXTERN mp_err TclBN_mp_set_int(mp_int *a, unsigned long i); /* 63 */ EXTERN int TclBN_mp_cnt_lsb(const mp_int *a); /* 64 */ @@ -321,28 +324,28 @@ EXTERN void TclBNInitBignumFromWideInt(mp_int *bignum, EXTERN void TclBNInitBignumFromWideUInt(mp_int *bignum, Tcl_WideUInt initVal); /* 67 */ -EXTERN int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, +EXTERN mp_err TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast); /* Slot 68 is reserved */ /* Slot 69 is reserved */ /* 70 */ -EXTERN int TclBN_mp_set_long(mp_int *a, unsigned long i); +EXTERN mp_err TclBN_mp_set_long(mp_int *a, unsigned long i); /* Slot 71 is reserved */ /* Slot 72 is reserved */ /* 73 */ -EXTERN int TclBN_mp_tc_and(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c); /* 74 */ -EXTERN int TclBN_mp_tc_or(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c); /* 75 */ -EXTERN int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, +EXTERN mp_err TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c); /* 76 */ -EXTERN int TclBN_mp_signed_rsh(const mp_int *a, int b, +EXTERN mp_err TclBN_mp_signed_rsh(const mp_int *a, int b, mp_int *c); /* 77 */ -EXTERN int TclBN_mp_get_bit(const mp_int *a, unsigned int b); +EXTERN mp_bool TclBN_mp_get_bit(const mp_int *a, unsigned int b); typedef struct TclTomMathStubs { int magic; @@ -350,82 +353,82 @@ typedef struct TclTomMathStubs { int (*tclBN_epoch) (void); /* 0 */ int (*tclBN_revision) (void); /* 1 */ - int (*tclBN_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 2 */ - int (*tclBN_mp_add_d) (const mp_int *a, mp_digit b, mp_int *c); /* 3 */ - int (*tclBN_mp_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 4 */ + mp_err (*tclBN_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 2 */ + mp_err (*tclBN_mp_add_d) (const mp_int *a, mp_digit b, mp_int *c); /* 3 */ + mp_err (*tclBN_mp_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 4 */ void (*tclBN_mp_clamp) (mp_int *a); /* 5 */ void (*tclBN_mp_clear) (mp_int *a); /* 6 */ void (*tclBN_mp_clear_multi) (mp_int *a, ...); /* 7 */ - int (*tclBN_mp_cmp) (const mp_int *a, const mp_int *b); /* 8 */ - int (*tclBN_mp_cmp_d) (const mp_int *a, mp_digit b); /* 9 */ - int (*tclBN_mp_cmp_mag) (const mp_int *a, const mp_int *b); /* 10 */ - int (*tclBN_mp_copy) (const mp_int *a, mp_int *b); /* 11 */ + mp_ord (*tclBN_mp_cmp) (const mp_int *a, const mp_int *b); /* 8 */ + mp_ord (*tclBN_mp_cmp_d) (const mp_int *a, mp_digit b); /* 9 */ + mp_ord (*tclBN_mp_cmp_mag) (const mp_int *a, const mp_int *b); /* 10 */ + mp_err (*tclBN_mp_copy) (const mp_int *a, mp_int *b); /* 11 */ int (*tclBN_mp_count_bits) (const mp_int *a); /* 12 */ - int (*tclBN_mp_div) (const mp_int *a, const mp_int *b, mp_int *q, mp_int *r); /* 13 */ - int (*tclBN_mp_div_d) (const mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 14 */ - int (*tclBN_mp_div_2) (const mp_int *a, mp_int *q); /* 15 */ - int (*tclBN_mp_div_2d) (const mp_int *a, int b, mp_int *q, mp_int *r); /* 16 */ - int (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, mp_digit *r); /* 17 */ + mp_err (*tclBN_mp_div) (const mp_int *a, const mp_int *b, mp_int *q, mp_int *r); /* 13 */ + mp_err (*tclBN_mp_div_d) (const mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 14 */ + mp_err (*tclBN_mp_div_2) (const mp_int *a, mp_int *q); /* 15 */ + mp_err (*tclBN_mp_div_2d) (const mp_int *a, int b, mp_int *q, mp_int *r); /* 16 */ + mp_err (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, mp_digit *r); /* 17 */ void (*tclBN_mp_exch) (mp_int *a, mp_int *b); /* 18 */ - int (*tclBN_mp_expt_d) (const mp_int *a, unsigned int b, mp_int *c); /* 19 */ - int (*tclBN_mp_grow) (mp_int *a, int size); /* 20 */ - int (*tclBN_mp_init) (mp_int *a); /* 21 */ - int (*tclBN_mp_init_copy) (mp_int *a, const mp_int *b); /* 22 */ - int (*tclBN_mp_init_multi) (mp_int *a, ...); /* 23 */ - int (*tclBN_mp_init_set) (mp_int *a, mp_digit b); /* 24 */ - int (*tclBN_mp_init_size) (mp_int *a, int size); /* 25 */ - int (*tclBN_mp_lshd) (mp_int *a, int shift); /* 26 */ - int (*tclBN_mp_mod) (const mp_int *a, const mp_int *b, mp_int *r); /* 27 */ - int (*tclBN_mp_mod_2d) (const mp_int *a, int b, mp_int *r); /* 28 */ - int (*tclBN_mp_mul) (const mp_int *a, const mp_int *b, mp_int *p); /* 29 */ - int (*tclBN_mp_mul_d) (const mp_int *a, mp_digit b, mp_int *p); /* 30 */ - int (*tclBN_mp_mul_2) (const mp_int *a, mp_int *p); /* 31 */ - int (*tclBN_mp_mul_2d) (const mp_int *a, int d, mp_int *p); /* 32 */ - int (*tclBN_mp_neg) (const mp_int *a, mp_int *b); /* 33 */ - int (*tclBN_mp_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 34 */ - int (*tclBN_mp_radix_size) (const mp_int *a, int radix, int *size); /* 35 */ - int (*tclBN_mp_read_radix) (mp_int *a, const char *str, int radix); /* 36 */ + mp_err (*tclBN_mp_expt_d) (const mp_int *a, unsigned int b, mp_int *c); /* 19 */ + mp_err (*tclBN_mp_grow) (mp_int *a, int size); /* 20 */ + mp_err (*tclBN_mp_init) (mp_int *a); /* 21 */ + mp_err (*tclBN_mp_init_copy) (mp_int *a, const mp_int *b); /* 22 */ + mp_err (*tclBN_mp_init_multi) (mp_int *a, ...); /* 23 */ + mp_err (*tclBN_mp_init_set) (mp_int *a, mp_digit b); /* 24 */ + mp_err (*tclBN_mp_init_size) (mp_int *a, int size); /* 25 */ + mp_err (*tclBN_mp_lshd) (mp_int *a, int shift); /* 26 */ + mp_err (*tclBN_mp_mod) (const mp_int *a, const mp_int *b, mp_int *r); /* 27 */ + mp_err (*tclBN_mp_mod_2d) (const mp_int *a, int b, mp_int *r); /* 28 */ + mp_err (*tclBN_mp_mul) (const mp_int *a, const mp_int *b, mp_int *p); /* 29 */ + mp_err (*tclBN_mp_mul_d) (const mp_int *a, mp_digit b, mp_int *p); /* 30 */ + mp_err (*tclBN_mp_mul_2) (const mp_int *a, mp_int *p); /* 31 */ + mp_err (*tclBN_mp_mul_2d) (const mp_int *a, int d, mp_int *p); /* 32 */ + mp_err (*tclBN_mp_neg) (const mp_int *a, mp_int *b); /* 33 */ + mp_err (*tclBN_mp_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 34 */ + mp_err (*tclBN_mp_radix_size) (const mp_int *a, int radix, int *size); /* 35 */ + mp_err (*tclBN_mp_read_radix) (mp_int *a, const char *str, int radix); /* 36 */ void (*tclBN_mp_rshd) (mp_int *a, int shift); /* 37 */ - int (*tclBN_mp_shrink) (mp_int *a); /* 38 */ + mp_err (*tclBN_mp_shrink) (mp_int *a); /* 38 */ void (*tclBN_mp_set) (mp_int *a, mp_digit b); /* 39 */ - int (*tclBN_mp_sqr) (const mp_int *a, mp_int *b); /* 40 */ - int (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b); /* 41 */ - int (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 42 */ - int (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */ - int (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */ - int (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */ - int (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */ + mp_err (*tclBN_mp_sqr) (const mp_int *a, mp_int *b); /* 40 */ + mp_err (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b); /* 41 */ + mp_err (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 42 */ + mp_err (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */ + mp_err (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */ + mp_err (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */ + mp_err (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */ int (*tclBN_mp_unsigned_bin_size) (const mp_int *a); /* 47 */ - int (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */ + mp_err (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */ void (*tclBN_mp_zero) (mp_int *a); /* 49 */ void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */ - int (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */ - int (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */ - int (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */ - int (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */ - int (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */ - int (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */ - int (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */ - int (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */ - int (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */ - int (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */ - int (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */ - int (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */ + mp_err (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */ + mp_err (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */ + mp_err (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */ + mp_err (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */ + mp_err (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */ + mp_err (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */ + mp_err (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */ + mp_err (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */ + mp_err (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */ + mp_err (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */ + mp_err (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */ + mp_err (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */ int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */ void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */ void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */ void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */ - int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */ + mp_err (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */ void (*reserved68)(void); void (*reserved69)(void); - int (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */ + mp_err (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */ void (*reserved71)(void); void (*reserved72)(void); - int (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */ - int (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */ - int (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */ - int (*tclBN_mp_signed_rsh) (const mp_int *a, int b, mp_int *c); /* 76 */ - int (*tclBN_mp_get_bit) (const mp_int *a, unsigned int b); /* 77 */ + mp_err (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */ + mp_err (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */ + mp_err (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */ + mp_err (*tclBN_mp_signed_rsh) (const mp_int *a, int b, mp_int *c); /* 76 */ + mp_bool (*tclBN_mp_get_bit) (const mp_int *a, unsigned int b); /* 77 */ } TclTomMathStubs; extern const TclTomMathStubs *tclTomMathStubsPtr; diff --git a/libtommath/bn_mp_error_to_string.c b/libtommath/bn_mp_error_to_string.c index e936ec1..2e2adb0 100644 --- a/libtommath/bn_mp_error_to_string.c +++ b/libtommath/bn_mp_error_to_string.c @@ -17,6 +17,8 @@ const char *mp_error_to_string(mp_err code) return "Value out of range"; case MP_ITER: return "Max. iterations reached"; + case MP_BUF: + return "Buffer overflow"; default: return "Invalid error code"; } diff --git a/libtommath/bn_mp_prime_next_prime.c b/libtommath/bn_mp_prime_next_prime.c index 1e971fa..d656565 100644 --- a/libtommath/bn_mp_prime_next_prime.c +++ b/libtommath/bn_mp_prime_next_prime.c @@ -10,9 +10,10 @@ */ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style) { - int x, y, cmp; - mp_err err; - mp_bool res = MP_NO; + int x, y; + mp_ord cmp; + mp_err err; + mp_bool res = MP_NO; mp_digit res_tab[PRIVATE_MP_PRIME_TAB_SIZE], step, kstep; mp_int b; diff --git a/libtommath/bn_s_mp_toom_mul.c b/libtommath/bn_s_mp_toom_mul.c index 8efd803..86901b0 100644 --- a/libtommath/bn_s_mp_toom_mul.c +++ b/libtommath/bn_s_mp_toom_mul.c @@ -32,7 +32,8 @@ mp_err s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) { mp_int S1, S2, T1, a0, a1, a2, b0, b1, b2; - int err, B, count; + int B, count; + mp_err err; /* init temps */ if ((err = mp_init_multi(&S1, &S2, &T1, NULL)) != MP_OKAY) { diff --git a/libtommath/bn_s_mp_toom_sqr.c b/libtommath/bn_s_mp_toom_sqr.c index 9eaa9d0..f2ffb30 100644 --- a/libtommath/bn_s_mp_toom_sqr.c +++ b/libtommath/bn_s_mp_toom_sqr.c @@ -22,7 +22,8 @@ mp_err s_mp_toom_sqr(const mp_int *a, mp_int *b) { mp_int S0, a0, a1, a2; mp_digit *tmpa, *tmpc; - mp_err err, B, count; + int B, count; + mp_err err; /* init temps */ diff --git a/libtommath/changes.txt b/libtommath/changes.txt index 6f44409..ebf7382 100644 --- a/libtommath/changes.txt +++ b/libtommath/changes.txt @@ -27,10 +27,12 @@ v1.2.0 -- The custom allocators which were formerly known as XMALLOC(), XFREE() etc. are now available as MP_MALLOC(), MP_REALLOC(), MP_CALLOC() and MP_FREE(). MP_REALLOC() and MP_FREE() now also provide the allocated size to ease the usage of simple allocators without tracking. + -- Building is now also possible with MSVC 2015, 2017 and 2019 (use makefile.msvc) -- Added mp_decr() and mp_incr() -- Added mp_log_u32() -- Improved prime-checking -- Improved Toom-Cook multiplication + -- Removed the LTM book (`make docs` now builds the user manual) Jan 28th, 2019 diff --git a/libtommath/makefile b/libtommath/makefile index df296de..be9fac6 100644 --- a/libtommath/makefile +++ b/libtommath/makefile @@ -123,7 +123,7 @@ tune: $(LIBNAME) coveralls: lcov coveralls-lcov -docdvi poster docs mandvi manual: +docs manual: $(MAKE) -C doc/ $@ V=$(V) .PHONY: pre_gen @@ -133,7 +133,7 @@ pre_gen: sed -e 's/[[:blank:]]*$$//' mpi.c > pre_gen/mpi.c rm mpi.c -zipup: clean astyle new_file manual poster +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. @@ -145,7 +145,7 @@ zipup: clean astyle new_file manual poster @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 doc/poster.pdf 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) diff --git a/libtommath/makefile_include.mk b/libtommath/makefile_include.mk index 00ae204..70f448f 100644 --- a/libtommath/makefile_include.mk +++ b/libtommath/makefile_include.mk @@ -3,7 +3,7 @@ # #version of library -VERSION=1.2.0-rc2 +VERSION=1.2.0-rc3 VERSION_PC=1.2.0 VERSION_SO=3:0:2 diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 4f82f88..22951c9 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -137,7 +137,7 @@ typedef enum { MP_MEM = -2, /* out of mem */ MP_VAL = -3, /* invalid input */ MP_ITER = -4, /* maximum iterations reached */ - MP_BUF = -5, /* buffer overflow, supplied buffer too small */ + MP_BUF = -5 /* buffer overflow, supplied buffer too small */ } mp_err; typedef enum { MP_LSB_FIRST = -1, |