38 if (Jacobi(in, m_n)==-1)
50 pass = pass && Jacobi(m_r, m_n) == -1 && Jacobi(m_s, m_n) == -1;
56 return GetValueHelper(
this, name, valueType, pValue).Assignable()
57 CRYPTOPP_GET_FUNCTION_ENTRY(
Modulus)
65 AssignFromHelper(
this, source)
66 CRYPTOPP_SET_FUNCTION_ENTRY(
Modulus)
78 int modulusSize = 2048;
82 throw InvalidArgument(
"InvertibleRabinFunction: specified modulus size is too small");
85 bool rFound=
false, sFound=
false;
89 (
"EquivalentTo", 3)(
"Mod", 4);
90 m_p.GenerateRandom(rng, primeParam);
91 m_q.GenerateRandom(rng, primeParam);
93 while (!(rFound && sFound))
95 int jp = Jacobi(t, m_p);
96 int jq = Jacobi(t, m_q);
98 if (!rFound && jp==1 && jq==-1)
104 if (!sFound && jp==-1 && jq==1)
143 DoQuickSanityCheck();
149 Integer c = modn.Multiply(in, r2);
153 int jp = Jacobi(cp, m_p);
154 int jq = Jacobi(cq, m_q);
158 cp = cp*EuclideanMultiplicativeInverse(m_r, m_p)%m_p;
159 cq = cq*EuclideanMultiplicativeInverse(m_r, m_q)%m_q;
164 cp = cp*EuclideanMultiplicativeInverse(m_s, m_p)%m_p;
165 cq = cq*EuclideanMultiplicativeInverse(m_s, m_q)%m_q;
168 cp = ModularSquareRoot(cp, m_p);
169 cq = ModularSquareRoot(cq, m_q);
174 Integer out = CRT(cq, m_q, cp, m_p, m_u);
176 out = modn.Divide(out, r);
178 if ((jq==-1 && out.IsEven()) || (jq==1 && out.IsOdd()))
187 pass = pass && m_p >
Integer::One() && m_p%4 == 3 && m_p < m_n;
188 pass = pass && m_q >
Integer::One() && m_q%4 == 3 && m_q < m_n;
189 pass = pass && m_u.IsPositive() && m_u < m_p;
192 pass = pass && m_p * m_q == m_n;
193 pass = pass && m_u * m_q % m_p == 1;
194 pass = pass && Jacobi(m_r, m_p) == 1;
195 pass = pass && Jacobi(m_r, m_q) == -1;
196 pass = pass && Jacobi(m_s, m_p) == -1;
197 pass = pass && Jacobi(m_s, m_q) == 1;
206 return GetValueHelper<RabinFunction>(
this, name, valueType, pValue).Assignable()
207 CRYPTOPP_GET_FUNCTION_ENTRY(
Prime1)
208 CRYPTOPP_GET_FUNCTION_ENTRY(
Prime2)
215 AssignFromHelper<RabinFunction>(
this, source)
216 CRYPTOPP_SET_FUNCTION_ENTRY(
Prime1)
217 CRYPTOPP_SET_FUNCTION_ENTRY(
Prime2)
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
const char * MultiplicativeInverseOfPrime2ModPrime1()
Integer.
An invalid argument was detected.
Classes for Rabin encryption and signature schemes.
Integer ApplyFunction(const Integer &x) const
Applies the trapdoor.
const char * Prime2()
Integer.
const char * QuadraticResidueModPrime1()
Integer.
Ring of congruence classes modulo n.
Interface for random number generators.
static const Integer & One()
Integer representing 1.
bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
const char * Prime1()
Integer.
const char * QuadraticResidueModPrime2()
Integer.
bool VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level=1)
Verifies a prime number.
Multiple precision integer with arithmetic operations.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Classes and functions for working with ANS.1 objects.
Classes for SHA-1 and SHA-2 family of message digests.
Classes and functions for number theoretic operations.
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
An object that implements NameValuePairs.
const char * Modulus()
Integer.
Integer InverseMod(const Integer &n) const
calculate multiplicative inverse of *this mod n
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
Class file for performing modular arithmetic.
Crypto++ library namespace.
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.
Interface for retrieving values given their names.