12 #ifndef CRYPTOPP_IMPORTS 15 static const bool CRYPTOPP_RW_USE_OMP =
true;
17 static const bool CRYPTOPP_RW_USE_OMP =
false;
45 const word r3a = (16 + 5 - r) % 16;
46 const word r3b = (16 + 13 - r) % 16;
47 const word r4 = (8 + 5 - r/2) % 8;
101 int modulusSize = 2048;
104 if (modulusSize < 16)
105 throw InvalidArgument(
"InvertibleRWFunction: specified modulus length is too small");
119 m_n = n; m_p = p; m_q = q; m_u = u;
128 #pragma omp parallel sections if(CRYPTOPP_RW_USE_OMP) 131 m_pre_2_9p = modp.Exponentiate(2, (9 * m_p - 11)/8);
135 m_pre_q_p = modp.Exponentiate(m_q, m_p - 2);
144 m_pre_2_9p.BERDecode(seq);
145 m_pre_2_3q.BERDecode(seq);
146 m_pre_q_p.BERDecode(seq);
158 m_pre_2_9p.DEREncode(seq);
159 m_pre_2_3q.DEREncode(seq);
160 m_pre_q_p.DEREncode(seq);
173 m_precompute =
false;
208 re = modn.Multiply(re, x);
210 const Integer &
h = re, &p = m_p, &q = m_q;
219 const Integer eh = e*
h, V = modp.Exponentiate(eh, (p-3)/8);
220 if(((modp.Multiply(modp.Exponentiate(V, 4), modp.Exponentiate(eh, 2)) - eh) % p).IsZero())
226 #pragma omp parallel sections if(CRYPTOPP_RW_USE_OMP) 234 const Integer t = modp.Multiply(modp.Exponentiate(V, 3), eh);
235 X = (f.
IsUnit() ? t : modp.Multiply(m_pre_2_9p, t));
238 const Integer Y = W + q * modp.Multiply(m_pre_q_p, (X - W));
241 Integer s = modn.Multiply(modn.Square(Y), rInv);
260 pass = pass && m_p * m_q ==
m_n;
261 pass = pass && m_u * m_q % m_p == 1;
270 return GetValueHelper<RWFunction>(
this,
name, valueType, pValue).Assignable()
279 AssignFromHelper<RWFunction>(
this,
source)
285 m_precompute =
false;
Base class for all exceptions thrown by the library.
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
An invalid argument was detected.
AlgorithmParameters MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength)
virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
Save precomputation for later use.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
#define NAMESPACE_BEGIN(x)
CRYPTOPP_DLL bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
Some other error occurred not belonging to other categories.
void Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u)
Initialize a Rabin-Williams private key.
void BERDecode(BufferedTransformation &bt)
Ring of congruence classes modulo n.
Interface for random number generators.
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
void Randomize(RandomNumberGenerator &rng, size_t bitCount)
Set this Integer to random integer.
Combines two sets of NameValuePairs.
Integer MultiplicativeInverse() const
return inverse if 1 or -1, otherwise return 0
static const Integer &CRYPTOPP_API One()
Integer representing 1.
Integer ApplyFunction(const Integer &x) const
Applies the trapdoor.
bool VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level)
Verifies a prime number.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
bool IsUnit() const
is 1 or -1
const Integer & Multiply(const Integer &a, const Integer &b) const
Multiplies elements in the ring.
Classes for Rabin-Williams signature scheme.
bool IsPositive() const
Determines if the Integer is positive.
Integer Squared() const
Multiply this integer by itself.
Rabin-Williams trapdoor function using the public key.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
void Negate()
Reverse the Sign of the Integer.
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
Multiple precision integer with arithmetic operations.
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.
AssignFromHelperClass< T, BASE > AssignFromHelper(T *pObject, const NameValuePairs &source)
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation)
Retrieve previously saved precomputation.
bool IsZero() const
Determines if the Integer is 0.
Classes and functions for working with ANS.1 objects.
void PrecomputeTweakedRoots() const
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
#define CRYPTOPP_SET_FUNCTION_ENTRY(name)
Classes and functions for number theoretic operations.
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
#define pass(a, b, c, mul, X)
#define CRYPTOPP_GET_FUNCTION_ENTRY(name)
#define CRYPTOPP_UNUSED(x)
An object that implements NameValuePairs.
Integer InverseMod(const Integer &n) const
calculate multiplicative inverse of *this mod n
Multiple precision integer with arithmetic operations.
static const Integer &CRYPTOPP_API Zero()
Integer representing 0.
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
void DEREncode(BufferedTransformation &bt) const
Class file for performing modular arithmetic.
void DEREncode(BufferedTransformation &bt) const
virtual Element Exponentiate(const Element &a, const Integer &e) const
Raises a base to an exponent in the group.
Interface for retrieving values given their names.
void DoQuickSanityCheck() const
Perform a quick sanity check.
GetValueHelperClass< T, BASE > GetValueHelper(const T *pObject, const char *name, const std::type_info &valueType, void *pValue, const NameValuePairs *searchFirst=NULL)