Coverage Report

Created: 2025-07-11 06:15

/src/Botan-3.4.0/build/include/public/botan/ecdsa.h
Line
Count
Source (jump to first uncovered line)
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 dom_par the domain parameters associated with this key
25
      * @param public_point the public point defining this key
26
      */
27
58.2k
      ECDSA_PublicKey(const EC_Group& dom_par, const EC_Point& public_point) : EC_PublicKey(dom_par, public_point) {}
28
29
      /**
30
      * Load a public key.
31
      * @param alg_id the X.509 algorithm identifier
32
      * @param key_bits DER encoded public key bits
33
      */
34
      ECDSA_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
35
0
            EC_PublicKey(alg_id, key_bits) {}
36
37
      /**
38
      * Recover a public key from a signature/msg pair
39
      * See SEC section 4.6.1
40
      * @param group the elliptic curve group
41
      * @param msg the message
42
      * @param r the r paramter of the signature
43
      * @param s the s paramter of the signature
44
      * @param v the recovery ID
45
      */
46
      ECDSA_PublicKey(
47
         const EC_Group& group, const std::vector<uint8_t>& msg, const BigInt& r, const BigInt& s, uint8_t v);
48
49
      /**
50
      * Get this keys algorithm name.
51
      * @result this keys algorithm name ("ECDSA")
52
      */
53
0
      std::string algo_name() const override { return "ECDSA"; }
54
55
58.2k
      size_t message_parts() const override { return 2; }
56
57
58.2k
      size_t message_part_size() const override { return domain().get_order().bytes(); }
58
59
0
      bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
60
61
      std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const override;
62
63
      uint8_t recovery_param(const std::vector<uint8_t>& msg, const BigInt& r, const BigInt& s) const;
64
65
      std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
66
                                                                   std::string_view provider) const override;
67
68
      std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
69
                                                                        std::string_view provider) const override;
70
71
   protected:
72
0
      ECDSA_PublicKey() = default;
73
};
74
75
/**
76
* This class represents ECDSA Private Keys
77
*/
78
79
BOTAN_DIAGNOSTIC_PUSH
80
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
81
82
class BOTAN_PUBLIC_API(2, 0) ECDSA_PrivateKey final : public ECDSA_PublicKey,
83
                                                      public EC_PrivateKey {
84
   public:
85
      /**
86
      * Load a private key
87
      * @param alg_id the X.509 algorithm identifier
88
      * @param key_bits ECPrivateKey bits
89
      */
90
      ECDSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) :
91
0
            EC_PrivateKey(alg_id, key_bits) {}
92
93
      /**
94
      * Create a private key.
95
      * @param rng a random number generator
96
      * @param domain parameters to used for this key
97
      * @param x the private key (if zero, generate a new random key)
98
      */
99
      ECDSA_PrivateKey(RandomNumberGenerator& rng, const EC_Group& domain, const BigInt& x = BigInt::zero()) :
100
0
            EC_PrivateKey(rng, domain, x) {}
101
102
      bool check_key(RandomNumberGenerator& rng, bool) const override;
103
104
      std::unique_ptr<Public_Key> public_key() const override;
105
106
      std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
107
                                                             std::string_view params,
108
                                                             std::string_view provider) const override;
109
};
110
111
BOTAN_DIAGNOSTIC_POP
112
113
}  // namespace Botan
114
115
#endif