Coverage Report

Created: 2021-01-13 07:05

/src/botan/src/lib/pubkey/dl_algo/dl_algo.cpp
Line
Count
Source (jump to first uncovered line)
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
0
   {
17
0
   return m_group.p_bits();
18
0
   }
19
20
size_t DL_Scheme_PublicKey::estimated_strength() const
21
0
   {
22
0
   return m_group.estimated_strength();
23
0
   }
24
25
AlgorithmIdentifier DL_Scheme_PublicKey::algorithm_identifier() const
26
0
   {
27
0
   return AlgorithmIdentifier(get_oid(),
28
0
                              m_group.DER_encode(group_format()));
29
0
   }
30
31
std::vector<uint8_t> DL_Scheme_PublicKey::public_key_bits() const
32
0
   {
33
0
   std::vector<uint8_t> output;
34
0
   DER_Encoder(output).encode(m_y);
35
0
   return output;
36
0
   }
37
38
DL_Scheme_PublicKey::DL_Scheme_PublicKey(const DL_Group& group, const BigInt& y) :
39
   m_y(y),
40
   m_group(group)
41
0
   {
42
0
   }
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
259
   {
49
259
   BER_Decoder(key_bits).decode(m_y);
50
259
   }
51
52
secure_vector<uint8_t> DL_Scheme_PrivateKey::private_key_bits() const
53
0
   {
54
0
   return DER_Encoder().encode(m_x).get_contents();
55
0
   }
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
230
   {
61
230
   m_group.BER_decode(alg_id.get_parameters(), format);
62
63
230
   BER_Decoder(key_bits).decode(m_x);
64
230
   }
65
66
/*
67
* Check Public DL Parameters
68
*/
69
bool DL_Scheme_PublicKey::check_key(RandomNumberGenerator& rng,
70
                                    bool strong) const
71
0
   {
72
0
   return m_group.verify_group(rng, strong) && m_group.verify_public_element(m_y);
73
0
   }
74
75
/*
76
* Check DL Scheme Private Parameters
77
*/
78
bool DL_Scheme_PrivateKey::check_key(RandomNumberGenerator& rng,
79
                                     bool strong) const
80
0
   {
81
0
   return m_group.verify_group(rng, strong) && m_group.verify_element_pair(m_y, m_x);
82
0
   }
83
84
}