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)
base class for all exceptions thrown by Crypto++
exception thrown when an invalid argument is detected
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
to be implemented by derived classes, users should use one of the above functions instead ...
some error not belong to any of the above categories
ring of congruence classes modulo n
interface for random number generators
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
check this object for errors
Integer MultiplicativeInverse() const
return inverse if 1 or -1, otherwise return 0
static const Integer & One()
avoid calling constructors for these frequently used integers
bool GetIntValue(const char *name, int &value) const
get a named value with type int
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
This file contains classes that implement the Rabin-Williams signature schemes as defined in IEEE P13...
void AssignFrom(const NameValuePairs &source)
assign values from source to this object
multiple precision integer and basic arithmetics
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
check this object for errors
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
to be implemented by derived classes, users should use one of the above functions instead ...
void DEREncode(BufferedTransformation &bt) const
encode using Distinguished Encoding Rules, put result into a BufferedTransformation object ...
Integer InverseMod(const Integer &n) const
calculate multiplicative inverse of *this mod n
static const Integer & Zero()
avoid calling constructors for these frequently used integers
void AssignFrom(const NameValuePairs &source)
assign values from source to this object
interface for retrieving values given their names