Botan  1.11.15
src/lib/pubkey/ecdh/ecdh.h
Go to the documentation of this file.
00001 /*
00002 * ECDH
00003 * (C) 2007 Falko Strenzke, FlexSecure GmbH
00004 *          Manuel Hartl, FlexSecure GmbH
00005 * (C) 2008-2010 Jack Lloyd
00006 *
00007 * Botan is released under the Simplified BSD License (see license.txt)
00008 */
00009 
00010 #ifndef BOTAN_ECDH_KEY_H__
00011 #define BOTAN_ECDH_KEY_H__
00012 
00013 #include <botan/ecc_key.h>
00014 
00015 namespace Botan {
00016 
00017 /**
00018 * This class represents ECDH Public Keys.
00019 */
00020 class BOTAN_DLL ECDH_PublicKey : public virtual EC_PublicKey
00021    {
00022    public:
00023 
00024       ECDH_PublicKey(const AlgorithmIdentifier& alg_id,
00025                      const secure_vector<byte>& key_bits) :
00026          EC_PublicKey(alg_id, key_bits) {}
00027 
00028       /**
00029       * Construct a public key from a given public point.
00030       * @param dom_par the domain parameters associated with this key
00031       * @param public_point the public point defining this key
00032       */
00033       ECDH_PublicKey(const EC_Group& dom_par,
00034                      const PointGFp& public_point) :
00035          EC_PublicKey(dom_par, public_point) {}
00036 
00037       /**
00038       * Get this keys algorithm name.
00039       * @return this keys algorithm name
00040       */
00041       std::string algo_name() const { return "ECDH"; }
00042 
00043       /**
00044       * Get the maximum number of bits allowed to be fed to this key.
00045       * This is the bitlength of the order of the base point.
00046 
00047       * @return maximum number of input bits
00048       */
00049       size_t max_input_bits() const { return domain().get_order().bits(); }
00050 
00051       /**
00052       * @return public point value
00053       */
00054       std::vector<byte> public_value() const
00055          { return unlock(EC2OSP(public_point(), PointGFp::UNCOMPRESSED)); }
00056 
00057    protected:
00058       ECDH_PublicKey() {}
00059    };
00060 
00061 /**
00062 * This class represents ECDH Private Keys.
00063 */
00064 class BOTAN_DLL ECDH_PrivateKey : public ECDH_PublicKey,
00065                                   public EC_PrivateKey,
00066                                   public PK_Key_Agreement_Key
00067    {
00068    public:
00069 
00070       ECDH_PrivateKey(const AlgorithmIdentifier& alg_id,
00071                       const secure_vector<byte>& key_bits) :
00072          EC_PrivateKey(alg_id, key_bits) {}
00073 
00074       /**
00075       * Generate a new private key
00076       * @param rng a random number generator
00077       * @param domain parameters to used for this key
00078       * @param x the private key; if zero, a new random key is generated
00079       */
00080       ECDH_PrivateKey(RandomNumberGenerator& rng,
00081                       const EC_Group& domain,
00082                       const BigInt& x = 0) :
00083          EC_PrivateKey(rng, domain, x) {}
00084 
00085       std::vector<byte> public_value() const
00086          { return ECDH_PublicKey::public_value(); }
00087    };
00088 
00089 }
00090 
00091 #endif