MCPcopy Create free account
hub / github.com/albertobsd/keyhunt / MontgomeryMult

Method MontgomeryMult

secp256k1/IntMod.cpp:777–813  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

775
776// ------------------------------------------------
777void Int::MontgomeryMult(Int *a) {
778
779 // Compute a*b*R^-1 (mod n), R=2^k (mod n), k = Msize*64
780 // a and b must be lower than n
781 // See SetupField()
782
783 Int t;
784 Int pr;
785 Int p;
786 uint64_t ML;
787 uint64_t c;
788
789 // i = 0
790 imm_umul(a->bits64, bits64[0], pr.bits64);
791 ML = pr.bits64[0] * MM64;
792 imm_umul(_P.bits64, ML, p.bits64);
793 c = pr.AddC(&p);
794 memcpy(t.bits64, pr.bits64 + 1, 8 * (NB64BLOCK - 1));
795 t.bits64[NB64BLOCK - 1] = c;
796
797 for (int i = 1; i < Msize; i++) {
798
799 imm_umul(a->bits64, bits64[i], pr.bits64);
800 ML = (pr.bits64[0] + t.bits64[0]) * MM64;
801 imm_umul(_P.bits64, ML, p.bits64);
802 c = pr.AddC(&p);
803 t.AddAndShift(&t, &pr, c);
804
805 }
806
807 p.Sub(&t,&_P);
808 if (p.IsPositive())
809 Set(&p);
810 else
811 Set(&t);
812
813}
814
815void Int::MontgomeryMult(Int *a, Int *b) {
816

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.45
IsPositiveMethod · 0.45

Tested by

no test coverage detected