Coverage Report

Created: 2023-01-25 06:35

/src/botan/build/include/botan/ecdh.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* ECDH
3
* (C) 2007 Falko Strenzke, FlexSecure GmbH
4
*          Manuel Hartl, FlexSecure GmbH
5
* (C) 2008-2010 Jack Lloyd
6
*
7
* Botan is released under the Simplified BSD License (see license.txt)
8
*/
9
10
#ifndef BOTAN_ECDH_KEY_H_
11
#define BOTAN_ECDH_KEY_H_
12
13
#include <botan/ecc_key.h>
14
15
namespace Botan {
16
17
/**
18
* This class represents ECDH Public Keys.
19
*/
20
class BOTAN_PUBLIC_API(2,0) ECDH_PublicKey : public virtual EC_PublicKey
21
   {
22
   public:
23
      /**
24
      * Create an ECDH public key.
25
      * @param alg_id algorithm identifier
26
      * @param key_bits DER encoded public key bits
27
      */
28
      ECDH_PublicKey(const AlgorithmIdentifier& alg_id,
29
                     const std::vector<uint8_t>& key_bits) :
30
3
         EC_PublicKey(alg_id, key_bits) {}
Botan::ECDH_PublicKey::ECDH_PublicKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&)
Line
Count
Source
30
3
         EC_PublicKey(alg_id, key_bits) {}
Unexecuted instantiation: Botan::ECDH_PublicKey::ECDH_PublicKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&)
31
32
      /**
33
      * Construct a public key from a given public point.
34
      * @param dom_par the domain parameters associated with this key
35
      * @param public_point the public point defining this key
36
      */
37
      ECDH_PublicKey(const EC_Group& dom_par,
38
                     const EC_Point& public_point) :
39
0
         EC_PublicKey(dom_par, public_point) {}
Unexecuted instantiation: Botan::ECDH_PublicKey::ECDH_PublicKey(Botan::EC_Group const&, Botan::EC_Point const&)
Unexecuted instantiation: Botan::ECDH_PublicKey::ECDH_PublicKey(Botan::EC_Group const&, Botan::EC_Point const&)
40
41
      /**
42
      * Get this keys algorithm name.
43
      * @return this keys algorithm name
44
      */
45
22.2k
      std::string algo_name() const override { return "ECDH"; }
46
47
      /**
48
      * @return public point value
49
      */
50
      std::vector<uint8_t> public_value() const
51
0
         { return public_point().encode(EC_Point::UNCOMPRESSED); }
52
53
      /**
54
      * @return public point value
55
      */
56
      std::vector<uint8_t> public_value(EC_Point::Compression_Type format) const
57
25.3k
         { return public_point().encode(format); }
58
59
   protected:
60
20.7k
      ECDH_PublicKey() = default;
61
   };
62
63
/**
64
* This class represents ECDH Private Keys.
65
*/
66
class BOTAN_PUBLIC_API(2,0) ECDH_PrivateKey final : public ECDH_PublicKey,
67
                                  public EC_PrivateKey,
68
                                  public PK_Key_Agreement_Key
69
   {
70
   public:
71
72
      /**
73
      * Load a private key.
74
      * @param alg_id the X.509 algorithm identifier
75
      * @param key_bits ECPrivateKey bits
76
      */
77
      ECDH_PrivateKey(const AlgorithmIdentifier& alg_id,
78
                      const secure_vector<uint8_t>& key_bits) :
79
1.85k
         EC_PrivateKey(alg_id, key_bits) {}
Botan::ECDH_PrivateKey::ECDH_PrivateKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, Botan::secure_allocator<unsigned char> > const&)
Line
Count
Source
79
1.85k
         EC_PrivateKey(alg_id, key_bits) {}
Unexecuted instantiation: Botan::ECDH_PrivateKey::ECDH_PrivateKey(Botan::AlgorithmIdentifier const&, std::__1::vector<unsigned char, Botan::secure_allocator<unsigned char> > const&)
80
81
      /**
82
      * Generate a new private key
83
      * @param rng a random number generator
84
      * @param domain parameters to used for this key
85
      * @param x the private key; if zero, a new random key is generated
86
      */
87
      ECDH_PrivateKey(RandomNumberGenerator& rng,
88
                      const EC_Group& domain,
89
                      const BigInt& x = BigInt::zero()) :
90
18.9k
         EC_PrivateKey(rng, domain, x) {}
Botan::ECDH_PrivateKey::ECDH_PrivateKey(Botan::RandomNumberGenerator&, Botan::EC_Group const&, Botan::BigInt const&)
Line
Count
Source
90
18.9k
         EC_PrivateKey(rng, domain, x) {}
Unexecuted instantiation: Botan::ECDH_PrivateKey::ECDH_PrivateKey(Botan::RandomNumberGenerator&, Botan::EC_Group const&, Botan::BigInt const&)
91
92
      std::unique_ptr<Public_Key> public_key() const override;
93
94
      std::vector<uint8_t> public_value() const override
95
6.38k
         { return ECDH_PublicKey::public_value(EC_Point::UNCOMPRESSED); }
96
97
      std::vector<uint8_t> public_value(EC_Point::Compression_Type type) const
98
18.9k
         { return ECDH_PublicKey::public_value(type); }
99
100
      std::unique_ptr<PK_Ops::Key_Agreement>
101
         create_key_agreement_op(RandomNumberGenerator& rng,
102
                                 const std::string& params,
103
                                 const std::string& provider) const override;
104
   };
105
106
}
107
108
#endif