388
nist_cp_bn_0(buf, a_d + BN_NIST_192_TOP, top - BN_NIST_192_TOP, BN_NIST_192_TOP);
390
nist_set_192(t_d, buf, 0, 3, 3);
399
nist_cp_bn_0(buf.bn, a_d + BN_NIST_192_TOP, top - BN_NIST_192_TOP, BN_NIST_192_TOP);
401
#if defined(NIST_INT64)
403
NIST_INT64 acc; /* accumulator */
404
unsigned int *rp=(unsigned int *)r_d;
405
const unsigned int *bp=(const unsigned int *)buf.ui;
407
acc = rp[0]; acc += bp[3*2-6];
408
acc += bp[5*2-6]; rp[0] = (unsigned int)acc; acc >>= 32;
410
acc += rp[1]; acc += bp[3*2-5];
411
acc += bp[5*2-5]; rp[1] = (unsigned int)acc; acc >>= 32;
413
acc += rp[2]; acc += bp[3*2-6];
415
acc += bp[5*2-6]; rp[2] = (unsigned int)acc; acc >>= 32;
417
acc += rp[3]; acc += bp[3*2-5];
419
acc += bp[5*2-5]; rp[3] = (unsigned int)acc; acc >>= 32;
421
acc += rp[4]; acc += bp[4*2-6];
422
acc += bp[5*2-6]; rp[4] = (unsigned int)acc; acc >>= 32;
424
acc += rp[5]; acc += bp[4*2-5];
425
acc += bp[5*2-5]; rp[5] = (unsigned int)acc;
427
carry = (int)(acc>>32);
431
BN_ULONG t_d[BN_NIST_192_TOP];
433
nist_set_192(t_d, buf.bn, 0, 3, 3);
391
434
carry = (int)bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
392
nist_set_192(t_d, buf, 4, 4, 0);
393
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
394
nist_set_192(t_d, buf, 5, 5, 5)
395
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
435
nist_set_192(t_d, buf.bn, 4, 4, 0);
436
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
437
nist_set_192(t_d, buf.bn, 5, 5, 5)
438
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
398
442
carry = (int)bn_sub_words(r_d,r_d,_nist_p_192[carry-1],BN_NIST_192_TOP);
476
519
/* copy upper 256 bits of 448 bit number ... */
477
nist_cp_bn_0(t_d, a_d + (BN_NIST_224_TOP-1), top - (BN_NIST_224_TOP-1), BN_NIST_224_TOP);
520
nist_cp_bn_0(c_d, a_d + (BN_NIST_224_TOP-1), top - (BN_NIST_224_TOP-1), BN_NIST_224_TOP);
478
521
/* ... and right shift by 32 to obtain upper 224 bits */
479
nist_set_224(buf, t_d, 14, 13, 12, 11, 10, 9, 8);
522
nist_set_224(buf, c_d, 14, 13, 12, 11, 10, 9, 8);
480
523
/* truncate lower part to 224 bits too */
481
524
r_d[BN_NIST_224_TOP-1] &= BN_MASK2l;
483
526
nist_cp_bn_0(buf, a_d + BN_NIST_224_TOP, top - BN_NIST_224_TOP, BN_NIST_224_TOP);
529
#if defined(NIST_INT64) && BN_BITS2!=64
531
NIST_INT64 acc; /* accumulator */
532
unsigned int *rp=(unsigned int *)r_d;
533
const unsigned int *bp=(const unsigned int *)buf;
535
acc = rp[0]; acc -= bp[7-7];
536
acc -= bp[11-7]; rp[0] = (unsigned int)acc; acc >>= 32;
538
acc += rp[1]; acc -= bp[8-7];
539
acc -= bp[12-7]; rp[1] = (unsigned int)acc; acc >>= 32;
541
acc += rp[2]; acc -= bp[9-7];
542
acc -= bp[13-7]; rp[2] = (unsigned int)acc; acc >>= 32;
544
acc += rp[3]; acc += bp[7-7];
546
acc -= bp[10-7]; rp[3] = (unsigned int)acc; acc>>= 32;
548
acc += rp[4]; acc += bp[8-7];
550
acc -= bp[11-7]; rp[4] = (unsigned int)acc; acc >>= 32;
552
acc += rp[5]; acc += bp[9-7];
554
acc -= bp[12-7]; rp[5] = (unsigned int)acc; acc >>= 32;
556
acc += rp[6]; acc += bp[10-7];
557
acc -= bp[13-7]; rp[6] = (unsigned int)acc;
559
carry = (int)(acc>>32);
566
BN_ULONG t_d[BN_NIST_224_TOP];
485
568
nist_set_224(t_d, buf, 10, 9, 8, 7, 0, 0, 0);
486
569
carry = (int)bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP);
487
570
nist_set_224(t_d, buf, 0, 13, 12, 11, 0, 0, 0);
587
nist_cp_bn_0(buf, a_d + BN_NIST_256_TOP, top - BN_NIST_256_TOP, BN_NIST_256_TOP);
674
nist_cp_bn_0(buf.bn, a_d + BN_NIST_256_TOP, top - BN_NIST_256_TOP, BN_NIST_256_TOP);
676
#if defined(NIST_INT64)
678
NIST_INT64 acc; /* accumulator */
679
unsigned int *rp=(unsigned int *)r_d;
680
const unsigned int *bp=(const unsigned int *)buf.ui;
682
acc = rp[0]; acc += bp[8-8];
687
acc -= bp[14-8]; rp[0] = (unsigned int)acc; acc >>= 32;
689
acc += rp[1]; acc += bp[9-8];
694
acc -= bp[15-8]; rp[1] = (unsigned int)acc; acc >>= 32;
696
acc += rp[2]; acc += bp[10-8];
700
acc -= bp[15-8]; rp[2] = (unsigned int)acc; acc >>= 32;
702
acc += rp[3]; acc += bp[11-8];
709
acc -= bp[9-8]; rp[3] = (unsigned int)acc; acc >>= 32;
711
acc += rp[4]; acc += bp[12-8];
717
acc -= bp[10-8]; rp[4] = (unsigned int)acc; acc >>= 32;
719
acc += rp[5]; acc += bp[13-8];
725
acc -= bp[11-8]; rp[5] = (unsigned int)acc; acc >>= 32;
727
acc += rp[6]; acc += bp[14-8];
734
acc -= bp[9-8]; rp[6] = (unsigned int)acc; acc >>= 32;
736
acc += rp[7]; acc += bp[15-8];
743
acc -= bp[13-8]; rp[7] = (unsigned int)acc;
745
carry = (int)(acc>>32);
749
BN_ULONG t_d[BN_NIST_256_TOP];
590
nist_set_256(t_d, buf, 15, 14, 13, 12, 11, 0, 0, 0);
752
nist_set_256(t_d, buf.bn, 15, 14, 13, 12, 11, 0, 0, 0);
592
nist_set_256(c_d, buf, 0, 15, 14, 13, 12, 0, 0, 0);
754
nist_set_256(c_d, buf.bn, 0, 15, 14, 13, 12, 0, 0, 0);
593
755
carry = (int)bn_add_words(t_d, t_d, c_d, BN_NIST_256_TOP);
608
770
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
610
nist_set_256(t_d, buf, 15, 14, 0, 0, 0, 10, 9, 8);
772
nist_set_256(t_d, buf.bn, 15, 14, 0, 0, 0, 10, 9, 8);
611
773
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
613
nist_set_256(t_d, buf, 8, 13, 15, 14, 13, 11, 10, 9);
775
nist_set_256(t_d, buf.bn, 8, 13, 15, 14, 13, 11, 10, 9);
614
776
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
616
nist_set_256(t_d, buf, 10, 8, 0, 0, 0, 13, 12, 11);
778
nist_set_256(t_d, buf.bn, 10, 8, 0, 0, 0, 13, 12, 11);
617
779
carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
619
nist_set_256(t_d, buf, 11, 9, 0, 0, 15, 14, 13, 12);
781
nist_set_256(t_d, buf.bn, 11, 9, 0, 0, 15, 14, 13, 12);
620
782
carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
622
nist_set_256(t_d, buf, 12, 0, 10, 9, 8, 15, 14, 13);
784
nist_set_256(t_d, buf.bn, 12, 0, 10, 9, 8, 15, 14, 13);
623
785
carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
625
nist_set_256(t_d, buf, 13, 0, 11, 10, 9, 0, 15, 14);
787
nist_set_256(t_d, buf.bn, 13, 0, 11, 10, 9, 0, 15, 14);
626
788
carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
628
792
/* see BN_nist_mod_224 for explanation */
629
793
u.f = bn_sub_words;
712
nist_cp_bn_0(buf, a_d + BN_NIST_384_TOP, top - BN_NIST_384_TOP, BN_NIST_384_TOP);
878
nist_cp_bn_0(buf.bn, a_d + BN_NIST_384_TOP, top - BN_NIST_384_TOP, BN_NIST_384_TOP);
880
#if defined(NIST_INT64)
882
NIST_INT64 acc; /* accumulator */
883
unsigned int *rp=(unsigned int *)r_d;
884
const unsigned int *bp=(const unsigned int *)buf.ui;
886
acc = rp[0]; acc += bp[12-12];
889
acc -= bp[23-12]; rp[0] = (unsigned int)acc; acc >>= 32;
891
acc += rp[1]; acc += bp[13-12];
895
acc -= bp[20-12]; rp[1] = (unsigned int)acc; acc >>= 32;
897
acc += rp[2]; acc += bp[14-12];
900
acc -= bp[21-12]; rp[2] = (unsigned int)acc; acc >>= 32;
902
acc += rp[3]; acc += bp[15-12];
908
acc -= bp[23-12]; rp[3] = (unsigned int)acc; acc >>= 32;
910
acc += rp[4]; acc += bp[21-12];
919
acc -= bp[23-12]; rp[4] = (unsigned int)acc; acc >>= 32;
921
acc += rp[5]; acc += bp[22-12];
928
acc -= bp[16-12]; rp[5] = (unsigned int)acc; acc >>= 32;
930
acc += rp[6]; acc += bp[23-12];
936
acc -= bp[17-12]; rp[6] = (unsigned int)acc; acc >>= 32;
938
acc += rp[7]; acc += bp[19-12];
942
acc -= bp[18-12]; rp[7] = (unsigned int)acc; acc >>= 32;
944
acc += rp[8]; acc += bp[20-12];
947
acc -= bp[19-12]; rp[8] = (unsigned int)acc; acc >>= 32;
949
acc += rp[9]; acc += bp[21-12];
952
acc -= bp[20-12]; rp[9] = (unsigned int)acc; acc >>= 32;
954
acc += rp[10]; acc += bp[22-12];
957
acc -= bp[21-12]; rp[10] = (unsigned int)acc; acc >>= 32;
959
acc += rp[11]; acc += bp[23-12];
962
acc -= bp[22-12]; rp[11] = (unsigned int)acc;
964
carry = (int)(acc>>32);
968
BN_ULONG t_d[BN_NIST_384_TOP];
715
nist_set_256(t_d, buf, 0, 0, 0, 0, 0, 23-4, 22-4, 21-4);
971
nist_set_256(t_d, buf.bn, 0, 0, 0, 0, 0, 23-4, 22-4, 21-4);
718
974
register BN_ULONG *ap,t,c;
729
985
carry = (int)bn_add_words(r_d+(128/BN_BITS2), r_d+(128/BN_BITS2),
730
986
t_d, BN_NIST_256_TOP);
732
carry += (int)bn_add_words(r_d, r_d, buf, BN_NIST_384_TOP);
988
carry += (int)bn_add_words(r_d, r_d, buf.bn, BN_NIST_384_TOP);
734
nist_set_384(t_d,buf,20,19,18,17,16,15,14,13,12,23,22,21);
990
nist_set_384(t_d,buf.bn,20,19,18,17,16,15,14,13,12,23,22,21);
735
991
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
737
nist_set_384(t_d,buf,19,18,17,16,15,14,13,12,20,0,23,0);
993
nist_set_384(t_d,buf.bn,19,18,17,16,15,14,13,12,20,0,23,0);
738
994
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
740
nist_set_384(t_d, buf,0,0,0,0,23,22,21,20,0,0,0,0);
996
nist_set_384(t_d, buf.bn,0,0,0,0,23,22,21,20,0,0,0,0);
741
997
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
743
nist_set_384(t_d,buf,0,0,0,0,0,0,23,22,21,0,0,20);
999
nist_set_384(t_d,buf.bn,0,0,0,0,0,0,23,22,21,0,0,20);
744
1000
carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
746
nist_set_384(t_d,buf,22,21,20,19,18,17,16,15,14,13,12,23);
1002
nist_set_384(t_d,buf.bn,22,21,20,19,18,17,16,15,14,13,12,23);
747
1003
carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);
749
nist_set_384(t_d,buf,0,0,0,0,0,0,0,23,22,21,20,0);
1005
nist_set_384(t_d,buf.bn,0,0,0,0,0,0,0,23,22,21,20,0);
750
1006
carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);
752
nist_set_384(t_d,buf,0,0,0,0,0,0,0,23,23,0,0,0);
1008
nist_set_384(t_d,buf.bn,0,0,0,0,0,0,0,23,23,0,0,0);
753
1009
carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);
755
1013
/* see BN_nist_mod_224 for explanation */
756
1014
u.f = bn_sub_words;