Botan: src/pubkey/dh/dh.h Source File

Botan 1.10.17

dh.h
Go to the documentation of this file.
1 /*
2 * Diffie-Hellman
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_DIFFIE_HELLMAN_H__
9 #define BOTAN_DIFFIE_HELLMAN_H__
10
11 #include <botan/dl_algo.h>
12 #include <botan/pow_mod.h>
13 #include <botan/blinding.h>
14 #include <botan/pk_ops.h>
15
16 namespace Botan {
17
18 /**
19 * This class represents Diffie-Hellman public keys.
20 */
21 class BOTAN_DLL DH_PublicKey : public virtual DL_Scheme_PublicKey
22 {
23 public:
24 std::string algo_name() const { return "DH"; }
25
26 MemoryVector<byte> public_value() const;
27 size_t max_input_bits() const { return group_p().bits(); }
28
29 DL_Group::Format group_format() const { return DL_Group::ANSI_X9_42; }
30
31 DH_PublicKey(const AlgorithmIdentifier& alg_id,
32 const MemoryRegion<byte>& key_bits) :
33 DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_42) {}
34
35 /**
36 * Construct a public key with the specified parameters.
37 * @param grp the DL group to use in the key
38 * @param y the public value y
39 */
40 DH_PublicKey(const DL_Group& grp, const BigInt& y);
41 protected:
42 DH_PublicKey() {}
43 };
44
45 /**
46 * This class represents Diffie-Hellman private keys.
47 */
48 class BOTAN_DLL DH_PrivateKey : public DH_PublicKey,
49 public PK_Key_Agreement_Key,
50 public virtual DL_Scheme_PrivateKey
51 {
52 public:
53 MemoryVector<byte> public_value() const;
54
55 /**
56 * Load a DH private key
57 * @param alg_id the algorithm id
58 * @param key_bits the subject public key
59 * @param rng a random number generator
60 */
61 DH_PrivateKey(const AlgorithmIdentifier& alg_id,
62 const MemoryRegion<byte>& key_bits,
63 RandomNumberGenerator& rng);
64
65 /**
66 * Construct a private key with predetermined value.
67 * @param rng random number generator to use
68 * @param grp the group to be used in the key
69 * @param x the key's secret value (or if zero, generate a new key)
70 */
71 DH_PrivateKey(RandomNumberGenerator& rng, const DL_Group& grp,
72 const BigInt& x = 0);
73 };
74
75 /**
76 * DH operation
77 */
78 class BOTAN_DLL DH_KA_Operation : public PK_Ops::Key_Agreement
79 {
80 public:
81 DH_KA_Operation(const DH_PrivateKey& key);
82
83 SecureVector<byte> agree(const byte w[], size_t w_len);
84 private:
85 const BigInt& p;
86
87 Fixed_Exponent_Power_Mod powermod_x_p;
88 Blinder blinder;
89 };
90
91 }
92
93 #endif
Botan::DL_Scheme_PrivateKey
Definition: dl_algo.h:85
Botan::DH_PublicKey::DH_PublicKey
DH_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: dh.h:31
Botan::BigInt
Definition: bigint.h:22
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::DL_Scheme_PublicKey
Definition: dl_algo.h:20
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::DH_PublicKey::group_format
DL_Group::Format group_format() const
Definition: dh.h:29
Botan::DH_PublicKey::max_input_bits
size_t max_input_bits() const
Definition: dh.h:27
Botan::DL_Group
Definition: dl_group.h:20
Botan::DL_Group::Format
Format
Definition: dl_group.h:44
Botan::DH_KA_Operation
Definition: dh.h:78
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::DL_Group::ANSI_X9_42
Definition: dl_group.h:45
Botan::MemoryVector< byte >
Botan::PK_Ops::Key_Agreement
Definition: pk_ops.h:145
Botan::DH_PublicKey
Definition: dh.h:21
Botan::Blinder
Definition: blinding.h:19
Botan::DH_PublicKey::DH_PublicKey
DH_PublicKey()
Definition: dh.h:42
Botan::PK_Key_Agreement_Key
Definition: pk_keys.h:118
Botan::DH_PublicKey::algo_name
std::string algo_name() const
Definition: dh.h:24
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::Fixed_Exponent_Power_Mod
Definition: pow_mod.h:73
Botan::SecureVector< byte >
Botan::DH_PrivateKey
Definition: dh.h:48