From 1a1fa9f0d7ff940ecfbf5e78d0cdbcd33b5e08b7 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Tue, 14 Feb 2023 17:58:26 +0000 Subject: 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@ --- src/lib/libcrypto/bn/bn_internal.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src') 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 @@ -/* $OpenBSD: bn_internal.h,v 1.1 2023/01/31 05:48:39 jsing Exp $ */ +/* $OpenBSD: bn_internal.h,v 1.2 2023/02/14 17:58:26 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -22,6 +22,38 @@ #ifndef HEADER_BN_INTERNAL_H #define HEADER_BN_INTERNAL_H +#ifndef HAVE_BN_CT_NE_ZERO +static inline int +bn_ct_ne_zero(BN_ULONG w) +{ + return (w | ~(w - 1)) >> (BN_BITS2 - 1); +} +#endif + +#ifndef HAVE_BN_CT_NE_ZERO_MASK +static inline BN_ULONG +bn_ct_ne_zero_mask(BN_ULONG w) +{ + return 0 - bn_ct_ne_zero(w); +} +#endif + +#ifndef HAVE_BN_CT_EQ_ZERO +static inline int +bn_ct_eq_zero(BN_ULONG w) +{ + return 1 - bn_ct_ne_zero(w); +} +#endif + +#ifndef HAVE_BN_CT_EQ_ZERO_MASK +static inline BN_ULONG +bn_ct_eq_zero_mask(BN_ULONG w) +{ + return 0 - bn_ct_eq_zero(w); +} +#endif + #ifndef HAVE_BN_UMUL_HILO #ifdef BN_LLONG static inline void -- cgit v1.2.3-55-g6feb