Botan
1.11.4
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
pubkey
ecdh
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
16
namespace
Botan {
17
18
/**
19
* This class represents ECDH Public Keys.
20
*/
21
class
BOTAN_DLL
ECDH_PublicKey
:
public
virtual
EC_PublicKey
22
{
23
public
:
24
25
ECDH_PublicKey
(
const
AlgorithmIdentifier
& alg_id,
26
const
secure_vector<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
*/
55
std::vector<byte>
public_value
()
const
56
{
return
unlock
(
EC2OSP
(public_point(),
PointGFp::UNCOMPRESSED
)); }
57
58
protected
:
59
ECDH_PublicKey
() {}
60
};
61
62
/**
63
* This class represents ECDH Private Keys.
64
*/
65
class
BOTAN_DLL
ECDH_PrivateKey
:
public
ECDH_PublicKey
,
66
public
EC_PrivateKey
,
67
public
PK_Key_Agreement_Key
68
{
69
public
:
70
71
ECDH_PrivateKey
(
const
AlgorithmIdentifier
& alg_id,
72
const
secure_vector<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
*/
81
ECDH_PrivateKey
(
RandomNumberGenerator
&
rng
,
82
const
EC_Group
& domain,
83
const
BigInt
& x = 0) :
84
EC_PrivateKey
(rng, domain, x) {}
85
86
std::vector<byte>
public_value
()
const
87
{
return
ECDH_PublicKey::public_value
(); }
88
};
89
90
/**
91
* ECDH operation
92
*/
93
class
BOTAN_DLL
ECDH_KA_Operation
:
public
PK_Ops::Key_Agreement
94
{
95
public
:
96
ECDH_KA_Operation
(
const
ECDH_PrivateKey
& key);
97
98
secure_vector<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
Generated on Wed Jun 12 2013 21:38:05 for Botan by
1.8.4