diff options
author | jsing <> | 2023-02-14 17:58:26 +0000 |
---|---|---|
committer | jsing <> | 2023-02-14 17:58:26 +0000 |
commit | 1a1fa9f0d7ff940ecfbf5e78d0cdbcd33b5e08b7 (patch) | |
tree | 758db4297e98603ab9faa07de6b5f11c27fc8d29 /src | |
parent | f9781f3238cbce0490220a33ae5ab7896fc771d0 (diff) | |
download | openbsd-1a1fa9f0d7ff940ecfbf5e78d0cdbcd33b5e08b7.tar.gz openbsd-1a1fa9f0d7ff940ecfbf5e78d0cdbcd33b5e08b7.tar.bz2 openbsd-1a1fa9f0d7ff940ecfbf5e78d0cdbcd33b5e08b7.zip |
Provide bn_ct_{eq,ne}_zero{,_mask}() inline functions.
These will be used to test a BN_ULONG in cases where constant time style
behaviour is required.
ok tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_internal.h | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bn/bn_internal.h b/src/lib/libcrypto/bn/bn_internal.h index de5cd22424..003d8cac2d 100644 --- a/src/lib/libcrypto/bn/bn_internal.h +++ b/src/lib/libcrypto/bn/bn_internal.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_internal.h,v 1.1 2023/01/31 05:48:39 jsing Exp $ */ | 1 | /* $OpenBSD: bn_internal.h,v 1.2 2023/02/14 17:58:26 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,6 +22,38 @@ | |||
22 | #ifndef HEADER_BN_INTERNAL_H | 22 | #ifndef HEADER_BN_INTERNAL_H |
23 | #define HEADER_BN_INTERNAL_H | 23 | #define HEADER_BN_INTERNAL_H |
24 | 24 | ||
25 | #ifndef HAVE_BN_CT_NE_ZERO | ||
26 | static inline int | ||
27 | bn_ct_ne_zero(BN_ULONG w) | ||
28 | { | ||
29 | return (w | ~(w - 1)) >> (BN_BITS2 - 1); | ||
30 | } | ||
31 | #endif | ||
32 | |||
33 | #ifndef HAVE_BN_CT_NE_ZERO_MASK | ||
34 | static inline BN_ULONG | ||
35 | bn_ct_ne_zero_mask(BN_ULONG w) | ||
36 | { | ||
37 | return 0 - bn_ct_ne_zero(w); | ||
38 | } | ||
39 | #endif | ||
40 | |||
41 | #ifndef HAVE_BN_CT_EQ_ZERO | ||
42 | static inline int | ||
43 | bn_ct_eq_zero(BN_ULONG w) | ||
44 | { | ||
45 | return 1 - bn_ct_ne_zero(w); | ||
46 | } | ||
47 | #endif | ||
48 | |||
49 | #ifndef HAVE_BN_CT_EQ_ZERO_MASK | ||
50 | static inline BN_ULONG | ||
51 | bn_ct_eq_zero_mask(BN_ULONG w) | ||
52 | { | ||
53 | return 0 - bn_ct_eq_zero(w); | ||
54 | } | ||
55 | #endif | ||
56 | |||
25 | #ifndef HAVE_BN_UMUL_HILO | 57 | #ifndef HAVE_BN_UMUL_HILO |
26 | #ifdef BN_LLONG | 58 | #ifdef BN_LLONG |
27 | static inline void | 59 | static inline void |