Coverage Report

Created: 2026-12-01 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Botan-3.13.0/build/include/public/botan/ecdsa.h
Line
Count
Source
1
/*
2
* ECDSA
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_ECDSA_KEY_H_
11
#define BOTAN_ECDSA_KEY_H_
12
13
#include <botan/ecc_key.h>
14
15
namespace Botan {
16
17
/**
18
* This class represents ECDSA Public Keys.
19
*/
20
class BOTAN_PUBLIC_API(2, 0) ECDSA_PublicKey : public virtual EC_PublicKey {
21
   public:
22
      /**
23
      * Create a public key from a given public point.
24
      * @param group the domain parameters associated with this key
25
      * @param public_key the public point defining this key
26
      */
27
121k
      ECDSA_PublicKey(const EC_Group& group, const EC_AffinePoint& public_key) : EC_PublicKey(group, public_key) {}
28
29
#if defined(BOTAN_HAS_LEGACY_EC_POINT)
30
      /**
31
      * Create a public key from a given public point.
32
      * @param group the domain parameters associated with this key
33
      * @param public_point the public point defining this key
34
      */
35
0
      ECDSA_PublicKey(const EC_Group& group, const EC_Point& public_point) : EC_PublicKey(group, public_point) {}
36
#endif
37
38
      /**
39
      * Load a public key.
40
      * @param alg_id the X.509 algorithm identifier
41
      * @param key_bits DER encoded public key bits
42
      */
43
      ECDSA_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
44
0
            EC_PublicKey(assert_algorithm_identifier(alg_id, "ECDSA"), key_bits) {}
45
46
      /**
47
      * Recover a public key from a signature/msg pair
48
      * See SEC section 4.6.1
49
      * @param group the elliptic curve group
50
      * @param msg the message
51
      * @param r the r parameter of the signature
52
      * @param s the s parameter of the signature
53
      * @param v the recovery ID
54
      */
55
      ECDSA_PublicKey(
56
         const EC_Group& group, const std::vector<uint8_t>& msg, const BigInt& r, const BigInt& s, uint8_t v);
57
58
      /**
59
      * Get this keys algorithm name.
60
      * @result this keys algorithm name ("ECDSA")
61
      */
62
0
      std::string algo_name() const override { return "ECDSA"; }
63
64
      std::optional<size_t> _signature_element_size_for_DER_encoding() const override;
65
66
0
      bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
67
68
      std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const override;
69
70
      uint8_t recovery_param(const std::vector<uint8_t>& msg, const BigInt& r, const BigInt& s) const;
71
72
      std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
73
                                                                   std::string_view provider) const override;
74
75
      std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
76
                                                                        std::string_view provider) const override;
77
78
   protected:
79
0
      ECDSA_PublicKey() = default;
80
};
81
82
/**
83
* This class represents ECDSA Private Keys
84
*/
85
86
BOTAN_DIAGNOSTIC_PUSH
87
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
88
89
class BOTAN_PUBLIC_API(2, 0) ECDSA_PrivateKey final : public ECDSA_PublicKey,
90
                                                      public EC_PrivateKey {
91
   public:
92
      /**
93
      * Load a private key
94
      * @param alg_id the X.509 algorithm identifier
95
      * @param key_bits ECPrivateKey bits
96
      */
97
      ECDSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
98
0
            EC_PrivateKey(assert_algorithm_identifier(alg_id, "ECDSA"), key_bits) {}
99
100
      /**
101
      * Create a private key from a given secret @p x
102
      * @param group curve parameters to bu used for this key
103
      * @param x      the private key
104
      */
105
0
      ECDSA_PrivateKey(const EC_Group& group, const EC_Scalar& x) : EC_PrivateKey(group, x) {}
106
107
      /**
108
      * Create a new private key
109
      * @param rng a random number generator
110
      * @param group parameters to used for this key
111
      */
112
0
      ECDSA_PrivateKey(RandomNumberGenerator& rng, const EC_Group& group) : EC_PrivateKey(rng, group) {}
113
114
      /**
115
      * Create a private key.
116
      * @param rng a random number generator
117
      * @param group parameters to used for this key
118
      * @param x the private key (if zero, generate a new random key)
119
      */
120
      BOTAN_DEPRECATED("Use one of the other constructors")
121
      ECDSA_PrivateKey(RandomNumberGenerator& rng, const EC_Group& group, const BigInt& x) :
122
0
            EC_PrivateKey(rng, group, x) {}
123
124
      bool check_key(RandomNumberGenerator& rng, bool strong) const override;
125
126
      std::unique_ptr<Public_Key> public_key() const override;
127
128
      std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
129
                                                             std::string_view params,
130
                                                             std::string_view provider) const override;
131
};
132
133
BOTAN_DIAGNOSTIC_POP
134
135
}  // namespace Botan
136
137
#endif