Public Member Functions | Static Public Member Functions

XTR_DH Class Reference

XTR-DH with key validation. More...

#include <xtrcrypt.h>

Inheritance diagram for XTR_DH:
SimpleKeyAgreementDomain CryptoParameters KeyAgreementAlgorithm GeneratableCryptoMaterial AsymmetricAlgorithm CryptoMaterial Algorithm NameValuePairs Clonable

List of all members.

Public Member Functions

 XTR_DH (const Integer &p, const Integer &q, const GFP2Element &g)
 XTR_DH (RandomNumberGenerator &rng, unsigned int pbits, unsigned int qbits)
 XTR_DH (BufferedTransformation &domainParams)
void DEREncode (BufferedTransformation &domainParams) const
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
 to be implemented by derived classes, users should use one of the above functions instead
void AssignFrom (const NameValuePairs &source)
 assign values from source to this object
CryptoParametersAccessCryptoParameters ()
unsigned int AgreedValueLength () const
unsigned int PrivateKeyLength () const
unsigned int PublicKeyLength () const
void GeneratePrivateKey (RandomNumberGenerator &rng, byte *privateKey) const
void GeneratePublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
bool Agree (byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const
const IntegerGetModulus () const
const IntegerGetSubgroupOrder () const
const GFP2ElementGetSubgroupGenerator () const
void SetModulus (const Integer &p)
void SetSubgroupOrder (const Integer &q)
void SetSubgroupGenerator (const GFP2Element &g)
virtual unsigned int AgreedValueLength () const =0
 return length of agreed value produced
virtual unsigned int PrivateKeyLength () const =0
 return length of private keys in this domain
virtual unsigned int PublicKeyLength () const =0
 return length of public keys in this domain
virtual void GeneratePrivateKey (RandomNumberGenerator &rng, byte *privateKey) const =0
 generate private key
virtual void GeneratePublicKey (RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0
 generate public key
virtual void GenerateKeyPair (RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
 generate private/public key pair
virtual bool Agree (byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const =0
 derive agreed value from your private key and couterparty's public key, return false in case of failure
CryptoMaterialAccessMaterial ()
 returns a reference to the crypto material used by this object
const CryptoMaterialGetMaterial () const
 returns a const reference to the crypto material used by this object
virtual CryptoParametersAccessCryptoParameters ()=0
virtual const CryptoParametersGetCryptoParameters () const
void BERDecode (BufferedTransformation &bt)
 for backwards compatibility, calls AccessMaterial().Load(bt)
void DEREncode (BufferedTransformation &bt) const
 for backwards compatibility, calls GetMaterial().Save(bt)
virtual std::string AlgorithmName () const
 returns name of this algorithm, not universally implemented yet
virtual ClonableClone () const
 this is not implemented by most classes yet
virtual void GenerateRandom (RandomNumberGenerator &rng, const NameValuePairs &params=g_nullNameValuePairs)
 generate a random key or crypto parameters
void GenerateRandomWithKeySize (RandomNumberGenerator &rng, unsigned int keySize)
 calls the above function with a NameValuePairs object that just specifies "KeySize"
virtual void ThrowIfInvalid (RandomNumberGenerator &rng, unsigned int level) const
 throws InvalidMaterial if this object fails Validate() test
virtual void Save (BufferedTransformation &bt) const
 save key into a BufferedTransformation
virtual void Load (BufferedTransformation &bt)
 load key from a BufferedTransformation
virtual bool SupportsPrecomputation () const
virtual void Precompute (unsigned int n)
 do 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 a subobject of it
template<class T >
bool GetThisPointer (T *&p) const
 get a pointer to this object, as a pointer to T
template<class T >
bool GetValue (const char *name, T &value) const
 get a named value, returns true if the name exists
template<class T >
GetValueWithDefault (const char *name, T defaultValue) const
 get a named value, returns the default if the name doesn't exist
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
void GetRequiredIntParameter (const char *className, const char *name, int &value) const

Static Public Member Functions

static void ThrowIfTypeMismatch (const char *name, const std::type_info &stored, const std::type_info &retrieving)
 used by derived classes to check for type mismatch

Detailed Description

XTR-DH with key validation.

Definition at line 14 of file xtrcrypt.h.

Member Function Documentation

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

check this object for errors

level denotes the level of thoroughness: 0 - using this object won't cause a crash or exception (rng is ignored) 1 - this object will probably function (encrypt, sign, etc.) correctly (but may not check for weak keys and such) 2 - make sure this object will function correctly, and do reasonable security checks 3 - do checks that may take a long time
true if the tests pass

Implements CryptoMaterial.

Definition at line 41 of file xtrcrypt.cpp.

References Integer::One().

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

assign values from source to this object

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

Implements CryptoMaterial.

Definition at line 68 of file xtrcrypt.cpp.

virtual void SimpleKeyAgreementDomain::GeneratePrivateKey ( RandomNumberGenerator rng,
byte *  privateKey 
) const [pure virtual, inherited]
virtual void SimpleKeyAgreementDomain::GeneratePublicKey ( RandomNumberGenerator rng,
const byte *  privateKey,
byte *  publicKey 
) const [pure virtual, inherited]
void SimpleKeyAgreementDomain::GenerateKeyPair ( RandomNumberGenerator rng,
byte *  privateKey,
byte *  publicKey 
) const [virtual, inherited]

generate private/public key pair

equivalent to calling GeneratePrivateKey() and then GeneratePublicKey()

Definition at line 808 of file cryptlib.cpp.

References SimpleKeyAgreementDomain::GeneratePrivateKey(), and SimpleKeyAgreementDomain::GeneratePublicKey().

virtual bool SimpleKeyAgreementDomain::Agree ( byte *  agreedValue,
const byte *  privateKey,
const byte *  otherPublicKey,
bool  validateOtherPublicKey = true 
) const [pure virtual, inherited]

derive agreed value from your private key and couterparty's public key, return false in case of failure

If you have previously validated the public key, use validateOtherPublicKey=false to save time.
size of agreedValue == AgreedValueLength()
length of privateKey == PrivateKeyLength()
length of otherPublicKey == PublicKeyLength()

Implemented in DL_SimpleKeyAgreementDomainBase< T >, and DL_SimpleKeyAgreementDomainBase< GROUP_PARAMETERS::Element >.

Referenced by DH2::Agree().

virtual void GeneratableCryptoMaterial::GenerateRandom ( RandomNumberGenerator rng,
const NameValuePairs params = g_nullNameValuePairs 
) [inline, virtual, inherited]

generate a random key or crypto parameters

KeyingErr if algorithm parameters are invalid, or if a key can't be generated (e.g., if this is a public key object)

Reimplemented in DL_GroupParameters_EC< EC >, InvertibleESIGNFunction, DL_GroupParameters_IntegerBased, DL_GroupParameters_DSA, InvertibleLUCFunction, DL_PrivateKeyImpl< GP >, InvertibleRabinFunction, InvertibleRSAFunction, InvertibleRWFunction, and DL_PrivateKeyImpl< DL_GroupParameters_EC< EC > >.

Definition at line 1107 of file cryptlib.h.

Referenced by GeneratableCryptoMaterial::GenerateRandomWithKeySize().

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

load key from a BufferedTransformation

KeyingErr if decode fails
Generally does not check that the key is valid. Call ValidateKey() or ThrowIfInvalidKey() to check that.

Reimplemented in InvertibleRSAFunction.

Definition at line 1072 of file cryptlib.h.

virtual bool CryptoMaterial::SupportsPrecomputation (  )  const [inline, virtual, inherited]
virtual void CryptoMaterial::Precompute ( unsigned int  n  )  [inline, virtual, inherited]

do precomputation

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

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 1081 of file cryptlib.h.

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

get a named value with type int

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)

Definition at line 282 of file cryptlib.h.

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

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