diff options
author | jsing <> | 2023-02-16 10:41:03 +0000 |
---|---|---|
committer | jsing <> | 2023-02-16 10:41:03 +0000 |
commit | d3699a732b869a27d4edac40e74816362ea9be8a (patch) | |
tree | 1567d4016a24536bb2e57960203cb4c640cd41e3 | |
parent | 86621357e60f9e67b9a598c67567b92aeaead6ba (diff) | |
download | openbsd-d3699a732b869a27d4edac40e74816362ea9be8a.tar.gz openbsd-d3699a732b869a27d4edac40e74816362ea9be8a.tar.bz2 openbsd-d3699a732b869a27d4edac40e74816362ea9be8a.zip |
Rename bn_umul_hilo() to bn_mulw().
This keeps the naming consistent with the other bignum primitives that have
been recently introduced. Also, use 1/0 intead of h/l (e.g. a1 instead of
ah), as this keeps consistency with other primitives and allows for naming
that works with double word, triple word and quadruple word inputs/outputs.
Discussed with tb@
-rw-r--r-- | src/lib/libcrypto/bn/arch/aarch64/bn_arch.h | 14 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/arch/alpha/bn_arch.h | 14 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/arch/amd64/bn_arch.h | 14 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/arch/i386/bn_arch.h | 14 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h | 14 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/arch/riscv64/bn_arch.h | 14 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_div.c | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_internal.h | 114 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_sqr.c | 12 |
9 files changed, 109 insertions, 105 deletions
diff --git a/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h b/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h index 7592971dc0..cc456848c9 100644 --- a/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h +++ b/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_arch.h,v 1.3 2023/02/04 11:48:55 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.4 2023/02/16 10:41:03 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -23,20 +23,20 @@ | |||
23 | #ifndef OPENSSL_NO_ASM | 23 | #ifndef OPENSSL_NO_ASM |
24 | 24 | ||
25 | #if defined(__GNUC__) | 25 | #if defined(__GNUC__) |
26 | #define HAVE_BN_UMUL_HILO | 26 | #define HAVE_BN_MULW |
27 | 27 | ||
28 | static inline void | 28 | static inline void |
29 | bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | 29 | bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) |
30 | { | 30 | { |
31 | BN_ULONG h, l; | 31 | BN_ULONG r1, r0; |
32 | 32 | ||
33 | /* Unsigned multiplication using a umulh/mul pair. */ | 33 | /* Unsigned multiplication using a umulh/mul pair. */ |
34 | __asm__ ("umulh %0, %2, %3; mul %1, %2, %3" | 34 | __asm__ ("umulh %0, %2, %3; mul %1, %2, %3" |
35 | : "=&r"(h), "=r"(l) | 35 | : "=&r"(r1), "=r"(r0) |
36 | : "r"(a), "r"(b)); | 36 | : "r"(a), "r"(b)); |
37 | 37 | ||
38 | *out_h = h; | 38 | *out_r1 = r1; |
39 | *out_l = l; | 39 | *out_r0 = r0; |
40 | } | 40 | } |
41 | #endif /* __GNUC__ */ | 41 | #endif /* __GNUC__ */ |
42 | 42 | ||
diff --git a/src/lib/libcrypto/bn/arch/alpha/bn_arch.h b/src/lib/libcrypto/bn/arch/alpha/bn_arch.h index 0f7c582fdf..5bf4ba8722 100644 --- a/src/lib/libcrypto/bn/arch/alpha/bn_arch.h +++ b/src/lib/libcrypto/bn/arch/alpha/bn_arch.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_arch.h,v 1.3 2023/02/04 11:48:55 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.4 2023/02/16 10:41:03 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,20 +22,20 @@ | |||
22 | 22 | ||
23 | #if 0 /* Needs testing and enabling. */ | 23 | #if 0 /* Needs testing and enabling. */ |
24 | #if defined(__GNUC__) | 24 | #if defined(__GNUC__) |
25 | #define HAVE_BN_UMUL_HILO | 25 | #define HAVE_BN_MULW |
26 | 26 | ||
27 | static inline void | 27 | static inline void |
28 | bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | 28 | bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) |
29 | { | 29 | { |
30 | BN_ULONG h, l; | 30 | BN_ULONG r1, r0; |
31 | 31 | ||
32 | /* Unsigned multiplication using a umulh/mulq pair. */ | 32 | /* Unsigned multiplication using a umulh/mulq pair. */ |
33 | __asm__ ("umulh %2, %3, %0; mulq %2, %3, %1" | 33 | __asm__ ("umulh %2, %3, %0; mulq %2, %3, %1" |
34 | : "=&r"(h), "=r"(l) | 34 | : "=&r"(r1), "=r"(r0) |
35 | : "r"(a), "r"(b)); | 35 | : "r"(a), "r"(b)); |
36 | 36 | ||
37 | *out_h = h; | 37 | *out_r1 = r1; |
38 | *out_l = l; | 38 | *out_r0 = r0; |
39 | } | 39 | } |
40 | #endif /* __GNUC__ */ | 40 | #endif /* __GNUC__ */ |
41 | #endif | 41 | #endif |
diff --git a/src/lib/libcrypto/bn/arch/amd64/bn_arch.h b/src/lib/libcrypto/bn/arch/amd64/bn_arch.h index 637903077a..80f73bf15f 100644 --- a/src/lib/libcrypto/bn/arch/amd64/bn_arch.h +++ b/src/lib/libcrypto/bn/arch/amd64/bn_arch.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_arch.h,v 1.11 2023/02/04 14:00:18 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.12 2023/02/16 10:41:03 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -63,24 +63,24 @@ bn_div_rem_words_inline(BN_ULONG h, BN_ULONG l, BN_ULONG d, BN_ULONG *out_q, | |||
63 | #endif /* __GNUC__ */ | 63 | #endif /* __GNUC__ */ |
64 | 64 | ||
65 | #if defined(__GNUC__) | 65 | #if defined(__GNUC__) |
66 | #define HAVE_BN_UMUL_HILO | 66 | #define HAVE_BN_MULW |
67 | 67 | ||
68 | static inline void | 68 | static inline void |
69 | bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | 69 | bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) |
70 | { | 70 | { |
71 | BN_ULONG h, l; | 71 | BN_ULONG r1, r0; |
72 | 72 | ||
73 | /* | 73 | /* |
74 | * Unsigned multiplication of %rax, with the double word result being | 74 | * Unsigned multiplication of %rax, with the double word result being |
75 | * stored in %rdx:%rax. | 75 | * stored in %rdx:%rax. |
76 | */ | 76 | */ |
77 | __asm__ ("mulq %3" | 77 | __asm__ ("mulq %3" |
78 | : "=d"(h), "=a"(l) | 78 | : "=d"(r1), "=a"(r0) |
79 | : "a"(a), "rm"(b) | 79 | : "a"(a), "rm"(b) |
80 | : "cc"); | 80 | : "cc"); |
81 | 81 | ||
82 | *out_h = h; | 82 | *out_r1 = r1; |
83 | *out_l = l; | 83 | *out_r0 = r0; |
84 | } | 84 | } |
85 | #endif /* __GNUC__ */ | 85 | #endif /* __GNUC__ */ |
86 | 86 | ||
diff --git a/src/lib/libcrypto/bn/arch/i386/bn_arch.h b/src/lib/libcrypto/bn/arch/i386/bn_arch.h index 268c51e41a..eef519fcc7 100644 --- a/src/lib/libcrypto/bn/arch/i386/bn_arch.h +++ b/src/lib/libcrypto/bn/arch/i386/bn_arch.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_arch.h,v 1.8 2023/01/31 05:53:49 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.9 2023/02/16 10:41:03 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -61,24 +61,24 @@ bn_div_rem_words_inline(BN_ULONG h, BN_ULONG l, BN_ULONG d, BN_ULONG *out_q, | |||
61 | #endif /* __GNUC__ */ | 61 | #endif /* __GNUC__ */ |
62 | 62 | ||
63 | #if defined(__GNUC__) | 63 | #if defined(__GNUC__) |
64 | #define HAVE_BN_UMUL_HILO | 64 | #define HAVE_BN_MULW |
65 | 65 | ||
66 | static inline void | 66 | static inline void |
67 | bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | 67 | bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) |
68 | { | 68 | { |
69 | BN_ULONG h, l; | 69 | BN_ULONG r1, r0; |
70 | 70 | ||
71 | /* | 71 | /* |
72 | * Unsigned multiplication of %eax, with the double word result being | 72 | * Unsigned multiplication of %eax, with the double word result being |
73 | * stored in %edx:%eax. | 73 | * stored in %edx:%eax. |
74 | */ | 74 | */ |
75 | __asm__ ("mull %3" | 75 | __asm__ ("mull %3" |
76 | : "=d"(h), "=a"(l) | 76 | : "=d"(r1), "=a"(r0) |
77 | : "a"(a), "rm"(b) | 77 | : "a"(a), "rm"(b) |
78 | : "cc"); | 78 | : "cc"); |
79 | 79 | ||
80 | *out_h = h; | 80 | *out_r1 = r1; |
81 | *out_l = l; | 81 | *out_r0 = r0; |
82 | } | 82 | } |
83 | #endif /* __GNUC__ */ | 83 | #endif /* __GNUC__ */ |
84 | 84 | ||
diff --git a/src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h b/src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h index 92e16e9f9c..18bac203eb 100644 --- a/src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h +++ b/src/lib/libcrypto/bn/arch/powerpc64/bn_arch.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_arch.h,v 1.3 2023/02/04 11:48:55 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.4 2023/02/16 10:41:03 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,20 +22,20 @@ | |||
22 | 22 | ||
23 | #if 0 /* Needs testing and enabling. */ | 23 | #if 0 /* Needs testing and enabling. */ |
24 | #if defined(__GNUC__) | 24 | #if defined(__GNUC__) |
25 | #define HAVE_BN_UMUL_HILO | 25 | #define HAVE_BN_MULW |
26 | 26 | ||
27 | static inline void | 27 | static inline void |
28 | bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | 28 | bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) |
29 | { | 29 | { |
30 | BN_ULONG h, l; | 30 | BN_ULONG r1, r0; |
31 | 31 | ||
32 | /* Unsigned multiplication using a mulhdu/mul pair. */ | 32 | /* Unsigned multiplication using a mulhdu/mul pair. */ |
33 | __asm__ ("mulhdu %0, %2, %3; mul %1, %2, %3" | 33 | __asm__ ("mulhdu %0, %2, %3; mul %1, %2, %3" |
34 | : "=&r"(h), "=r"(l) | 34 | : "=&r"(r1), "=r"(r0) |
35 | : "r"(a), "r"(b)); | 35 | : "r"(a), "r"(b)); |
36 | 36 | ||
37 | *out_h = h; | 37 | *out_r1 = r1; |
38 | *out_l = l; | 38 | *out_r0 = r0; |
39 | } | 39 | } |
40 | #endif /* __GNUC__ */ | 40 | #endif /* __GNUC__ */ |
41 | #endif | 41 | #endif |
diff --git a/src/lib/libcrypto/bn/arch/riscv64/bn_arch.h b/src/lib/libcrypto/bn/arch/riscv64/bn_arch.h index 36cf3a4f66..354774cde3 100644 --- a/src/lib/libcrypto/bn/arch/riscv64/bn_arch.h +++ b/src/lib/libcrypto/bn/arch/riscv64/bn_arch.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_arch.h,v 1.3 2023/02/04 11:48:55 jsing Exp $ */ | 1 | /* $OpenBSD: bn_arch.h,v 1.4 2023/02/16 10:41:03 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,12 +22,12 @@ | |||
22 | 22 | ||
23 | #if 0 /* Needs testing and enabling. */ | 23 | #if 0 /* Needs testing and enabling. */ |
24 | #if defined(__GNUC__) | 24 | #if defined(__GNUC__) |
25 | #define HAVE_BN_UMUL_HILO | 25 | #define HAVE_BN_MULW |
26 | 26 | ||
27 | static inline void | 27 | static inline void |
28 | bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | 28 | bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) |
29 | { | 29 | { |
30 | BN_ULONG h, l; | 30 | BN_ULONG r1, r0; |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * Unsigned multiplication using a mulh/mul pair. Note that the order | 33 | * Unsigned multiplication using a mulh/mul pair. Note that the order |
@@ -35,11 +35,11 @@ bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | |||
35 | * into a single operation. | 35 | * into a single operation. |
36 | */ | 36 | */ |
37 | __asm__ ("mulh %0, %2, %3; mul %1, %2, %3" | 37 | __asm__ ("mulh %0, %2, %3; mul %1, %2, %3" |
38 | : "=&r"(h), "=r"(l) | 38 | : "=&r"(r1), "=r"(r0) |
39 | : "r"(a), "r"(b)); | 39 | : "r"(a), "r"(b)); |
40 | 40 | ||
41 | *out_h = h; | 41 | *out_r1 = r1; |
42 | *out_l = l; | 42 | *out_r0 = r0; |
43 | } | 43 | } |
44 | #endif /* __GNUC__ */ | 44 | #endif /* __GNUC__ */ |
45 | #endif | 45 | #endif |
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c index 686b957eb5..692e618407 100644 --- a/src/lib/libcrypto/bn/bn_div.c +++ b/src/lib/libcrypto/bn/bn_div.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_div.c,v 1.38 2023/02/14 18:19:27 jsing Exp $ */ | 1 | /* $OpenBSD: bn_div.c,v 1.39 2023/02/16 10:41:03 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 | * |
@@ -204,7 +204,7 @@ bn_div_3_words(const BN_ULONG *m, BN_ULONG d1, BN_ULONG d0) | |||
204 | /* n0 < d0 */ | 204 | /* n0 < d0 */ |
205 | bn_div_rem_words(n0, n1, d0, &q, &rem); | 205 | bn_div_rem_words(n0, n1, d0, &q, &rem); |
206 | 206 | ||
207 | bn_umul_hilo(d1, q, &t2h, &t2l); | 207 | bn_mulw(d1, q, &t2h, &t2l); |
208 | 208 | ||
209 | for (;;) { | 209 | for (;;) { |
210 | if (t2h < rem || (t2h == rem && t2l <= m[-2])) | 210 | if (t2h < rem || (t2h == rem && t2l <= m[-2])) |
diff --git a/src/lib/libcrypto/bn/bn_internal.h b/src/lib/libcrypto/bn/bn_internal.h index 64240555d1..2872e21185 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.6 2023/02/16 10:02:02 jsing Exp $ */ | 1 | /* $OpenBSD: bn_internal.h,v 1.7 2023/02/16 10:41:03 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -159,17 +159,21 @@ bn_subw_subw(BN_ULONG a, BN_ULONG b, BN_ULONG c, BN_ULONG *out_borrow, | |||
159 | } | 159 | } |
160 | #endif | 160 | #endif |
161 | 161 | ||
162 | #ifndef HAVE_BN_UMUL_HILO | 162 | /* |
163 | * bn_mulw() computes (r1:r0) = a * b, where both inputs are single words, | ||
164 | * producing a double word result. | ||
165 | */ | ||
166 | #ifndef HAVE_BN_MULW | ||
163 | #ifdef BN_LLONG | 167 | #ifdef BN_LLONG |
164 | static inline void | 168 | static inline void |
165 | bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | 169 | bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) |
166 | { | 170 | { |
167 | BN_ULLONG r; | 171 | BN_ULLONG r; |
168 | 172 | ||
169 | r = (BN_ULLONG)a * (BN_ULLONG)b; | 173 | r = (BN_ULLONG)a * (BN_ULLONG)b; |
170 | 174 | ||
171 | *out_h = r >> BN_BITS2; | 175 | *out_r1 = r >> BN_BITS2; |
172 | *out_l = r & BN_MASK2; | 176 | *out_r0 = r & BN_MASK2; |
173 | } | 177 | } |
174 | 178 | ||
175 | #else /* !BN_LLONG */ | 179 | #else /* !BN_LLONG */ |
@@ -193,38 +197,38 @@ bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | |||
193 | */ | 197 | */ |
194 | #if 1 | 198 | #if 1 |
195 | static inline void | 199 | static inline void |
196 | bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | 200 | bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) |
197 | { | 201 | { |
198 | BN_ULONG ah, al, bh, bl, h, l, x, c1, c2; | 202 | BN_ULONG a1, a0, b1, b0, r1, r0, c1, c2, x; |
199 | 203 | ||
200 | ah = a >> BN_BITS4; | 204 | a1 = a >> BN_BITS4; |
201 | al = a & BN_MASK2l; | 205 | a0 = a & BN_MASK2l; |
202 | bh = b >> BN_BITS4; | 206 | b1 = b >> BN_BITS4; |
203 | bl = b & BN_MASK2l; | 207 | b0 = b & BN_MASK2l; |
204 | 208 | ||
205 | h = ah * bh; | 209 | r1 = a1 * b1; |
206 | l = al * bl; | 210 | r0 = a0 * b0; |
207 | 211 | ||
208 | /* (ah * bl) << BN_BITS4, partition the result across h:l with carry. */ | 212 | /* (a1 * b0) << BN_BITS4, partition the result across r1:r0 with carry. */ |
209 | x = ah * bl; | 213 | x = a1 * b0; |
210 | h += x >> BN_BITS4; | 214 | r1 += x >> BN_BITS4; |
211 | x <<= BN_BITS4; | 215 | x <<= BN_BITS4; |
212 | c1 = l | x; | 216 | c1 = r0 | x; |
213 | c2 = l & x; | 217 | c2 = r0 & x; |
214 | l += x; | 218 | r0 += x; |
215 | h += ((c1 & ~l) | c2) >> (BN_BITS2 - 1); /* carry */ | 219 | r1 += ((c1 & ~r0) | c2) >> (BN_BITS2 - 1); /* carry */ |
216 | 220 | ||
217 | /* (bh * al) << BN_BITS4, partition the result across h:l with carry. */ | 221 | /* (b1 * a0) << BN_BITS4, partition the result across r1:r0 with carry. */ |
218 | x = bh * al; | 222 | x = b1 * a0; |
219 | h += x >> BN_BITS4; | 223 | r1 += x >> BN_BITS4; |
220 | x <<= BN_BITS4; | 224 | x <<= BN_BITS4; |
221 | c1 = l | x; | 225 | c1 = r0 | x; |
222 | c2 = l & x; | 226 | c2 = r0 & x; |
223 | l += x; | 227 | r0 += x; |
224 | h += ((c1 & ~l) | c2) >> (BN_BITS2 - 1); /* carry */ | 228 | r1 += ((c1 & ~r0) | c2) >> (BN_BITS2 - 1); /* carry */ |
225 | 229 | ||
226 | *out_h = h; | 230 | *out_r1 = r1; |
227 | *out_l = l; | 231 | *out_r0 = r0; |
228 | } | 232 | } |
229 | #else | 233 | #else |
230 | 234 | ||
@@ -236,62 +240,62 @@ bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | |||
236 | * implementations should eventually be removed. | 240 | * implementations should eventually be removed. |
237 | */ | 241 | */ |
238 | static inline void | 242 | static inline void |
239 | bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) | 243 | bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) |
240 | { | 244 | { |
241 | BN_ULONG ah, bh, al, bl, x, h, l; | 245 | BN_ULONG a1, a0, b1, b0, r1, r0, x; |
242 | BN_ULONG acc0, acc1, acc2, acc3; | 246 | BN_ULONG acc0, acc1, acc2, acc3; |
243 | 247 | ||
244 | ah = a >> BN_BITS4; | 248 | a1 = a >> BN_BITS4; |
245 | bh = b >> BN_BITS4; | 249 | b1 = b >> BN_BITS4; |
246 | al = a & BN_MASK2l; | 250 | a0 = a & BN_MASK2l; |
247 | bl = b & BN_MASK2l; | 251 | b0 = b & BN_MASK2l; |
248 | 252 | ||
249 | h = ah * bh; | 253 | r1 = a1 * b1; |
250 | l = al * bl; | 254 | r0 = a0 * b0; |
251 | 255 | ||
252 | acc0 = l & BN_MASK2l; | 256 | acc0 = r0 & BN_MASK2l; |
253 | acc1 = l >> BN_BITS4; | 257 | acc1 = r0 >> BN_BITS4; |
254 | acc2 = h & BN_MASK2l; | 258 | acc2 = r1 & BN_MASK2l; |
255 | acc3 = h >> BN_BITS4; | 259 | acc3 = r1 >> BN_BITS4; |
256 | 260 | ||
257 | /* (ah * bl) << BN_BITS4, partition the result across h:l. */ | 261 | /* (a1 * b0) << BN_BITS4, partition the result across r1:r0. */ |
258 | x = ah * bl; | 262 | x = a1 * b0; |
259 | acc1 += x & BN_MASK2l; | 263 | acc1 += x & BN_MASK2l; |
260 | acc2 += (acc1 >> BN_BITS4) + (x >> BN_BITS4); | 264 | acc2 += (acc1 >> BN_BITS4) + (x >> BN_BITS4); |
261 | acc1 &= BN_MASK2l; | 265 | acc1 &= BN_MASK2l; |
262 | acc3 += acc2 >> BN_BITS4; | 266 | acc3 += acc2 >> BN_BITS4; |
263 | acc2 &= BN_MASK2l; | 267 | acc2 &= BN_MASK2l; |
264 | 268 | ||
265 | /* (bh * al) << BN_BITS4, partition the result across h:l. */ | 269 | /* (b1 * a0) << BN_BITS4, partition the result across r1:r0. */ |
266 | x = bh * al; | 270 | x = b1 * a0; |
267 | acc1 += x & BN_MASK2l; | 271 | acc1 += x & BN_MASK2l; |
268 | acc2 += (acc1 >> BN_BITS4) + (x >> BN_BITS4); | 272 | acc2 += (acc1 >> BN_BITS4) + (x >> BN_BITS4); |
269 | acc1 &= BN_MASK2l; | 273 | acc1 &= BN_MASK2l; |
270 | acc3 += acc2 >> BN_BITS4; | 274 | acc3 += acc2 >> BN_BITS4; |
271 | acc2 &= BN_MASK2l; | 275 | acc2 &= BN_MASK2l; |
272 | 276 | ||
273 | *out_h = (acc3 << BN_BITS4) | acc2; | 277 | *out_r1 = (acc3 << BN_BITS4) | acc2; |
274 | *out_l = (acc1 << BN_BITS4) | acc0; | 278 | *out_r0 = (acc1 << BN_BITS4) | acc0; |
275 | } | 279 | } |
276 | #endif | 280 | #endif |
277 | #endif /* !BN_LLONG */ | 281 | #endif /* !BN_LLONG */ |
278 | #endif | 282 | #endif |
279 | 283 | ||
280 | #ifndef HAVE_BN_UMUL_LO | 284 | #ifndef HAVE_BN_MULW_LO |
281 | static inline BN_ULONG | 285 | static inline BN_ULONG |
282 | bn_umul_lo(BN_ULONG a, BN_ULONG b) | 286 | bn_mulw_lo(BN_ULONG a, BN_ULONG b) |
283 | { | 287 | { |
284 | return a * b; | 288 | return a * b; |
285 | } | 289 | } |
286 | #endif | 290 | #endif |
287 | 291 | ||
288 | #ifndef HAVE_BN_UMUL_HI | 292 | #ifndef HAVE_BN_MULW_HI |
289 | static inline BN_ULONG | 293 | static inline BN_ULONG |
290 | bn_umul_hi(BN_ULONG a, BN_ULONG b) | 294 | bn_mulw_hi(BN_ULONG a, BN_ULONG b) |
291 | { | 295 | { |
292 | BN_ULONG h, l; | 296 | BN_ULONG h, l; |
293 | 297 | ||
294 | bn_umul_hilo(a, b, &h, &l); | 298 | bn_mulw(a, b, &h, &l); |
295 | 299 | ||
296 | return h; | 300 | return h; |
297 | } | 301 | } |
@@ -308,7 +312,7 @@ bn_mulw_addw(BN_ULONG a, BN_ULONG b, BN_ULONG c, BN_ULONG *out_r1, | |||
308 | { | 312 | { |
309 | BN_ULONG carry, r1, r0; | 313 | BN_ULONG carry, r1, r0; |
310 | 314 | ||
311 | bn_umul_hilo(a, b, &r1, &r0); | 315 | bn_mulw(a, b, &r1, &r0); |
312 | bn_addw(r0, c, &carry, &r0); | 316 | bn_addw(r0, c, &carry, &r0); |
313 | r1 += carry; | 317 | r1 += carry; |
314 | 318 | ||
@@ -350,7 +354,7 @@ bn_mulw_addtw(BN_ULONG a, BN_ULONG b, BN_ULONG c2, BN_ULONG c1, BN_ULONG c0, | |||
350 | { | 354 | { |
351 | BN_ULONG carry, r2, r1, r0, x1, x0; | 355 | BN_ULONG carry, r2, r1, r0, x1, x0; |
352 | 356 | ||
353 | bn_umul_hilo(a, b, &x1, &x0); | 357 | bn_mulw(a, b, &x1, &x0); |
354 | bn_addw(c0, x0, &carry, &r0); | 358 | bn_addw(c0, x0, &carry, &r0); |
355 | x1 += carry; | 359 | x1 += carry; |
356 | bn_addw(c1, x1, &carry, &r1); | 360 | bn_addw(c1, x1, &carry, &r1); |
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c index 5332d17f6b..f649b9bce8 100644 --- a/src/lib/libcrypto/bn/bn_sqr.c +++ b/src/lib/libcrypto/bn/bn_sqr.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_sqr.c,v 1.25 2023/02/13 04:25:37 jsing Exp $ */ | 1 | /* $OpenBSD: bn_sqr.c,v 1.26 2023/02/16 10:41:03 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 | * |
@@ -193,17 +193,17 @@ bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n) | |||
193 | 193 | ||
194 | #ifndef OPENSSL_SMALL_FOOTPRINT | 194 | #ifndef OPENSSL_SMALL_FOOTPRINT |
195 | while (n & ~3) { | 195 | while (n & ~3) { |
196 | bn_umul_hilo(a[0], a[0], &r[1], &r[0]); | 196 | bn_mulw(a[0], a[0], &r[1], &r[0]); |
197 | bn_umul_hilo(a[1], a[1], &r[3], &r[2]); | 197 | bn_mulw(a[1], a[1], &r[3], &r[2]); |
198 | bn_umul_hilo(a[2], a[2], &r[5], &r[4]); | 198 | bn_mulw(a[2], a[2], &r[5], &r[4]); |
199 | bn_umul_hilo(a[3], a[3], &r[7], &r[6]); | 199 | bn_mulw(a[3], a[3], &r[7], &r[6]); |
200 | a += 4; | 200 | a += 4; |
201 | r += 8; | 201 | r += 8; |
202 | n -= 4; | 202 | n -= 4; |
203 | } | 203 | } |
204 | #endif | 204 | #endif |
205 | while (n) { | 205 | while (n) { |
206 | bn_umul_hilo(a[0], a[0], &r[1], &r[0]); | 206 | bn_mulw(a[0], a[0], &r[1], &r[0]); |
207 | a++; | 207 | a++; |
208 | r += 2; | 208 | r += 2; |
209 | n--; | 209 | n--; |