MCPcopy Create free account
hub / github.com/LUX-Core/lux / SolveModularQuadraticEquation

Function SolveModularQuadraticEquation

src/cryptopp/nbtheory.cpp:623–646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

621}
622
623bool SolveModularQuadraticEquation(Integer &r1, Integer &r2, const Integer &a, const Integer &b, const Integer &c, const Integer &p)
624{
625 Integer D = (b.Squared() - 4*a*c) % p;
626 switch (Jacobi(D, p))
627 {
628 default:
629 CRYPTOPP_ASSERT(false); // not reached
630 return false;
631 case -1:
632 return false;
633 case 0:
634 r1 = r2 = (-b*(a+a).InverseMod(p)) % p;
635 CRYPTOPP_ASSERT(((r1.Squared()*a + r1*b + c) % p).IsZero());
636 return true;
637 case 1:
638 Integer s = ModularSquareRoot(D, p);
639 Integer t = (a+a).InverseMod(p);
640 r1 = (s-b)*t % p;
641 r2 = (-s-b)*t % p;
642 CRYPTOPP_ASSERT(((r1.Squared()*a + r1*b + c) % p).IsZero());
643 CRYPTOPP_ASSERT(((r2.Squared()*a + r2*b + c) % p).IsZero());
644 return true;
645 }
646}
647
648Integer ModularRoot(const Integer &a, const Integer &dp, const Integer &dq,
649 const Integer &p, const Integer &q, const Integer &u)

Callers 1

Calls 5

JacobiFunction · 0.85
ModularSquareRootFunction · 0.85
InverseModMethod · 0.80
IsZeroMethod · 0.80
SquaredMethod · 0.45

Tested by

no test coverage detected