8 #ifndef CRYPTOPP_IMPORTS
10 NAMESPACE_BEGIN(CryptoPP)
35 const word r3a = (16 + 5 - r) % 16;
36 const word r3b = (16 + 13 - r) % 16;
37 const word r4 = (8 + 5 - r/2) % 8;
72 return GetValueHelper(
this, name, valueType, pValue).Assignable()
73 CRYPTOPP_GET_FUNCTION_ENTRY(Modulus)
79 AssignFromHelper(
this, source)
80 CRYPTOPP_SET_FUNCTION_ENTRY(Modulus)
90 int modulusSize = 2048;
94 throw InvalidArgument(
"InvertibleRWFunction: specified modulus length is too small");
126 DoQuickSanityCheck();
132 }
while (rInv.IsZero());
134 re = modn.Multiply(re, x);
137 if (Jacobi(cp, m_p) * Jacobi(cq, m_q) != 1)
139 cp = cp.IsOdd() ? (cp+m_p) >> 1 : cp >> 1;
140 cq = cq.IsOdd() ? (cq+m_q) >> 1 : cq >> 1;
147 cp = ModularSquareRoot(cp, m_p);
149 cq = ModularSquareRoot(cq, m_q);
152 Integer y = CRT(cq, m_q, cp, m_p, m_u);
153 y = modn.Multiply(y, rInv);
154 y = STDMIN(y, m_n-y);
155 if (ApplyFunction(y) != x)
163 pass = pass && m_p >
Integer::One() && m_p%8 == 3 && m_p < m_n;
164 pass = pass && m_q >
Integer::One() && m_q%8 == 7 && m_q < m_n;
165 pass = pass && m_u.IsPositive() && m_u < m_p;
168 pass = pass && m_p * m_q == m_n;
169 pass = pass && m_u * m_q % m_p == 1;
172 pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
178 return GetValueHelper<RWFunction>(
this, name, valueType, pValue).Assignable()
179 CRYPTOPP_GET_FUNCTION_ENTRY(Prime1)
180 CRYPTOPP_GET_FUNCTION_ENTRY(Prime2)
181 CRYPTOPP_GET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1)
187 AssignFromHelper<RWFunction>(
this, source)
188 CRYPTOPP_SET_FUNCTION_ENTRY(Prime1)
189 CRYPTOPP_SET_FUNCTION_ENTRY(Prime2)
190 CRYPTOPP_SET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1)