diff options
author | jsing <> | 2023-05-27 09:18:17 +0000 |
---|---|---|
committer | jsing <> | 2023-05-27 09:18:17 +0000 |
commit | 5a32256b8c814723cdf8b800d976a1cc155f50cd (patch) | |
tree | a08cff9b4e35549320f4459a98e3dfc282dbdb90 /src/lib/libcrypto/crypto_internal.h | |
parent | 554239a1a00c924c930a5c40df5b85d0b4c0e1a4 (diff) | |
download | openbsd-5a32256b8c814723cdf8b800d976a1cc155f50cd.tar.gz openbsd-5a32256b8c814723cdf8b800d976a1cc155f50cd.tar.bz2 openbsd-5a32256b8c814723cdf8b800d976a1cc155f50cd.zip |
Clean up alignment handling for SHA-512.
This recommits r1.37 of sha512.c, however uses uint8_t * instead of void *
for the crypto_load_* functions and primarily uses const uint8_t * to track
input, only casting to const SHA_LONG64 * once we know that it is suitably
aligned. This prevents the compiler from implying alignment based on type.
Tested by tb@ and deraadt@ on platforms with gcc and strict alignment.
ok tb@
Diffstat (limited to 'src/lib/libcrypto/crypto_internal.h')
-rw-r--r-- | src/lib/libcrypto/crypto_internal.h | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/src/lib/libcrypto/crypto_internal.h b/src/lib/libcrypto/crypto_internal.h index db3e99510b..4fe868e9a1 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.5 2023/05/19 00:54:27 deraadt Exp $ */ | 1 | /* $OpenBSD: crypto_internal.h,v 1.6 2023/05/27 09:18:17 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -22,10 +22,30 @@ | |||
22 | #ifndef HEADER_CRYPTO_INTERNAL_H | 22 | #ifndef HEADER_CRYPTO_INTERNAL_H |
23 | #define HEADER_CRYPTO_INTERNAL_H | 23 | #define HEADER_CRYPTO_INTERNAL_H |
24 | 24 | ||
25 | #define CTASSERT(x) \ | ||
26 | extern char _ctassert[(x) ? 1 : -1] __attribute__((__unused__)) | ||
27 | |||
28 | /* | ||
29 | * crypto_load_be32toh() loads a 32 bit unsigned big endian value as a 32 bit | ||
30 | * unsigned host endian value, from the specified address in memory. The memory | ||
31 | * address may have any alignment. | ||
32 | */ | ||
33 | #ifndef HAVE_CRYPTO_LOAD_BE32TOH | ||
34 | static inline uint32_t | ||
35 | crypto_load_be32toh(const uint8_t *src) | ||
36 | { | ||
37 | uint32_t v; | ||
38 | |||
39 | memcpy(&v, src, sizeof(v)); | ||
40 | |||
41 | return be32toh(v); | ||
42 | } | ||
43 | #endif | ||
44 | |||
25 | /* | 45 | /* |
26 | * crypto_store_htobe32() stores a 32 bit unsigned host endian value | 46 | * crypto_store_htobe32() stores a 32 bit unsigned host endian value as a 32 bit |
27 | * as a 32 bit unsigned big endian value, at the specified location in | 47 | * unsigned big endian value, at the specified address in memory. The memory |
28 | * memory. The memory location may have any alignment. | 48 | * address may have any alignment. |
29 | */ | 49 | */ |
30 | #ifndef HAVE_CRYPTO_STORE_HTOBE32 | 50 | #ifndef HAVE_CRYPTO_STORE_HTOBE32 |
31 | static inline void | 51 | static inline void |
@@ -37,9 +57,26 @@ crypto_store_htobe32(uint8_t *dst, uint32_t v) | |||
37 | #endif | 57 | #endif |
38 | 58 | ||
39 | /* | 59 | /* |
40 | * crypto_store_htobe64() stores a 64 bit unsigned host endian value | 60 | * crypto_load_be64toh() loads a 64 bit unsigned big endian value as a 64 bit |
41 | * as a 64 bit unsigned big endian value, at the specified location in | 61 | * unsigned host endian value, from the specified address in memory. The memory |
42 | * memory. The memory location may have any alignment. | 62 | * address may have any alignment. |
63 | */ | ||
64 | #ifndef HAVE_CRYPTO_LOAD_BE64TOH | ||
65 | static inline uint64_t | ||
66 | crypto_load_be64toh(const uint8_t *src) | ||
67 | { | ||
68 | uint64_t v; | ||
69 | |||
70 | memcpy(&v, src, sizeof(v)); | ||
71 | |||
72 | return be64toh(v); | ||
73 | } | ||
74 | #endif | ||
75 | |||
76 | /* | ||
77 | * crypto_store_htobe64() stores a 64 bit unsigned host endian value as a 64 bit | ||
78 | * unsigned big endian value, at the specified address in memory. The memory | ||
79 | * address may have any alignment. | ||
43 | */ | 80 | */ |
44 | #ifndef HAVE_CRYPTO_STORE_HTOBE64 | 81 | #ifndef HAVE_CRYPTO_STORE_HTOBE64 |
45 | static inline void | 82 | static inline void |