Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

CODEX_Ciphers::RSAPrivateKey Class Reference

Serializable encapsulation of an RSA private key. More...

#include <RSA.h>

Inheritance diagram for CODEX_Ciphers::RSAPrivateKey:

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

Collaboration graph
[legend]
List of all members.

Public Methods

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

 RSAPrivateKey (BIGNUM *p, BIGNUM *q, BIGNUM *d, BIGNUM *n=0, BIGNUM *phi=0)
 Create an RSAPrivateKey from BIGNUMs.

 RSAPrivateKey (const CODEX_ASN1::BigNumber &p, const CODEX_ASN1::BigNumber &q, const CODEX_ASN1::BigNumber &d)
 Create an RSAPrivateKey from BigNumbers.

 RSAPrivateKey (const RSAPrivateKey &aKey)
 Copy constructor.

virtual ~RSAPrivateKey ()
 Destructor.

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

virtual const CODEX_ASN1::SecureBigNumberp () const
 
Returns:
one prime factor of the public modulus


virtual const CODEX_ASN1::SecureBigNumberq () const
 
Returns:
one prime factor of the public modulus


virtual const CODEX_ASN1::SecureBigNumberd () const
 
Returns:
the private decryption exponent.


virtual const CODEX_ASN1::SecureBigNumbern () const
 
Returns:
the public modulus


virtual const CODEX_ASN1::SecureBigNumberphi () const
 
Returns:
Euler totient function of n


BIGNUM * decrypt (const RSACipherText &cipherText) const
 Decrypt a message.

RSASignaturesign (const BIGNUM *message) const
 Sign 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 private key to a file.

void * fromFile (const char *fname)
 Reads the private key from a file.

void fromPEMFile (const char *fname, const char *phrase=0)
 Reads the private key from a PEM-format file.


Detailed Description

Serializable encapsulation of an RSA private key.

This is not an especially memory-efficient implementation, in that the public modulus and the Euler totient function of it are both stored and are also marshalled with the data. Since private keys are not typically sent over the wire and only need to be read during process initialization (or upon creation of a new key), this should not be a serious issue.

Definition at line 187 of file RSA.h.


Constructor & Destructor Documentation

RSAPrivateKey::RSAPrivateKey BIGNUM *    p,
BIGNUM *    q,
BIGNUM *    d,
BIGNUM *    n = 0,
BIGNUM *    phi = 0
 

Create an RSAPrivateKey from BIGNUMs.

Exceptions:
BignumMulException 
BignumSubException 

Definition at line 36 of file RSAPrivateKey.cc.

References n(), p(), phi(), and q().

RSAPrivateKey::RSAPrivateKey const CODEX_ASN1::BigNumber   p,
const CODEX_ASN1::BigNumber   q,
const CODEX_ASN1::BigNumber   d
 

Create an RSAPrivateKey from BigNumbers.

Exceptions:
BignumMulException 
BignumSubException 

Definition at line 132 of file RSAPrivateKey.cc.

References CODEX_ASN1::BigNumber::value().


Member Function Documentation

BIGNUM * RSAPrivateKey::decrypt const RSACipherText   cipherText const
 

Decrypt a message.

Parameters:
cipherText  The encryption of a message using the public key corresponding to this private key.
Returns:
A pointer to a new BIGNUM containing the plaintext.
Exceptions:
BignumNullException  Some memory allocation failed.
BignumModExpException  There was an error during modular exponentiation.
BignumContextException  Memory allocation failed for a BN_CTX.

Definition at line 235 of file RSAPrivateKey.cc.

References CODEX_ASN1::BigNumber::value().

void * RSAPrivateKey::fromFile const char *    fname
 

Reads the private 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 376 of file RSAPrivateKey.cc.

References p(), and unmarshal().

void RSAPrivateKey::fromPEMFile const char *    fname,
const char *    phrase = 0
 

Reads the private key from a PEM-format file.

Parameters:
fname  Name of the file from which to read the key
phrase  Passphrase for the file. If 0 the user will be prompted for it.
Exceptions:
FileCannotOpenException  The file fname could not be opened.
BignumContextException  A BN_CTX could not be allocated.
BignumNullException  A BIGNUM could not be allocated.
BignumSubException  Error occurred in subtraction.
BignumMulException  Error occurred in multiplication.

Definition at line 405 of file RSAPrivateKey.cc.

References CODEX_ASN1::Base::m_initialized.

RSASignature * RSAPrivateKey::sign const BIGNUM *    message const
 

Sign a message.

Parameters:
message  Non-null pointer to a BIGNUM containing the message to sign. This message must be smaller than the modulus of the public key.
Returns:
A pointer to a new RSASignature object.
Exceptions:
BignumNullException  The message is 0 or some memory allocation failed.
BignumModExpException  There was an error during modular exponentiation.
BignumContextException  Memory allocation failed for a BN_CTX.

Reimplemented in CODEX_Ciphers::VarRSAPrivateKey.

Definition at line 241 of file RSAPrivateKey.cc.

Referenced by CODEX_APSS::InitActivity::addEvidence(), CODEX_APSS::SecretManagement::beginRun(), CODEX_Client::Client::createKey(), CODEX_Server::QuorumBuilderAct::handler(), CODEX_APSS::MessageProcessor::handler(), CODEX_APSS::InitActivity::handler(), CODEX_KeyService::ClientResponseSigner::handler(), CODEX_APSS::InitCallback::operator()(), CODEX_APSS::ComputeCallback::operator()(), CODEX_Ciphers::PolCredBase::PolCredBase(), CODEX_Client::Client::readKey(), CODEX_APSS::StateInfo::recover(), CODEX_Ciphers::VarRSAPrivateKey::sign(), CODEX_Server::SignedAugmentedEGPublicKey::SignedAugmentedEGPublicKey(), and CODEX_Client::Client::writeKey().

void RSAPrivateKey::toFile const char *    fname const
 

Writes the private 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 353 of file RSAPrivateKey.cc.

References marshal(), and p().


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