Botan 1.10.17
ecdh.h
Go to the documentation of this file.
1/*
2* ECDH
3* (C) 2007 Falko Strenzke, FlexSecure GmbH
4* Manuel Hartl, FlexSecure GmbH
5* (C) 2008-2010 Jack Lloyd
6*
7* Distributed under the terms of the Botan license
8*/
9
10#ifndef BOTAN_ECDH_KEY_H__
11#define BOTAN_ECDH_KEY_H__
12
13#include <botan/ecc_key.h>
14#include <botan/pk_ops.h>
15
16namespace Botan {
17
18/**
19* This class represents ECDH Public Keys.
20*/
21class BOTAN_DLL ECDH_PublicKey : public virtual EC_PublicKey
22 {
23 public:
24
26 const MemoryRegion<byte>& key_bits) :
27 EC_PublicKey(alg_id, key_bits) {}
28
29 /**
30 * Construct a public key from a given public point.
31 * @param dom_par the domain parameters associated with this key
32 * @param public_point the public point defining this key
33 */
34 ECDH_PublicKey(const EC_Group& dom_par,
35 const PointGFp& public_point) :
36 EC_PublicKey(dom_par, public_point) {}
37
38 /**
39 * Get this keys algorithm name.
40 * @return this keys algorithm name
41 */
42 std::string algo_name() const { return "ECDH"; }
43
44 /**
45 * Get the maximum number of bits allowed to be fed to this key.
46 * This is the bitlength of the order of the base point.
47
48 * @return maximum number of input bits
49 */
50 size_t max_input_bits() const { return domain().get_order().bits(); }
51
52 /**
53 * @return public point value
54 */
57
58 protected:
60 };
61
62/**
63* This class represents ECDH Private Keys.
64*/
65class BOTAN_DLL ECDH_PrivateKey : public ECDH_PublicKey,
66 public EC_PrivateKey,
68 {
69 public:
70
72 const MemoryRegion<byte>& key_bits) :
73 EC_PrivateKey(alg_id, key_bits) {}
74
75 /**
76 * Generate a new private key
77 * @param rng a random number generator
78 * @param domain parameters to used for this key
79 * @param x the private key; if zero, a new random key is generated
80 */
82 const EC_Group& domain,
83 const BigInt& x = 0) :
84 EC_PrivateKey(rng, domain, x) {}
85
88 };
89
90/**
91* ECDH operation
92*/
94 {
95 public:
97
98 SecureVector<byte> agree(const byte w[], size_t w_len);
99 private:
100 const CurveGFp& curve;
101 const BigInt& cofactor;
102 BigInt l_times_priv;
103 };
104
105}
106
107#endif
SecureVector< byte > agree(const byte w[], size_t w_len)
Definition ecdh.cpp:23
ECDH_KA_Operation(const ECDH_PrivateKey &key)
Definition ecdh.cpp:15
ECDH_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition ecdh.h:71
ECDH_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &x=0)
Definition ecdh.h:81
MemoryVector< byte > public_value() const
Definition ecdh.h:86
MemoryVector< byte > public_value() const
Definition ecdh.h:55
ECDH_PublicKey(const EC_Group &dom_par, const PointGFp &public_point)
Definition ecdh.h:34
std::string algo_name() const
Definition ecdh.h:42
ECDH_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition ecdh.h:25
size_t max_input_bits() const
Definition ecdh.h:50
EC_PrivateKey(RandomNumberGenerator &rng, const EC_Group &domain, const BigInt &private_key)
Definition ecc_key.cpp:81
const EC_Group & domain() const
Definition ecc_key.h:60
EC_PublicKey(const EC_Group &dom_par, const PointGFp &pub_point)
Definition ecc_key.cpp:21
const PointGFp & public_point() const
Definition ecc_key.h:45
SecureVector< byte > EC2OSP(const PointGFp &point, byte format)