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

randombit / botan / 19012754211

02 Nov 2025 01:10PM UTC coverage: 90.677% (+0.006%) from 90.671%
19012754211

push

github

web-flow
Merge pull request #5137 from randombit/jack/clang-tidy-includes

Remove various unused includes flagged by clang-tidy misc-include-cleaner

100457 of 110786 relevant lines covered (90.68%)

12189873.8 hits per line

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

88.89
/src/lib/pubkey/classic_mceliece/cmce.cpp
1
/*
2
 * Classic McEliece Key Generation
3
 * (C) 2023 Jack Lloyd
4
 *     2023,2024 Fabian Albert, Amos Treiber - Rohde & Schwarz Cybersecurity
5
 *
6
 * Botan is released under the Simplified BSD License (see license.txt)
7
 **/
8

9
#include <botan/cmce.h>
10
#include <botan/pk_ops.h>
11
#include <botan/rng.h>
12
#include <botan/internal/cmce_decaps.h>
13
#include <botan/internal/cmce_encaps.h>
14
#include <botan/internal/cmce_keys_internal.h>
15
#include <botan/internal/cmce_matrix.h>
16
#include <botan/internal/ct_utils.h>
17

18
namespace Botan {
19

20
Classic_McEliece_PublicKey::Classic_McEliece_PublicKey(const AlgorithmIdentifier& alg_id,
20✔
21
                                                       std::span<const uint8_t> key_bits) :
20✔
22
      Classic_McEliece_PublicKey(key_bits, Classic_McEliece_Parameter_Set::from_oid(alg_id.oid())) {}
20✔
23

24
Classic_McEliece_PublicKey::Classic_McEliece_PublicKey(std::span<const uint8_t> key_bits,
39✔
25
                                                       Classic_McEliece_Parameter_Set param_set) {
39✔
26
   auto params = Classic_McEliece_Parameters::create(param_set);
39✔
27
   BOTAN_ARG_CHECK(key_bits.size() == params.pk_size_bytes(), "Wrong public key length");
39✔
28
   m_public = std::make_shared<Classic_McEliece_PublicKeyInternal>(
78✔
29
      params, Classic_McEliece_Matrix(params, {key_bits.begin(), key_bits.end()}));
117✔
30
}
39✔
31

32
Classic_McEliece_PublicKey::Classic_McEliece_PublicKey(const Classic_McEliece_PublicKey& other) {
37✔
33
   m_public = std::make_shared<Classic_McEliece_PublicKeyInternal>(*other.m_public);
37✔
34
}
37✔
35

36
Classic_McEliece_PublicKey& Classic_McEliece_PublicKey::operator=(const Classic_McEliece_PublicKey& other) {
×
37
   if(this != &other) {
×
38
      m_public = std::make_shared<Classic_McEliece_PublicKeyInternal>(*other.m_public);
×
39
   }
40
   return *this;
×
41
}
42

43
AlgorithmIdentifier Classic_McEliece_PublicKey::algorithm_identifier() const {
68✔
44
   return AlgorithmIdentifier(object_identifier(), AlgorithmIdentifier::USE_EMPTY_PARAM);
68✔
45
}
46

47
OID Classic_McEliece_PublicKey::object_identifier() const {
68✔
48
   return m_public->params().object_identifier();
68✔
49
}
50

51
size_t Classic_McEliece_PublicKey::key_length() const {
×
52
   // The key length is the dimension k of the goppa code (i.e. the code has 2^k codewords)
53
   return m_public->params().pk_no_cols();
×
54
}
55

56
size_t Classic_McEliece_PublicKey::estimated_strength() const {
44✔
57
   return m_public->params().estimated_strength();
44✔
58
}
59

60
std::vector<uint8_t> Classic_McEliece_PublicKey::public_key_bits() const {
46✔
61
   return raw_public_key_bits();
46✔
62
}
63

64
std::vector<uint8_t> Classic_McEliece_PublicKey::raw_public_key_bits() const {
82✔
65
   return m_public->matrix().bytes();
82✔
66
}
67

68
bool Classic_McEliece_PublicKey::check_key(RandomNumberGenerator& /*rng*/, bool /*strong*/) const {
2✔
69
   return true;
2✔
70
}
71

72
std::unique_ptr<Private_Key> Classic_McEliece_PublicKey::generate_another(RandomNumberGenerator& rng) const {
2✔
73
   return std::make_unique<Classic_McEliece_PrivateKey>(rng, m_public->params().parameter_set());
2✔
74
}
75

76
std::unique_ptr<PK_Ops::KEM_Encryption> Classic_McEliece_PublicKey::create_kem_encryption_op(
33✔
77
   std::string_view params, std::string_view provider) const {
78
   if(provider.empty() || provider == "base") {
33✔
79
      return std::make_unique<Classic_McEliece_Encryptor>(this->m_public, params);
33✔
80
   }
81
   throw Provider_Not_Found(algo_name(), provider);
×
82
}
83

84
Classic_McEliece_PrivateKey::Classic_McEliece_PrivateKey(RandomNumberGenerator& rng,
41✔
85
                                                         Classic_McEliece_Parameter_Set param_set) {
41✔
86
   auto params = Classic_McEliece_Parameters::create(param_set);
41✔
87
   const auto seed = rng.random_vec<CmceInitialSeed>(params.seed_len());
41✔
88
   CT::poison(seed);
41✔
89
   std::tie(m_private, m_public) = Classic_McEliece_KeyPair_Internal::generate(params, seed).decompose_to_pair();
41✔
90

91
   BOTAN_ASSERT_NONNULL(m_private);
41✔
92
   BOTAN_ASSERT_NONNULL(m_public);
41✔
93
   CT::unpoison_all(*m_private, *m_public);
41✔
94
}
41✔
95

96
Classic_McEliece_PrivateKey::Classic_McEliece_PrivateKey(std::span<const uint8_t> sk,
45✔
97
                                                         Classic_McEliece_Parameter_Set param_set) {
45✔
98
   auto scope = CT::scoped_poison(sk);
45✔
99
   auto params = Classic_McEliece_Parameters::create(param_set);
45✔
100
   auto sk_internal = Classic_McEliece_PrivateKeyInternal::from_bytes(params, sk);
45✔
101
   m_private = std::make_shared<Classic_McEliece_PrivateKeyInternal>(std::move(sk_internal));
45✔
102
   // This creates and loads the public key, which is very large. Potentially, we could only load
103
   // it on demand (since one may use the private key only for decapsulation without needing the public key).
104
   // TODO: consider building a load-on-demand mechanism for the public key
105
   m_public = Classic_McEliece_PublicKeyInternal::create_from_private_key(*m_private);
45✔
106
   CT::unpoison_all(*m_public, *m_private);
45✔
107
}
45✔
108

109
Classic_McEliece_PrivateKey::Classic_McEliece_PrivateKey(const AlgorithmIdentifier& alg_id,
28✔
110
                                                         std::span<const uint8_t> key_bits) :
28✔
111
      Classic_McEliece_PrivateKey(key_bits, Classic_McEliece_Parameter_Set::from_oid(alg_id.oid())) {}
28✔
112

113
std::unique_ptr<Public_Key> Classic_McEliece_PrivateKey::public_key() const {
37✔
114
   return std::make_unique<Classic_McEliece_PublicKey>(*this);
37✔
115
}
116

117
secure_vector<uint8_t> Classic_McEliece_PrivateKey::private_key_bits() const {
46✔
118
   return raw_private_key_bits();
46✔
119
}
120

121
secure_vector<uint8_t> Classic_McEliece_PrivateKey::raw_private_key_bits() const {
96✔
122
   return m_private->serialize();
96✔
123
}
124

125
bool Classic_McEliece_PrivateKey::check_key(RandomNumberGenerator& /*rng*/, bool /*strong*/) const {
2✔
126
   return m_private->check_key();
2✔
127
}
128

129
std::unique_ptr<PK_Ops::KEM_Decryption> Classic_McEliece_PrivateKey::create_kem_decryption_op(
34✔
130
   RandomNumberGenerator& rng, std::string_view params, std::string_view provider) const {
131
   BOTAN_UNUSED(rng);
34✔
132
   if(provider.empty() || provider == "base") {
34✔
133
      return std::make_unique<Classic_McEliece_Decryptor>(this->m_private, params);
34✔
134
   }
135
   throw Provider_Not_Found(algo_name(), provider);
×
136
}
137

138
}  // 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