Botan 1.10.17

dl_algo.cpp
Go to the documentation of this file.
1 /*
2 * DL Scheme
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
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 AlgorithmIdentifier DL_Scheme_PublicKey::algorithm_identifier() const
16 {
17 return AlgorithmIdentifier(get_oid(),
18 group.DER_encode(group_format()));
19 }
20
21 MemoryVector<byte> DL_Scheme_PublicKey::x509_subject_public_key() const
22 {
23 return DER_Encoder().encode(y).get_contents();
24 }
25
26 DL_Scheme_PublicKey::DL_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
27 const MemoryRegion<byte>& key_bits,
28 DL_Group::Format format)
29 {
30 DataSource_Memory source(alg_id.parameters);
31 group.BER_decode(source, format);
32
33 BER_Decoder(key_bits).decode(y);
34 }
35
36 MemoryVector<byte> DL_Scheme_PrivateKey::pkcs8_private_key() const
37 {
38 return DER_Encoder().encode(x).get_contents();
39 }
40
41 DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
42 const MemoryRegion<byte>& key_bits,
43 DL_Group::Format format)
44 {
45 DataSource_Memory source(alg_id.parameters);
46 group.BER_decode(source, format);
47
48 BER_Decoder(key_bits).decode(x);
49 }
50
51 /*
52 * Check Public DL Parameters
53 */
54 bool DL_Scheme_PublicKey::check_key(RandomNumberGenerator& rng,
55 bool strong) const
56 {
57 if(y < 2 || y >= group_p())
58 return false;
59 if(!group.verify_group(rng, strong))
60 return false;
61 return true;
62 }
63
64 /*
65 * Check DL Scheme Private Parameters
66 */
67 bool DL_Scheme_PrivateKey::check_key(RandomNumberGenerator& rng,
68 bool strong) const
69 {
70 const BigInt& p = group_p();
71 const BigInt& g = group_g();
72
73 if(y < 2 || y >= p || x < 2 || x >= p)
74 return false;
75 if(!group.verify_group(rng, strong))
76 return false;
77
78 if(!strong)
79 return true;
80
81 if(y != power_mod(g, x, p))
82 return false;
83
84 return true;
85 }
86
87 }
Botan::DER_Encoder::get_contents
SecureVector< byte > get_contents()
Definition: der_enc.cpp:122
Botan::BigInt
Definition: bigint.h:22
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::DL_Scheme_PrivateKey::check_key
bool check_key(RandomNumberGenerator &rng, bool) const
Definition: dl_algo.cpp:67
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &)
Definition: ber_dec.cpp:344
Botan::AlgorithmIdentifier::parameters
SecureVector< byte > parameters
Definition: alg_id.h:36
Botan::DL_Group::BER_decode
void BER_decode(DataSource &src, Format format)
Definition: dl_group.cpp:264
Botan::DL_Scheme_PublicKey::x509_subject_public_key
MemoryVector< byte > x509_subject_public_key() const
Definition: dl_algo.cpp:21
Botan::DER_Encoder::encode
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:209
Botan::DER_Encoder
Definition: der_enc.h:22
Botan::DL_Scheme_PublicKey::algorithm_identifier
AlgorithmIdentifier algorithm_identifier() const
Definition: dl_algo.cpp:15
Botan::DL_Group::verify_group
bool verify_group(RandomNumberGenerator &rng, bool strong) const
Definition: dl_group.cpp:153
Botan::Public_Key::get_oid
virtual OID get_oid() const
Definition: pk_keys.cpp:17
Botan::DL_Scheme_PublicKey::DL_Scheme_PublicKey
DL_Scheme_PublicKey()
Definition: dl_algo.h:69
Botan::DL_Group::Format
Format
Definition: dl_group.h:44
Botan::DL_Scheme_PublicKey::check_key
bool check_key(RandomNumberGenerator &rng, bool) const
Definition: dl_algo.cpp:54
Botan::DL_Scheme_PublicKey::group_format
virtual DL_Group::Format group_format() const =0
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::MemoryVector< byte >
Botan::DL_Scheme_PrivateKey::DL_Scheme_PrivateKey
DL_Scheme_PrivateKey()
Definition: dl_algo.h:104
Botan::DL_Scheme_PublicKey::group_p
const BigInt & group_p() const
Definition: dl_algo.h:44
Botan::DataSource_Memory
Definition: data_src.h:94
Botan::power_mod
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:366
Botan::DL_Scheme_PrivateKey::x
BigInt x
Definition: dl_algo.h:109
Botan::DL_Scheme_PublicKey::group
DL_Group group
Definition: dl_algo.h:79
Botan::DL_Group::DER_encode
SecureVector< byte > DER_encode(Format format) const
Definition: dl_group.cpp:205
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::DL_Scheme_PublicKey::group_g
const BigInt & group_g() const
Definition: dl_algo.h:56
Botan::BER_Decoder
Definition: ber_dec.h:19
Botan::DL_Scheme_PrivateKey::pkcs8_private_key
MemoryVector< byte > pkcs8_private_key() const
Definition: dl_algo.cpp:36
Botan::DL_Scheme_PublicKey::y
BigInt y
Definition: dl_algo.h:74