11NAMESPACE_BEGIN(CryptoPP)
38 if (Jacobi(in, m_n)==-1)
47 CRYPTOPP_ASSERT(pass);
49 CRYPTOPP_ASSERT(pass);
51 CRYPTOPP_ASSERT(pass);
54 pass = pass && Jacobi(m_r, m_n) == -1 && Jacobi(m_s, m_n) == -1;
55 CRYPTOPP_ASSERT(pass);
62 return GetValueHelper(
this, name, valueType, pValue).Assignable()
63 CRYPTOPP_GET_FUNCTION_ENTRY(Modulus)
64 CRYPTOPP_GET_FUNCTION_ENTRY(QuadraticResidueModPrime1)
65 CRYPTOPP_GET_FUNCTION_ENTRY(QuadraticResidueModPrime2)
71 AssignFromHelper(
this, source)
72 CRYPTOPP_SET_FUNCTION_ENTRY(Modulus)
73 CRYPTOPP_SET_FUNCTION_ENTRY(QuadraticResidueModPrime1)
74 CRYPTOPP_SET_FUNCTION_ENTRY(QuadraticResidueModPrime2)
84 int modulusSize = 2048;
88 throw InvalidArgument(
"InvertibleRabinFunction: specified modulus size is too small");
91 bool rFound=
false, sFound=
false;
95 (
"EquivalentTo", 3)(
"Mod", 4);
99 while (!(rFound && sFound))
101 int jp = Jacobi(t, m_p);
102 int jq = Jacobi(t, m_q);
104 if (!rFound && jp==1 && jq==-1)
110 if (!sFound && jp==-1 && jq==1)
159 int jp = Jacobi(cp, m_p);
160 int jq = Jacobi(cq, m_q);
174 cp = ModularSquareRoot(cp, m_p);
175 cq = ModularSquareRoot(cq, m_q);
180 Integer out = CRT(cq, m_q, cp, m_p, m_u);
182 out = modn.
Divide(out, r);
184 if ((jq==-1 && out.
IsEven()) || (jq==1 && out.
IsOdd()))
193 CRYPTOPP_ASSERT(pass);
194 pass = pass && m_p >
Integer::One() && m_p%4 == 3 && m_p < m_n;
195 CRYPTOPP_ASSERT(pass);
196 pass = pass && m_q >
Integer::One() && m_q%4 == 3 && m_q < m_n;
197 CRYPTOPP_ASSERT(pass);
199 CRYPTOPP_ASSERT(pass);
202 pass = pass && m_p * m_q == m_n;
203 CRYPTOPP_ASSERT(pass);
204 pass = pass && m_u * m_q % m_p == 1;
205 CRYPTOPP_ASSERT(pass);
206 pass = pass && Jacobi(m_r, m_p) == 1;
207 CRYPTOPP_ASSERT(pass);
208 pass = pass && Jacobi(m_r, m_q) == -1;
209 CRYPTOPP_ASSERT(pass);
210 pass = pass && Jacobi(m_s, m_p) == -1;
211 CRYPTOPP_ASSERT(pass);
212 pass = pass && Jacobi(m_s, m_q) == 1;
213 CRYPTOPP_ASSERT(pass);
217 pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
218 CRYPTOPP_ASSERT(pass);
225 return GetValueHelper<RabinFunction>(
this, name, valueType, pValue).Assignable()
226 CRYPTOPP_GET_FUNCTION_ENTRY(Prime1)
227 CRYPTOPP_GET_FUNCTION_ENTRY(Prime2)
228 CRYPTOPP_GET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1)
234 AssignFromHelper<RabinFunction>(
this, source)
235 CRYPTOPP_SET_FUNCTION_ENTRY(Prime1)
236 CRYPTOPP_SET_FUNCTION_ENTRY(Prime2)
237 CRYPTOPP_SET_FUNCTION_ENTRY(MultiplicativeInverseOfPrime2ModPrime1)
Classes and functions for working with ANS.1 objects.
An object that implements NameValuePairs.
void DoQuickSanityCheck() const
Perform a quick sanity check.
Multiple precision integer with arithmetic operations.
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs)
Generate a random number.
bool IsPositive() const
Determines if the Integer is positive.
Integer Squared() const
Multiply this integer by itself.
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
static const Integer &CRYPTOPP_API One()
Integer representing 1.
bool IsOdd() const
Determines if the Integer is odd parity.
Integer InverseMod(const Integer &n) const
Calculate multiplicative inverse.
bool IsEven() const
Determines if the Integer is even parity.
An invalid argument was detected.
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
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
Get a named value.
Ring of congruence classes modulo n.
const Integer & Square(const Integer &a) const
Square an element in the ring.
const Integer & Multiply(const Integer &a, const Integer &b) const
Multiplies elements in the ring.
const Integer & Divide(const Integer &a, const Integer &b) const
Divides elements in the ring.
Interface for retrieving values given their names.
CRYPTOPP_DLL bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
Integer ApplyFunction(const Integer &x) const
Applies the trapdoor.
Interface for random number generators.
Multiple precision integer with arithmetic operations.
Class file for performing modular arithmetic.
Classes and functions for number theoretic operations.
Integer EuclideanMultiplicativeInverse(const Integer &a, const Integer &b)
Calculate multiplicative inverse.
Classes for Rabin encryption and signature schemes.
Classes for SHA-1 and SHA-2 family of message digests.