Botan  1.11.15
src/lib/pubkey/dh/dh.h
Go to the documentation of this file.
00001 /*
00002 * Diffie-Hellman
00003 * (C) 1999-2007 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_DIFFIE_HELLMAN_H__
00009 #define BOTAN_DIFFIE_HELLMAN_H__
00010 
00011 #include <botan/dl_algo.h>
00012 
00013 namespace Botan {
00014 
00015 /**
00016 * This class represents Diffie-Hellman public keys.
00017 */
00018 class BOTAN_DLL DH_PublicKey : public virtual DL_Scheme_PublicKey
00019    {
00020    public:
00021       std::string algo_name() const { return "DH"; }
00022 
00023       std::vector<byte> public_value() const;
00024       size_t max_input_bits() const { return group_p().bits(); }
00025 
00026       DL_Group::Format group_format() const { return DL_Group::ANSI_X9_42; }
00027 
00028       DH_PublicKey(const AlgorithmIdentifier& alg_id,
00029                    const secure_vector<byte>& key_bits) :
00030          DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_42) {}
00031 
00032       /**
00033       * Construct a public key with the specified parameters.
00034       * @param grp the DL group to use in the key
00035       * @param y the public value y
00036       */
00037       DH_PublicKey(const DL_Group& grp, const BigInt& y);
00038    protected:
00039       DH_PublicKey() {}
00040    };
00041 
00042 /**
00043 * This class represents Diffie-Hellman private keys.
00044 */
00045 class BOTAN_DLL DH_PrivateKey : public DH_PublicKey,
00046                                 public PK_Key_Agreement_Key,
00047                                 public virtual DL_Scheme_PrivateKey
00048    {
00049    public:
00050       std::vector<byte> public_value() const;
00051 
00052       /**
00053       * Load a DH private key
00054       * @param alg_id the algorithm id
00055       * @param key_bits the subject public key
00056       * @param rng a random number generator
00057       */
00058       DH_PrivateKey(const AlgorithmIdentifier& alg_id,
00059                     const secure_vector<byte>& key_bits,
00060                     RandomNumberGenerator& rng);
00061 
00062       /**
00063       * Construct a private key with predetermined value.
00064       * @param rng random number generator to use
00065       * @param grp the group to be used in the key
00066       * @param x the key's secret value (or if zero, generate a new key)
00067       */
00068       DH_PrivateKey(RandomNumberGenerator& rng, const DL_Group& grp,
00069                     const BigInt& x = 0);
00070    };
00071 
00072 }
00073 
00074 #endif