summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_nist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_nist.c')
-rw-r--r--src/lib/libcrypto/bn/bn_nist.c64
1 files changed, 28 insertions, 36 deletions
diff --git a/src/lib/libcrypto/bn/bn_nist.c b/src/lib/libcrypto/bn/bn_nist.c
index c6de032696..2ca5b01391 100644
--- a/src/lib/libcrypto/bn/bn_nist.c
+++ b/src/lib/libcrypto/bn/bn_nist.c
@@ -354,7 +354,7 @@ int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
354 buf[BN_NIST_192_TOP], 354 buf[BN_NIST_192_TOP],
355 c_d[BN_NIST_192_TOP], 355 c_d[BN_NIST_192_TOP],
356 *res; 356 *res;
357 PTR_SIZE_INT mask; 357 size_t mask;
358 static const BIGNUM _bignum_nist_p_192_sqr = { 358 static const BIGNUM _bignum_nist_p_192_sqr = {
359 (BN_ULONG *)_nist_p_192_sqr, 359 (BN_ULONG *)_nist_p_192_sqr,
360 sizeof(_nist_p_192_sqr)/sizeof(_nist_p_192_sqr[0]), 360 sizeof(_nist_p_192_sqr)/sizeof(_nist_p_192_sqr[0]),
@@ -405,10 +405,9 @@ int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
405 * 'tmp=result-modulus; if (!carry || !borrow) result=tmp;' 405 * 'tmp=result-modulus; if (!carry || !borrow) result=tmp;'
406 * this is what happens below, but without explicit if:-) a. 406 * this is what happens below, but without explicit if:-) a.
407 */ 407 */
408 mask = 0-(PTR_SIZE_INT)bn_sub_words(c_d,r_d,_nist_p_192[0],BN_NIST_192_TOP); 408 mask = 0-(size_t)bn_sub_words(c_d,r_d,_nist_p_192[0],BN_NIST_192_TOP);
409 mask &= 0-(PTR_SIZE_INT)carry; 409 mask &= 0-(size_t)carry;
410 res = (BN_ULONG *) 410 res = (BN_ULONG *)(((size_t)c_d&~mask) | ((size_t)r_d&mask));
411 (((PTR_SIZE_INT)c_d&~mask) | ((PTR_SIZE_INT)r_d&mask));
412 nist_cp_bn(r_d, res, BN_NIST_192_TOP); 411 nist_cp_bn(r_d, res, BN_NIST_192_TOP);
413 r->top = BN_NIST_192_TOP; 412 r->top = BN_NIST_192_TOP;
414 bn_correct_top(r); 413 bn_correct_top(r);
@@ -439,8 +438,8 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
439 buf[BN_NIST_224_TOP], 438 buf[BN_NIST_224_TOP],
440 c_d[BN_NIST_224_TOP], 439 c_d[BN_NIST_224_TOP],
441 *res; 440 *res;
442 PTR_SIZE_INT mask; 441 size_t mask;
443 union { bn_addsub_f f; PTR_SIZE_INT p; } u; 442 union { bn_addsub_f f; size_t p; } u;
444 static const BIGNUM _bignum_nist_p_224_sqr = { 443 static const BIGNUM _bignum_nist_p_224_sqr = {
445 (BN_ULONG *)_nist_p_224_sqr, 444 (BN_ULONG *)_nist_p_224_sqr,
446 sizeof(_nist_p_224_sqr)/sizeof(_nist_p_224_sqr[0]), 445 sizeof(_nist_p_224_sqr)/sizeof(_nist_p_224_sqr[0]),
@@ -511,18 +510,16 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
511 * to be compared to the modulus and conditionally 510 * to be compared to the modulus and conditionally
512 * adjusted by *subtracting* the latter. */ 511 * adjusted by *subtracting* the latter. */
513 carry = (int)bn_add_words(r_d,r_d,_nist_p_224[-carry-1],BN_NIST_224_TOP); 512 carry = (int)bn_add_words(r_d,r_d,_nist_p_224[-carry-1],BN_NIST_224_TOP);
514 mask = 0-(PTR_SIZE_INT)carry; 513 mask = 0-(size_t)carry;
515 u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | 514 u.p = ((size_t)bn_sub_words&mask) | ((size_t)bn_add_words&~mask);
516 ((PTR_SIZE_INT)bn_add_words&~mask);
517 } 515 }
518 else 516 else
519 carry = 1; 517 carry = 1;
520 518
521 /* otherwise it's effectively same as in BN_nist_mod_192... */ 519 /* otherwise it's effectively same as in BN_nist_mod_192... */
522 mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP); 520 mask = 0-(size_t)(*u.f)(c_d,r_d,_nist_p_224[0],BN_NIST_224_TOP);
523 mask &= 0-(PTR_SIZE_INT)carry; 521 mask &= 0-(size_t)carry;
524 res = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) | 522 res = (BN_ULONG *)(((size_t)c_d&~mask) | ((size_t)r_d&mask));
525 ((PTR_SIZE_INT)r_d&mask));
526 nist_cp_bn(r_d, res, BN_NIST_224_TOP); 523 nist_cp_bn(r_d, res, BN_NIST_224_TOP);
527 r->top = BN_NIST_224_TOP; 524 r->top = BN_NIST_224_TOP;
528 bn_correct_top(r); 525 bn_correct_top(r);
@@ -552,8 +549,8 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
552 buf[BN_NIST_256_TOP], 549 buf[BN_NIST_256_TOP],
553 c_d[BN_NIST_256_TOP], 550 c_d[BN_NIST_256_TOP],
554 *res; 551 *res;
555 PTR_SIZE_INT mask; 552 size_t mask;
556 union { bn_addsub_f f; PTR_SIZE_INT p; } u; 553 union { bn_addsub_f f; size_t p; } u;
557 static const BIGNUM _bignum_nist_p_256_sqr = { 554 static const BIGNUM _bignum_nist_p_256_sqr = {
558 (BN_ULONG *)_nist_p_256_sqr, 555 (BN_ULONG *)_nist_p_256_sqr,
559 sizeof(_nist_p_256_sqr)/sizeof(_nist_p_256_sqr[0]), 556 sizeof(_nist_p_256_sqr)/sizeof(_nist_p_256_sqr[0]),
@@ -632,17 +629,15 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
632 else if (carry < 0) 629 else if (carry < 0)
633 { 630 {
634 carry = (int)bn_add_words(r_d,r_d,_nist_p_256[-carry-1],BN_NIST_256_TOP); 631 carry = (int)bn_add_words(r_d,r_d,_nist_p_256[-carry-1],BN_NIST_256_TOP);
635 mask = 0-(PTR_SIZE_INT)carry; 632 mask = 0-(size_t)carry;
636 u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | 633 u.p = ((size_t)bn_sub_words&mask) | ((size_t)bn_add_words&~mask);
637 ((PTR_SIZE_INT)bn_add_words&~mask);
638 } 634 }
639 else 635 else
640 carry = 1; 636 carry = 1;
641 637
642 mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP); 638 mask = 0-(size_t)(*u.f)(c_d,r_d,_nist_p_256[0],BN_NIST_256_TOP);
643 mask &= 0-(PTR_SIZE_INT)carry; 639 mask &= 0-(size_t)carry;
644 res = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) | 640 res = (BN_ULONG *)(((size_t)c_d&~mask) | ((size_t)r_d&mask));
645 ((PTR_SIZE_INT)r_d&mask));
646 nist_cp_bn(r_d, res, BN_NIST_256_TOP); 641 nist_cp_bn(r_d, res, BN_NIST_256_TOP);
647 r->top = BN_NIST_256_TOP; 642 r->top = BN_NIST_256_TOP;
648 bn_correct_top(r); 643 bn_correct_top(r);
@@ -676,8 +671,8 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
676 buf[BN_NIST_384_TOP], 671 buf[BN_NIST_384_TOP],
677 c_d[BN_NIST_384_TOP], 672 c_d[BN_NIST_384_TOP],
678 *res; 673 *res;
679 PTR_SIZE_INT mask; 674 size_t mask;
680 union { bn_addsub_f f; PTR_SIZE_INT p; } u; 675 union { bn_addsub_f f; size_t p; } u;
681 static const BIGNUM _bignum_nist_p_384_sqr = { 676 static const BIGNUM _bignum_nist_p_384_sqr = {
682 (BN_ULONG *)_nist_p_384_sqr, 677 (BN_ULONG *)_nist_p_384_sqr,
683 sizeof(_nist_p_384_sqr)/sizeof(_nist_p_384_sqr[0]), 678 sizeof(_nist_p_384_sqr)/sizeof(_nist_p_384_sqr[0]),
@@ -759,17 +754,15 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
759 else if (carry < 0) 754 else if (carry < 0)
760 { 755 {
761 carry = (int)bn_add_words(r_d,r_d,_nist_p_384[-carry-1],BN_NIST_384_TOP); 756 carry = (int)bn_add_words(r_d,r_d,_nist_p_384[-carry-1],BN_NIST_384_TOP);
762 mask = 0-(PTR_SIZE_INT)carry; 757 mask = 0-(size_t)carry;
763 u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | 758 u.p = ((size_t)bn_sub_words&mask) | ((size_t)bn_add_words&~mask);
764 ((PTR_SIZE_INT)bn_add_words&~mask);
765 } 759 }
766 else 760 else
767 carry = 1; 761 carry = 1;
768 762
769 mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP); 763 mask = 0-(size_t)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP);
770 mask &= 0-(PTR_SIZE_INT)carry; 764 mask &= 0-(size_t)carry;
771 res = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) | 765 res = (BN_ULONG *)(((size_t)c_d&~mask) | ((size_t)r_d&mask));
772 ((PTR_SIZE_INT)r_d&mask));
773 nist_cp_bn(r_d, res, BN_NIST_384_TOP); 766 nist_cp_bn(r_d, res, BN_NIST_384_TOP);
774 r->top = BN_NIST_384_TOP; 767 r->top = BN_NIST_384_TOP;
775 bn_correct_top(r); 768 bn_correct_top(r);
@@ -788,7 +781,7 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
788 BN_ULONG *r_d, *a_d = a->d, 781 BN_ULONG *r_d, *a_d = a->d,
789 t_d[BN_NIST_521_TOP], 782 t_d[BN_NIST_521_TOP],
790 val,tmp,*res; 783 val,tmp,*res;
791 PTR_SIZE_INT mask; 784 size_t mask;
792 static const BIGNUM _bignum_nist_p_521_sqr = { 785 static const BIGNUM _bignum_nist_p_521_sqr = {
793 (BN_ULONG *)_nist_p_521_sqr, 786 (BN_ULONG *)_nist_p_521_sqr,
794 sizeof(_nist_p_521_sqr)/sizeof(_nist_p_521_sqr[0]), 787 sizeof(_nist_p_521_sqr)/sizeof(_nist_p_521_sqr[0]),
@@ -833,9 +826,8 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
833 r_d[i] &= BN_NIST_521_TOP_MASK; 826 r_d[i] &= BN_NIST_521_TOP_MASK;
834 827
835 bn_add_words(r_d,r_d,t_d,BN_NIST_521_TOP); 828 bn_add_words(r_d,r_d,t_d,BN_NIST_521_TOP);
836 mask = 0-(PTR_SIZE_INT)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP); 829 mask = 0-(size_t)bn_sub_words(t_d,r_d,_nist_p_521,BN_NIST_521_TOP);
837 res = (BN_ULONG *)(((PTR_SIZE_INT)t_d&~mask) | 830 res = (BN_ULONG *)(((size_t)t_d&~mask) | ((size_t)r_d&mask));
838 ((PTR_SIZE_INT)r_d&mask));
839 nist_cp_bn(r_d,res,BN_NIST_521_TOP); 831 nist_cp_bn(r_d,res,BN_NIST_521_TOP);
840 r->top = BN_NIST_521_TOP; 832 r->top = BN_NIST_521_TOP;
841 bn_correct_top(r); 833 bn_correct_top(r);