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
16namespace Botan {
17
18/**
19* This class represents Diffie-Hellman public keys.
20*/
21class 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*/
48class BOTAN_DLL DH_PrivateKey : public DH_PublicKey,
50 public virtual DL_Scheme_PrivateKey
51 {
52 public:
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 */
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*/
78class BOTAN_DLL DH_KA_Operation : public PK_Ops::Key_Agreement
79 {
80 public:
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
SecureVector< byte > agree(const byte w[], size_t w_len)
Definition dh.cpp:86
DH_KA_Operation(const DH_PrivateKey &key)
Definition dh.cpp:79
DH_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition dh.cpp:60
MemoryVector< byte > public_value() const
Definition dh.cpp:74
size_t max_input_bits() const
Definition dh.h:27
DH_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition dh.h:31
DL_Group::Format group_format() const
Definition dh.h:29
std::string algo_name() const
Definition dh.h:24
DL_Scheme_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, DL_Group::Format group_format)
Definition dl_algo.cpp:41
const BigInt & group_p() const
Definition dl_algo.h:44
DL_Scheme_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, DL_Group::Format group_format)
Definition dl_algo.cpp:26