Coverage Report

Created: 2026-09-14 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/botan/build/include/public/botan/dsa.h
Line
Count
Source
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
BOTAN_DEPRECATED_HEADER("dsa.h")
15
16
namespace Botan {
17
18
class BigInt;
19
class DL_Group;
20
class DL_PublicKey;
21
class DL_PrivateKey;
22
23
/**
24
* DSA Public Key
25
*/
26
class BOTAN_PUBLIC_API(2, 0) DSA_PublicKey : public virtual Public_Key {
27
   public:
28
0
      bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::Signature); }
29
30
      /**
31
      * Load a public key from the ASN.1 encoding
32
      * @param alg_id the X.509 algorithm identifier
33
      * @param key_bits DER encoded public key bits
34
      */
35
      DSA_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
36
37
      /**
38
      * Load a public key from the integer value
39
      * @param group the underlying DL group
40
      * @param y the public value y = g^x mod p
41
      */
42
      DSA_PublicKey(const DL_Group& group, const BigInt& y);
43
44
0
      std::string algo_name() const override { return "DSA"; }
45
46
      std::optional<size_t> _signature_element_size_for_DER_encoding() 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(const PK_Signature_Options& options) const override;
63
64
      std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
65
                                                                        std::string_view provider) const override;
66
67
   private:
68
      friend class DSA_PrivateKey;
69
70
11
      DSA_PublicKey() = default;
71
72
0
      explicit DSA_PublicKey(std::shared_ptr<const DL_PublicKey> key) : m_public_key(std::move(key)) {}
73
74
      std::shared_ptr<const DL_PublicKey> m_public_key;
75
};
76
77
/**
78
* DSA Private Key
79
*/
80
81
BOTAN_DIAGNOSTIC_PUSH
82
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
83
84
class BOTAN_PUBLIC_API(2, 0) DSA_PrivateKey final : public DSA_PublicKey,
85
                                                    public virtual Private_Key {
86
   public:
87
      /**
88
      * Load a private key from the ASN.1 encoding
89
      * @param alg_id the X.509 algorithm identifier
90
      * @param key_bits DER encoded key bits in ANSI X9.57 format
91
      */
92
      DSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
93
94
      /**
95
      * Create a new private key.
96
      * @param group the underlying DL group
97
      * @param rng the RNG to use
98
      */
99
      DSA_PrivateKey(RandomNumberGenerator& rng, const DL_Group& group);
100
101
      /**
102
      * Load a private key
103
      * @param group the underlying DL group
104
      * @param private_key the private key
105
      */
106
      DSA_PrivateKey(const DL_Group& group, const BigInt& private_key);
107
108
      std::unique_ptr<Public_Key> public_key() const override;
109
110
      bool check_key(RandomNumberGenerator& rng, bool strong) const override;
111
112
      secure_vector<uint8_t> private_key_bits() const override;
113
114
      const BigInt& get_int_field(std::string_view field) const override;
115
      secure_vector<uint8_t> raw_private_key_bits() const override;
116
117
      std::unique_ptr<PK_Ops::Signature> _create_signature_op(RandomNumberGenerator& rng,
118
                                                              const PK_Signature_Options& options) const override;
119
120
   private:
121
      std::shared_ptr<const DL_PrivateKey> m_private_key;
122
};
123
124
BOTAN_DIAGNOSTIC_POP
125
126
}  // namespace Botan
127
128
#endif