diff options
| author | jsing <> | 2023-04-12 04:54:16 +0000 |
|---|---|---|
| committer | jsing <> | 2023-04-12 04:54:16 +0000 |
| commit | df53803271f666cca4371636e989aa3c43db7649 (patch) | |
| tree | 71be9c2306d6ac3d5d004e512e05bf07782c26a6 /src/lib/libcrypto/crypto_internal.h | |
| parent | e4e955e54a109e3d9721a1aea29d3ca7c7d0c065 (diff) | |
| download | openbsd-df53803271f666cca4371636e989aa3c43db7649.tar.gz openbsd-df53803271f666cca4371636e989aa3c43db7649.tar.bz2 openbsd-df53803271f666cca4371636e989aa3c43db7649.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/crypto_internal.h')
| -rw-r--r-- | src/lib/libcrypto/crypto_internal.h | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/lib/libcrypto/crypto_internal.h b/src/lib/libcrypto/crypto_internal.h index af2a87216e..fa1dc504f7 100644 --- a/src/lib/libcrypto/crypto_internal.h +++ b/src/lib/libcrypto/crypto_internal.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: crypto_internal.h,v 1.1 2023/04/12 04:40:39 jsing Exp $ */ | 1 | /* $OpenBSD: crypto_internal.h,v 1.2 2023/04/12 04:54:15 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -31,4 +31,36 @@ crypto_store_htobe64(uint8_t *dst, uint64_t v) | |||
| 31 | } | 31 | } |
| 32 | #endif | 32 | #endif |
| 33 | 33 | ||
| 34 | #ifndef HAVE_CRYPTO_ROL_U32 | ||
| 35 | static inline uint32_t | ||
| 36 | crypto_rol_u32(uint32_t v, size_t shift) | ||
| 37 | { | ||
| 38 | return (v << shift) | (v >> (32 - shift)); | ||
| 39 | } | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #ifndef HAVE_CRYPTO_ROR_U32 | ||
| 43 | static inline uint32_t | ||
| 44 | crypto_ror_u32(uint32_t v, size_t shift) | ||
| 45 | { | ||
| 46 | return (v << (32 - shift)) | (v >> shift); | ||
| 47 | } | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #ifndef HAVE_CRYPTO_ROL_U64 | ||
| 51 | static inline uint64_t | ||
| 52 | crypto_rol_u64(uint64_t v, size_t shift) | ||
| 53 | { | ||
| 54 | return (v << shift) | (v >> (64 - shift)); | ||
| 55 | } | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #ifndef HAVE_CRYPTO_ROR_U64 | ||
| 59 | static inline uint64_t | ||
| 60 | crypto_ror_u64(uint64_t v, size_t shift) | ||
| 61 | { | ||
| 62 | return (v << (64 - shift)) | (v >> shift); | ||
| 63 | } | ||
| 64 | #endif | ||
| 65 | |||
| 34 | #endif | 66 | #endif |
