InvertibleRSAFunction Class Reference

_ More...

Inheritance diagram for InvertibleRSAFunction:
RSAFunction TrapdoorFunctionInverse PKCS8PrivateKey TrapdoorFunction X509PublicKey RandomizedTrapdoorFunctionInverse ASN1CryptoMaterial< PrivateKey > RandomizedTrapdoorFunction ASN1CryptoMaterial< PublicKey > ASN1Object PrivateKey TrapdoorFunctionBounds ASN1Object PublicKey GeneratableCryptoMaterial CryptoMaterial CryptoMaterial NameValuePairs NameValuePairs InvertibleRSAFunction_ISO

List of all members.

Public Member Functions

void Initialize (RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &e=17)
void Initialize (const Integer &n, const Integer &e, const Integer &d, const Integer &p, const Integer &q, const Integer &dp, const Integer &dq, const Integer &u)
void Initialize (const Integer &n, const Integer &e, const Integer &d)
 factor n given private exponent
void BERDecode (BufferedTransformation &bt)
 Decode this object from a BufferedTransformation.
void DEREncode (BufferedTransformation &bt) const
 Encode this object into a BufferedTransformation.
void Load (BufferedTransformation &bt)
 Loads a key from a BufferedTransformation.
void Save (BufferedTransformation &bt) const
 Saves a key to a BufferedTransformation.
OID GetAlgorithmID () const
void BERDecodePrivateKey (BufferedTransformation &bt, bool parametersPresent, size_t size)
 decode privateKey part of privateKeyInfo, without the OCTET STRING header
void DEREncodePrivateKey (BufferedTransformation &bt) const
 encode privateKey part of privateKeyInfo, without the OCTET STRING header
Integer CalculateInverse (RandomNumberGenerator &rng, const Integer &x) const
bool Validate (RandomNumberGenerator &rng, unsigned int level) const
 Check this object for errors.
void GenerateRandom (RandomNumberGenerator &rng, const NameValuePairs &alg)
bool GetVoidValue (const char *name, const std::type_info &valueType, void *pValue) const
 Get a named value.
void AssignFrom (const NameValuePairs &source)
 Assign values to this object.
const IntegerGetPrime1 () const
const IntegerGetPrime2 () const
const IntegerGetPrivateExponent () const
const IntegerGetModPrime1PrivateExponent () const
const IntegerGetModPrime2PrivateExponent () const
const IntegerGetMultiplicativeInverseOfPrime2ModPrime1 () const
void SetPrime1 (const Integer &p)
void SetPrime2 (const Integer &q)
void SetPrivateExponent (const Integer &d)
void SetModPrime1PrivateExponent (const Integer &dp)
void SetModPrime2PrivateExponent (const Integer &dq)
void SetMultiplicativeInverseOfPrime2ModPrime1 (const Integer &u)
void Initialize (const Integer &n, const Integer &e)
void BERDecodePublicKey (BufferedTransformation &bt, bool parametersPresent, size_t size)
 decode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header
void DEREncodePublicKey (BufferedTransformation &bt) const
 encode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header
Integer ApplyFunction (const Integer &x) const
 Applies the trapdoor.
Integer PreimageBound () const
 Returns the maximum size of a message before the trapdoor function is applied.
Integer ImageBound () const
 Returns the maximum size of a message after the trapdoor function is applied.
const IntegerGetModulus () const
const IntegerGetPublicExponent () const
void SetModulus (const Integer &n)
void SetPublicExponent (const Integer &e)
Integer ApplyRandomizedFunction (RandomNumberGenerator &rng, const Integer &x) const
 Applies the trapdoor function.
bool IsRandomized () const
 Determines if the encryption algorithm is randomized.
virtual Integer MaxPreimage () const
 Returns the maximum size of a message before the trapdoor function is applied bound to a public key.
virtual Integer MaxImage () const
 Returns the maximum size of a message after the trapdoor function is applied bound to a public key.
virtual bool BERDecodeAlgorithmParameters (BufferedTransformation &bt)
virtual bool DEREncodeAlgorithmParameters (BufferedTransformation &bt) const
virtual void BEREncode (BufferedTransformation &bt) const
 Encode this object into a BufferedTransformation.
virtual void ThrowIfInvalid (RandomNumberGenerator &rng, unsigned int level) const
 Check this object for errors.
virtual bool SupportsPrecomputation () const
 Determines whether the object supports precomputation.
virtual void Precompute (unsigned int precomputationStorage)
 Perform precomputation.
virtual void LoadPrecomputation (BufferedTransformation &storedPrecomputation)
 retrieve previously saved precomputation
virtual void SavePrecomputation (BufferedTransformation &storedPrecomputation) const
 save precomputation for later use
void DoQuickSanityCheck () const
template<class T >
bool GetThisObject (T &object) const
 Get a copy of this object or subobject.
template<class T >
bool GetThisPointer (T *&ptr) const
 Get a pointer to this object.
template<class T >
bool GetValue (const char *name, T &value) const
 Get a named value.
template<class T >
GetValueWithDefault (const char *name, T defaultValue) const
 Get a named value.
std::string GetValueNames () const
 Get a list of value names that can be retrieved.
bool GetIntValue (const char *name, int &value) const
 Get a named value with type int.
int GetIntValueWithDefault (const char *name, int defaultValue) const
 Get a named value with type int, with default.
template<class T >
void GetRequiredParameter (const char *className, const char *name, T &value) const
 Retrieves a required name/value pair.
void GetRequiredIntParameter (const char *className, const char *name, int &value) const
 Retrieves a required name/value pair.
Integer CalculateRandomizedInverse (RandomNumberGenerator &rng, const Integer &x) const
 Applies the inverse of the trapdoor function.
bool IsRandomized () const
 Determines if the decryption algorithm is randomized.
virtual bool BERDecodeAlgorithmParameters (BufferedTransformation &bt)
virtual bool DEREncodeAlgorithmParameters (BufferedTransformation &bt) const
virtual void BERDecodeOptionalAttributes (BufferedTransformation &bt)
 decode optional attributes including context-specific tag
virtual void DEREncodeOptionalAttributes (BufferedTransformation &bt) const
 encode optional attributes including context-specific tag
void GenerateRandomWithKeySize (RandomNumberGenerator &rng, unsigned int keySize)
 Generate a random key or crypto parameters.

Static Public Member Functions

static void ThrowIfTypeMismatch (const char *name, const std::type_info &stored, const std::type_info &retrieving)
 Ensures an expected name and type is present.

Protected Attributes

ByteQueue m_optionalAttributes

Detailed Description

_

Definition at line 57 of file rsa.h.


Member Function Documentation

void InvertibleRSAFunction::BERDecode ( BufferedTransformation bt  )  [inline, virtual]

Decode this object from a BufferedTransformation.

Parameters:
bt BufferedTransformation object

Uses Basic Encoding Rules (BER)

Reimplemented from PKCS8PrivateKey.

Definition at line 69 of file rsa.h.

References PKCS8PrivateKey::BERDecode().

void InvertibleRSAFunction::DEREncode ( BufferedTransformation bt  )  const [inline, virtual]

Encode this object into a BufferedTransformation.

Parameters:
bt BufferedTransformation object

Uses Distinguished Encoding Rules (DER)

Reimplemented from PKCS8PrivateKey.

Definition at line 71 of file rsa.h.

References PKCS8PrivateKey::DEREncode().

void InvertibleRSAFunction::Load ( BufferedTransformation bt  )  [inline, virtual]

Loads a key from a BufferedTransformation.

Parameters:
bt the source BufferedTransformation
Exceptions:
KeyingErr 

Load attempts to read material from a BufferedTransformation. If the material is a key that was generated outside the library, then the following usually applies:

  • the key should be ASN.1 BER encoded
  • the key should be a "key info"

"key info" means the key should have an object identifier with an algorthm id, like a subjectPublicKeyInfo.

To read a "raw" key without the "key info", then call the key's BERDecode method.

Note:
Load generally does not check that the key is valid. Call Validate(), if needed.

Reimplemented from ASN1CryptoMaterial< PrivateKey >.

Definition at line 73 of file rsa.h.

References PKCS8PrivateKey::BERDecode().

void InvertibleRSAFunction::Save ( BufferedTransformation bt  )  const [inline, virtual]

Saves a key to a BufferedTransformation.

Parameters:
bt the destination BufferedTransformation
Exceptions:
NotImplemented 

Save writes the material to a BufferedTransformation.

If the material is a key, then the key is written with ASN.1 DER encoding. The key includes an object identifier with an algorthm id, like a subjectPublicKeyInfo.

A "raw" key without the "key info" can be saved using a key's DEREncode method.

If a derived class does not override Save, then the base class throws NotImplemented.

Reimplemented from ASN1CryptoMaterial< PrivateKey >.

Definition at line 75 of file rsa.h.

References PKCS8PrivateKey::DEREncode().

bool InvertibleRSAFunction::Validate ( RandomNumberGenerator rng,
unsigned int  level 
) const [virtual]

Check this object for errors.

Parameters:
rng a RandomNumberGenerator for objects which use randomized testing
level the level of thoroughness
Returns:
true if the tests succeed, false otherwise

There are four levels of thoroughness:

  • 0 - using this object won't cause a crash or exception
  • 1 - this object will probably function, and encrypt, sign, other operations correctly
  • 2 - ensure this object will function correctly, and perform reasonable security checks
  • 3 - perform reasonable security checks, and do checks that may take a long time

Level 0 does not require a RandomNumberGenerator. A NullRNG() can be used for level 0.

Level 1 may not check for weak keys and such.

Levels 2 and 3 are recommended.

Reimplemented from RSAFunction.

Definition at line 247 of file rsa.cpp.

References Integer::One().

void InvertibleRSAFunction::GenerateRandom ( RandomNumberGenerator rng,
const NameValuePairs alg 
) [virtual]

parameters: (ModulusSize, PublicExponent (default 17))

Reimplemented from GeneratableCryptoMaterial.

Definition at line 106 of file rsa.cpp.

References NameValuePairs::GetIntValue(), NameValuePairs::GetValueWithDefault(), Integer::InverseMod(), KeySize(), ModulusSize(), PointerToPrimeSelector(), and PublicExponent().

bool InvertibleRSAFunction::GetVoidValue ( const char *  name,
const std::type_info &  valueType,
void *  pValue 
) const [virtual]

Get a named value.

Parameters:
name the name of the object or value to retrieve
valueType reference to a variable that receives the value
pValue void pointer to a variable that receives the value
Returns:
true if the value was retrieved, false otherwise

GetVoidValue() retrives the value of name if it exists.

Note:
GetVoidValue() is an internal function and should be implemented by derived classes. Users should use one of the other functions instead.
See also:
GetValue(), GetValueWithDefault(), GetIntValue(), GetIntValueWithDefault(), GetRequiredParameter() and GetRequiredIntParameter()

Reimplemented from RSAFunction.

Definition at line 268 of file rsa.cpp.

References ModPrime1PrivateExponent(), ModPrime2PrivateExponent(), MultiplicativeInverseOfPrime2ModPrime1(), Prime1(), Prime2(), and PrivateExponent().

void InvertibleRSAFunction::AssignFrom ( const NameValuePairs source  )  [virtual]

Assign values to this object.

This function can be used to create a public key from a private key.

Reimplemented from RSAFunction.

Definition at line 280 of file rsa.cpp.

References ModPrime1PrivateExponent(), ModPrime2PrivateExponent(), MultiplicativeInverseOfPrime2ModPrime1(), Prime1(), Prime2(), and PrivateExponent().

Integer RSAFunction::ApplyFunction ( const Integer x  )  const [virtual, inherited]

Applies the trapdoor.

Parameters:
x the message on which the encryption function is applied
Returns:
the message x encrypted under the public key

ApplyFunction is a generalization of encryption under a public key cryptosystem. Derived classes must implement it.

Implements TrapdoorFunction.

Reimplemented in RSAFunction_ISO.

Definition at line 64 of file rsa.cpp.

Integer RSAFunction::PreimageBound (  )  const [inline, virtual, inherited]

Returns the maximum size of a message before the trapdoor function is applied.

Returns:
the maximum size of a message before the trapdoor function is applied

Derived classes must implement PreimageBound().

Implements TrapdoorFunctionBounds.

Reimplemented in RSAFunction_ISO, and InvertibleRSAFunction_ISO.

Definition at line 42 of file rsa.h.

Integer RSAFunction::ImageBound (  )  const [inline, virtual, inherited]

Returns the maximum size of a message after the trapdoor function is applied.

Returns:
the maximum size of a message after the trapdoor function is applied

Derived classes must implement ImageBound().

Implements TrapdoorFunctionBounds.

Definition at line 43 of file rsa.h.

Integer TrapdoorFunction::ApplyRandomizedFunction ( RandomNumberGenerator rng,
const Integer x 
) const [inline, virtual, inherited]

Applies the trapdoor function.

Parameters:
rng a RandomNumberGenerator derived class
x the message on which the encryption function is applied

ApplyRandomizedFunction is a generalization of encryption under a public key cryptosystem. The RandomNumberGenerator may (or may not) be required.

Internally, ApplyRandomizedFunction() calls ApplyFunction() without the RandomNumberGenerator.

Implements RandomizedTrapdoorFunction.

Definition at line 141 of file pubkey.h.

bool TrapdoorFunction::IsRandomized (  )  const [inline, virtual, inherited]

Determines if the encryption algorithm is randomized.

Returns:
true if the encryption algorithm is randomized, false otherwise

If IsRandomized() returns false, then NullRNG() can be used.

Reimplemented from RandomizedTrapdoorFunction.

Definition at line 143 of file pubkey.h.

virtual Integer TrapdoorFunctionBounds::MaxPreimage (  )  const [inline, virtual, inherited]

Returns the maximum size of a message before the trapdoor function is applied bound to a public key.

Returns:
the maximum size of a message before the trapdoor function is applied bound to a public key

The default implementation returns PreimageBound() - 1.

Definition at line 85 of file pubkey.h.

virtual Integer TrapdoorFunctionBounds::MaxImage (  )  const [inline, virtual, inherited]

Returns the maximum size of a message after the trapdoor function is applied bound to a public key.

Returns:
the the maximum size of a message after the trapdoor function is applied bound to a public key

The default implementation returns ImageBound() - 1.

Definition at line 89 of file pubkey.h.

Referenced by ESIGNFunction::ApplyFunction().

virtual void ASN1Object::BEREncode ( BufferedTransformation bt  )  const [inline, virtual, inherited]

Encode this object into a BufferedTransformation.

Parameters:
bt BufferedTransformation object

Uses Basic Encoding Rules (BER).

This may be useful if DEREncode() would be too inefficient.

Definition at line 2649 of file cryptlib.h.

virtual void CryptoMaterial::ThrowIfInvalid ( RandomNumberGenerator rng,
unsigned int  level 
) const [inline, virtual, inherited]

Check this object for errors.

Parameters:
rng a RandomNumberGenerator for objects which use randomized testing
level the level of thoroughness
Exceptions:
InvalidMaterial 

Internally, ThrowIfInvalid() calls Validate() and throws InvalidMaterial if validation fails.

Definition at line 1939 of file cryptlib.h.

virtual bool CryptoMaterial::SupportsPrecomputation (  )  const [inline, virtual, inherited]

Determines whether the object supports precomputation.

Returns:
true if the object supports precomputation, false otherwise

Reimplemented in DL_GroupParameters< T >, DL_PrivateKeyImpl< GP >, DL_PublicKeyImpl< GP >, DL_GroupParameters< Integer >, DL_GroupParameters< typenameEcPrecomputation< EC >::Element >, DL_PrivateKeyImpl< DL_GroupParameters_EC< EC > >, and DL_PublicKeyImpl< DL_GroupParameters_EC< EC > >.

Definition at line 1973 of file cryptlib.h.

virtual void CryptoMaterial::Precompute ( unsigned int  precomputationStorage  )  [inline, virtual, inherited]

Perform precomputation.

Parameters:
precomputationStorage the suggested number of objects for the precompute table
Exceptions:
NotImplemented 

The exact semantics of Precompute() varies, but it typically means calculate a table of n objects that can be used later to speed up computation.

If a derived class does not override Precompute, then the base class throws NotImplemented.

Reimplemented in DL_GroupParameters< T >, DL_PrivateKeyImpl< GP >, DL_PublicKeyImpl< GP >, DL_GroupParameters< Integer >, DL_GroupParameters< typenameEcPrecomputation< EC >::Element >, DL_PrivateKeyImpl< DL_GroupParameters_EC< EC > >, and DL_PublicKeyImpl< DL_GroupParameters_EC< EC > >.

Definition at line 1982 of file cryptlib.h.

template<class T >
bool NameValuePairs::GetThisObject ( T &  object  )  const [inline, inherited]

Get a copy of this object or subobject.

Template Parameters:
T class or type
Parameters:
object reference to a variable that receives the value

Definition at line 297 of file cryptlib.h.

Referenced by DL_PrivateKeyImpl< DL_GroupParameters_EC< EC > >::GenerateRandom().

template<class T >
bool NameValuePairs::GetThisPointer ( T *&  ptr  )  const [inline, inherited]

Get a pointer to this object.

Template Parameters:
T class or type
Parameters:
ptr reference to a pointer to a variable that receives the value

Definition at line 306 of file cryptlib.h.

template<class T >
bool NameValuePairs::GetValue ( const char *  name,
T &  value 
) const [inline, inherited]

Get a named value.

Template Parameters:
T class or type
Parameters:
name the name of the object or value to retrieve
value reference to a variable that receives the value
Returns:
true if the value was retrieved, false otherwise
See also:
GetValue(), GetValueWithDefault(), GetIntValue(), GetIntValueWithDefault(), GetRequiredParameter() and GetRequiredIntParameter()

Definition at line 319 of file cryptlib.h.

Referenced by DL_GroupParameters_EC< EC >::AssignFrom(), DL_GroupParameters_IntegerBased::GenerateRandom(), DL_GroupParameters_DSA::GenerateRandom(), InvertibleESIGNFunction::GenerateRandom(), Inflator::IsolatedInitialize(), StringSinkTemplate< T >::IsolatedInitialize(), ArraySink::IsolatedInitialize(), FileSink::IsolatedInitialize(), and Grouper::IsolatedInitialize().

template<class T >
T NameValuePairs::GetValueWithDefault ( const char *  name,
defaultValue 
) const [inline, inherited]
std::string NameValuePairs::GetValueNames (  )  const [inline, inherited]

Get a list of value names that can be retrieved.

Returns:
a list of names available to retrieve

the items in the list are delimited with a colon.

Definition at line 344 of file cryptlib.h.

bool NameValuePairs::GetIntValue ( const char *  name,
int &  value 
) const [inline, inherited]

Get a named value with type int.

Parameters:
name the name of the value to retrieve
value the value retrieved upon success
Returns:
true if an int value was retrieved, false otherwise

GetIntValue() is used to ensure we don't accidentally try to get an unsigned int or some other type when we mean int (which is the most common case)

See also:
GetValue(), GetValueWithDefault(), GetIntValue(), GetIntValueWithDefault(), GetRequiredParameter() and GetRequiredIntParameter()

Definition at line 355 of file cryptlib.h.

Referenced by InvertibleRWFunction::GenerateRandom(), GenerateRandom(), InvertibleRabinFunction::GenerateRandom(), InvertibleLUCFunction::GenerateRandom(), DL_GroupParameters_IntegerBased::GenerateRandom(), DL_GroupParameters_DSA::GenerateRandom(), and InvertibleESIGNFunction::GenerateRandom().

int NameValuePairs::GetIntValueWithDefault ( const char *  name,
int  defaultValue 
) const [inline, inherited]

Get a named value with type int, with default.

Parameters:
name the name of the value to retrieve
defaultValue the default value if the name does not exist
Returns:
the value retrieved on success or the default value
See also:
GetValue(), GetValueWithDefault(), GetIntValue(), GetIntValueWithDefault(), GetRequiredParameter() and GetRequiredIntParameter()

Definition at line 364 of file cryptlib.h.

Referenced by DL_GroupParameters_IntegerBased::GenerateRandom(), Redirector::Initialize(), Deflator::IsolatedInitialize(), ByteQueue::IsolatedInitialize(), HashFilter::IsolatedInitialize(), Grouper::IsolatedInitialize(), Base64URLEncoder::IsolatedInitialize(), VMAC_Base::UncheckedSetKey(), SAFER::Base::UncheckedSetKey(), and Weak1::ARC4_Base::UncheckedSetKey().

static void NameValuePairs::ThrowIfTypeMismatch ( const char *  name,
const std::type_info &  stored,
const std::type_info &  retrieving 
) [inline, static, inherited]

Ensures an expected name and type is present.

Parameters:
name the name of the value
stored the type that was stored for the name
retrieving the type that is being retrieved for the name
Exceptions:
ValueTypeMismatch 

ThrowIfTypeMismatch() effectively performs a type safety check. stored and retrieving are C++ mangled names for the type.

See also:
GetValue(), GetValueWithDefault(), GetIntValue(), GetIntValueWithDefault(), GetRequiredParameter() and GetRequiredIntParameter()

Definition at line 376 of file cryptlib.h.

Referenced by DL_GroupParameters_EC< EC >::GetVoidValue().

template<class T >
void NameValuePairs::GetRequiredParameter ( const char *  className,
const char *  name,
T &  value 
) const [inline, inherited]

Retrieves a required name/value pair.

Template Parameters:
T class or type
Parameters:
className the name of the class
name the name of the value
value reference to a variable to receive the value
Exceptions:
InvalidArgument 

GetRequiredParameter() throws InvalidArgument if the name is not present or not of the expected type T.

See also:
GetValue(), GetValueWithDefault(), GetIntValue(), GetIntValueWithDefault(), GetRequiredParameter() and GetRequiredIntParameter()

Definition at line 390 of file cryptlib.h.

Referenced by DL_GroupParameters_EC< EC >::AssignFrom(), RandomNumberSink::IsolatedInitialize(), Grouper::IsolatedInitialize(), and BaseN_Decoder::IsolatedInitialize().

void NameValuePairs::GetRequiredIntParameter ( const char *  className,
const char *  name,
int &  value 
) const [inline, inherited]

Retrieves a required name/value pair.

Parameters:
className the name of the class
name the name of the value
value reference to a variable to receive the value
Exceptions:
InvalidArgument 

GetRequiredParameter() throws InvalidArgument if the name is not present or not of the expected type T.

See also:
GetValue(), GetValueWithDefault(), GetIntValue(), GetIntValueWithDefault(), GetRequiredParameter() and GetRequiredIntParameter()

Definition at line 405 of file cryptlib.h.

Referenced by BaseN_Decoder::IsolatedInitialize().

Integer TrapdoorFunctionInverse::CalculateRandomizedInverse ( RandomNumberGenerator rng,
const Integer x 
) const [inline, virtual, inherited]

Applies the inverse of the trapdoor function.

Parameters:
rng a RandomNumberGenerator derived class
x the message on which the decryption function is applied
Returns:
the message x decrypted under the private key

CalculateRandomizedInverse is a generalization of decryption using the private key

Internally, CalculateRandomizedInverse() calls CalculateInverse() without the RandomNumberGenerator.

Implements RandomizedTrapdoorFunctionInverse.

Definition at line 196 of file pubkey.h.

bool TrapdoorFunctionInverse::IsRandomized (  )  const [inline, virtual, inherited]

Determines if the decryption algorithm is randomized.

Returns:
true if the decryption algorithm is randomized, false otherwise

If IsRandomized() returns false, then NullRNG() can be used.

Reimplemented from RandomizedTrapdoorFunctionInverse.

Definition at line 202 of file pubkey.h.

void PKCS8PrivateKey::BERDecodeOptionalAttributes ( BufferedTransformation bt  )  [virtual, inherited]

decode optional attributes including context-specific tag

/note default implementation stores attributes to be output in DEREncodeOptionalAttributes

Definition at line 594 of file asn.cpp.

Referenced by PKCS8PrivateKey::BERDecode().

void GeneratableCryptoMaterial::GenerateRandomWithKeySize ( RandomNumberGenerator rng,
unsigned int  keySize 
) [inherited]

Generate a random key or crypto parameters.

Parameters:
rng a RandomNumberGenerator to produce keying material
keySize the size of the key, in bits
Exceptions:
KeyingErr if a key can't be generated or algorithm parameters are invalid

GenerateRandomWithKeySize calls GenerateRandom with a NameValuePairs object with only "KeySize"

Definition at line 771 of file cryptlib.cpp.

References GeneratableCryptoMaterial::GenerateRandom(), and MakeParameters().


The documentation for this class was generated from the following files:

Generated on 24 Mar 2016 for Crypto++ by  doxygen 1.6.1