diff options
author | jsing <> | 2023-06-21 07:48:41 +0000 |
---|---|---|
committer | jsing <> | 2023-06-21 07:48:41 +0000 |
commit | f91290f116c7d9e13993e1e56be029f210d76516 (patch) | |
tree | 279fd7ba83f6adb19a12c4a0d34196850a955e43 /src | |
parent | e977838d69c1994d3229516f8fca1fe64aafb9cb (diff) | |
download | openbsd-f91290f116c7d9e13993e1e56be029f210d76516.tar.gz openbsd-f91290f116c7d9e13993e1e56be029f210d76516.tar.bz2 openbsd-f91290f116c7d9e13993e1e56be029f210d76516.zip |
Provide and use bn_clzw() in place of bn_word_clz().
On some architectures, we can provide an optimised (often single
instruction) count-leading-zero implementation. In order to do this
effectively, provide bn_clzw() as a static inline that can be replaced
by an architecture specific version. The default implementation defers
to the bn_word_clz() function (which may also be architecture specific).
ok tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_internal.h | 10 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_lib.c | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_primitives.c | 6 |
3 files changed, 15 insertions, 5 deletions
diff --git a/src/lib/libcrypto/bn/bn_internal.h b/src/lib/libcrypto/bn/bn_internal.h index f5c69c5d77..b712b736f6 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.13 2023/06/21 07:41:55 jsing Exp $ */ | 1 | /* $OpenBSD: bn_internal.h,v 1.14 2023/06/21 07:48:41 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -58,6 +58,14 @@ bn_ct_eq_zero_mask(BN_ULONG w) | |||
58 | } | 58 | } |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #ifndef HAVE_BN_CLZW | ||
62 | static inline int | ||
63 | bn_clzw(BN_ULONG w) | ||
64 | { | ||
65 | return bn_word_clz(w); | ||
66 | } | ||
67 | #endif | ||
68 | |||
61 | /* | 69 | /* |
62 | * Big number primitives are named as the operation followed by a suffix | 70 | * Big number primitives are named as the operation followed by a suffix |
63 | * that indicates the number of words that it operates on, where 'w' means | 71 | * that indicates the number of words that it operates on, where 'w' means |
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index b8eb565497..bac0290efa 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_lib.c,v 1.87 2023/06/21 07:41:55 jsing Exp $ */ | 1 | /* $OpenBSD: bn_lib.c,v 1.88 2023/06/21 07:48:41 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -162,7 +162,7 @@ BN_value_one(void) | |||
162 | int | 162 | int |
163 | BN_num_bits_word(BN_ULONG w) | 163 | BN_num_bits_word(BN_ULONG w) |
164 | { | 164 | { |
165 | return BN_BITS2 - bn_word_clz(w); | 165 | return BN_BITS2 - bn_clzw(w); |
166 | } | 166 | } |
167 | 167 | ||
168 | int | 168 | int |
diff --git a/src/lib/libcrypto/bn/bn_primitives.c b/src/lib/libcrypto/bn/bn_primitives.c index e9caec4818..66427a9046 100644 --- a/src/lib/libcrypto/bn/bn_primitives.c +++ b/src/lib/libcrypto/bn/bn_primitives.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_primitives.c,v 1.1 2023/06/21 07:41:55 jsing Exp $ */ | 1 | /* $OpenBSD: bn_primitives.c,v 1.2 2023/06/21 07:48:41 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -21,6 +21,7 @@ | |||
21 | #include "bn_internal.h" | 21 | #include "bn_internal.h" |
22 | #include "bn_local.h" | 22 | #include "bn_local.h" |
23 | 23 | ||
24 | #ifndef HAVE_BN_CLZW | ||
24 | #ifndef HAVE_BN_WORD_CLZ | 25 | #ifndef HAVE_BN_WORD_CLZ |
25 | int | 26 | int |
26 | bn_word_clz(BN_ULONG w) | 27 | bn_word_clz(BN_ULONG w) |
@@ -41,6 +42,7 @@ bn_word_clz(BN_ULONG w) | |||
41 | return BN_BITS2 - bits; | 42 | return BN_BITS2 - bits; |
42 | } | 43 | } |
43 | #endif | 44 | #endif |
45 | #endif | ||
44 | 46 | ||
45 | #ifndef HAVE_BN_BITSIZE | 47 | #ifndef HAVE_BN_BITSIZE |
46 | int | 48 | int |
@@ -58,6 +60,6 @@ bn_bitsize(const BIGNUM *bn) | |||
58 | i++; | 60 | i++; |
59 | } | 61 | } |
60 | 62 | ||
61 | return (n + 1) * BN_BITS2 - bn_word_clz(x); | 63 | return (n + 1) * BN_BITS2 - bn_clzw(x); |
62 | } | 64 | } |
63 | #endif | 65 | #endif |