Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

dl_algo.cpp
Go to the documentation of this file.
1 /*
2 * DL Scheme
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/dl_algo.h>
9 #include <botan/numthry.h>
10 #include <botan/der_enc.h>
11 #include <botan/ber_dec.h>
12
13 namespace Botan {
14
15 size_t DL_Scheme_PublicKey::key_length() const
16 {
17 return m_group.p_bits();
18 }
19
20 size_t DL_Scheme_PublicKey::estimated_strength() const
21 {
22 return m_group.estimated_strength();
23 }
24
25 AlgorithmIdentifier DL_Scheme_PublicKey::algorithm_identifier() const
26 {
27 return AlgorithmIdentifier(get_oid(),
28 m_group.DER_encode(group_format()));
29 }
30
31 std::vector<uint8_t> DL_Scheme_PublicKey::public_key_bits() const
32 {
33 std::vector<uint8_t> output;
34 DER_Encoder(output).encode(m_y);
35 return output;
36 }
37
38 DL_Scheme_PublicKey::DL_Scheme_PublicKey(const DL_Group& group, const BigInt& y) :
39 m_y(y),
40 m_group(group)
41 {
42 }
43
44 DL_Scheme_PublicKey::DL_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
45 const std::vector<uint8_t>& key_bits,
46 DL_Group::Format format) :
47 m_group(alg_id.get_parameters(), format)
48 {
49 BER_Decoder(key_bits).decode(m_y);
50 }
51
52 secure_vector<uint8_t> DL_Scheme_PrivateKey::private_key_bits() const
53 {
54 return DER_Encoder().encode(m_x).get_contents();
55 }
56
57 DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
58 const secure_vector<uint8_t>& key_bits,
59 DL_Group::Format format)
60 {
61 m_group.BER_decode(alg_id.get_parameters(), format);
62
63 BER_Decoder(key_bits).decode(m_x);
64 }
65
66 /*
67 * Check Public DL Parameters
68 */
69 bool DL_Scheme_PublicKey::check_key(RandomNumberGenerator& rng,
70 bool strong) const
71 {
72 return m_group.verify_group(rng, strong) && m_group.verify_public_element(m_y);
73 }
74
75 /*
76 * Check DL Scheme Private Parameters
77 */
78 bool DL_Scheme_PrivateKey::check_key(RandomNumberGenerator& rng,
79 bool strong) const
80 {
81 return m_group.verify_group(rng, strong) && m_group.verify_element_pair(m_y, m_x);
82 }
83
84 }
Botan::DL_Scheme_PublicKey::DL_Scheme_PublicKey
DL_Scheme_PublicKey()=default
Botan::DL_Scheme_PrivateKey::m_x
BigInt m_x
Definition: dl_algo.h:135
Botan::BigInt
Definition: bigint.h:24
Botan::DL_Scheme_PublicKey::key_length
size_t key_length() const override
Definition: dl_algo.cpp:15
Botan::DL_Scheme_PublicKey::check_key
bool check_key(RandomNumberGenerator &rng, bool) const override
Definition: dl_algo.cpp:69
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::DL_Scheme_PrivateKey::DL_Scheme_PrivateKey
DL_Scheme_PrivateKey()=default
Botan::DL_Group::verify_element_pair
bool verify_element_pair(const BigInt &y, const BigInt &x) const
Definition: dl_group.cpp:356
Botan::DER_Encoder::get_contents
secure_vector< uint8_t > get_contents()
Definition: der_enc.cpp:152
m_y
const BigInt & m_y
Definition: dsa.cpp:179
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::DL_Group::DER_encode
std::vector< uint8_t > DER_encode(Format format) const
Definition: dl_group.cpp:533
Botan::Public_Key::get_oid
virtual OID get_oid() const
Definition: pk_keys.cpp:53
Botan::DL_Group::p_bits
size_t p_bits() const
Definition: dl_group.cpp:436
Botan::DER_Encoder::encode
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:285
Botan::DER_Encoder
Definition: der_enc.h:23
Botan::DL_Group::estimated_strength
size_t estimated_strength() const
Definition: dl_group.cpp:458
Botan::DL_Group
Definition: dl_group.h:23
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::DL_Group::Format
Format
Definition: dl_group.h:34
Botan::DL_Scheme_PublicKey::algorithm_identifier
AlgorithmIdentifier algorithm_identifier() const override
Definition: dl_algo.cpp:25
Botan::DL_Scheme_PublicKey::m_group
DL_Group m_group
Definition: dl_algo.h:97
Botan::DL_Scheme_PrivateKey::private_key_bits
secure_vector< uint8_t > private_key_bits() const override
Definition: dl_algo.cpp:52
Botan::DL_Scheme_PublicKey::m_y
BigInt m_y
Definition: dl_algo.h:92
Botan::DL_Scheme_PublicKey::group_format
virtual DL_Group::Format group_format() const =0
Botan::DL_Group::verify_group
bool verify_group(RandomNumberGenerator &rng, bool strong=true) const
Definition: dl_group.cpp:372
Botan::DL_Scheme_PublicKey::estimated_strength
size_t estimated_strength() const override
Definition: dl_algo.cpp:20
m_group
const DL_Group m_group
Definition: dsa.cpp:99
Botan
Definition: alg_id.cpp:13
Botan::DL_Scheme_PublicKey::public_key_bits
std::vector< uint8_t > public_key_bits() const override
Definition: dl_algo.cpp:31
Botan::DL_Scheme_PrivateKey::check_key
bool check_key(RandomNumberGenerator &rng, bool) const override
Definition: dl_algo.cpp:78
Botan::DL_Group::verify_public_element
bool verify_public_element(const BigInt &y) const
Definition: dl_group.cpp:339
Botan::AlgorithmIdentifier
Definition: alg_id.h:21
Botan::DL_Group::BER_decode
void BER_decode(const std::vector< uint8_t > &ber, Format format)
Definition: dl_group.cpp:592
Botan::BER_Decoder
Definition: ber_dec.h:21
Botan::AlgorithmIdentifier::get_parameters
const std::vector< uint8_t > & get_parameters() const
Definition: alg_id.h:38