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

randombit / botan / 11364833501

16 Oct 2024 11:36AM UTC coverage: 91.11% (-0.002%) from 91.112%
11364833501

push

github

web-flow
Merge pull request #4374 from Rohde-Schwarz/pqc/ml_kem_compat

ML-KEM: Provide type aliases

90987 of 99865 relevant lines covered (91.11%)

9384224.82 hits per line

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

95.58
/src/lib/pubkey/pk_algs.cpp
1
/*
2
* PK Key
3
* (C) 1999-2010,2016 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/pk_algs.h>
9

10
#include <botan/internal/fmt.h>
11
#include <botan/internal/parsing.h>
12

13
#if defined(BOTAN_HAS_RSA)
14
   #include <botan/rsa.h>
15
#endif
16

17
#if defined(BOTAN_HAS_DSA)
18
   #include <botan/dsa.h>
19
#endif
20

21
#if defined(BOTAN_HAS_DL_GROUP)
22
   #include <botan/dl_group.h>
23
#endif
24

25
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
26
   #include <botan/dh.h>
27
#endif
28

29
#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
30
   #include <botan/ecc_key.h>
31
#endif
32

33
#if defined(BOTAN_HAS_ECDSA)
34
   #include <botan/ecdsa.h>
35
#endif
36

37
#if defined(BOTAN_HAS_ECGDSA)
38
   #include <botan/ecgdsa.h>
39
#endif
40

41
#if defined(BOTAN_HAS_ECKCDSA)
42
   #include <botan/eckcdsa.h>
43
#endif
44

45
#if defined(BOTAN_HAS_ED25519)
46
   #include <botan/ed25519.h>
47
#endif
48

49
#if defined(BOTAN_HAS_ED448)
50
   #include <botan/ed448.h>
51
#endif
52

53
#if defined(BOTAN_HAS_GOST_34_10_2001)
54
   #include <botan/gost_3410.h>
55
#endif
56

57
#if defined(BOTAN_HAS_ELGAMAL)
58
   #include <botan/elgamal.h>
59
#endif
60

61
#if defined(BOTAN_HAS_ECDH)
62
   #include <botan/ecdh.h>
63
#endif
64

65
#if defined(BOTAN_HAS_X25519)
66
   #include <botan/x25519.h>
67
#endif
68

69
#if defined(BOTAN_HAS_X448)
70
   #include <botan/x448.h>
71
#endif
72

73
#if defined(BOTAN_HAS_MCELIECE)
74
   #include <botan/mceliece.h>
75
#endif
76

77
#if defined(BOTAN_HAS_FRODOKEM)
78
   #include <botan/frodokem.h>
79
#endif
80

81
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
82
   #include <botan/kyber.h>
83
#endif
84

85
#if defined(BOTAN_HAS_ML_KEM)
86
   #include <botan/ml_kem.h>
87
#endif
88

89
#if defined(BOTAN_HAS_HSS_LMS)
90
   #include <botan/hss_lms.h>
91
#endif
92

93
#if defined(BOTAN_HAS_XMSS_RFC8391)
94
   #include <botan/xmss.h>
95
#endif
96

97
#if defined(BOTAN_HAS_SM2)
98
   #include <botan/sm2.h>
99
#endif
100

101
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES) || defined(BOTAN_HAS_ML_DSA)
102
   #include <botan/dilithium.h>
103
#endif
104

105
#if defined(BOTAN_HAS_SPHINCS_PLUS_COMMON)
106
   #include <botan/sphincsplus.h>
107
#endif
108

109
namespace Botan {
110

111
std::unique_ptr<Public_Key> load_public_key(const AlgorithmIdentifier& alg_id,
22,285✔
112
                                            [[maybe_unused]] std::span<const uint8_t> key_bits) {
113
   const std::string oid_str = alg_id.oid().to_formatted_string();
22,285✔
114
   const std::vector<std::string> alg_info = split_on(oid_str, '/');
22,285✔
115
   std::string_view alg_name = alg_info[0];
22,285✔
116

117
#if defined(BOTAN_HAS_RSA)
118
   if(alg_name == "RSA") {
22,285✔
119
      return std::make_unique<RSA_PublicKey>(alg_id, key_bits);
32,021✔
120
   }
121
#endif
122

123
#if defined(BOTAN_HAS_X25519)
124
   if(alg_name == "X25519" || alg_name == "Curve25519") {
5,960✔
125
      return std::make_unique<X25519_PublicKey>(alg_id, key_bits);
48✔
126
   }
127
#endif
128

129
#if defined(BOTAN_HAS_X448)
130
   if(alg_name == "X448") {
5,839✔
131
      return std::make_unique<X448_PublicKey>(alg_id, key_bits);
4✔
132
   }
133
#endif
134

135
#if defined(BOTAN_HAS_MCELIECE)
136
   if(alg_name == "McEliece") {
5,837✔
137
      return std::make_unique<McEliece_PublicKey>(key_bits);
2✔
138
   }
139
#endif
140

141
#if defined(BOTAN_HAS_FRODOKEM)
142
   if(alg_name == "FrodoKEM" || alg_name.starts_with("FrodoKEM-") || alg_name.starts_with("eFrodoKEM-")) {
5,837✔
143
      return std::make_unique<FrodoKEM_PublicKey>(alg_id, key_bits);
632✔
144
   }
145
#endif
146

147
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
148
   if(alg_name == "Kyber" || alg_name.starts_with("Kyber-")) {
9,182✔
149
      return std::make_unique<Kyber_PublicKey>(alg_id, key_bits);
328✔
150
   }
151
#endif
152

153
#if defined(BOTAN_HAS_ML_KEM)
154
   if(alg_name.starts_with("ML-KEM-")) {
5,356✔
155
      return std::make_unique<ML_KEM_PublicKey>(alg_id, key_bits);
162✔
156
   }
157
#endif
158

159
#if defined(BOTAN_HAS_ECDSA)
160
   if(alg_name == "ECDSA") {
5,275✔
161
      return std::make_unique<ECDSA_PublicKey>(alg_id, key_bits);
6,999✔
162
   }
163
#endif
164

165
#if defined(BOTAN_HAS_ECDH)
166
   if(alg_name == "ECDH") {
1,687✔
167
      return std::make_unique<ECDH_PublicKey>(alg_id, key_bits);
33✔
168
   }
169
#endif
170

171
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
172
   if(alg_name == "DH") {
1,670✔
173
      return std::make_unique<DH_PublicKey>(alg_id, key_bits);
11✔
174
   }
175
#endif
176

177
#if defined(BOTAN_HAS_DSA)
178
   if(alg_name == "DSA") {
1,662✔
179
      return std::make_unique<DSA_PublicKey>(alg_id, key_bits);
355✔
180
   }
181
#endif
182

183
#if defined(BOTAN_HAS_ELGAMAL)
184
   if(alg_name == "ElGamal") {
1,428✔
185
      return std::make_unique<ElGamal_PublicKey>(alg_id, key_bits);
8✔
186
   }
187
#endif
188

189
#if defined(BOTAN_HAS_ECGDSA)
190
   if(alg_name == "ECGDSA") {
1,424✔
191
      return std::make_unique<ECGDSA_PublicKey>(alg_id, key_bits);
146✔
192
   }
193
#endif
194

195
#if defined(BOTAN_HAS_ECKCDSA)
196
   if(alg_name == "ECKCDSA") {
1,351✔
197
      return std::make_unique<ECKCDSA_PublicKey>(alg_id, key_bits);
144✔
198
   }
199
#endif
200

201
#if defined(BOTAN_HAS_ED25519)
202
   if(alg_name == "Ed25519") {
1,279✔
203
      return std::make_unique<Ed25519_PublicKey>(alg_id, key_bits);
1,528✔
204
   }
205
#endif
206

207
#if defined(BOTAN_HAS_ED448)
208
   if(alg_name == "Ed448") {
515✔
209
      return std::make_unique<Ed448_PublicKey>(alg_id, key_bits);
146✔
210
   }
211
#endif
212

213
#if defined(BOTAN_HAS_GOST_34_10_2001)
214
   if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" || alg_name == "GOST-34.10-2012-512") {
574✔
215
      return std::make_unique<GOST_3410_PublicKey>(alg_id, key_bits);
132✔
216
   }
217
#endif
218

219
#if defined(BOTAN_HAS_SM2)
220
   if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") {
444✔
221
      return std::make_unique<SM2_PublicKey>(alg_id, key_bits);
30✔
222
   }
223
#endif
224

225
#if defined(BOTAN_HAS_XMSS_RFC8391)
226
   if(alg_name == "XMSS") {
361✔
227
      return std::make_unique<XMSS_PublicKey>(key_bits);
88✔
228
   }
229
#endif
230

231
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES) || defined(BOTAN_HAS_ML_DSA)
232
   if(alg_name == "Dilithium" || alg_name.starts_with("Dilithium-") || alg_name.starts_with("ML-DSA-")) {
319✔
233
      return std::make_unique<Dilithium_PublicKey>(alg_id, key_bits);
288✔
234
   }
235
#endif
236

237
#if defined(BOTAN_HAS_HSS_LMS)
238
   if(alg_name == "HSS-LMS") {
173✔
239
      return std::make_unique<HSS_LMS_PublicKey>(key_bits);
106✔
240
   }
241
#endif
242

243
#if defined(BOTAN_HAS_SPHINCS_PLUS_COMMON)
244
   if(alg_name == "SPHINCS+" || alg_name.starts_with("SphincsPlus-") || alg_name.starts_with("SLH-DSA-") ||
175✔
245
      alg_name.starts_with("Hash-SLH-DSA-")) {
54✔
246
      return std::make_unique<SphincsPlus_PublicKey>(alg_id, key_bits);
132✔
247
   }
248
#endif
249

250
   throw Decoding_Error(fmt("Unknown or unavailable public key algorithm '{}'", alg_name));
108✔
251
}
22,285✔
252

253
std::unique_ptr<Private_Key> load_private_key(const AlgorithmIdentifier& alg_id,
4,861✔
254
                                              [[maybe_unused]] std::span<const uint8_t> key_bits) {
255
   const std::string oid_str = alg_id.oid().to_formatted_string();
4,861✔
256
   const std::vector<std::string> alg_info = split_on(oid_str, '/');
4,861✔
257
   std::string_view alg_name = alg_info[0];
4,861✔
258

259
#if defined(BOTAN_HAS_RSA)
260
   if(alg_name == "RSA") {
4,861✔
261
      return std::make_unique<RSA_PrivateKey>(alg_id, key_bits);
2,086✔
262
   }
263
#endif
264

265
#if defined(BOTAN_HAS_X25519)
266
   if(alg_name == "X25519" || alg_name == "Curve25519") {
2,821✔
267
      return std::make_unique<X25519_PrivateKey>(alg_id, key_bits);
54✔
268
   }
269
#endif
270

271
#if defined(BOTAN_HAS_X448)
272
   if(alg_name == "X448") {
2,747✔
273
      return std::make_unique<X448_PrivateKey>(alg_id, key_bits);
12✔
274
   }
275
#endif
276

277
#if defined(BOTAN_HAS_ECDSA)
278
   if(alg_name == "ECDSA") {
2,741✔
279
      return std::make_unique<ECDSA_PrivateKey>(alg_id, key_bits);
1,528✔
280
   }
281
#endif
282

283
#if defined(BOTAN_HAS_ECDH)
284
   if(alg_name == "ECDH") {
1,541✔
285
      return std::make_unique<ECDH_PrivateKey>(alg_id, key_bits);
184✔
286
   }
287
#endif
288

289
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
290
   if(alg_name == "DH") {
1,419✔
291
      return std::make_unique<DH_PrivateKey>(alg_id, key_bits);
67✔
292
   }
293
#endif
294

295
#if defined(BOTAN_HAS_DSA)
296
   if(alg_name == "DSA") {
1,379✔
297
      return std::make_unique<DSA_PrivateKey>(alg_id, key_bits);
373✔
298
   }
299
#endif
300

301
#if defined(BOTAN_HAS_FRODOKEM)
302
   if(alg_name == "FrodoKEM" || alg_name.starts_with("FrodoKEM-") || alg_name.starts_with("eFrodoKEM-")) {
1,067✔
303
      return std::make_unique<FrodoKEM_PrivateKey>(alg_id, key_bits);
348✔
304
   }
305
#endif
306

307
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
308
   if(alg_name == "Kyber" || alg_name.starts_with("Kyber-")) {
733✔
309
      return std::make_unique<Kyber_PrivateKey>(alg_id, key_bits);
211✔
310
   }
311
#endif
312

313
#if defined(BOTAN_HAS_ML_KEM)
314
   if(alg_name.starts_with("ML-KEM-")) {
504✔
315
      return std::make_unique<ML_KEM_PrivateKey>(alg_id, key_bits);
93✔
316
   }
317
#endif
318

319
#if defined(BOTAN_HAS_MCELIECE)
320
   if(alg_name == "McEliece") {
411✔
321
      return std::make_unique<McEliece_PrivateKey>(key_bits);
4✔
322
   }
323
#endif
324

325
#if defined(BOTAN_HAS_ECGDSA)
326
   if(alg_name == "ECGDSA") {
407✔
327
      return std::make_unique<ECGDSA_PrivateKey>(alg_id, key_bits);
36✔
328
   }
329
#endif
330

331
#if defined(BOTAN_HAS_ECKCDSA)
332
   if(alg_name == "ECKCDSA") {
389✔
333
      return std::make_unique<ECKCDSA_PrivateKey>(alg_id, key_bits);
36✔
334
   }
335
#endif
336

337
#if defined(BOTAN_HAS_ED25519)
338
   if(alg_name == "Ed25519") {
371✔
339
      return std::make_unique<Ed25519_PrivateKey>(alg_id, key_bits);
17✔
340
   }
341
#endif
342

343
#if defined(BOTAN_HAS_ED448)
344
   if(alg_name == "Ed448") {
361✔
345
      return std::make_unique<Ed448_PrivateKey>(alg_id, key_bits);
36✔
346
   }
347
#endif
348

349
#if defined(BOTAN_HAS_GOST_34_10_2001)
350
   if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" || alg_name == "GOST-34.10-2012-512") {
388✔
351
      return std::make_unique<GOST_3410_PrivateKey>(alg_id, key_bits);
24✔
352
   }
353
#endif
354

355
#if defined(BOTAN_HAS_SM2)
356
   if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") {
365✔
357
      return std::make_unique<SM2_PrivateKey>(alg_id, key_bits);
40✔
358
   }
359
#endif
360

361
#if defined(BOTAN_HAS_ELGAMAL)
362
   if(alg_name == "ElGamal") {
311✔
363
      return std::make_unique<ElGamal_PrivateKey>(alg_id, key_bits);
28✔
364
   }
365
#endif
366

367
#if defined(BOTAN_HAS_XMSS_RFC8391)
368
   if(alg_name == "XMSS") {
297✔
369
      return std::make_unique<XMSS_PrivateKey>(key_bits);
19✔
370
   }
371
#endif
372

373
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES) || defined(BOTAN_HAS_ML_DSA)
374
   if(alg_name == "Dilithium" || alg_name.starts_with("Dilithium-") || alg_name.starts_with("ML-DSA-")) {
288✔
375
      return std::make_unique<Dilithium_PrivateKey>(alg_id, key_bits);
79✔
376
   }
377
#endif
378

379
#if defined(BOTAN_HAS_HSS_LMS)
380
   if(alg_name == "HSS-LMS-Private-Key") {
199✔
381
      return std::make_unique<HSS_LMS_PrivateKey>(key_bits);
6✔
382
   }
383
#endif
384

385
#if defined(BOTAN_HAS_SPHINCS_PLUS_COMMON)
386
   if(alg_name == "SPHINCS+" || alg_name.starts_with("SphincsPlus-") || alg_name.starts_with("SLH-DSA-") ||
242✔
387
      alg_name.starts_with("Hash-SLH-DSA-")) {
49✔
388
      return std::make_unique<SphincsPlus_PrivateKey>(alg_id, key_bits);
144✔
389
   }
390
#endif
391

392
   throw Decoding_Error(fmt("Unknown or unavailable public key algorithm '{}'", alg_name));
98✔
393
}
4,861✔
394

395
std::unique_ptr<Private_Key> create_ec_private_key(std::string_view alg_name,
157✔
396
                                                   const EC_Group& ec_group,
397
                                                   RandomNumberGenerator& rng) {
398
   // Potentially unused if all EC algorithms are disabled
399
   BOTAN_UNUSED(alg_name, ec_group, rng);
157✔
400

401
#if defined(BOTAN_HAS_ECDSA)
402
   if(alg_name == "ECDSA") {
157✔
403
      return std::make_unique<ECDSA_PrivateKey>(rng, ec_group);
144✔
404
   }
405
#endif
406

407
#if defined(BOTAN_HAS_ECDH)
408
   if(alg_name == "ECDH") {
85✔
409
      return std::make_unique<ECDH_PrivateKey>(rng, ec_group);
58✔
410
   }
411
#endif
412

413
#if defined(BOTAN_HAS_ECKCDSA)
414
   if(alg_name == "ECKCDSA") {
56✔
415
      return std::make_unique<ECKCDSA_PrivateKey>(rng, ec_group);
36✔
416
   }
417
#endif
418

419
#if defined(BOTAN_HAS_GOST_34_10_2001)
420
   if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" || alg_name == "GOST-34.10-2012-512") {
50✔
421
      return std::make_unique<GOST_3410_PrivateKey>(rng, ec_group);
24✔
422
   }
423
#endif
424

425
#if defined(BOTAN_HAS_SM2)
426
   if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") {
35✔
427
      return std::make_unique<SM2_PrivateKey>(rng, ec_group);
16✔
428
   }
429
#endif
430

431
#if defined(BOTAN_HAS_ECGDSA)
432
   if(alg_name == "ECGDSA") {
18✔
433
      return std::make_unique<ECGDSA_PrivateKey>(rng, ec_group);
36✔
434
   }
435
#endif
436

437
   return nullptr;
×
438
}
439

440
std::unique_ptr<Private_Key> create_private_key(std::string_view alg_name,
1,051✔
441
                                                RandomNumberGenerator& rng,
442
                                                std::string_view params,
443
                                                std::string_view provider) {
444
   /*
445
   * Default paramaters are chosen for work factor > 2**128 where possible
446
   */
447

448
#if defined(BOTAN_HAS_X25519)
449
   if(alg_name == "X25519" || alg_name == "Curve25519") {
1,250✔
450
      return std::make_unique<X25519_PrivateKey>(rng);
16✔
451
   }
452
#endif
453

454
#if defined(BOTAN_HAS_X448)
455
   if(alg_name == "X448") {
1,043✔
456
      return std::make_unique<X448_PrivateKey>(rng);
10✔
457
   }
458
#endif
459

460
#if defined(BOTAN_HAS_RSA)
461
   if(alg_name == "RSA") {
1,038✔
462
      const size_t modulus_bits = params.empty() ? 3072 : to_u32bit(params);
51✔
463
      return std::make_unique<RSA_PrivateKey>(rng, modulus_bits);
51✔
464
   }
465
#endif
466

467
#if defined(BOTAN_HAS_MCELIECE)
468
   if(alg_name == "McEliece") {
987✔
469
      const auto [n, t] = [&]() -> std::pair<size_t, size_t> {
2✔
470
         if(params.empty()) {
2✔
471
            return {2960, 57};
×
472
         }
473

474
         const auto mce_params = split_on(params, ',');
2✔
475

476
         if(mce_params.size() != 2) {
2✔
477
            throw Invalid_Argument(fmt("create_private_key: invalid McEliece parameters '{}'", params));
×
478
         }
479

480
         const size_t mce_n = to_u32bit(mce_params[0]);
2✔
481
         const size_t mce_t = to_u32bit(mce_params[1]);
2✔
482
         return {mce_n, mce_t};
2✔
483
      }();
4✔
484

485
      return std::make_unique<McEliece_PrivateKey>(rng, n, t);
2✔
486
   }
487
#endif
488

489
#if defined(BOTAN_HAS_FRODOKEM)
490
   if(alg_name == "FrodoKEM") {
985✔
491
      const auto mode = params.empty() ? FrodoKEMMode::FrodoKEM976_SHAKE : FrodoKEMMode(params);
322✔
492
      return std::make_unique<FrodoKEM_PrivateKey>(rng, mode);
322✔
493
   }
494
#endif
495

496
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
497
   if(alg_name == "Kyber") {
663✔
498
      const auto mode = [&]() -> KyberMode {
513✔
499
         if(params.empty()) {
171✔
500
            return KyberMode::Kyber1024_R3;
1✔
501
         }
502
         return KyberMode(params);
170✔
503
      }();
171✔
504

505
      return std::make_unique<Kyber_PrivateKey>(rng, mode);
171✔
506
   }
507
#endif
508

509
#if defined(BOTAN_HAS_ML_KEM)
510
   if(alg_name == "ML-KEM") {
492✔
511
      const auto mode = [&]() -> ML_KEM_Mode {
474✔
512
         if(params.empty()) {
158✔
513
            return ML_KEM_Mode::ML_KEM_768;
1✔
514
         }
515
         return ML_KEM_Mode(params);
157✔
516
      }();
158✔
517

518
      return std::make_unique<ML_KEM_PrivateKey>(rng, mode);
158✔
519
   }
520
#endif
521

522
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
523
   if(alg_name == "Dilithium" || alg_name.starts_with("Dilithium-")) {
359✔
524
      const auto mode = [&]() -> DilithiumMode {
25✔
525
         if(params.empty()) {
25✔
526
            return DilithiumMode::Dilithium6x5;
527
         }
528
         return DilithiumMode(params);
17✔
529
      }();
25✔
530

531
      return std::make_unique<Dilithium_PrivateKey>(rng, mode);
25✔
532
   }
533
#endif
534

535
#if defined(BOTAN_HAS_ML_DSA)
536
   if(alg_name == "ML-DSA") {
309✔
537
      const auto mode = [&]() -> DilithiumMode {
15✔
538
         if(params.empty()) {
15✔
539
            return DilithiumMode::ML_DSA_6x5;
540
         }
541
         return DilithiumMode(params);
7✔
542
      }();
15✔
543

544
      return std::make_unique<Dilithium_PrivateKey>(rng, mode);
15✔
545
   }
546
#endif
547

548
#if defined(BOTAN_HAS_HSS_LMS)
549
   if(alg_name == "HSS-LMS") {
294✔
550
      return std::make_unique<HSS_LMS_PrivateKey>(rng, params);
15✔
551
   }
552
#endif
553

554
#if defined(BOTAN_HAS_SPHINCS_PLUS_COMMON)
555
   if(alg_name == "SPHINCS+" || alg_name == "SphincsPlus" || alg_name == "SLH-DSA") {
331✔
556
      auto sphincs_params = Sphincs_Parameters::create(params);
52✔
557

558
      return std::make_unique<SphincsPlus_PrivateKey>(rng, sphincs_params);
52✔
559
   }
560
#endif
561

562
#if defined(BOTAN_HAS_XMSS_RFC8391)
563
   if(alg_name == "XMSS") {
227✔
564
      const auto xmss_oid = [&]() -> XMSS_Parameters::xmss_algorithm_t {
24✔
565
         if(params.empty()) {
8✔
566
            return XMSS_Parameters::XMSS_SHA2_10_512;
567
         }
568
         return XMSS_Parameters(params).oid();
14✔
569
      }();
8✔
570

571
      return std::make_unique<XMSS_PrivateKey>(xmss_oid, rng);
8✔
572
   }
573
#endif
574

575
#if defined(BOTAN_HAS_ED25519)
576
   if(alg_name == "Ed25519") {
219✔
577
      return std::make_unique<Ed25519_PrivateKey>(rng);
26✔
578
   }
579
#endif
580

581
#if defined(BOTAN_HAS_ED448)
582
   if(alg_name == "Ed448") {
206✔
583
      return std::make_unique<Ed448_PrivateKey>(rng);
26✔
584
   }
585
#endif
586

587
   // ECC crypto
588
#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
589

590
   if(alg_name == "ECDSA" || alg_name == "ECDH" || alg_name == "ECKCDSA" || alg_name == "ECGDSA" || alg_name == "SM2" ||
359✔
591
      alg_name == "SM2_Sig" || alg_name == "SM2_Enc" || alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" ||
79✔
592
      alg_name == "GOST-34.10-2012-512") {
36✔
593
      const std::string group_id = [&]() -> std::string {
471✔
594
         if(!params.empty()) {
157✔
595
            return std::string(params);
148✔
596
         }
597
         if(alg_name == "SM2" || alg_name == "SM2_Enc" || alg_name == "SM2_Sig") {
9✔
598
            return "sm2p256v1";
×
599
         }
600
         if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256") {
9✔
601
            return "gost_256A";
×
602
         }
603
         if(alg_name == "GOST-34.10-2012-512") {
9✔
604
            return "gost_512A";
×
605
         }
606
         if(alg_name == "ECGDSA") {
9✔
607
            return "brainpool256r1";
×
608
         }
609
         return "secp256r1";
9✔
610
      }();
157✔
611

612
      auto ec_group = EC_Group::from_name(group_id);
157✔
613
      return create_ec_private_key(alg_name, ec_group, rng);
157✔
614
   }
157✔
615
#endif
616

617
   // DL crypto
618
#if defined(BOTAN_HAS_DL_GROUP)
619
   if(alg_name == "DH" || alg_name == "DSA" || alg_name == "ElGamal") {
72✔
620
      const std::string group_id = [&]() -> std::string {
108✔
621
         if(!params.empty()) {
36✔
622
            return std::string(params);
26✔
623
         }
624
         if(alg_name == "DSA") {
10✔
625
            return "dsa/botan/2048";
8✔
626
         }
627
         return "modp/ietf/2048";
2✔
628
      }();
36✔
629

630
      DL_Group modp_group(group_id);
36✔
631

632
   #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
633
      if(alg_name == "DH") {
36✔
634
         return std::make_unique<DH_PrivateKey>(rng, modp_group);
30✔
635
      }
636
   #endif
637

638
   #if defined(BOTAN_HAS_DSA)
639
      if(alg_name == "DSA") {
21✔
640
         return std::make_unique<DSA_PrivateKey>(rng, modp_group);
28✔
641
      }
642
   #endif
643

644
   #if defined(BOTAN_HAS_ELGAMAL)
645
      if(alg_name == "ElGamal") {
7✔
646
         return std::make_unique<ElGamal_PrivateKey>(rng, modp_group);
14✔
647
      }
648
   #endif
649
   }
36✔
650
#endif
651

652
   BOTAN_UNUSED(alg_name, rng, params, provider);
×
653

654
   return std::unique_ptr<Private_Key>();
×
655
}
656

657
std::vector<std::string> probe_provider_private_key(std::string_view alg_name,
110✔
658
                                                    const std::vector<std::string>& possible) {
659
   std::vector<std::string> providers;
110✔
660

661
   for(auto&& prov : possible) {
550✔
662
      if(prov == "base") {
440✔
663
         providers.push_back(prov);
110✔
664
      }
665
   }
666

667
   BOTAN_UNUSED(alg_name);
110✔
668

669
   return providers;
110✔
670
}
×
671
}  // 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