Crypto++  5.6.3
Free C++ class library of cryptographic schemes
Public Member Functions | Static Public Member Functions | List of all members
RabinFunction Class Reference

_ More...

+ Inheritance diagram for RabinFunction:

Public Member Functions

void Initialize (const Integer &n, const Integer &r, const Integer &s)
 
void BERDecode (BufferedTransformation &bt)
 
void DEREncode (BufferedTransformation &bt) const
 
Integer ApplyFunction (const Integer &x) const
 Applies the trapdoor. More...
 
Integer PreimageBound () const
 Returns the maximum size of a message before the trapdoor function is applied. More...
 
Integer ImageBound () const
 Returns the maximum size of a message after the trapdoor function is applied. More...
 
bool Validate (RandomNumberGenerator &rng, unsigned int level) const
 Check this object for errors. More...
 
bool GetVoidValue (const char *name, const std::type_info &valueType, void *pValue) const
 Get a named value. More...
 
void AssignFrom (const NameValuePairs &source)
 Assign values to this object. More...
 
const IntegerGetModulus () const
 
const IntegerGetQuadraticResidueModPrime1 () const
 
const IntegerGetQuadraticResidueModPrime2 () const
 
void SetModulus (const Integer &n)
 
void SetQuadraticResidueModPrime1 (const Integer &r)
 
void SetQuadraticResidueModPrime2 (const Integer &s)
 
Integer ApplyRandomizedFunction (RandomNumberGenerator &rng, const Integer &x) const
 Applies the trapdoor function. More...
 
bool IsRandomized () const
 Determines if the encryption algorithm is randomized. More...
 
virtual Integer MaxPreimage () const
 Returns the maximum size of a message before the trapdoor function is applied bound to a public key. More...
 
virtual Integer MaxImage () const
 Returns the maximum size of a message after the trapdoor function is applied bound to a public key. More...
 
virtual void ThrowIfInvalid (RandomNumberGenerator &rng, unsigned int level) const
 Check this object for errors. More...
 
virtual void Save (BufferedTransformation &bt) const
 Saves a key to a BufferedTransformation. More...
 
virtual void Load (BufferedTransformation &bt)
 Loads a key from a BufferedTransformation. More...
 
virtual bool SupportsPrecomputation () const
 Determines whether the object supports precomputation. More...
 
virtual void Precompute (unsigned int precomputationStorage)
 Perform precomputation. More...
 
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. More...
 
template<class T >
bool GetThisPointer (T *&ptr) const
 Get a pointer to this object. More...
 
template<class T >
bool GetValue (const char *name, T &value) const
 Get a named value. More...
 
template<class T >
GetValueWithDefault (const char *name, T defaultValue) const
 Get a named value. More...
 
std::string GetValueNames () const
 Get a list of value names that can be retrieved. More...
 
bool GetIntValue (const char *name, int &value) const
 Get a named value with type int. More...
 
int GetIntValueWithDefault (const char *name, int defaultValue) const
 Get a named value with type int, with default. More...
 
template<class T >
void GetRequiredParameter (const char *className, const char *name, T &value) const
 Retrieves a required name/value pair. More...
 
void GetRequiredIntParameter (const char *className, const char *name, int &value) const
 Retrieves a required name/value pair. More...
 

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. More...
 

Detailed Description

_

Definition at line 18 of file rabin.h.

Member Function Documentation

Integer RabinFunction::ApplyFunction ( const Integer x) const
virtual

Applies the trapdoor.

Parameters
xthe 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.

Definition at line 31 of file rabin.cpp.

References Integer::Squared().

Integer RabinFunction::PreimageBound ( ) const
inlinevirtual

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.

Definition at line 30 of file rabin.h.

Integer RabinFunction::ImageBound ( ) const
inlinevirtual

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 31 of file rabin.h.

bool RabinFunction::Validate ( RandomNumberGenerator rng,
unsigned int  level 
) const
virtual

Check this object for errors.

Parameters
rnga RandomNumberGenerator for objects which use randomized testing
levelthe 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.

Implements CryptoMaterial.

Reimplemented in InvertibleRabinFunction.

Definition at line 43 of file rabin.cpp.

References Integer::One().

Referenced by InvertibleRabinFunction::Validate().

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

Get a named value.

Parameters
namethe name of the object or value to retrieve
valueTypereference to a variable that receives the value
pValuevoid 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()

Implements NameValuePairs.

Reimplemented in InvertibleRabinFunction.

Definition at line 54 of file rabin.cpp.

References Name::Modulus(), Name::QuadraticResidueModPrime1(), and Name::QuadraticResidueModPrime2().

void RabinFunction::AssignFrom ( const NameValuePairs source)
virtual

Assign values to this object.

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

Implements CryptoMaterial.

Reimplemented in InvertibleRabinFunction.

Definition at line 63 of file rabin.cpp.

References Name::Modulus(), Name::QuadraticResidueModPrime1(), and Name::QuadraticResidueModPrime2().

Integer TrapdoorFunction::ApplyRandomizedFunction ( RandomNumberGenerator rng,
const Integer x 
) const
inlinevirtualinherited

Applies the trapdoor function.

Parameters
rnga RandomNumberGenerator derived class
xthe 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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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 CryptoMaterial::ThrowIfInvalid ( RandomNumberGenerator rng,
unsigned int  level 
) const
inlinevirtualinherited

Check this object for errors.

Parameters
rnga RandomNumberGenerator for objects which use randomized testing
levelthe level of thoroughness
Exceptions
InvalidMaterial

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

Definition at line 1938 of file cryptlib.h.

virtual void CryptoMaterial::Save ( BufferedTransformation bt) const
inlinevirtualinherited

Saves a key to a BufferedTransformation.

Parameters
btthe 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 in InvertibleRSAFunction, InvertibleRWFunction, and RWFunction.

Definition at line 1950 of file cryptlib.h.

Referenced by TestDataNameValuePairs::GetVoidValue().

virtual void CryptoMaterial::Load ( BufferedTransformation bt)
inlinevirtualinherited

Loads a key from a BufferedTransformation.

Parameters
btthe 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 in InvertibleRSAFunction, InvertibleRWFunction, and RWFunction.

Definition at line 1967 of file cryptlib.h.

Referenced by TestDataNameValuePairs::GetVoidValue().

virtual bool CryptoMaterial::SupportsPrecomputation ( ) const
inlinevirtualinherited

Determines whether the object supports precomputation.

Returns
true if the object supports precomputation, false otherwise

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

Definition at line 1972 of file cryptlib.h.

virtual void CryptoMaterial::Precompute ( unsigned int  precomputationStorage)
inlinevirtualinherited

Perform precomputation.

Parameters
precomputationStoragethe 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_PublicKeyImpl< GP >, DL_PublicKeyImpl< DL_GroupParameters_EC< EC > >, DL_PrivateKeyImpl< GP >, DL_PrivateKeyImpl< DL_GroupParameters_EC< EC > >, DL_GroupParameters< T >, DL_GroupParameters< Integer >, and DL_GroupParameters< typename EcPrecomputation< EC >::Element >.

Definition at line 1981 of file cryptlib.h.

template<class T >
bool NameValuePairs::GetThisObject ( T &  object) const
inlineinherited

Get a copy of this object or subobject.

Template Parameters
Tclass or type
Parameters
objectreference 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
inlineinherited

Get a pointer to this object.

Template Parameters
Tclass or type
Parameters
ptrreference 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
inlineinherited
template<class T >
T NameValuePairs::GetValueWithDefault ( const char *  name,
defaultValue 
) const
inlineinherited
std::string NameValuePairs::GetValueNames ( ) const
inlineinherited

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.

Referenced by TestDataNameValuePairs::GetVoidValue().

bool NameValuePairs::GetIntValue ( const char *  name,
int &  value 
) const
inlineinherited

Get a named value with type int.

Parameters
namethe name of the value to retrieve
valuethe 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 KDF2_RNG::GenerateBlock(), DL_GroupParameters_IntegerBased::GenerateRandom(), InvertibleRabinFunction::GenerateRandom(), InvertibleRWFunction::GenerateRandom(), InvertibleESIGNFunction::GenerateRandom(), InvertibleLUCFunction::GenerateRandom(), InvertibleRSAFunction::GenerateRandom(), and DL_GroupParameters_DSA::GenerateRandom().

int NameValuePairs::GetIntValueWithDefault ( const char *  name,
int  defaultValue 
) const
inlineinherited
static void NameValuePairs::ThrowIfTypeMismatch ( const char *  name,
const std::type_info &  stored,
const std::type_info &  retrieving 
)
inlinestaticinherited

Ensures an expected name and type is present.

Parameters
namethe name of the value
storedthe type that was stored for the name
retrievingthe 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 CombinedNameValuePairs::GetVoidValue().

template<class T >
void NameValuePairs::GetRequiredParameter ( const char *  className,
const char *  name,
T &  value 
) const
inlineinherited

Retrieves a required name/value pair.

Template Parameters
Tclass or type
Parameters
classNamethe name of the class
namethe name of the value
valuereference 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(), StringStore::CopyRangeTo2(), BaseN_Decoder::IsolatedInitialize(), Grouper::IsolatedInitialize(), and RandomNumberSink::IsolatedInitialize().

void NameValuePairs::GetRequiredIntParameter ( const char *  className,
const char *  name,
int &  value 
) const
inlineinherited

Retrieves a required name/value pair.

Parameters
classNamethe name of the class
namethe name of the value
valuereference 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.

References g_nullNameValuePairs.

Referenced by StringStore::CopyRangeTo2(), and BaseN_Decoder::IsolatedInitialize().


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