diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_internal.h')
-rw-r--r-- | src/lib/libcrypto/bn/bn_internal.h | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bn/bn_internal.h b/src/lib/libcrypto/bn/bn_internal.h index 12ea3641e6..1b5ab9c42c 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.4 2023/02/15 04:46:49 tb Exp $ */ | 1 | /* $OpenBSD: bn_internal.h,v 1.5 2023/02/16 04:42:20 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -102,6 +102,63 @@ bn_addw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) | |||
102 | #endif | 102 | #endif |
103 | #endif | 103 | #endif |
104 | 104 | ||
105 | /* | ||
106 | * bn_addw_addw() computes (r1:r0) = a + b + c, where all inputs are single | ||
107 | * words, producing a double word result. | ||
108 | */ | ||
109 | #ifndef HAVE_BN_ADDW_ADDW | ||
110 | static inline void | ||
111 | bn_addw_addw(BN_ULONG a, BN_ULONG b, BN_ULONG c, BN_ULONG *out_r1, | ||
112 | BN_ULONG *out_r0) | ||
113 | { | ||
114 | BN_ULONG carry, r1, r0; | ||
115 | |||
116 | bn_addw(a, b, &r1, &r0); | ||
117 | bn_addw(r0, c, &carry, &r0); | ||
118 | r1 += carry; | ||
119 | |||
120 | *out_r1 = r1; | ||
121 | *out_r0 = r0; | ||
122 | } | ||
123 | #endif | ||
124 | |||
125 | /* | ||
126 | * bn_subw() computes r0 = a - b, where both inputs are single words, | ||
127 | * producing a single word result and borrow. | ||
128 | */ | ||
129 | #ifndef HAVE_BN_SUBW | ||
130 | static inline void | ||
131 | bn_subw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_borrow, BN_ULONG *out_r0) | ||
132 | { | ||
133 | BN_ULONG borrow, r0; | ||
134 | |||
135 | r0 = a - b; | ||
136 | borrow = ((r0 | (b & ~a)) & (b | ~a)) >> (BN_BITS2 - 1); | ||
137 | |||
138 | *out_borrow = borrow; | ||
139 | *out_r0 = r0; | ||
140 | } | ||
141 | #endif | ||
142 | |||
143 | /* | ||
144 | * bn_subw_subw() computes r0 = a - b - c, where all inputs are single words, | ||
145 | * producing a single word result and borrow. | ||
146 | */ | ||
147 | #ifndef HAVE_BN_SUBW_SUBW | ||
148 | static inline void | ||
149 | bn_subw_subw(BN_ULONG a, BN_ULONG b, BN_ULONG c, BN_ULONG *out_borrow, | ||
150 | BN_ULONG *out_r0) | ||
151 | { | ||
152 | BN_ULONG b1, b2, r0; | ||
153 | |||
154 | bn_subw(a, b, &b1, &r0); | ||
155 | bn_subw(r0, c, &b2, &r0); | ||
156 | |||
157 | *out_borrow = b1 + b2; | ||
158 | *out_r0 = r0; | ||
159 | } | ||
160 | #endif | ||
161 | |||
105 | #ifndef HAVE_BN_UMUL_HILO | 162 | #ifndef HAVE_BN_UMUL_HILO |
106 | #ifdef BN_LLONG | 163 | #ifdef BN_LLONG |
107 | static inline void | 164 | static inline void |