Crypto++
8.3
Free C++ class library of cryptographic schemes
|
14 #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) && !defined(CRYPTOPP_IS_DLL)
18 void RSA_TestInstantiations()
45 #ifndef CRYPTOPP_IMPORTS
51 return ASN1::rsaEncryption();
73 return a_exp_b_mod_c(x, m_e, m_n);
78 CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(level);
90 return GetValueHelper(
this, name, valueType, pValue).Assignable()
91 CRYPTOPP_GET_FUNCTION_ENTRY(
Modulus)
98 AssignFromHelper(
this, source)
99 CRYPTOPP_SET_FUNCTION_ENTRY(
Modulus)
116 int modulusSize = 2048;
120 if (modulusSize < 16)
121 throw InvalidArgument(
"InvertibleRSAFunction: specified modulus size is too small");
126 if (m_e < 3 || m_e.IsEven())
127 throw InvalidArgument(
"InvertibleRSAFunction: invalid public exponent");
138 m_dp = m_d % (m_p-1);
139 m_dq = m_d % (m_q-1);
147 SignaturePairwiseConsistencyTest_FIPS_140_Only(signer, verifier);
151 EncryptionPairwiseConsistencyTest_FIPS_140_Only(encryptor, decryptor);
162 if (n.
IsEven() || e.IsEven() | d.IsEven())
163 throw InvalidArgument(
"InvertibleRSAFunction: input is not a valid RSA private key");
192 m_dp = m_d % (m_p-1);
193 m_dq = m_d % (m_q-1);
198 throw InvalidArgument(
"InvertibleRSAFunction: input is not a valid RSA private key");
208 BERDecodeUnsigned<word32>(privateKey, version,
INTEGER, 0, 0);
209 m_n.BERDecode(privateKey);
210 m_e.BERDecode(privateKey);
223 DEREncodeUnsigned<word32>(privateKey, 0);
224 m_n.DEREncode(privateKey);
225 m_e.DEREncode(privateKey);
273 pass = pass && m_p * m_q == m_n;
275 pass = pass && m_e*m_d %
LCM(m_p-1, m_q-1) == 1;
277 pass = pass && m_dp == m_d%(m_p-1) && m_dq == m_d%(m_q-1);
279 pass = pass && m_u * m_q % m_p == 1;
292 return GetValueHelper<RSAFunction>(
this, name, valueType, pValue).Assignable()
293 CRYPTOPP_GET_FUNCTION_ENTRY(
Prime1)
294 CRYPTOPP_GET_FUNCTION_ENTRY(
Prime2)
304 AssignFromHelper<RSAFunction>(
this, source)
305 CRYPTOPP_SET_FUNCTION_ENTRY(
Prime1)
306 CRYPTOPP_SET_FUNCTION_ENTRY(
Prime2)
319 return t % 16 == 12 ? t : m_n - t;
An object that implements NameValuePairs.
void BERDecodePrivateKey(BufferedTransformation &bt, bool parametersPresent, size_t size)
Decode privateKey part of privateKeyInfo.
void BERDecodePublicKey(BufferedTransformation &bt, bool parametersPresent, size_t size)
Decode subjectPublicKey part of subjectPublicKeyInfo.
Integer InverseMod(const Integer &n) const
Calculate multiplicative inverse.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
const Integer & MultiplicativeInverse(const Integer &a) const
Calculate the multiplicative inverse of an element in the ring.
Classes and functions for number theoretic operations.
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
const char * Modulus()
Integer.
const char * PointerToPrimeSelector()
const PrimeSelector *
static const Integer &CRYPTOPP_API One()
Integer representing 1.
Ring of congruence classes modulo n.
void MessageEnd()
Signals the end of messages to the object.
const char * Prime2()
Integer.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
bool IsEven() const
Determines if the Integer is even parity.
Classes for probablistic signature schemes.
CRYPTOPP_DLL bool CRYPTOPP_API VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level=1)
Verifies a number is probably prime.
bool IsZero() const
Determines if the Integer is 0.
Class file for performing modular arithmetic.
const Integer & Multiply(const Integer &a, const Integer &b) const
Multiplies elements in the ring.
const char * ModulusSize()
int, in bits
const char * PrivateExponent()
Integer.
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
Integer ApplyFunction(const Integer &x) const
Applies the trapdoor.
void DoQuickSanityCheck() const
Perform a quick sanity check.
const char * ModPrime1PrivateExponent()
Integer.
Classes for PKCS padding schemes.
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
const Integer & Square(const Integer &a) const
Square an element in the ring.
Interface for random number generators.
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
Classes and functions for the FIPS 140-2 validated library.
void DEREncodePublicKey(BufferedTransformation &bt) const
Encode subjectPublicKey part of subjectPublicKeyInfo.
Base class for all exceptions thrown by the library.
Classes for SHA-1 and SHA-2 family of message digests.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
Classes for the RSA cryptosystem.
Integer CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const
Calculates the inverse of an element.
bool IsOdd() const
Determines if the Integer is odd parity.
void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &e=17)
Create a RSA private key.
Application callback to signal suitability of a cabdidate prime.
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.
Integer GCD(const Integer &a, const Integer &b)
Calculate the greatest common divisor.
ASN.1 object identifiers for algorthms and schemes.
CRYPTOPP_DLL bool CRYPTOPP_API FIPS_140_2_ComplianceEnabled()
Determines whether the library provides FIPS validated cryptography.
void MessageEnd()
Signals the end of messages to the object.
CRYPTOPP_DLL bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs)
Generate a random number.
RSA trapdoor function using the public key.
void Randomize(RandomNumberGenerator &rng, size_t bitCount)
Set this Integer to random integer.
void DEREncodePrivateKey(BufferedTransformation &bt) const
Encode privateKey part of privateKeyInfo.
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
bool IsPositive() const
Determines if the Integer is positive.
const char * Prime1()
Integer.
An invalid argument was detected.
Integer LCM(const Integer &a, const Integer &b)
Calculate the least common multiple.
Crypto++ library namespace.
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
CRYPTOPP_DLL RandomNumberGenerator &CRYPTOPP_API NullRNG()
Random Number Generator that does not produce random numbers.
const char * MultiplicativeInverseOfPrime2ModPrime1()
Integer.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
Generate a random key or crypto parameters.
CRYPTOPP_DLL Integer CRYPTOPP_API ModularRoot(const Integer &a, const Integer &dp, const Integer &dq, const Integer &p, const Integer &q, const Integer &u)
Extract a modular root.
Classes for SHA3 message digests.
bool RelativelyPrime(const Integer &a, const Integer &b)
Determine relative primality.
Integer ApplyFunction(const Integer &x) const
Applies the trapdoor.
virtual Element Exponentiate(const Element &a, const Integer &e) const
Raises a base to an exponent in the group.
const char * ModPrime2PrivateExponent()
Integer.
Template implementing constructors for public key algorithm classes.
const char * KeySize()
int, in bits
@ OTHER_ERROR
Some other error occurred not belonging to other categories.
const char * PublicExponent()
Integer.
RSA encryption algorithm.
Interface for retrieving values given their names.
Classes for working with NameValuePairs.
Multiple precision integer with arithmetic operations.