Botan  1.10.9
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 
30 
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:
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,
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  */
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
DL_Group::Format group_format() const
Definition: dh.h:29
DH_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: dh.h:31
unsigned char byte
Definition: types.h:22
RandomNumberGenerator * rng
Definition: global_rng.cpp:165
std::string algo_name() const
Definition: dh.h:24
size_t max_input_bits() const
Definition: dh.h:27