summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/crypto_internal.h69
1 files changed, 68 insertions, 1 deletions
diff --git a/src/lib/libcrypto/crypto_internal.h b/src/lib/libcrypto/crypto_internal.h
index 924cf6db49..8229db2d68 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.9 2024/03/28 08:36:13 jsing Exp $ */ 1/* $OpenBSD: crypto_internal.h,v 1.10 2024/04/17 14:43:37 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -27,6 +27,73 @@
27 extern char _ctassert[(x) ? 1 : -1] __attribute__((__unused__)) 27 extern char _ctassert[(x) ? 1 : -1] __attribute__((__unused__))
28 28
29/* 29/*
30 * Constant time operations for uint8_t.
31 */
32#ifndef HAVE_CRYPTO_CT_NE_ZERO_U8
33static inline int
34crypto_ct_ne_zero_u8(uint8_t v)
35{
36 return (uint8_t)(v | ~(v - 1)) >> ((sizeof(v) * 8) - 1);
37}
38#endif
39
40#ifndef HAVE_CRYPTO_CT_NE_ZERO_MASK_U8
41static inline uint8_t
42crypto_ct_ne_zero_mask_u8(uint8_t v)
43{
44 return 0 - crypto_ct_ne_zero_u8(v);
45}
46#endif
47
48#ifndef HAVE_CRYPTO_CT_EQ_ZERO_U8
49static inline int
50crypto_ct_eq_zero_u8(uint8_t v)
51{
52 return 1 - crypto_ct_ne_zero_u8(v);
53}
54#endif
55
56#ifndef HAVE_CRYPTO_CT_EQ_ZERO_MASK_U8
57static inline uint8_t
58crypto_ct_eq_zero_mask_u8(uint8_t v)
59{
60 return 0 - crypto_ct_eq_zero_u8(v);
61}
62#endif
63
64#ifndef HAVE_CRYPTO_CT_NE_U8
65static inline int
66crypto_ct_ne_u8(uint8_t a, uint8_t b)
67{
68 return crypto_ct_ne_zero_u8(a - b);
69}
70#endif
71
72#ifndef HAVE_CRYPTO_CT_NE_MASK_U8
73static inline uint8_t
74crypto_ct_ne_mask_u8(uint8_t a, uint8_t b)
75{
76 return 0 - crypto_ct_ne_u8(a, b);
77}
78#endif
79
80#ifndef HAVE_CRYPTO_CT_EQ_U8
81static inline int
82crypto_ct_eq_u8(uint8_t a, uint8_t b)
83{
84 return crypto_ct_eq_zero_u8(a - b);
85}
86#endif
87
88#ifndef HAVE_CRYPTO_CT_EQ_MASK_U8
89static inline uint8_t
90crypto_ct_eq_mask_u8(uint8_t a, uint8_t b)
91{
92 return 0 - crypto_ct_eq_u8(a, b);
93}
94#endif
95
96/*
30 * crypto_load_be32toh() loads a 32 bit unsigned big endian value as a 32 bit 97 * crypto_load_be32toh() loads a 32 bit unsigned big endian value as a 32 bit
31 * unsigned host endian value, from the specified address in memory. The memory 98 * unsigned host endian value, from the specified address in memory. The memory
32 * address may have any alignment. 99 * address may have any alignment.