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

randombit / botan / 11327544235

14 Oct 2024 12:28PM UTC coverage: 91.125% (+0.005%) from 91.12%
11327544235

Pull #3893

github

web-flow
Merge a2498c19d into ed74c9542
Pull Request #3893: PQC: ML-KEM

90382 of 99185 relevant lines covered (91.12%)

9134193.3 hits per line

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

95.33
/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) || defined(BOTAN_HAS_ML_KEM)
82
   #include <botan/kyber.h>
83
#endif
84

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

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

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

97
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
98
   #include <botan/dilithium.h>
99
#endif
100

101
#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
102
   #include <botan/sphincsplus.h>
103
#endif
104

105
namespace Botan {
106

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

113
#if defined(BOTAN_HAS_RSA)
114
   if(alg_name == "RSA") {
22,196✔
115
      return std::make_unique<RSA_PublicKey>(alg_id, key_bits);
32,029✔
116
   }
117
#endif
118

119
#if defined(BOTAN_HAS_X25519)
120
   if(alg_name == "X25519" || alg_name == "Curve25519") {
5,867✔
121
      return std::make_unique<X25519_PublicKey>(alg_id, key_bits);
48✔
122
   }
123
#endif
124

125
#if defined(BOTAN_HAS_X448)
126
   if(alg_name == "X448") {
5,746✔
127
      return std::make_unique<X448_PublicKey>(alg_id, key_bits);
4✔
128
   }
129
#endif
130

131
#if defined(BOTAN_HAS_MCELIECE)
132
   if(alg_name == "McEliece") {
5,744✔
133
      return std::make_unique<McEliece_PublicKey>(key_bits);
2✔
134
   }
135
#endif
136

137
#if defined(BOTAN_HAS_FRODOKEM)
138
   if(alg_name == "FrodoKEM" || alg_name.starts_with("FrodoKEM-") || alg_name.starts_with("eFrodoKEM-")) {
5,744✔
139
      return std::make_unique<FrodoKEM_PublicKey>(alg_id, key_bits);
632✔
140
   }
141
#endif
142

143
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S) || defined(BOTAN_HAS_ML_KEM)
144
   if(alg_name.starts_with("ML-KEM-") || alg_name == "Kyber" || alg_name.starts_with("Kyber-")) {
9,097✔
145
      return std::make_unique<Kyber_PublicKey>(alg_id, key_bits);
490✔
146
   }
147
#endif
148

149
#if defined(BOTAN_HAS_ECDSA)
150
   if(alg_name == "ECDSA") {
5,182✔
151
      return std::make_unique<ECDSA_PublicKey>(alg_id, key_bits);
7,015✔
152
   }
153
#endif
154

155
#if defined(BOTAN_HAS_ECDH)
156
   if(alg_name == "ECDH") {
1,586✔
157
      return std::make_unique<ECDH_PublicKey>(alg_id, key_bits);
33✔
158
   }
159
#endif
160

161
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
162
   if(alg_name == "DH") {
1,569✔
163
      return std::make_unique<DH_PublicKey>(alg_id, key_bits);
11✔
164
   }
165
#endif
166

167
#if defined(BOTAN_HAS_DSA)
168
   if(alg_name == "DSA") {
1,561✔
169
      return std::make_unique<DSA_PublicKey>(alg_id, key_bits);
355✔
170
   }
171
#endif
172

173
#if defined(BOTAN_HAS_ELGAMAL)
174
   if(alg_name == "ElGamal") {
1,327✔
175
      return std::make_unique<ElGamal_PublicKey>(alg_id, key_bits);
8✔
176
   }
177
#endif
178

179
#if defined(BOTAN_HAS_ECGDSA)
180
   if(alg_name == "ECGDSA") {
1,323✔
181
      return std::make_unique<ECGDSA_PublicKey>(alg_id, key_bits);
146✔
182
   }
183
#endif
184

185
#if defined(BOTAN_HAS_ECKCDSA)
186
   if(alg_name == "ECKCDSA") {
1,250✔
187
      return std::make_unique<ECKCDSA_PublicKey>(alg_id, key_bits);
144✔
188
   }
189
#endif
190

191
#if defined(BOTAN_HAS_ED25519)
192
   if(alg_name == "Ed25519") {
1,178✔
193
      return std::make_unique<Ed25519_PublicKey>(alg_id, key_bits);
1,528✔
194
   }
195
#endif
196

197
#if defined(BOTAN_HAS_ED448)
198
   if(alg_name == "Ed448") {
414✔
199
      return std::make_unique<Ed448_PublicKey>(alg_id, key_bits);
146✔
200
   }
201
#endif
202

203
#if defined(BOTAN_HAS_GOST_34_10_2001)
204
   if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" || alg_name == "GOST-34.10-2012-512") {
413✔
205
      return std::make_unique<GOST_3410_PublicKey>(alg_id, key_bits);
132✔
206
   }
207
#endif
208

209
#if defined(BOTAN_HAS_SM2)
210
   if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") {
343✔
211
      return std::make_unique<SM2_PublicKey>(alg_id, key_bits);
30✔
212
   }
213
#endif
214

215
#if defined(BOTAN_HAS_XMSS_RFC8391)
216
   if(alg_name == "XMSS") {
260✔
217
      return std::make_unique<XMSS_PublicKey>(key_bits);
88✔
218
   }
219
#endif
220

221
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
222
   if(alg_name == "Dilithium" || alg_name.starts_with("Dilithium-")) {
218✔
223
      return std::make_unique<Dilithium_PublicKey>(alg_id, key_bits);
168✔
224
   }
225
#endif
226

227
#if defined(BOTAN_HAS_HSS_LMS)
228
   if(alg_name == "HSS-LMS") {
132✔
229
      return std::make_unique<HSS_LMS_PublicKey>(key_bits);
106✔
230
   }
231
#endif
232

233
#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
234
   if(alg_name == "SPHINCS+" || alg_name.starts_with("SphincsPlus-")) {
80✔
235
      return std::make_unique<SphincsPlus_PublicKey>(alg_id, key_bits);
50✔
236
   }
237
#endif
238

239
   throw Decoding_Error(fmt("Unknown or unavailable public key algorithm '{}'", alg_name));
108✔
240
}
22,196✔
241

242
std::unique_ptr<Private_Key> load_private_key(const AlgorithmIdentifier& alg_id,
4,765✔
243
                                              [[maybe_unused]] std::span<const uint8_t> key_bits) {
244
   const std::string oid_str = alg_id.oid().to_formatted_string();
4,765✔
245
   const std::vector<std::string> alg_info = split_on(oid_str, '/');
4,765✔
246
   std::string_view alg_name = alg_info[0];
4,765✔
247

248
#if defined(BOTAN_HAS_RSA)
249
   if(alg_name == "RSA") {
4,765✔
250
      return std::make_unique<RSA_PrivateKey>(alg_id, key_bits);
2,086✔
251
   }
252
#endif
253

254
#if defined(BOTAN_HAS_X25519)
255
   if(alg_name == "X25519" || alg_name == "Curve25519") {
2,725✔
256
      return std::make_unique<X25519_PrivateKey>(alg_id, key_bits);
54✔
257
   }
258
#endif
259

260
#if defined(BOTAN_HAS_X448)
261
   if(alg_name == "X448") {
2,651✔
262
      return std::make_unique<X448_PrivateKey>(alg_id, key_bits);
12✔
263
   }
264
#endif
265

266
#if defined(BOTAN_HAS_ECDSA)
267
   if(alg_name == "ECDSA") {
2,645✔
268
      return std::make_unique<ECDSA_PrivateKey>(alg_id, key_bits);
1,528✔
269
   }
270
#endif
271

272
#if defined(BOTAN_HAS_ECDH)
273
   if(alg_name == "ECDH") {
1,445✔
274
      return std::make_unique<ECDH_PrivateKey>(alg_id, key_bits);
184✔
275
   }
276
#endif
277

278
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
279
   if(alg_name == "DH") {
1,323✔
280
      return std::make_unique<DH_PrivateKey>(alg_id, key_bits);
67✔
281
   }
282
#endif
283

284
#if defined(BOTAN_HAS_DSA)
285
   if(alg_name == "DSA") {
1,283✔
286
      return std::make_unique<DSA_PrivateKey>(alg_id, key_bits);
373✔
287
   }
288
#endif
289

290
#if defined(BOTAN_HAS_FRODOKEM)
291
   if(alg_name == "FrodoKEM" || alg_name.starts_with("FrodoKEM-") || alg_name.starts_with("eFrodoKEM-")) {
971✔
292
      return std::make_unique<FrodoKEM_PrivateKey>(alg_id, key_bits);
348✔
293
   }
294
#endif
295

296
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S) || defined(BOTAN_HAS_ML_KEM)
297
   if(alg_name.starts_with("ML-KEM-") || alg_name == "Kyber" || alg_name.starts_with("Kyber-")) {
637✔
298
      return std::make_unique<Kyber_PrivateKey>(alg_id, key_bits);
304✔
299
   }
300
#endif
301

302
#if defined(BOTAN_HAS_MCELIECE)
303
   if(alg_name == "McEliece") {
315✔
304
      return std::make_unique<McEliece_PrivateKey>(key_bits);
4✔
305
   }
306
#endif
307

308
#if defined(BOTAN_HAS_ECGDSA)
309
   if(alg_name == "ECGDSA") {
311✔
310
      return std::make_unique<ECGDSA_PrivateKey>(alg_id, key_bits);
36✔
311
   }
312
#endif
313

314
#if defined(BOTAN_HAS_ECKCDSA)
315
   if(alg_name == "ECKCDSA") {
293✔
316
      return std::make_unique<ECKCDSA_PrivateKey>(alg_id, key_bits);
36✔
317
   }
318
#endif
319

320
#if defined(BOTAN_HAS_ED25519)
321
   if(alg_name == "Ed25519") {
275✔
322
      return std::make_unique<Ed25519_PrivateKey>(alg_id, key_bits);
17✔
323
   }
324
#endif
325

326
#if defined(BOTAN_HAS_ED448)
327
   if(alg_name == "Ed448") {
265✔
328
      return std::make_unique<Ed448_PrivateKey>(alg_id, key_bits);
36✔
329
   }
330
#endif
331

332
#if defined(BOTAN_HAS_GOST_34_10_2001)
333
   if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" || alg_name == "GOST-34.10-2012-512") {
268✔
334
      return std::make_unique<GOST_3410_PrivateKey>(alg_id, key_bits);
24✔
335
   }
336
#endif
337

338
#if defined(BOTAN_HAS_SM2)
339
   if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") {
269✔
340
      return std::make_unique<SM2_PrivateKey>(alg_id, key_bits);
40✔
341
   }
342
#endif
343

344
#if defined(BOTAN_HAS_ELGAMAL)
345
   if(alg_name == "ElGamal") {
215✔
346
      return std::make_unique<ElGamal_PrivateKey>(alg_id, key_bits);
28✔
347
   }
348
#endif
349

350
#if defined(BOTAN_HAS_XMSS_RFC8391)
351
   if(alg_name == "XMSS") {
201✔
352
      return std::make_unique<XMSS_PrivateKey>(key_bits);
19✔
353
   }
354
#endif
355

356
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
357
   if(alg_name == "Dilithium" || alg_name.starts_with("Dilithium-")) {
192✔
358
      return std::make_unique<Dilithium_PrivateKey>(alg_id, key_bits);
55✔
359
   }
360
#endif
361

362
#if defined(BOTAN_HAS_HSS_LMS)
363
   if(alg_name == "HSS-LMS-Private-Key") {
127✔
364
      return std::make_unique<HSS_LMS_PrivateKey>(key_bits);
6✔
365
   }
366
#endif
367

368
#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
369
   if(alg_name == "SPHINCS+" || alg_name.starts_with("SphincsPlus-")) {
121✔
370
      return std::make_unique<SphincsPlus_PrivateKey>(alg_id, key_bits);
72✔
371
   }
372
#endif
373

374
   throw Decoding_Error(fmt("Unknown or unavailable public key algorithm '{}'", alg_name));
98✔
375
}
4,765✔
376

377
std::unique_ptr<Private_Key> create_ec_private_key(std::string_view alg_name,
157✔
378
                                                   const EC_Group& ec_group,
379
                                                   RandomNumberGenerator& rng) {
380
   // Potentially unused if all EC algorithms are disabled
381
   BOTAN_UNUSED(alg_name, ec_group, rng);
157✔
382

383
#if defined(BOTAN_HAS_ECDSA)
384
   if(alg_name == "ECDSA") {
157✔
385
      return std::make_unique<ECDSA_PrivateKey>(rng, ec_group);
144✔
386
   }
387
#endif
388

389
#if defined(BOTAN_HAS_ECDH)
390
   if(alg_name == "ECDH") {
85✔
391
      return std::make_unique<ECDH_PrivateKey>(rng, ec_group);
58✔
392
   }
393
#endif
394

395
#if defined(BOTAN_HAS_ECKCDSA)
396
   if(alg_name == "ECKCDSA") {
56✔
397
      return std::make_unique<ECKCDSA_PrivateKey>(rng, ec_group);
36✔
398
   }
399
#endif
400

401
#if defined(BOTAN_HAS_GOST_34_10_2001)
402
   if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" || alg_name == "GOST-34.10-2012-512") {
50✔
403
      return std::make_unique<GOST_3410_PrivateKey>(rng, ec_group);
24✔
404
   }
405
#endif
406

407
#if defined(BOTAN_HAS_SM2)
408
   if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") {
35✔
409
      return std::make_unique<SM2_PrivateKey>(rng, ec_group);
16✔
410
   }
411
#endif
412

413
#if defined(BOTAN_HAS_ECGDSA)
414
   if(alg_name == "ECGDSA") {
18✔
415
      return std::make_unique<ECGDSA_PrivateKey>(rng, ec_group);
36✔
416
   }
417
#endif
418

419
   return nullptr;
×
420
}
421

422
std::unique_ptr<Private_Key> create_private_key(std::string_view alg_name,
992✔
423
                                                RandomNumberGenerator& rng,
424
                                                std::string_view params,
425
                                                std::string_view provider) {
426
   /*
427
   * Default paramaters are chosen for work factor > 2**128 where possible
428
   */
429

430
#if defined(BOTAN_HAS_X25519)
431
   if(alg_name == "X25519" || alg_name == "Curve25519") {
1,172✔
432
      return std::make_unique<X25519_PrivateKey>(rng);
16✔
433
   }
434
#endif
435

436
#if defined(BOTAN_HAS_X448)
437
   if(alg_name == "X448") {
984✔
438
      return std::make_unique<X448_PrivateKey>(rng);
10✔
439
   }
440
#endif
441

442
#if defined(BOTAN_HAS_RSA)
443
   if(alg_name == "RSA") {
979✔
444
      const size_t modulus_bits = params.empty() ? 3072 : to_u32bit(params);
51✔
445
      return std::make_unique<RSA_PrivateKey>(rng, modulus_bits);
51✔
446
   }
447
#endif
448

449
#if defined(BOTAN_HAS_MCELIECE)
450
   if(alg_name == "McEliece") {
928✔
451
      const auto [n, t] = [&]() -> std::pair<size_t, size_t> {
2✔
452
         if(params.empty()) {
2✔
453
            return {2960, 57};
×
454
         }
455

456
         const auto mce_params = split_on(params, ',');
2✔
457

458
         if(mce_params.size() != 2) {
2✔
459
            throw Invalid_Argument(fmt("create_private_key: invalid McEliece parameters '{}'", params));
×
460
         }
461

462
         const size_t mce_n = to_u32bit(mce_params[0]);
2✔
463
         const size_t mce_t = to_u32bit(mce_params[1]);
2✔
464
         return {mce_n, mce_t};
2✔
465
      }();
4✔
466

467
      return std::make_unique<McEliece_PrivateKey>(rng, n, t);
2✔
468
   }
469
#endif
470

471
#if defined(BOTAN_HAS_FRODOKEM)
472
   if(alg_name == "FrodoKEM") {
926✔
473
      const auto mode = params.empty() ? FrodoKEMMode::FrodoKEM976_SHAKE : FrodoKEMMode(params);
309✔
474
      return std::make_unique<FrodoKEM_PrivateKey>(rng, mode);
309✔
475
   }
476
#endif
477

478
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
479
   if(alg_name == "Kyber") {
617✔
480
      const auto mode = [&]() -> KyberMode {
513✔
481
         if(params.empty()) {
171✔
482
            return KyberMode::Kyber1024_R3;
1✔
483
         }
484
         return KyberMode(params);
170✔
485
      }();
171✔
486

487
      return std::make_unique<Kyber_PrivateKey>(rng, mode);
171✔
488
   }
489
#endif
490

491
#if defined(BOTAN_HAS_ML_KEM)
492
   if(alg_name == "ML-KEM") {
446✔
493
      const auto mode = [&]() -> KyberMode {
462✔
494
         if(params.empty()) {
154✔
495
            return KyberMode::ML_KEM_768;
1✔
496
         }
497
         return KyberMode(params);
153✔
498
      }();
154✔
499

500
      return std::make_unique<Kyber_PrivateKey>(rng, mode);
154✔
501
   }
502
#endif
503

504
#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
505
   if(alg_name == "Dilithium" || alg_name == "Dilithium-") {
317✔
506
      const auto mode = [&]() -> DilithiumMode {
25✔
507
         if(params.empty()) {
25✔
508
            return DilithiumMode::Dilithium6x5;
509
         }
510
         return DilithiumMode(params);
17✔
511
      }();
25✔
512

513
      return std::make_unique<Dilithium_PrivateKey>(rng, mode);
25✔
514
   }
515
#endif
516

517
#if defined(BOTAN_HAS_HSS_LMS)
518
   if(alg_name == "HSS-LMS") {
267✔
519
      return std::make_unique<HSS_LMS_PrivateKey>(rng, params);
15✔
520
   }
521
#endif
522

523
#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
524
   if(alg_name == "SPHINCS+" || alg_name == "SphincsPlus-") {
277✔
525
      auto sphincs_params = Sphincs_Parameters::create(params);
25✔
526

527
      return std::make_unique<SphincsPlus_PrivateKey>(rng, sphincs_params);
25✔
528
   }
529
#endif
530

531
#if defined(BOTAN_HAS_XMSS_RFC8391)
532
   if(alg_name == "XMSS") {
227✔
533
      const auto xmss_oid = [&]() -> XMSS_Parameters::xmss_algorithm_t {
24✔
534
         if(params.empty()) {
8✔
535
            return XMSS_Parameters::XMSS_SHA2_10_512;
536
         }
537
         return XMSS_Parameters(params).oid();
14✔
538
      }();
8✔
539

540
      return std::make_unique<XMSS_PrivateKey>(xmss_oid, rng);
8✔
541
   }
542
#endif
543

544
#if defined(BOTAN_HAS_ED25519)
545
   if(alg_name == "Ed25519") {
219✔
546
      return std::make_unique<Ed25519_PrivateKey>(rng);
26✔
547
   }
548
#endif
549

550
#if defined(BOTAN_HAS_ED448)
551
   if(alg_name == "Ed448") {
206✔
552
      return std::make_unique<Ed448_PrivateKey>(rng);
26✔
553
   }
554
#endif
555

556
   // ECC crypto
557
#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
558

559
   if(alg_name == "ECDSA" || alg_name == "ECDH" || alg_name == "ECKCDSA" || alg_name == "ECGDSA" || alg_name == "SM2" ||
359✔
560
      alg_name == "SM2_Sig" || alg_name == "SM2_Enc" || alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" ||
79✔
561
      alg_name == "GOST-34.10-2012-512") {
36✔
562
      const std::string group_id = [&]() -> std::string {
471✔
563
         if(!params.empty()) {
157✔
564
            return std::string(params);
148✔
565
         }
566
         if(alg_name == "SM2" || alg_name == "SM2_Enc" || alg_name == "SM2_Sig") {
9✔
567
            return "sm2p256v1";
×
568
         }
569
         if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256") {
9✔
570
            return "gost_256A";
×
571
         }
572
         if(alg_name == "GOST-34.10-2012-512") {
9✔
573
            return "gost_512A";
×
574
         }
575
         if(alg_name == "ECGDSA") {
9✔
576
            return "brainpool256r1";
×
577
         }
578
         return "secp256r1";
9✔
579
      }();
157✔
580

581
      auto ec_group = EC_Group::from_name(group_id);
157✔
582
      return create_ec_private_key(alg_name, ec_group, rng);
157✔
583
   }
157✔
584
#endif
585

586
   // DL crypto
587
#if defined(BOTAN_HAS_DL_GROUP)
588
   if(alg_name == "DH" || alg_name == "DSA" || alg_name == "ElGamal") {
72✔
589
      const std::string group_id = [&]() -> std::string {
108✔
590
         if(!params.empty()) {
36✔
591
            return std::string(params);
26✔
592
         }
593
         if(alg_name == "DSA") {
10✔
594
            return "dsa/botan/2048";
8✔
595
         }
596
         return "modp/ietf/2048";
2✔
597
      }();
36✔
598

599
      DL_Group modp_group(group_id);
36✔
600

601
   #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
602
      if(alg_name == "DH") {
36✔
603
         return std::make_unique<DH_PrivateKey>(rng, modp_group);
30✔
604
      }
605
   #endif
606

607
   #if defined(BOTAN_HAS_DSA)
608
      if(alg_name == "DSA") {
21✔
609
         return std::make_unique<DSA_PrivateKey>(rng, modp_group);
28✔
610
      }
611
   #endif
612

613
   #if defined(BOTAN_HAS_ELGAMAL)
614
      if(alg_name == "ElGamal") {
7✔
615
         return std::make_unique<ElGamal_PrivateKey>(rng, modp_group);
14✔
616
      }
617
   #endif
618
   }
36✔
619
#endif
620

621
   BOTAN_UNUSED(alg_name, rng, params, provider);
×
622

623
   return std::unique_ptr<Private_Key>();
×
624
}
625

626
std::vector<std::string> probe_provider_private_key(std::string_view alg_name,
95✔
627
                                                    const std::vector<std::string>& possible) {
628
   std::vector<std::string> providers;
95✔
629

630
   for(auto&& prov : possible) {
475✔
631
      if(prov == "base") {
380✔
632
         providers.push_back(prov);
95✔
633
      }
634
   }
635

636
   BOTAN_UNUSED(alg_name);
95✔
637

638
   return providers;
95✔
639
}
×
640
}  // 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

© 2025 Coveralls, Inc