diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_asm.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_asm.c | 81 |
1 files changed, 1 insertions, 80 deletions
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c index 4224396c00..a7f288fc1c 100644 --- a/src/lib/libcrypto/bn/bn_asm.c +++ b/src/lib/libcrypto/bn/bn_asm.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_asm.c,v 1.20 2023/01/23 10:31:03 jsing Exp $ */ | 1 | /* $OpenBSD: bn_asm.c,v 1.21 2023/01/23 12:02:48 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 | * |
@@ -246,85 +246,6 @@ bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n) | |||
246 | 246 | ||
247 | #endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ | 247 | #endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ |
248 | 248 | ||
249 | #if defined(BN_LLONG) && defined(BN_DIV2W) | ||
250 | |||
251 | BN_ULONG | ||
252 | bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d) | ||
253 | { | ||
254 | return ((BN_ULONG)(((((BN_ULLONG)h) << BN_BITS2)|l)/(BN_ULLONG)d)); | ||
255 | } | ||
256 | |||
257 | #else | ||
258 | |||
259 | /* Divide h,l by d and return the result. */ | ||
260 | /* I need to test this some more :-( */ | ||
261 | BN_ULONG | ||
262 | bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d) | ||
263 | { | ||
264 | BN_ULONG dh, dl, q,ret = 0, th, tl, t; | ||
265 | int i, count = 2; | ||
266 | |||
267 | if (d == 0) | ||
268 | return (BN_MASK2); | ||
269 | |||
270 | i = BN_num_bits_word(d); | ||
271 | assert((i == BN_BITS2) || (h <= (BN_ULONG)1 << i)); | ||
272 | |||
273 | i = BN_BITS2 - i; | ||
274 | if (h >= d) | ||
275 | h -= d; | ||
276 | |||
277 | if (i) { | ||
278 | d <<= i; | ||
279 | h = (h << i) | (l >> (BN_BITS2 - i)); | ||
280 | l <<= i; | ||
281 | } | ||
282 | dh = (d & BN_MASK2h) >> BN_BITS4; | ||
283 | dl = (d & BN_MASK2l); | ||
284 | for (;;) { | ||
285 | if ((h >> BN_BITS4) == dh) | ||
286 | q = BN_MASK2l; | ||
287 | else | ||
288 | q = h / dh; | ||
289 | |||
290 | th = q * dh; | ||
291 | tl = dl * q; | ||
292 | for (;;) { | ||
293 | t = h - th; | ||
294 | if ((t & BN_MASK2h) || | ||
295 | ((tl) <= ( | ||
296 | (t << BN_BITS4) | | ||
297 | ((l & BN_MASK2h) >> BN_BITS4)))) | ||
298 | break; | ||
299 | q--; | ||
300 | th -= dh; | ||
301 | tl -= dl; | ||
302 | } | ||
303 | t = (tl >> BN_BITS4); | ||
304 | tl = (tl << BN_BITS4) & BN_MASK2h; | ||
305 | th += t; | ||
306 | |||
307 | if (l < tl) | ||
308 | th++; | ||
309 | l -= tl; | ||
310 | if (h < th) { | ||
311 | h += d; | ||
312 | q--; | ||
313 | } | ||
314 | h -= th; | ||
315 | |||
316 | if (--count == 0) | ||
317 | break; | ||
318 | |||
319 | ret = q << BN_BITS4; | ||
320 | h = ((h << BN_BITS4) | (l >> BN_BITS4)) & BN_MASK2; | ||
321 | l = (l & BN_MASK2l) << BN_BITS4; | ||
322 | } | ||
323 | ret |= q; | ||
324 | return (ret); | ||
325 | } | ||
326 | #endif /* !defined(BN_LLONG) && defined(BN_DIV2W) */ | ||
327 | |||
328 | #if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT) | 249 | #if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT) |
329 | 250 | ||
330 | #ifdef OPENSSL_NO_ASM | 251 | #ifdef OPENSSL_NO_ASM |