~ubuntu-branches/ubuntu/utopic/openssl/utopic

« back to all changes in this revision

Viewing changes to crypto/bn/bn_nist.c

  • Committer: Package Import Robot
  • Author(s): Kurt Roeckx
  • Date: 2012-03-19 18:23:32 UTC
  • mfrom: (1.2.6)
  • mto: This revision was merged to the branch mainline in revision 64.
  • Revision ID: package-import@ubuntu.com-20120319182332-q4zgqvw51ahauk27
Tags: 1.0.1-1
* New upstream version
  - Remove kfreebsd-pipe.patch, fixed upstream
  - Update pic.patch, openssl-pod-misspell.patch and make-targets.patch
  - Add OPENSSL_1.0.1 to version-script.patch and libssl1.0.0.symbols for
    the new functions.
  - AES-NI support (Closes: #644743)
* pic.patch: upstream made OPENSSL_ia32cap_P and OPENSSL_cpuid_setup
  hidden on amd64, no need to access it PIC anymore.
* pic.patch: Make OPENSSL_ia32cap_P hidden on i386 too (Closes: #663977)
* Enable hardening using dpkg-buildflags (Closes: #653495)
* s_client and s_server were forcing SSLv3 only connection when SSLv2 was
  disabled instead of the SSLv2 with upgrade method.  (Closes: #664454)
* Add Beaks on openssh < 1:5.9p1-4, it has a too strict version check.

Show diffs side-by-side

added added

removed removed

Lines of Context:
319
319
                                                :(to[(n)/2] =((m)&1)?(from[(m)/2]>>32):(from[(m)/2]&BN_MASK2l)))
320
320
#define bn_32_set_0(to, n)              (((n)&1)?(to[(n)/2]&=BN_MASK2l):(to[(n)/2]=0));
321
321
#define bn_cp_32(to,n,from,m)           ((m)>=0)?bn_cp_32_naked(to,n,from,m):bn_32_set_0(to,n)
 
322
# if defined(L_ENDIAN)
 
323
#  if defined(__arch64__)
 
324
#   define NIST_INT64 long
 
325
#  else
 
326
#   define NIST_INT64 long long
 
327
#  endif
 
328
# endif
322
329
#else
323
330
#define bn_cp_64(to, n, from, m) \
324
331
        { \
330
337
        bn_32_set_0(to, (n)*2); \
331
338
        bn_32_set_0(to, (n)*2+1); \
332
339
        }
333
 
#if BN_BITS2 == 32
334
340
#define bn_cp_32(to, n, from, m)        (to)[n] = (m>=0)?((from)[m]):0;
335
341
#define bn_32_set_0(to, n)              (to)[n] = (BN_ULONG)0;
336
 
#endif
 
342
# if defined(_WIN32) && !defined(__GNUC__)
 
343
#  define NIST_INT64 __int64
 
344
# elif defined(BN_LLONG)
 
345
#  define NIST_INT64 long long
 
346
# endif
337
347
#endif /* BN_BITS2 != 64 */
338
348
 
339
 
 
340
349
#define nist_set_192(to, from, a1, a2, a3) \
341
350
        { \
342
351
        bn_cp_64(to, 0, from, (a3) - 3) \
350
359
        int      top = a->top, i;
351
360
        int      carry;
352
361
        register BN_ULONG *r_d, *a_d = a->d;
353
 
        BN_ULONG t_d[BN_NIST_192_TOP],
354
 
                 buf[BN_NIST_192_TOP],
355
 
                 c_d[BN_NIST_192_TOP],
 
362
        union   {
 
363
                BN_ULONG        bn[BN_NIST_192_TOP];
 
364
                unsigned int    ui[BN_NIST_192_TOP*sizeof(BN_ULONG)/sizeof(unsigned int)];
 
365
                } buf;
 
366
        BN_ULONG c_d[BN_NIST_192_TOP],
356
367
                *res;
357
368
        PTR_SIZE_INT mask;
358
369
        static const BIGNUM _bignum_nist_p_192_sqr = {
385
396
        else
386
397
                r_d = a_d;
387
398
 
388
 
        nist_cp_bn_0(buf, a_d + BN_NIST_192_TOP, top - BN_NIST_192_TOP, BN_NIST_192_TOP);
389
 
 
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);
 
400
 
 
401
#if defined(NIST_INT64)
 
402
        {
 
403
        NIST_INT64              acc;    /* accumulator */
 
404
        unsigned int            *rp=(unsigned int *)r_d;
 
405
        const unsigned int      *bp=(const unsigned int *)buf.ui;
 
406
 
 
407
        acc  = rp[0];   acc += bp[3*2-6];
 
408
                        acc += bp[5*2-6]; rp[0] = (unsigned int)acc; acc >>= 32;
 
409
 
 
410
        acc += rp[1];   acc += bp[3*2-5];
 
411
                        acc += bp[5*2-5]; rp[1] = (unsigned int)acc; acc >>= 32;
 
412
 
 
413
        acc += rp[2];   acc += bp[3*2-6];
 
414
                        acc += bp[4*2-6];
 
415
                        acc += bp[5*2-6]; rp[2] = (unsigned int)acc; acc >>= 32;
 
416
 
 
417
        acc += rp[3];   acc += bp[3*2-5];
 
418
                        acc += bp[4*2-5];
 
419
                        acc += bp[5*2-5]; rp[3] = (unsigned int)acc; acc >>= 32;
 
420
 
 
421
        acc += rp[4];   acc += bp[4*2-6];
 
422
                        acc += bp[5*2-6]; rp[4] = (unsigned int)acc; acc >>= 32;
 
423
 
 
424
        acc += rp[5];   acc += bp[4*2-5];
 
425
                        acc += bp[5*2-5]; rp[5] = (unsigned int)acc;
 
426
 
 
427
        carry = (int)(acc>>32);
 
428
        }
 
429
#else
 
430
        {
 
431
        BN_ULONG t_d[BN_NIST_192_TOP];
 
432
 
 
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);
396
 
 
 
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);
 
439
        }
 
440
#endif
397
441
        if (carry > 0)
398
442
                carry = (int)bn_sub_words(r_d,r_d,_nist_p_192[carry-1],BN_NIST_192_TOP);
399
443
        else
435
479
        int     top = a->top, i;
436
480
        int     carry;
437
481
        BN_ULONG *r_d, *a_d = a->d;
438
 
        BN_ULONG t_d[BN_NIST_224_TOP],
439
 
                 buf[BN_NIST_224_TOP],
 
482
        BN_ULONG buf[BN_NIST_224_TOP],
440
483
                 c_d[BN_NIST_224_TOP],
441
484
                *res;
442
485
        PTR_SIZE_INT mask;
474
517
 
475
518
#if BN_BITS2==64
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;
482
525
#else
483
526
        nist_cp_bn_0(buf, a_d + BN_NIST_224_TOP, top - BN_NIST_224_TOP, BN_NIST_224_TOP);
484
527
#endif
 
528
 
 
529
#if defined(NIST_INT64) && BN_BITS2!=64
 
530
        {
 
531
        NIST_INT64              acc;    /* accumulator */
 
532
        unsigned int            *rp=(unsigned int *)r_d;
 
533
        const unsigned int      *bp=(const unsigned int *)buf;
 
534
 
 
535
        acc  = rp[0];   acc -= bp[7-7];
 
536
                        acc -= bp[11-7]; rp[0] = (unsigned int)acc; acc >>= 32;
 
537
 
 
538
        acc += rp[1];   acc -= bp[8-7];
 
539
                        acc -= bp[12-7]; rp[1] = (unsigned int)acc; acc >>= 32;
 
540
 
 
541
        acc += rp[2];   acc -= bp[9-7];
 
542
                        acc -= bp[13-7]; rp[2] = (unsigned int)acc; acc >>= 32;
 
543
 
 
544
        acc += rp[3];   acc += bp[7-7];
 
545
                        acc += bp[11-7];
 
546
                        acc -= bp[10-7]; rp[3] = (unsigned int)acc; acc>>= 32;
 
547
 
 
548
        acc += rp[4];   acc += bp[8-7];
 
549
                        acc += bp[12-7];
 
550
                        acc -= bp[11-7]; rp[4] = (unsigned int)acc; acc >>= 32;
 
551
 
 
552
        acc += rp[5];   acc += bp[9-7];
 
553
                        acc += bp[13-7];
 
554
                        acc -= bp[12-7]; rp[5] = (unsigned int)acc; acc >>= 32;
 
555
 
 
556
        acc += rp[6];   acc += bp[10-7];
 
557
                        acc -= bp[13-7]; rp[6] = (unsigned int)acc;
 
558
 
 
559
        carry = (int)(acc>>32);
 
560
# if BN_BITS2==64
 
561
        rp[7] = carry;
 
562
# endif
 
563
        }       
 
564
#else
 
565
        {
 
566
        BN_ULONG t_d[BN_NIST_224_TOP];
 
567
 
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);
494
577
#if BN_BITS2==64
495
578
        carry = (int)(r_d[BN_NIST_224_TOP-1]>>32);
496
579
#endif
 
580
        }
 
581
#endif
497
582
        u.f = bn_sub_words;
498
583
        if (carry > 0)
499
584
                {
548
633
        int     i, top = a->top;
549
634
        int     carry = 0;
550
635
        register BN_ULONG *a_d = a->d, *r_d;
551
 
        BN_ULONG t_d[BN_NIST_256_TOP],
552
 
                 buf[BN_NIST_256_TOP],
553
 
                 c_d[BN_NIST_256_TOP],
 
636
        union   {
 
637
                BN_ULONG bn[BN_NIST_256_TOP];
 
638
                unsigned int ui[BN_NIST_256_TOP*sizeof(BN_ULONG)/sizeof(unsigned int)];
 
639
                } buf;
 
640
        BN_ULONG c_d[BN_NIST_256_TOP],
554
641
                *res;
555
642
        PTR_SIZE_INT mask;
556
643
        union { bn_addsub_f f; PTR_SIZE_INT p; } u;
584
671
        else
585
672
                r_d = a_d;
586
673
 
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);
 
675
 
 
676
#if defined(NIST_INT64)
 
677
        {
 
678
        NIST_INT64              acc;    /* accumulator */
 
679
        unsigned int            *rp=(unsigned int *)r_d;
 
680
        const unsigned int      *bp=(const unsigned int *)buf.ui;
 
681
 
 
682
        acc = rp[0];    acc += bp[8-8];
 
683
                        acc += bp[9-8];
 
684
                        acc -= bp[11-8];
 
685
                        acc -= bp[12-8];
 
686
                        acc -= bp[13-8];
 
687
                        acc -= bp[14-8]; rp[0] = (unsigned int)acc; acc >>= 32;
 
688
 
 
689
        acc += rp[1];   acc += bp[9-8];
 
690
                        acc += bp[10-8];
 
691
                        acc -= bp[12-8];
 
692
                        acc -= bp[13-8];
 
693
                        acc -= bp[14-8];
 
694
                        acc -= bp[15-8]; rp[1] = (unsigned int)acc; acc >>= 32;
 
695
 
 
696
        acc += rp[2];   acc += bp[10-8];
 
697
                        acc += bp[11-8];
 
698
                        acc -= bp[13-8];
 
699
                        acc -= bp[14-8];
 
700
                        acc -= bp[15-8]; rp[2] = (unsigned int)acc; acc >>= 32;
 
701
 
 
702
        acc += rp[3];   acc += bp[11-8];
 
703
                        acc += bp[11-8];
 
704
                        acc += bp[12-8];
 
705
                        acc += bp[12-8];
 
706
                        acc += bp[13-8];
 
707
                        acc -= bp[15-8];
 
708
                        acc -= bp[8-8];
 
709
                        acc -= bp[9-8];  rp[3] = (unsigned int)acc; acc >>= 32;
 
710
 
 
711
        acc += rp[4];   acc += bp[12-8];
 
712
                        acc += bp[12-8];
 
713
                        acc += bp[13-8];
 
714
                        acc += bp[13-8];
 
715
                        acc += bp[14-8];
 
716
                        acc -= bp[9-8];
 
717
                        acc -= bp[10-8]; rp[4] = (unsigned int)acc; acc >>= 32;
 
718
 
 
719
        acc += rp[5];   acc += bp[13-8];
 
720
                        acc += bp[13-8];
 
721
                        acc += bp[14-8];
 
722
                        acc += bp[14-8];
 
723
                        acc += bp[15-8];
 
724
                        acc -= bp[10-8];
 
725
                        acc -= bp[11-8]; rp[5] = (unsigned int)acc; acc >>= 32;
 
726
 
 
727
        acc += rp[6];   acc += bp[14-8];
 
728
                        acc += bp[14-8];
 
729
                        acc += bp[15-8];
 
730
                        acc += bp[15-8];
 
731
                        acc += bp[14-8];
 
732
                        acc += bp[13-8];
 
733
                        acc -= bp[8-8];
 
734
                        acc -= bp[9-8];  rp[6] = (unsigned int)acc; acc >>= 32;
 
735
 
 
736
        acc += rp[7];   acc += bp[15-8];
 
737
                        acc += bp[15-8];
 
738
                        acc += bp[15-8];
 
739
                        acc += bp[8 -8];
 
740
                        acc -= bp[10-8];
 
741
                        acc -= bp[11-8];
 
742
                        acc -= bp[12-8];
 
743
                        acc -= bp[13-8]; rp[7] = (unsigned int)acc;
 
744
 
 
745
        carry = (int)(acc>>32);
 
746
        }
 
747
#else
 
748
        {
 
749
        BN_ULONG t_d[BN_NIST_256_TOP];
588
750
 
589
751
        /*S1*/
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);
591
753
        /*S2*/
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);
594
756
        /* left shift */
595
757
                {
607
769
                }
608
770
        carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
609
771
        /*S3*/
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);
612
774
        /*S4*/
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);
615
777
        /*D1*/
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);
618
780
        /*D2*/
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);
621
783
        /*D3*/
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);
624
786
        /*D4*/
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);
627
789
 
 
790
        }
 
791
#endif
628
792
        /* see BN_nist_mod_224 for explanation */
629
793
        u.f = bn_sub_words;
630
794
        if (carry > 0)
672
836
        int     i, top = a->top;
673
837
        int     carry = 0;
674
838
        register BN_ULONG *r_d, *a_d = a->d;
675
 
        BN_ULONG t_d[BN_NIST_384_TOP],
676
 
                 buf[BN_NIST_384_TOP],
677
 
                 c_d[BN_NIST_384_TOP],
 
839
        union   {
 
840
                BN_ULONG bn[BN_NIST_384_TOP];
 
841
                unsigned int ui[BN_NIST_384_TOP*sizeof(BN_ULONG)/sizeof(unsigned int)];
 
842
                } buf;
 
843
        BN_ULONG c_d[BN_NIST_384_TOP],
678
844
                *res;
679
845
        PTR_SIZE_INT mask;
680
846
        union { bn_addsub_f f; PTR_SIZE_INT p; } u;
709
875
        else
710
876
                r_d = a_d;
711
877
 
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);
 
879
 
 
880
#if defined(NIST_INT64)
 
881
        {
 
882
        NIST_INT64              acc;    /* accumulator */
 
883
        unsigned int            *rp=(unsigned int *)r_d;
 
884
        const unsigned int      *bp=(const unsigned int *)buf.ui;
 
885
 
 
886
        acc = rp[0];    acc += bp[12-12];
 
887
                        acc += bp[21-12];
 
888
                        acc += bp[20-12];
 
889
                        acc -= bp[23-12]; rp[0] = (unsigned int)acc; acc >>= 32;
 
890
 
 
891
        acc += rp[1];   acc += bp[13-12];
 
892
                        acc += bp[22-12];
 
893
                        acc += bp[23-12];
 
894
                        acc -= bp[12-12];
 
895
                        acc -= bp[20-12]; rp[1] = (unsigned int)acc; acc >>= 32;
 
896
 
 
897
        acc += rp[2];   acc += bp[14-12];
 
898
                        acc += bp[23-12];
 
899
                        acc -= bp[13-12];
 
900
                        acc -= bp[21-12]; rp[2] = (unsigned int)acc; acc >>= 32;
 
901
 
 
902
        acc += rp[3];   acc += bp[15-12];
 
903
                        acc += bp[12-12];
 
904
                        acc += bp[20-12];
 
905
                        acc += bp[21-12];
 
906
                        acc -= bp[14-12];
 
907
                        acc -= bp[22-12];
 
908
                        acc -= bp[23-12]; rp[3] = (unsigned int)acc; acc >>= 32;
 
909
 
 
910
        acc += rp[4];   acc += bp[21-12];
 
911
                        acc += bp[21-12];
 
912
                        acc += bp[16-12];
 
913
                        acc += bp[13-12];
 
914
                        acc += bp[12-12];
 
915
                        acc += bp[20-12];
 
916
                        acc += bp[22-12];
 
917
                        acc -= bp[15-12];
 
918
                        acc -= bp[23-12];
 
919
                        acc -= bp[23-12]; rp[4] = (unsigned int)acc; acc >>= 32;
 
920
 
 
921
        acc += rp[5];   acc += bp[22-12];
 
922
                        acc += bp[22-12];
 
923
                        acc += bp[17-12];
 
924
                        acc += bp[14-12];
 
925
                        acc += bp[13-12];
 
926
                        acc += bp[21-12];
 
927
                        acc += bp[23-12];
 
928
                        acc -= bp[16-12]; rp[5] = (unsigned int)acc; acc >>= 32;
 
929
                        
 
930
        acc += rp[6];   acc += bp[23-12];
 
931
                        acc += bp[23-12];
 
932
                        acc += bp[18-12];
 
933
                        acc += bp[15-12];
 
934
                        acc += bp[14-12];
 
935
                        acc += bp[22-12];
 
936
                        acc -= bp[17-12]; rp[6] = (unsigned int)acc; acc >>= 32;
 
937
                        
 
938
        acc += rp[7];   acc += bp[19-12];
 
939
                        acc += bp[16-12];
 
940
                        acc += bp[15-12];
 
941
                        acc += bp[23-12];
 
942
                        acc -= bp[18-12]; rp[7] = (unsigned int)acc; acc >>= 32;
 
943
                        
 
944
        acc += rp[8];   acc += bp[20-12];
 
945
                        acc += bp[17-12];
 
946
                        acc += bp[16-12];
 
947
                        acc -= bp[19-12]; rp[8] = (unsigned int)acc; acc >>= 32;
 
948
                        
 
949
        acc += rp[9];   acc += bp[21-12];
 
950
                        acc += bp[18-12];
 
951
                        acc += bp[17-12];
 
952
                        acc -= bp[20-12]; rp[9] = (unsigned int)acc; acc >>= 32;
 
953
                        
 
954
        acc += rp[10];  acc += bp[22-12];
 
955
                        acc += bp[19-12];
 
956
                        acc += bp[18-12];
 
957
                        acc -= bp[21-12]; rp[10] = (unsigned int)acc; acc >>= 32;
 
958
                        
 
959
        acc += rp[11];  acc += bp[23-12];
 
960
                        acc += bp[20-12];
 
961
                        acc += bp[19-12];
 
962
                        acc -= bp[22-12]; rp[11] = (unsigned int)acc;
 
963
 
 
964
        carry = (int)(acc>>32);
 
965
        }
 
966
#else
 
967
        {
 
968
        BN_ULONG t_d[BN_NIST_384_TOP];
713
969
 
714
970
        /*S1*/
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);
716
972
                /* left shift */
717
973
                {
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);
731
987
        /*S2 */
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);
733
989
        /*S3*/
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);
736
992
        /*S4*/
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);
739
995
        /*S5*/
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);
742
998
        /*S6*/
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);
745
1001
        /*D1*/
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);
748
1004
        /*D2*/
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);
751
1007
        /*D3*/
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);
754
1010
 
 
1011
        }
 
1012
#endif
755
1013
        /* see BN_nist_mod_224 for explanation */
756
1014
        u.f = bn_sub_words;
757
1015
        if (carry > 0)