From 561fe83532aa2a1e612c49ccca890d4db5180b7a Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 4 Mar 2014 21:42:29 +0100 Subject: [PATCH 1/6] fix strict-aliasing compiler warnings --- src/headers/tomcrypt_cfg.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/headers/tomcrypt_cfg.h b/src/headers/tomcrypt_cfg.h index c797cf8..d573580 100644 --- a/src/headers/tomcrypt_cfg.h +++ b/src/headers/tomcrypt_cfg.h @@ -60,7 +60,6 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); #define ENDIAN_LITTLE #define ENDIAN_32BITWORD #define LTC_FAST - #define LTC_FAST_TYPE unsigned long #endif /* detects MIPS R5900 processors (PS2) */ @@ -74,7 +73,6 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); #define ENDIAN_LITTLE #define ENDIAN_64BITWORD #define LTC_FAST - #define LTC_FAST_TYPE unsigned long #endif /* detect PPC32 */ @@ -82,9 +80,16 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); #define ENDIAN_BIG #define ENDIAN_32BITWORD #define LTC_FAST - #define LTC_FAST_TYPE unsigned long #endif +#ifdef LTC_FAST +#if __GNUC__ < 4 /* if the compiler does not support gnu extensions, i.e. its neither clang nor gcc */ +#error the LTC_FAST hack is only available on compilers that support __attribute__((may_alias)) - disable it for your compiler, and dont worry, it won`t buy you much anyway +#else +typedef unsigned int __attribute__((__may_alias__)) LTC_FAST_TYPE; +#endif +#endif /* LTC_FAST */ + /* detect sparc and sparc64 */ #if defined(__sparc__) #define ENDIAN_BIG From e027dda26f5ad71d3d033e23e844f542d26fde71 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 12 Mar 2014 10:53:23 +0200 Subject: [PATCH 2/6] travis: add "after_failure" section --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5f6fe2b..3ac670b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,9 @@ branches: - develop before_script: - sudo apt-get install libtommath-dev +after_failure: + - cat test_std.txt + - cat test_err.txt after_script: - cat gcc_2.txt notifications: From 1f7cf9dc0b0128147337529ee345f9dbe9047326 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 3 Apr 2014 15:05:56 +0200 Subject: [PATCH 3/6] move typedefs from tomcrypt_macros.h to tomcrypt_cfg.h --- src/headers/tomcrypt_cfg.h | 18 ++++++++++++++++++ src/headers/tomcrypt_macros.h | 17 ----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/headers/tomcrypt_cfg.h b/src/headers/tomcrypt_cfg.h index d573580..82be01b 100644 --- a/src/headers/tomcrypt_cfg.h +++ b/src/headers/tomcrypt_cfg.h @@ -90,6 +90,24 @@ typedef unsigned int __attribute__((__may_alias__)) LTC_FAST_TYPE; #endif #endif /* LTC_FAST */ +/* fix for MSVC ...evil! */ +#ifdef _MSC_VER + #define CONST64(n) n ## ui64 + typedef unsigned __int64 ulong64; +#else + #define CONST64(n) n ## ULL + typedef unsigned long long ulong64; +#endif + +/* this is the "32-bit at least" data type + * Re-define it to suit your platform but it must be at least 32-bits + */ +#if defined(__x86_64__) || (defined(__sparc__) && defined(__arch64__)) + typedef unsigned ulong32; +#else + typedef unsigned long ulong32; +#endif + /* detect sparc and sparc64 */ #if defined(__sparc__) #define ENDIAN_BIG diff --git a/src/headers/tomcrypt_macros.h b/src/headers/tomcrypt_macros.h index d56764f..deea16c 100644 --- a/src/headers/tomcrypt_macros.h +++ b/src/headers/tomcrypt_macros.h @@ -1,20 +1,3 @@ -/* fix for MSVC ...evil! */ -#ifdef _MSC_VER - #define CONST64(n) n ## ui64 - typedef unsigned __int64 ulong64; -#else - #define CONST64(n) n ## ULL - typedef unsigned long long ulong64; -#endif - -/* this is the "32-bit at least" data type - * Re-define it to suit your platform but it must be at least 32-bits - */ -#if defined(__x86_64__) || (defined(__sparc__) && defined(__arch64__)) - typedef unsigned ulong32; -#else - typedef unsigned long ulong32; -#endif /* ---- HELPER MACROS ---- */ #ifdef ENDIAN_NEUTRAL From 53f04b8e6b9cee1fbc213433f42d1c9e288cb65e Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 3 Apr 2014 15:06:56 +0200 Subject: [PATCH 4/6] only use ulong32 or ulong64 in the macros --- src/headers/tomcrypt_macros.h | 64 +++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/headers/tomcrypt_macros.h b/src/headers/tomcrypt_macros.h index deea16c..5a5f513 100644 --- a/src/headers/tomcrypt_macros.h +++ b/src/headers/tomcrypt_macros.h @@ -7,10 +7,10 @@ (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } #define LOAD32L(x, y) \ - { x = ((unsigned long)((y)[3] & 255)<<24) | \ - ((unsigned long)((y)[2] & 255)<<16) | \ - ((unsigned long)((y)[1] & 255)<<8) | \ - ((unsigned long)((y)[0] & 255)); } + { x = ((ulong32)((y)[3] & 255)<<24) | \ + ((ulong32)((y)[2] & 255)<<16) | \ + ((ulong32)((y)[1] & 255)<<8) | \ + ((ulong32)((y)[0] & 255)); } #define STORE64L(x, y) \ { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \ @@ -29,10 +29,10 @@ (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); } #define LOAD32H(x, y) \ - { x = ((unsigned long)((y)[0] & 255)<<24) | \ - ((unsigned long)((y)[1] & 255)<<16) | \ - ((unsigned long)((y)[2] & 255)<<8) | \ - ((unsigned long)((y)[3] & 255)); } + { x = ((ulong32)((y)[0] & 255)<<24) | \ + ((ulong32)((y)[1] & 255)<<16) | \ + ((ulong32)((y)[2] & 255)<<8) | \ + ((ulong32)((y)[3] & 255)); } #define STORE64H(x, y) \ { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \ @@ -82,10 +82,10 @@ asm __volatile__ ( \ (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); } #define LOAD32H(x, y) \ - { x = ((unsigned long)((y)[0] & 255)<<24) | \ - ((unsigned long)((y)[1] & 255)<<16) | \ - ((unsigned long)((y)[2] & 255)<<8) | \ - ((unsigned long)((y)[3] & 255)); } + { x = ((ulong32)((y)[0] & 255)<<24) | \ + ((ulong32)((y)[1] & 255)<<16) | \ + ((ulong32)((y)[2] & 255)<<8) | \ + ((ulong32)((y)[3] & 255)); } #endif @@ -175,10 +175,10 @@ asm __volatile__ ( \ (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } #define LOAD32L(x, y) \ - { x = ((unsigned long)((y)[3] & 255)<<24) | \ - ((unsigned long)((y)[2] & 255)<<16) | \ - ((unsigned long)((y)[1] & 255)<<8) | \ - ((unsigned long)((y)[0] & 255)); } + { x = ((ulong32)((y)[3] & 255)<<24) | \ + ((ulong32)((y)[2] & 255)<<16) | \ + ((ulong32)((y)[1] & 255)<<8) | \ + ((ulong32)((y)[0] & 255)); } #define STORE64L(x, y) \ { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \ @@ -246,7 +246,7 @@ asm __volatile__ ( \ #elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM) -static inline unsigned ROL(unsigned word, int i) +static inline ulong32 ROL(ulong32 word, int i) { asm ("roll %%cl,%0" :"=r" (word) @@ -254,7 +254,7 @@ static inline unsigned ROL(unsigned word, int i) return word; } -static inline unsigned ROR(unsigned word, int i) +static inline ulong32 ROR(ulong32 word, int i) { asm ("rorl %%cl,%0" :"=r" (word) @@ -264,7 +264,7 @@ static inline unsigned ROR(unsigned word, int i) #ifndef LTC_NO_ROLC -static inline unsigned ROLc(unsigned word, const int i) +static inline ulong32 ROLc(ulong32 word, const int i) { asm ("roll %2,%0" :"=r" (word) @@ -272,7 +272,7 @@ static inline unsigned ROLc(unsigned word, const int i) return word; } -static inline unsigned RORc(unsigned word, const int i) +static inline ulong32 RORc(ulong32 word, const int i) { asm ("rorl %2,%0" :"=r" (word) @@ -289,7 +289,7 @@ static inline unsigned RORc(unsigned word, const int i) #elif !defined(__STRICT_ANSI__) && defined(LTC_PPC32) -static inline unsigned ROL(unsigned word, int i) +static inline ulong32 ROL(ulong32 word, int i) { asm ("rotlw %0,%0,%2" :"=r" (word) @@ -297,7 +297,7 @@ static inline unsigned ROL(unsigned word, int i) return word; } -static inline unsigned ROR(unsigned word, int i) +static inline ulong32 ROR(ulong32 word, int i) { asm ("rotlw %0,%0,%2" :"=r" (word) @@ -307,7 +307,7 @@ static inline unsigned ROR(unsigned word, int i) #ifndef LTC_NO_ROLC -static inline unsigned ROLc(unsigned word, const int i) +static inline ulong32 ROLc(ulong32 word, const int i) { asm ("rotlwi %0,%0,%2" :"=r" (word) @@ -315,7 +315,7 @@ static inline unsigned ROLc(unsigned word, const int i) return word; } -static inline unsigned RORc(unsigned word, const int i) +static inline ulong32 RORc(ulong32 word, const int i) { asm ("rotrwi %0,%0,%2" :"=r" (word) @@ -334,10 +334,10 @@ static inline unsigned RORc(unsigned word, const int i) #else /* rotates the hard way */ -#define ROL(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL) -#define ROR(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL) -#define ROLc(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL) -#define RORc(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL) +#define ROL(x, y) ( (((ulong32)(x)<<(ulong32)((y)&31)) | (((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)(32-((y)&31)))) & 0xFFFFFFFFUL) +#define ROR(x, y) ( ((((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)((y)&31)) | ((ulong32)(x)<<(ulong32)(32-((y)&31)))) & 0xFFFFFFFFUL) +#define ROLc(x, y) ( (((ulong32)(x)<<(ulong32)((y)&31)) | (((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)(32-((y)&31)))) & 0xFFFFFFFFUL) +#define RORc(x, y) ( ((((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)((y)&31)) | ((ulong32)(x)<<(ulong32)(32-((y)&31)))) & 0xFFFFFFFFUL) #endif @@ -345,7 +345,7 @@ static inline unsigned RORc(unsigned word, const int i) /* 64-bit Rotates */ #if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__x86_64__) && !defined(LTC_NO_ASM) -static inline unsigned long ROL64(unsigned long word, int i) +static inline ulong64 ROL64(ulong64 word, int i) { asm("rolq %%cl,%0" :"=r" (word) @@ -353,7 +353,7 @@ static inline unsigned long ROL64(unsigned long word, int i) return word; } -static inline unsigned long ROR64(unsigned long word, int i) +static inline ulong64 ROR64(ulong64 word, int i) { asm("rorq %%cl,%0" :"=r" (word) @@ -363,7 +363,7 @@ static inline unsigned long ROR64(unsigned long word, int i) #ifndef LTC_NO_ROLC -static inline unsigned long ROL64c(unsigned long word, const int i) +static inline ulong64 ROL64c(ulong64 word, const int i) { asm("rolq %2,%0" :"=r" (word) @@ -371,7 +371,7 @@ static inline unsigned long ROL64c(unsigned long word, const int i) return word; } -static inline unsigned long ROR64c(unsigned long word, const int i) +static inline ulong64 ROR64c(ulong64 word, const int i) { asm("rorq %2,%0" :"=r" (word) From 68bfdd0fac9a48c080cca3e4efab328360d47e2c Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 3 Apr 2014 15:08:17 +0200 Subject: [PATCH 5/6] move mac_test() before modes_test() since lrw uses gcm it makes sense to fail already at gcm --- demos/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/test.c b/demos/test.c index 0d26b95..e9c9a90 100644 --- a/demos/test.c +++ b/demos/test.c @@ -20,9 +20,9 @@ int main(void) printf("\nstore_test...."); fflush(stdout); x = store_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\nmisc_test...."); fflush(stdout); x = misc_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\ncipher_test..."); fflush(stdout); x = cipher_hash_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); + printf("\nmac_test......"); fflush(stdout); x = mac_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\nmodes_test...."); fflush(stdout); x = modes_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\nder_test......"); fflush(stdout); x = der_tests(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); - printf("\nmac_test......"); fflush(stdout); x = mac_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\npkcs_1_test..."); fflush(stdout); x = pkcs_1_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\nrsa_test......"); fflush(stdout); x = rsa_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\ndh_test......."); fflush(stdout); x = dh_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); From ffeb70b48a13ef5b669ab5b5b6238392efcb5bd2 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 3 Apr 2014 22:22:01 +0200 Subject: [PATCH 6/6] fix typedef of LTC_FAST_TYPE on x86_64 --- src/headers/tomcrypt_cfg.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/headers/tomcrypt_cfg.h b/src/headers/tomcrypt_cfg.h index 82be01b..8b06b14 100644 --- a/src/headers/tomcrypt_cfg.h +++ b/src/headers/tomcrypt_cfg.h @@ -82,14 +82,6 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); #define LTC_FAST #endif -#ifdef LTC_FAST -#if __GNUC__ < 4 /* if the compiler does not support gnu extensions, i.e. its neither clang nor gcc */ -#error the LTC_FAST hack is only available on compilers that support __attribute__((may_alias)) - disable it for your compiler, and dont worry, it won`t buy you much anyway -#else -typedef unsigned int __attribute__((__may_alias__)) LTC_FAST_TYPE; -#endif -#endif /* LTC_FAST */ - /* fix for MSVC ...evil! */ #ifdef _MSC_VER #define CONST64(n) n ## ui64 @@ -108,6 +100,18 @@ typedef unsigned int __attribute__((__may_alias__)) LTC_FAST_TYPE; typedef unsigned long ulong32; #endif +#ifdef LTC_FAST +#if __GNUC__ < 4 /* if the compiler does not support gnu extensions, i.e. its neither clang nor gcc */ +#error the LTC_FAST hack is only available on compilers that support __attribute__((may_alias)) - disable it for your compiler, and dont worry, it won`t buy you much anyway +#else +#ifdef ENDIAN_64BITWORD +typedef ulong64 __attribute__((__may_alias__)) LTC_FAST_TYPE; +#else +typedef ulong32 __attribute__((__may_alias__)) LTC_FAST_TYPE; +#endif +#endif +#endif /* LTC_FAST */ + /* detect sparc and sparc64 */ #if defined(__sparc__) #define ENDIAN_BIG