diff options
author | jsing <> | 2023-04-12 04:54:16 +0000 |
---|---|---|
committer | jsing <> | 2023-04-12 04:54:16 +0000 |
commit | 0639a12b364c61132014c0052e54345f2de59568 (patch) | |
tree | 71be9c2306d6ac3d5d004e512e05bf07782c26a6 /src/lib/libcrypto/md32_common.h | |
parent | a9c434936ce2a17263afcfb92d37ece5fd9b1220 (diff) | |
download | openbsd-0639a12b364c61132014c0052e54345f2de59568.tar.gz openbsd-0639a12b364c61132014c0052e54345f2de59568.tar.bz2 openbsd-0639a12b364c61132014c0052e54345f2de59568.zip |
Provide and use crypto_ro{l,r}_u{32,64}().
Various code in libcrypto needs bitwise rotation - rather than defining
different versions across the code base, provide a common set that can
be reused. Any sensible compiler optimises these to a single instruction
where the architecture supports it, which means we can ditch the inline
assembly.
On the chance that we need to provide a platform specific versions, this
follows the approach used in BN where a MD crypto_arch.h header could be
added in the future, which would then provide more specific versions of
these functions.
ok tb@
Diffstat (limited to 'src/lib/libcrypto/md32_common.h')
-rw-r--r-- | src/lib/libcrypto/md32_common.h | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h index a8b0d9ab74..cce4cfb0f7 100644 --- a/src/lib/libcrypto/md32_common.h +++ b/src/lib/libcrypto/md32_common.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: md32_common.h,v 1.23 2022/12/26 07:18:50 jmc Exp $ */ | 1 | /* $OpenBSD: md32_common.h,v 1.24 2023/04/12 04:54:15 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -111,6 +111,8 @@ | |||
111 | 111 | ||
112 | #include <openssl/opensslconf.h> | 112 | #include <openssl/opensslconf.h> |
113 | 113 | ||
114 | #include "crypto_internal.h" | ||
115 | |||
114 | #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) | 116 | #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) |
115 | #error "DATA_ORDER must be defined!" | 117 | #error "DATA_ORDER must be defined!" |
116 | #endif | 118 | #endif |
@@ -139,15 +141,7 @@ | |||
139 | #error "HASH_BLOCK_DATA_ORDER must be defined!" | 141 | #error "HASH_BLOCK_DATA_ORDER must be defined!" |
140 | #endif | 142 | #endif |
141 | 143 | ||
142 | /* | 144 | #define ROTATE(a, n) crypto_rol_u32(a, n) |
143 | * This common idiom is recognized by the compiler and turned into a | ||
144 | * CPU-specific intrinsic as appropriate. | ||
145 | * e.g. GCC optimizes to roll on amd64 at -O0 | ||
146 | */ | ||
147 | static inline uint32_t ROTATE(uint32_t a, uint32_t n) | ||
148 | { | ||
149 | return (a<<n)|(a>>(32-n)); | ||
150 | } | ||
151 | 145 | ||
152 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | 146 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) |
153 | 147 | ||