summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto_internal.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/crypto_internal.h55
1 files changed, 46 insertions, 9 deletions
diff --git a/src/lib/libcrypto/crypto_internal.h b/src/lib/libcrypto/crypto_internal.h
index 24a06256db..2e6ab82692 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.3 2023/04/14 10:42:51 jsing Exp $ */ 1/* $OpenBSD: crypto_internal.h,v 1.4 2023/05/17 06:37:14 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,14 +22,34 @@
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
34static inline uint32_t
35crypto_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
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
31static inline void 51static inline void
32crypto_store_htobe32(uint8_t *dst, uint32_t v) 52crypto_store_htobe32(void *dst, uint32_t v)
33{ 53{
34 v = htobe32(v); 54 v = htobe32(v);
35 memcpy(dst, &v, sizeof(v)); 55 memcpy(dst, &v, sizeof(v));
@@ -37,13 +57,30 @@ 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
65static inline uint64_t
66crypto_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.
43 */ 80 */
44#ifndef HAVE_CRYPTO_STORE_HTOBE64 81#ifndef HAVE_CRYPTO_STORE_HTOBE64
45static inline void 82static inline void
46crypto_store_htobe64(uint8_t *dst, uint64_t v) 83crypto_store_htobe64(void *dst, uint64_t v)
47{ 84{
48 v = htobe64(v); 85 v = htobe64(v);
49 memcpy(dst, &v, sizeof(v)); 86 memcpy(dst, &v, sizeof(v));