Coverage Report

Created: 2026-02-14 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/botan/build/include/public/botan/ecgdsa.h
Line
Count
Source
1
/*
2
* ECGDSA (BSI-TR-03111, version 2.0)
3
* (C) 2016 René Korthaus
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_ECGDSA_KEY_H_
9
#define BOTAN_ECGDSA_KEY_H_
10
11
#include <botan/ecc_key.h>
12
13
namespace Botan {
14
15
/**
16
* This class represents ECGDSA public keys.
17
*/
18
class BOTAN_PUBLIC_API(2, 0) ECGDSA_PublicKey : public virtual EC_PublicKey {
19
   public:
20
      /**
21
      * Construct a public key from a given public point.
22
      * @param group the domain parameters associated with this key
23
      * @param public_key the public point defining this key
24
      */
25
0
      ECGDSA_PublicKey(const EC_Group& group, const EC_AffinePoint& public_key) : EC_PublicKey(group, public_key) {}
26
27
#if defined(BOTAN_HAS_LEGACY_EC_POINT)
28
      /**
29
      * Construct a public key from a given public point.
30
      * @param group the domain parameters associated with this key
31
      * @param public_point the public point defining this key
32
      */
33
0
      ECGDSA_PublicKey(const EC_Group& group, const EC_Point& public_point) : EC_PublicKey(group, public_point) {}
34
#endif
35
36
      /**
37
      * Load a public key.
38
      * @param alg_id the X.509 algorithm identifier
39
      * @param key_bits DER encoded public key bits
40
      */
41
      ECGDSA_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
42
0
            EC_PublicKey(alg_id, key_bits) {}
43
44
      /**
45
      * Get this keys algorithm name.
46
      * @result this keys algorithm name ("ECGDSA")
47
      */
48
0
      std::string algo_name() const override { return "ECGDSA"; }
49
50
0
      std::optional<size_t> _signature_element_size_for_DER_encoding() const override {
51
0
         return domain().get_order_bytes();
52
0
      }
53
54
      std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
55
56
0
      bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
57
58
      std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
59
                                                                   std::string_view provider) const override;
60
61
      std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
62
                                                                        std::string_view provider) const override;
63
64
   protected:
65
0
      ECGDSA_PublicKey() = default;
66
};
67
68
/**
69
* This class represents ECGDSA private keys.
70
*/
71
72
BOTAN_DIAGNOSTIC_PUSH
73
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
74
75
class BOTAN_PUBLIC_API(2, 0) ECGDSA_PrivateKey final : public ECGDSA_PublicKey,
76
                                                       public EC_PrivateKey {
77
   public:
78
      /**
79
      * Load a private key.
80
      * @param alg_id the X.509 algorithm identifier
81
      * @param key_bits ECPrivateKey bits
82
      */
83
      ECGDSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
84
0
            EC_PrivateKey(alg_id, key_bits, true) {}
85
86
      /**
87
      * Create a private key from a given secret @p x
88
      * @param group curve parameters to bu used for this key
89
      * @param x      the private key
90
      */
91
0
      ECGDSA_PrivateKey(EC_Group group, EC_Scalar x) : EC_PrivateKey(std::move(group), std::move(x), true) {}
92
93
      /**
94
      * Create a new private key
95
      * @param rng a random number generator
96
      * @param group parameters to used for this key
97
      */
98
0
      ECGDSA_PrivateKey(RandomNumberGenerator& rng, EC_Group group) : EC_PrivateKey(rng, std::move(group), true) {}
99
100
      /**
101
      * Generate a new private key.
102
      * @param rng a random number generator
103
      * @param group parameters to used for this key
104
      * @param x the private key (if zero, generate a new random key)
105
      */
106
      BOTAN_DEPRECATED("Use one of the other constructors")
107
      ECGDSA_PrivateKey(RandomNumberGenerator& rng, const EC_Group& group, const BigInt& x) :
108
0
            EC_PrivateKey(rng, group, x, true) {}
109
110
      std::unique_ptr<Public_Key> public_key() const override;
111
112
      bool check_key(RandomNumberGenerator& rng, bool strong) const override;
113
114
      std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
115
                                                             std::string_view params,
116
                                                             std::string_view provider) const override;
117
};
118
119
BOTAN_DIAGNOSTIC_POP
120
121
}  // namespace Botan
122
123
#endif