Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CODEX_Ciphers::ElGamalPublicKey Class Reference

Serializable encapsulation of an ElGamal public key. More...

#include <ElGamal.h>

Inheritance diagram for CODEX_Ciphers::ElGamalPublicKey:

Inheritance graph
[legend]
Collaboration diagram for CODEX_Ciphers::ElGamalPublicKey:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ElGamalPublicKey ()
 Default constructor, for creating an object to be unmarshalled.
 ElGamalPublicKey (BIGNUM *p, BIGNUM *g, BIGNUM *y)
 Constructor taking components of the key as BIGNUM%s.
 ElGamalPublicKey (const CODEX_ASN1::BigNumber &p, const CODEX_ASN1::BigNumber &g, const CODEX_ASN1::BigNumber &y)
 Constructor taking components of the key as BigNumber%s.
 ElGamalPublicKey (const ElGamalPublicKey &aKey)
 Copy constructor.
virtual ~ElGamalPublicKey ()
 Destructor.
void operator= (const ElGamalPublicKey &aKey)
 Assignment operator.
const CODEX_ASN1::BigNumberp () const
 Prime modulus of the public key.
const CODEX_ASN1::BigNumberg () const
 Generator of the multiplicative subgroup of Z_p.
const CODEX_ASN1::BigNumbery () const
 g^x for private key x
const BIGNUM * p1 () const
const BIGNUM * q () const
ElGamalCipherTextencrypt (const BIGNUM *message, BIGNUM *k=0) const
 Encrypt a message.
ElGamalSchnorrCipherTextencryptS (const BIGNUM *message, const CODEX_ASN1::Base &id, const HashFunction &hashFunc, BIGNUM *k=0) const
 Encrypt a message with a Schnorr signature attached.
bool verifySignature (const ElGamalSignature &signature, const BIGNUM *message) const
 Verify the signature for a message.
int marshal (unsigned char **pp) const
 Serialize the object.
void * unmarshal (void *bogus, unsigned char **pp, long length)
 Unserialize the object.
void toFile (const char *fname) const
 Writes the public key to a file.
void * fromFile (const char *fname)
 Reads the public key from a file.
bool initialized () const

Protected Member Functions

void encryptVals (const BIGNUM *message, BIGNUM *k, BIGNUM *c1, BIGNUM *c2) const
 Helper function for computing encryptions.

Protected Attributes

bool m_initialized
 Has this object been initialized yet, or is it still blank?

Detailed Description

Serializable encapsulation of an ElGamal public key.

Definition at line 193 of file ElGamal.h.


Member Function Documentation

ElGamalCipherText * ElGamalPublicKey::encrypt const BIGNUM *  message,
BIGNUM *  k = 0
const
 

Encrypt a message.

In general, the message should include some sort of padding to defend against attacks exploiting short messages. See, for example, "Why Textbook ElGamal and RSA Encryption are Insecure" by D. Boneh, A. Joux, and P.Q. Nguyen.

Parameters:
message Non-null pointer to a BIGNUM containing the message to encrypt. This message must be smaller than the modulus of the public key.
k If not 0, the random encryption exponent will be returned.
Returns:
A pointer to a new ElGamalCipherText object.
Exceptions:
BignumNullException The message is 0 or some memory allocation failed.
BignumRandRangeException There was an error generating the random exponent.
BignumModExpException There was an error during modular exponentiation.
BignumModMulException There was an error during modular multiplication.
BignumContextException Memory allocation failed for a BN_CTX.

Definition at line 155 of file ElGamalPublicKey.cc.

References encryptVals().

ElGamalSchnorrCipherText * ElGamalPublicKey::encryptS const BIGNUM *  message,
const CODEX_ASN1::Base id,
const HashFunction hashFunc,
BIGNUM *  k = 0
const
 

Encrypt a message with a Schnorr signature attached.

In general, the message should include some sort of padding to defend against attacks exploiting short messages. See, for example, "Why Textbook ElGamal and RSA Encryption are Insecure" by D. Boneh, A. Joux, and P.Q. Nguyen.

The addition of a Schnorr signature is described in "Security of Signed ElGamal Encryption" by C.P. Schnorr and M. Jakobsson. That scheme defends against adaptive chosen ciphertext attacks. We extend this to an encrypter-aware scheme by adding a unique identifier for the principal that knows the plaintext.

Parameters:
message Non-null pointer to a BIGNUM containing the message to encrypt. This message must be smaller than the modulus of the public key.
id serializable object containing an identifier for the encrypting party.
hashFunc A secure hash function.
k If not 0, the random encryption exponent will be returned.
Returns:
A pointer to a new ElGamalSchnorrCipherText object.
Exceptions:
BignumNullException The message is 0 or some memory allocation failed.
BignumRandRangeException There was an error generating the random exponent.
BignumModExpException There was an error during modular exponentiation.
BignumModMulException There was an error during modular multiplication.
BignumContextException Memory allocation failed for a BN_CTX.

Definition at line 198 of file ElGamalPublicKey.cc.

References encryptVals(), CODEX_ASN1::BigNumber::marshal(), q(), and CODEX_ASN1::BigNumber::value().

Referenced by CODEX_Client::Client::readKey(), and CODEX_Client::Client::writeKey().

void ElGamalPublicKey::encryptVals const BIGNUM *  message,
BIGNUM *  k,
BIGNUM *  c1,
BIGNUM *  c2
const [protected]
 

Helper function for computing encryptions.

All parameters must be allocated beforehand.

Parameters:
message Non-null pointer to a BIGNUM containing the message to encrypt. This message must be smaller than the modulus of the public key.
k Random exponent used to generate ciphertext. If 0, a new random value will be chosen.
c1 The first part of the ciphertext
c2 The second part of the ciphertext

Definition at line 354 of file ElGamalPublicKey.cc.

References CODEX_Ciphers::jacobi(), q(), and CODEX_ASN1::BigNumber::value().

Referenced by encrypt(), and encryptS().

void * ElGamalPublicKey::fromFile const char *  fname  ) 
 

Reads the public key from a file.

Parameters:
fname Name of the file from which to read the key
Exceptions:
FileCannotOpenException The file fname could not be opened.

Definition at line 590 of file ElGamalPublicKey.cc.

References p(), and unmarshal().

bool CODEX_ASN1::Base::initialized  )  const [inline, inherited]
 

Returns:
Has this object been initialized?

Definition at line 175 of file Base.h.

References CODEX_ASN1::Base::m_initialized.

Referenced by CODEX_APSS::SecretManagement::addComputeMsg(), CODEX_APSS::SecretManagement::addEstablishMsg(), CODEX_APSS::SecretManagement::addEstablishResponse(), CODEX_APSS::SecretManagement::addInitMsg(), CODEX_APSS::SecretManagement::addSharing(), CODEX_APSS::SecretManagement::addSubsharing(), CODEX_VSS::Combinatoric< NumT, ThreshT >::apply(), CODEX_Server::ServerState::caKey(), CODEX_KeyService::ClientCreateCallback::ClientCreateCallback(), CODEX_VSS::Combinatoric< NumT, ThreshT >::count(), CODEX_Server::QuorumBuilderAct::handler(), CODEX_APSS::MessageVerifier::handler(), CODEX_KeyService::DelegateResponseVerifier::handler(), CODEX_KeyService::DelegateRequestDistributor::handler(), CODEX_KeyService::ClientMessageVerifier::handler(), CODEX_KeyService::ClientMessageSigner::handler(), CODEX_VSS::SubshareLabel< LabelType >::marshal(), CODEX_KeyService::KeyInfo::marshal(), CODEX_VSS::LabeledShare< ShareType, OneWay >::marshal(), CODEX_VSS::ShareLabel< _ShareType, _OneWay >::marshal(), CODEX_VSS::ModExpFunctionalArgs::marshal(), CODEX_VSS::Combinatoric< NumT, ThreshT >::marshal(), CODEX_KeyService::SignWriteCallback::operator()(), CODEX_KeyService::SignReadCallback::operator()(), CODEX_KeyService::SignCreateCallback::operator()(), CODEX_VSS::ModExpFunctional::operator()(), CODEX_KeyService::ClientReadCallback::operator()(), CODEX_KeyService::ClientCreateCallback::operator()(), CODEX_VSS::Combinatoric< NumT, ThreshT >::operator+=(), CODEX_Server::ServerState::readElGamalShares(), CODEX_VSS::Combinatoric< NumT, ThreshT >::recover(), CODEX_APSS::SecretManagement::sendFinished(), CODEX_Server::ServerState::serviceKey(), CODEX_Server::ServerState::setEGShareCallback(), and CODEX_Server::ServerState::setRSAShareCallback().

const BIGNUM * ElGamalPublicKey::p1  )  const
 

Returns:
p-1
Exceptions:
BignumNullException Memory could not be allocated.
BignumSubException An error occurred during subtraction.

Definition at line 114 of file ElGamalPublicKey.cc.

References CODEX_ASN1::BigNumber::value().

Referenced by CODEX_KeyService::ClientMessageSigner::handler(), and q().

const BIGNUM * ElGamalPublicKey::q  )  const
 

Returns:
(p-1)/2
Exceptions:
BignumNullException Memory could not be allocated.
BignumRshiftException An error occurred while bit-shifting.

Definition at line 134 of file ElGamalPublicKey.cc.

References p1().

Referenced by CODEX_APSS::StateInfo::configure(), encryptS(), encryptVals(), and CODEX_Client::Client::readKey().

void ElGamalPublicKey::toFile const char *  fname  )  const
 

Writes the public key to a file.

Parameters:
fname Name of the file in which to store the key
Exceptions:
FileCannotCreateException The file fname could not be created.

Definition at line 568 of file ElGamalPublicKey.cc.

References marshal(), and p().

bool ElGamalPublicKey::verifySignature const ElGamalSignature signature,
const BIGNUM *  message
const
 

Verify the signature for a message.

Parameters:
signature Signature object to verify
message Non-null pointer to a BIGNUM containing the message allegedly signed with signature. The message must be smaller than the modulus of the public key, and might be a digest of a longer message.
Returns:
Success or failure of the signature verification
Exceptions:
BignumNullException The message is 0 or some memory allocation failed.
BignumModExpException There was an error during modular exponentiation.
BignumModMulException There was an error during modular multiplication.
BignumContextException Memory allocation failed for a BN_CTX.

Definition at line 428 of file ElGamalPublicKey.cc.

References CODEX_ASN1::BigNumber::value().


The documentation for this class was generated from the following files:
Generated on Fri May 6 17:41:51 2005 for COrnell Data EXchange (CODEX) by  doxygen 1.4.1