Botan 3.4.0
Crypto and TLS for C&
dsa.h
Go to the documentation of this file.
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
14namespace Botan {
15
16class BigInt;
17class DL_Group;
18class DL_PublicKey;
19class DL_PrivateKey;
20
21/**
22* DSA Public Key
23*/
24class BOTAN_PUBLIC_API(2, 0) DSA_PublicKey : public virtual Public_Key {
25 public:
26 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 std::string algo_name() const override { return "DSA"; }
43
44 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 std::vector<uint8_t> public_key_bits() const override;
50
51 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
52
53 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
54
55 size_t estimated_strength() const override;
56 size_t key_length() const override;
57
58 const BigInt& get_int_field(std::string_view field) const override;
59
60 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
61 std::string_view provider) const override;
62
63 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
64 std::string_view provider) const override;
65
66 private:
67 friend class DSA_PrivateKey;
68
69 DSA_PublicKey() = default;
70
71 DSA_PublicKey(std::shared_ptr<const DL_PublicKey> key) : m_public_key(std::move(key)) {}
72
73 std::shared_ptr<const DL_PublicKey> m_public_key;
74};
75
76/**
77* DSA Private Key
78*/
79
82
84 public virtual Private_Key {
85 public:
86 /**
87 * Load a private key from the ASN.1 encoding
88 * @param alg_id the X.509 algorithm identifier
89 * @param key_bits DER encoded key bits in ANSI X9.57 format
90 */
91 DSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
92
93 /**
94 * Create a new private key.
95 * @param group the underlying DL group
96 * @param rng the RNG to use
97 */
99
100 /**
101 * Load a private key
102 * @param group the underlying DL group
103 * @param private_key the private key
104 */
105 DSA_PrivateKey(const DL_Group& group, const BigInt& private_key);
106
107 std::unique_ptr<Public_Key> public_key() const override;
108
109 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
110
111 secure_vector<uint8_t> private_key_bits() const override;
112
113 const BigInt& get_int_field(std::string_view field) const override;
114 secure_vector<uint8_t> raw_private_key_bits() const override;
115
116 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
117 std::string_view params,
118 std::string_view provider) const override;
119
120 private:
121 std::shared_ptr<const DL_PrivateKey> m_private_key;
122};
123
125
126} // namespace Botan
127
128#endif
size_t message_parts() const override
Definition dsa.h:44
bool supports_operation(PublicKeyOperation op) const override
Definition dsa.h:26
std::string algo_name() const override
Definition dsa.h:42
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition compiler.h:191
#define BOTAN_DIAGNOSTIC_PUSH
Definition compiler.h:188
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition compiler.h:190
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
PublicKeyOperation
Definition pk_keys.h:45
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61