RSA Class Reference

#include <pk.h>

Inheritance diagram for RSA:

Inheritance graph
Collaboration diagram for RSA:

Collaboration graph

Detailed Description

Implementation of RSA-based cryptographic schemes.

Code samples illustrating the use of class RSA can be found in the Cookbook section Handling Public and Private Keys.

References

The RSA public key cryptosystem is specified in:


Public Types

 pkcs1 = 1
 Perform PKCS#1 v1.5 compliant operations.
 x931 = 2
 Perform ANSI x9.31 compliant operations.
 pss = 3
 Use PSS (PKCS#1 v2.1).
enum  {
  pkcs1 = 1,
  x931 = 2,
  pss = 3
}
 Standards compliance flags. More...

Public Member Functions

 RSA ()
 Constructor used to create an empty RSA object (PKCS#1 with 2 primes).
virtual ~RSA ()
 Destructor.
int check () const
 Check the consistency of the public and private key components in this object.
int loadpub (const num &expo1, const num &pq1)
 Load a (raw) RSA public key into this object.
int loadpriv (const num &p1)
 Load (raw) RSA private key into this object (as a single prime factor of the modulus).
int loadpriv (const num &p1, const num &q1)
 Load a (raw) RSA private key into this object (as a pair of prime factors of the modulus).
str asn1private () const
 Get this object's ASN.1 DER-encoded private key.
int loadasn1private (const str &b1)
 Load an ASN.1 DER-encoded private key.
int loadpub (const str &pubk)
 Load an ASN.1 DER-encoded public key.
int genpub ()
 Generate a public key based on the private key in this object.
int setup ()
 Derive PKCS#1 RSA private key components from the prime factors of the modulus.
int encrypt (const num &m, num &x) const
 Encrypt a specified buffer.
int decrypt (const num &c, num &x) const
 Decrypt a specified buffer.
int sign (const num &hash, const num &random, num &sig, int nHashType) const
 Sign a specified message digest.
bool hasPrivate () const
 Predicate used to test whether this object contains a private key.
bool hasPublic () const
 Predicate used to test whether this object contains a public key.
void clear ()
 Clear this object.


Member Enumeration Documentation

anonymous enum

Standards compliance flags.

Enumerator:
pkcs1  Perform PKCS#1 v1.5 compliant operations.
x931  Perform ANSI x9.31 compliant operations.
pss  Use PSS (PKCS#1 v2.1).


Member Function Documentation

str asn1private (  )  const

Get this object's ASN.1 DER-encoded private key.

Returns:
a str containing this object's ASN.1 DER-encoded private key (in the clear!)

int check (  )  const

Check the consistency of the public and private key components in this object.

Returns:
0 (success, i.e., the key is OK)
CDK_NO_KEY
CDK_KEYPAIR_INCONSISTENT, if the public key doesn't match the private key

void clear ( void   )  [inline]

Clear this object.

Remarks:
Modifies: size and public key are zeroized; other components are zeroized by their own destructors when the object is destroyed.

int decrypt ( const num c,
num x 
) const

Decrypt a specified buffer.

Parameters:
c a num representing the ciphertext to decrypt
x a num to receive the plaintext output
Returns:
0 (success)
CDK_ERROR_STATE

int encrypt ( const num m,
num x 
) const

Encrypt a specified buffer.

Parameters:
m a num representing the message to encrypt
x a num to receive the ciphertext output
Returns:
0 (success)
CDK_ERROR_STATE

int genpub (  ) 

Generate a public key based on the private key in this object.

Returns:
0

bool hasPrivate (  )  const [inline]

Predicate used to test whether this object contains a private key.

Returns:
true, if this object contains a private key
false, otherwise

bool hasPublic (  )  const [inline]

Predicate used to test whether this object contains a public key.

Returns:
true, if this object contains a public key
false otherwise

int loadasn1private ( const str b1  ) 

Load an ASN.1 DER-encoded private key.

Parameters:
b1 the ASN.1 DER-encoded private key to be loaded
Returns:
0 (success)
CDK_PARSE_ERROR
CDK_INVALID_KEY_TOO_MANY_PRIMES
Remarks:
Only private keys containing 2, 3, or 4 primes are supported.

int loadpriv ( const num p1,
const num q1 
) [inline]

Load a (raw) RSA private key into this object (as a pair of prime factors of the modulus).

Parameters:
p1 the first prime
q1 the second prime
Returns:
0

int loadpriv ( const num p1  )  [inline]

Load (raw) RSA private key into this object (as a single prime factor of the modulus).

Parameters:
p1 the private key to load into this object.
Returns:
0
Remarks:
This call clears the object's public key.

int loadpub ( const str pubk  ) 

Load an ASN.1 DER-encoded public key.

Parameters:
pubk the ASN.1 DER-encoded RSA public key to be loaded
Returns:
0 (success)
CDK_NO_KEY
CDK_KEYPAIR_INCONSISTENT
CDK_KEY_INVALID

int loadpub ( const num expo1,
const num pq1 
)

Load a (raw) RSA public key into this object.

Parameters:
expo1 the RSA exponent
pq1 the RSA modulus
Returns:
0

int setup (  ) 

Derive PKCS#1 RSA private key components from the prime factors of the modulus.

Returns:
0 (success)
Remarks:
Modifies: d, dmodp1, dmodq1, qinvmodp, dmodr1, pqinvmodr, dmods1, and pqrinvmods.

int sign ( const num hash,
const num random,
num sig,
int  nHashType 
) const [inline]

Sign a specified message digest.

Parameters:
hash a num containing the hash value to be signed
random unused (provided for template compatability with Key)
sig the output buffer to receive the signature
nHashType algorithm id: hSHA1 or hMD5 (FIPS 140-1 compliant applications must use hSHA1)
Returns:
0 (success)
CDK_ERROR_STATE


The documentation for this class was generated from the following file:
ISC Cryptographic Development Kit - User's Guide
ISC website
Questions? E-mail ISC technical support
Copyright© 2002-2006 Information Security Corp. All rights reserved.