Botan: src/pubkey/dsa/dsa.h Source File

Botan 1.10.16

dsa.h
Go to the documentation of this file.
1 /*
2 * DSA
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_DSA_H__
9 #define BOTAN_DSA_H__
10
11 #include <botan/dl_algo.h>
12 #include <botan/pk_ops.h>
13 #include <botan/reducer.h>
14 #include <botan/pow_mod.h>
15
16 namespace Botan {
17
18 /**
19 * DSA Public Key
20 */
21 class BOTAN_DLL DSA_PublicKey : public virtual DL_Scheme_PublicKey
22 {
23 public:
24 std::string algo_name() const { return "DSA"; }
25
26 DL_Group::Format group_format() const { return DL_Group::ANSI_X9_57; }
27 size_t message_parts() const { return 2; }
28 size_t message_part_size() const { return group_q().bytes(); }
29 size_t max_input_bits() const { return group_q().bits(); }
30
31 DSA_PublicKey(const AlgorithmIdentifier& alg_id,
32 const MemoryRegion<byte>& key_bits) :
33 DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_57)
34 {
35 }
36
37 DSA_PublicKey(const DL_Group& group, const BigInt& y);
38 protected:
39 DSA_PublicKey() {}
40 };
41
42 /**
43 * DSA Private Key
44 */
45 class BOTAN_DLL DSA_PrivateKey : public DSA_PublicKey,
46 public virtual DL_Scheme_PrivateKey
47 {
48 public:
49 DSA_PrivateKey(const AlgorithmIdentifier& alg_id,
50 const MemoryRegion<byte>& key_bits,
51 RandomNumberGenerator& rng);
52
53 DSA_PrivateKey(RandomNumberGenerator& rng,
54 const DL_Group& group,
55 const BigInt& private_key = 0);
56
57 bool check_key(RandomNumberGenerator& rng, bool strong) const;
58 };
59
60 /**
61 * Object that can create a DSA signature
62 */
63 class BOTAN_DLL DSA_Signature_Operation : public PK_Ops::Signature
64 {
65 public:
66 DSA_Signature_Operation(const DSA_PrivateKey& dsa);
67
68 size_t message_parts() const { return 2; }
69 size_t message_part_size() const { return q.bytes(); }
70 size_t max_input_bits() const { return q.bits(); }
71
72 SecureVector<byte> sign(const byte msg[], size_t msg_len,
73 RandomNumberGenerator& rng);
74 private:
75 const BigInt& q;
76 const BigInt& x;
77 Fixed_Base_Power_Mod powermod_g_p;
78 Modular_Reducer mod_q;
79 };
80
81 /**
82 * Object that can verify a DSA signature
83 */
84 class BOTAN_DLL DSA_Verification_Operation : public PK_Ops::Verification
85 {
86 public:
87 DSA_Verification_Operation(const DSA_PublicKey& dsa);
88
89 size_t message_parts() const { return 2; }
90 size_t message_part_size() const { return q.bytes(); }
91 size_t max_input_bits() const { return q.bits(); }
92
93 bool with_recovery() const { return false; }
94
95 bool verify(const byte msg[], size_t msg_len,
96 const byte sig[], size_t sig_len);
97 private:
98 const BigInt& q;
99 const BigInt& y;
100
101 Fixed_Base_Power_Mod powermod_g_p, powermod_y_p;
102 Modular_Reducer mod_p, mod_q;
103 };
104
105 }
106
107 #endif
Botan::DL_Scheme_PrivateKey
Definition: dl_algo.h:85
Botan::DSA_PublicKey::algo_name
std::string algo_name() const
Definition: dsa.h:24
Botan::DSA_Signature_Operation::message_parts
size_t message_parts() const
Definition: dsa.h:68
Botan::DSA_PublicKey::DSA_PublicKey
DSA_PublicKey()
Definition: dsa.h:39
Botan::Fixed_Base_Power_Mod
Definition: pow_mod.h:87
Botan::BigInt
Definition: bigint.h:22
Botan::DSA_Signature_Operation
Definition: dsa.h:63
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::DL_Group::ANSI_X9_57
Definition: dl_group.h:46
Botan::DL_Scheme_PublicKey
Definition: dl_algo.h:20
Botan::PK_Ops::Signature
Definition: pk_ops.h:49
Botan::DSA_PublicKey::message_part_size
size_t message_part_size() const
Definition: dsa.h:28
Botan::DSA_Verification_Operation::with_recovery
bool with_recovery() const
Definition: dsa.h:93
Botan::DSA_Signature_Operation::max_input_bits
size_t max_input_bits() const
Definition: dsa.h:70
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::DSA_Verification_Operation::max_input_bits
size_t max_input_bits() const
Definition: dsa.h:91
Botan::DL_Group
Definition: dl_group.h:20
Botan::DL_Group::Format
Format
Definition: dl_group.h:44
Botan::DSA_Signature_Operation::message_part_size
size_t message_part_size() const
Definition: dsa.h:69
Botan::DSA_Verification_Operation
Definition: dsa.h:84
Botan::DSA_Verification_Operation::message_parts
size_t message_parts() const
Definition: dsa.h:89
Botan::DSA_PrivateKey
Definition: dsa.h:45
Botan::DSA_PublicKey::message_parts
size_t message_parts() const
Definition: dsa.h:27
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::DSA_PublicKey::DSA_PublicKey
DSA_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: dsa.h:31
Botan::DSA_PublicKey
Definition: dsa.h:21
Botan::DSA_PublicKey::group_format
DL_Group::Format group_format() const
Definition: dsa.h:26
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::SecureVector< byte >
Botan::DSA_Verification_Operation::message_part_size
size_t message_part_size() const
Definition: dsa.h:90
Botan::Modular_Reducer
Definition: reducer.h:18
Botan::PK_Ops::Verification
Definition: pk_ops.h:85
Botan::DSA_PublicKey::max_input_bits
size_t max_input_bits() const
Definition: dsa.h:29