Botan  1.11.15
src/lib/pubkey/rsa/rsa.h
Go to the documentation of this file.
00001 /*
00002 * RSA
00003 * (C) 1999-2008 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_RSA_H__
00009 #define BOTAN_RSA_H__
00010 
00011 #include <botan/if_algo.h>
00012 
00013 
00014 namespace Botan {
00015 
00016 /**
00017 * RSA Public Key
00018 */
00019 class BOTAN_DLL RSA_PublicKey : public virtual IF_Scheme_PublicKey
00020    {
00021    public:
00022       std::string algo_name() const { return "RSA"; }
00023 
00024       RSA_PublicKey(const AlgorithmIdentifier& alg_id,
00025                     const secure_vector<byte>& key_bits) :
00026          IF_Scheme_PublicKey(alg_id, key_bits)
00027          {}
00028 
00029       /**
00030       * Create a RSA_PublicKey
00031       * @arg n the modulus
00032       * @arg e the exponent
00033       */
00034       RSA_PublicKey(const BigInt& n, const BigInt& e) :
00035          IF_Scheme_PublicKey(n, e)
00036          {}
00037 
00038    protected:
00039       RSA_PublicKey() {}
00040    };
00041 
00042 /**
00043 * RSA Private Key
00044 */
00045 class BOTAN_DLL RSA_PrivateKey : public RSA_PublicKey,
00046                                  public IF_Scheme_PrivateKey
00047    {
00048    public:
00049       bool check_key(RandomNumberGenerator& rng, bool) const;
00050 
00051       RSA_PrivateKey(const AlgorithmIdentifier& alg_id,
00052                      const secure_vector<byte>& key_bits,
00053                      RandomNumberGenerator& rng) :
00054          IF_Scheme_PrivateKey(rng, alg_id, key_bits) {}
00055 
00056       /**
00057       * Construct a private key from the specified parameters.
00058       * @param rng a random number generator
00059       * @param p the first prime
00060       * @param q the second prime
00061       * @param e the exponent
00062       * @param d if specified, this has to be d with
00063       * exp * d = 1 mod (p - 1, q - 1). Leave it as 0 if you wish to
00064       * the constructor to calculate it.
00065       * @param n if specified, this must be n = p * q. Leave it as 0
00066       * if you wish to the constructor to calculate it.
00067       */
00068       RSA_PrivateKey(RandomNumberGenerator& rng,
00069                      const BigInt& p, const BigInt& q,
00070                      const BigInt& e, const BigInt& d = 0,
00071                      const BigInt& n = 0) :
00072          IF_Scheme_PrivateKey(rng, p, q, e, d, n) {}
00073 
00074       /**
00075       * Create a new private key with the specified bit length
00076       * @param rng the random number generator to use
00077       * @param bits the desired bit length of the private key
00078       * @param exp the public exponent to be used
00079       */
00080       RSA_PrivateKey(RandomNumberGenerator& rng,
00081                      size_t bits, size_t exp = 65537);
00082    };
00083 
00084 }
00085 
00086 #endif