diff options
| author | bcook <> | 2014-08-18 19:15:34 +0000 |
|---|---|---|
| committer | bcook <> | 2014-08-18 19:15:34 +0000 |
| commit | 14d7e512f02ca19b08bb321eadc6d6490ae21f11 (patch) | |
| tree | 7d07556e432d7fe68487ffbfe2b3e4e748b4c680 | |
| parent | e69e6c520df1c38ea3e6925c74ab03a4b4984068 (diff) | |
| download | openbsd-14d7e512f02ca19b08bb321eadc6d6490ae21f11.tar.gz openbsd-14d7e512f02ca19b08bb321eadc6d6490ae21f11.tar.bz2 openbsd-14d7e512f02ca19b08bb321eadc6d6490ae21f11.zip | |
replace more ROTATE macros with plain-old C code.
Let the compiler optimize these. Even older versions of gcc generate
equal or better quality code than the inline asm.
ok miod@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/des/des_locl.h | 21 | ||||
| -rw-r--r-- | src/lib/libcrypto/rc5/rc5_locl.h | 38 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/des/des_locl.h | 21 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/rc5/rc5_locl.h | 38 |
4 files changed, 38 insertions, 80 deletions
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h index 477aeb60d9..9480d37489 100644 --- a/src/lib/libcrypto/des/des_locl.h +++ b/src/lib/libcrypto/des/des_locl.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: des_locl.h,v 1.16 2014/07/10 22:45:56 jsing Exp $ */ | 1 | /* $OpenBSD: des_locl.h,v 1.17 2014/08/18 19:15:34 bcook Exp $ */ |
| 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -60,6 +60,7 @@ | |||
| 60 | #define HEADER_DES_LOCL_H | 60 | #define HEADER_DES_LOCL_H |
| 61 | 61 | ||
| 62 | #include <math.h> | 62 | #include <math.h> |
| 63 | #include <stdint.h> | ||
| 63 | #include <stdio.h> | 64 | #include <stdio.h> |
| 64 | #include <stdlib.h> | 65 | #include <stdlib.h> |
| 65 | #include <string.h> | 66 | #include <string.h> |
| @@ -131,20 +132,10 @@ | |||
| 131 | } \ | 132 | } \ |
| 132 | } | 133 | } |
| 133 | 134 | ||
| 134 | #if defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | 135 | static inline uint32_t ROTATE(uint32_t a, uint32_t n) |
| 135 | # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | 136 | { |
| 136 | # define ROTATE(a,n) ({ register unsigned int ret; \ | 137 | return (a>>n)+(a<<(32-n)); |
| 137 | asm ("rorl %1,%0" \ | 138 | } |
| 138 | : "=r"(ret) \ | ||
| 139 | : "I"(n),"0"(a) \ | ||
| 140 | : "cc"); \ | ||
| 141 | ret; \ | ||
| 142 | }) | ||
| 143 | # endif | ||
| 144 | #endif | ||
| 145 | #ifndef ROTATE | ||
| 146 | #define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) | ||
| 147 | #endif | ||
| 148 | 139 | ||
| 149 | /* Don't worry about the LOAD_DATA() stuff, that is used by | 140 | /* Don't worry about the LOAD_DATA() stuff, that is used by |
| 150 | * fcrypt() to add it's little bit to the front */ | 141 | * fcrypt() to add it's little bit to the front */ |
diff --git a/src/lib/libcrypto/rc5/rc5_locl.h b/src/lib/libcrypto/rc5/rc5_locl.h index 07671decaa..d4e0d30eca 100644 --- a/src/lib/libcrypto/rc5/rc5_locl.h +++ b/src/lib/libcrypto/rc5/rc5_locl.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: rc5_locl.h,v 1.5 2014/07/10 22:45:57 jsing Exp $ */ | 1 | /* $OpenBSD: rc5_locl.h,v 1.6 2014/08/18 19:15:34 bcook Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -56,6 +56,7 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <stdint.h> | ||
| 59 | #include <stdlib.h> | 60 | #include <stdlib.h> |
| 60 | 61 | ||
| 61 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
| @@ -148,30 +149,17 @@ | |||
| 148 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | 149 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ |
| 149 | *((c)++)=(unsigned char)(((l) )&0xff)) | 150 | *((c)++)=(unsigned char)(((l) )&0xff)) |
| 150 | 151 | ||
| 151 | #if defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | 152 | static inline uint32_t ROTATE_l32(uint32_t a, uint32_t n) |
| 152 | # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | 153 | { |
| 153 | # define ROTATE_l32(a,n) ({ register unsigned int ret; \ | 154 | uint32_t amt = n & 0x1f; |
| 154 | asm ("roll %%cl,%0" \ | 155 | return (a << amt) | (a >> (32 - amt)); |
| 155 | : "=r"(ret) \ | 156 | } |
| 156 | : "c"(n),"0"((unsigned int)(a)) \ | 157 | |
| 157 | : "cc"); \ | 158 | static inline uint32_t ROTATE_r32(uint32_t a, uint32_t n) |
| 158 | ret; \ | 159 | { |
| 159 | }) | 160 | uint32_t amt = n & 0x1f; |
| 160 | # define ROTATE_r32(a,n) ({ register unsigned int ret; \ | 161 | return (a << (32 - amt)) | (a >> amt); |
| 161 | asm ("rorl %%cl,%0" \ | 162 | } |
| 162 | : "=r"(ret) \ | ||
| 163 | : "c"(n),"0"((unsigned int)(a)) \ | ||
| 164 | : "cc"); \ | ||
| 165 | ret; \ | ||
| 166 | }) | ||
| 167 | # endif | ||
| 168 | #endif | ||
| 169 | #ifndef ROTATE_l32 | ||
| 170 | #define ROTATE_l32(a,n) (((a)<<(n&0x1f))|(((a)&0xffffffff)>>(32-(n&0x1f)))) | ||
| 171 | #endif | ||
| 172 | #ifndef ROTATE_r32 | ||
| 173 | #define ROTATE_r32(a,n) (((a)<<(32-(n&0x1f)))|(((a)&0xffffffff)>>(n&0x1f))) | ||
| 174 | #endif | ||
| 175 | 163 | ||
| 176 | #define RC5_32_MASK 0xffffffffL | 164 | #define RC5_32_MASK 0xffffffffL |
| 177 | 165 | ||
diff --git a/src/lib/libssl/src/crypto/des/des_locl.h b/src/lib/libssl/src/crypto/des/des_locl.h index 477aeb60d9..9480d37489 100644 --- a/src/lib/libssl/src/crypto/des/des_locl.h +++ b/src/lib/libssl/src/crypto/des/des_locl.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: des_locl.h,v 1.16 2014/07/10 22:45:56 jsing Exp $ */ | 1 | /* $OpenBSD: des_locl.h,v 1.17 2014/08/18 19:15:34 bcook Exp $ */ |
| 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -60,6 +60,7 @@ | |||
| 60 | #define HEADER_DES_LOCL_H | 60 | #define HEADER_DES_LOCL_H |
| 61 | 61 | ||
| 62 | #include <math.h> | 62 | #include <math.h> |
| 63 | #include <stdint.h> | ||
| 63 | #include <stdio.h> | 64 | #include <stdio.h> |
| 64 | #include <stdlib.h> | 65 | #include <stdlib.h> |
| 65 | #include <string.h> | 66 | #include <string.h> |
| @@ -131,20 +132,10 @@ | |||
| 131 | } \ | 132 | } \ |
| 132 | } | 133 | } |
| 133 | 134 | ||
| 134 | #if defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | 135 | static inline uint32_t ROTATE(uint32_t a, uint32_t n) |
| 135 | # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | 136 | { |
| 136 | # define ROTATE(a,n) ({ register unsigned int ret; \ | 137 | return (a>>n)+(a<<(32-n)); |
| 137 | asm ("rorl %1,%0" \ | 138 | } |
| 138 | : "=r"(ret) \ | ||
| 139 | : "I"(n),"0"(a) \ | ||
| 140 | : "cc"); \ | ||
| 141 | ret; \ | ||
| 142 | }) | ||
| 143 | # endif | ||
| 144 | #endif | ||
| 145 | #ifndef ROTATE | ||
| 146 | #define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) | ||
| 147 | #endif | ||
| 148 | 139 | ||
| 149 | /* Don't worry about the LOAD_DATA() stuff, that is used by | 140 | /* Don't worry about the LOAD_DATA() stuff, that is used by |
| 150 | * fcrypt() to add it's little bit to the front */ | 141 | * fcrypt() to add it's little bit to the front */ |
diff --git a/src/lib/libssl/src/crypto/rc5/rc5_locl.h b/src/lib/libssl/src/crypto/rc5/rc5_locl.h index 07671decaa..d4e0d30eca 100644 --- a/src/lib/libssl/src/crypto/rc5/rc5_locl.h +++ b/src/lib/libssl/src/crypto/rc5/rc5_locl.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: rc5_locl.h,v 1.5 2014/07/10 22:45:57 jsing Exp $ */ | 1 | /* $OpenBSD: rc5_locl.h,v 1.6 2014/08/18 19:15:34 bcook Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -56,6 +56,7 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <stdint.h> | ||
| 59 | #include <stdlib.h> | 60 | #include <stdlib.h> |
| 60 | 61 | ||
| 61 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
| @@ -148,30 +149,17 @@ | |||
| 148 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | 149 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ |
| 149 | *((c)++)=(unsigned char)(((l) )&0xff)) | 150 | *((c)++)=(unsigned char)(((l) )&0xff)) |
| 150 | 151 | ||
| 151 | #if defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | 152 | static inline uint32_t ROTATE_l32(uint32_t a, uint32_t n) |
| 152 | # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | 153 | { |
| 153 | # define ROTATE_l32(a,n) ({ register unsigned int ret; \ | 154 | uint32_t amt = n & 0x1f; |
| 154 | asm ("roll %%cl,%0" \ | 155 | return (a << amt) | (a >> (32 - amt)); |
| 155 | : "=r"(ret) \ | 156 | } |
| 156 | : "c"(n),"0"((unsigned int)(a)) \ | 157 | |
| 157 | : "cc"); \ | 158 | static inline uint32_t ROTATE_r32(uint32_t a, uint32_t n) |
| 158 | ret; \ | 159 | { |
| 159 | }) | 160 | uint32_t amt = n & 0x1f; |
| 160 | # define ROTATE_r32(a,n) ({ register unsigned int ret; \ | 161 | return (a << (32 - amt)) | (a >> amt); |
| 161 | asm ("rorl %%cl,%0" \ | 162 | } |
| 162 | : "=r"(ret) \ | ||
| 163 | : "c"(n),"0"((unsigned int)(a)) \ | ||
| 164 | : "cc"); \ | ||
| 165 | ret; \ | ||
| 166 | }) | ||
| 167 | # endif | ||
| 168 | #endif | ||
| 169 | #ifndef ROTATE_l32 | ||
| 170 | #define ROTATE_l32(a,n) (((a)<<(n&0x1f))|(((a)&0xffffffff)>>(32-(n&0x1f)))) | ||
| 171 | #endif | ||
| 172 | #ifndef ROTATE_r32 | ||
| 173 | #define ROTATE_r32(a,n) (((a)<<(32-(n&0x1f)))|(((a)&0xffffffff)>>(n&0x1f))) | ||
| 174 | #endif | ||
| 175 | 163 | ||
| 176 | #define RC5_32_MASK 0xffffffffL | 164 | #define RC5_32_MASK 0xffffffffL |
| 177 | 165 | ||
