From 196f25e32fafa221e5d1cbe7706cc510434a3212 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Fri, 24 Nov 2017 07:39:36 +0100 Subject: [PATCH 01/12] there should be no need to pass CFLAGS when linking --- makefile | 2 +- makefile.shared | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index a7ff18faa..cd94b86f7 100644 --- a/makefile +++ b/makefile @@ -69,7 +69,7 @@ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1). ifneq ($V,1) @echo " * $${CC} $$@" endif - $${silent} $$(CC) $$(LTC_CFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1) + $${silent} $$(CC) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1) endef $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) diff --git a/makefile.shared b/makefile.shared index 4bc6015e1..9f861c83f 100644 --- a/makefile.shared +++ b/makefile.shared @@ -49,15 +49,15 @@ src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c LOBJECTS = $(OBJECTS:.o=.lo) $(LIBNAME): $(OBJECTS) - $(LT) --mode=link --tag=CC $(CC) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) $(NO_UNDEFINED) + $(LT) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) $(NO_UNDEFINED) test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) $(LIBNAME) $(TOBJECTS) - $(LT) --mode=link --tag=CC $(CC) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS) + $(LT) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS) # build the demos from a template define DEMO_template $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME) - $$(LT) --mode=link --tag=CC $$(CC) $$(LTC_CFLAGS) $$(CPPFLAGS) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $(1) + $$(LT) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $(1) endef $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) From ea43e5dd68c3161416b1f0645a13eaa837ebf983 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sun, 26 Nov 2017 01:14:34 +0100 Subject: [PATCH 02/12] suppress 'missing-braces' warnings --- makefile_include.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/makefile_include.mk b/makefile_include.mk index 25bd3b40b..2c9b9e32e 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -104,7 +104,8 @@ endif # COMPILE_DEBUG ifneq ($(findstring clang,$(CC)),) -LTC_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header -Wno-missing-field-initializers +LTC_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header +LTC_CFLAGS += -Wno-missing-field-initializers -Wno-missing-braces endif ifneq ($(findstring mingw,$(CC)),) LTC_CFLAGS += -Wno-shadow -Wno-attributes From 5e3e7e5304ed5eb73208e0e46ef76e9b03b0f4af Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 28 Nov 2017 10:49:12 +0100 Subject: [PATCH 03/12] fixup type of `type` in `ltc_asn1_list` doc --- doc/crypt.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/crypt.tex b/doc/crypt.tex index 223d4d187..e4e721052 100644 --- a/doc/crypt.tex +++ b/doc/crypt.tex @@ -5500,7 +5500,7 @@ \chapter{Standards Support} \index{ltc\_asn1\_list structure} \begin{verbatim} typedef struct { - int type; + ltc_asn1_type type; void *data; unsigned long size; int used; @@ -5572,6 +5572,7 @@ \chapter{Standards Support} \hline \end{tabular} \caption{List of ASN.1 Supported Types} +\index{ltc\_asn1\_type} \end{small} \end{center} \end{figure} From 6d71d657ef0371ac50c51ef9001e2e340dedf95a Mon Sep 17 00:00:00 2001 From: Karel Miko Date: Wed, 22 Nov 2017 18:27:11 +0100 Subject: [PATCH 04/12] fix staticfunc_name detection --- helper.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper.pl b/helper.pl index a1eebeeb4..447a0063c 100755 --- a/helper.pl +++ b/helper.pl @@ -61,7 +61,7 @@ sub check_source { $file !~ m|src/hashes/.*\.c$| && $file !~ m|src/math/.+_desc.c$| && $file !~ m|src/stream/sober128/sober128_stream.c$| && - $l =~ /^static(\s+\S+)+\s+([^_][a-zA-Z0-9_]+)\s*\(/) { + $l =~ /^static(\s+[a-zA-Z0-9_]+)+\s+([^_][a-zA-Z0-9_]+)\s*\(/) { push @{$troubles->{staticfunc_name}}, "$lineno($2)"; } $lineno++; From 5546e8521866ae6f954284f06c9a1561611bf8a9 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 6 Dec 2017 23:54:33 +0100 Subject: [PATCH 05/12] introduce LTC_EXTRALIBS it's used for libraries added in the makefile --- makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/makefile b/makefile index cd94b86f7..1cdd3b7c7 100644 --- a/makefile +++ b/makefile @@ -34,9 +34,11 @@ ifeq ($(COVERAGE),1) all_test: LIB_PRE = -Wl,--whole-archive all_test: LIB_POST = -Wl,--no-whole-archive LTC_CFLAGS += -fprofile-arcs -ftest-coverage -EXTRALIBS += -lgcov +LTC_EXTRALIBS += -lgcov endif +LTC_EXTRALIBS += $(EXTRALIBS) + #AES comes in two flavours... enc+dec and enc src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c ${silent} ${CC} ${LTC_CFLAGS} -DENCRYPT_ONLY -c $< -o $@ @@ -61,7 +63,7 @@ test: $(call print-help,test,Builds the library and the 'test' application to ru ifneq ($V,1) @echo " * ${CC} $@" endif - ${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST) + ${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(LTC_EXTRALIBS) -o $(TEST) # build the demos from a template define DEMO_template @@ -69,7 +71,7 @@ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1). ifneq ($V,1) @echo " * $${CC} $$@" endif - $${silent} $$(CC) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1) + $${silent} $$(CC) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $(1) endef $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) @@ -85,10 +87,10 @@ install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL uninstall: $(call print-help,uninstall,Uninstalls the library and headers) .common_uninstall profile: - LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov" + LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(LTC_EXTRALIBS) -lgcov" ./timing rm -f timing `find . -type f | grep [.][ao] | xargs` - LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-use" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov" + LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-use" $(MAKE) timing EXTRALIBS="$(LTC_EXTRALIBS) -lgcov" # target that pre-processes all coverage data lcov-single-create: @@ -117,7 +119,7 @@ lcov-single: #make the code coverage of the library coverage: LTC_CFLAGS += -fprofile-arcs -ftest-coverage -coverage: EXTRALIBS += -lgcov +coverage: LTC_EXTRALIBS += -lgcov coverage: LIB_PRE = -Wl,--whole-archive coverage: LIB_POST = -Wl,--no-whole-archive From c0b7c8dd67f35105b42f0ffad192992fb035ed6f Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 25 Oct 2017 15:31:59 +0200 Subject: [PATCH 06/12] more output in debug build make compare_testvector() a bit more verbose in debug build --- src/misc/compare_testvector.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/misc/compare_testvector.c b/src/misc/compare_testvector.c index 82433c6f8..74cebcc39 100644 --- a/src/misc/compare_testvector.c +++ b/src/misc/compare_testvector.c @@ -73,6 +73,10 @@ int compare_testvector(const void* is, const unsigned long is_len, const void* s fprintf(stderr, "Testvector #%i of %s failed:\n", which, what); _print_hex("SHOULD", should, should_len); _print_hex("IS ", is, is_len); +#if LTC_TEST_DBG > 1 + } else { + fprintf(stderr, "Testvector #%i of %s passed!\n", which, what); +#endif } #else LTC_UNUSED_PARAM(which); From 5c0b1b4bf6ee7ca0cec867e04f3253710b267ed4 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 25 Oct 2017 15:30:05 +0200 Subject: [PATCH 07/12] add copy_or_zeromem() --- src/encauth/ccm/ccm_memory.c | 24 +------------- src/headers/tomcrypt_misc.h | 3 ++ src/misc/copy_or_zeromem.c | 61 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 src/misc/copy_or_zeromem.c diff --git a/src/encauth/ccm/ccm_memory.c b/src/encauth/ccm/ccm_memory.c index 3326ce5c1..0ffdbcef3 100644 --- a/src/encauth/ccm/ccm_memory.c +++ b/src/encauth/ccm/ccm_memory.c @@ -51,10 +51,6 @@ int ccm_memory(int cipher, symmetric_key *skey; int err; unsigned long len, L, x, y, z, CTRlen; -#ifdef LTC_FAST - LTC_FAST_TYPE fastMask = ~0; /* initialize fastMask at all zeroes */ -#endif - unsigned char mask = 0xff; /* initialize mask at all zeroes */ if (uskey == NULL) { LTC_ARGCHK(key != NULL); @@ -360,29 +356,11 @@ int ccm_memory(int cipher, /* Zero the plaintext if the tag was invalid (in constant time) */ if (ptlen > 0) { - y = 0; - mask *= 1 - err; /* mask = ( err ? 0 : 0xff ) */ -#ifdef LTC_FAST - fastMask *= 1 - err; - if (ptlen & ~15) { - for (; y < (ptlen & ~15); y += 16) { - for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST(&pt_real[y+z])) = *(LTC_FAST_TYPE_PTR_CAST(&pt[y+z])) & fastMask; - } - } - } -#endif - for (; y < ptlen; y++) { - pt_real[y] = pt[y] & mask; - } + copy_or_zeromem(pt, pt_real, ptlen, err); } } #ifdef LTC_CLEAN_STACK -#ifdef LTC_FAST - fastMask = 0; -#endif - mask = 0; zeromem(PAD, sizeof(PAD)); zeromem(CTRPAD, sizeof(CTRPAD)); if (pt_work != NULL) { diff --git a/src/headers/tomcrypt_misc.h b/src/headers/tomcrypt_misc.h index 0440a5ef9..63fc3a897 100644 --- a/src/headers/tomcrypt_misc.h +++ b/src/headers/tomcrypt_misc.h @@ -72,6 +72,9 @@ int hkdf(int hash_idx, /* ---- MEM routines ---- */ int mem_neq(const void *a, const void *b, size_t len); void zeromem(volatile void *dst, size_t len); +#ifdef LTC_SOURCE +void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned long len, int coz); +#endif void burn_stack(unsigned long len); const char *error_to_string(int err); diff --git a/src/misc/copy_or_zeromem.c b/src/misc/copy_or_zeromem.c new file mode 100644 index 000000000..ec78fed6e --- /dev/null +++ b/src/misc/copy_or_zeromem.c @@ -0,0 +1,61 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + */ +#include "tomcrypt.h" + +/** + @file copy_or_zeromem.c + Either copy or zero a block of memory in constant time, Steffen Jaeckel +*/ + +/** + Either copy or zero a block of memory in constant time + @param src The source where to read from + @param dest The destination where to write to + @param len The length of the area to process (octets) + @param coz Copy (on 0) Or Zero (> 0) +*/ +void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned long len, int coz) +{ + unsigned long y; +#ifdef LTC_FAST + unsigned long z; + LTC_FAST_TYPE fastMask = ~0; /* initialize fastMask at all ones */ +#endif + unsigned char mask = 0xff; /* initialize mask at all ones */ + + LTC_ARGCHK(src != NULL); + LTC_ARGCHK(dest != NULL); + + if (coz != 0) coz = 1; + y = 0; + mask *= 1 - coz; /* mask = ( coz ? 0 : 0xff ) */ +#ifdef LTC_FAST + fastMask *= 1 - coz; + if (len & ~15) { + for (; y < (len & ~15); y += 16) { + for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) { + *(LTC_FAST_TYPE_PTR_CAST(&dest[y+z])) = *(LTC_FAST_TYPE_PTR_CAST(&src[y+z])) & fastMask; + } + } + } +#endif + for (; y < len; y++) { + dest[y] = src[y] & mask; + } +#ifdef LTC_CLEAN_STACK +#ifdef LTC_FAST + fastMask = 0; +#endif + mask = 0; +#endif +} + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ From 8fffebc395f1b8a1900c94095d16bce79059398c Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 5 Dec 2017 17:31:10 +0100 Subject: [PATCH 08/12] fix .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e373a28bc..e34d84ca6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ script: env: - | BUILDSCRIPT=".ci/meta_builds.sh" - BUILDNAME="META_BUILS" + BUILDNAME="META_BUILDS" BUILDOPTIONS="-DGMP_DESC" - | BUILDSCRIPT=".ci/valgrind.sh" From fd46a74331c7e6f700f55d6515914263b8de0aca Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 12 Oct 2017 12:44:14 +0200 Subject: [PATCH 09/12] re-order tomcrypt_mac.h --- src/headers/tomcrypt_mac.h | 182 +++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 89 deletions(-) diff --git a/src/headers/tomcrypt_mac.h b/src/headers/tomcrypt_mac.h index 9c2602145..c4b24239a 100644 --- a/src/headers/tomcrypt_mac.h +++ b/src/headers/tomcrypt_mac.h @@ -146,6 +146,99 @@ int blake2bmac_file(const char *fname, const unsigned char *key, unsigned long k int blake2bmac_test(void); #endif /* LTC_BLAKE2BMAC */ +#ifdef LTC_PELICAN + +typedef struct pelican_state +{ + symmetric_key K; + unsigned char state[16]; + int buflen; +} pelican_state; + +int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen); +int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen); +int pelican_done(pelican_state *pelmac, unsigned char *out); +int pelican_test(void); + +int pelican_memory(const unsigned char *key, unsigned long keylen, + const unsigned char *in, unsigned long inlen, + unsigned char *out); + +#endif + +#ifdef LTC_XCBC + +/* add this to "keylen" to xcbc_init to use a pure three-key XCBC MAC */ +#define LTC_XCBC_PURE 0x8000UL + +typedef struct { + unsigned char K[3][MAXBLOCKSIZE], + IV[MAXBLOCKSIZE]; + + symmetric_key key; + + int cipher, + buflen, + blocksize; +} xcbc_state; + +int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned long keylen); +int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen); +int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen); +int xcbc_memory(int cipher, + const unsigned char *key, unsigned long keylen, + const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen); +int xcbc_memory_multi(int cipher, + const unsigned char *key, unsigned long keylen, + unsigned char *out, unsigned long *outlen, + const unsigned char *in, unsigned long inlen, ...); +int xcbc_file(int cipher, + const unsigned char *key, unsigned long keylen, + const char *filename, + unsigned char *out, unsigned long *outlen); +int xcbc_test(void); + +#endif + +#ifdef LTC_F9_MODE + +typedef struct { + unsigned char akey[MAXBLOCKSIZE], + ACC[MAXBLOCKSIZE], + IV[MAXBLOCKSIZE]; + + symmetric_key key; + + int cipher, + buflen, + keylen, + blocksize; +} f9_state; + +int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long keylen); +int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen); +int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen); +int f9_memory(int cipher, + const unsigned char *key, unsigned long keylen, + const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen); +int f9_memory_multi(int cipher, + const unsigned char *key, unsigned long keylen, + unsigned char *out, unsigned long *outlen, + const unsigned char *in, unsigned long inlen, ...); +int f9_file(int cipher, + const unsigned char *key, unsigned long keylen, + const char *filename, + unsigned char *out, unsigned long *outlen); +int f9_test(void); + +#endif + +/* + * ENC+AUTH modes + */ + #ifdef LTC_EAX_MODE #if !(defined(LTC_OMAC) && defined(LTC_CTR_MODE)) @@ -440,95 +533,6 @@ int gcm_test(void); #endif /* LTC_GCM_MODE */ -#ifdef LTC_PELICAN - -typedef struct pelican_state -{ - symmetric_key K; - unsigned char state[16]; - int buflen; -} pelican_state; - -int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen); -int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen); -int pelican_done(pelican_state *pelmac, unsigned char *out); -int pelican_test(void); - -int pelican_memory(const unsigned char *key, unsigned long keylen, - const unsigned char *in, unsigned long inlen, - unsigned char *out); - -#endif - -#ifdef LTC_XCBC - -/* add this to "keylen" to xcbc_init to use a pure three-key XCBC MAC */ -#define LTC_XCBC_PURE 0x8000UL - -typedef struct { - unsigned char K[3][MAXBLOCKSIZE], - IV[MAXBLOCKSIZE]; - - symmetric_key key; - - int cipher, - buflen, - blocksize; -} xcbc_state; - -int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned long keylen); -int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen); -int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen); -int xcbc_memory(int cipher, - const unsigned char *key, unsigned long keylen, - const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); -int xcbc_memory_multi(int cipher, - const unsigned char *key, unsigned long keylen, - unsigned char *out, unsigned long *outlen, - const unsigned char *in, unsigned long inlen, ...); -int xcbc_file(int cipher, - const unsigned char *key, unsigned long keylen, - const char *filename, - unsigned char *out, unsigned long *outlen); -int xcbc_test(void); - -#endif - -#ifdef LTC_F9_MODE - -typedef struct { - unsigned char akey[MAXBLOCKSIZE], - ACC[MAXBLOCKSIZE], - IV[MAXBLOCKSIZE]; - - symmetric_key key; - - int cipher, - buflen, - keylen, - blocksize; -} f9_state; - -int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long keylen); -int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen); -int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen); -int f9_memory(int cipher, - const unsigned char *key, unsigned long keylen, - const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); -int f9_memory_multi(int cipher, - const unsigned char *key, unsigned long keylen, - unsigned char *out, unsigned long *outlen, - const unsigned char *in, unsigned long inlen, ...); -int f9_file(int cipher, - const unsigned char *key, unsigned long keylen, - const char *filename, - unsigned char *out, unsigned long *outlen); -int f9_test(void); - -#endif - #ifdef LTC_CHACHA20POLY1305_MODE typedef struct { From 38143771d74a71aa0242874e912aa527d90e2f68 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 6 Dec 2017 23:58:21 +0100 Subject: [PATCH 10/12] Update makefiles --- libtomcrypt_VS2008.vcproj | 4 ++++ makefile.mingw | 28 ++++++++++++++-------------- makefile.msvc | 28 ++++++++++++++-------------- makefile.unix | 28 ++++++++++++++-------------- makefile_include.mk | 28 ++++++++++++++-------------- 5 files changed, 60 insertions(+), 56 deletions(-) diff --git a/libtomcrypt_VS2008.vcproj b/libtomcrypt_VS2008.vcproj index e6cebe3da..4c9ee2c2a 100644 --- a/libtomcrypt_VS2008.vcproj +++ b/libtomcrypt_VS2008.vcproj @@ -1351,6 +1351,10 @@ RelativePath="src\misc\compare_testvector.c" > + + diff --git a/makefile.mingw b/makefile.mingw index 14558bb58..e3e5712a0 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -92,20 +92,20 @@ src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_t 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/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/burn_stack.o src/misc/compare_testvector.o src/misc/crc32.o \ -src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash_id.o \ -src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ -src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ -src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ -src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ -src/misc/crypt/crypt_prng_rng_descriptor.o src/misc/crypt/crypt_register_all_ciphers.o \ -src/misc/crypt/crypt_register_all_hashes.o src/misc/crypt/crypt_register_all_prngs.o \ -src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \ -src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ +src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/compare_testvector.o \ +src/misc/copy_or_zeromem.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \ +src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \ +src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ +src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ +src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_inits.o \ +src/misc/crypt/crypt_ltc_mp_descriptor.o src/misc/crypt/crypt_prng_descriptor.o \ +src/misc/crypt/crypt_prng_is_valid.o src/misc/crypt/crypt_prng_rng_descriptor.o \ +src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \ +src/misc/crypt/crypt_register_all_prngs.o src/misc/crypt/crypt_register_cipher.o \ +src/misc/crypt/crypt_register_hash.o src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ src/misc/hkdf/hkdf_test.o src/misc/mem_neq.o src/misc/pk_get_oid.o src/misc/pkcs5/pkcs_5_1.o \ diff --git a/makefile.msvc b/makefile.msvc index 4140c8306..94c744d34 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -85,20 +85,20 @@ src/mac/xcbc/xcbc_memory_multi.obj src/mac/xcbc/xcbc_process.obj src/mac/xcbc/xc src/math/fp/ltc_ecc_fp_mulmod.obj src/math/gmp_desc.obj src/math/ltm_desc.obj src/math/multi.obj \ src/math/radix_to_bin.obj src/math/rand_bn.obj src/math/rand_prime.obj src/math/tfm_desc.obj src/misc/adler32.obj \ src/misc/base32/base32_decode.obj src/misc/base32/base32_encode.obj src/misc/base64/base64_decode.obj \ -src/misc/base64/base64_encode.obj src/misc/burn_stack.obj src/misc/compare_testvector.obj src/misc/crc32.obj \ -src/misc/crypt/crypt.obj src/misc/crypt/crypt_argchk.obj src/misc/crypt/crypt_cipher_descriptor.obj \ -src/misc/crypt/crypt_cipher_is_valid.obj src/misc/crypt/crypt_constants.obj \ -src/misc/crypt/crypt_find_cipher.obj src/misc/crypt/crypt_find_cipher_any.obj \ -src/misc/crypt/crypt_find_cipher_id.obj src/misc/crypt/crypt_find_hash.obj \ -src/misc/crypt/crypt_find_hash_any.obj src/misc/crypt/crypt_find_hash_id.obj \ -src/misc/crypt/crypt_find_hash_oid.obj src/misc/crypt/crypt_find_prng.obj src/misc/crypt/crypt_fsa.obj \ -src/misc/crypt/crypt_hash_descriptor.obj src/misc/crypt/crypt_hash_is_valid.obj \ -src/misc/crypt/crypt_inits.obj src/misc/crypt/crypt_ltc_mp_descriptor.obj \ -src/misc/crypt/crypt_prng_descriptor.obj src/misc/crypt/crypt_prng_is_valid.obj \ -src/misc/crypt/crypt_prng_rng_descriptor.obj src/misc/crypt/crypt_register_all_ciphers.obj \ -src/misc/crypt/crypt_register_all_hashes.obj src/misc/crypt/crypt_register_all_prngs.obj \ -src/misc/crypt/crypt_register_cipher.obj src/misc/crypt/crypt_register_hash.obj \ -src/misc/crypt/crypt_register_prng.obj src/misc/crypt/crypt_sizes.obj \ +src/misc/base64/base64_encode.obj src/misc/burn_stack.obj src/misc/compare_testvector.obj \ +src/misc/copy_or_zeromem.obj src/misc/crc32.obj src/misc/crypt/crypt.obj src/misc/crypt/crypt_argchk.obj \ +src/misc/crypt/crypt_cipher_descriptor.obj src/misc/crypt/crypt_cipher_is_valid.obj \ +src/misc/crypt/crypt_constants.obj src/misc/crypt/crypt_find_cipher.obj \ +src/misc/crypt/crypt_find_cipher_any.obj src/misc/crypt/crypt_find_cipher_id.obj \ +src/misc/crypt/crypt_find_hash.obj src/misc/crypt/crypt_find_hash_any.obj \ +src/misc/crypt/crypt_find_hash_id.obj src/misc/crypt/crypt_find_hash_oid.obj \ +src/misc/crypt/crypt_find_prng.obj src/misc/crypt/crypt_fsa.obj src/misc/crypt/crypt_hash_descriptor.obj \ +src/misc/crypt/crypt_hash_is_valid.obj src/misc/crypt/crypt_inits.obj \ +src/misc/crypt/crypt_ltc_mp_descriptor.obj src/misc/crypt/crypt_prng_descriptor.obj \ +src/misc/crypt/crypt_prng_is_valid.obj src/misc/crypt/crypt_prng_rng_descriptor.obj \ +src/misc/crypt/crypt_register_all_ciphers.obj src/misc/crypt/crypt_register_all_hashes.obj \ +src/misc/crypt/crypt_register_all_prngs.obj src/misc/crypt/crypt_register_cipher.obj \ +src/misc/crypt/crypt_register_hash.obj src/misc/crypt/crypt_register_prng.obj src/misc/crypt/crypt_sizes.obj \ src/misc/crypt/crypt_unregister_cipher.obj src/misc/crypt/crypt_unregister_hash.obj \ src/misc/crypt/crypt_unregister_prng.obj src/misc/error_to_string.obj src/misc/hkdf/hkdf.obj \ src/misc/hkdf/hkdf_test.obj src/misc/mem_neq.obj src/misc/pk_get_oid.obj src/misc/pkcs5/pkcs_5_1.obj \ diff --git a/makefile.unix b/makefile.unix index c7f4bbc89..f3e1b808e 100644 --- a/makefile.unix +++ b/makefile.unix @@ -102,20 +102,20 @@ src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_t 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/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/burn_stack.o src/misc/compare_testvector.o src/misc/crc32.o \ -src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash_id.o \ -src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ -src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ -src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ -src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ -src/misc/crypt/crypt_prng_rng_descriptor.o src/misc/crypt/crypt_register_all_ciphers.o \ -src/misc/crypt/crypt_register_all_hashes.o src/misc/crypt/crypt_register_all_prngs.o \ -src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \ -src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ +src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/compare_testvector.o \ +src/misc/copy_or_zeromem.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \ +src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \ +src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ +src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ +src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_inits.o \ +src/misc/crypt/crypt_ltc_mp_descriptor.o src/misc/crypt/crypt_prng_descriptor.o \ +src/misc/crypt/crypt_prng_is_valid.o src/misc/crypt/crypt_prng_rng_descriptor.o \ +src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \ +src/misc/crypt/crypt_register_all_prngs.o src/misc/crypt/crypt_register_cipher.o \ +src/misc/crypt/crypt_register_hash.o src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ src/misc/hkdf/hkdf_test.o src/misc/mem_neq.o src/misc/pk_get_oid.o src/misc/pkcs5/pkcs_5_1.o \ diff --git a/makefile_include.mk b/makefile_include.mk index 2c9b9e32e..ced786d5e 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -242,20 +242,20 @@ src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_t 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/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/burn_stack.o src/misc/compare_testvector.o src/misc/crc32.o \ -src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash_id.o \ -src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ -src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ -src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ -src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ -src/misc/crypt/crypt_prng_rng_descriptor.o src/misc/crypt/crypt_register_all_ciphers.o \ -src/misc/crypt/crypt_register_all_hashes.o src/misc/crypt/crypt_register_all_prngs.o \ -src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \ -src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ +src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/compare_testvector.o \ +src/misc/copy_or_zeromem.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \ +src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \ +src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ +src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ +src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_inits.o \ +src/misc/crypt/crypt_ltc_mp_descriptor.o src/misc/crypt/crypt_prng_descriptor.o \ +src/misc/crypt/crypt_prng_is_valid.o src/misc/crypt/crypt_prng_rng_descriptor.o \ +src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \ +src/misc/crypt/crypt_register_all_prngs.o src/misc/crypt/crypt_register_cipher.o \ +src/misc/crypt/crypt_register_hash.o src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ src/misc/hkdf/hkdf_test.o src/misc/mem_neq.o src/misc/pk_get_oid.o src/misc/pkcs5/pkcs_5_1.o \ From b84bea8e78ce3418637aa8c67d82a18bc499797c Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 23 Nov 2017 18:30:19 +0100 Subject: [PATCH 11/12] easier calculation --- src/pk/asn1/der/bit/der_encode_bit_string.c | 2 +- src/pk/asn1/der/bit/der_encode_raw_bit_string.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pk/asn1/der/bit/der_encode_bit_string.c b/src/pk/asn1/der/bit/der_encode_bit_string.c index c552184c7..2a6747902 100644 --- a/src/pk/asn1/der/bit/der_encode_bit_string.c +++ b/src/pk/asn1/der/bit/der_encode_bit_string.c @@ -47,7 +47,7 @@ int der_encode_bit_string(const unsigned char *in, unsigned long inlen, /* store header (include bit padding count in length) */ x = 0; - y = (inlen >> 3) + ((inlen&7) ? 1 : 0) + 1; + y = ((inlen + 7) >> 3) + 1; out[x++] = 0x03; if (y < 128) { diff --git a/src/pk/asn1/der/bit/der_encode_raw_bit_string.c b/src/pk/asn1/der/bit/der_encode_raw_bit_string.c index 298c4e369..4101a1da6 100644 --- a/src/pk/asn1/der/bit/der_encode_raw_bit_string.c +++ b/src/pk/asn1/der/bit/der_encode_raw_bit_string.c @@ -49,7 +49,7 @@ int der_encode_raw_bit_string(const unsigned char *in, unsigned long inlen, /* store header (include bit padding count in length) */ x = 0; - y = (inlen >> 3) + ((inlen&7) ? 1 : 0) + 1; + y = ((inlen + 7) >> 3) + 1; out[x++] = 0x03; if (y < 128) { From 35c4d157d0455615a3528ef7b31a84b2f1239191 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 7 Dec 2017 13:23:38 +0100 Subject: [PATCH 12/12] as of POSIX.1-2008 gettimeofday() is obsolete --- tests/test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test.c b/tests/test.c index 16cbb4fbb..9ed6850bb 100644 --- a/tests/test.c +++ b/tests/test.c @@ -72,9 +72,9 @@ static ulong64 epoch_usec(void) cur_time /= 10; /* nanoseconds > microseconds */ return cur_time; #else - struct timeval tv; - gettimeofday(&tv, NULL); - return (ulong64)(tv.tv_sec) * 1000000 + (ulong64)(tv.tv_usec); /* get microseconds */ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (ulong64)(ts.tv_sec) * 1000000 + (ulong64)(ts.tv_nsec) / 1000; /* get microseconds */ #endif }