Botan  1.11.15
src/lib/pubkey/pk_keys.h
Go to the documentation of this file.
00001 /*
00002 * PK Key Types
00003 * (C) 1999-2007 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_PK_KEYS_H__
00009 #define BOTAN_PK_KEYS_H__
00010 
00011 #include <botan/secmem.h>
00012 #include <botan/asn1_oid.h>
00013 #include <botan/alg_id.h>
00014 #include <botan/rng.h>
00015 
00016 namespace Botan {
00017 
00018 /**
00019 * Public Key Base Class.
00020 */
00021 class BOTAN_DLL Public_Key
00022    {
00023    public:
00024       /**
00025       * Get the name of the underlying public key scheme.
00026       * @return name of the public key scheme
00027       */
00028       virtual std::string algo_name() const = 0;
00029 
00030       /**
00031       * Return the estimated strength of the underlying key against
00032       * the best currently known attack. Note that this ignores anything
00033       * but pure attacks against the key itself and do not take into
00034       * account padding schemes, usage mistakes, etc which might reduce
00035       * the strength. However it does suffice to provide an upper bound.
00036       *
00037       * @return estimated strength in bits
00038       */
00039       virtual size_t estimated_strength() const = 0;
00040 
00041       /**
00042       * Get the OID of the underlying public key scheme.
00043       * @return OID of the public key scheme
00044       */
00045       virtual OID get_oid() const;
00046 
00047       /**
00048       * Test the key values for consistency.
00049       * @param rng rng to use
00050       * @param strong whether to perform strong and lengthy version
00051       * of the test
00052       * @return true if the test is passed
00053       */
00054       virtual bool check_key(RandomNumberGenerator& rng,
00055                              bool strong) const = 0;
00056 
00057       /**
00058       * Find out the number of message parts supported by this scheme.
00059       * @return number of message parts
00060       */
00061       virtual size_t message_parts() const { return 1; }
00062 
00063       /**
00064       * Find out the message part size supported by this scheme/key.
00065       * @return size of the message parts in bits
00066       */
00067       virtual size_t message_part_size() const { return 0; }
00068 
00069       /**
00070       * Get the maximum message size in bits supported by this public key.
00071       * @return maximum message size in bits
00072       */
00073       virtual size_t max_input_bits() const = 0;
00074 
00075       /**
00076       * @return X.509 AlgorithmIdentifier for this key
00077       */
00078       virtual AlgorithmIdentifier algorithm_identifier() const = 0;
00079 
00080       /**
00081       * @return X.509 subject key encoding for this key object
00082       */
00083       virtual std::vector<byte> x509_subject_public_key() const = 0;
00084 
00085       virtual ~Public_Key() {}
00086    protected:
00087       /**
00088       * Self-test after loading a key
00089       * @param rng a random number generator
00090       */
00091       virtual void load_check(RandomNumberGenerator& rng) const;
00092    };
00093 
00094 /**
00095 * Private Key Base Class
00096 */
00097 class BOTAN_DLL Private_Key : public virtual Public_Key
00098    {
00099    public:
00100       /**
00101       * @return PKCS #8 private key encoding for this key object
00102       */
00103       virtual secure_vector<byte> pkcs8_private_key() const = 0;
00104 
00105       /**
00106       * @return PKCS #8 AlgorithmIdentifier for this key
00107       * Might be different from the X.509 identifier, but normally is not
00108       */
00109       virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
00110          { return algorithm_identifier(); }
00111 
00112    protected:
00113       /**
00114       * Self-test after loading a key
00115       * @param rng a random number generator
00116       */
00117       void load_check(RandomNumberGenerator& rng) const;
00118 
00119       /**
00120       * Self-test after generating a key
00121       * @param rng a random number generator
00122       */
00123       void gen_check(RandomNumberGenerator& rng) const;
00124    };
00125 
00126 /**
00127 * PK Secret Value Derivation Key
00128 */
00129 class BOTAN_DLL PK_Key_Agreement_Key : public virtual Private_Key
00130    {
00131    public:
00132       /*
00133       * @return public component of this key
00134       */
00135       virtual std::vector<byte> public_value() const = 0;
00136 
00137       virtual ~PK_Key_Agreement_Key() {}
00138    };
00139 
00140 /*
00141 * Typedefs
00142 */
00143 typedef PK_Key_Agreement_Key PK_KA_Key;
00144 typedef Public_Key X509_PublicKey;
00145 typedef Private_Key PKCS8_PrivateKey;
00146 
00147 }
00148 
00149 #endif