diff options
Diffstat (limited to 'src/lib/libcrypto/crypto_internal.h')
-rw-r--r-- | src/lib/libcrypto/crypto_internal.h | 55 |
1 files changed, 9 insertions, 46 deletions
diff --git a/src/lib/libcrypto/crypto_internal.h b/src/lib/libcrypto/crypto_internal.h index 2e6ab82692..db3e99510b 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.4 2023/05/17 06:37:14 jsing Exp $ */ | 1 | /* $OpenBSD: crypto_internal.h,v 1.5 2023/05/19 00:54:27 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -22,34 +22,14 @@ | |||
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 void *src) | ||
36 | { | ||
37 | uint32_t v; | ||
38 | |||
39 | memcpy(&v, src, sizeof(v)); | ||
40 | |||
41 | return be32toh(v); | ||
42 | } | ||
43 | #endif | ||
44 | |||
45 | /* | 25 | /* |
46 | * crypto_store_htobe32() stores a 32 bit unsigned host endian value as a 32 bit | 26 | * crypto_store_htobe32() stores a 32 bit unsigned host endian value |
47 | * unsigned big endian value, at the specified address in memory. The memory | 27 | * as a 32 bit unsigned big endian value, at the specified location in |
48 | * address may have any alignment. | 28 | * memory. The memory location may have any alignment. |
49 | */ | 29 | */ |
50 | #ifndef HAVE_CRYPTO_STORE_HTOBE32 | 30 | #ifndef HAVE_CRYPTO_STORE_HTOBE32 |
51 | static inline void | 31 | static inline void |
52 | crypto_store_htobe32(void *dst, uint32_t v) | 32 | crypto_store_htobe32(uint8_t *dst, uint32_t v) |
53 | { | 33 | { |
54 | v = htobe32(v); | 34 | v = htobe32(v); |
55 | memcpy(dst, &v, sizeof(v)); | 35 | memcpy(dst, &v, sizeof(v)); |
@@ -57,30 +37,13 @@ crypto_store_htobe32(void *dst, uint32_t v) | |||
57 | #endif | 37 | #endif |
58 | 38 | ||
59 | /* | 39 | /* |
60 | * crypto_load_be64toh() loads a 64 bit unsigned big endian value as a 64 bit | 40 | * crypto_store_htobe64() stores a 64 bit unsigned host endian value |
61 | * unsigned host endian value, from the specified address in memory. The memory | 41 | * as a 64 bit unsigned big endian value, at the specified location in |
62 | * address may have any alignment. | 42 | * memory. The memory location may have any alignment. |
63 | */ | ||
64 | #ifndef HAVE_CRYPTO_LOAD_BE64TOH | ||
65 | static inline uint64_t | ||
66 | crypto_load_be64toh(const void *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. | ||
80 | */ | 43 | */ |
81 | #ifndef HAVE_CRYPTO_STORE_HTOBE64 | 44 | #ifndef HAVE_CRYPTO_STORE_HTOBE64 |
82 | static inline void | 45 | static inline void |
83 | crypto_store_htobe64(void *dst, uint64_t v) | 46 | crypto_store_htobe64(uint8_t *dst, uint64_t v) |
84 | { | 47 | { |
85 | v = htobe64(v); | 48 | v = htobe64(v); |
86 | memcpy(dst, &v, sizeof(v)); | 49 | memcpy(dst, &v, sizeof(v)); |