From 67b9cd8a9576268899479a72d82b2dcafd2224ed Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 2 Sep 2014 02:17:43 +0200 Subject: [PATCH 1/4] trim trailing spaces --- src/misc/crypt/crypt.c | 1 - src/pk/ecc/ecc_test.c | 2 +- src/pk/ecc/ltc_ecc_mulmod.c | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/misc/crypt/crypt.c b/src/misc/crypt/crypt.c index a5fbbca..61f4f84 100644 --- a/src/misc/crypt/crypt.c +++ b/src/misc/crypt/crypt.c @@ -393,7 +393,6 @@ const char *crypt_build_settings = " LTC_ECC_SHAMIR " #endif "\n" - "\n\n\n" ; diff --git a/src/pk/ecc/ecc_test.c b/src/pk/ecc/ecc_test.c index 873e70b..e371da9 100644 --- a/src/pk/ecc/ecc_test.c +++ b/src/pk/ecc/ecc_test.c @@ -19,7 +19,7 @@ /** @file ecc_test.c ECC Crypto, Tom St Denis -*/ +*/ #ifdef LTC_MECC diff --git a/src/pk/ecc/ltc_ecc_mulmod.c b/src/pk/ecc/ltc_ecc_mulmod.c index 28eebdc..c3e7cc5 100644 --- a/src/pk/ecc/ltc_ecc_mulmod.c +++ b/src/pk/ecc/ltc_ecc_mulmod.c @@ -62,7 +62,7 @@ int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map) mp_clear(mu); return err; } - + /* alloc ram for window temps */ for (i = 0; i < 8; i++) { M[i] = ltc_ecc_new_point(); @@ -92,7 +92,7 @@ int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map) } mp_clear(mu); mu = NULL; - + /* calc the M tab, which holds kG for k==8..15 */ /* M[0] == 8G */ if ((err = ltc_mp.ecc_ptdbl(tG, M[0], modulus, mp)) != CRYPT_OK) { goto done; } From 1793072c674ad6e7110236188ef87ea1fc73a484 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 10 Sep 2014 16:08:49 +0200 Subject: [PATCH 2/4] fix CC parameter given to make in testprof folder --- makefile.mingw | 2 +- makefile.shared | 2 +- makefile.unix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/makefile.mingw b/makefile.mingw index 2893aa2..28da819 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -210,7 +210,7 @@ library: $(LIBNAME) .PHONY: testprof/$(LIBTEST) testprof/$(LIBTEST): - $(MAKE) -C testprof -f makefile.mingw CFLAGS_OPTS="$(CFLAGS)" LIBTEST_S=$(LIBTEST) CC=$(CC) LD=$(LD) AR=$(AR) ARFLAGS=$(ARFLAGS) RANLIB=$(RANLIB) + $(MAKE) -C testprof -f makefile.mingw CFLAGS_OPTS="$(CFLAGS)" LIBTEST_S=$(LIBTEST) CC="$(CC)" LD=$(LD) AR=$(AR) ARFLAGS="$(ARFLAGS)" RANLIB=$(RANLIB) $(LIBNAME): $(OBJECTS) $(AR) $(ARFLAGS) $@ $(OBJECTS) diff --git a/makefile.shared b/makefile.shared index f54ecb0..96adb41 100644 --- a/makefile.shared +++ b/makefile.shared @@ -263,7 +263,7 @@ library: $(LIBNAME) .PHONY: testprof/$(LIBTEST) testprof/$(LIBTEST): - cd testprof ; CFLAGS="$(CFLAGS)" GROUP=$(GROUP) USER=$(USER) VERSION=$(VERSION) LIBPATH=$(LIBPATH) LIBTEST=$(LIBTEST) LIBTEST_S=$(LIBTEST_S) LT=$(LT) CC=$(CC) make -f makefile.shared + cd testprof ; CFLAGS="$(CFLAGS)" GROUP=$(GROUP) USER=$(USER) VERSION=$(VERSION) LIBPATH=$(LIBPATH) LIBTEST=$(LIBTEST) LIBTEST_S=$(LIBTEST_S) LT=$(LT) CC="$(CC)" make -f makefile.shared .c.o: $(LTCOMPILE) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -c $< diff --git a/makefile.unix b/makefile.unix index 91af9b1..83abbce 100644 --- a/makefile.unix +++ b/makefile.unix @@ -210,7 +210,7 @@ library: $(LIBNAME) .PHONY: testprof/$(LIBTEST) testprof/$(LIBTEST): - cd testprof ; CFLAGS="$(CFLAGS)" LIBTEST_S=$(LIBTEST_S) $(MAKE) + cd testprof ; CFLAGS="$(CFLAGS)" LIBTEST_S=$(LIBTEST_S) CC="$(CC)" LD="$(LD)" AR="$(AR)" RANLIB="$(RANLIB)" $(MAKE) $(LIBNAME): $(OBJECTS) $(AR) $(ARFLAGS) $@ $(OBJECTS) From f597f29ece2bc413ec0872164ff3e594f8ec8749 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 10 Sep 2014 16:15:35 +0200 Subject: [PATCH 3/4] math: change get_digit() return value unsigned long is 32bit wide when compiling with the compiler flag "-mx32" but the digit size of the math libraries is still 64 bit which lead to the buggy ecc code. Therefore define a new type ltc_mp_digit with the correct width and use that as return value of get_digit() Has been tested with all three math providers --- src/headers/tomcrypt_cfg.h | 5 +++++ src/headers/tomcrypt_math.h | 2 +- src/math/gmp_desc.c | 2 +- src/math/ltm_desc.c | 2 +- src/math/tfm_desc.c | 2 +- src/pk/ecc/ltc_ecc_mulmod.c | 2 +- src/pk/ecc/ltc_ecc_mulmod_timing.c | 2 +- 7 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/headers/tomcrypt_cfg.h b/src/headers/tomcrypt_cfg.h index c341694..ab43978 100644 --- a/src/headers/tomcrypt_cfg.h +++ b/src/headers/tomcrypt_cfg.h @@ -122,6 +122,11 @@ typedef ulong32 __attribute__((__may_alias__)) LTC_FAST_TYPE; #endif #endif +#ifdef ENDIAN_64BITWORD +typedef ulong64 ltc_mp_digit; +#else +typedef ulong32 ltc_mp_digit; +#endif #ifdef LTC_NO_FAST #ifdef LTC_FAST diff --git a/src/headers/tomcrypt_math.h b/src/headers/tomcrypt_math.h index f4f397a..c605283 100644 --- a/src/headers/tomcrypt_math.h +++ b/src/headers/tomcrypt_math.h @@ -80,7 +80,7 @@ typedef struct { @param n The number of the digit to fetch @return The bits_per_digit sized n'th digit of a */ - unsigned long (*get_digit)(void *a, int n); + ltc_mp_digit (*get_digit)(void *a, int n); /** Get the number of digits that represent the number @param a The number to count diff --git a/src/math/gmp_desc.c b/src/math/gmp_desc.c index c6082d2..8709880 100644 --- a/src/math/gmp_desc.c +++ b/src/math/gmp_desc.c @@ -74,7 +74,7 @@ static unsigned long get_int(void *a) return mpz_get_ui(a); } -static unsigned long get_digit(void *a, int n) +static ltc_mp_digit get_digit(void *a, int n) { LTC_ARGCHK(a != NULL); return mpz_getlimbn(a, n); diff --git a/src/math/ltm_desc.c b/src/math/ltm_desc.c index 3c00aaf..5ff8ff8 100644 --- a/src/math/ltm_desc.c +++ b/src/math/ltm_desc.c @@ -100,7 +100,7 @@ static unsigned long get_int(void *a) return mp_get_int(a); } -static unsigned long get_digit(void *a, int n) +static ltc_mp_digit get_digit(void *a, int n) { mp_int *A; LTC_ARGCHK(a != NULL); diff --git a/src/math/tfm_desc.c b/src/math/tfm_desc.c index 693b926..df4c63c 100644 --- a/src/math/tfm_desc.c +++ b/src/math/tfm_desc.c @@ -99,7 +99,7 @@ static unsigned long get_int(void *a) return A->used > 0 ? A->dp[0] : 0; } -static unsigned long get_digit(void *a, int n) +static ltc_mp_digit get_digit(void *a, int n) { fp_int *A; LTC_ARGCHK(a != NULL); diff --git a/src/pk/ecc/ltc_ecc_mulmod.c b/src/pk/ecc/ltc_ecc_mulmod.c index c3e7cc5..a0ca6ce 100644 --- a/src/pk/ecc/ltc_ecc_mulmod.c +++ b/src/pk/ecc/ltc_ecc_mulmod.c @@ -41,7 +41,7 @@ int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map) ecc_point *tG, *M[8]; int i, j, err; void *mu, *mp; - unsigned long buf; + ltc_mp_digit buf; int first, bitbuf, bitcpy, bitcnt, mode, digidx; LTC_ARGCHK(k != NULL); diff --git a/src/pk/ecc/ltc_ecc_mulmod_timing.c b/src/pk/ecc/ltc_ecc_mulmod_timing.c index 9e819c8..ce4d9a4 100644 --- a/src/pk/ecc/ltc_ecc_mulmod_timing.c +++ b/src/pk/ecc/ltc_ecc_mulmod_timing.c @@ -39,7 +39,7 @@ int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map) ecc_point *tG, *M[3]; int i, j, err; void *mu, *mp; - unsigned long buf; + ltc_mp_digit buf; int bitcnt, mode, digidx; LTC_ARGCHK(k != NULL); From afaef3993cababa8fd0ad681353d970670e2858e Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 10 Sep 2014 16:16:46 +0200 Subject: [PATCH 4/4] fix compiler warning when compiling with GMP_DESC --- src/math/gmp_desc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/math/gmp_desc.c b/src/math/gmp_desc.c index 8709880..16c1d90 100644 --- a/src/math/gmp_desc.c +++ b/src/math/gmp_desc.c @@ -430,6 +430,7 @@ static int montgomery_reduce(void *a, void *b, void *c) /* clean up */ static void montgomery_deinit(void *a) { + LTC_UNUSED_PARAM(a); } static int exptmod(void *a, void *b, void *c, void *d)