• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 12831658451

17 Jan 2025 03:07PM UTC coverage: 91.206% (-0.006%) from 91.212%
12831658451

Pull #4567

github

web-flow
Merge 34786d9de into 6a97b80e9
Pull Request #4567: Context support for ML-DSA and SLH-DSA

93825 of 102871 relevant lines covered (91.21%)

11369960.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.16
/src/lib/pubkey/pk_keys.cpp
1
/*
2
* PK Key Types
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/pk_keys.h>
9

10
#include <botan/der_enc.h>
11
#include <botan/hash.h>
12
#include <botan/hex.h>
13
#include <botan/pk_ops.h>
14
#include <botan/pk_options.h>
15
#include <botan/internal/fmt.h>
16

17
namespace Botan {
18

19
const BigInt& Asymmetric_Key::get_int_field(std::string_view field) const {
4✔
20
   throw Unknown_PK_Field_Name(algo_name(), field);
8✔
21
}
22

23
bool Asymmetric_Key::supports_context_data() const {
×
24
   return false;
×
25
}
26

27
OID Asymmetric_Key::object_identifier() const {
3,349✔
28
   try {
3,349✔
29
      return OID::from_string(algo_name());
6,698✔
30
   } catch(Lookup_Error&) {
×
31
      throw Lookup_Error(fmt("Public key algorithm {} has no defined OIDs", algo_name()));
×
32
   }
×
33
}
34

35
std::string create_hex_fingerprint(const uint8_t bits[], size_t bits_len, std::string_view hash_name) {
37,162✔
36
   auto hash_fn = HashFunction::create_or_throw(hash_name);
37,162✔
37
   const std::string hex_hash = hex_encode(hash_fn->process(bits, bits_len));
74,324✔
38

39
   std::string fprint;
37,162✔
40

41
   for(size_t i = 0; i != hex_hash.size(); i += 2) {
1,003,578✔
42
      if(i != 0) {
966,416✔
43
         fprint.push_back(':');
929,254✔
44
      }
45

46
      fprint.push_back(hex_hash[i]);
966,416✔
47
      fprint.push_back(hex_hash[i + 1]);
966,416✔
48
   }
49

50
   return fprint;
37,162✔
51
}
74,324✔
52

53
std::vector<uint8_t> Public_Key::subject_public_key() const {
2,284✔
54
   std::vector<uint8_t> output;
2,284✔
55

56
   DER_Encoder(output)
2,284✔
57
      .start_sequence()
2,284✔
58
      .encode(algorithm_identifier())
4,568✔
59
      .encode(public_key_bits(), ASN1_Type::BitString)
4,568✔
60
      .end_cons();
2,284✔
61

62
   return output;
2,284✔
63
}
×
64

65
secure_vector<uint8_t> Private_Key::private_key_info() const {
1,623✔
66
   const size_t PKCS8_VERSION = 0;
1,623✔
67

68
   return DER_Encoder()
1,623✔
69
      .start_sequence()
1,623✔
70
      .encode(PKCS8_VERSION)
1,623✔
71
      .encode(pkcs8_algorithm_identifier())
3,246✔
72
      .encode(private_key_bits(), ASN1_Type::OctetString)
3,246✔
73
      .end_cons()
1,623✔
74
      .get_contents();
3,246✔
75
}
76

77
secure_vector<uint8_t> Private_Key::raw_private_key_bits() const {
1✔
78
   throw Not_Implemented(algo_name() + " does not implement raw_private_key_bits");
3✔
79
}
80

81
/*
82
* Hash of the X.509 subjectPublicKey encoding
83
*/
84
std::string Public_Key::fingerprint_public(std::string_view hash_algo) const {
18✔
85
   return create_hex_fingerprint(subject_public_key(), hash_algo);
36✔
86
}
87

88
/*
89
* Hash of the PKCS #8 encoding for this key object
90
*/
91
std::string Private_Key::fingerprint_private(std::string_view hash_algo) const {
16✔
92
   return create_hex_fingerprint(private_key_bits(), hash_algo);
32✔
93
}
94

95
std::unique_ptr<PK_Ops::Encryption> Public_Key::create_encryption_op(RandomNumberGenerator& /*rng*/,
×
96
                                                                     std::string_view /*params*/,
97
                                                                     std::string_view /*provider*/) const {
98
   throw Lookup_Error(fmt("{} does not support encryption", algo_name()));
×
99
}
100

101
std::unique_ptr<PK_Ops::KEM_Encryption> Public_Key::create_kem_encryption_op(std::string_view /*params*/,
×
102
                                                                             std::string_view /*provider*/) const {
103
   throw Lookup_Error(fmt("{} does not support KEM encryption", algo_name()));
×
104
}
105

106
std::unique_ptr<PK_Ops::Verification> Public_Key::_create_verification_op(PK_Signature_Options& options) const {
×
107
   BOTAN_UNUSED(options);
×
108
   throw Lookup_Error(fmt("{} does not support verification", algo_name()));
×
109
}
110

111
std::unique_ptr<PK_Ops::Verification> Public_Key::create_x509_verification_op(const AlgorithmIdentifier& /*params*/,
1✔
112
                                                                              std::string_view /*provider*/) const {
113
   throw Lookup_Error(fmt("{} does not support X.509 verification", algo_name()));
1✔
114
}
115

116
std::unique_ptr<PK_Ops::Decryption> Private_Key::create_decryption_op(RandomNumberGenerator& /*rng*/,
×
117
                                                                      std::string_view /*params*/,
118
                                                                      std::string_view /*provider*/) const {
119
   throw Lookup_Error(fmt("{} does not support decryption", algo_name()));
×
120
}
121

122
std::unique_ptr<PK_Ops::KEM_Decryption> Private_Key::create_kem_decryption_op(RandomNumberGenerator& /*rng*/,
×
123
                                                                              std::string_view /*params*/,
124
                                                                              std::string_view /*provider*/) const {
125
   throw Lookup_Error(fmt("{} does not support KEM decryption", algo_name()));
×
126
}
127

128
std::unique_ptr<PK_Ops::Signature> Private_Key::_create_signature_op(RandomNumberGenerator& rng,
×
129
                                                                     PK_Signature_Options& options) const {
130
   BOTAN_UNUSED(rng, options);
×
131
   throw Lookup_Error(fmt("{} does not support signatures", algo_name()));
×
132
}
133

134
std::unique_ptr<PK_Ops::Key_Agreement> Private_Key::create_key_agreement_op(RandomNumberGenerator& /*rng*/,
×
135
                                                                            std::string_view /*params*/,
136
                                                                            std::string_view /*provider*/) const {
137
   throw Lookup_Error(fmt("{} does not support key agreement", algo_name()));
×
138
}
139

140
// Forwarding functions for compat
141

142
std::unique_ptr<PK_Ops::Verification> Public_Key::create_verification_op(std::string_view params,
×
143
                                                                         std::string_view provider) const {
144
   auto opts = PK_Signature_Options::from_legacy(
×
145
      *this /* won't be consumed */, params, Signature_Format::Standard /* won't be consumed */, provider);
×
146
   return this->_create_verification_op(opts);
×
147
}
×
148

149
std::unique_ptr<PK_Ops::Signature> Private_Key::create_signature_op(RandomNumberGenerator& rng,
×
150
                                                                    std::string_view params,
151
                                                                    std::string_view provider) const {
152
   auto opts = PK_Signature_Options::from_legacy(*this /* won't be consumed */,
×
153
                                                 rng /* won't be consumed */,
154
                                                 params,
155
                                                 Signature_Format::Standard /* won't be consumed */,
156
                                                 provider);
×
157
   return this->_create_signature_op(rng, opts);
×
158
}
×
159

160
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc