13 #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) && !defined(CRYPTOPP_IS_DLL) 16 void RSA_TestInstantiations()
39 #ifndef CRYPTOPP_IMPORTS 45 return ASN1::rsaEncryption();
108 int modulusSize = 2048;
112 if (modulusSize < 16)
113 throw InvalidArgument(
"InvertibleRSAFunction: specified modulus size is too small");
119 throw InvalidArgument(
"InvertibleRSAFunction: invalid public exponent");
124 m_p.GenerateRandom(rng, primeParam);
125 m_q.GenerateRandom(rng, primeParam);
130 m_dp = m_d % (m_p-1);
131 m_dq = m_d % (m_q-1);
149 GenerateRandom(rng,
MakeParameters(Name::ModulusSize(), (
int)keybits)(Name::PublicExponent(), e+e.
IsEven()));
155 throw InvalidArgument(
"InvertibleRSAFunction: input is not a valid RSA private key");
184 m_dp = m_d % (m_p-1);
185 m_dq = m_d % (m_q-1);
190 throw InvalidArgument(
"InvertibleRSAFunction: input is not a valid RSA private key");
203 m_d.BERDecode(privateKey);
204 m_p.BERDecode(privateKey);
205 m_q.BERDecode(privateKey);
206 m_dp.BERDecode(privateKey);
207 m_dq.BERDecode(privateKey);
208 m_u.BERDecode(privateKey);
209 privateKey.MessageEnd();
215 DEREncodeUnsigned<word32>(privateKey, 0);
218 m_d.DEREncode(privateKey);
219 m_p.DEREncode(privateKey);
220 m_q.DEREncode(privateKey);
221 m_dp.DEREncode(privateKey);
222 m_dq.DEREncode(privateKey);
223 m_u.DEREncode(privateKey);
224 privateKey.MessageEnd();
255 pass = pass && m_u.IsPositive() && m_u < m_p;
258 pass = pass && m_p * m_q ==
m_n;
259 pass = pass &&
m_e*m_d %
LCM(m_p-1, m_q-1) == 1;
260 pass = pass && m_dp == m_d%(m_p-1) && m_dq == m_d%(m_q-1);
261 pass = pass && m_u * m_q % m_p == 1;
270 return GetValueHelper<RSAFunction>(
this,
name, valueType, pValue).Assignable()
282 AssignFromHelper<RSAFunction>(
this,
source)
297 return t % 16 == 12 ? t :
m_n - t;
Base class for all exceptions thrown by the library.
Integer ModularRoot(const Integer &a, const Integer &dp, const Integer &dq, const Integer &p, const Integer &q, const Integer &u)
An invalid argument was detected.
Classes for working with NameValuePairs.
AlgorithmParameters MakeParametersForTwoPrimesOfEqualSize(unsigned int productBitLength)
void SignaturePairwiseConsistencyTest_FIPS_140_Only(const PK_Signer &signer, const PK_Verifier &verifier)
bool IsOdd() const
Determines if the Integer is odd parity.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
void DEREncodePublicKey(BufferedTransformation &bt) const
encode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header ...
#define NAMESPACE_BEGIN(x)
bool FIPS_140_2_ComplianceEnabled()
Determines whether the library provides FIPS validated cryptography.
void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size)
decode privateKey part of privateKeyInfo, without the OCTET STRING header
CRYPTOPP_DLL bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
bool IsEven() const
Determines if the Integer is even parity.
const Integer & MultiplicativeInverse(const Integer &a) const
Calculate the multiplicative inverse of an element in the ring.
Some other error occurred not belonging to other categories.
ASN.1 object identifiers for algorthms and schemes.
const Integer & Square(const Integer &a) const
Square an element in the ring.
Ring of congruence classes modulo n.
Interface for random number generators.
void Randomize(RandomNumberGenerator &rng, size_t bitCount)
Set this Integer to random integer.
static const Integer &CRYPTOPP_API One()
Integer representing 1.
bool IsAcceptable(const Integer &candidate) const
bool VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level)
Verifies a prime number.
void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size)
decode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header ...
Integer GCD(const Integer &a, const Integer &b)
const Integer & Multiply(const Integer &a, const Integer &b) const
Multiplies elements in the ring.
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &e=17)
Create a RSA private key.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
Integer ApplyFunction(const Integer &x) const
Applies the trapdoor.
void EncryptionPairwiseConsistencyTest_FIPS_140_Only(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor)
Application callback to signal suitability of a cabdidate prime.
Multiple precision integer with arithmetic operations.
Integer LCM(const Integer &a, const Integer &b)
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
void DEREncodePrivateKey(BufferedTransformation &bt) const
encode privateKey part of privateKeyInfo, without the OCTET STRING header
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
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)
bool IsZero() const
Determines if the Integer is 0.
Classes and functions for working with ANS.1 objects.
Classes for SHA-1 and SHA-2 family of message digests.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
#define CRYPTOPP_SET_FUNCTION_ENTRY(name)
Classes and functions for number theoretic operations.
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
Classes for the RSA cryptosystem.
#define pass(a, b, c, mul, X)
Classes and functions for the FIPS 140-2 validated library.
#define CRYPTOPP_GET_FUNCTION_ENTRY(name)
#define CRYPTOPP_UNUSED(x)
RandomNumberGenerator & NullRNG()
Random Number Generator that does not produce random numbers.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
bool RelativelyPrime(const Integer &a, const Integer &b)
An object that implements NameValuePairs.
Integer InverseMod(const Integer &n) const
calculate multiplicative inverse of *this mod n
RSA encryption algorithm.
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
Class file for performing modular arithmetic.
Integer ApplyFunction(const Integer &x) const
Applies the trapdoor.
RSAPrimeSelector(const Integer &e)
Integer a_exp_b_mod_c(const Integer &x, const Integer &e, const Integer &m)
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
const PrimeSelector * GetSelectorPointer() const
Classes for probablistic signature schemes.
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
virtual Element Exponentiate(const Element &a, const Integer &e) const
Raises a base to an exponent in the group.
RSA trapdoor function using the public key.
Interface for retrieving values given their names.
void DoQuickSanityCheck() const
Perform a quick sanity check.
Template implementing constructors for public key algorithm classes.
GetValueHelperClass< T, BASE > GetValueHelper(const T *pObject, const char *name, const std::type_info &valueType, void *pValue, const NameValuePairs *searchFirst=NULL)