Botan  1.10.9
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 
16  {
19  }
20 
22  {
23  return DER_Encoder().encode(y).get_contents();
24  }
25 
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 
37  {
38  return DER_Encoder().encode(x).get_contents();
39  }
40 
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 */
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 */
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 }
SecureVector< byte > get_contents()
Definition: der_enc.cpp:122
AlgorithmIdentifier algorithm_identifier() const
Definition: dl_algo.cpp:15
MemoryVector< byte > pkcs8_private_key() const
Definition: dl_algo.cpp:36
BER_Decoder & decode(bool &)
Definition: ber_dec.cpp:338
const BigInt & group_p() const
Definition: dl_algo.h:44
bool verify_group(RandomNumberGenerator &rng, bool strong) const
Definition: dl_group.cpp:153
SecureVector< byte > parameters
Definition: alg_id.h:36
void BER_decode(DataSource &src, Format format)
Definition: dl_group.cpp:264
virtual OID get_oid() const
Definition: pk_keys.cpp:17
bool check_key(RandomNumberGenerator &rng, bool) const
Definition: dl_algo.cpp:67
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:209
RandomNumberGenerator * rng
Definition: global_rng.cpp:165
SecureVector< byte > DER_encode(Format format) const
Definition: dl_group.cpp:205
bool check_key(RandomNumberGenerator &rng, bool) const
Definition: dl_algo.cpp:54
virtual DL_Group::Format group_format() const =0
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:251
MemoryVector< byte > x509_subject_public_key() const
Definition: dl_algo.cpp:21
const BigInt & group_g() const
Definition: dl_algo.h:56