MCPcopy Create free account
hub / github.com/c3d/tao3D / InverseMod

Method InverseMod

libcryptopp/cryptopp/integer.cpp:3958–3981  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3956}
3957
3958Integer Integer::InverseMod(const Integer &m) const
3959{
3960 assert(m.NotNegative());
3961
3962 if (IsNegative())
3963 return Modulo(m).InverseMod(m);
3964
3965 if (m.IsEven())
3966 {
3967 if (!m || IsEven())
3968 return Zero(); // no inverse
3969 if (*this == One())
3970 return One();
3971
3972 Integer u = m.Modulo(*this).InverseMod(*this);
3973 return !u ? Zero() : (m*(*this-u)+1)/(*this);
3974 }
3975
3976 SecBlock<word> T(m.reg.size() * 4);
3977 Integer r((word)0, m.reg.size());
3978 unsigned k = AlmostInverse(r.reg, T, reg, reg.size(), m.reg, m.reg.size());
3979 DivideByPower2Mod(r.reg, r.reg, k, m.reg, m.reg.size());
3980 return r;
3981}
3982
3983word Integer::InverseMod(word mod) const
3984{

Callers

nothing calls this directly

Calls 6

IsNegativeFunction · 0.85
IsEvenFunction · 0.85
AlmostInverseFunction · 0.85
DivideByPower2ModFunction · 0.85
ModuloMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected