7 #if CRYPTOPP_MSC_VERSION 8 # pragma warning(disable: 4100) 11 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 12 # pragma GCC diagnostic ignored "-Wunused" 13 # pragma GCC diagnostic ignored "-Wunused-but-set-variable" 17 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 18 # pragma GCC diagnostic ignored "-Wconversion" 19 # pragma GCC diagnostic ignored "-Wsign-conversion" 22 #ifndef CRYPTOPP_IMPORTS 41 #if (_MSC_VER >= 1400) && !defined(_M_ARM) 50 #if (__SUNPRO_CC >= 0x5130) 52 # define MAYBE_UNCONST_CAST const_cast<word*> 54 # define MAYBE_CONST const 55 # define MAYBE_UNCONST_CAST 60 #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) 61 # undef CRYPTOPP_X86_ASM_AVAILABLE 62 # undef CRYPTOPP_X32_ASM_AVAILABLE 63 # undef CRYPTOPP_X64_ASM_AVAILABLE 64 # undef CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 65 # undef CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 66 # define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 0 67 # define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 0 69 # define CRYPTOPP_INTEGER_SSE2 (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && (CRYPTOPP_BOOL_X86)) 76 if (valueType !=
typeid(
Integer))
78 *
reinterpret_cast<Integer *
>(pInteger) = *reinterpret_cast<const int *>(pInt);
82 inline static int Compare(
const word *A,
const word *B,
size_t N)
93 inline static int Increment(
word *A,
size_t N,
word B=1)
100 for (
unsigned i=1; i<N; i++)
106 inline static int Decrement(
word *A,
size_t N,
word B=1)
113 for (
unsigned i=1; i<N; i++)
119 static void TwosComplement(
word *A,
size_t N)
122 for (
unsigned i=0; i<N; i++)
126 static word AtomicInverseModPower2(
word A)
141 #if !defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE) || (defined(__x86_64__) && defined(CRYPTOPP_WORD128_AVAILABLE)) 142 #define Declare2Words(x) word x##0, x##1; 143 #define AssignWord(a, b) a##0 = b; a##1 = 0; 144 #define Add2WordsBy1(a, b, c) a##0 = b##0 + c; a##1 = b##1 + (a##0 < c); 145 #define LowWord(a) a##0 146 #define HighWord(a) a##1 148 #define MultiplyWordsLoHi(p0, p1, a, b) p0 = _umul128(a, b, &p1); 149 #ifndef __INTEL_COMPILER 150 #define Double3Words(c, d) d##1 = __shiftleft128(d##0, d##1, 1); d##0 = __shiftleft128(c, d##0, 1); c *= 2; 152 #elif defined(__DECCXX) 153 #define MultiplyWordsLoHi(p0, p1, a, b) p0 = a*b; p1 = asm("umulh %a0, %a1, %v0", a, b); 154 #elif defined(__x86_64__) 155 #if defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5100 157 #define MultiplyWordsLoHi(p0, p1, a, b) asm ("mulq %3" : "=a"(p0), "=d"(p1) : "a"(a), "r"(b) : "cc"); 159 #define MultiplyWordsLoHi(p0, p1, a, b) asm ("mulq %3" : "=a"(p0), "=d"(p1) : "a"(a), "g"(b) : "cc"); 160 #define MulAcc(c, d, a, b) asm ("mulq %6; addq %3, %0; adcq %4, %1; adcq $0, %2;" : "+r"(c), "+r"(d##0), "+r"(d##1), "=a"(p0), "=d"(p1) : "a"(a), "g"(b) : "cc"); 161 #define Double3Words(c, d) asm ("addq %0, %0; adcq %1, %1; adcq %2, %2;" : "+r"(c), "+r"(d##0), "+r"(d##1) : : "cc"); 162 #define Acc2WordsBy1(a, b) asm ("addq %2, %0; adcq $0, %1;" : "+r"(a##0), "+r"(a##1) : "r"(b) : "cc"); 163 #define Acc2WordsBy2(a, b) asm ("addq %2, %0; adcq %3, %1;" : "+r"(a##0), "+r"(a##1) : "r"(b##0), "r"(b##1) : "cc"); 164 #define Acc3WordsBy2(c, d, e) asm ("addq %5, %0; adcq %6, %1; adcq $0, %2;" : "+r"(c), "=r"(e##0), "=r"(e##1) : "1"(d##0), "2"(d##1), "r"(e##0), "r"(e##1) : "cc"); 167 #define MultiplyWords(p, a, b) MultiplyWordsLoHi(p##0, p##1, a, b) 169 #define Double3Words(c, d) d##1 = 2*d##1 + (d##0>>(WORD_BITS-1)); d##0 = 2*d##0 + (c>>(WORD_BITS-1)); c *= 2; 172 #define Acc2WordsBy2(a, b) a##0 += b##0; a##1 += a##0 < b##0; a##1 += b##1; 174 #define AddWithCarry(u, a, b) {word t = a+b; u##0 = t + u##1; u##1 = (t<a) + (u##0<t);} 175 #define SubtractWithBorrow(u, a, b) {word t = a-b; u##0 = t - u##1; u##1 = (t>a) + (u##0>t);} 176 #define GetCarry(u) u##1 177 #define GetBorrow(u) u##1 179 #define Declare2Words(x) dword x; 180 #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER) && !defined(_M_ARM) 181 #define MultiplyWords(p, a, b) p = __emulu(a, b); 183 #define MultiplyWords(p, a, b) p = (dword)a*b; 185 #define AssignWord(a, b) a = b; 186 #define Add2WordsBy1(a, b, c) a = b + c; 187 #define Acc2WordsBy2(a, b) a += b; 188 #define LowWord(a) word(a) 189 #define HighWord(a) word(a>>WORD_BITS) 190 #define Double3Words(c, d) d = 2*d + (c>>(WORD_BITS-1)); c *= 2; 191 #define AddWithCarry(u, a, b) u = dword(a) + b + GetCarry(u); 192 #define SubtractWithBorrow(u, a, b) u = dword(a) - b - GetBorrow(u); 193 #define GetCarry(u) HighWord(u) 194 #define GetBorrow(u) word(u>>(WORD_BITS*2-1)) 197 #define MulAcc(c, d, a, b) MultiplyWords(p, a, b); Acc2WordsBy1(p, c); c = LowWord(p); Acc2WordsBy1(d, HighWord(p)); 200 #define Acc2WordsBy1(a, b) Add2WordsBy1(a, a, b) 203 #define Acc3WordsBy2(c, d, e) Acc2WordsBy1(e, c); c = LowWord(e); Add2WordsBy1(e, d, HighWord(e)); 209 #if defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE) 215 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 224 #if defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE) 230 #if defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE) 231 # if defined(IS_LITTLE_ENDIAN) 232 const word t[2] = {low,high};
235 const word t[2] = {high,low};
247 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 249 #elif defined(MultiplyWordsLoHi) 265 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 277 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 289 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 301 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 317 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 336 #ifdef IS_LITTLE_ENDIAN 346 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 358 #if defined(__COVERITY__) 412 template <
class S,
class D>
424 S Q;
bool pre = (
S(B1+1) == 0);
426 Q = D(A[1], A[2]) /
S(B1+1);
430 Q = D(A[0], A[1]) /
B0;
434 D u = (D) A[0] - p.GetLowHalf();
435 A[0] = u.GetLowHalf();
436 u = (D) A[1] - p.GetHighHalf() - u.GetHighHalfAsBorrow() -
D::Multiply(B1, Q);
437 A[1] = u.GetLowHalf();
438 A[2] += u.GetHighHalf();
441 while (A[2] || A[1] > B1 || (A[1]==B1 && A[0]>=B0))
444 A[0] = u.GetLowHalf();
445 u = (D) A[1] - B1 - u.GetHighHalfAsBorrow();
446 A[1] = u.GetLowHalf();
447 A[2] += u.GetHighHalf();
456 template <
class S,
class D>
465 T[0] = Al.GetLowHalf();
466 T[1] = Al.GetHighHalf();
467 T[2] = Ah.GetLowHalf();
468 T[3] = Ah.GetHighHalf();
469 Q[1] = DivideThreeWordsByTwo<S, D>(T+1, B.GetLowHalf(), B.GetHighHalf());
470 Q[0] = DivideThreeWordsByTwo<S, D>(
T, B.GetLowHalf(), B.GetHighHalf());
471 return D(Q[0], Q[1]);
475 return D(Ah.GetLowHalf(), Ah.GetHighHalf());
482 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 492 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 514 #if defined(__GNUC__) 515 #define AddPrologue \ 517 __asm__ __volatile__ \ 520 #define AddEpilogue \ 523 : "d" (C), "a" (A), "D" (B), "c" (N) \ 524 : "%esi", "memory", "cc" \ 527 #define MulPrologue \ 528 __asm__ __volatile__ \ 533 #define MulEpilogue \ 537 : "d" (s_maskLow16), "c" (C), "a" (A), "D" (B) \ 538 : "%esi", "memory", "cc" \ 540 #define SquPrologue MulPrologue 541 #define SquEpilogue \ 545 : "d" (s_maskLow16), "c" (C), "a" (A) \ 546 : "%esi", "%edi", "memory", "cc" \ 548 #define TopPrologue MulPrologue 549 #define TopEpilogue \ 553 : "d" (s_maskLow16), "c" (C), "a" (A), "D" (B), "S" (L) \ 557 #define AddPrologue \ 560 __asm mov eax, [esp+12] \ 561 __asm mov edi, [esp+16] 562 #define AddEpilogue \ 568 #define SquPrologue \ 572 AS2( lea ebx, s_maskLow16) 573 #define MulPrologue \ 578 AS2( lea ebx, s_maskLow16) 579 #define TopPrologue \ 585 AS2( lea ebx, s_maskLow16) 586 #define SquEpilogue RestoreEBX 587 #define MulEpilogue RestoreEBX 588 #define TopEpilogue RestoreEBX 591 #ifdef CRYPTOPP_X64_MASM_AVAILABLE 596 #elif defined(CRYPTOPP_X64_ASM_AVAILABLE) && defined(__GNUC__) && defined(CRYPTOPP_WORD128_AVAILABLE) 605 AS2( mov %0,[%3+8*%1])
606 AS2( add %0,[%4+8*%1])
607 AS2( mov [%2+8*%1],%0)
609 AS2( mov %0,[%3+8*%1+8])
610 AS2( adc %0,[%4+8*%1+8])
611 AS2( mov [%2+8*%1+8],%0)
614 AS2( mov %0,[%3+8*%1])
615 AS2( adc %0,[%4+8*%1])
616 AS2( mov [%2+8*%1],%0)
622 :
"=&r" (result),
"+c" (N)
623 :
"r" (C+N),
"r" (A+N),
"r" (B+N)
637 AS2( mov %0,[%3+8*%1])
638 AS2( sub %0,[%4+8*%1])
639 AS2( mov [%2+8*%1],%0)
641 AS2( mov %0,[%3+8*%1+8])
642 AS2( sbb %0,[%4+8*%1+8])
643 AS2( mov [%2+8*%1+8],%0)
646 AS2( mov %0,[%3+8*%1])
647 AS2( sbb %0,[%4+8*%1])
648 AS2( mov [%2+8*%1],%0)
654 :
"=&r" (result),
"+c" (N)
655 :
"r" (C+N),
"r" (A+N),
"r" (B+N)
660 #elif defined(CRYPTOPP_X86_ASM_AVAILABLE) && CRYPTOPP_BOOL_X86 666 AS2( lea eax, [eax+4*ecx])
667 AS2( lea edi, [edi+4*ecx])
668 AS2( lea edx, [edx+4*ecx])
678 AS2( mov esi,[eax+4*ecx])
679 AS2( adc esi,[edi+4*ecx])
680 AS2( mov [edx+4*ecx],esi)
681 AS2( mov esi,[eax+4*ecx+4])
682 AS2( adc esi,[edi+4*ecx+4])
683 AS2( mov [edx+4*ecx+4],esi)
685 AS2( mov esi,[eax+4*ecx+8])
686 AS2( adc esi,[edi+4*ecx+8])
687 AS2( mov [edx+4*ecx+8],esi)
688 AS2( mov esi,[eax+4*ecx+12])
689 AS2( adc esi,[edi+4*ecx+12])
690 AS2( mov [edx+4*ecx+12],esi)
692 AS2( lea ecx,[ecx+4])
707 AS2( lea eax, [eax+4*ecx])
708 AS2( lea edi, [edi+4*ecx])
709 AS2( lea edx, [edx+4*ecx])
719 AS2( mov esi,[eax+4*ecx])
720 AS2( sbb esi,[edi+4*ecx])
721 AS2( mov [edx+4*ecx],esi)
722 AS2( mov esi,[eax+4*ecx+4])
723 AS2( sbb esi,[edi+4*ecx+4])
724 AS2( mov [edx+4*ecx+4],esi)
726 AS2( mov esi,[eax+4*ecx+8])
727 AS2( sbb esi,[edi+4*ecx+8])
728 AS2( mov [edx+4*ecx+8],esi)
729 AS2( mov esi,[eax+4*ecx+12])
730 AS2( sbb esi,[edi+4*ecx+12])
731 AS2( mov [edx+4*ecx+12],esi)
733 AS2( lea ecx,[ecx+4])
743 #if CRYPTOPP_INTEGER_SSE2 749 AS2( lea eax, [eax+4*ecx])
750 AS2( lea edi, [edi+4*ecx])
751 AS2( lea edx, [edx+4*ecx])
762 AS2( movd mm0, DWORD PTR [eax+4*ecx])
763 AS2( movd mm1, DWORD PTR [edi+4*ecx])
766 AS2( movd DWORD PTR [edx+4*ecx], mm2)
769 AS2( movd mm0, DWORD PTR [eax+4*ecx+4])
770 AS2( movd mm1, DWORD PTR [edi+4*ecx+4])
773 AS2( movd DWORD PTR [edx+4*ecx+4], mm2)
777 AS2( movd mm0, DWORD PTR [eax+4*ecx+8])
778 AS2( movd mm1, DWORD PTR [edi+4*ecx+8])
781 AS2( movd DWORD PTR [edx+4*ecx+8], mm2)
784 AS2( movd mm0, DWORD PTR [eax+4*ecx+12])
785 AS2( movd mm1, DWORD PTR [edi+4*ecx+12])
788 AS2( movd DWORD PTR [edx+4*ecx+12], mm2)
805 AS2( lea eax, [eax+4*ecx])
806 AS2( lea edi, [edi+4*ecx])
807 AS2( lea edx, [edx+4*ecx])
818 AS2( movd mm0, DWORD PTR [eax+4*ecx])
819 AS2( movd mm1, DWORD PTR [edi+4*ecx])
822 AS2( movd DWORD PTR [edx+4*ecx], mm0)
825 AS2( movd mm2, DWORD PTR [eax+4*ecx+4])
826 AS2( movd mm1, DWORD PTR [edi+4*ecx+4])
829 AS2( movd DWORD PTR [edx+4*ecx+4], mm2)
833 AS2( movd mm0, DWORD PTR [eax+4*ecx+8])
834 AS2( movd mm1, DWORD PTR [edi+4*ecx+8])
837 AS2( movd DWORD PTR [edx+4*ecx+8], mm0)
840 AS2( movd mm2, DWORD PTR [eax+4*ecx+12])
841 AS2( movd mm1, DWORD PTR [edi+4*ecx+12])
844 AS2( movd DWORD PTR [edx+4*ecx+12], mm2)
856 #endif // CRYPTOPP_INTEGER_SSE2 857 #else // CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 864 for (
size_t i=0; i<N; i+=2)
880 for (
size_t i=0; i<N; i+=2)
897 for(
unsigned i=0; i<N; i++)
908 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 912 Mul_SaveAcc(0, 0, 1) Mul_Acc(1, 0) \ 917 Mul_SaveAcc(0, 0, 1) Mul_Acc(1, 0) \ 918 Mul_SaveAcc(1, 0, 2) Mul_Acc(1, 1) Mul_Acc(2, 0) \ 919 Mul_SaveAcc(2, 0, 3) Mul_Acc(1, 2) Mul_Acc(2, 1) Mul_Acc(3, 0) \ 920 Mul_SaveAcc(3, 1, 3) Mul_Acc(2, 2) Mul_Acc(3, 1) \ 921 Mul_SaveAcc(4, 2, 3) Mul_Acc(3, 2) \ 926 Mul_SaveAcc(0, 0, 1) Mul_Acc(1, 0) \ 927 Mul_SaveAcc(1, 0, 2) Mul_Acc(1, 1) Mul_Acc(2, 0) \ 928 Mul_SaveAcc(2, 0, 3) Mul_Acc(1, 2) Mul_Acc(2, 1) Mul_Acc(3, 0) \ 929 Mul_SaveAcc(3, 0, 4) Mul_Acc(1, 3) Mul_Acc(2, 2) Mul_Acc(3, 1) Mul_Acc(4, 0) \ 930 Mul_SaveAcc(4, 0, 5) Mul_Acc(1, 4) Mul_Acc(2, 3) Mul_Acc(3, 2) Mul_Acc(4, 1) Mul_Acc(5, 0) \ 931 Mul_SaveAcc(5, 0, 6) Mul_Acc(1, 5) Mul_Acc(2, 4) Mul_Acc(3, 3) Mul_Acc(4, 2) Mul_Acc(5, 1) Mul_Acc(6, 0) \ 932 Mul_SaveAcc(6, 0, 7) Mul_Acc(1, 6) Mul_Acc(2, 5) Mul_Acc(3, 4) Mul_Acc(4, 3) Mul_Acc(5, 2) Mul_Acc(6, 1) Mul_Acc(7, 0) \ 933 Mul_SaveAcc(7, 1, 7) Mul_Acc(2, 6) Mul_Acc(3, 5) Mul_Acc(4, 4) Mul_Acc(5, 3) Mul_Acc(6, 2) Mul_Acc(7, 1) \ 934 Mul_SaveAcc(8, 2, 7) Mul_Acc(3, 6) Mul_Acc(4, 5) Mul_Acc(5, 4) Mul_Acc(6, 3) Mul_Acc(7, 2) \ 935 Mul_SaveAcc(9, 3, 7) Mul_Acc(4, 6) Mul_Acc(5, 5) Mul_Acc(6, 4) Mul_Acc(7, 3) \ 936 Mul_SaveAcc(10, 4, 7) Mul_Acc(5, 6) Mul_Acc(6, 5) Mul_Acc(7, 4) \ 937 Mul_SaveAcc(11, 5, 7) Mul_Acc(6, 6) Mul_Acc(7, 5) \ 938 Mul_SaveAcc(12, 6, 7) Mul_Acc(7, 6) \ 943 Mul_SaveAcc(0, 0, 1) Mul_Acc(1, 0) \ 944 Mul_SaveAcc(1, 0, 2) Mul_Acc(1, 1) Mul_Acc(2, 0) \ 945 Mul_SaveAcc(2, 0, 3) Mul_Acc(1, 2) Mul_Acc(2, 1) Mul_Acc(3, 0) \ 946 Mul_SaveAcc(3, 0, 4) Mul_Acc(1, 3) Mul_Acc(2, 2) Mul_Acc(3, 1) Mul_Acc(4, 0) \ 947 Mul_SaveAcc(4, 0, 5) Mul_Acc(1, 4) Mul_Acc(2, 3) Mul_Acc(3, 2) Mul_Acc(4, 1) Mul_Acc(5, 0) \ 948 Mul_SaveAcc(5, 0, 6) Mul_Acc(1, 5) Mul_Acc(2, 4) Mul_Acc(3, 3) Mul_Acc(4, 2) Mul_Acc(5, 1) Mul_Acc(6, 0) \ 949 Mul_SaveAcc(6, 0, 7) Mul_Acc(1, 6) Mul_Acc(2, 5) Mul_Acc(3, 4) Mul_Acc(4, 3) Mul_Acc(5, 2) Mul_Acc(6, 1) Mul_Acc(7, 0) \ 950 Mul_SaveAcc(7, 0, 8) Mul_Acc(1, 7) Mul_Acc(2, 6) Mul_Acc(3, 5) Mul_Acc(4, 4) Mul_Acc(5, 3) Mul_Acc(6, 2) Mul_Acc(7, 1) Mul_Acc(8, 0) \ 951 Mul_SaveAcc(8, 0, 9) Mul_Acc(1, 8) Mul_Acc(2, 7) Mul_Acc(3, 6) Mul_Acc(4, 5) Mul_Acc(5, 4) Mul_Acc(6, 3) Mul_Acc(7, 2) Mul_Acc(8, 1) Mul_Acc(9, 0) \ 952 Mul_SaveAcc(9, 0, 10) Mul_Acc(1, 9) Mul_Acc(2, 8) Mul_Acc(3, 7) Mul_Acc(4, 6) Mul_Acc(5, 5) Mul_Acc(6, 4) Mul_Acc(7, 3) Mul_Acc(8, 2) Mul_Acc(9, 1) Mul_Acc(10, 0) \ 953 Mul_SaveAcc(10, 0, 11) Mul_Acc(1, 10) Mul_Acc(2, 9) Mul_Acc(3, 8) Mul_Acc(4, 7) Mul_Acc(5, 6) Mul_Acc(6, 5) Mul_Acc(7, 4) Mul_Acc(8, 3) Mul_Acc(9, 2) Mul_Acc(10, 1) Mul_Acc(11, 0) \ 954 Mul_SaveAcc(11, 0, 12) Mul_Acc(1, 11) Mul_Acc(2, 10) Mul_Acc(3, 9) Mul_Acc(4, 8) Mul_Acc(5, 7) Mul_Acc(6, 6) Mul_Acc(7, 5) Mul_Acc(8, 4) Mul_Acc(9, 3) Mul_Acc(10, 2) Mul_Acc(11, 1) Mul_Acc(12, 0) \ 955 Mul_SaveAcc(12, 0, 13) Mul_Acc(1, 12) Mul_Acc(2, 11) Mul_Acc(3, 10) Mul_Acc(4, 9) Mul_Acc(5, 8) Mul_Acc(6, 7) Mul_Acc(7, 6) Mul_Acc(8, 5) Mul_Acc(9, 4) Mul_Acc(10, 3) Mul_Acc(11, 2) Mul_Acc(12, 1) Mul_Acc(13, 0) \ 956 Mul_SaveAcc(13, 0, 14) Mul_Acc(1, 13) Mul_Acc(2, 12) Mul_Acc(3, 11) Mul_Acc(4, 10) Mul_Acc(5, 9) Mul_Acc(6, 8) Mul_Acc(7, 7) Mul_Acc(8, 6) Mul_Acc(9, 5) Mul_Acc(10, 4) Mul_Acc(11, 3) Mul_Acc(12, 2) Mul_Acc(13, 1) Mul_Acc(14, 0) \ 957 Mul_SaveAcc(14, 0, 15) Mul_Acc(1, 14) Mul_Acc(2, 13) Mul_Acc(3, 12) Mul_Acc(4, 11) Mul_Acc(5, 10) Mul_Acc(6, 9) Mul_Acc(7, 8) Mul_Acc(8, 7) Mul_Acc(9, 6) Mul_Acc(10, 5) Mul_Acc(11, 4) Mul_Acc(12, 3) Mul_Acc(13, 2) Mul_Acc(14, 1) Mul_Acc(15, 0) \ 958 Mul_SaveAcc(15, 1, 15) Mul_Acc(2, 14) Mul_Acc(3, 13) Mul_Acc(4, 12) Mul_Acc(5, 11) Mul_Acc(6, 10) Mul_Acc(7, 9) Mul_Acc(8, 8) Mul_Acc(9, 7) Mul_Acc(10, 6) Mul_Acc(11, 5) Mul_Acc(12, 4) Mul_Acc(13, 3) Mul_Acc(14, 2) Mul_Acc(15, 1) \ 959 Mul_SaveAcc(16, 2, 15) Mul_Acc(3, 14) Mul_Acc(4, 13) Mul_Acc(5, 12) Mul_Acc(6, 11) Mul_Acc(7, 10) Mul_Acc(8, 9) Mul_Acc(9, 8) Mul_Acc(10, 7) Mul_Acc(11, 6) Mul_Acc(12, 5) Mul_Acc(13, 4) Mul_Acc(14, 3) Mul_Acc(15, 2) \ 960 Mul_SaveAcc(17, 3, 15) Mul_Acc(4, 14) Mul_Acc(5, 13) Mul_Acc(6, 12) Mul_Acc(7, 11) Mul_Acc(8, 10) Mul_Acc(9, 9) Mul_Acc(10, 8) Mul_Acc(11, 7) Mul_Acc(12, 6) Mul_Acc(13, 5) Mul_Acc(14, 4) Mul_Acc(15, 3) \ 961 Mul_SaveAcc(18, 4, 15) Mul_Acc(5, 14) Mul_Acc(6, 13) Mul_Acc(7, 12) Mul_Acc(8, 11) Mul_Acc(9, 10) Mul_Acc(10, 9) Mul_Acc(11, 8) Mul_Acc(12, 7) Mul_Acc(13, 6) Mul_Acc(14, 5) Mul_Acc(15, 4) \ 962 Mul_SaveAcc(19, 5, 15) Mul_Acc(6, 14) Mul_Acc(7, 13) Mul_Acc(8, 12) Mul_Acc(9, 11) Mul_Acc(10, 10) Mul_Acc(11, 9) Mul_Acc(12, 8) Mul_Acc(13, 7) Mul_Acc(14, 6) Mul_Acc(15, 5) \ 963 Mul_SaveAcc(20, 6, 15) Mul_Acc(7, 14) Mul_Acc(8, 13) Mul_Acc(9, 12) Mul_Acc(10, 11) Mul_Acc(11, 10) Mul_Acc(12, 9) Mul_Acc(13, 8) Mul_Acc(14, 7) Mul_Acc(15, 6) \ 964 Mul_SaveAcc(21, 7, 15) Mul_Acc(8, 14) Mul_Acc(9, 13) Mul_Acc(10, 12) Mul_Acc(11, 11) Mul_Acc(12, 10) Mul_Acc(13, 9) Mul_Acc(14, 8) Mul_Acc(15, 7) \ 965 Mul_SaveAcc(22, 8, 15) Mul_Acc(9, 14) Mul_Acc(10, 13) Mul_Acc(11, 12) Mul_Acc(12, 11) Mul_Acc(13, 10) Mul_Acc(14, 9) Mul_Acc(15, 8) \ 966 Mul_SaveAcc(23, 9, 15) Mul_Acc(10, 14) Mul_Acc(11, 13) Mul_Acc(12, 12) Mul_Acc(13, 11) Mul_Acc(14, 10) Mul_Acc(15, 9) \ 967 Mul_SaveAcc(24, 10, 15) Mul_Acc(11, 14) Mul_Acc(12, 13) Mul_Acc(13, 12) Mul_Acc(14, 11) Mul_Acc(15, 10) \ 968 Mul_SaveAcc(25, 11, 15) Mul_Acc(12, 14) Mul_Acc(13, 13) Mul_Acc(14, 12) Mul_Acc(15, 11) \ 969 Mul_SaveAcc(26, 12, 15) Mul_Acc(13, 14) Mul_Acc(14, 13) Mul_Acc(15, 12) \ 970 Mul_SaveAcc(27, 13, 15) Mul_Acc(14, 14) Mul_Acc(15, 13) \ 971 Mul_SaveAcc(28, 14, 15) Mul_Acc(15, 14) \ 980 Squ_SaveAcc(1, 0, 2) Squ_Diag(1) \ 981 Squ_SaveAcc(2, 0, 3) Squ_Acc(1, 2) Squ_NonDiag \ 982 Squ_SaveAcc(3, 1, 3) Squ_Diag(2) \ 983 Squ_SaveAcc(4, 2, 3) Squ_NonDiag \ 988 Squ_SaveAcc(1, 0, 2) Squ_Diag(1) \ 989 Squ_SaveAcc(2, 0, 3) Squ_Acc(1, 2) Squ_NonDiag \ 990 Squ_SaveAcc(3, 0, 4) Squ_Acc(1, 3) Squ_Diag(2) \ 991 Squ_SaveAcc(4, 0, 5) Squ_Acc(1, 4) Squ_Acc(2, 3) Squ_NonDiag \ 992 Squ_SaveAcc(5, 0, 6) Squ_Acc(1, 5) Squ_Acc(2, 4) Squ_Diag(3) \ 993 Squ_SaveAcc(6, 0, 7) Squ_Acc(1, 6) Squ_Acc(2, 5) Squ_Acc(3, 4) Squ_NonDiag \ 994 Squ_SaveAcc(7, 1, 7) Squ_Acc(2, 6) Squ_Acc(3, 5) Squ_Diag(4) \ 995 Squ_SaveAcc(8, 2, 7) Squ_Acc(3, 6) Squ_Acc(4, 5) Squ_NonDiag \ 996 Squ_SaveAcc(9, 3, 7) Squ_Acc(4, 6) Squ_Diag(5) \ 997 Squ_SaveAcc(10, 4, 7) Squ_Acc(5, 6) Squ_NonDiag \ 998 Squ_SaveAcc(11, 5, 7) Squ_Diag(6) \ 999 Squ_SaveAcc(12, 6, 7) Squ_NonDiag \ 1004 Squ_SaveAcc(1, 0, 2) Squ_Diag(1) \ 1005 Squ_SaveAcc(2, 0, 3) Squ_Acc(1, 2) Squ_NonDiag \ 1006 Squ_SaveAcc(3, 0, 4) Squ_Acc(1, 3) Squ_Diag(2) \ 1007 Squ_SaveAcc(4, 0, 5) Squ_Acc(1, 4) Squ_Acc(2, 3) Squ_NonDiag \ 1008 Squ_SaveAcc(5, 0, 6) Squ_Acc(1, 5) Squ_Acc(2, 4) Squ_Diag(3) \ 1009 Squ_SaveAcc(6, 0, 7) Squ_Acc(1, 6) Squ_Acc(2, 5) Squ_Acc(3, 4) Squ_NonDiag \ 1010 Squ_SaveAcc(7, 0, 8) Squ_Acc(1, 7) Squ_Acc(2, 6) Squ_Acc(3, 5) Squ_Diag(4) \ 1011 Squ_SaveAcc(8, 0, 9) Squ_Acc(1, 8) Squ_Acc(2, 7) Squ_Acc(3, 6) Squ_Acc(4, 5) Squ_NonDiag \ 1012 Squ_SaveAcc(9, 0, 10) Squ_Acc(1, 9) Squ_Acc(2, 8) Squ_Acc(3, 7) Squ_Acc(4, 6) Squ_Diag(5) \ 1013 Squ_SaveAcc(10, 0, 11) Squ_Acc(1, 10) Squ_Acc(2, 9) Squ_Acc(3, 8) Squ_Acc(4, 7) Squ_Acc(5, 6) Squ_NonDiag \ 1014 Squ_SaveAcc(11, 0, 12) Squ_Acc(1, 11) Squ_Acc(2, 10) Squ_Acc(3, 9) Squ_Acc(4, 8) Squ_Acc(5, 7) Squ_Diag(6) \ 1015 Squ_SaveAcc(12, 0, 13) Squ_Acc(1, 12) Squ_Acc(2, 11) Squ_Acc(3, 10) Squ_Acc(4, 9) Squ_Acc(5, 8) Squ_Acc(6, 7) Squ_NonDiag \ 1016 Squ_SaveAcc(13, 0, 14) Squ_Acc(1, 13) Squ_Acc(2, 12) Squ_Acc(3, 11) Squ_Acc(4, 10) Squ_Acc(5, 9) Squ_Acc(6, 8) Squ_Diag(7) \ 1017 Squ_SaveAcc(14, 0, 15) Squ_Acc(1, 14) Squ_Acc(2, 13) Squ_Acc(3, 12) Squ_Acc(4, 11) Squ_Acc(5, 10) Squ_Acc(6, 9) Squ_Acc(7, 8) Squ_NonDiag \ 1018 Squ_SaveAcc(15, 1, 15) Squ_Acc(2, 14) Squ_Acc(3, 13) Squ_Acc(4, 12) Squ_Acc(5, 11) Squ_Acc(6, 10) Squ_Acc(7, 9) Squ_Diag(8) \ 1019 Squ_SaveAcc(16, 2, 15) Squ_Acc(3, 14) Squ_Acc(4, 13) Squ_Acc(5, 12) Squ_Acc(6, 11) Squ_Acc(7, 10) Squ_Acc(8, 9) Squ_NonDiag \ 1020 Squ_SaveAcc(17, 3, 15) Squ_Acc(4, 14) Squ_Acc(5, 13) Squ_Acc(6, 12) Squ_Acc(7, 11) Squ_Acc(8, 10) Squ_Diag(9) \ 1021 Squ_SaveAcc(18, 4, 15) Squ_Acc(5, 14) Squ_Acc(6, 13) Squ_Acc(7, 12) Squ_Acc(8, 11) Squ_Acc(9, 10) Squ_NonDiag \ 1022 Squ_SaveAcc(19, 5, 15) Squ_Acc(6, 14) Squ_Acc(7, 13) Squ_Acc(8, 12) Squ_Acc(9, 11) Squ_Diag(10) \ 1023 Squ_SaveAcc(20, 6, 15) Squ_Acc(7, 14) Squ_Acc(8, 13) Squ_Acc(9, 12) Squ_Acc(10, 11) Squ_NonDiag \ 1024 Squ_SaveAcc(21, 7, 15) Squ_Acc(8, 14) Squ_Acc(9, 13) Squ_Acc(10, 12) Squ_Diag(11) \ 1025 Squ_SaveAcc(22, 8, 15) Squ_Acc(9, 14) Squ_Acc(10, 13) Squ_Acc(11, 12) Squ_NonDiag \ 1026 Squ_SaveAcc(23, 9, 15) Squ_Acc(10, 14) Squ_Acc(11, 13) Squ_Diag(12) \ 1027 Squ_SaveAcc(24, 10, 15) Squ_Acc(11, 14) Squ_Acc(12, 13) Squ_NonDiag \ 1028 Squ_SaveAcc(25, 11, 15) Squ_Acc(12, 14) Squ_Diag(13) \ 1029 Squ_SaveAcc(26, 12, 15) Squ_Acc(13, 14) Squ_NonDiag \ 1030 Squ_SaveAcc(27, 13, 15) Squ_Diag(14) \ 1031 Squ_SaveAcc(28, 14, 15) Squ_NonDiag \ 1036 Bot_SaveAcc(0, 0, 1) Bot_Acc(1, 0) \ 1041 Mul_SaveAcc(0, 0, 1) Mul_Acc(1, 0) \ 1042 Mul_SaveAcc(1, 2, 0) Mul_Acc(1, 1) Mul_Acc(0, 2) \ 1043 Bot_SaveAcc(2, 0, 3) Bot_Acc(1, 2) Bot_Acc(2, 1) Bot_Acc(3, 0) \ 1048 Mul_SaveAcc(0, 0, 1) Mul_Acc(1, 0) \ 1049 Mul_SaveAcc(1, 0, 2) Mul_Acc(1, 1) Mul_Acc(2, 0) \ 1050 Mul_SaveAcc(2, 0, 3) Mul_Acc(1, 2) Mul_Acc(2, 1) Mul_Acc(3, 0) \ 1051 Mul_SaveAcc(3, 0, 4) Mul_Acc(1, 3) Mul_Acc(2, 2) Mul_Acc(3, 1) Mul_Acc(4, 0) \ 1052 Mul_SaveAcc(4, 0, 5) Mul_Acc(1, 4) Mul_Acc(2, 3) Mul_Acc(3, 2) Mul_Acc(4, 1) Mul_Acc(5, 0) \ 1053 Mul_SaveAcc(5, 0, 6) Mul_Acc(1, 5) Mul_Acc(2, 4) Mul_Acc(3, 3) Mul_Acc(4, 2) Mul_Acc(5, 1) Mul_Acc(6, 0) \ 1054 Bot_SaveAcc(6, 0, 7) Bot_Acc(1, 6) Bot_Acc(2, 5) Bot_Acc(3, 4) Bot_Acc(4, 3) Bot_Acc(5, 2) Bot_Acc(6, 1) Bot_Acc(7, 0) \ 1059 Mul_SaveAcc(0, 0, 1) Mul_Acc(1, 0) \ 1060 Mul_SaveAcc(1, 0, 2) Mul_Acc(1, 1) Mul_Acc(2, 0) \ 1061 Mul_SaveAcc(2, 0, 3) Mul_Acc(1, 2) Mul_Acc(2, 1) Mul_Acc(3, 0) \ 1062 Mul_SaveAcc(3, 0, 4) Mul_Acc(1, 3) Mul_Acc(2, 2) Mul_Acc(3, 1) Mul_Acc(4, 0) \ 1063 Mul_SaveAcc(4, 0, 5) Mul_Acc(1, 4) Mul_Acc(2, 3) Mul_Acc(3, 2) Mul_Acc(4, 1) Mul_Acc(5, 0) \ 1064 Mul_SaveAcc(5, 0, 6) Mul_Acc(1, 5) Mul_Acc(2, 4) Mul_Acc(3, 3) Mul_Acc(4, 2) Mul_Acc(5, 1) Mul_Acc(6, 0) \ 1065 Mul_SaveAcc(6, 0, 7) Mul_Acc(1, 6) Mul_Acc(2, 5) Mul_Acc(3, 4) Mul_Acc(4, 3) Mul_Acc(5, 2) Mul_Acc(6, 1) Mul_Acc(7, 0) \ 1066 Mul_SaveAcc(7, 0, 8) Mul_Acc(1, 7) Mul_Acc(2, 6) Mul_Acc(3, 5) Mul_Acc(4, 4) Mul_Acc(5, 3) Mul_Acc(6, 2) Mul_Acc(7, 1) Mul_Acc(8, 0) \ 1067 Mul_SaveAcc(8, 0, 9) Mul_Acc(1, 8) Mul_Acc(2, 7) Mul_Acc(3, 6) Mul_Acc(4, 5) Mul_Acc(5, 4) Mul_Acc(6, 3) Mul_Acc(7, 2) Mul_Acc(8, 1) Mul_Acc(9, 0) \ 1068 Mul_SaveAcc(9, 0, 10) Mul_Acc(1, 9) Mul_Acc(2, 8) Mul_Acc(3, 7) Mul_Acc(4, 6) Mul_Acc(5, 5) Mul_Acc(6, 4) Mul_Acc(7, 3) Mul_Acc(8, 2) Mul_Acc(9, 1) Mul_Acc(10, 0) \ 1069 Mul_SaveAcc(10, 0, 11) Mul_Acc(1, 10) Mul_Acc(2, 9) Mul_Acc(3, 8) Mul_Acc(4, 7) Mul_Acc(5, 6) Mul_Acc(6, 5) Mul_Acc(7, 4) Mul_Acc(8, 3) Mul_Acc(9, 2) Mul_Acc(10, 1) Mul_Acc(11, 0) \ 1070 Mul_SaveAcc(11, 0, 12) Mul_Acc(1, 11) Mul_Acc(2, 10) Mul_Acc(3, 9) Mul_Acc(4, 8) Mul_Acc(5, 7) Mul_Acc(6, 6) Mul_Acc(7, 5) Mul_Acc(8, 4) Mul_Acc(9, 3) Mul_Acc(10, 2) Mul_Acc(11, 1) Mul_Acc(12, 0) \ 1071 Mul_SaveAcc(12, 0, 13) Mul_Acc(1, 12) Mul_Acc(2, 11) Mul_Acc(3, 10) Mul_Acc(4, 9) Mul_Acc(5, 8) Mul_Acc(6, 7) Mul_Acc(7, 6) Mul_Acc(8, 5) Mul_Acc(9, 4) Mul_Acc(10, 3) Mul_Acc(11, 2) Mul_Acc(12, 1) Mul_Acc(13, 0) \ 1072 Mul_SaveAcc(13, 0, 14) Mul_Acc(1, 13) Mul_Acc(2, 12) Mul_Acc(3, 11) Mul_Acc(4, 10) Mul_Acc(5, 9) Mul_Acc(6, 8) Mul_Acc(7, 7) Mul_Acc(8, 6) Mul_Acc(9, 5) Mul_Acc(10, 4) Mul_Acc(11, 3) Mul_Acc(12, 2) Mul_Acc(13, 1) Mul_Acc(14, 0) \ 1073 Bot_SaveAcc(14, 0, 15) Bot_Acc(1, 14) Bot_Acc(2, 13) Bot_Acc(3, 12) Bot_Acc(4, 11) Bot_Acc(5, 10) Bot_Acc(6, 9) Bot_Acc(7, 8) Bot_Acc(8, 7) Bot_Acc(9, 6) Bot_Acc(10, 5) Bot_Acc(11, 4) Bot_Acc(12, 3) Bot_Acc(13, 2) Bot_Acc(14, 1) Bot_Acc(15, 0) \ 1079 #define Mul_Begin(n) \ 1083 MultiplyWords(p, A[0], B[0]) \ 1084 AssignWord(c, LowWord(p)) \ 1085 AssignWord(d, HighWord(p)) 1087 #define Mul_Acc(i, j) \ 1088 MultiplyWords(p, A[i], B[j]) \ 1089 Acc2WordsBy1(c, LowWord(p)) \ 1090 Acc2WordsBy1(d, HighWord(p)) 1092 #define Mul_SaveAcc(k, i, j) \ 1093 R[k] = LowWord(c); \ 1094 Add2WordsBy1(c, d, HighWord(c)) \ 1095 MultiplyWords(p, A[i], B[j]) \ 1096 AssignWord(d, HighWord(p)) \ 1097 Acc2WordsBy1(c, LowWord(p)) 1099 #define Mul_End(n) \ 1100 R[2*n-3] = LowWord(c); \ 1101 Acc2WordsBy1(d, HighWord(c)) \ 1102 MultiplyWords(p, A[n-1], B[n-1])\ 1103 Acc2WordsBy2(d, p) \ 1104 R[2*n-2] = LowWord(d); \ 1105 R[2*n-1] = HighWord(d); 1107 #define Bot_SaveAcc(k, i, j) \ 1108 R[k] = LowWord(c); \ 1109 word e = LowWord(d) + HighWord(c); \ 1112 #define Bot_Acc(i, j) \ 1115 #define Bot_End(n) \ 1118 #define Mul_Begin(n) \ 1122 MultiplyWords(p, A[0], B[0]) \ 1124 AssignWord(d, HighWord(p)) 1126 #define Mul_Acc(i, j) \ 1127 MulAcc(c, d, A[i], B[j]) 1129 #define Mul_SaveAcc(k, i, j) \ 1132 AssignWord(d, HighWord(d)) \ 1133 MulAcc(c, d, A[i], B[j]) 1135 #define Mul_End(k, i) \ 1137 MultiplyWords(p, A[i], B[i]) \ 1138 Acc2WordsBy2(p, d) \ 1139 R[k+1] = LowWord(p); \ 1140 R[k+2] = HighWord(p); 1142 #define Bot_SaveAcc(k, i, j) \ 1147 #define Bot_Acc(i, j) \ 1150 #define Bot_End(n) \ 1154 #define Squ_Begin(n) \ 1159 MultiplyWords(p, A[0], A[0]) \ 1160 R[0] = LowWord(p); \ 1161 AssignWord(e, HighWord(p)) \ 1162 MultiplyWords(p, A[0], A[1]) \ 1164 AssignWord(d, HighWord(p)) \ 1167 #define Squ_NonDiag \ 1170 #define Squ_SaveAcc(k, i, j) \ 1171 Acc3WordsBy2(c, d, e) \ 1173 MultiplyWords(p, A[i], A[j]) \ 1175 AssignWord(d, HighWord(p)) \ 1177 #define Squ_Acc(i, j) \ 1178 MulAcc(c, d, A[i], A[j]) 1180 #define Squ_Diag(i) \ 1182 MulAcc(c, d, A[i], A[i]) 1184 #define Squ_End(n) \ 1185 Acc3WordsBy2(c, d, e) \ 1187 MultiplyWords(p, A[n-1], A[n-1])\ 1188 Acc2WordsBy2(p, e) \ 1189 R[2*n-2] = LowWord(p); \ 1190 R[2*n-1] = HighWord(p); 1271 #define Top_Begin(n) \ 1275 MultiplyWords(p, A[0], B[n-2]);\ 1276 AssignWord(d, HighWord(p)); 1278 #define Top_Acc(i, j) \ 1279 MultiplyWords(p, A[i], B[j]);\ 1280 Acc2WordsBy1(d, HighWord(p)); 1282 #define Top_SaveAcc0(i, j) \ 1284 AssignWord(d, HighWord(d)) \ 1285 MulAcc(c, d, A[i], B[j]) 1287 #define Top_SaveAcc1(i, j) \ 1289 Acc2WordsBy1(d, c); \ 1291 AssignWord(d, HighWord(d)) \ 1292 MulAcc(c, d, A[i], B[j]) 1335 #if !CRYPTOPP_INTEGER_SSE2 // save memory by not compiling these functions when SSE2 is available 1369 Top_Acc(1, 13)
Top_Acc(2, 12)
Top_Acc(3, 11)
Top_Acc(4, 10)
Top_Acc(5, 9)
Top_Acc(6, 8)
Top_Acc(7, 7)
Top_Acc(8, 6)
Top_Acc(9, 5)
Top_Acc(10, 4)
Top_Acc(11, 3)
Top_Acc(12, 2)
Top_Acc(13, 1)
Top_Acc(14, 0)
\ 1370 Top_SaveAcc0(0, 15)
Mul_Acc(1, 14)
Mul_Acc(2, 13)
Mul_Acc(3, 12)
Mul_Acc(4, 11)
Mul_Acc(5, 10)
Mul_Acc(6, 9)
Mul_Acc(7, 8)
Mul_Acc(8, 7)
Mul_Acc(9, 6)
Mul_Acc(10, 5)
Mul_Acc(11, 4)
Mul_Acc(12, 3)
Mul_Acc(13, 2)
Mul_Acc(14, 1)
Mul_Acc(15, 0)
\ 1371 Top_SaveAcc1(1, 15)
Mul_Acc(2, 14)
Mul_Acc(3, 13)
Mul_Acc(4, 12)
Mul_Acc(5, 11)
Mul_Acc(6, 10)
Mul_Acc(7, 9)
Mul_Acc(8, 8)
Mul_Acc(9, 7)
Mul_Acc(10, 6)
Mul_Acc(11, 5)
Mul_Acc(12, 4)
Mul_Acc(13, 3)
Mul_Acc(14, 2)
Mul_Acc(15, 1)
\ 1372 Mul_SaveAcc(0, 2, 15)
Mul_Acc(3, 14)
Mul_Acc(4, 13)
Mul_Acc(5, 12)
Mul_Acc(6, 11)
Mul_Acc(7, 10)
Mul_Acc(8, 9)
Mul_Acc(9, 8)
Mul_Acc(10, 7)
Mul_Acc(11, 6)
Mul_Acc(12, 5)
Mul_Acc(13, 4)
Mul_Acc(14, 3)
Mul_Acc(15, 2)
\ 1373 Mul_SaveAcc(1, 3, 15)
Mul_Acc(4, 14)
Mul_Acc(5, 13)
Mul_Acc(6, 12)
Mul_Acc(7, 11)
Mul_Acc(8, 10)
Mul_Acc(9, 9)
Mul_Acc(10, 8)
Mul_Acc(11, 7)
Mul_Acc(12, 6)
Mul_Acc(13, 5)
Mul_Acc(14, 4)
Mul_Acc(15, 3)
\ 1374 Mul_SaveAcc(2, 4, 15)
Mul_Acc(5, 14)
Mul_Acc(6, 13)
Mul_Acc(7, 12)
Mul_Acc(8, 11)
Mul_Acc(9, 10)
Mul_Acc(10, 9)
Mul_Acc(11, 8)
Mul_Acc(12, 7)
Mul_Acc(13, 6)
Mul_Acc(14, 5)
Mul_Acc(15, 4)
\ 1375 Mul_SaveAcc(3, 5, 15)
Mul_Acc(6, 14)
Mul_Acc(7, 13)
Mul_Acc(8, 12)
Mul_Acc(9, 11)
Mul_Acc(10, 10)
Mul_Acc(11, 9)
Mul_Acc(12, 8)
Mul_Acc(13, 7)
Mul_Acc(14, 6)
Mul_Acc(15, 5)
\ 1376 Mul_SaveAcc(4, 6, 15)
Mul_Acc(7, 14)
Mul_Acc(8, 13)
Mul_Acc(9, 12)
Mul_Acc(10, 11)
Mul_Acc(11, 10)
Mul_Acc(12, 9)
Mul_Acc(13, 8)
Mul_Acc(14, 7)
Mul_Acc(15, 6)
\ 1377 Mul_SaveAcc(5, 7, 15)
Mul_Acc(8, 14)
Mul_Acc(9, 13)
Mul_Acc(10, 12)
Mul_Acc(11, 11)
Mul_Acc(12, 10)
Mul_Acc(13, 9)
Mul_Acc(14, 8)
Mul_Acc(15, 7)
\ 1391 #if CRYPTOPP_INTEGER_SSE2 1411 #define SSE2_FinalSave(k) \ 1412 AS2( psllq xmm5, 16) \ 1413 AS2( paddq xmm4, xmm5) \ 1414 AS2( movq QWORD PTR [ecx+8*(k)], xmm4) 1416 #define SSE2_SaveShift(k) \ 1417 AS2( movq xmm0, xmm6) \ 1418 AS2( punpckhqdq xmm6, xmm0) \ 1419 AS2( movq xmm1, xmm7) \ 1420 AS2( punpckhqdq xmm7, xmm1) \ 1421 AS2( paddd xmm6, xmm0) \ 1422 AS2( pslldq xmm6, 4) \ 1423 AS2( paddd xmm7, xmm1) \ 1424 AS2( paddd xmm4, xmm6) \ 1425 AS2( pslldq xmm7, 4) \ 1426 AS2( movq xmm6, xmm4) \ 1427 AS2( paddd xmm5, xmm7) \ 1428 AS2( movq xmm7, xmm5) \ 1429 AS2( movd DWORD PTR [ecx+8*(k)], xmm4) \ 1430 AS2( psrlq xmm6, 16) \ 1431 AS2( paddq xmm6, xmm7) \ 1432 AS2( punpckhqdq xmm4, xmm0) \ 1433 AS2( punpckhqdq xmm5, xmm0) \ 1434 AS2( movq QWORD PTR [ecx+8*(k)+2], xmm6) \ 1435 AS2( psrlq xmm6, 3*16) \ 1436 AS2( paddd xmm4, xmm6) \ 1438 #define Squ_SSE2_SaveShift(k) \ 1439 AS2( movq xmm0, xmm6) \ 1440 AS2( punpckhqdq xmm6, xmm0) \ 1441 AS2( movq xmm1, xmm7) \ 1442 AS2( punpckhqdq xmm7, xmm1) \ 1443 AS2( paddd xmm6, xmm0) \ 1444 AS2( pslldq xmm6, 4) \ 1445 AS2( paddd xmm7, xmm1) \ 1446 AS2( paddd xmm4, xmm6) \ 1447 AS2( pslldq xmm7, 4) \ 1448 AS2( movhlps xmm6, xmm4) \ 1449 AS2( movd DWORD PTR [ecx+8*(k)], xmm4) \ 1450 AS2( paddd xmm5, xmm7) \ 1451 AS2( movhps QWORD PTR [esp+12], xmm5)\ 1452 AS2( psrlq xmm4, 16) \ 1453 AS2( paddq xmm4, xmm5) \ 1454 AS2( movq QWORD PTR [ecx+8*(k)+2], xmm4) \ 1455 AS2( psrlq xmm4, 3*16) \ 1456 AS2( paddd xmm4, xmm6) \ 1457 AS2( movq QWORD PTR [esp+4], xmm4)\ 1459 #define SSE2_FirstMultiply(i) \ 1460 AS2( movdqa xmm7, [esi+(i)*16])\ 1461 AS2( movdqa xmm5, [edi-(i)*16])\ 1462 AS2( pmuludq xmm5, xmm7) \ 1463 AS2( movdqa xmm4, [ebx])\ 1464 AS2( movdqa xmm6, xmm4) \ 1465 AS2( pand xmm4, xmm5) \ 1466 AS2( psrld xmm5, 16) \ 1467 AS2( pmuludq xmm7, [edx-(i)*16])\ 1468 AS2( pand xmm6, xmm7) \ 1469 AS2( psrld xmm7, 16) 1471 #define Squ_Begin(n) \ 1474 AS2( and esp, 0xfffffff0)\ 1475 AS2( lea edi, [esp-32*n])\ 1476 AS2( sub esp, 32*n+16)\ 1478 AS2( mov esi, edi) \ 1479 AS2( xor edx, edx) \ 1481 ASS( pshufd xmm0, [eax+edx], 3,1,2,0) \ 1482 ASS( pshufd xmm1, [eax+edx], 2,0,3,1) \ 1483 AS2( movdqa [edi+2*edx], xmm0) \ 1484 AS2( psrlq xmm0, 32) \ 1485 AS2( movdqa [edi+2*edx+16], xmm0) \ 1486 AS2( movdqa [edi+16*n+2*edx], xmm1) \ 1487 AS2( psrlq xmm1, 32) \ 1488 AS2( movdqa [edi+16*n+2*edx+16], xmm1) \ 1490 AS2( cmp edx, 8*(n)) \ 1492 AS2( lea edx, [edi+16*n])\ 1493 SSE2_FirstMultiply(0) \ 1495 #define Squ_Acc(i) \ 1497 AS2( movdqa xmm1, [esi+(i)*16]) \ 1498 AS2( movdqa xmm0, [edi-(i)*16]) \ 1499 AS2( movdqa xmm2, [ebx]) \ 1500 AS2( pmuludq xmm0, xmm1) \ 1501 AS2( pmuludq xmm1, [edx-(i)*16]) \ 1502 AS2( movdqa xmm3, xmm2) \ 1503 AS2( pand xmm2, xmm0) \ 1504 AS2( psrld xmm0, 16) \ 1505 AS2( paddd xmm4, xmm2) \ 1506 AS2( paddd xmm5, xmm0) \ 1507 AS2( pand xmm3, xmm1) \ 1508 AS2( psrld xmm1, 16) \ 1509 AS2( paddd xmm6, xmm3) \ 1510 AS2( paddd xmm7, xmm1) \ 1513 #define Squ_Acc2(i) ASC(call, LSqu##i) 1514 #define Squ_Acc3(i) Squ_Acc2(i) 1515 #define Squ_Acc4(i) Squ_Acc2(i) 1516 #define Squ_Acc5(i) Squ_Acc2(i) 1517 #define Squ_Acc6(i) Squ_Acc2(i) 1518 #define Squ_Acc7(i) Squ_Acc2(i) 1519 #define Squ_Acc8(i) Squ_Acc2(i) 1521 #define SSE2_End(E, n) \ 1522 SSE2_SaveShift(2*(n)-3) \ 1523 AS2( movdqa xmm7, [esi+16]) \ 1524 AS2( movdqa xmm0, [edi]) \ 1525 AS2( pmuludq xmm0, xmm7) \ 1526 AS2( movdqa xmm2, [ebx]) \ 1527 AS2( pmuludq xmm7, [edx]) \ 1528 AS2( movdqa xmm6, xmm2) \ 1529 AS2( pand xmm2, xmm0) \ 1530 AS2( psrld xmm0, 16) \ 1531 AS2( paddd xmm4, xmm2) \ 1532 AS2( paddd xmm5, xmm0) \ 1533 AS2( pand xmm6, xmm7) \ 1534 AS2( psrld xmm7, 16) \ 1535 SSE2_SaveShift(2*(n)-2) \ 1536 SSE2_FinalSave(2*(n)-1) \ 1540 #define Squ_End(n) SSE2_End(SquEpilogue, n) 1541 #define Mul_End(n) SSE2_End(MulEpilogue, n) 1542 #define Top_End(n) SSE2_End(TopEpilogue, n) 1544 #define Squ_Column1(k, i) \ 1545 Squ_SSE2_SaveShift(k) \ 1547 SSE2_FirstMultiply(1)\ 1549 AS2( paddd xmm4, xmm4) \ 1550 AS2( paddd xmm5, xmm5) \ 1551 AS2( movdqa xmm3, [esi]) \ 1552 AS2( movq xmm1, QWORD PTR [esi+8]) \ 1553 AS2( pmuludq xmm1, xmm3) \ 1554 AS2( pmuludq xmm3, xmm3) \ 1555 AS2( movdqa xmm0, [ebx])\ 1556 AS2( movdqa xmm2, xmm0) \ 1557 AS2( pand xmm0, xmm1) \ 1558 AS2( psrld xmm1, 16) \ 1559 AS2( paddd xmm6, xmm0) \ 1560 AS2( paddd xmm7, xmm1) \ 1561 AS2( pand xmm2, xmm3) \ 1562 AS2( psrld xmm3, 16) \ 1563 AS2( paddd xmm6, xmm6) \ 1564 AS2( paddd xmm7, xmm7) \ 1565 AS2( paddd xmm4, xmm2) \ 1566 AS2( paddd xmm5, xmm3) \ 1567 AS2( movq xmm0, QWORD PTR [esp+4])\ 1568 AS2( movq xmm1, QWORD PTR [esp+12])\ 1569 AS2( paddd xmm4, xmm0)\ 1570 AS2( paddd xmm5, xmm1)\ 1572 #define Squ_Column0(k, i) \ 1573 Squ_SSE2_SaveShift(k) \ 1576 SSE2_FirstMultiply(1)\ 1578 AS2( paddd xmm6, xmm6) \ 1579 AS2( paddd xmm7, xmm7) \ 1580 AS2( paddd xmm4, xmm4) \ 1581 AS2( paddd xmm5, xmm5) \ 1582 AS2( movq xmm0, QWORD PTR [esp+4])\ 1583 AS2( movq xmm1, QWORD PTR [esp+12])\ 1584 AS2( paddd xmm4, xmm0)\ 1585 AS2( paddd xmm5, xmm1)\ 1587 #define SSE2_MulAdd45 \ 1588 AS2( movdqa xmm7, [esi]) \ 1589 AS2( movdqa xmm0, [edi]) \ 1590 AS2( pmuludq xmm0, xmm7) \ 1591 AS2( movdqa xmm2, [ebx]) \ 1592 AS2( pmuludq xmm7, [edx]) \ 1593 AS2( movdqa xmm6, xmm2) \ 1594 AS2( pand xmm2, xmm0) \ 1595 AS2( psrld xmm0, 16) \ 1596 AS2( paddd xmm4, xmm2) \ 1597 AS2( paddd xmm5, xmm0) \ 1598 AS2( pand xmm6, xmm7) \ 1599 AS2( psrld xmm7, 16) 1601 #define Mul_Begin(n) \ 1604 AS2( and esp, 0xfffffff0)\ 1605 AS2( sub esp, 48*n+16)\ 1607 AS2( xor edx, edx) \ 1609 ASS( pshufd xmm0, [eax+edx], 3,1,2,0) \ 1610 ASS( pshufd xmm1, [eax+edx], 2,0,3,1) \ 1611 ASS( pshufd xmm2, [edi+edx], 3,1,2,0) \ 1612 AS2( movdqa [esp+20+2*edx], xmm0) \ 1613 AS2( psrlq xmm0, 32) \ 1614 AS2( movdqa [esp+20+2*edx+16], xmm0) \ 1615 AS2( movdqa [esp+20+16*n+2*edx], xmm1) \ 1616 AS2( psrlq xmm1, 32) \ 1617 AS2( movdqa [esp+20+16*n+2*edx+16], xmm1) \ 1618 AS2( movdqa [esp+20+32*n+2*edx], xmm2) \ 1619 AS2( psrlq xmm2, 32) \ 1620 AS2( movdqa [esp+20+32*n+2*edx+16], xmm2) \ 1622 AS2( cmp edx, 8*(n)) \ 1624 AS2( lea edi, [esp+20])\ 1625 AS2( lea edx, [esp+20+16*n])\ 1626 AS2( lea esi, [esp+20+32*n])\ 1627 SSE2_FirstMultiply(0) \ 1629 #define Mul_Acc(i) \ 1631 AS2( movdqa xmm1, [esi+i/2*(1-(i-2*(i/2))*2)*16]) \ 1632 AS2( movdqa xmm0, [edi-i/2*(1-(i-2*(i/2))*2)*16]) \ 1633 AS2( movdqa xmm2, [ebx]) \ 1634 AS2( pmuludq xmm0, xmm1) \ 1635 AS2( pmuludq xmm1, [edx-i/2*(1-(i-2*(i/2))*2)*16]) \ 1636 AS2( movdqa xmm3, xmm2) \ 1637 AS2( pand xmm2, xmm0) \ 1638 AS2( psrld xmm0, 16) \ 1639 AS2( paddd xmm4, xmm2) \ 1640 AS2( paddd xmm5, xmm0) \ 1641 AS2( pand xmm3, xmm1) \ 1642 AS2( psrld xmm1, 16) \ 1643 AS2( paddd xmm6, xmm3) \ 1644 AS2( paddd xmm7, xmm1) \ 1647 #define Mul_Acc2(i) ASC(call, LMul##i) 1648 #define Mul_Acc3(i) Mul_Acc2(i) 1649 #define Mul_Acc4(i) Mul_Acc2(i) 1650 #define Mul_Acc5(i) Mul_Acc2(i) 1651 #define Mul_Acc6(i) Mul_Acc2(i) 1652 #define Mul_Acc7(i) Mul_Acc2(i) 1653 #define Mul_Acc8(i) Mul_Acc2(i) 1654 #define Mul_Acc9(i) Mul_Acc2(i) 1655 #define Mul_Acc10(i) Mul_Acc2(i) 1656 #define Mul_Acc11(i) Mul_Acc2(i) 1657 #define Mul_Acc12(i) Mul_Acc2(i) 1658 #define Mul_Acc13(i) Mul_Acc2(i) 1659 #define Mul_Acc14(i) Mul_Acc2(i) 1660 #define Mul_Acc15(i) Mul_Acc2(i) 1661 #define Mul_Acc16(i) Mul_Acc2(i) 1663 #define Mul_Column1(k, i) \ 1669 #define Mul_Column0(k, i) \ 1676 #define Bot_Acc(i) \ 1677 AS2( movdqa xmm1, [esi+i/2*(1-(i-2*(i/2))*2)*16]) \ 1678 AS2( movdqa xmm0, [edi-i/2*(1-(i-2*(i/2))*2)*16]) \ 1679 AS2( pmuludq xmm0, xmm1) \ 1680 AS2( pmuludq xmm1, [edx-i/2*(1-(i-2*(i/2))*2)*16]) \ 1681 AS2( paddq xmm4, xmm0) \ 1682 AS2( paddd xmm6, xmm1) 1684 #define Bot_SaveAcc(k) \ 1688 AS2( movdqa xmm6, [esi]) \ 1689 AS2( movdqa xmm0, [edi]) \ 1690 AS2( pmuludq xmm0, xmm6) \ 1691 AS2( paddq xmm4, xmm0) \ 1692 AS2( psllq xmm5, 16) \ 1693 AS2( paddq xmm4, xmm5) \ 1694 AS2( pmuludq xmm6, [edx]) 1696 #define Bot_End(n) \ 1697 AS2( movhlps xmm7, xmm6) \ 1698 AS2( paddd xmm6, xmm7) \ 1699 AS2( psllq xmm6, 32) \ 1700 AS2( paddd xmm4, xmm6) \ 1701 AS2( movq QWORD PTR [ecx+8*((n)-1)], xmm4) \ 1705 #define Top_Begin(n) \ 1708 AS2( and esp, 0xfffffff0)\ 1709 AS2( sub esp, 48*n+16)\ 1711 AS2( xor edx, edx) \ 1713 ASS( pshufd xmm0, [eax+edx], 3,1,2,0) \ 1714 ASS( pshufd xmm1, [eax+edx], 2,0,3,1) \ 1715 ASS( pshufd xmm2, [edi+edx], 3,1,2,0) \ 1716 AS2( movdqa [esp+20+2*edx], xmm0) \ 1717 AS2( psrlq xmm0, 32) \ 1718 AS2( movdqa [esp+20+2*edx+16], xmm0) \ 1719 AS2( movdqa [esp+20+16*n+2*edx], xmm1) \ 1720 AS2( psrlq xmm1, 32) \ 1721 AS2( movdqa [esp+20+16*n+2*edx+16], xmm1) \ 1722 AS2( movdqa [esp+20+32*n+2*edx], xmm2) \ 1723 AS2( psrlq xmm2, 32) \ 1724 AS2( movdqa [esp+20+32*n+2*edx+16], xmm2) \ 1726 AS2( cmp edx, 8*(n)) \ 1728 AS2( mov eax, esi) \ 1729 AS2( lea edi, [esp+20+00*n+16*(n/2-1)])\ 1730 AS2( lea edx, [esp+20+16*n+16*(n/2-1)])\ 1731 AS2( lea esi, [esp+20+32*n+16*(n/2-1)])\ 1732 AS2( pxor xmm4, xmm4)\ 1733 AS2( pxor xmm5, xmm5) 1735 #define Top_Acc(i) \ 1736 AS2( movq xmm0, QWORD PTR [esi+i/2*(1-(i-2*(i/2))*2)*16+8]) \ 1737 AS2( pmuludq xmm0, [edx-i/2*(1-(i-2*(i/2))*2)*16]) \ 1738 AS2( psrlq xmm0, 48) \ 1739 AS2( paddd xmm5, xmm0)\ 1741 #define Top_Column0(i) \ 1742 AS2( psllq xmm5, 32) \ 1748 #define Top_Column1(i) \ 1754 AS2( movd xmm0, eax)\ 1755 AS2( movd xmm1, [ecx+4])\ 1756 AS2( psrld xmm1, 16)\ 1757 AS2( pcmpgtd xmm1, xmm0)\ 1758 AS2( psrld xmm1, 31)\ 1759 AS2( paddd xmm4, xmm1)\ 1761 void SSE2_Square4(
word *C,
const word *A)
1768 void SSE2_Square8(
word *C,
const word *A)
1784 void SSE2_Square16(
word *C,
const word *A)
1808 void SSE2_Square32(
word *C,
const word *A)
1846 void SSE2_Multiply4(
word *C,
const word *A,
const word *B)
1858 void SSE2_Multiply8(
word *C,
const word *A,
const word *B)
1874 void SSE2_Multiply16(
word *C,
const word *A,
const word *B)
1898 void SSE2_Multiply32(
word *C,
const word *A,
const word *B)
1936 void SSE2_MultiplyBottom4(
word *C,
const word *A,
const word *B)
1943 void SSE2_MultiplyBottom8(
word *C,
const word *A,
const word *B)
1957 void SSE2_MultiplyBottom16(
word *C,
const word *A,
const word *B)
1975 void SSE2_MultiplyBottom32(
word *C,
const word *A,
const word *B)
2062 #endif // #if CRYPTOPP_INTEGER_SSE2 2071 #if CRYPTOPP_INTEGER_SSE2 2073 static size_t s_recursionLimit = 8;
2075 static const size_t s_recursionLimit = 16;
2076 #endif // CRYPTOPP_INTEGER_SSE2 2078 static PMul s_pMul[9], s_pBot[9];
2079 static PSqu s_pSqu[9];
2082 static void SetFunctionPointers()
2090 #if CRYPTOPP_INTEGER_SSE2 2099 s_recursionLimit = 32;
2101 s_pMul[1] = &SSE2_Multiply4;
2102 s_pMul[2] = &SSE2_Multiply8;
2103 s_pMul[4] = &SSE2_Multiply16;
2104 s_pMul[8] = &SSE2_Multiply32;
2106 s_pBot[1] = &SSE2_MultiplyBottom4;
2107 s_pBot[2] = &SSE2_MultiplyBottom8;
2108 s_pBot[4] = &SSE2_MultiplyBottom16;
2109 s_pBot[8] = &SSE2_MultiplyBottom32;
2111 s_pSqu[1] = &SSE2_Square4;
2112 s_pSqu[2] = &SSE2_Square8;
2113 s_pSqu[4] = &SSE2_Square16;
2114 s_pSqu[8] = &SSE2_Square32;
2116 s_pTop[2] = &SSE2_MultiplyTop8;
2117 s_pTop[4] = &SSE2_MultiplyTop16;
2118 s_pTop[8] = &SSE2_MultiplyTop32;
2121 #endif // CRYPTOPP_INTEGER_SSE2 2134 #if !CRYPTOPP_INTEGER_SSE2 2139 #endif // !CRYPTOPP_INTEGER_SSE2 2145 #if CRYPTOPP_INTEGER_SSE2 2146 return s_pAdd(N, C, A, B);
2149 #endif // CRYPTOPP_INTEGER_SSE2 2154 #if CRYPTOPP_INTEGER_SSE2 2155 return s_pSub(N, C, A, B);
2158 #endif // CRYPTOPP_INTEGER_SSE2 2188 if (N <= s_recursionLimit)
2189 s_pMul[N/4](
R, A, B);
2192 const size_t N2 = N/2;
2194 size_t AN2 = Compare(
A0,
A1, N2) > 0 ? 0 : N2;
2197 size_t BN2 = Compare(
B0,
B1, N2) > 0 ? 0 : N2;
2216 c3 += Increment(
R2, N2, c2);
2218 Increment(
R3, N2, c3);
2230 if (N <= s_recursionLimit)
2234 const size_t N2 = N/2;
2242 Increment(
R3, N2, carry);
2255 if (N <= s_recursionLimit)
2256 s_pBot[N/4](
R, A, B);
2259 const size_t N2 = N/2;
2279 if (N <= s_recursionLimit)
2280 s_pTop[N/4](
R, A, B, L[N-1]);
2283 const size_t N2 = N/2;
2285 size_t AN2 = Compare(
A0,
A1, N2) > 0 ? 0 : N2;
2288 size_t BN2 = Compare(
B0,
B1, N2) > 0 ? 0 : N2;
2302 t = (Compare(
T2,
R0, N2) == -1);
2308 t = (Compare(
T2,
R0, N2) == -1);
2314 c3 += Increment(
T2, N2, c2);
2316 c3 -= Decrement(
T2, N2, -c2);
2320 Increment(
R1, N2, c3);
2373 R[NB] = LinearMultiply(R, B, A[0], NB);
2381 R[NB] = R[NB+1] = 0;
2392 for (i=2*NA; i<NB; i+=2*NA)
2394 for (i=NA; i<NB; i+=2*NA)
2399 for (i=0; i<NB; i+=2*NA)
2401 for (i=NA; i<NB; i+=2*NA)
2405 if (
Add(R+NA, R+NA, T+2*NA, NB-NA))
2406 Increment(R+NB, NA);
2419 const size_t N2 = N/2;
2426 TwosComplement(
T0, N2);
2431 T[0] = AtomicInverseModPower2(A[0]);
2433 s_pBot[0](T+2,
T, A);
2434 TwosComplement(T+2, 2);
2435 Increment(T+2, 2, 2);
2436 s_pBot[0](
R,
T, T+2);
2453 word carry =
Add(T+N, T, M, N);
2458 const word u = 0-U[0];
2460 for (
size_t i=0; i<N; i++)
2462 const word t = u * X[i];
2464 for (
size_t j=0; j<N; j+=2)
2478 if (Increment(X+N+i, N-i, c))
2479 while (!
Subtract(X+N, X+N, M, N)) {}
2484 __m64 u = _mm_cvtsi32_si64(0-U[0]), p;
2485 for (
size_t i=0; i<N; i++)
2487 __m64 t = _mm_cvtsi32_si64(X[i]);
2488 t = _mm_mul_su32(t, u);
2489 __m64
c = _mm_setzero_si64();
2490 for (
size_t j=0; j<N; j+=2)
2492 p = _mm_mul_su32(t, _mm_cvtsi32_si64(M[j]));
2493 p = _mm_add_si64(p, _mm_cvtsi32_si64(X[i+j]));
2494 c = _mm_add_si64(c, p);
2495 X[i+j] = _mm_cvtsi64_si32(c);
2496 c = _mm_srli_si64(c, 32);
2497 p = _mm_mul_su32(t, _mm_cvtsi32_si64(M[j+1]));
2498 p = _mm_add_si64(p, _mm_cvtsi32_si64(X[i+j+1]));
2499 c = _mm_add_si64(c, p);
2500 X[i+j+1] = _mm_cvtsi64_si32(c);
2501 c = _mm_srli_si64(c, 32);
2504 if (Increment(X+N+i, N-i, _mm_cvtsi64_si32(c)))
2505 while (!
Subtract(X+N, X+N, M, N)) {}
2508 memcpy(R, X+N, N*WORD_SIZE);
2534 const size_t N2 = N/2;
2544 c3 +=
Add(R, R, T, N);
2547 c3 += Increment(
R1, N2);
2549 c3 -= Decrement(
R1, N2, -c2);
2647 static inline void AtomicDivide(
word *
Q,
const word *A,
const word *B)
2650 DWord q = DivideFourWordsByTwo<word, DWord>(
T,
DWord(A[0], A[1]),
DWord(A[2], A[3]),
DWord(B[0], B[1]));
2654 #if defined(CRYPTOPP_DEBUG) 2658 CRYPTOPP_ASSERT(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]<B[0])));
2678 while (
R[N] || Compare(
R, B, N) >= 0)
2681 Q[1] += (++
Q[0]==0);
2700 word *
const TB=T+NA+2;
2701 word *
const TP=T+NA+2+NB;
2704 unsigned shiftWords = (B[NB-1]==0);
2705 TB[0] = TB[NB-1] = 0;
2706 CopyWords(TB+shiftWords, B, NB-shiftWords);
2712 TA[0] = TA[NA] = TA[NA+1] = 0;
2716 if (TA[NA+1]==0 && TA[NA] <= 1)
2718 Q[NA-NB+1] = Q[NA-NB] = 0;
2719 while (TA[NA] || Compare(TA+NA-NB, TB, NB) >= 0)
2721 TA[NA] -=
Subtract(TA+NA-NB, TA+NA-NB, TB, NB);
2732 BT[0] = TB[NB-2] + 1;
2733 BT[1] = TB[NB-1] + (BT[0]==0);
2736 for (
size_t i=NA-2; i>=NB; i-=2)
2738 AtomicDivide(Q+i-NB, TA+i-2, BT);
2739 CorrectQuotientEstimate(TA+i-NB, TP, Q+i-NB, TB, NB);
2747 static inline size_t EvenWordCount(
const word *
X,
size_t N)
2749 while (N &&
X[N-2]==0 &&
X[N-1]==0)
2768 size_t bcLen=2, fgLen=EvenWordCount(M, N);
2782 if (EvenWordCount(f, fgLen)==0)
2789 bcLen += 2 * (c[bcLen-1] != 0);
2801 if (t==1 && f[1]==0 && EvenWordCount(f+2, fgLen-2)==0)
2813 bcLen += 2 * (t!=0);
2816 bool swap = Compare(f, g, fgLen)==-1;
2821 fgLen -= 2 * !(f[fgLen-2] | f[fgLen-1]);
2824 t =
Add(b, b, c, bcLen);
2871 SetFunctionPointers();
2876 static const unsigned int RoundupSizeTable[] = {2, 2, 2, 4, 4, 8, 8, 8, 8};
2878 static inline size_t RoundupSize(
size_t n)
2881 return RoundupSizeTable[n];
2893 : reg(2),
sign(POSITIVE)
2937 unsigned long value = (
unsigned long)
reg[0];
2941 return (
signed long)value >= 0;
2943 return -(
signed long)value < 0;
2950 unsigned long value = (
unsigned long)
reg[0];
2962 encodedInteger.
Get(block, block.
size());
2969 Decode(encodedInteger, byteCount, s);
2979 #if (CRYPTOPP_MSC_VERSION >= 1400) 2980 std::reverse_copy(encodedInteger, encodedInteger+byteCount,
2981 stdext::make_checked_array_iterator(block.
begin(), block.
size()));
2983 std::reverse_copy(encodedInteger, encodedInteger+byteCount, block.
begin());
2989 Decode(encodedInteger, byteCount, s);
3004 if (!
Randomize(rng, min, max, rnType, equiv, mod))
3110 for (
unsigned int j=0; j<n; j++)
3147 int radix,
sign = 1;
3150 unsigned int length;
3151 for (length = 0; str[length] != 0; length++) {}
3158 switch (str[length-1])
3180 str += 1, length -= 1;
3183 if (length > 2 && str[0] ==
'0' && (str[1] ==
'x' || str[1] ==
'X'))
3186 str += 2, length -= 2;
3191 for (
unsigned int i=0; i<length; i++)
3193 int digit,
ch =
static_cast<int>(str[i]);
3197 if (ch >=
'0' && ch <=
'9')
3199 else if (ch >=
'a' && ch <=
'f')
3200 digit = ch -
'a' + 10;
3201 else if (ch >=
'A' && ch <=
'F')
3202 digit = ch -
'A' + 10;
3216 unsigned int nh = 0, nl = 0, nc = 0;
3219 for (
unsigned int i=0; i<length; i++)
3221 int digit,
ch =
static_cast<int>(str[i]);
3223 if (ch >=
'0' && ch <=
'9')
3225 else if (ch >=
'a' && ch <=
'f')
3226 digit = ch -
'a' + 10;
3227 else if (ch >=
'A' && ch <=
'F')
3228 digit = ch -
'A' + 10;
3241 v += position * (nh << 4 | nl);
3242 nc = 0, position <<= 8;
3252 for (
int i=static_cast<int>(length)-1; i>=0; i--)
3254 int digit,
ch =
static_cast<int>(str[i]);
3256 if (ch >=
'0' && ch <=
'9')
3258 else if (ch >=
'a' && ch <=
'f')
3259 digit = ch -
'a' + 10;
3260 else if (ch >=
'A' && ch <=
'F')
3261 digit = ch -
'A' + 10;
3282 *
this = StringToInteger(str,order);
3288 *
this = StringToInteger(str,order);
3317 Decode(store, inputLen, s);
3328 while (inputLen>0 && (
sign==
POSITIVE ? b==0 : b==0xff))
3340 for (
size_t i=inputLen; i > 0; i--)
3359 const bool pre = (signedness ==
UNSIGNED);
3373 Encode(sink, outputLen, signedness);
3380 for (
size_t i=outputLen; i > 0; i--)
3441 return 2 + byteCount;
3460 const size_t nbytes = nbits/8 + 1;
3464 buf[0] = (
byte)
Crop(buf[0], nbits % 8);
3474 const unsigned int nbits = range.
BitCount();
3480 while (*
this > range);
3494 : m_counter(0), m_counterAndSeed(seedSize + 4)
3496 memcpy(m_counterAndSeed + 4, seed, seedSize);
3530 throw InvalidArgument(
"Integer: invalid EquivalentTo and/or Mod argument");
3536 if (params.
GetValue(Name::Seed(), seed))
3549 bq.
Get(finalSeed, finalSeed.size());
3550 kdf2Rng.
reset(
new KDF2_RNG(finalSeed.begin(), finalSeed.size()));
3582 if (
FirstPrime(first, max, equiv, mod, pSelector))
3586 if (!
FirstPrime(first, max, equiv, mod, pSelector))
3607 unsigned int length = 0;
3616 if (length >= str.
size())
3617 str.
Grow(length + 16);
3619 while (in && (c==
'-' || c==
'x' || (c>=
'0' && c<=
'9') || (c>=
'a' && c<=
'f') || (c>=
'A' && c<=
'F') || c==
'h' || c==
'H' || c==
'o' || c==
'O' || c==
',' || c==
'.'));
3623 str[length-1] =
'\0';
3632 const long f = out.flags() & std::ios::basefield;
3637 case std::ios::oct :
3642 case std::ios::hex :
3664 static const char upper[]=
"0123456789ABCDEF";
3665 static const char lower[]=
"0123456789abcdef";
3667 const char* vec = (out.flags() & std::ios::uppercase) ? upper : lower;
3686 #ifdef CRYPTOPP_USE_STD_SHOWBASE 3687 if (out.flags() & std::ios_base::showbase)
3692 return out << suffix;
3857 borrow = Decrement(diff.
reg+bSize, aSize-bSize, borrow);
3861 else if (aSize == bSize)
3878 borrow = Decrement(diff.
reg+aSize, bSize-aSize, borrow);
3887 return a < b ? b :
a;
3985 const size_t shiftWords = n /
WORD_BITS;
3986 const unsigned int shiftBits = (
unsigned int)(n %
WORD_BITS);
3997 const size_t shiftWords = n /
WORD_BITS;
3998 const unsigned int shiftBits = (
unsigned int)(n %
WORD_BITS);
4001 if (wordCount > shiftWords)
4030 const size_t head =
reg.
size();
4055 const size_t head =
reg.
size();
4068 size_t aSize = RoundupSize(a.
WordCount());
4069 size_t bSize = RoundupSize(b.
WordCount());
4137 quotient.
reg.
CleanNew(RoundupSize(aSize-bSize+2));
4209 if ((divisor & (divisor-1)) == 0)
4212 remainder = dividend.
reg[0] & (divisor-1);
4221 quotient.
reg[i] =
DWord(dividend.
reg[i], remainder) / divisor;
4222 remainder =
DWord(dividend.
reg[i], remainder) % divisor;
4233 remainder = divisor - remainder;
4255 if ((divisor & (divisor-1)) != 0)
4264 remainder =
DWord(
reg[i], remainder) % divisor;
4271 remainder = sum % divisor;
4276 remainder =
reg[0] & (divisor-1);
4280 remainder = divisor - remainder;
4297 return size > tSize ? 1 : -1;
4299 return CryptoPP::Compare(
reg, t.
reg, size);
4332 y = (x + *
this/
x) >> 1;
4385 return !u ?
Zero() : (m*(*
this-u)+1)/(*this);
4398 word v0 = 0, v1 = 1;
4426 if (oid != ASN1::prime_field())
4428 m_modulus.BERDecode(seq);
4430 m_result.reg.resize(m_modulus.reg.size());
4436 ASN1::prime_field().DEREncode(seq);
4437 m_modulus.DEREncode(seq);
4453 if (a.
reg.
size()==m_modulus.reg.size())
4459 return m_result1 = (a.
IsEven() ? (a >> 1) : ((a+m_modulus) >> 1));
4464 if (a.
reg.
size()==m_modulus.reg.size() && b.
reg.
size()==m_modulus.reg.size())
4476 if (m_result1 >= m_modulus)
4477 m_result1 -= m_modulus;
4484 if (a.
reg.
size()==m_modulus.reg.size() && b.
reg.
size()==m_modulus.reg.size())
4504 if (a.
reg.
size()==m_modulus.reg.size() && b.
reg.
size()==m_modulus.reg.size())
4513 if (m_result1.IsNegative())
4514 m_result1 += m_modulus;
4521 if (a.
reg.
size()==m_modulus.reg.size() && b.
reg.
size()==m_modulus.reg.size())
4550 if (m_modulus.IsOdd())
4561 if (m_modulus.IsOdd())
4565 for (
unsigned int i=0; i<exponentsCount; i++)
4575 m_workspace(5*m_modulus.
reg.
size())
4578 throw InvalidArgument(
"MontgomeryRepresentation: Montgomery representation requires an odd modulus");
4651 static const unsigned int BIT_32 = (1U << 31);
4652 const bool UPPER = !!(base & BIT_32);
4653 static const unsigned int BIT_31 = (1U << 30);
4654 const bool BASE = !!(base & BIT_31);
4656 const char CH = UPPER ?
'A' :
'a';
4657 base &= ~(BIT_32|BIT_31);
4663 bool negative =
false, zero =
false;
4664 if (value.IsNegative())
4681 s[i++]=char((digit < 10 ?
'0' : (CH - 10)) + digit);
4686 result.reserve(i+2);
4701 else if (base == 16)
4717 static const unsigned int HIGH_BIT = (1U << 31);
4718 const char CH = !!(base & HIGH_BIT) ?
'A' :
'a';
4728 word64 digit = value % base;
4729 result = char((digit < 10 ?
'0' : (CH - 10)) + digit) + result;
Used to pass byte array input as part of a NameValuePairs object.
#define AddWithCarry(u, a, b)
Integer Minus(const Integer &b) const
Subtraction.
An invalid argument was detected.
lword RemainingLength() const
void MultiplyByPower2Mod(word *R, const word *A, size_t k, const word *M, size_t N)
Integer And(const Integer &) const
Bitwise AND.
void Baseline_Square16(word *R, const word *AA)
void DEREncode(BufferedTransformation &bt) const
Encodes in DER format.
Integer CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const
TODO.
void RecursiveMultiply(word *R, word *T, const word *A, const word *B, size_t N)
unsigned int PrimeSearchInterval(const Integer &max)
Classes for working with NameValuePairs.
const Integer & Square(const Integer &a) const
Square an element in the ring.
Integer & operator|=(const Integer &t)
Bitwise OR Assignment.
void CopyWords(word *r, const word *a, size_t n)
const Integer & MultiplicativeInverse(const Integer &a) const
Calculate the multiplicative inverse of an element in the ring.
friend void PositiveAdd(Integer &sum, const Integer &a, const Integer &b)
void swap(SecBlock< T, A > &b)
Swap contents with another SecBlock.
a number which is probabilistically prime
Utility functions for the Crypto++ library.
word operator/(word divisor)
bool(CRYPTOPP_API * PAssignIntToInteger)(const std::type_info &valueType, void *pInteger, const void *pInt)
ByteOrder
Provides the byte ordering.
Restricts the instantiation of a class to one static object without locks.
bool NotZero() const
Determines if the Integer is non-0.
unsigned int AlmostInverse(word *R, word *T, const word *A, size_t NA, const word *M, size_t N)
bool AssignIntToInteger(const std::type_info &valueType, void *pInteger, const void *pInt)
size_t CountWords(const word *X, size_t N)
bool GetBit(size_t i) const
Provides the i-th bit of the Integer.
void CleanNew(size_type newSize)
Change size without preserving contents.
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
CRYPTOPP_DLL friend Integer CRYPTOPP_API a_times_b_mod_c(const Integer &x, const Integer &y, const Integer &m)
modular multiplication
Integer & Reduce(Integer &a, const Integer &b) const
TODO.
bool IsOdd() const
Determines if the Integer is odd parity.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag=INTEGER)
DER Encode unsigned value.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
const T & STDMAX2(const T &a, const T &b)
Integer & operator=(const Integer &t)
Assignment.
bool operator!() const
Negation.
static Integer CRYPTOPP_API Gcd(const Integer &a, const Integer &n)
greatest common divisor
void resize(size_type newSize)
Change size and preserve contents.
Integer & operator+=(const Integer &t)
Addition Assignment.
size_t BitsToWords(size_t bitCount)
Returns the number of words required for the specified number of bits.
const Integer & Subtract(const Integer &a, const Integer &b) const
Subtracts elements in the ring.
void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, const byte *xorBlock=NULL)
Access a block of memory.
void Baseline_Square8(word *R, const word *AA)
unsigned int BytePrecision(const T &value)
Returns the number of 8-bit bytes or octets required for a value.
int PositiveCompare(const Integer &t) const
void CleanGrow(size_type newSize)
Change size and preserve contents.
#define NAMESPACE_BEGIN(x)
void Baseline_Multiply4(word *R, const word *AA, const word *BB)
Integer & operator--()
Pre-decrement.
CRYPTOPP_DLL bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
void Baseline_Multiply2(word *R, const word *AA, const word *BB)
friend void PositiveMultiply(Integer &product, const Integer &a, const Integer &b)
Integer * operator()() const
bool IsEven() const
Determines if the Integer is even parity.
unsigned int WordCount() const
Determines the number of words required to represent the Integer.
void Baseline_MultiplyBottom2(word *R, const word *AA, const word *BB)
void MontgomeryReduce(word *R, word *T, word *X, const word *M, const word *U, size_t N)
CRYPTOPP_DLL std::string IntToString< word64 >(word64 value, unsigned int base)
Converts an unsigned value to a string.
void OpenPGPDecode(const byte *input, size_t inputLen)
Decode from OpenPGP format.
Signedness
Used when importing and exporting integers.
size_type size() const
Provides the count of elements in the SecBlock.
int CRYPTOPP_FASTCALL Baseline_Add(size_t N, word *C, const word *A, const word *B)
ASN.1 object identifiers for algorthms and schemes.
Classes for automatic resource management.
size_t size() const
Length of the memory block.
void RecursiveInverseModPower2(word *R, word *T, const word *A, size_t N)
byte GetByte(size_t i) const
Provides the i-th byte of the Integer.
Library configuration file.
MontgomeryRepresentation(const Integer &modulus)
Construct a MontgomeryRepresentation.
static void CRYPTOPP_API DivideByPowerOf2(Integer &r, Integer &q, const Integer &a, unsigned int n)
returns same result as Divide(r, q, a, Power2(n)), but faster
Ring of congruence classes modulo n.
std::hash for asio::adress
Interface for random number generators.
size_t BytesToWords(size_t byteCount)
Returns the number of words required for the specified number of bytes.
void Randomize(RandomNumberGenerator &rng, size_t bitCount)
Set this Integer to random integer.
KDF2_RNG(const byte *seed, size_t seedSize)
#define SubtractWithBorrow(u, a, b)
size_t MinEncodedSize(Signedness sign=UNSIGNED) const
Minimum number of bytes to encode this integer.
void New(size_type newSize)
Change size without preserving contents.
int Add(word *C, const word *A, const word *B, size_t N)
void Baseline_MultiplyBottom4(word *R, const word *AA, const word *BB)
void SetByte(size_t n, byte value)
Set the n-th byte to value.
virtual void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the Ring.
void DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const
Encode absolute value as big-endian octet string.
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
const byte * begin() const
Pointer to the first byte in the memory block.
bool IsConvertableToLong() const
Determines if the Integer is convertable to Long.
Integer MultiplicativeInverse() const
return inverse if 1 or -1, otherwise return 0
if(a.IndicesBefore(b, len, lenIndices))
void(* PMul)(word *C, const word *A, const word *B)
static const Integer &CRYPTOPP_API One()
Integer representing 1.
const Integer & Add(const Integer &a, const Integer &b) const
Adds elements in the ring.
byte order is little-endian
Sign
Used internally to represent the integer.
void Baseline_MultiplyBottom16(word *R, const word *AA, const word *BB)
Pointer that overloads operator ->
bool IsSquare() const
Determine whether this integer is a perfect square.
size_t OpenPGPEncode(byte *output, size_t bufferSize) const
Encode absolute value in OpenPGP format.
#define Mul_SaveAcc(k, i, j)
Classes and functions for secure memory allocations.
unsigned int BitCount() const
Determines the number of bits required to represent the Integer.
SecByteBlock m_counterAndSeed
void BERDecodeElement(BufferedTransformation &in, Element &a) const
Decodes element in DER format.
bool IsUnit() const
is 1 or -1
Copy input to a memory buffer.
void MultiplyTop(word *R, word *T, const word *L, const word *A, const word *B, size_t N)
Integer operator<<(size_t n) const
Left-shift.
size_t DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
ASN Strings.
void ShiftWordsLeftByWords(word *r, size_t n, size_t shiftWords)
CRYPTOPP_DLL std::string IntToString< Integer >(Integer value, unsigned int base)
Converts an Integer to a string.
PAssignIntToInteger g_pAssignIntToInteger
#define CRYPTOPP_ALIGN_DATA(x)
void(* PSqu)(word *C, const word *A)
Integer SquareRoot() const
Extract square root.
IntegerSecBlock m_workspace
const unsigned int WORD_BITS
#define Acc2WordsBy1(a, b)
bool IsPositive() const
Determines if the Integer is positive.
int(CRYPTOPP_FASTCALL * PAdd)(size_t N, word *C, const word *A, const word *B)
bool GetValue(const char *name, T &value) const
Get a named value.
a number with no special properties
Integer Squared() const
Multiply this integer by itself.
void Baseline_Square2(word *R, const word *AA)
Integer & operator++()
Pre-increment.
bool IsNegative() const
Determines if the Integer is negative.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
void swap(Integer &a)
Swaps this Integer with another Integer.
Integer()
Creates the zero integer.
unsigned int TrailingZeros(word32 v)
Determines the number of trailing 0-bits in a value.
friend void PositiveSubtract(Integer &diff, const Integer &a, const Integer &b)
Word(hword low, hword high)
Integer & operator<<=(size_t n)
Left-shift Assignment.
signed long ConvertToLong() const
Convert the Integer to Long.
D DivideFourWordsByTwo(S *T, const D &Al, const D &Ah, const D &B)
Exception thrown when an error is encountered decoding an OpenPGP integer.
void Negate()
Reverse the Sign of the Integer.
#define Top_SaveAcc1(i, j)
hword GetHighHalf() const
T Crop(T value, size_t bits)
Truncates the value to the specified number of bits.
Integer Times(const Integer &b) const
Multiplication.
bool IsDefiniteLength() const
void BERDecodeAsOctetString(BufferedTransformation &bt, size_t length)
Decode nonnegative value from big-endian octet string.
static DWord Multiply(word a, word b)
Application callback to signal suitability of a cabdidate prime.
void ConditionalSwapPointers(bool c, T &a, T &b)
Performs a branchless swap of pointers a and b if condition c is true.
static Integer CRYPTOPP_API Power2(size_t e)
Exponentiates to a power of 2.
DWord(word low, word high)
void AsymmetricMultiply(word *R, word *T, const word *A, size_t NA, const word *B, size_t NB)
Multiple precision integer with arithmetic operations.
hword GetHighHalfAsBorrow() const
void SetWords(word *r, word a, size_t n)
CRYPTOPP_DLL friend Integer CRYPTOPP_API a_exp_b_mod_c(const Integer &x, const Integer &e, const Integer &m)
modular exponentiation
void Divide(word *R, word *Q, word *T, const word *A, size_t NA, const word *B, size_t NB)
void MultiplyBottom(word *R, word *T, const word *A, const word *B, size_t N)
DWord & operator+=(word a)
void Baseline_MultiplyBottom8(word *R, const word *AA, const word *BB)
unsigned long long word64
void RecursiveMultiplyBottom(word *R, word *T, const word *A, const word *B, size_t N)
static const Integer &CRYPTOPP_API Two()
Integer representing 2.
Integer ConvertOut(const Integer &a) const
Reduces an element in the congruence class.
virtual Element CascadeExponentiate(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const
TODO.
Integer DividedBy(const Integer &b) const
Division.
void Baseline_MultiplyTop2(word *R, const word *A, const word *B, word L)
void Baseline_Multiply8(word *R, const word *AA, const word *BB)
Integer & operator^=(const Integer &t)
Bitwise XOR Assignment.
RandomNumberType
Properties of a random integer.
const Integer & Inverse(const Integer &a) const
Inverts the element in the ring.
void ShiftWordsRightByWords(word *r, size_t n, size_t shiftWords)
const unsigned int WORD_SIZE
hword operator/(hword divisor)
Safely right shift values when undefined behavior could occur.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
String-based implementation of Store interface.
#define CRYPTOPP_ASSERT(exp)
static void CRYPTOPP_API Divide(Integer &r, Integer &q, const Integer &a, const Integer &d)
calculate r and q such that (a == d*q + r) && (0 <= r < abs(d))
void RecursiveSquare(word *R, word *T, const word *A, size_t N)
ModularArithmetic(const Integer &modulus=Integer::One())
Construct a ModularArithmetic.
void BERDecodeError()
Raises a BERDecodeErr.
Data structure used to store byte strings.
Functions for CPU features and intrinsics.
Classes and functions for working with ANS.1 objects.
Classes for SHA-1 and SHA-2 family of message digests.
void SetBit(size_t n, bool value=1)
Set the n-th bit to value.
iterator begin()
Provides an iterator pointing to the first element in the memory block.
#define Top_SaveAcc0(i, j)
Signature sign(Secret const &_k, h256 const &_hash)
Returns siganture of message hash.
Integer & Accumulate(Integer &a, const Integer &b) const
TODO.
Implementation of BufferedTransformation's attachment interface.
Classes and functions for number theoretic operations.
void Baseline_MultiplyTop4(word *R, const word *AA, const word *BB, word L)
const Integer & Half(const Integer &a) const
Divides an element by 2.
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
Exception thrown when division by 0 is encountered.
void XorWords(word *r, const word *a, const word *b, size_t n)
T1 SaturatingSubtract1(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 1.
void Baseline_MultiplyTop16(word *R, const word *AA, const word *BB, word L)
Exception thrown when a random number cannot be found that satisfies the condition.
bool GenerateRandomNoThrow(RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs)
Performs modular arithmetic in Montgomery representation for increased speed.
void Baseline_MultiplyTop8(word *R, const word *AA, const word *BB, word L)
uint8_t const size_t const size
bool FirstPrime(Integer &p, const Integer &max, const Integer &equiv, const Integer &mod, const PrimeSelector *pSelector)
Finds a random prime of special form.
void * memcpy(void *a, const void *b, size_t c)
void Baseline_Square4(word *R, const word *AA)
#define CRYPTOPP_UNUSED(x)
static DWord MultiplyAndAdd(word a, word b, word c)
#define Bot_SaveAcc(k, i, j)
void Multiply(word *R, word *T, const word *A, const word *B, size_t N)
Integer CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const
TODO.
Integer Plus(const Integer &b) const
Addition.
void(* PMulTop)(word *C, const word *A, const word *B, word L)
N diff(N const &_a, N const &_b)
const Integer & Multiply(const Integer &a, const Integer &b) const
Multiplies elements in the ring.
void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Integer InverseMod(const Integer &n) const
calculate multiplicative inverse of *this mod n
void Decode(const byte *input, size_t inputLen, Signedness sign=UNSIGNED)
Decode from big-endian byte array.
word ShiftWordsRightByBits(word *r, size_t n, unsigned int shiftBits)
Multiple precision integer with arithmetic operations.
void DEREncodeElement(BufferedTransformation &out, const Element &a) const
Encodes element in DER format.
#define CRYPTOPP_FASTCALL
void Square(word *R, word *T, const word *A, size_t N)
Safely left shift values when undefined behavior could occur.
static const Integer &CRYPTOPP_API Zero()
Integer representing 0.
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
int CRYPTOPP_FASTCALL Baseline_Sub(size_t N, word *C, const word *A, const word *B)
void Grow(size_type newSize)
Change size and preserve contents.
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
lword GetBits(size_t i, size_t n) const
Provides the low order bits of the Integer.
#define MultiplyWords(p, a, b)
Class file for performing modular arithmetic.
Integer Xor(const Integer &) const
Bitwise XOR.
int Subtract(word *C, const word *A, const word *B, size_t N)
Integer operator>>(size_t n) const
Right-shift.
Integer & operator>>=(size_t n)
Right-shift Assignment.
Integer Or(const Integer &) const
Bitwise OR.
word GetHighHalfAsBorrow() const
friend void PositiveDivide(Integer &remainder, Integer "ient, const Integer ÷nd, const Integer &divisor)
size_type SizeInBytes() const
Provides the number of bytes in the SecBlock.
Integer operator-() const
Subtraction.
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the ring.
word ShiftWordsLeftByBits(word *r, size_t n, unsigned int shiftBits)
uint32_t ch(uint32_t x, uint32_t y, uint32_t z)
int Compare(const Integer &a) const
Perform signed comparison.
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the ring.
void Baseline_Multiply16(word *R, const word *AA, const word *BB)
Integer Modulo(const Integer &b) const
Remainder.
void DivideByPower2Mod(word *R, const word *A, size_t k, const word *M, size_t N)
size_t Get(byte &outByte)
Retrieve a 8-bit byte.
void OrWords(word *r, const word *a, const word *b, size_t n)
static Word Multiply(hword a, hword b)
Integer & operator&=(const Integer &t)
Bitwise AND Assignment.
static void CRYPTOPP_API DeriveKey(byte *output, size_t outputLength, const byte *input, size_t inputLength, const byte *derivationParams, size_t derivationParamsLength)
#define MAYBE_UNCONST_CAST
S DivideThreeWordsByTwo(S *A, S B0, S B1, D *dummy=NULL)
Integer & operator-=(const Integer &t)
Subtraction Assignment.
unsigned int BitPrecision(const T &value)
Returns the number of bits required for a value.
unsigned int ByteCount() const
Determines the number of bytes required to represent the Integer.
virtual Element Exponentiate(const Element &a, const Integer &e) const
Raises a base to an exponent in the group.
void HalfMontgomeryReduce(word *R, word *T, const word *X, const word *M, const word *U, const word *V, size_t N)
Integer ConvertIn(const Integer &a) const
Reduces an element in the congruence class.
the value is positive or 0
Integer AbsoluteValue() const
Retrieve the absolute value of this integer.
bool NotNegative() const
Determines if the Integer is non-negative.
Interface for retrieving values given their names.
#define CRYPTOPP_SECTION_ALIGN16
void AndWords(word *r, const word *a, const word *b, size_t n)