Coverage Report

Created: 2023-02-13 06:21

/src/botan/build/include/botan/dh.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* Diffie-Hellman
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_DIFFIE_HELLMAN_H_
9
#define BOTAN_DIFFIE_HELLMAN_H_
10
11
#include <botan/dl_algo.h>
12
13
namespace Botan {
14
15
/**
16
* This class represents Diffie-Hellman public keys.
17
*/
18
class BOTAN_PUBLIC_API(2,0) DH_PublicKey : public virtual DL_Scheme_PublicKey
19
   {
20
   public:
21
3
      std::string algo_name() const override { return "DH"; }
22
23
      std::vector<uint8_t> public_value() const;
24
25
0
      DL_Group_Format group_format() const override { return DL_Group_Format::ANSI_X9_42; }
26
27
      /**
28
      * Create a public key.
29
      * @param alg_id the X.509 algorithm identifier
30
      * @param key_bits DER encoded public key bits
31
      */
32
      DH_PublicKey(const AlgorithmIdentifier& alg_id,
33
                   const std::vector<uint8_t>& key_bits) :
34
47
         DL_Scheme_PublicKey(alg_id, key_bits, DL_Group_Format::ANSI_X9_42) {}
Botan::DH_PublicKey::DH_PublicKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&)
Line
Count
Source
34
47
         DL_Scheme_PublicKey(alg_id, key_bits, DL_Group_Format::ANSI_X9_42) {}
Unexecuted instantiation: Botan::DH_PublicKey::DH_PublicKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&)
35
36
      /**
37
      * Construct a public key with the specified parameters.
38
      * @param grp the DL group to use in the key
39
      * @param y the public value y
40
      */
41
      DH_PublicKey(const DL_Group& grp, const BigInt& y);
42
   protected:
43
40
      DH_PublicKey() = default;
44
   };
45
46
/**
47
* This class represents Diffie-Hellman private keys.
48
*/
49
class BOTAN_PUBLIC_API(2,0) DH_PrivateKey final : public DH_PublicKey,
50
                                public PK_Key_Agreement_Key,
51
                                public virtual DL_Scheme_PrivateKey
52
   {
53
   public:
54
      std::vector<uint8_t> public_value() const override;
55
56
      /**
57
      * Load a private key.
58
      * @param alg_id the X.509 algorithm identifier
59
      * @param key_bits PKCS #8 structure
60
      */
61
      DH_PrivateKey(const AlgorithmIdentifier& alg_id,
62
                    const secure_vector<uint8_t>& key_bits);
63
64
      /**
65
      * Create a private key.
66
      * @param rng random number generator to use
67
      * @param grp the group to be used in the key
68
      * @param x the key's secret value (or if zero, generate a new key)
69
      */
70
      DH_PrivateKey(RandomNumberGenerator& rng, const DL_Group& grp,
71
                    const BigInt& x = BigInt::zero());
72
73
      std::unique_ptr<Public_Key> public_key() const override;
74
75
      std::unique_ptr<PK_Ops::Key_Agreement>
76
         create_key_agreement_op(RandomNumberGenerator& rng,
77
                                 const std::string& params,
78
                                 const std::string& provider) const override;
79
   };
80
81
}
82
83
#endif