diff options
author | jsing <> | 2023-01-20 17:26:03 +0000 |
---|---|---|
committer | jsing <> | 2023-01-20 17:26:03 +0000 |
commit | a50b434b87829ee0d12767c21ae98194684ab720 (patch) | |
tree | e3bd648b0409707ec556c3fb4a63555600a9eb16 /src/lib/libcrypto/bn/bn_asm.c | |
parent | 7eb968d539adfad40fdf827796365d0d38b3db5f (diff) | |
download | openbsd-a50b434b87829ee0d12767c21ae98194684ab720.tar.gz openbsd-a50b434b87829ee0d12767c21ae98194684ab720.tar.bz2 openbsd-a50b434b87829ee0d12767c21ae98194684ab720.zip |
Move {mul,sqr}_add_c{,2} macros from bn_asm.c to bn_local.h.
These depend on other macros that are in already in bn_local.h and this
makes them available to other source files. A lot more clean up will be
needed in the future.
Of course x86_64-gcc.c makes use of the same macro names - sprinkle some
undef in there for the time being.
ok tb@
Diffstat (limited to 'src/lib/libcrypto/bn/bn_asm.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_asm.c | 150 |
1 files changed, 1 insertions, 149 deletions
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c index e5627cf6de..84063486b3 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.17 2022/11/30 01:47:19 jsing Exp $ */ | 1 | /* $OpenBSD: bn_asm.c,v 1.18 2023/01/20 17:26: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 | * |
@@ -484,154 +484,6 @@ bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n) | |||
484 | #undef bn_sqr_comba8 | 484 | #undef bn_sqr_comba8 |
485 | #undef bn_sqr_comba4 | 485 | #undef bn_sqr_comba4 |
486 | 486 | ||
487 | /* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */ | ||
488 | /* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */ | ||
489 | /* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */ | ||
490 | /* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */ | ||
491 | |||
492 | #ifdef BN_LLONG | ||
493 | /* | ||
494 | * Keep in mind that additions to multiplication result can not | ||
495 | * overflow, because its high half cannot be all-ones. | ||
496 | */ | ||
497 | #define mul_add_c(a,b,c0,c1,c2) do { \ | ||
498 | BN_ULONG hi; \ | ||
499 | BN_ULLONG t = (BN_ULLONG)(a)*(b); \ | ||
500 | t += c0; /* no carry */ \ | ||
501 | c0 = (BN_ULONG)Lw(t); \ | ||
502 | hi = (BN_ULONG)Hw(t); \ | ||
503 | c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \ | ||
504 | } while(0) | ||
505 | |||
506 | #define mul_add_c2(a,b,c0,c1,c2) do { \ | ||
507 | BN_ULONG hi; \ | ||
508 | BN_ULLONG t = (BN_ULLONG)(a)*(b); \ | ||
509 | BN_ULLONG tt = t+c0; /* no carry */ \ | ||
510 | c0 = (BN_ULONG)Lw(tt); \ | ||
511 | hi = (BN_ULONG)Hw(tt); \ | ||
512 | c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \ | ||
513 | t += c0; /* no carry */ \ | ||
514 | c0 = (BN_ULONG)Lw(t); \ | ||
515 | hi = (BN_ULONG)Hw(t); \ | ||
516 | c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \ | ||
517 | } while(0) | ||
518 | |||
519 | #define sqr_add_c(a,i,c0,c1,c2) do { \ | ||
520 | BN_ULONG hi; \ | ||
521 | BN_ULLONG t = (BN_ULLONG)a[i]*a[i]; \ | ||
522 | t += c0; /* no carry */ \ | ||
523 | c0 = (BN_ULONG)Lw(t); \ | ||
524 | hi = (BN_ULONG)Hw(t); \ | ||
525 | c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \ | ||
526 | } while(0) | ||
527 | |||
528 | #define sqr_add_c2(a,i,j,c0,c1,c2) \ | ||
529 | mul_add_c2((a)[i],(a)[j],c0,c1,c2) | ||
530 | |||
531 | #elif defined(BN_UMULT_LOHI) | ||
532 | /* | ||
533 | * Keep in mind that additions to hi can not overflow, because | ||
534 | * the high word of a multiplication result cannot be all-ones. | ||
535 | */ | ||
536 | #define mul_add_c(a,b,c0,c1,c2) do { \ | ||
537 | BN_ULONG ta = (a), tb = (b); \ | ||
538 | BN_ULONG lo, hi; \ | ||
539 | BN_UMULT_LOHI(lo,hi,ta,tb); \ | ||
540 | c0 += lo; hi += (c0<lo)?1:0; \ | ||
541 | c1 += hi; c2 += (c1<hi)?1:0; \ | ||
542 | } while(0) | ||
543 | |||
544 | #define mul_add_c2(a,b,c0,c1,c2) do { \ | ||
545 | BN_ULONG ta = (a), tb = (b); \ | ||
546 | BN_ULONG lo, hi, tt; \ | ||
547 | BN_UMULT_LOHI(lo,hi,ta,tb); \ | ||
548 | c0 += lo; tt = hi+((c0<lo)?1:0); \ | ||
549 | c1 += tt; c2 += (c1<tt)?1:0; \ | ||
550 | c0 += lo; hi += (c0<lo)?1:0; \ | ||
551 | c1 += hi; c2 += (c1<hi)?1:0; \ | ||
552 | } while(0) | ||
553 | |||
554 | #define sqr_add_c(a,i,c0,c1,c2) do { \ | ||
555 | BN_ULONG ta = (a)[i]; \ | ||
556 | BN_ULONG lo, hi; \ | ||
557 | BN_UMULT_LOHI(lo,hi,ta,ta); \ | ||
558 | c0 += lo; hi += (c0<lo)?1:0; \ | ||
559 | c1 += hi; c2 += (c1<hi)?1:0; \ | ||
560 | } while(0) | ||
561 | |||
562 | #define sqr_add_c2(a,i,j,c0,c1,c2) \ | ||
563 | mul_add_c2((a)[i],(a)[j],c0,c1,c2) | ||
564 | |||
565 | #elif defined(BN_UMULT_HIGH) | ||
566 | /* | ||
567 | * Keep in mind that additions to hi can not overflow, because | ||
568 | * the high word of a multiplication result cannot be all-ones. | ||
569 | */ | ||
570 | #define mul_add_c(a,b,c0,c1,c2) do { \ | ||
571 | BN_ULONG ta = (a), tb = (b); \ | ||
572 | BN_ULONG lo = ta * tb; \ | ||
573 | BN_ULONG hi = BN_UMULT_HIGH(ta,tb); \ | ||
574 | c0 += lo; hi += (c0<lo)?1:0; \ | ||
575 | c1 += hi; c2 += (c1<hi)?1:0; \ | ||
576 | } while(0) | ||
577 | |||
578 | #define mul_add_c2(a,b,c0,c1,c2) do { \ | ||
579 | BN_ULONG ta = (a), tb = (b), tt; \ | ||
580 | BN_ULONG lo = ta * tb; \ | ||
581 | BN_ULONG hi = BN_UMULT_HIGH(ta,tb); \ | ||
582 | c0 += lo; tt = hi + ((c0<lo)?1:0); \ | ||
583 | c1 += tt; c2 += (c1<tt)?1:0; \ | ||
584 | c0 += lo; hi += (c0<lo)?1:0; \ | ||
585 | c1 += hi; c2 += (c1<hi)?1:0; \ | ||
586 | } while(0) | ||
587 | |||
588 | #define sqr_add_c(a,i,c0,c1,c2) do { \ | ||
589 | BN_ULONG ta = (a)[i]; \ | ||
590 | BN_ULONG lo = ta * ta; \ | ||
591 | BN_ULONG hi = BN_UMULT_HIGH(ta,ta); \ | ||
592 | c0 += lo; hi += (c0<lo)?1:0; \ | ||
593 | c1 += hi; c2 += (c1<hi)?1:0; \ | ||
594 | } while(0) | ||
595 | |||
596 | #define sqr_add_c2(a,i,j,c0,c1,c2) \ | ||
597 | mul_add_c2((a)[i],(a)[j],c0,c1,c2) | ||
598 | |||
599 | #else /* !BN_LLONG */ | ||
600 | /* | ||
601 | * Keep in mind that additions to hi can not overflow, because | ||
602 | * the high word of a multiplication result cannot be all-ones. | ||
603 | */ | ||
604 | #define mul_add_c(a,b,c0,c1,c2) do { \ | ||
605 | BN_ULONG lo = LBITS(a), hi = HBITS(a); \ | ||
606 | BN_ULONG bl = LBITS(b), bh = HBITS(b); \ | ||
607 | mul64(lo,hi,bl,bh); \ | ||
608 | c0 = (c0+lo)&BN_MASK2; if (c0<lo) hi++; \ | ||
609 | c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \ | ||
610 | } while(0) | ||
611 | |||
612 | #define mul_add_c2(a,b,c0,c1,c2) do { \ | ||
613 | BN_ULONG tt; \ | ||
614 | BN_ULONG lo = LBITS(a), hi = HBITS(a); \ | ||
615 | BN_ULONG bl = LBITS(b), bh = HBITS(b); \ | ||
616 | mul64(lo,hi,bl,bh); \ | ||
617 | tt = hi; \ | ||
618 | c0 = (c0+lo)&BN_MASK2; if (c0<lo) tt++; \ | ||
619 | c1 = (c1+tt)&BN_MASK2; if (c1<tt) c2++; \ | ||
620 | c0 = (c0+lo)&BN_MASK2; if (c0<lo) hi++; \ | ||
621 | c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \ | ||
622 | } while(0) | ||
623 | |||
624 | #define sqr_add_c(a,i,c0,c1,c2) do { \ | ||
625 | BN_ULONG lo, hi; \ | ||
626 | sqr64(lo,hi,(a)[i]); \ | ||
627 | c0 = (c0+lo)&BN_MASK2; if (c0<lo) hi++; \ | ||
628 | c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \ | ||
629 | } while(0) | ||
630 | |||
631 | #define sqr_add_c2(a,i,j,c0,c1,c2) \ | ||
632 | mul_add_c2((a)[i],(a)[j],c0,c1,c2) | ||
633 | #endif /* !BN_LLONG */ | ||
634 | |||
635 | void | 487 | void |
636 | bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) | 488 | bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) |
637 | { | 489 | { |