Botan 3.0.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 {
26 public:
27 bool supports_operation(PublicKeyOperation op) const override
28 {
29 return (op == PublicKeyOperation::Signature);
30 }
31
32 /**
33 * Load a public key from the ASN.1 encoding
34 * @param alg_id the X.509 algorithm identifier
35 * @param key_bits DER encoded public key bits
36 */
38 std::span<const uint8_t> key_bits);
39
40 /**
41 * Load a public key from the integer value
42 * @param group the underlying DL group
43 * @param y the public value y = g^x mod p
44 */
45 DSA_PublicKey(const DL_Group& group, const BigInt& y);
46
47 std::string algo_name() const override { return "DSA"; }
48
49 size_t message_parts() const override { return 2; }
50 size_t message_part_size() const override;
51
52 AlgorithmIdentifier algorithm_identifier() const override;
53 std::vector<uint8_t> public_key_bits() const override;
54
55 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
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>
63 create_verification_op(std::string_view params,
64 std::string_view provider) const override;
65
66 std::unique_ptr<PK_Ops::Verification>
67 create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
68 std::string_view provider) const override;
69 private:
70 friend class DSA_PrivateKey;
71
72 DSA_PublicKey() = default;
73
74 DSA_PublicKey(std::shared_ptr<const DL_PublicKey> key) :
75 m_public_key(key) {}
76
77 std::shared_ptr<const DL_PublicKey> m_public_key;
78 };
79
80/**
81* DSA Private Key
82*/
83
86
88 public DSA_PublicKey,
89 public virtual Private_Key
90 {
91 public:
92 /**
93 * Load a private key from the ASN.1 encoding
94 * @param alg_id the X.509 algorithm identifier
95 * @param key_bits DER encoded key bits in ANSI X9.57 format
96 */
98 std::span<const uint8_t> key_bits);
99
100 /**
101 * Create a new private key.
102 * @param group the underlying DL group
103 * @param rng the RNG to use
104 */
106 const DL_Group& group);
107
108 /**
109 * Load a private key
110 * @param group the underlying DL group
111 * @param private_key the private key
112 */
113 DSA_PrivateKey(const DL_Group& group,
114 const BigInt& private_key);
115
116 std::unique_ptr<Public_Key> public_key() const override;
117
118 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
119
120 secure_vector<uint8_t> private_key_bits() const override;
121
122 const BigInt& get_int_field(std::string_view field) const override;
123 secure_vector<uint8_t> raw_private_key_bits() const override;
124
125 std::unique_ptr<PK_Ops::Signature>
126 create_signature_op(RandomNumberGenerator& rng,
127 std::string_view params,
128 std::string_view provider) const override;
129 private:
130 std::shared_ptr<const DL_PrivateKey> m_private_key;
131 };
132
134
135}
136
137#endif
static SIMD_4x64 y
size_t message_parts() const override
Definition: dsa.h:49
bool supports_operation(PublicKeyOperation op) const override
Definition: dsa.h:27
std::string algo_name() const override
Definition: dsa.h:47
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition: compiler.h:204
#define BOTAN_DIAGNOSTIC_PUSH
Definition: compiler.h:201
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition: compiler.h:203
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:12
PublicKeyOperation
Definition: pk_keys.h:43
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64