summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAndrew Golovashevich <tankist.scratch.p@gmail.com>2024-05-05 14:27:26 +0300
committerTomas Mraz <tomas@openssl.org>2024-05-15 13:37:48 +0200
commitaaa1bda7187c8d920cf9e426c2cf8ec7c1c65576 (patch)
tree5951432ff285f06fa34a518a4fc3fd230a6fd2a7 /include
parent5a0c92cf093b4f0aa65f4fdbff88d7bdc83491f3 (diff)
Optimizated calculation of shared power of 2 in bn_gcd
Reviewed-by: Paul Dale <ppzgs1@gmail.com> Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/24332)
Diffstat (limited to 'include')
-rw-r--r--include/internal/constant_time.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/internal/constant_time.h b/include/internal/constant_time.h
index f2572ded51..9ffa4399a3 100644
--- a/include/internal/constant_time.h
+++ b/include/internal/constant_time.h
@@ -141,6 +141,17 @@ static ossl_inline uint64_t constant_time_lt_64(uint64_t a, uint64_t b)
}
#ifdef BN_ULONG
+static ossl_inline BN_ULONG value_barrier_bn(BN_ULONG a)
+{
+#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
+ BN_ULONG r;
+ __asm__("" : "=r"(r) : "0"(a));
+#else
+ volatile BN_ULONG r = a;
+#endif
+ return r;
+}
+
static ossl_inline BN_ULONG constant_time_msb_bn(BN_ULONG a)
{
return 0 - (a >> (sizeof(a) * 8 - 1));
@@ -161,6 +172,13 @@ static ossl_inline BN_ULONG constant_time_eq_bn(BN_ULONG a,
{
return constant_time_is_zero_bn(a ^ b);
}
+
+static ossl_inline BN_ULONG constant_time_select_bn(BN_ULONG mask,
+ BN_ULONG a,
+ BN_ULONG b)
+{
+ return (value_barrier_bn(mask) & a) | (value_barrier_bn(~mask) & b);
+}
#endif
static ossl_inline unsigned int constant_time_ge(unsigned int a,