diff --git a/demos/timing.c b/demos/timing.c index 8b252e222..4bba416a5 100644 --- a/demos/timing.c +++ b/demos/timing.c @@ -521,7 +521,7 @@ static void time_mult(void) unsigned long x, y; void *a, *b, *c; - if (ltc_mp.name == NULL) return; + if (mp_name() == NULL) return; fprintf(stderr, "Timing Multiplying:\n"); mp_init_multi(&a,&b,&c,NULL); @@ -554,7 +554,7 @@ static void time_sqr(void) unsigned long x, y; void *a, *b; - if (ltc_mp.name == NULL) return; + if (mp_name() == NULL) return; fprintf(stderr, "Timing Squaring:\n"); mp_init_multi(&a,&b,NULL); @@ -652,7 +652,7 @@ static const struct { #endif }; - if (ltc_mp.name == NULL) return; + if (mp_name() == NULL) return; for (x = 0; x < (sizeof(groups)/sizeof(groups[0])); x++) { t2 = 0; @@ -699,7 +699,7 @@ static void time_rsa(void) unsigned long x, y, z, zzz; int err, zz, stat; - if (ltc_mp.name == NULL) return; + if (mp_name() == NULL) return; for (x = 2048; x <= 8192; x <<= 1) { t2 = 0; @@ -830,7 +830,7 @@ static void time_dh(void) 100000 }; - if (ltc_mp.name == NULL) return; + if (mp_name() == NULL) return; for (x = sizes[i=0]; x < 100000; x = sizes[++i]) { t2 = 0; @@ -895,7 +895,7 @@ static void time_ecc(void) #endif 100000}; - if (ltc_mp.name == NULL) return; + if (mp_name() == NULL) return; for (x = sizes[i=0]; x < 100000; x = sizes[++i]) { t2 = 0; diff --git a/demos/tv_gen.c b/demos/tv_gen.c index 3cbc0e06d..54953a1df 100644 --- a/demos/tv_gen.c +++ b/demos/tv_gen.c @@ -686,7 +686,7 @@ static void ecc_gen(void) mp_set(G->z, 1); while (mp_cmp(k, order) == LTC_MP_LT) { - ltc_mp.ecc_ptmul(k, G, R, a, modulus, 1); + mp_ecc_ptmul(k, G, R, a, modulus, 1); mp_tohex(k, (char*)str); fprintf(out, "%s, ", (char*)str); mp_tohex(R->x, (char*)str); fprintf(out, "%s, ", (char*)str); mp_tohex(R->y, (char*)str); fprintf(out, "%s\n", (char*)str); @@ -807,7 +807,7 @@ int main(void) printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n"); #endif printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n"); - if (ltc_mp.name != NULL) { + if (mp_name() != NULL) { printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n"); printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n"); } diff --git a/makefile b/makefile index 32e8072a5..3c192749b 100644 --- a/makefile +++ b/makefile @@ -32,6 +32,18 @@ ifndef LIBNAME LIBNAME=libtomcrypt.a endif +ifndef LIBNAME_LTM + LIBNAME_LTM=libtomcrypt_ltm.a +endif + +ifndef LIBNAME_TFM + LIBNAME_TFM=libtomcrypt_tfm.a +endif + +ifndef LIBNAME_GMP + LIBNAME_GMP=libtomcrypt_gmp.a +endif + include makefile_include.mk @@ -57,21 +69,55 @@ ifneq ($V,1) endif ${silent} ${CC} ${LTC_CFLAGS} -c $< -o $@ -$(LIBNAME): $(OBJECTS) +$(LIBNAME): $(OBJECTS) $(MOBJECTS) +ifneq ($V,1) + @echo " * ${AR} $@" +endif + ${silent} $(AR) $(ARFLAGS) $@ $^ +ifneq ($V,1) + @echo " * ${RANLIB} $@" +endif + ${silent} $(RANLIB) $@ + +$(LIBNAME_LTM): $(OBJECTS) src/math/ltm_static.o ifneq ($V,1) @echo " * ${AR} $@" ${silent_echo} endif - ${silent} $(AR) $(ARFLAGS) $@ $(OBJECTS) + ${silent} $(AR) $(ARFLAGS) $@ $^ ifneq ($V,1) @echo " * ${RANLIB} $@" ${silent_echo} endif ${silent} $(RANLIB) $@ +$(LIBNAME_TFM): $(OBJECTS) src/math/tfm_static.o +ifneq ($V,1) + @echo " * ${AR} $@" +endif + ${silent} $(AR) $(ARFLAGS) $@ $^ +ifneq ($V,1) + @echo " * ${RANLIB} $@" +endif + ${silent} $(RANLIB) $@ + +$(LIBNAME_GMP): $(OBJECTS) src/math/gmp_static.o +ifneq ($V,1) + @echo " * ${AR} $@" +endif + ${silent} $(AR) $(ARFLAGS) $@ $^ +ifneq ($V,1) + @echo " * ${RANLIB} $@" +endif + ${silent} $(RANLIB) $@ + + test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) $(LIBNAME) $(TOBJECTS) ifneq ($V,1) @echo " * ${CC} $@" ${silent_echo} endif ${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(LTC_EXTRALIBS) -o $(TEST) + ${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME_LTM) $(LIB_POST) $(LTC_EXTRALIBS) -ltommath -o $(TEST)_ltm + ${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME_TFM) $(LIB_POST) $(LTC_EXTRALIBS) -o $(TEST)_tfm + ${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME_GMP) $(LIB_POST) $(LTC_EXTRALIBS) -o $(TEST)_gmp # build the demos from a template define DEMO_template diff --git a/makefile_include.mk b/makefile_include.mk index d466a2021..55d20912b 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -202,7 +202,7 @@ endif #The first rule is also the default rule and builds the libtomcrypt library. -library: $(call print-help,library,Builds the library) $(LIBNAME) +library: $(call print-help,library,Builds the library) $(LIBNAME) $(LIBNAME_LTM) $(LIBNAME_TFM) $(LIBNAME_GMP) # List of objects to compile (all goes to libtomcrypt.a) @@ -260,8 +260,8 @@ src/mac/poly1305/poly1305_file.o src/mac/poly1305/poly1305_memory.o \ src/mac/poly1305/poly1305_memory_multi.o src/mac/poly1305/poly1305_test.o src/mac/xcbc/xcbc_done.o \ src/mac/xcbc/xcbc_file.o src/mac/xcbc/xcbc_init.o src/mac/xcbc/xcbc_memory.o \ src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_test.o \ -src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src/math/ltm_desc.o src/math/multi.o \ -src/math/radix_to_bin.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o src/misc/adler32.o \ +src/math/fp/ltc_ecc_fp_mulmod.o src/math/multi.o \ +src/math/radix_to_bin.o src/math/rand_bn.o src/math/rand_prime.o src/misc/adler32.o \ src/misc/base16/base16_decode.o src/misc/base16/base16_encode.o src/misc/base32/base32_decode.o \ src/misc/base32/base32_encode.o src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o \ src/misc/bcrypt/bcrypt.o src/misc/burn_stack.o src/misc/compare_testvector.o src/misc/copy_or_zeromem.o \ @@ -393,6 +393,12 @@ src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \ src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o +# List of dynamic math objects to compile (all goes to libtomcrypt.a) +MOBJECTS=src/math/gmp_desc.o src/math/ltm_desc.o src/math/tfm_desc.o src/math/dynamic.o + +# List of static math objects +SOBJECTS=src/math/gmp_static.o src/math/ltm_static.o src/math/tfm_static.o + # List of test objects to compile (all goes to libtomcrypt_prof.a) TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/bcrypt_test.o \ tests/cipher_hash_test.o tests/common.o tests/der_test.o tests/dh_test.o tests/dsa_test.o \ @@ -424,7 +430,7 @@ $(DOBJECTS): LTC_CFLAGS := -Itests $(LTC_CFLAGS) $(TOBJECTS): LTC_CFLAGS := -Itests $(LTC_CFLAGS) #Dependencies on *.h -$(OBJECTS): $(HEADERS) +$(OBJECTS) $(MOBJECTS) $(SOBJECTS): $(HEADERS) $(DOBJECTS): $(HEADERS) $(THEADERS) $(TOBJECTS): $(HEADERS) $(THEADERS) diff --git a/src/headers/tomcrypt_math.h b/src/headers/tomcrypt_math.h index bb49915fc..f9b6a9d4c 100644 --- a/src/headers/tomcrypt_math.h +++ b/src/headers/tomcrypt_math.h @@ -506,6 +506,77 @@ int ltc_init_multi(void **a, ...); void ltc_deinit_multi(void *a, ...); void ltc_cleanup_multi(void **a, ...); +const char *ltc_mp_name(void); +int ltc_mp_bits_per_digit(void); +int ltc_mp_init(void *a); +void ltc_mp_deinit(void *a); +int ltc_mp_init_copy(void **dst, void *src); + +int ltc_mp_neg(void *src, void *dst); +int ltc_mp_copy(void *src, void *dst); + +int ltc_mp_set_int(void *a, ltc_mp_digit n); +unsigned long ltc_mp_get_int(void *a); +ltc_mp_digit ltc_mp_get_digit(void *a, int n); +int ltc_mp_get_digit_count(void *a); +int ltc_mp_compare(void *a, void *b); +int ltc_mp_compare_d(void *a, ltc_mp_digit n); +int ltc_mp_count_bits(void *a); +int ltc_mp_count_lsb_bits(void *a); +int ltc_mp_twoexpt(void *a , int n); + +int ltc_mp_read_radix(void *a, const char *str, int radix); +int ltc_mp_write_radix(void *a, char *str, int radix); +unsigned long ltc_mp_unsigned_size(void *a); +int ltc_mp_unsigned_write(void *src, unsigned char *dst); +int ltc_mp_unsigned_read(void *dst, unsigned char *src, unsigned long len); + +int ltc_mp_add(void *a, void *b, void *c); +int ltc_mp_addi(void *a, ltc_mp_digit b, void *c); +int ltc_mp_sub(void *a, void *b, void *c); +int ltc_mp_subi(void *a, ltc_mp_digit b, void *c); +int ltc_mp_mul(void *a, void *b, void *c); +int ltc_mp_muli(void *a, ltc_mp_digit b, void *c); +int ltc_mp_sqr(void *a, void *b); +int ltc_mp_sqrtmod_prime_support(void); +int ltc_mp_sqrtmod_prime(void *a, void *b, void *c); +int ltc_mp_mpdiv(void *a, void *b, void *c, void *d); +int ltc_mp_div_2(void *a, void *b); +int ltc_mp_modi(void *a, ltc_mp_digit b, ltc_mp_digit *c); +int ltc_mp_gcd(void *a, void *b, void *c); +int ltc_mp_lcm(void *a, void *b, void *c); + +int ltc_mp_rsa_me(const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen, int which, + const rsa_key *key); + +int ltc_mp_addmod(void *a, void *b, void *c, void *d); +int ltc_mp_submod(void *a, void *b, void *c, void *d); +int ltc_mp_mulmod(void *a, void *b, void *c, void *d); +int ltc_mp_sqrmod(void *a, void *b, void *c); +int ltc_mp_invmod(void *a, void *b, void *c); + +int ltc_mp_montgomery_setup(void *a, void **b); +int ltc_mp_montgomery_normalization(void *a, void *b); +int ltc_mp_montgomery_reduce(void *a, void *b, void *c); +void ltc_mp_montgomery_deinit(void *a); + +int ltc_mp_exptmod(void *a, void *b, void *c, void *d); +int ltc_mp_isprime(void *a, int b, int *c); + +int ltc_mp_ecc_ptmul(void *k, const ecc_point *G, ecc_point *R, void *a, + void *modulus, int map); +int ltc_mp_ecc_ptadd(const ecc_point *P, const ecc_point *Q, ecc_point *R, + void *ma, void *modulus, void *mp); +int ltc_mp_ecc_ptdbl(const ecc_point *P, ecc_point *R, void *ma, void *modulus, + void *mp); +int ltc_mp_ecc_map(ecc_point *P, void *modulus, void *mp); +int ltc_mp_ecc_mul2add_support(void); +int ltc_mp_ecc_mul2add(const ecc_point *A, void *kA, const ecc_point *B, + void *kB, ecc_point *C, void *ma, void *modulus); + +int ltc_mp_rand(void *a, int size); + #ifdef LTM_DESC extern const ltc_math_descriptor ltm_desc; #endif diff --git a/src/headers/tomcrypt_private.h b/src/headers/tomcrypt_private.h index 589323d6b..c95584928 100644 --- a/src/headers/tomcrypt_private.h +++ b/src/headers/tomcrypt_private.h @@ -130,64 +130,75 @@ void ocb3_int_xor_blocks(unsigned char *out, const unsigned char *block_a, const #if !defined(DESC_DEF_ONLY) -#define MP_DIGIT_BIT ltc_mp.bits_per_digit +#define MP_DIGIT_BIT ltc_mp_bits_per_digit() /* some handy macros */ -#define mp_init(a) ltc_mp.init(a) +#define mp_name() ltc_mp_name() +#define mp_init(a) ltc_mp_init(a) #define mp_init_multi ltc_init_multi -#define mp_clear(a) ltc_mp.deinit(a) +#define mp_clear(a) ltc_mp_deinit(a) #define mp_clear_multi ltc_deinit_multi #define mp_cleanup_multi ltc_cleanup_multi -#define mp_init_copy(a, b) ltc_mp.init_copy(a, b) - -#define mp_neg(a, b) ltc_mp.neg(a, b) -#define mp_copy(a, b) ltc_mp.copy(a, b) - -#define mp_set(a, b) ltc_mp.set_int(a, b) -#define mp_set_int(a, b) ltc_mp.set_int(a, b) -#define mp_get_int(a) ltc_mp.get_int(a) -#define mp_get_digit(a, n) ltc_mp.get_digit(a, n) -#define mp_get_digit_count(a) ltc_mp.get_digit_count(a) -#define mp_cmp(a, b) ltc_mp.compare(a, b) -#define mp_cmp_d(a, b) ltc_mp.compare_d(a, b) -#define mp_count_bits(a) ltc_mp.count_bits(a) -#define mp_cnt_lsb(a) ltc_mp.count_lsb_bits(a) -#define mp_2expt(a, b) ltc_mp.twoexpt(a, b) - -#define mp_read_radix(a, b, c) ltc_mp.read_radix(a, b, c) -#define mp_toradix(a, b, c) ltc_mp.write_radix(a, b, c) -#define mp_unsigned_bin_size(a) ltc_mp.unsigned_size(a) -#define mp_to_unsigned_bin(a, b) ltc_mp.unsigned_write(a, b) -#define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c) - -#define mp_add(a, b, c) ltc_mp.add(a, b, c) -#define mp_add_d(a, b, c) ltc_mp.addi(a, b, c) -#define mp_sub(a, b, c) ltc_mp.sub(a, b, c) -#define mp_sub_d(a, b, c) ltc_mp.subi(a, b, c) -#define mp_mul(a, b, c) ltc_mp.mul(a, b, c) -#define mp_mul_d(a, b, c) ltc_mp.muli(a, b, c) -#define mp_sqr(a, b) ltc_mp.sqr(a, b) -#define mp_sqrtmod_prime(a, b, c) ltc_mp.sqrtmod_prime(a, b, c) -#define mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d) -#define mp_div_2(a, b) ltc_mp.div_2(a, b) -#define mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c) -#define mp_mod_d(a, b, c) ltc_mp.modi(a, b, c) -#define mp_gcd(a, b, c) ltc_mp.gcd(a, b, c) -#define mp_lcm(a, b, c) ltc_mp.lcm(a, b, c) - -#define mp_addmod(a, b, c, d) ltc_mp.addmod(a, b, c, d) -#define mp_submod(a, b, c, d) ltc_mp.submod(a, b, c, d) -#define mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d) -#define mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c) -#define mp_invmod(a, b, c) ltc_mp.invmod(a, b, c) - -#define mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b) -#define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b) -#define mp_montgomery_reduce(a, b, c) ltc_mp.montgomery_reduce(a, b, c) -#define mp_montgomery_free(a) ltc_mp.montgomery_deinit(a) - -#define mp_exptmod(a,b,c,d) ltc_mp.exptmod(a,b,c,d) -#define mp_prime_is_prime(a, b, c) ltc_mp.isprime(a, b, c) +#define mp_init_copy(a, b) ltc_mp_init_copy(a, b) + +#define mp_neg(a, b) ltc_mp_neg(a, b) +#define mp_copy(a, b) ltc_mp_copy(a, b) + +#define mp_set(a, b) ltc_mp_set_int(a, b) +#define mp_set_int(a, b) ltc_mp_set_int(a, b) +#define mp_get_int(a) ltc_mp_get_int(a) +#define mp_get_digit(a, n) ltc_mp_get_digit(a, n) +#define mp_get_digit_count(a) ltc_mp_get_digit_count(a) +#define mp_cmp(a, b) ltc_mp_compare(a, b) +#define mp_cmp_d(a, b) ltc_mp_compare_d(a, b) +#define mp_count_bits(a) ltc_mp_count_bits(a) +#define mp_cnt_lsb(a) ltc_mp_count_lsb_bits(a) +#define mp_2expt(a, b) ltc_mp_twoexpt(a, b) + +#define mp_read_radix(a, b, c) ltc_mp_read_radix(a, b, c) +#define mp_toradix(a, b, c) ltc_mp_write_radix(a, b, c) +#define mp_unsigned_bin_size(a) ltc_mp_unsigned_size(a) +#define mp_to_unsigned_bin(a, b) ltc_mp_unsigned_write(a, b) +#define mp_read_unsigned_bin(a, b, c) ltc_mp_unsigned_read(a, b, c) + +#define mp_add(a, b, c) ltc_mp_add(a, b, c) +#define mp_add_d(a, b, c) ltc_mp_addi(a, b, c) +#define mp_sub(a, b, c) ltc_mp_sub(a, b, c) +#define mp_sub_d(a, b, c) ltc_mp_subi(a, b, c) +#define mp_mul(a, b, c) ltc_mp_mul(a, b, c) +#define mp_mul_d(a, b, c) ltc_mp_muli(a, b, c) +#define mp_sqr(a, b) ltc_mp_sqr(a, b) +#define mp_sqrtmod_prime_support() ltc_mp_sqrtmod_prime_support() +#define mp_sqrtmod_prime(a, b, c) ltc_mp_sqrtmod_prime(a, b, c) +#define mp_div(a, b, c, d) ltc_mp_mpdiv(a, b, c, d) +#define mp_div_2(a, b) ltc_mp_div_2(a, b) +#define mp_mod(a, b, c) ltc_mp_mpdiv(a, b, NULL, c) +#define mp_mod_d(a, b, c) ltc_mp_modi(a, b, c) +#define mp_gcd(a, b, c) ltc_mp_gcd(a, b, c) +#define mp_lcm(a, b, c) ltc_mp_lcm(a, b, c) + +#define mp_rsa_me(a, b, c, d, e, f) ltc_mp_rsa_me(a, b, c, d, e, f) + +#define mp_addmod(a, b, c, d) ltc_mp_addmod(a, b, c, d) +#define mp_submod(a, b, c, d) ltc_mp_submod(a, b, c, d) +#define mp_mulmod(a, b, c, d) ltc_mp_mulmod(a, b, c, d) +#define mp_sqrmod(a, b, c) ltc_mp_sqrmod(a, b, c) +#define mp_invmod(a, b, c) ltc_mp_invmod(a, b, c) + +#define mp_montgomery_setup(a, b) ltc_mp_montgomery_setup(a, b) +#define mp_montgomery_normalization(a, b) ltc_mp_montgomery_normalization(a, b) +#define mp_montgomery_reduce(a, b, c) ltc_mp_montgomery_reduce(a, b, c) +#define mp_montgomery_free(a) ltc_mp_montgomery_deinit(a) + +#define mp_exptmod(a,b,c,d) ltc_mp_exptmod(a,b,c,d) +#define mp_prime_is_prime(a, b, c) ltc_mp_isprime(a, b, c) + +#define mp_ecc_ptmul(a, b, c, d, e, f) ltc_mp_ecc_ptmul(a, b, c, d, e, f) +#define mp_ecc_ptadd(a, b, c, d, e, f) ltc_mp_ecc_ptadd(a, b, c, d, e, f) +#define mp_ecc_ptdbl(a, b, c, d, e) ltc_mp_ecc_ptdbl(a, b, c, d, e) +#define mp_ecc_map(a, b, c) ltc_mp_ecc_map(a, b, c) +#define mp_ecc_mul2add_support() ltc_mp_ecc_mul2add_support() +#define mp_ecc_mul2add(a, b, c, d, e, f, g) ltc_mp_ecc_mul2add(a, b, c, d, e, f, g) #define mp_iszero(a) (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO) #define mp_isodd(a) (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO) @@ -195,7 +206,7 @@ void ocb3_int_xor_blocks(unsigned char *out, const unsigned char *block_a, const #define mp_tohex(a, b) mp_toradix(a, b, 16) -#define mp_rand(a, b) ltc_mp.rand(a, b) +#define mp_rand(a, b) ltc_mp_rand(a, b) #endif diff --git a/src/math/dynamic.c b/src/math/dynamic.c new file mode 100644 index 000000000..9c7113f02 --- /dev/null +++ b/src/math/dynamic.c @@ -0,0 +1,277 @@ +#include "tomcrypt.h" + +const char *ltc_mp_name(void) +{ + return ltc_mp.name; +} + +int ltc_mp_bits_per_digit(void) +{ + return ltc_mp.bits_per_digit; +} + +int ltc_mp_init(void *a) +{ + return ltc_mp.init(a); +} + +void ltc_mp_deinit(void *a) +{ + ltc_mp.deinit(a); +} + +int ltc_mp_init_copy(void **dst, void *src) +{ + return ltc_mp.init_copy(dst, src); +} + +int ltc_mp_neg(void *src, void *dst) +{ + return ltc_mp.neg(src, dst); +} + +int ltc_mp_copy(void *src, void *dst) +{ + return ltc_mp.copy(src, dst); +} + +int ltc_mp_set_int(void *a, ltc_mp_digit n) +{ + return ltc_mp.set_int(a, n); +} + +unsigned long ltc_mp_get_int(void *a) +{ + return ltc_mp.get_int(a); +} + +ltc_mp_digit ltc_mp_get_digit(void *a, int n) +{ + return ltc_mp.get_digit(a, n); +} + +int ltc_mp_get_digit_count(void *a) +{ + return ltc_mp.get_digit_count(a); +} + +int ltc_mp_compare(void *a, void *b) +{ + return ltc_mp.compare(a, b); +} + +int ltc_mp_compare_d(void *a, ltc_mp_digit n) +{ + return ltc_mp.compare_d(a, n); +} + +int ltc_mp_count_bits(void *a) +{ + return ltc_mp.count_bits(a); +} + +int ltc_mp_count_lsb_bits(void *a) +{ + return ltc_mp.count_lsb_bits(a); +} + +int ltc_mp_twoexpt(void *a , int n) +{ + return ltc_mp.twoexpt(a, n); +} + +int ltc_mp_read_radix(void *a, const char *str, int radix) +{ + return ltc_mp.read_radix(a, str, radix); +} + +int ltc_mp_write_radix(void *a, char *str, int radix) +{ + return ltc_mp.write_radix(a, str, radix); +} + +unsigned long ltc_mp_unsigned_size(void *a) +{ + return ltc_mp.unsigned_size(a); +} + +int ltc_mp_unsigned_write(void *src, unsigned char *dst) +{ + return ltc_mp.unsigned_write(src, dst); +} + +int ltc_mp_unsigned_read(void *dst, unsigned char *src, unsigned long len) +{ + return ltc_mp.unsigned_read(dst, src, len); +} + +int ltc_mp_add(void *a, void *b, void *c) +{ + return ltc_mp.add(a, b, c); +} + +int ltc_mp_addi(void *a, ltc_mp_digit b, void *c) +{ + return ltc_mp.addi(a, b, c); +} + +int ltc_mp_sub(void *a, void *b, void *c) +{ + return ltc_mp.sub(a, b, c); +} + +int ltc_mp_subi(void *a, ltc_mp_digit b, void *c) +{ + return ltc_mp.subi(a, b, c); +} + +int ltc_mp_mul(void *a, void *b, void *c) +{ + return ltc_mp.mul(a, b, c); +} + +int ltc_mp_muli(void *a, ltc_mp_digit b, void *c) +{ + return ltc_mp.muli(a, b, c); +} + +int ltc_mp_sqr(void *a, void *b) +{ + return ltc_mp.sqr(a, b); +} + +int ltc_mp_sqrtmod_prime_support(void) +{ + return ltc_mp.sqrtmod_prime != NULL; +} + +int ltc_mp_sqrtmod_prime(void *a, void *b, void *c) +{ + return ltc_mp.sqrtmod_prime(a, b, c); +} + +int ltc_mp_mpdiv(void *a, void *b, void *c, void *d) +{ + return ltc_mp.mpdiv(a, b, c, d); +} + +int ltc_mp_div_2(void *a, void *b) +{ + return ltc_mp.div_2(a, b); +} + +int ltc_mp_modi(void *a, ltc_mp_digit b, ltc_mp_digit *c) +{ + return ltc_mp.modi(a, b, c); +} + +int ltc_mp_gcd(void *a, void *b, void *c) +{ + return ltc_mp.gcd(a, b, c); +} + +int ltc_mp_lcm(void *a, void *b, void *c) +{ + return ltc_mp.lcm(a, b, c); +} + +int ltc_mp_rsa_me(const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen, int which, + const rsa_key *key) +{ + return ltc_mp.rsa_me(in, inlen, out, outlen, which, key); +} + +int ltc_mp_addmod(void *a, void *b, void *c, void *d) +{ + return ltc_mp.addmod(a, b, c, d); +} + +int ltc_mp_submod(void *a, void *b, void *c, void *d) +{ + return ltc_mp.submod(a, b, c, d); +} + +int ltc_mp_mulmod(void *a, void *b, void *c, void *d) +{ + return ltc_mp.mulmod(a, b, c, d); +} + +int ltc_mp_sqrmod(void *a, void *b, void *c) +{ + return ltc_mp.sqrmod(a, b, c); +} + +int ltc_mp_invmod(void *a, void *b, void *c) +{ + return ltc_mp.invmod(a, b, c); +} + +int ltc_mp_montgomery_setup(void *a, void **b) +{ + return ltc_mp.montgomery_setup(a, b); +} + +int ltc_mp_montgomery_normalization(void *a, void *b) +{ + return ltc_mp.montgomery_normalization(a, b); +} + +int ltc_mp_montgomery_reduce(void *a, void *b, void *c) +{ + return ltc_mp.montgomery_reduce(a, b, c); +} + +void ltc_mp_montgomery_deinit(void *a) +{ + ltc_mp.montgomery_deinit(a); +} + +int ltc_mp_exptmod(void *a, void *b, void *c, void *d) +{ + return ltc_mp.exptmod(a,b,c,d); +} + +int ltc_mp_isprime(void *a, int b, int *c) +{ + return ltc_mp.isprime(a, b, c); +} + +int ltc_mp_ecc_ptmul(void *k, const ecc_point *G, ecc_point *R, void *a, + void *modulus, int map) +{ + return ltc_mp.ecc_ptmul(k, G, R, a, modulus, map); +} + +int ltc_mp_ecc_ptadd(const ecc_point *P, const ecc_point *Q, ecc_point *R, + void *ma, void *modulus, void *mp) +{ + return ltc_mp.ecc_ptadd(P, Q, R, ma, modulus, mp); +} + +int ltc_mp_ecc_ptdbl(const ecc_point *P, ecc_point *R, void *ma, void *modulus, + void *mp) +{ + return ltc_mp.ecc_ptdbl(P, R, ma, modulus, mp); +} + +int ltc_mp_ecc_map(ecc_point *P, void *modulus, void *mp) +{ + return ltc_mp.ecc_map(P, modulus, mp); +} + +int ltc_mp_ecc_mul2add_support(void) +{ + return ltc_mp.ecc_mul2add != NULL; +} + +int ltc_mp_ecc_mul2add(const ecc_point *A, void *kA, const ecc_point *B, + void *kB, ecc_point *C, void *ma, void *modulus) +{ + return ltc_mp.ecc_mul2add(A, kA, B, kB, C, ma, modulus); +} + +int ltc_mp_rand(void *a, int size) +{ + return ltc_mp.rand(a, size); +} diff --git a/src/math/fp/ltc_ecc_fp_mulmod.c b/src/math/fp/ltc_ecc_fp_mulmod.c index cb183868b..d7692ed04 100644 --- a/src/math/fp/ltc_ecc_fp_mulmod.c +++ b/src/math/fp/ltc_ecc_fp_mulmod.c @@ -701,7 +701,7 @@ static int _build_lut(int idx, void *a, void *modulus, void *mp, void *mu) /* now double it bitlen/FP_LUT times */ for (y = 0; y < lut_gap; y++) { - if ((err = ltc_mp.ecc_ptdbl(fp_cache[idx].LUT[1<> Result = point at infinity */ - ltc_mp.set_int(R->x, 1); - ltc_mp.set_int(R->y, 1); - ltc_mp.set_int(R->z, 0); + mp_set_int(R->x, 1); + mp_set_int(R->y, 1); + mp_set_int(R->z, 0); return CRYPT_OK; } @@ -598,18 +598,18 @@ static int tfm_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, if ((err = ltc_ecc_is_point_at_infinity(P, modulus, &inf)) != CRYPT_OK) return err; if (inf) { /* P is point at infinity >> Result = Q */ - ltc_mp.copy(Q->x, R->x); - ltc_mp.copy(Q->y, R->y); - ltc_mp.copy(Q->z, R->z); + mp_copy(Q->x, R->x); + mp_copy(Q->y, R->y); + mp_copy(Q->z, R->z); return CRYPT_OK; } if ((err = ltc_ecc_is_point_at_infinity(Q, modulus, &inf)) != CRYPT_OK) return err; if (inf) { /* Q is point at infinity >> Result = P */ - ltc_mp.copy(P->x, R->x); - ltc_mp.copy(P->y, R->y); - ltc_mp.copy(P->z, R->z); + mp_copy(P->x, R->x); + mp_copy(P->y, R->y); + mp_copy(P->z, R->z); return CRYPT_OK; } diff --git a/src/pk/dh/dh_generate_key.c b/src/pk/dh/dh_generate_key.c index c24f3764b..69fc420b2 100644 --- a/src/pk/dh/dh_generate_key.c +++ b/src/pk/dh/dh_generate_key.c @@ -41,7 +41,7 @@ int dh_generate_key(prng_state *prng, int wprng, dh_key *key) int err, max_iterations = LTC_PK_MAX_RETRIES; LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* good prng? */ if ((err = prng_is_valid(wprng)) != CRYPT_OK) { diff --git a/src/pk/dh/dh_set.c b/src/pk/dh/dh_set.c index 1f094f20e..8efbfe0ba 100644 --- a/src/pk/dh/dh_set.c +++ b/src/pk/dh/dh_set.c @@ -24,7 +24,7 @@ int dh_set_pg(const unsigned char *p, unsigned long plen, LTC_ARGCHK(key != NULL); LTC_ARGCHK(p != NULL); LTC_ARGCHK(g != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); if ((err = mp_init_multi(&key->x, &key->y, &key->base, &key->prime, NULL)) != CRYPT_OK) { return err; @@ -52,7 +52,7 @@ int dh_set_pg_groupsize(int groupsize, dh_key *key) int err, i; LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); LTC_ARGCHK(groupsize > 0); for (i = 0; (groupsize > ltc_dh_sets[i].size) && (ltc_dh_sets[i].size != 0); i++); @@ -87,7 +87,7 @@ int dh_set_key(const unsigned char *in, unsigned long inlen, int type, dh_key *k int err; LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); if (type == PK_PRIVATE) { key->type = PK_PRIVATE; diff --git a/src/pk/dh/dh_set_pg_dhparam.c b/src/pk/dh/dh_set_pg_dhparam.c index 972c6ac04..c24f0dee4 100644 --- a/src/pk/dh/dh_set_pg_dhparam.c +++ b/src/pk/dh/dh_set_pg_dhparam.c @@ -20,7 +20,7 @@ int dh_set_pg_dhparam(const unsigned char *dhparam, unsigned long dhparamlen, dh int err; LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); LTC_ARGCHK(dhparam != NULL); LTC_ARGCHK(dhparamlen > 0); diff --git a/src/pk/dsa/dsa_generate_key.c b/src/pk/dsa/dsa_generate_key.c index bc83c0ed9..fbe7fb7c3 100644 --- a/src/pk/dsa/dsa_generate_key.c +++ b/src/pk/dsa/dsa_generate_key.c @@ -21,7 +21,7 @@ int dsa_generate_key(prng_state *prng, int wprng, dsa_key *key) int err; LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* so now we have our DH structure, generator g, order q, modulus p Now we need a random exponent [mod q] and it's power g^x mod p diff --git a/src/pk/dsa/dsa_generate_pqg.c b/src/pk/dsa/dsa_generate_pqg.c index 1b7359c8d..bbe2151d2 100644 --- a/src/pk/dsa/dsa_generate_pqg.c +++ b/src/pk/dsa/dsa_generate_pqg.c @@ -210,7 +210,7 @@ int dsa_generate_pqg(prng_state *prng, int wprng, int group_size, int modulus_si int err; LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* init mp_ints */ if ((err = mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL)) != CRYPT_OK) { diff --git a/src/pk/dsa/dsa_import.c b/src/pk/dsa/dsa_import.c index a1d22818d..fb832a387 100644 --- a/src/pk/dsa/dsa_import.c +++ b/src/pk/dsa/dsa_import.c @@ -25,7 +25,7 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key) LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* init key */ if (mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL) != CRYPT_OK) { diff --git a/src/pk/dsa/dsa_set.c b/src/pk/dsa/dsa_set.c index 026f28066..066f63d7c 100644 --- a/src/pk/dsa/dsa_set.c +++ b/src/pk/dsa/dsa_set.c @@ -27,7 +27,7 @@ int dsa_set_pqg(const unsigned char *p, unsigned long plen, LTC_ARGCHK(q != NULL); LTC_ARGCHK(g != NULL); LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* init key */ err = mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL); @@ -74,7 +74,7 @@ int dsa_set_key(const unsigned char *in, unsigned long inlen, int type, dsa_key LTC_ARGCHK(key->p != NULL); LTC_ARGCHK(key->g != NULL); LTC_ARGCHK(key->q != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); if (type == PK_PRIVATE) { key->type = PK_PRIVATE; diff --git a/src/pk/dsa/dsa_set_pqg_dsaparam.c b/src/pk/dsa/dsa_set_pqg_dsaparam.c index 3ab922822..d42b226bb 100644 --- a/src/pk/dsa/dsa_set_pqg_dsaparam.c +++ b/src/pk/dsa/dsa_set_pqg_dsaparam.c @@ -22,7 +22,7 @@ int dsa_set_pqg_dsaparam(const unsigned char *dsaparam, unsigned long dsaparamle LTC_ARGCHK(dsaparam != NULL); LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* init key */ err = mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL); diff --git a/src/pk/ecc/ecc_encrypt_key.c b/src/pk/ecc/ecc_encrypt_key.c index 9929ff5af..58d174de9 100644 --- a/src/pk/ecc/ecc_encrypt_key.c +++ b/src/pk/ecc/ecc_encrypt_key.c @@ -67,7 +67,7 @@ int ecc_encrypt_key(const unsigned char *in, unsigned long inlen, } pubkeysize = ECC_BUF_SIZE; - if (ltc_mp.sqrtmod_prime != NULL) { + if (mp_sqrtmod_prime_support()) { /* PK_COMPRESSED requires sqrtmod_prime */ err = ecc_get_key(pub_expt, &pubkeysize, PK_PUBLIC|PK_COMPRESSED, &pubkey); } diff --git a/src/pk/ecc/ecc_import.c b/src/pk/ecc/ecc_import.c index 64bed21c9..83ba8ee17 100644 --- a/src/pk/ecc/ecc_import.c +++ b/src/pk/ecc/ecc_import.c @@ -38,7 +38,7 @@ int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, co LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* find out what type of key it is */ err = der_decode_sequence_multi(in, inlen, LTC_ASN1_BIT_STRING, 1UL, flags, diff --git a/src/pk/ecc/ecc_import_pkcs8.c b/src/pk/ecc/ecc_import_pkcs8.c index 7093fc410..14fe4e8ed 100644 --- a/src/pk/ecc/ecc_import_pkcs8.c +++ b/src/pk/ecc/ecc_import_pkcs8.c @@ -53,7 +53,7 @@ int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen, LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* get EC alg oid */ err = pk_get_oid(PKA_EC, &pka_ec_oid); diff --git a/src/pk/ecc/ecc_make_key.c b/src/pk/ecc/ecc_make_key.c index 1b047417b..c57c65b1f 100644 --- a/src/pk/ecc/ecc_make_key.c +++ b/src/pk/ecc/ecc_make_key.c @@ -39,7 +39,7 @@ int ecc_generate_key(prng_state *prng, int wprng, ecc_key *key) { int err; - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); LTC_ARGCHK(key != NULL); LTC_ARGCHK(key->dp.size > 0); @@ -55,7 +55,7 @@ int ecc_generate_key(prng_state *prng, int wprng, ecc_key *key) } /* make the public key */ - if ((err = ltc_mp.ecc_ptmul(key->k, &key->dp.base, &key->pubkey, key->dp.A, key->dp.prime, 1)) != CRYPT_OK) { + if ((err = mp_ecc_ptmul(key->k, &key->dp.base, &key->pubkey, key->dp.A, key->dp.prime, 1)) != CRYPT_OK) { goto error; } key->type = PK_PRIVATE; diff --git a/src/pk/ecc/ecc_recover_key.c b/src/pk/ecc/ecc_recover_key.c index ae932767f..0813a3dd3 100644 --- a/src/pk/ecc/ecc_recover_key.c +++ b/src/pk/ecc/ecc_recover_key.c @@ -41,7 +41,7 @@ int ecc_recover_key(const unsigned char *sig, unsigned long siglen, LTC_ARGCHK(key != NULL); /* BEWARE: requires sqrtmod_prime */ - if (ltc_mp.sqrtmod_prime == NULL) { + if (!mp_sqrtmod_prime_support()) { return CRYPT_ERROR; } @@ -221,10 +221,10 @@ int ecc_recover_key(const unsigned char *sig, unsigned long siglen, /* recover mQ from mR */ /* compute v1*mR + v2*mG = mQ using Shamir's trick */ - if ((err = ltc_mp.ecc_mul2add(mR, v1, mG, v2, mQ, ma, m)) != CRYPT_OK) { goto error; } + if ((err = mp_ecc_mul2add(mR, v1, mG, v2, mQ, ma, m)) != CRYPT_OK) { goto error; } /* compute u1*mG + u2*mQ = mG using Shamir's trick */ - if ((err = ltc_mp.ecc_mul2add(mG, u1, mQ, u2, mG, ma, m)) != CRYPT_OK) { goto error; } + if ((err = mp_ecc_mul2add(mG, u1, mQ, u2, mG, ma, m)) != CRYPT_OK) { goto error; } /* v = X_x1 mod n */ if ((err = mp_mod(mG->x, p, v)) != CRYPT_OK) { goto error; } diff --git a/src/pk/ecc/ecc_set_key.c b/src/pk/ecc/ecc_set_key.c index 3cf5488b5..add6bb1d2 100644 --- a/src/pk/ecc/ecc_set_key.c +++ b/src/pk/ecc/ecc_set_key.c @@ -28,7 +28,7 @@ int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key goto error; } /* compute public key */ - if ((err = ltc_mp.ecc_ptmul(key->k, &key->dp.base, &key->pubkey, a, prime, 1)) != CRYPT_OK) { goto error; } + if ((err = mp_ecc_ptmul(key->k, &key->dp.base, &key->pubkey, a, prime, 1)) != CRYPT_OK) { goto error; } } else if (type == PK_PUBLIC) { /* load public key */ diff --git a/src/pk/ecc/ecc_shared_secret.c b/src/pk/ecc/ecc_shared_secret.c index 21ac91346..cb3d199f9 100644 --- a/src/pk/ecc/ecc_shared_secret.c +++ b/src/pk/ecc/ecc_shared_secret.c @@ -45,7 +45,7 @@ int ecc_shared_secret(const ecc_key *private_key, const ecc_key *public_key, prime = private_key->dp.prime; a = private_key->dp.A; - if ((err = ltc_mp.ecc_ptmul(private_key->k, &public_key->pubkey, result, a, prime, 1)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptmul(private_key->k, &public_key->pubkey, result, a, prime, 1)) != CRYPT_OK) { goto done; } x = (unsigned long)mp_unsigned_bin_size(prime); if (*outlen < x) { diff --git a/src/pk/ecc/ecc_verify_hash.c b/src/pk/ecc/ecc_verify_hash.c index 377b4d311..86e9d2a39 100644 --- a/src/pk/ecc/ecc_verify_hash.c +++ b/src/pk/ecc/ecc_verify_hash.c @@ -169,18 +169,18 @@ int ecc_verify_hash_ex(const unsigned char *sig, unsigned long siglen, } /* compute u1*mG + u2*mQ = mG */ - if (ltc_mp.ecc_mul2add == NULL) { - if ((err = ltc_mp.ecc_ptmul(u1, mG, mG, a, m, 0)) != CRYPT_OK) { goto error; } - if ((err = ltc_mp.ecc_ptmul(u2, mQ, mQ, a, m, 0)) != CRYPT_OK) { goto error; } + if (mp_ecc_mul2add_support()) { + if ((err = mp_ecc_ptmul(u1, mG, mG, a, m, 0)) != CRYPT_OK) { goto error; } + if ((err = mp_ecc_ptmul(u2, mQ, mQ, a, m, 0)) != CRYPT_OK) { goto error; } /* add them */ - if ((err = ltc_mp.ecc_ptadd(mQ, mG, mG, ma, m, mp)) != CRYPT_OK) { goto error; } + if ((err = mp_ecc_ptadd(mQ, mG, mG, ma, m, mp)) != CRYPT_OK) { goto error; } /* reduce */ - if ((err = ltc_mp.ecc_map(mG, m, mp)) != CRYPT_OK) { goto error; } + if ((err = mp_ecc_map(mG, m, mp)) != CRYPT_OK) { goto error; } } else { /* use Shamir's trick to compute u1*mG + u2*mQ using half of the doubles */ - if ((err = ltc_mp.ecc_mul2add(mG, u1, mQ, u2, mG, ma, m)) != CRYPT_OK) { goto error; } + if ((err = mp_ecc_mul2add(mG, u1, mQ, u2, mG, ma, m)) != CRYPT_OK) { goto error; } } /* v = X_x1 mod n */ diff --git a/src/pk/ecc/ltc_ecc_import_point.c b/src/pk/ecc/ltc_ecc_import_point.c index 8ef31eaf3..5fe36a1f0 100644 --- a/src/pk/ecc/ltc_ecc_import_point.c +++ b/src/pk/ecc/ltc_ecc_import_point.c @@ -25,7 +25,7 @@ int ltc_ecc_import_point(const unsigned char *in, unsigned long inlen, void *pri /* load y */ if ((err = mp_read_unsigned_bin(y, (unsigned char *)in+1+size, size)) != CRYPT_OK) { goto cleanup; } } - else if ((in[0] == 0x02 || in[0] == 0x03) && (inlen-1) == size && ltc_mp.sqrtmod_prime != NULL) { + else if ((in[0] == 0x02 || in[0] == 0x03) && (inlen-1) == size && mp_sqrtmod_prime_support()) { /* read compressed point - BEWARE: requires sqrtmod_prime */ /* load x */ if ((err = mp_read_unsigned_bin(x, (unsigned char *)in+1, size)) != CRYPT_OK) { goto cleanup; } diff --git a/src/pk/ecc/ltc_ecc_mul2add.c b/src/pk/ecc/ltc_ecc_mul2add.c index a0188e328..3b0fd2a1a 100644 --- a/src/pk/ecc/ltc_ecc_mul2add.c +++ b/src/pk/ecc/ltc_ecc_mul2add.c @@ -104,17 +104,17 @@ int ltc_ecc_mul2add(const ecc_point *A, void *kA, if ((err = mp_mulmod(B->z, mu, modulus, precomp[1<<2]->z)) != CRYPT_OK) { goto ERR_MU; } /* precomp [i,0](A + B) table */ - if ((err = ltc_mp.ecc_ptdbl(precomp[1], precomp[2], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } - if ((err = ltc_mp.ecc_ptadd(precomp[1], precomp[2], precomp[3], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } + if ((err = mp_ecc_ptdbl(precomp[1], precomp[2], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } + if ((err = mp_ecc_ptadd(precomp[1], precomp[2], precomp[3], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } /* precomp [0,i](A + B) table */ - if ((err = ltc_mp.ecc_ptdbl(precomp[1<<2], precomp[2<<2], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } - if ((err = ltc_mp.ecc_ptadd(precomp[1<<2], precomp[2<<2], precomp[3<<2], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } + if ((err = mp_ecc_ptdbl(precomp[1<<2], precomp[2<<2], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } + if ((err = mp_ecc_ptadd(precomp[1<<2], precomp[2<<2], precomp[3<<2], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } /* precomp [i,j](A + B) table (i != 0, j != 0) */ for (x = 1; x < 4; x++) { for (y = 1; y < 4; y++) { - if ((err = ltc_mp.ecc_ptadd(precomp[x], precomp[(y<<2)], precomp[x+(y<<2)], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } + if ((err = mp_ecc_ptadd(precomp[x], precomp[(y<<2)], precomp[x+(y<<2)], ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } } } @@ -148,8 +148,8 @@ int ltc_ecc_mul2add(const ecc_point *A, void *kA, /* double twice, only if this isn't the first */ if (first == 0) { /* double twice */ - if ((err = ltc_mp.ecc_ptdbl(C, C, ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } - if ((err = ltc_mp.ecc_ptdbl(C, C, ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } + if ((err = mp_ecc_ptdbl(C, C, ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } + if ((err = mp_ecc_ptdbl(C, C, ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } } /* if not both zero */ @@ -160,7 +160,7 @@ int ltc_ecc_mul2add(const ecc_point *A, void *kA, if ((err = ltc_ecc_copy_point(precomp[nA + (nB<<2)], C)) != CRYPT_OK) { goto ERR_MU; } } else { /* if not first, add from table */ - if ((err = ltc_mp.ecc_ptadd(C, precomp[nA + (nB<<2)], C, ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } + if ((err = mp_ecc_ptadd(C, precomp[nA + (nB<<2)], C, ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } } } } diff --git a/src/pk/ecc/ltc_ecc_mulmod.c b/src/pk/ecc/ltc_ecc_mulmod.c index cabe266af..7ea4781c4 100644 --- a/src/pk/ecc/ltc_ecc_mulmod.c +++ b/src/pk/ecc/ltc_ecc_mulmod.c @@ -84,13 +84,13 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod /* calc the M tab, which holds kG for k==8..15 */ /* M[0] == 8G */ - if ((err = ltc_mp.ecc_ptdbl(tG, M[0], ma, modulus, mp)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.ecc_ptdbl(M[0], M[0], ma, modulus, mp)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.ecc_ptdbl(M[0], M[0], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(tG, M[0], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(M[0], M[0], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(M[0], M[0], ma, modulus, mp)) != CRYPT_OK) { goto done; } /* now find (8+k)G for k=1..7 */ for (j = 9; j < 16; j++) { - if ((err = ltc_mp.ecc_ptadd(M[j-9], tG, M[j-8], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptadd(M[j-9], tG, M[j-8], ma, modulus, mp)) != CRYPT_OK) { goto done; } } /* setup sliding window */ @@ -109,12 +109,12 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod break; } buf = mp_get_digit(k, digidx); - bitcnt = (int) ltc_mp.bits_per_digit; + bitcnt = (int) mp_bits_per_digit; --digidx; } /* grab the next msb from the ltiplicand */ - i = (buf >> (ltc_mp.bits_per_digit - 1)) & 1; + i = (buf >> (mp_bits_per_digit - 1)) & 1; buf <<= 1; /* skip leading zero bits */ @@ -124,7 +124,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod /* if the bit is zero and mode == 1 then we double */ if (mode == 1 && i == 0) { - if ((err = ltc_mp.ecc_ptdbl(R, R, ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(R, R, ma, modulus, mp)) != CRYPT_OK) { goto done; } continue; } @@ -143,11 +143,11 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod /* ok window is filled so double as required and add */ /* double first */ for (j = 0; j < WINSIZE; j++) { - if ((err = ltc_mp.ecc_ptdbl(R, R, ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(R, R, ma, modulus, mp)) != CRYPT_OK) { goto done; } } /* then add, bitbuf will be 8..15 [8..2^WINSIZE] guaranteed */ - if ((err = ltc_mp.ecc_ptadd(R, M[bitbuf-8], R, ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptadd(R, M[bitbuf-8], R, ma, modulus, mp)) != CRYPT_OK) { goto done; } } /* empty window and reset */ bitcpy = bitbuf = 0; @@ -161,7 +161,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod for (j = 0; j < bitcpy; j++) { /* only double if we have had at least one add first */ if (first == 0) { - if ((err = ltc_mp.ecc_ptdbl(R, R, ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(R, R, ma, modulus, mp)) != CRYPT_OK) { goto done; } } bitbuf <<= 1; @@ -172,7 +172,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod first = 0; } else { /* then add */ - if ((err = ltc_mp.ecc_ptadd(R, tG, R, ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptadd(R, tG, R, ma, modulus, mp)) != CRYPT_OK) { goto done; } } } } diff --git a/src/pk/ecc/ltc_ecc_mulmod_timing.c b/src/pk/ecc/ltc_ecc_mulmod_timing.c index 96f50f9eb..35e338598 100644 --- a/src/pk/ecc/ltc_ecc_mulmod_timing.c +++ b/src/pk/ecc/ltc_ecc_mulmod_timing.c @@ -82,7 +82,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod /* M[0] == G */ if ((err = ltc_ecc_copy_point(tG, M[0])) != CRYPT_OK) { goto done; } /* M[1] == 2G */ - if ((err = ltc_mp.ecc_ptdbl(tG, M[1], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(tG, M[1], ma, modulus, mp)) != CRYPT_OK) { goto done; } /* setup sliding window */ mode = 0; @@ -108,21 +108,21 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod if (mode == 0 && i == 0) { /* dummy operations */ - if ((err = ltc_mp.ecc_ptadd(M[0], M[1], M[2], ma, modulus, mp)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.ecc_ptdbl(M[1], M[2], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptadd(M[0], M[1], M[2], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(M[1], M[2], ma, modulus, mp)) != CRYPT_OK) { goto done; } continue; } if (mode == 0 && i == 1) { mode = 1; /* dummy operations */ - if ((err = ltc_mp.ecc_ptadd(M[0], M[1], M[2], ma, modulus, mp)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.ecc_ptdbl(M[1], M[2], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptadd(M[0], M[1], M[2], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(M[1], M[2], ma, modulus, mp)) != CRYPT_OK) { goto done; } continue; } - if ((err = ltc_mp.ecc_ptadd(M[0], M[1], M[i^1], ma, modulus, mp)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.ecc_ptdbl(M[i], M[i], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptadd(M[0], M[1], M[i^1], ma, modulus, mp)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptdbl(M[i], M[i], ma, modulus, mp)) != CRYPT_OK) { goto done; } } /* copy result out */ diff --git a/src/pk/ecc/ltc_ecc_points.c b/src/pk/ecc/ltc_ecc_points.c index 5700c0ed1..fba70e0e3 100644 --- a/src/pk/ecc/ltc_ecc_points.c +++ b/src/pk/ecc/ltc_ecc_points.c @@ -43,18 +43,18 @@ void ltc_ecc_del_point(ecc_point *p) int ltc_ecc_set_point_xyz(ltc_mp_digit x, ltc_mp_digit y, ltc_mp_digit z, ecc_point *p) { int err; - if ((err = ltc_mp.set_int(p->x, x)) != CRYPT_OK) return err; - if ((err = ltc_mp.set_int(p->y, y)) != CRYPT_OK) return err; - if ((err = ltc_mp.set_int(p->z, z)) != CRYPT_OK) return err; + if ((err = mp_set_int(p->x, x)) != CRYPT_OK) return err; + if ((err = mp_set_int(p->y, y)) != CRYPT_OK) return err; + if ((err = mp_set_int(p->z, z)) != CRYPT_OK) return err; return CRYPT_OK; } int ltc_ecc_copy_point(const ecc_point *src, ecc_point *dst) { int err; - if ((err = ltc_mp.copy(src->x, dst->x)) != CRYPT_OK) return err; - if ((err = ltc_mp.copy(src->y, dst->y)) != CRYPT_OK) return err; - if ((err = ltc_mp.copy(src->z, dst->z)) != CRYPT_OK) return err; + if ((err = mp_copy(src->x, dst->x)) != CRYPT_OK) return err; + if ((err = mp_copy(src->y, dst->y)) != CRYPT_OK) return err; + if ((err = mp_copy(src->z, dst->z)) != CRYPT_OK) return err; return CRYPT_OK; } diff --git a/src/pk/ecc/ltc_ecc_verify_key.c b/src/pk/ecc/ltc_ecc_verify_key.c index 26c8383f7..927c5b7c0 100644 --- a/src/pk/ecc/ltc_ecc_verify_key.c +++ b/src/pk/ecc/ltc_ecc_verify_key.c @@ -22,11 +22,11 @@ int ltc_ecc_verify_key(const ecc_key *key) void *a = key->dp.A; /* Test 1: Are the x and y points of the public key in the field? */ - if (ltc_mp.compare_d(key->pubkey.z, 1) == LTC_MP_EQ) { - if ((ltc_mp.compare(key->pubkey.x, prime) != LTC_MP_LT) || - (ltc_mp.compare(key->pubkey.y, prime) != LTC_MP_LT) || - (ltc_mp.compare_d(key->pubkey.x, 0) == LTC_MP_LT) || - (ltc_mp.compare_d(key->pubkey.y, 0) == LTC_MP_LT) || + if (mp_cmp_d(key->pubkey.z, 1) == LTC_MP_EQ) { + if ((mp_cmp(key->pubkey.x, prime) != LTC_MP_LT) || + (mp_cmp(key->pubkey.y, prime) != LTC_MP_LT) || + (mp_cmp_d(key->pubkey.x, 0) == LTC_MP_LT) || + (mp_cmp_d(key->pubkey.y, 0) == LTC_MP_LT) || (mp_iszero(key->pubkey.x) && mp_iszero(key->pubkey.y)) ) { diff --git a/src/pk/rsa/rsa_decrypt_key.c b/src/pk/rsa/rsa_decrypt_key.c index 34a11f918..7143f58ea 100644 --- a/src/pk/rsa/rsa_decrypt_key.c +++ b/src/pk/rsa/rsa_decrypt_key.c @@ -72,7 +72,7 @@ int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen /* rsa decode the packet */ x = inlen; - if ((err = ltc_mp.rsa_me(in, inlen, tmp, &x, PK_PRIVATE, key)) != CRYPT_OK) { + if ((err = mp_rsa_me(in, inlen, tmp, &x, PK_PRIVATE, key)) != CRYPT_OK) { XFREE(tmp); return err; } diff --git a/src/pk/rsa/rsa_encrypt_key.c b/src/pk/rsa/rsa_encrypt_key.c index 66942608a..03327d213 100644 --- a/src/pk/rsa/rsa_encrypt_key.c +++ b/src/pk/rsa/rsa_encrypt_key.c @@ -86,7 +86,7 @@ int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen, } /* rsa exptmod the OAEP or PKCS #1 v1.5 pad */ - return ltc_mp.rsa_me(out, x, out, outlen, PK_PUBLIC, key); + return mp_rsa_me(out, x, out, outlen, PK_PUBLIC, key); } #endif /* LTC_MRSA */ diff --git a/src/pk/rsa/rsa_import.c b/src/pk/rsa/rsa_import.c index 5efb125e2..4d1b23be9 100644 --- a/src/pk/rsa/rsa_import.c +++ b/src/pk/rsa/rsa_import.c @@ -25,7 +25,7 @@ int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key) LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* init key */ if ((err = rsa_init(key)) != CRYPT_OK) { diff --git a/src/pk/rsa/rsa_import_pkcs8.c b/src/pk/rsa/rsa_import_pkcs8.c index 5d0bb6d2a..a71a1b209 100644 --- a/src/pk/rsa/rsa_import_pkcs8.c +++ b/src/pk/rsa/rsa_import_pkcs8.c @@ -58,7 +58,7 @@ int rsa_import_pkcs8(const unsigned char *in, unsigned long inlen, LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* get RSA alg oid */ err = pk_get_oid(PKA_RSA, &rsaoid); diff --git a/src/pk/rsa/rsa_import_x509.c b/src/pk/rsa/rsa_import_x509.c index 265e1a5a0..6ee633f1f 100644 --- a/src/pk/rsa/rsa_import_x509.c +++ b/src/pk/rsa/rsa_import_x509.c @@ -31,7 +31,7 @@ int rsa_import_x509(const unsigned char *in, unsigned long inlen, rsa_key *key) LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); /* init key */ if ((err = rsa_init(key)) != CRYPT_OK) { diff --git a/src/pk/rsa/rsa_make_key.c b/src/pk/rsa/rsa_make_key.c index 5211b31e9..315c71fcc 100644 --- a/src/pk/rsa/rsa_make_key.c +++ b/src/pk/rsa/rsa_make_key.c @@ -23,7 +23,7 @@ int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key) void *p, *q, *tmp1, *tmp2, *tmp3; int err; - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); LTC_ARGCHK(key != NULL); LTC_ARGCHK(size > 0); diff --git a/src/pk/rsa/rsa_set.c b/src/pk/rsa/rsa_set.c index d4dc6ed0f..fcd85bde5 100644 --- a/src/pk/rsa/rsa_set.c +++ b/src/pk/rsa/rsa_set.c @@ -27,7 +27,7 @@ int rsa_set_key(const unsigned char *N, unsigned long Nlen, LTC_ARGCHK(key != NULL); LTC_ARGCHK(N != NULL); LTC_ARGCHK(e != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); if ((err = rsa_init(key)) != CRYPT_OK) return err; @@ -68,7 +68,7 @@ int rsa_set_factors(const unsigned char *p, unsigned long plen, LTC_ARGCHK(key != NULL); LTC_ARGCHK(p != NULL); LTC_ARGCHK(q != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); if (key->type != PK_PRIVATE) return CRYPT_PK_TYPE_MISMATCH; @@ -106,7 +106,7 @@ int rsa_set_crt_params(const unsigned char *dP, unsigned long dPlen, LTC_ARGCHK(dP != NULL); LTC_ARGCHK(dQ != NULL); LTC_ARGCHK(qP != NULL); - LTC_ARGCHK(ltc_mp.name != NULL); + LTC_ARGCHK(mp_name() != NULL); if (key->type != PK_PRIVATE) return CRYPT_PK_TYPE_MISMATCH; diff --git a/src/pk/rsa/rsa_sign_hash.c b/src/pk/rsa/rsa_sign_hash.c index aec30e2ab..d5e0d9ccc 100644 --- a/src/pk/rsa/rsa_sign_hash.c +++ b/src/pk/rsa/rsa_sign_hash.c @@ -130,7 +130,7 @@ int rsa_sign_hash_ex(const unsigned char *in, unsigned long inlen, } /* RSA encode it */ - return ltc_mp.rsa_me(out, x, out, outlen, PK_PRIVATE, key); + return mp_rsa_me(out, x, out, outlen, PK_PRIVATE, key); } #endif /* LTC_MRSA */ diff --git a/src/pk/rsa/rsa_verify_hash.c b/src/pk/rsa/rsa_verify_hash.c index ca4cdf9c4..6491bc156 100644 --- a/src/pk/rsa/rsa_verify_hash.c +++ b/src/pk/rsa/rsa_verify_hash.c @@ -72,7 +72,7 @@ int rsa_verify_hash_ex(const unsigned char *sig, unsigned long sigle /* RSA decode it */ x = siglen; - if ((err = ltc_mp.rsa_me(sig, siglen, tmpbuf, &x, PK_PUBLIC, key)) != CRYPT_OK) { + if ((err = mp_rsa_me(sig, siglen, tmpbuf, &x, PK_PUBLIC, key)) != CRYPT_OK) { XFREE(tmpbuf); return err; } diff --git a/tests/der_test.c b/tests/der_test.c index 4c6e87e59..a0f406897 100644 --- a/tests/der_test.c +++ b/tests/der_test.c @@ -1612,7 +1612,7 @@ int der_test(void) ltc_asn1_list *list; #endif - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; _der_recursion_limit(); diff --git a/tests/dh_test.c b/tests/dh_test.c index ff6919baa..3f5ddd96b 100644 --- a/tests/dh_test.c +++ b/tests/dh_test.c @@ -13,7 +13,7 @@ static int _prime_test(void) for (x = 0; ltc_dh_sets[x].size != 0; x++) { /* tfm has a problem with larger sizes */ - if ((strcmp(ltc_mp.name, "TomsFastMath") == 0) && (ltc_dh_sets[x].size > 256)) break; + if ((strcmp(mp_name(), "TomsFastMath") == 0) && (ltc_dh_sets[x].size > 256)) break; if ((err = mp_read_radix(g, ltc_dh_sets[x].base, 16)) != CRYPT_OK) { goto error; } if ((err = mp_read_radix(p, ltc_dh_sets[x].prime, 16)) != CRYPT_OK) { goto error; } @@ -316,7 +316,7 @@ static int _basic_test(void) dh_key usera, userb; /* tfm has a problem with larger sizes */ - KEYSIZE = (strcmp(ltc_mp.name, "TomsFastMath") == 0) ? 2048 : 4096; + KEYSIZE = (strcmp(mp_name(), "TomsFastMath") == 0) ? 2048 : 4096; /* make up two keys */ DO(dh_set_pg_groupsize(KEYSIZE/8, &usera)); @@ -367,7 +367,7 @@ static int _basic_test(void) for (x = 0; ltc_dh_sets[x].size != 0; x++) { /* tfm has a problem with larger sizes */ - if ((strcmp(ltc_mp.name, "TomsFastMath") == 0) && (ltc_dh_sets[x].size > 256)) break; + if ((strcmp(mp_name(), "TomsFastMath") == 0) && (ltc_dh_sets[x].size > 256)) break; DO(dh_set_pg_groupsize(ltc_dh_sets[x].size, &usera)); DO(dh_generate_key(&yarrow_prng, find_prng ("yarrow"), &usera)); @@ -387,7 +387,7 @@ int dh_test(void) { int fails = 0; - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; if (_prime_test() != CRYPT_OK) fails++; if (_basic_test() != CRYPT_OK) fails++; diff --git a/tests/dsa_test.c b/tests/dsa_test.c index 034a67d1b..bf5bae631 100644 --- a/tests/dsa_test.c +++ b/tests/dsa_test.c @@ -305,7 +305,7 @@ int dsa_test(void) int stat1, stat2; dsa_key key, key2; - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; DO(_dsa_compat_test()); DO(_dsa_wycheproof_test()); diff --git a/tests/ecc_test.c b/tests/ecc_test.c index 5cee46f29..c96926b11 100644 --- a/tests/ecc_test.c +++ b/tests/ecc_test.c @@ -160,10 +160,10 @@ static int _ecc_test_shamir(void) DO(mp_read_unsigned_bin(rB, buf, sizes[x])); /* compute rA * G = A */ - DO(ltc_mp.ecc_ptmul(rA, G, A, a, modulus, 1)); + DO(mp_ecc_ptmul(rA, G, A, a, modulus, 1)); /* compute rB * G = B */ - DO(ltc_mp.ecc_ptmul(rB, G, B, a, modulus, 1)); + DO(mp_ecc_ptmul(rB, G, B, a, modulus, 1)); /* pick a random kA, kB */ LTC_ARGCHK(yarrow_read(buf, sizes[x], &yarrow_prng) == sizes[x]); @@ -172,13 +172,13 @@ static int _ecc_test_shamir(void) DO(mp_read_unsigned_bin(kB, buf, sizes[x])); /* now, compute kA*A + kB*B = C1 using the older method */ - DO(ltc_mp.ecc_ptmul(kA, A, C1, a, modulus, 0)); - DO(ltc_mp.ecc_ptmul(kB, B, C2, a, modulus, 0)); - DO(ltc_mp.ecc_ptadd(C1, C2, C1, a, modulus, mp)); - DO(ltc_mp.ecc_map(C1, modulus, mp)); + DO(mp_ecc_ptmul(kA, A, C1, a, modulus, 0)); + DO(mp_ecc_ptmul(kB, B, C2, a, modulus, 0)); + DO(mp_ecc_ptadd(C1, C2, C1, a, modulus, mp)); + DO(mp_ecc_map(C1, modulus, mp)); /* now compute using mul2add */ - DO(ltc_mp.ecc_mul2add(A, kA, B, kB, C2, ma, modulus)); + DO(mp_ecc_mul2add(A, kA, B, kB, C2, ma, modulus)); /* is they the sames? */ if ((mp_cmp(C1->x, C2->x) != LTC_MP_EQ) || (mp_cmp(C1->y, C2->y) != LTC_MP_EQ) || (mp_cmp(C1->z, C2->z) != LTC_MP_EQ)) { @@ -224,7 +224,7 @@ static int _ecc_issue108(void) if ((err = mp_read_radix(Q->y, (char *)"6C9CB8E68AABFEC989CAC5E2326E0448B7E69C3E56039BA21A44FDAC", 16)) != CRYPT_OK) { goto done; } mp_set(Q->z, 1); /* calculate nQ */ - if ((err = ltc_mp.ecc_ptmul(order, Q, Result, a, modulus, 1)) != CRYPT_OK) { goto done; } + if ((err = mp_ecc_ptmul(order, Q, Result, a, modulus, 1)) != CRYPT_OK) { goto done; } done: ltc_ecc_del_point(Result); @@ -332,7 +332,7 @@ static int _ecc_test_mp(void) /* then we should have G == (order + 1)G */ DO(mp_add_d(order, 1, order)); - DO(ltc_mp.ecc_ptmul(order, G, GG, a, modulus, 1)); + DO(mp_ecc_ptmul(order, G, GG, a, modulus, 1)); if (mp_cmp(G->x, GG->x) != LTC_MP_EQ || mp_cmp(G->y, GG->y) != LTC_MP_EQ) { err = CRYPT_FAIL_TESTVECTOR; } @@ -547,7 +547,7 @@ static int _ecc_new_api(void) DO(ecc_set_curve(dp, &privkey)); DO(ecc_set_key(buf, len, PK_PRIVATE, &privkey)); - if (strcmp(ltc_mp.name, "TomsFastMath") != 0) { + if (strcmp(mp_name(), "TomsFastMath") != 0) { /* XXX-FIXME: TFM does not support sqrtmod_prime */ /* export compressed public key */ len = sizeof(buf); @@ -585,7 +585,7 @@ static int _ecc_new_api(void) #endif #ifdef LTC_ECC_SHAMIR - if (strcmp(ltc_mp.name, "TomsFastMath") != 0) { + if (strcmp(mp_name(), "TomsFastMath") != 0) { /* XXX-FIXME: TFM does not support sqrtmod_prime */ int found = 0; ecc_key reckey; @@ -1301,7 +1301,7 @@ static int _ecc_import_export(void) { 0xae, 0x97, 0xaf, 0x64, 0x64, 0xf9, 0x69, 0xd8 }; - if (ltc_mp.sqrtmod_prime == NULL) return CRYPT_NOP; /* we need compressed points which requires sqrtmod_prime */ + if (!mp_sqrtmod_prime_support()) return CRYPT_NOP; /* we need compressed points which requires sqrtmod_prime */ DO(ecc_import_openssl(short_pub, sizeof(short_pub), &pub)); DO(ecc_import_openssl(short_pri, sizeof(short_pri), &pri)); @@ -1515,7 +1515,7 @@ static int _ecc_test_recovery(void) }; /* XXX-FIXME: TFM does not support sqrtmod_prime */ - if (strcmp(ltc_mp.name, "TomsFastMath") == 0) return CRYPT_NOP; + if (strcmp(mp_name(), "TomsFastMath") == 0) return CRYPT_NOP; #ifdef LTC_ECC_SECP256K1 DO(ecc_find_curve("SECP256K1", &dp)); @@ -1591,7 +1591,7 @@ static int _ecc_test_recovery(void) int ecc_test(void) { - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; DO(_ecc_old_api()); /* up to 1.18 */ DO(_ecc_new_api()); diff --git a/tests/ed25519_test.c b/tests/ed25519_test.c index 4e01a5d54..cffcf560a 100644 --- a/tests/ed25519_test.c +++ b/tests/ed25519_test.c @@ -231,7 +231,7 @@ int ed25519_test(void) return ret; } - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; if ((ret = _rfc_8410_10_test()) != CRYPT_OK) { return ret; diff --git a/tests/mpi_test.c b/tests/mpi_test.c index cf4e159b9..b5284d414 100644 --- a/tests/mpi_test.c +++ b/tests/mpi_test.c @@ -127,7 +127,7 @@ static int _radix_to_bin_test(void) int mpi_test(void) { - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; return _radix_to_bin_test(); } #else diff --git a/tests/pkcs_1_eme_test.c b/tests/pkcs_1_eme_test.c index 77e0ded0e..82cd10030 100644 --- a/tests/pkcs_1_eme_test.c +++ b/tests/pkcs_1_eme_test.c @@ -16,7 +16,7 @@ int pkcs_1_eme_test(void) unsigned int i; unsigned int j; - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; DO(prng_is_valid(prng_idx)); DO(hash_is_valid(hash_idx)); diff --git a/tests/pkcs_1_emsa_test.c b/tests/pkcs_1_emsa_test.c index 5818b55bf..00cc3d813 100644 --- a/tests/pkcs_1_emsa_test.c +++ b/tests/pkcs_1_emsa_test.c @@ -14,7 +14,7 @@ int pkcs_1_emsa_test(void) unsigned int i; unsigned int j; - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; DO(hash_is_valid(hash_idx)); diff --git a/tests/pkcs_1_oaep_test.c b/tests/pkcs_1_oaep_test.c index 53ca68c7c..55927a238 100644 --- a/tests/pkcs_1_oaep_test.c +++ b/tests/pkcs_1_oaep_test.c @@ -16,7 +16,7 @@ int pkcs_1_oaep_test(void) unsigned int i; unsigned int j; - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; DO(prng_is_valid(prng_idx)); DO(hash_is_valid(hash_idx)); diff --git a/tests/pkcs_1_pss_test.c b/tests/pkcs_1_pss_test.c index e9ab28101..187d98265 100644 --- a/tests/pkcs_1_pss_test.c +++ b/tests/pkcs_1_pss_test.c @@ -16,7 +16,7 @@ int pkcs_1_pss_test(void) unsigned int i; unsigned int j; - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; DO(prng_is_valid(prng_idx)); DO(hash_is_valid(hash_idx)); diff --git a/tests/rsa_test.c b/tests/rsa_test.c index 94bc44f32..c827411b8 100644 --- a/tests/rsa_test.c +++ b/tests/rsa_test.c @@ -333,7 +333,7 @@ static int _rsa_import_x509(const void *in, unsigned long inlen, void *key) /* here we use the filesize as indicator for the rsa size * that would fail to import for tfm because it's fixed-size */ - if ((strcmp(ltc_mp.name, "TomsFastMath") == 0) && (inlen > 2048)) { + if ((strcmp(mp_name(), "TomsFastMath") == 0) && (inlen > 2048)) { #if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1 fprintf(stderr, "Skipping testcase because of TomsFastMath\n"); #endif @@ -362,7 +362,7 @@ int rsa_test(void) unsigned char* p2; unsigned char* p3; - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; if (rsa_compat_test() != 0) { return 1; @@ -647,7 +647,7 @@ print_hex("q", tmp, len); DOX(stat == 1?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, "should succeed"); len3 = sizeof(tmp); /* (3) */ - DO(ltc_mp.rsa_me(p2, len2, p3, &len3, PK_PUBLIC, &key)); + DO(mp_rsa_me(p2, len2, p3, &len3, PK_PUBLIC, &key)); /* (4) */ #if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1 print_hex("Original signature", p3, len3); @@ -673,7 +673,7 @@ print_hex("q", tmp, len); len2 = sizeof(out); /* (5) */ - DO(ltc_mp.rsa_me(p3, len3, p2, &len2, PK_PRIVATE, &key)); + DO(mp_rsa_me(p3, len3, p2, &len2, PK_PRIVATE, &key)); len3 = sizeof(tmp); /* (6) */ diff --git a/tests/ssh_test.c b/tests/ssh_test.c index def34922f..7af825623 100644 --- a/tests/ssh_test.c +++ b/tests/ssh_test.c @@ -337,7 +337,7 @@ static int _ssh_decoding_test(void) */ int ssh_test(void) { - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; DO(_ssh_encoding_test()); DO(_ssh_decoding_test()); diff --git a/tests/test.c b/tests/test.c index b917d9b37..2029a6c44 100644 --- a/tests/test.c +++ b/tests/test.c @@ -340,8 +340,8 @@ int main(int argc, char **argv) crypt_mp_init(mpi_provider); - if (ltc_mp.name != NULL) { - printf("MP_PROVIDER = %s\n", ltc_mp.name); + if (mp_name() != NULL) { + printf("MP_PROVIDER = %s\n", mp_name()); printf("MP_DIGIT_BIT = %d\n", MP_DIGIT_BIT); printf("sizeof(ltc_mp_digit) = %d\n", (int)sizeof(ltc_mp_digit)); } else { diff --git a/tests/x25519_test.c b/tests/x25519_test.c index b66682a1e..d21732b07 100644 --- a/tests/x25519_test.c +++ b/tests/x25519_test.c @@ -219,7 +219,7 @@ int x25519_test(void) { int ret; - if (ltc_mp.name == NULL) return CRYPT_NOP; + if (mp_name() == NULL) return CRYPT_NOP; if ((ret = _rfc_7748_5_2_test()) != CRYPT_OK) { return ret;