summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_asm.c
diff options
context:
space:
mode:
authorjsing <>2023-01-23 10:31:03 +0000
committerjsing <>2023-01-23 10:31:03 +0000
commite18a6c33767d9180e59054a8c34c6d6f865c97cb (patch)
tree2c0d2f05d5d07f457de45d8fb57e0308a29ef9d5 /src/lib/libcrypto/bn/bn_asm.c
parent28b5c32c404672e404306baeb4d86804c51f79c9 (diff)
downloadopenbsd-e18a6c33767d9180e59054a8c34c6d6f865c97cb.tar.gz
openbsd-e18a6c33767d9180e59054a8c34c6d6f865c97cb.tar.bz2
openbsd-e18a6c33767d9180e59054a8c34c6d6f865c97cb.zip
Move bn_add_words() and bn_sub_words from bn_asm.c to bn_add.c.
These are wrapped with #ifndef HAVE_BN_ADD_WORDS/HAVE_BN_SUB_WORDS, which are defined for architectures that provide their own assembly versions.
Diffstat (limited to 'src/lib/libcrypto/bn/bn_asm.c')
-rw-r--r--src/lib/libcrypto/bn/bn_asm.c154
1 files changed, 1 insertions, 153 deletions
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c
index df4ddaea17..4224396c00 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.19 2023/01/20 17:31:52 jsing Exp $ */ 1/* $OpenBSD: bn_asm.c,v 1.20 2023/01/23 10:31: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 *
@@ -325,158 +325,6 @@ bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
325} 325}
326#endif /* !defined(BN_LLONG) && defined(BN_DIV2W) */ 326#endif /* !defined(BN_LLONG) && defined(BN_DIV2W) */
327 327
328#ifdef BN_LLONG
329BN_ULONG
330bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
331{
332 BN_ULLONG ll = 0;
333
334 assert(n >= 0);
335 if (n <= 0)
336 return ((BN_ULONG)0);
337
338#ifndef OPENSSL_SMALL_FOOTPRINT
339 while (n & ~3) {
340 ll += (BN_ULLONG)a[0] + b[0];
341 r[0] = (BN_ULONG)ll & BN_MASK2;
342 ll >>= BN_BITS2;
343 ll += (BN_ULLONG)a[1] + b[1];
344 r[1] = (BN_ULONG)ll & BN_MASK2;
345 ll >>= BN_BITS2;
346 ll += (BN_ULLONG)a[2] + b[2];
347 r[2] = (BN_ULONG)ll & BN_MASK2;
348 ll >>= BN_BITS2;
349 ll += (BN_ULLONG)a[3] + b[3];
350 r[3] = (BN_ULONG)ll & BN_MASK2;
351 ll >>= BN_BITS2;
352 a += 4;
353 b += 4;
354 r += 4;
355 n -= 4;
356 }
357#endif
358 while (n) {
359 ll += (BN_ULLONG)a[0] + b[0];
360 r[0] = (BN_ULONG)ll & BN_MASK2;
361 ll >>= BN_BITS2;
362 a++;
363 b++;
364 r++;
365 n--;
366 }
367 return ((BN_ULONG)ll);
368}
369#else /* !BN_LLONG */
370BN_ULONG
371bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
372{
373 BN_ULONG c, l, t;
374
375 assert(n >= 0);
376 if (n <= 0)
377 return ((BN_ULONG)0);
378
379 c = 0;
380#ifndef OPENSSL_SMALL_FOOTPRINT
381 while (n & ~3) {
382 t = a[0];
383 t = (t + c) & BN_MASK2;
384 c = (t < c);
385 l = (t + b[0]) & BN_MASK2;
386 c += (l < t);
387 r[0] = l;
388 t = a[1];
389 t = (t + c) & BN_MASK2;
390 c = (t < c);
391 l = (t + b[1]) & BN_MASK2;
392 c += (l < t);
393 r[1] = l;
394 t = a[2];
395 t = (t + c) & BN_MASK2;
396 c = (t < c);
397 l = (t + b[2]) & BN_MASK2;
398 c += (l < t);
399 r[2] = l;
400 t = a[3];
401 t = (t + c) & BN_MASK2;
402 c = (t < c);
403 l = (t + b[3]) & BN_MASK2;
404 c += (l < t);
405 r[3] = l;
406 a += 4;
407 b += 4;
408 r += 4;
409 n -= 4;
410 }
411#endif
412 while (n) {
413 t = a[0];
414 t = (t + c) & BN_MASK2;
415 c = (t < c);
416 l = (t + b[0]) & BN_MASK2;
417 c += (l < t);
418 r[0] = l;
419 a++;
420 b++;
421 r++;
422 n--;
423 }
424 return ((BN_ULONG)c);
425}
426#endif /* !BN_LLONG */
427
428BN_ULONG
429bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
430{
431 BN_ULONG t1, t2;
432 int c = 0;
433
434 assert(n >= 0);
435 if (n <= 0)
436 return ((BN_ULONG)0);
437
438#ifndef OPENSSL_SMALL_FOOTPRINT
439 while (n&~3) {
440 t1 = a[0];
441 t2 = b[0];
442 r[0] = (t1 - t2 - c) & BN_MASK2;
443 if (t1 != t2)
444 c = (t1 < t2);
445 t1 = a[1];
446 t2 = b[1];
447 r[1] = (t1 - t2 - c) & BN_MASK2;
448 if (t1 != t2)
449 c = (t1 < t2);
450 t1 = a[2];
451 t2 = b[2];
452 r[2] = (t1 - t2 - c) & BN_MASK2;
453 if (t1 != t2)
454 c = (t1 < t2);
455 t1 = a[3];
456 t2 = b[3];
457 r[3] = (t1 - t2 - c) & BN_MASK2;
458 if (t1 != t2)
459 c = (t1 < t2);
460 a += 4;
461 b += 4;
462 r += 4;
463 n -= 4;
464 }
465#endif
466 while (n) {
467 t1 = a[0];
468 t2 = b[0];
469 r[0] = (t1 - t2 - c) & BN_MASK2;
470 if (t1 != t2)
471 c = (t1 < t2);
472 a++;
473 b++;
474 r++;
475 n--;
476 }
477 return (c);
478}
479
480#if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT) 328#if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT)
481 329
482#ifdef OPENSSL_NO_ASM 330#ifdef OPENSSL_NO_ASM