Coverage Report

Created: 2024-11-29 06:10

/src/botan/build/include/public/botan/dsa.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* DSA
3
* (C) 1999-2010,2023 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_DSA_H_
9
#define BOTAN_DSA_H_
10
11
#include <botan/pk_keys.h>
12
#include <memory>
13
14
namespace Botan {
15
16
class BigInt;
17
class DL_Group;
18
class DL_PublicKey;
19
class DL_PrivateKey;
20
21
/**
22
* DSA Public Key
23
*/
24
class BOTAN_PUBLIC_API(2, 0) DSA_PublicKey : public virtual Public_Key {
25
   public:
26
0
      bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
27
28
      /**
29
      * Load a public key from the ASN.1 encoding
30
      * @param alg_id the X.509 algorithm identifier
31
      * @param key_bits DER encoded public key bits
32
      */
33
      DSA_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
34
35
      /**
36
      * Load a public key from the integer value
37
      * @param group the underlying DL group
38
      * @param y the public value y = g^x mod p
39
      */
40
      DSA_PublicKey(const DL_Group& group, const BigInt& y);
41
42
0
      std::string algo_name() const override { return "DSA"; }
43
44
0
      size_t message_parts() const override { return 2; }
45
46
      size_t message_part_size() const override;
47
48
      AlgorithmIdentifier algorithm_identifier() const override;
49
50
      std::vector<uint8_t> raw_public_key_bits() const override;
51
      std::vector<uint8_t> public_key_bits() const override;
52
53
      bool check_key(RandomNumberGenerator& rng, bool strong) const override;
54
55
      std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
56
57
      size_t estimated_strength() const override;
58
      size_t key_length() const override;
59
60
      const BigInt& get_int_field(std::string_view field) const override;
61
62
      std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
63
                                                                   std::string_view provider) const override;
64
65
      std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
66
                                                                        std::string_view provider) const override;
67
68
   private:
69
      friend class DSA_PrivateKey;
70
71
192
      DSA_PublicKey() = default;
72
73
0
      DSA_PublicKey(std::shared_ptr<const DL_PublicKey> key) : m_public_key(std::move(key)) {}
74
75
      std::shared_ptr<const DL_PublicKey> m_public_key;
76
};
77
78
/**
79
* DSA Private Key
80
*/
81
82
BOTAN_DIAGNOSTIC_PUSH
83
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
84
85
class BOTAN_PUBLIC_API(2, 0) DSA_PrivateKey final : public DSA_PublicKey,
86
                                                    public virtual Private_Key {
87
   public:
88
      /**
89
      * Load a private key from the ASN.1 encoding
90
      * @param alg_id the X.509 algorithm identifier
91
      * @param key_bits DER encoded key bits in ANSI X9.57 format
92
      */
93
      DSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
94
95
      /**
96
      * Create a new private key.
97
      * @param group the underlying DL group
98
      * @param rng the RNG to use
99
      */
100
      DSA_PrivateKey(RandomNumberGenerator& rng, const DL_Group& group);
101
102
      /**
103
      * Load a private key
104
      * @param group the underlying DL group
105
      * @param private_key the private key
106
      */
107
      DSA_PrivateKey(const DL_Group& group, const BigInt& private_key);
108
109
      std::unique_ptr<Public_Key> public_key() const override;
110
111
      bool check_key(RandomNumberGenerator& rng, bool strong) const override;
112
113
      secure_vector<uint8_t> private_key_bits() const override;
114
115
      const BigInt& get_int_field(std::string_view field) const override;
116
      secure_vector<uint8_t> raw_private_key_bits() const override;
117
118
      std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
119
                                                             std::string_view params,
120
                                                             std::string_view provider) const override;
121
122
   private:
123
      std::shared_ptr<const DL_PrivateKey> m_private_key;
124
};
125
126
BOTAN_DIAGNOSTIC_POP
127
128
}  // namespace Botan
129
130
#endif