Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound 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 Methods

 ElGamalPublicKey ()
 Default constructor, for creating an object to be unmarshalled.

 ElGamalPublicKey (BIGNUM *p, BIGNUM *g, BIGNUM *y)
 Constructor taking components of the key as BIGNUMs.

 ElGamalPublicKey (const CODEX_ASN1::BigNumber &p, const CODEX_ASN1::BigNumber &g, const CODEX_ASN1::BigNumber &y)
 Constructor taking components of the key as BigNumbers.

 ElGamalPublicKey (const ElGamalPublicKey &aKey)
 Copy constructor.

virtual ~ElGamalPublicKey ()
 Destructor.

void operator= (const ElGamalPublicKey &aKey)
 Assignment operator.

const CODEX_ASN1::BigNumberp () const
 
Returns:
prime modulus of the public key


const CODEX_ASN1::BigNumberg () const
 
Returns:
generator of the multiplicative subgroup of Z_p


const CODEX_ASN1::BigNumbery () const
 
Returns:
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.


Protected Methods

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


Detailed Description

Serializable encapsulation of an ElGamal public key.

Definition at line 190 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::Base::marshal(), 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().

const BIGNUM * ElGamalPublicKey::p1  
 

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(), q(), CODEX_Ciphers::TranslationCertificate::TranslationCertificate(), and CODEX_Ciphers::TranslationCertificate::verify().

const BIGNUM * ElGamalPublicKey::q  
 

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(), CODEX_Ciphers::ElGamalPrivateKey::decrypt(), encryptS(), encryptVals(), CODEX_Client::Client::readKey(), and CODEX_Ciphers::ElGamalPrivateKey::sign().

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_Ciphers::ElGamalSignature::r(), CODEX_Ciphers::ElGamalSignature::s(), and CODEX_ASN1::BigNumber::value().


The documentation for this class was generated from the following files:
Generated on Wed Jun 2 16:33:04 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18