MCPcopy Create free account
hub / github.com/JeanLucPons/VanitySearch / MontgomeryMult

Method MontgomeryMult

IntMod.cpp:836–872  ·  view source on GitHub ↗

------------------------------------------------

Source from the content-addressed store, hash-verified

834
835// ------------------------------------------------
836void Int::MontgomeryMult(Int *a) {
837
838 // Compute a*b*R^-1 (mod n), R=2^k (mod n), k = Msize*64
839 // a and b must be lower than n
840 // See SetupField()
841
842 Int t;
843 Int pr;
844 Int p;
845 uint64_t ML;
846 uint64_t c;
847
848 // i = 0
849 imm_umul(a->bits64, bits64[0], pr.bits64);
850 ML = pr.bits64[0] * MM64;
851 imm_umul(_P.bits64, ML, p.bits64);
852 c = pr.AddC(&p);
853 memcpy(t.bits64, pr.bits64 + 1, 8 * (NB64BLOCK - 1));
854 t.bits64[NB64BLOCK - 1] = c;
855
856 for (int i = 1; i < Msize; i++) {
857
858 imm_umul(a->bits64, bits64[i], pr.bits64);
859 ML = (pr.bits64[0] + t.bits64[0]) * MM64;
860 imm_umul(_P.bits64, ML, p.bits64);
861 c = pr.AddC(&p);
862 t.AddAndShift(&t, &pr, c);
863
864 }
865
866 p.Sub(&t,&_P);
867 if (p.IsPositive())
868 Set(&p);
869 else
870 Set(&t);
871
872}
873
874void Int::MontgomeryMult(Int *a, Int *b) {
875

Callers 4

ModMulMethod · 0.80
ModSquareMethod · 0.80
ModCubeMethod · 0.80
SetupFieldMethod · 0.80

Calls 5

imm_umulFunction · 0.85
AddCMethod · 0.80
AddAndShiftMethod · 0.80
SubMethod · 0.80
IsPositiveMethod · 0.80

Tested by

no test coverage detected