From 048cbc55b0e67a82023378ed736e5b65a6507a63 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 12 Jun 2017 18:47:28 +0200 Subject: [PATCH 1/8] disable yet another warning --- makefile_include.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/makefile_include.mk b/makefile_include.mk index c7bb707..ca1cf29 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -92,6 +92,9 @@ endif # COMPILE_DEBUG ifneq ($(findstring clang,$(CC)),) CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header endif +ifeq ($(PLATFORM), Darwin) +CFLAGS += -Wno-nullability-completeness +endif GIT_VERSION := $(shell [ -e .git ] && { printf git- ; git describe --tags --always --dirty ; } || echo $(VERSION)) From 3995f971d73f596064ccc1a33d0a85f54eba6667 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 13 Jun 2017 12:25:25 +0200 Subject: [PATCH 2/8] make sure to use makefile.shared on Mac --- makefile | 12 ++++++++---- makefile.shared | 2 ++ makefile_include.mk | 2 -- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/makefile b/makefile index 4620b86..92e1384 100644 --- a/makefile +++ b/makefile @@ -13,14 +13,18 @@ silent=@ silent_stdout= > /dev/null endif +PLATFORM := $(shell uname | sed -e 's/_.*//') + +ifneq ($(MAKECMDGOALS),clean) +ifeq ($(PLATFORM), Darwin) +$(error Can't build static library on Mac, please use makefile.shared) +endif +endif + # ranlib tools ifndef RANLIB -ifeq ($(PLATFORM), Darwin) -RANLIB:=$(PREFIX)ranlib -c -else RANLIB:=$(PREFIX)ranlib endif -endif INSTALL_CMD = install #Output filenames for various targets. diff --git a/makefile.shared b/makefile.shared index e6be085..0e9e6bc 100644 --- a/makefile.shared +++ b/makefile.shared @@ -7,6 +7,8 @@ # # (GNU make only) +PLATFORM := $(shell uname | sed -e 's/_.*//') + ifndef LT ifeq ($(PLATFORM), Darwin) LT:=glibtool diff --git a/makefile_include.mk b/makefile_include.mk index ca1cf29..78b70bc 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -7,8 +7,6 @@ VERSION=1.17 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html VERSION_LT=0:117 -PLATFORM := $(shell uname | sed -e 's/_.*//') - # Compiler and Linker Names ifndef PREFIX PREFIX:= From a0e5c2e4ff2e790800550f9e1d148bee5028bd7f Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 13 Jun 2017 14:57:07 +0200 Subject: [PATCH 3/8] add some makefile docs --- makefile.shared | 7 +++++++ makefile_include.mk | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/makefile.shared b/makefile.shared index 0e9e6bc..a36e86e 100644 --- a/makefile.shared +++ b/makefile.shared @@ -7,6 +7,13 @@ # # (GNU make only) +### USAGE: +# +# CFLAGS="-DUSE_LTM -DLTM_DESC -I/path/to/libtommath" make -f makefile.shared all EXTRALIBS=/path/to/libtommath/libtommath.a +# ./test +# make -f makefile.shared DESTDIR=/opt/libtom install +# + PLATFORM := $(shell uname | sed -e 's/_.*//') ifndef LT diff --git a/makefile_include.mk b/makefile_include.mk index 78b70bc..08086f5 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -43,6 +43,11 @@ endif # # Compilation flags. Note the += does not write over the user's CFLAGS! # +# Also note that we're extending the environments' CFLAGS. +# If you think that our CFLAGS are not nice you can easily override them +# by giving them as a parameter to make: +# make CFLAGS="-I./src/headers/ -DLTC_SOURCE ..." ... +# CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow -DLTC_SOURCE ifdef OLD_GCC @@ -338,6 +343,8 @@ $(TOBJECTS): $(HEADERS) $(THEADERS) bins: $(USEFUL_DEMOS) +all: all_test + all_test: test $(UNBROKEN_DEMOS) #build the doxy files (requires Doxygen, tetex and patience) From 0cf7c4904519f66042dfbcdb92f24b762dd8701c Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 12 Jun 2017 12:02:10 +0200 Subject: [PATCH 4/8] sync ltc_math_descriptor from doc --- src/headers/tomcrypt_math.h | 83 +++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/src/headers/tomcrypt_math.h b/src/headers/tomcrypt_math.h index c605283..833deac 100644 --- a/src/headers/tomcrypt_math.h +++ b/src/headers/tomcrypt_math.h @@ -65,13 +65,14 @@ typedef struct { /** set small constant @param a Number to write to @param n Source upto bits_per_digit (actually meant for very small constants) - @return CRYPT_OK on succcess + @return CRYPT_OK on success */ int (*set_int)(void *a, unsigned long n); /** get small constant - @param a Number to read, only fetches upto bits_per_digit from the number - @return The lower bits_per_digit of the integer (unsigned) + @param a Small number to read, + only fetches up to bits_per_digit from the number + @return The lower bits_per_digit of the integer (unsigned) */ unsigned long (*get_int)(void *a); @@ -91,14 +92,18 @@ typedef struct { /** compare two integers @param a The left side integer @param b The right side integer - @return LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison) + @return LTC_MP_LT if a < b, + LTC_MP_GT if a > b and + LTC_MP_EQ otherwise. (signed comparison) */ int (*compare)(void *a, void *b); /** compare against int @param a The left side integer @param b The right side integer (upto bits_per_digit) - @return LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison) + @return LTC_MP_LT if a < b, + LTC_MP_GT if a > b and + LTC_MP_EQ otherwise. (signed comparison) */ int (*compare_d)(void *a, unsigned long n); @@ -140,8 +145,8 @@ typedef struct { int (*write_radix)(void *a, char *str, int radix); /** get size as unsigned char string - @param a The integer to get the size (when stored in array of octets) - @return The length of the integer + @param a The integer to get the size (when stored in array of octets) + @return The length of the integer in octets */ unsigned long (*unsigned_size)(void *a); @@ -158,7 +163,9 @@ typedef struct { @param len The number of octets @return CRYPT_OK on success */ - int (*unsigned_read)(void *dst, unsigned char *src, unsigned long len); + int (*unsigned_read)( void *dst, + unsigned char *src, + unsigned long len); /* ---- basic math ---- */ @@ -170,10 +177,10 @@ typedef struct { */ int (*add)(void *a, void *b, void *c); - /** add two integers @param a The first source integer - @param b The second source integer (single digit of upto bits_per_digit in length) + @param b The second source integer + (single digit of upto bits_per_digit in length) @param c The destination of "a + b" @return CRYPT_OK on success */ @@ -189,7 +196,8 @@ typedef struct { /** subtract two integers @param a The first source integer - @param b The second source integer (single digit of upto bits_per_digit in length) + @param b The second source integer + (single digit of upto bits_per_digit in length) @param c The destination of "a - b" @return CRYPT_OK on success */ @@ -197,7 +205,8 @@ typedef struct { /** multiply two integers @param a The first source integer - @param b The second source integer (single digit of upto bits_per_digit in length) + @param b The second source integer + (single digit of upto bits_per_digit in length) @param c The destination of "a * b" @return CRYPT_OK on success */ @@ -205,7 +214,8 @@ typedef struct { /** multiply two integers @param a The first source integer - @param b The second source integer (single digit of upto bits_per_digit in length) + @param b The second source integer + (single digit of upto bits_per_digit in length) @param c The destination of "a * b" @return CRYPT_OK on success */ @@ -285,7 +295,7 @@ typedef struct { /* ---- reduction ---- */ - /** setup montgomery + /** setup Montgomery @param a The modulus @param b The destination for the reduction digit @return CRYPT_OK on success @@ -339,10 +349,15 @@ typedef struct { @param G The point to multiply @param R The destination for kG @param modulus The modulus for the field - @param map Boolean indicated whether to map back to affine or not (can be ignored if you work in affine only) + @param map Boolean indicated whether to map back to affine or not + (can be ignored if you work in affine only) @return CRYPT_OK on success */ - int (*ecc_ptmul)(void *k, ecc_point *G, ecc_point *R, void *modulus, int map); + int (*ecc_ptmul)( void *k, + ecc_point *G, + ecc_point *R, + void *modulus, + int map); /** ECC GF(p) point addition @param P The first point @@ -352,7 +367,11 @@ typedef struct { @param mp The "b" value from montgomery_setup() @return CRYPT_OK on success */ - int (*ecc_ptadd)(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp); + int (*ecc_ptadd)(ecc_point *P, + ecc_point *Q, + ecc_point *R, + void *modulus, + void *mp); /** ECC GF(p) point double @param P The first point @@ -361,15 +380,20 @@ typedef struct { @param mp The "b" value from montgomery_setup() @return CRYPT_OK on success */ - int (*ecc_ptdbl)(ecc_point *P, ecc_point *R, void *modulus, void *mp); + int (*ecc_ptdbl)(ecc_point *P, + ecc_point *R, + void *modulus, + void *mp); - /** ECC mapping from projective to affine, currently uses (x,y,z) => (x/z^2, y/z^3, 1) + /** ECC mapping from projective to affine, + currently uses (x,y,z) => (x/z^2, y/z^3, 1) @param P The point to map @param modulus The modulus @param mp The "b" value from montgomery_setup() @return CRYPT_OK on success - @remark The mapping can be different but keep in mind a ecc_point only has three - integers (x,y,z) so if you use a different mapping you have to make it fit. + @remark The mapping can be different but keep in mind a + ecc_point only has three integers (x,y,z) so if + you use a different mapping you have to make it fit. */ int (*ecc_map)(ecc_point *P, void *modulus, void *mp); @@ -378,7 +402,7 @@ typedef struct { @param kA What to multiple A by @param B Second point to multiply @param kB What to multiple B by - @param C [out] Destination point (can overlap with A or B + @param C [out] Destination point (can overlap with A or B) @param modulus Modulus for curve @return CRYPT_OK on success */ @@ -392,19 +416,24 @@ typedef struct { /** RSA Key Generation @param prng An active PRNG state @param wprng The index of the PRNG desired - @param size The size of the modulus (key size) desired (octets) - @param e The "e" value (public key). e==65537 is a good choice + @param size The size of the key in octets + @param e The "e" value (public key). + e==65537 is a good choice @param key [out] Destination of a newly created private key pair @return CRYPT_OK if successful, upon error all allocated ram is freed */ - int (*rsa_keygen)(prng_state *prng, int wprng, int size, long e, rsa_key *key); - + int (*rsa_keygen)(prng_state *prng, + int wprng, + int size, + long e, + rsa_key *key); /** RSA exponentiation @param in The octet array representing the base @param inlen The length of the input @param out The destination (to be stored in an octet array format) - @param outlen The length of the output buffer and the resulting size (zero padded to the size of the modulus) + @param outlen The length of the output buffer and the resulting size + (zero padded to the size of the modulus) @param which PK_PUBLIC for public RSA and PK_PRIVATE for private RSA @param key The RSA key to use @return CRYPT_OK on success From 98b500e8736bf7c7d6a8ae37f7f11bdb042cb07c Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 12 Jun 2017 12:29:16 +0200 Subject: [PATCH 5/8] update crypt_build_settings et al. --- src/headers/tomcrypt_custom.h | 4 ++++ src/misc/crypt/crypt.c | 29 +++++++++++++++++------------ src/misc/crypt/crypt_constants.c | 7 +++++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/headers/tomcrypt_custom.h b/src/headers/tomcrypt_custom.h index 1c9ebe0..908175f 100644 --- a/src/headers/tomcrypt_custom.h +++ b/src/headers/tomcrypt_custom.h @@ -536,6 +536,10 @@ #error LTC_BLAKE2BMAC requires LTC_BLAKE2B #endif +#if defined(LTC_NO_MATH) && (defined(LTM_DESC) || defined(TFM_DESC) || defined(GMP_DESC)) + #error LTC_NO_MATH defined, but also a math descriptor +#endif + /* THREAD management */ #ifdef LTC_PTHREAD diff --git a/src/misc/crypt/crypt.c b/src/misc/crypt/crypt.c index cfe2606..b88e474 100644 --- a/src/misc/crypt/crypt.c +++ b/src/misc/crypt/crypt.c @@ -332,6 +332,23 @@ const char *crypt_build_settings = " Katja\n" #endif + "\nMPI (Math):\n" +#if defined(LTC_MPI) + " LTC_MPI\n" +#endif +#if defined(LTM_DESC) + " LTM_DESC\n" +#endif +#if defined(TFM_DESC) + " TFM_DESC\n" +#endif +#if defined(GMP_DESC) + " GMP_DESC\n" +#endif +#if defined(LTC_MILLER_RABIN_REPS) + " "NAME_VALUE(LTC_MILLER_RABIN_REPS)"\n" +#endif + "\nCompiler:\n" #if defined(_WIN64) " WIN64 platform detected.\n" @@ -390,9 +407,6 @@ const char *crypt_build_settings = #if defined(LTC_HKDF) " HKDF " #endif -#if defined(MPI) - " MPI " -#endif #if defined(LTC_DEVRANDOM) " LTC_DEVRANDOM " #endif @@ -456,15 +470,6 @@ const char *crypt_build_settings = #if defined(LTC_PTHREAD) " LTC_PTHREAD " #endif -#if defined(LTM_DESC) - " LTM_DESC " -#endif -#if defined(TFM_DESC) - " TFM_DESC " -#endif -#if defined(GMP_DESC) - " GMP_DESC " -#endif #if defined(LTC_EASY) " LTC_EASY " #endif diff --git a/src/misc/crypt/crypt_constants.c b/src/misc/crypt/crypt_constants.c index f3b968d..55612f4 100644 --- a/src/misc/crypt/crypt_constants.c +++ b/src/misc/crypt/crypt_constants.c @@ -80,6 +80,13 @@ static const crypt_constant _crypt_constants[] = { {"LTC_MDSA", 0}, #endif +#ifdef LTC_DER_MAX_PUBKEY_SIZE + _C_STRINGIFY(LTC_DER_MAX_PUBKEY_SIZE), +#endif +#ifdef LTC_MILLER_RABIN_REPS + _C_STRINGIFY(LTC_MILLER_RABIN_REPS), +#endif + #ifdef LTC_CTR_MODE {"LTC_CTR_MODE", 1}, _C_STRINGIFY(CTR_COUNTER_LITTLE_ENDIAN), From d6e2a585d0fcc1df6a0fb8987b65312d1304040a Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 12 Jun 2017 12:41:55 +0200 Subject: [PATCH 6/8] sync doc from ltc_math_descriptor --- doc/crypt.tex | 55 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/doc/crypt.tex b/doc/crypt.tex index d5461ab..9bb8a56 100644 --- a/doc/crypt.tex +++ b/doc/crypt.tex @@ -6789,6 +6789,13 @@ typedef struct { /* ---- data movement ---- */ + /** negate + @param src The number to negate + @param dst The destination + @return CRYPT_OK on success + */ + int (*neg)(void *src, void *dst); + /** copy @param src The number to copy from @param dst The number to write to @@ -6800,13 +6807,14 @@ typedef struct { /** set small constant @param a Number to write to - @param n Source upto bits_per_digit (meant for small constants) + @param n Source upto bits_per_digit (actually meant for very small constants) @return CRYPT_OK on success */ int (*set_int)(void *a, unsigned long n); /** get small constant - @param a Small number to read + @param a Small number to read, + only fetches up to bits_per_digit from the number @return The lower bits_per_digit of the integer (unsigned) */ unsigned long (*get_int)(void *a); @@ -6816,7 +6824,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 @@ -6880,7 +6888,7 @@ typedef struct { int (*write_radix)(void *a, char *str, int radix); /** get size as unsigned char string - @param a The integer to get the size + @param a The integer to get the size (when stored in array of octets) @return The length of the integer in octets */ unsigned long (*unsigned_size)(void *a); @@ -6915,7 +6923,7 @@ typedef struct { /** add two integers @param a The first source integer @param b The second source integer - (single digit of upto bits_per_digit in length) + (single digit of upto bits_per_digit in length) @param c The destination of "a + b" @return CRYPT_OK on success */ @@ -6970,7 +6978,7 @@ typedef struct { @param d The remainder (can be NULL to signify don't care) @return CRYPT_OK on success */ - int (*div)(void *a, void *b, void *c, void *d); + int (*mpdiv)(void *a, void *b, void *c, void *d); /** divide by two @param a The integer to divide (shift right) @@ -7071,10 +7079,11 @@ typedef struct { /** Primality testing @param a The integer to test - @param b The destination of the result (FP_YES if prime) + @param b The number of Miller-Rabin tests that shall be executed + @param c The destination of the result (FP_YES if prime) @return CRYPT_OK on success */ - int (*isprime)(void *a, int *b); + int (*isprime)(void *a, int b, int *c); /* ---- (optional) ecc point math ---- */ @@ -7145,7 +7154,6 @@ typedef struct { ecc_point *C, void *modulus); - /* ---- (optional) rsa optimized math (for internal CRT) ---- */ /** RSA Key Generation @@ -7176,6 +7184,35 @@ typedef struct { int (*rsa_me)(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen, int which, rsa_key *key); + +/* ---- basic math continued ---- */ + + /** Modular addition + @param a The first source + @param b The second source + @param c The modulus + @param d The destination (a + b mod c) + @return CRYPT_OK on success + */ + int (*addmod)(void *a, void *b, void *c, void *d); + + /** Modular substraction + @param a The first source + @param b The second source + @param c The modulus + @param d The destination (a - b mod c) + @return CRYPT_OK on success + */ + int (*submod)(void *a, void *b, void *c, void *d); + +/* ---- misc stuff ---- */ + + /** Make a pseudo-random mpi + @param a The mpi to make random + @param size The desired length + @return CRYPT_OK on success + */ + int (*rand)(void *a, int size); } ltc_math_descriptor; \end{verbatim} \end{small} From 258de3ceccbdf2d31e0e8e7c0dd158d3450df253 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 12 Jun 2017 13:07:12 +0200 Subject: [PATCH 7/8] use ltc_mp_digit instead of unsigned long --- src/headers/tomcrypt_math.h | 12 ++++++------ src/math/gmp_desc.c | 12 ++++++------ src/math/ltm_desc.c | 12 ++++++------ src/math/tfm_desc.c | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/headers/tomcrypt_math.h b/src/headers/tomcrypt_math.h index 833deac..6c1ceda 100644 --- a/src/headers/tomcrypt_math.h +++ b/src/headers/tomcrypt_math.h @@ -67,7 +67,7 @@ typedef struct { @param n Source upto bits_per_digit (actually meant for very small constants) @return CRYPT_OK on success */ - int (*set_int)(void *a, unsigned long n); + int (*set_int)(void *a, ltc_mp_digit n); /** get small constant @param a Small number to read, @@ -105,7 +105,7 @@ typedef struct { LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison) */ - int (*compare_d)(void *a, unsigned long n); + int (*compare_d)(void *a, ltc_mp_digit n); /** Count the number of bits used to represent the integer @param a The integer to count @@ -184,7 +184,7 @@ typedef struct { @param c The destination of "a + b" @return CRYPT_OK on success */ - int (*addi)(void *a, unsigned long b, void *c); + int (*addi)(void *a, ltc_mp_digit b, void *c); /** subtract two integers @param a The first source integer @@ -201,7 +201,7 @@ typedef struct { @param c The destination of "a - b" @return CRYPT_OK on success */ - int (*subi)(void *a, unsigned long b, void *c); + int (*subi)(void *a, ltc_mp_digit b, void *c); /** multiply two integers @param a The first source integer @@ -219,7 +219,7 @@ typedef struct { @param c The destination of "a * b" @return CRYPT_OK on success */ - int (*muli)(void *a, unsigned long b, void *c); + int (*muli)(void *a, ltc_mp_digit b, void *c); /** Square an integer @param a The integer to square @@ -250,7 +250,7 @@ typedef struct { @param c The destination for the residue @return CRYPT_OK on success */ - int (*modi)(void *a, unsigned long b, unsigned long *c); + int (*modi)(void *a, ltc_mp_digit b, ltc_mp_digit *c); /** gcd @param a The first integer diff --git a/src/math/gmp_desc.c b/src/math/gmp_desc.c index 0a23e99..817f08c 100644 --- a/src/math/gmp_desc.c +++ b/src/math/gmp_desc.c @@ -61,7 +61,7 @@ static int init_copy(void **a, void *b) } /* ---- trivial ---- */ -static int set_int(void *a, unsigned long b) +static int set_int(void *a, ltc_mp_digit b) { LTC_ARGCHK(a != NULL); mpz_set_ui(((__mpz_struct *)a), b); @@ -101,7 +101,7 @@ static int compare(void *a, void *b) } } -static int compare_d(void *a, unsigned long b) +static int compare_d(void *a, ltc_mp_digit b) { int ret; LTC_ARGCHK(a != NULL); @@ -235,7 +235,7 @@ static int add(void *a, void *b, void *c) return CRYPT_OK; } -static int addi(void *a, unsigned long b, void *c) +static int addi(void *a, ltc_mp_digit b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); @@ -253,7 +253,7 @@ static int sub(void *a, void *b, void *c) return CRYPT_OK; } -static int subi(void *a, unsigned long b, void *c) +static int subi(void *a, ltc_mp_digit b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); @@ -271,7 +271,7 @@ static int mul(void *a, void *b, void *c) return CRYPT_OK; } -static int muli(void *a, unsigned long b, void *c) +static int muli(void *a, ltc_mp_digit b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); @@ -317,7 +317,7 @@ static int div_2(void *a, void *b) } /* modi */ -static int modi(void *a, unsigned long b, unsigned long *c) +static int modi(void *a, ltc_mp_digit b, ltc_mp_digit *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); diff --git a/src/math/ltm_desc.c b/src/math/ltm_desc.c index 22937e8..ca87d6d 100644 --- a/src/math/ltm_desc.c +++ b/src/math/ltm_desc.c @@ -88,7 +88,7 @@ static int init_copy(void **a, void *b) } /* ---- trivial ---- */ -static int set_int(void *a, unsigned long b) +static int set_int(void *a, ltc_mp_digit b) { LTC_ARGCHK(a != NULL); return mpi_to_ltc_error(mp_set_int(a, b)); @@ -130,7 +130,7 @@ static int compare(void *a, void *b) } } -static int compare_d(void *a, unsigned long b) +static int compare_d(void *a, ltc_mp_digit b) { int ret; LTC_ARGCHK(a != NULL); @@ -212,7 +212,7 @@ static int add(void *a, void *b, void *c) return mpi_to_ltc_error(mp_add(a, b, c)); } -static int addi(void *a, unsigned long b, void *c) +static int addi(void *a, ltc_mp_digit b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); @@ -228,7 +228,7 @@ static int sub(void *a, void *b, void *c) return mpi_to_ltc_error(mp_sub(a, b, c)); } -static int subi(void *a, unsigned long b, void *c) +static int subi(void *a, ltc_mp_digit b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); @@ -244,7 +244,7 @@ static int mul(void *a, void *b, void *c) return mpi_to_ltc_error(mp_mul(a, b, c)); } -static int muli(void *a, unsigned long b, void *c) +static int muli(void *a, ltc_mp_digit b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); @@ -275,7 +275,7 @@ static int div_2(void *a, void *b) } /* modi */ -static int modi(void *a, unsigned long b, unsigned long *c) +static int modi(void *a, ltc_mp_digit b, ltc_mp_digit *c) { mp_digit tmp; int err; diff --git a/src/math/tfm_desc.c b/src/math/tfm_desc.c index d8e09af..66b4f3e 100644 --- a/src/math/tfm_desc.c +++ b/src/math/tfm_desc.c @@ -84,7 +84,7 @@ static int init_copy(void **a, void *b) } /* ---- trivial ---- */ -static int set_int(void *a, unsigned long b) +static int set_int(void *a, ltc_mp_digit b) { LTC_ARGCHK(a != NULL); fp_set(a, b); @@ -129,7 +129,7 @@ static int compare(void *a, void *b) return 0; } -static int compare_d(void *a, unsigned long b) +static int compare_d(void *a, ltc_mp_digit b) { int ret; LTC_ARGCHK(a != NULL); @@ -214,7 +214,7 @@ static int add(void *a, void *b, void *c) return CRYPT_OK; } -static int addi(void *a, unsigned long b, void *c) +static int addi(void *a, ltc_mp_digit b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); @@ -232,7 +232,7 @@ static int sub(void *a, void *b, void *c) return CRYPT_OK; } -static int subi(void *a, unsigned long b, void *c) +static int subi(void *a, ltc_mp_digit b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); @@ -250,7 +250,7 @@ static int mul(void *a, void *b, void *c) return CRYPT_OK; } -static int muli(void *a, unsigned long b, void *c) +static int muli(void *a, ltc_mp_digit b, void *c) { LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); @@ -284,7 +284,7 @@ static int div_2(void *a, void *b) } /* modi */ -static int modi(void *a, unsigned long b, unsigned long *c) +static int modi(void *a, ltc_mp_digit b, ltc_mp_digit *c) { fp_digit tmp; int err; From f2076f070069c94c7297619df4b4c653d094ef97 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 12 Jun 2017 13:08:37 +0200 Subject: [PATCH 8/8] use zeromem() where appropriate --- src/prngs/chacha20.c | 2 +- src/prngs/rc4.c | 1 + src/prngs/sober128.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/prngs/chacha20.c b/src/prngs/chacha20.c index faaf629..b528dd2 100644 --- a/src/prngs/chacha20.c +++ b/src/prngs/chacha20.c @@ -71,7 +71,7 @@ int chacha20_prng_add_entropy(const unsigned char *in, unsigned long inlen, prng /* iv 8 bytes */ if ((err = chacha_ivctr64(&prng->chacha.s, buf + 32, 8, 0)) != CRYPT_OK) goto LBL_UNLOCK; /* clear KEY + IV */ - XMEMSET(buf, 0, sizeof(buf)); + zeromem(buf, sizeof(buf)); } else { /* chacha20_prng_ready() was not called yet, add entropy to ent buffer */ diff --git a/src/prngs/rc4.c b/src/prngs/rc4.c index e7d3afc..ac88fd5 100644 --- a/src/prngs/rc4.c +++ b/src/prngs/rc4.c @@ -72,6 +72,7 @@ int rc4_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *pr if ((err = rc4_stream_setup(&prng->rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK; /* drop first 3072 bytes - https://en.wikipedia.org/wiki/RC4#Fluhrer.2C_Mantin_and_Shamir_attack */ for (i = 0; i < 12; i++) rc4_stream_keystream(&prng->rc4.s, buf, sizeof(buf)); + zeromem(buf, sizeof(buf)); } else { /* rc4_ready() was not called yet, add entropy to the buffer */ diff --git a/src/prngs/sober128.c b/src/prngs/sober128.c index 56f873c..64d083b 100644 --- a/src/prngs/sober128.c +++ b/src/prngs/sober128.c @@ -73,7 +73,7 @@ int sober128_add_entropy(const unsigned char *in, unsigned long inlen, prng_stat /* iv 8 bytes */ if ((err = sober128_stream_setiv(&prng->sober128.s, buf + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK; /* clear KEY + IV */ - XMEMSET(buf, 0, sizeof(buf)); + zeromem(buf, sizeof(buf)); } else { /* sober128_ready() was not called yet, add entropy to ent buffer */