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

randombit / botan / 20882978085

10 Jan 2026 07:03PM UTC coverage: 90.42% (-0.01%) from 90.43%
20882978085

push

github

web-flow
Merge pull request #5225 from arckoor/rsa-pkcs1-pubkey

Add RSA PKCS#1 pubkey loader

101694 of 112468 relevant lines covered (90.42%)

13017398.54 hits per line

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

96.53
/src/lib/ffi/ffi_pkey_algs.cpp
1
/*
2
* (C) 2015,2017 Jack Lloyd
3
* (C) 2017 Ribose Inc
4
* (C) 2018 René Korthaus, Rohde & Schwarz Cybersecurity
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8

9
#include <botan/ffi.h>
10

11
#include <botan/hash.h>
12
#include <botan/pem.h>
13
#include <botan/internal/ffi_mp.h>
14
#include <botan/internal/ffi_pkey.h>
15
#include <botan/internal/ffi_rng.h>
16
#include <botan/internal/ffi_util.h>
17

18
#if defined(BOTAN_HAS_DL_GROUP)
19
   #include <botan/dl_group.h>
20
#endif
21

22
#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
23
   #include <botan/ecc_key.h>
24
#endif
25

26
#if defined(BOTAN_HAS_RSA)
27
   #include <botan/rsa.h>
28
#endif
29

30
#if defined(BOTAN_HAS_ELGAMAL)
31
   #include <botan/elgamal.h>
32
#endif
33

34
#if defined(BOTAN_HAS_DSA)
35
   #include <botan/dsa.h>
36
#endif
37

38
#if defined(BOTAN_HAS_ECDSA)
39
   #include <botan/ecdsa.h>
40
#endif
41

42
#if defined(BOTAN_HAS_SM2)
43
   #include <botan/sm2.h>
44
#endif
45

46
#if defined(BOTAN_HAS_ECDH)
47
   #include <botan/ecdh.h>
48
#endif
49

50
#if defined(BOTAN_HAS_X25519)
51
   #include <botan/x25519.h>
52
#endif
53

54
#if defined(BOTAN_HAS_X448)
55
   #include <botan/x448.h>
56
#endif
57

58
#if defined(BOTAN_HAS_ED25519)
59
   #include <botan/ed25519.h>
60
#endif
61

62
#if defined(BOTAN_HAS_ED448)
63
   #include <botan/ed448.h>
64
#endif
65

66
#if defined(BOTAN_HAS_MCELIECE)
67
   #include <botan/mceliece.h>
68
#endif
69

70
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
71
   #include <botan/dh.h>
72
#endif
73

74
#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
75
   #include <botan/kyber.h>
76
#endif
77

78
#if defined(BOTAN_HAS_ML_KEM)
79
   #include <botan/ml_kem.h>
80
#endif
81

82
#if defined(BOTAN_HAS_FRODOKEM)
83
   #include <botan/frodokem.h>
84
#endif
85

86
#if defined(BOTAN_HAS_ML_DSA)
87
   #include <botan/ml_dsa.h>
88
#endif
89

90
#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
91
   #include <botan/slh_dsa.h>
92
#endif
93

94
#if defined(BOTAN_HAS_CLASSICMCELIECE)
95
   #include <botan/cmce.h>
96
#endif
97

98
namespace {
99

100
#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
101

102
// These are always called within an existing try/catch block
103

104
template <class ECPrivateKey_t>
105
int privkey_load_ec(std::unique_ptr<ECPrivateKey_t>& key, const Botan::BigInt& scalar, const char* curve_name) {
9✔
106
   if(curve_name == nullptr) {
9✔
107
      return BOTAN_FFI_ERROR_NULL_POINTER;
108
   }
109
   if(!Botan::EC_Group::supports_named_group(curve_name)) {
9✔
110
      return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
111
   }
112

113
   Botan::Null_RNG null_rng;
9✔
114
   const auto grp = Botan::EC_Group::from_name(curve_name);
9✔
115
   key.reset(new ECPrivateKey_t(null_rng, grp, scalar));
9✔
116
   return BOTAN_FFI_SUCCESS;
117
}
9✔
118

119
template <class ECPublicKey_t>
120
int pubkey_load_ec(std::unique_ptr<ECPublicKey_t>& key,
6✔
121
                   const Botan::BigInt& public_x,
122
                   const Botan::BigInt& public_y,
123
                   const char* curve_name) {
124
   if(curve_name == nullptr) {
6✔
125
      return BOTAN_FFI_ERROR_NULL_POINTER;
126
   }
127

128
   if(!Botan::EC_Group::supports_named_group(curve_name)) {
6✔
129
      return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
130
   }
131

132
   const auto group = Botan::EC_Group::from_name(curve_name);
6✔
133

134
   if(auto pt = Botan::EC_AffinePoint::from_bigint_xy(group, public_x, public_y)) {
6✔
135
      key.reset(new ECPublicKey_t(group, pt.value()));
6✔
136
      return BOTAN_FFI_SUCCESS;
6✔
137
   } else {
138
      return BOTAN_FFI_ERROR_BAD_PARAMETER;
139
   }
140
}
6✔
141

142
template <class ECPublicKey_t>
143
int pubkey_load_ec_sec1(std::unique_ptr<ECPublicKey_t>& key,
14✔
144
                        std::span<const uint8_t> sec1,
145
                        std::string_view curve_name) {
146
   if(!Botan::EC_Group::supports_named_group(curve_name)) {
14✔
147
      return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
148
   }
149

150
   const auto group = Botan::EC_Group::from_name(curve_name);
14✔
151

152
   if(auto pt = Botan::EC_AffinePoint::deserialize(group, sec1)) {
14✔
153
      key.reset(new ECPublicKey_t(group, pt.value()));
14✔
154
      return BOTAN_FFI_SUCCESS;
14✔
155
   } else {
156
      return BOTAN_FFI_ERROR_BAD_PARAMETER;
157
   }
158
}
14✔
159

160
#endif
161

162
Botan::BigInt pubkey_get_field(const Botan::Public_Key& key, std::string_view field) {
40✔
163
#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
164
   // Not currently handled by get_int_field
165
   if(const Botan::EC_PublicKey* ecc = dynamic_cast<const Botan::EC_PublicKey*>(&key)) {
40✔
166
      if(field == "public_x") {
15✔
167
         return Botan::BigInt::from_bytes(ecc->_public_ec_point().x_bytes());
16✔
168
      } else if(field == "public_y") {
7✔
169
         return Botan::BigInt::from_bytes(ecc->_public_ec_point().y_bytes());
12✔
170
      }
171
   }
172
#endif
173

174
   try {
26✔
175
      return key.get_int_field(field);
26✔
176
   } catch(Botan::Unknown_PK_Field_Name&) {
2✔
177
      throw Botan_FFI::FFI_Error("Unknown key field", BOTAN_FFI_ERROR_BAD_PARAMETER);
2✔
178
   }
2✔
179
}
180

181
Botan::BigInt privkey_get_field(const Botan::Private_Key& key, std::string_view field) {
35✔
182
#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
183
   // Not currently handled by get_int_field
184
   if(const Botan::EC_PublicKey* ecc = dynamic_cast<const Botan::EC_PublicKey*>(&key)) {
35✔
185
      if(field == "public_x") {
16✔
186
         return Botan::BigInt::from_bytes(ecc->_public_ec_point().x_bytes());
4✔
187
      } else if(field == "public_y") {
14✔
188
         return Botan::BigInt::from_bytes(ecc->_public_ec_point().y_bytes());
8✔
189
      }
190
   }
191
#endif
192

193
   try {
29✔
194
      return key.get_int_field(field);
29✔
195
   } catch(Botan::Unknown_PK_Field_Name&) {
4✔
196
      throw Botan_FFI::FFI_Error("Unknown key field", BOTAN_FFI_ERROR_BAD_PARAMETER);
4✔
197
   }
4✔
198
}
199

200
}  // namespace
201

202
extern "C" {
203

204
using namespace Botan_FFI;
205

206
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char* field_name_cstr) {
40✔
207
   if(field_name_cstr == nullptr) {
40✔
208
      return BOTAN_FFI_ERROR_NULL_POINTER;
209
   }
210

211
   const std::string field_name(field_name_cstr);
40✔
212

213
   return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); });
158✔
214
}
40✔
215

216
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char* field_name_cstr) {
35✔
217
   if(field_name_cstr == nullptr) {
35✔
218
      return BOTAN_FFI_ERROR_NULL_POINTER;
219
   }
220

221
   const std::string field_name(field_name_cstr);
35✔
222

223
   return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); });
136✔
224
}
35✔
225

226
/* RSA specific operations */
227

228
int botan_privkey_create_rsa(botan_privkey_t* key_obj, botan_rng_t rng_obj, size_t n_bits) {
2✔
229
   if(n_bits < 1024 || n_bits > 16 * 1024) {
2✔
230
      return BOTAN_FFI_ERROR_BAD_PARAMETER;
231
   }
232

233
   const std::string n_str = std::to_string(n_bits);
2✔
234

235
   return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
2✔
236
}
2✔
237

238
int botan_privkey_load_rsa(botan_privkey_t* key, botan_mp_t rsa_p, botan_mp_t rsa_q, botan_mp_t rsa_e) {
2✔
239
#if defined(BOTAN_HAS_RSA)
240
   if(key == nullptr) {
2✔
241
      return BOTAN_FFI_ERROR_NULL_POINTER;
242
   }
243
   *key = nullptr;
2✔
244

245
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
246
      auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p), safe_get(rsa_q), safe_get(rsa_e));
2✔
247
      return ffi_new_object(key, std::move(rsa));
4✔
248
   });
4✔
249
#else
250
   BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
251
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
252
#endif
253
}
254

255
int botan_privkey_load_rsa_pkcs1(botan_privkey_t* key, const uint8_t bits[], size_t len) {
1✔
256
#if defined(BOTAN_HAS_RSA)
257
   if(key == nullptr || bits == nullptr) {
1✔
258
      return BOTAN_FFI_ERROR_NULL_POINTER;
259
   }
260
   *key = nullptr;
1✔
261

262
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
263
      const Botan::AlgorithmIdentifier alg_id("RSA", Botan::AlgorithmIdentifier::USE_NULL_PARAM);
1✔
264
      auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, std::span{bits, len});
1✔
265
      return ffi_new_object(key, std::move(rsa));
2✔
266
   });
2✔
267
#else
268
   BOTAN_UNUSED(key, bits, len);
269
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
270
#endif
271
}
272

273
int botan_pubkey_load_rsa(botan_pubkey_t* key, botan_mp_t n, botan_mp_t e) {
4✔
274
#if defined(BOTAN_HAS_RSA)
275
   if(key == nullptr) {
4✔
276
      return BOTAN_FFI_ERROR_NULL_POINTER;
277
   }
278
   *key = nullptr;
4✔
279
   return ffi_guard_thunk(__func__, [=]() -> int {
4✔
280
      auto rsa = std::make_unique<Botan::RSA_PublicKey>(safe_get(n), safe_get(e));
4✔
281
      return ffi_new_object(key, std::move(rsa));
3✔
282
   });
7✔
283
#else
284
   BOTAN_UNUSED(key, n, e);
285
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
286
#endif
287
}
288

289
int botan_pubkey_load_rsa_pkcs1(botan_pubkey_t* key, const uint8_t bits[], size_t len) {
×
290
#if defined(BOTAN_HAS_RSA)
291
   if(key == nullptr || bits == nullptr) {
×
292
      return BOTAN_FFI_ERROR_NULL_POINTER;
293
   }
294
   *key = nullptr;
×
295

296
   return ffi_guard_thunk(__func__, [=]() -> int {
×
297
      const Botan::AlgorithmIdentifier alg_id("RSA", Botan::AlgorithmIdentifier::USE_NULL_PARAM);
×
298
      auto rsa = std::make_unique<Botan::RSA_PublicKey>(alg_id, std::span{bits, len});
×
299
      return ffi_new_object(key, std::move(rsa));
×
300
   });
×
301
#else
302
   BOTAN_UNUSED(key, bits, len);
303
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
304
#endif
305
}
306

307
int botan_privkey_rsa_get_p(botan_mp_t p, botan_privkey_t key) {
1✔
308
   return botan_privkey_get_field(p, key, "p");
1✔
309
}
310

311
int botan_privkey_rsa_get_q(botan_mp_t q, botan_privkey_t key) {
1✔
312
   return botan_privkey_get_field(q, key, "q");
1✔
313
}
314

315
int botan_privkey_rsa_get_n(botan_mp_t n, botan_privkey_t key) {
1✔
316
   return botan_privkey_get_field(n, key, "n");
1✔
317
}
318

319
int botan_privkey_rsa_get_e(botan_mp_t e, botan_privkey_t key) {
1✔
320
   return botan_privkey_get_field(e, key, "e");
1✔
321
}
322

323
int botan_privkey_rsa_get_d(botan_mp_t d, botan_privkey_t key) {
1✔
324
   return botan_privkey_get_field(d, key, "d");
1✔
325
}
326

327
int botan_pubkey_rsa_get_e(botan_mp_t e, botan_pubkey_t key) {
1✔
328
   return botan_pubkey_get_field(e, key, "e");
1✔
329
}
330

331
int botan_pubkey_rsa_get_n(botan_mp_t n, botan_pubkey_t key) {
1✔
332
   return botan_pubkey_get_field(n, key, "n");
1✔
333
}
334

335
int botan_privkey_rsa_get_privkey(botan_privkey_t rsa_key, uint8_t out[], size_t* out_len, uint32_t flags) {
4✔
336
#if defined(BOTAN_HAS_RSA)
337
   return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
14✔
338
      if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
339
         if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
340
            return write_vec_output(out, out_len, rsa->private_key_bits());
341
         } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
342
            // TODO define new generic functions for this
343
            return write_str_output(reinterpret_cast<char*>(out),
344
                                    out_len,
345
                                    Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
346
         } else {
347
            return BOTAN_FFI_ERROR_BAD_FLAG;
348
         }
349
      } else {
350
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
351
      }
352
   });
353
#else
354
   BOTAN_UNUSED(rsa_key, out, out_len, flags);
355
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
356
#endif
357
}
358

359
/* DSA specific operations */
360
int botan_privkey_create_dsa(botan_privkey_t* key, botan_rng_t rng_obj, size_t pbits, size_t qbits) {
1✔
361
#if defined(BOTAN_HAS_DSA)
362

363
   if((rng_obj == nullptr) || (key == nullptr)) {
1✔
364
      return BOTAN_FFI_ERROR_NULL_POINTER;
365
   }
366

367
   if((pbits % 64 != 0) || (qbits % 8 != 0) || (pbits < 1024) || (pbits > 3072) || (qbits < 160) || (qbits > 256)) {
1✔
368
      return BOTAN_FFI_ERROR_BAD_PARAMETER;
369
   }
370

371
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
372
      Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1✔
373
      const Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
1✔
374
      auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
1✔
375
      return ffi_new_object(key, std::move(dsa));
1✔
376
   });
3✔
377
#else
378
   BOTAN_UNUSED(key, rng_obj, pbits, qbits);
379
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
380
#endif
381
}
382

383
int botan_privkey_load_dsa(botan_privkey_t* key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t x) {
2✔
384
#if defined(BOTAN_HAS_DSA)
385
   if(key == nullptr) {
2✔
386
      return BOTAN_FFI_ERROR_NULL_POINTER;
387
   }
388
   *key = nullptr;
2✔
389

390
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
391
      const Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
2✔
392
      auto dsa = std::make_unique<Botan::DSA_PrivateKey>(group, safe_get(x));
2✔
393
      return ffi_new_object(key, std::move(dsa));
2✔
394
   });
6✔
395
#else
396
   BOTAN_UNUSED(key, p, q, g, x);
397
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
398
#endif
399
}
400

401
int botan_pubkey_load_dsa(botan_pubkey_t* key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t y) {
2✔
402
#if defined(BOTAN_HAS_DSA)
403
   if(key == nullptr) {
2✔
404
      return BOTAN_FFI_ERROR_NULL_POINTER;
405
   }
406
   *key = nullptr;
2✔
407

408
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
409
      const Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
2✔
410
      auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
2✔
411
      return ffi_new_object(key, std::move(dsa));
2✔
412
   });
6✔
413
#else
414
   BOTAN_UNUSED(key, p, q, g, y);
415
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
416
#endif
417
}
418

419
int botan_privkey_dsa_get_x(botan_mp_t x, botan_privkey_t key) {
2✔
420
   return botan_privkey_get_field(x, key, "x");
2✔
421
}
422

423
int botan_pubkey_dsa_get_p(botan_mp_t p, botan_pubkey_t key) {
2✔
424
   return botan_pubkey_get_field(p, key, "p");
2✔
425
}
426

427
int botan_pubkey_dsa_get_q(botan_mp_t q, botan_pubkey_t key) {
2✔
428
   return botan_pubkey_get_field(q, key, "q");
2✔
429
}
430

431
int botan_pubkey_dsa_get_g(botan_mp_t g, botan_pubkey_t key) {
2✔
432
   return botan_pubkey_get_field(g, key, "g");
2✔
433
}
434

435
int botan_pubkey_dsa_get_y(botan_mp_t y, botan_pubkey_t key) {
2✔
436
   return botan_pubkey_get_field(y, key, "y");
2✔
437
}
438

439
int botan_privkey_create_ecdsa(botan_privkey_t* key_obj, botan_rng_t rng_obj, const char* param_str) {
1✔
440
   return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
1✔
441
}
442

443
/* ECDSA specific operations */
444

445
int botan_pubkey_ecc_key_used_explicit_encoding(botan_pubkey_t key) {
1✔
446
#if defined(BOTAN_HAS_ECC_KEY)
447
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
448
      const Botan::Public_Key& pub_key = safe_get(key);
1✔
449
      const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
1✔
450

451
      if(ec_key == nullptr) {
1✔
452
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
453
      }
454

455
      return ec_key->domain().used_explicit_encoding() ? 1 : 0;
1✔
456
   });
1✔
457
#else
458
   BOTAN_UNUSED(key);
459
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
460
#endif
461
}
462

463
// NOLINTBEGIN(misc-misplaced-const)
464

465
int botan_pubkey_load_ecdsa(botan_pubkey_t* key,
2✔
466
                            const botan_mp_t public_x,
467
                            const botan_mp_t public_y,
468
                            const char* curve_name) {
469
#if defined(BOTAN_HAS_ECDSA)
470
   if(key == nullptr || curve_name == nullptr) {
2✔
471
      return BOTAN_FFI_ERROR_NULL_POINTER;
472
   }
473
   *key = nullptr;
2✔
474

475
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
476
      std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
2✔
477

478
      const int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
2✔
479
      if(rc == BOTAN_FFI_SUCCESS) {
2✔
480
         ffi_new_object(key, std::move(p_key));
2✔
481
      }
482

483
      return rc;
2✔
484
   });
4✔
485
#else
486
   BOTAN_UNUSED(key, public_x, public_y, curve_name);
487
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
488
#endif
489
}
490

491
int botan_pubkey_load_ecdsa_sec1(botan_pubkey_t* key, const uint8_t sec1[], size_t sec1_len, const char* curve_name) {
3✔
492
#if defined(BOTAN_HAS_ECDSA)
493
   if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
3✔
494
      return BOTAN_FFI_ERROR_NULL_POINTER;
495
   }
496
   *key = nullptr;
3✔
497

498
   return ffi_guard_thunk(__func__, [=]() -> int {
3✔
499
      std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
3✔
500

501
      const int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
3✔
502
      if(rc == BOTAN_FFI_SUCCESS) {
3✔
503
         ffi_new_object(key, std::move(p_key));
3✔
504
      }
505

506
      return rc;
3✔
507
   });
6✔
508
#else
509
   BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
510
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
511
#endif
512
}
513

514
int botan_privkey_load_ecdsa(botan_privkey_t* key, const botan_mp_t scalar, const char* curve_name) {
2✔
515
#if defined(BOTAN_HAS_ECDSA)
516
   if(key == nullptr || curve_name == nullptr) {
2✔
517
      return BOTAN_FFI_ERROR_NULL_POINTER;
518
   }
519
   *key = nullptr;
2✔
520

521
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
522
      std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
2✔
523
      const int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
2✔
524
      if(rc == BOTAN_FFI_SUCCESS) {
2✔
525
         ffi_new_object(key, std::move(p_key));
4✔
526
      }
527
      return rc;
2✔
528
   });
4✔
529
#else
530
   BOTAN_UNUSED(key, scalar, curve_name);
531
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
532
#endif
533
}
534

535
/* ElGamal specific operations */
536
int botan_privkey_create_elgamal(botan_privkey_t* key, botan_rng_t rng_obj, size_t pbits, size_t qbits) {
1✔
537
#if defined(BOTAN_HAS_ELGAMAL)
538
   if(key == nullptr || rng_obj == nullptr) {
1✔
539
      return BOTAN_FFI_ERROR_NULL_POINTER;
540
   }
541
   *key = nullptr;
1✔
542

543
   if(pbits < 1024 || qbits < 160) {
1✔
544
      return BOTAN_FFI_ERROR_BAD_PARAMETER;
545
   }
546

547
   const Botan::DL_Group::PrimeType prime_type =
1✔
548
      ((pbits - 1) == qbits) ? Botan::DL_Group::Strong : Botan::DL_Group::Prime_Subgroup;
1✔
549

550
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
551
      Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1✔
552
      const Botan::DL_Group group(rng, prime_type, pbits, qbits);
1✔
553
      auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
1✔
554
      return ffi_new_object(key, std::move(elg));
1✔
555
   });
3✔
556
#else
557
   BOTAN_UNUSED(key, rng_obj, pbits, qbits);
558
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
559
#endif
560
}
561

562
int botan_pubkey_load_elgamal(botan_pubkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t y) {
2✔
563
#if defined(BOTAN_HAS_ELGAMAL)
564
   if(key == nullptr) {
2✔
565
      return BOTAN_FFI_ERROR_NULL_POINTER;
566
   }
567
   *key = nullptr;
2✔
568
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
569
      const Botan::DL_Group group(safe_get(p), safe_get(g));
2✔
570
      auto elg = std::make_unique<Botan::ElGamal_PublicKey>(group, safe_get(y));
2✔
571
      return ffi_new_object(key, std::move(elg));
2✔
572
   });
6✔
573
#else
574
   BOTAN_UNUSED(key, p, g, y);
575
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
576
#endif
577
}
578

579
int botan_privkey_load_elgamal(botan_privkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t x) {
2✔
580
#if defined(BOTAN_HAS_ELGAMAL)
581
   if(key == nullptr) {
2✔
582
      return BOTAN_FFI_ERROR_NULL_POINTER;
583
   }
584
   *key = nullptr;
2✔
585
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
586
      const Botan::DL_Group group(safe_get(p), safe_get(g));
2✔
587
      auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(group, safe_get(x));
2✔
588
      return ffi_new_object(key, std::move(elg));
2✔
589
   });
6✔
590
#else
591
   BOTAN_UNUSED(key, p, g, x);
592
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
593
#endif
594
}
595

596
/* Diffie Hellman specific operations */
597

598
int botan_privkey_create_dh(botan_privkey_t* key_obj, botan_rng_t rng_obj, const char* param_str) {
2✔
599
   return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
2✔
600
}
601

602
int botan_privkey_load_dh(botan_privkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t x) {
1✔
603
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
604
   if(key == nullptr) {
1✔
605
      return BOTAN_FFI_ERROR_NULL_POINTER;
606
   }
607
   *key = nullptr;
1✔
608
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
609
      const Botan::DL_Group group(safe_get(p), safe_get(g));
1✔
610
      auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
1✔
611
      return ffi_new_object(key, std::move(dh));
1✔
612
   });
3✔
613
#else
614
   BOTAN_UNUSED(key, p, g, x);
615
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
616
#endif
617
}
618

619
int botan_pubkey_load_dh(botan_pubkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t y) {
1✔
620
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
621
   if(key == nullptr) {
1✔
622
      return BOTAN_FFI_ERROR_NULL_POINTER;
623
   }
624
   *key = nullptr;
1✔
625
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
626
      const Botan::DL_Group group(safe_get(p), safe_get(g));
1✔
627
      auto dh = std::make_unique<Botan::DH_PublicKey>(group, safe_get(y));
1✔
628
      return ffi_new_object(key, std::move(dh));
1✔
629
   });
3✔
630
#else
631
   BOTAN_UNUSED(key, p, g, y);
632
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
633
#endif
634
}
635

636
/* ECDH + x25519/x448 specific operations */
637

638
int botan_privkey_create_ecdh(botan_privkey_t* key_obj, botan_rng_t rng_obj, const char* param_str) {
2✔
639
   if(key_obj == nullptr || param_str == nullptr) {
2✔
640
      return BOTAN_FFI_ERROR_NULL_POINTER;
641
   }
642
   *key_obj = nullptr;
2✔
643

644
   const std::string params(param_str);
2✔
645

646
   if(params == "X25519" || params == "x25519" || params == "curve25519") {
2✔
647
      return botan_privkey_create(key_obj, "X25519", "", rng_obj);
×
648
   }
649

650
   if(params == "X448" || params == "x448") {
2✔
651
      return botan_privkey_create(key_obj, "X448", "", rng_obj);
×
652
   }
653

654
   return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
2✔
655
}
2✔
656

657
int botan_pubkey_load_ecdh(botan_pubkey_t* key,
1✔
658
                           const botan_mp_t public_x,
659
                           const botan_mp_t public_y,
660
                           const char* curve_name) {
661
#if defined(BOTAN_HAS_ECDH)
662
   if(key == nullptr || curve_name == nullptr) {
1✔
663
      return BOTAN_FFI_ERROR_NULL_POINTER;
664
   }
665
   *key = nullptr;
1✔
666
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
667
      std::unique_ptr<Botan::ECDH_PublicKey> p_key;
1✔
668
      const int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
1✔
669

670
      if(rc == BOTAN_FFI_SUCCESS) {
1✔
671
         ffi_new_object(key, std::move(p_key));
1✔
672
      }
673
      return rc;
1✔
674
   });
2✔
675
#else
676
   BOTAN_UNUSED(key, public_x, public_y, curve_name);
677
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
678
#endif
679
}
680

681
int botan_pubkey_load_ecdh_sec1(botan_pubkey_t* key, const uint8_t sec1[], size_t sec1_len, const char* curve_name) {
7✔
682
#if defined(BOTAN_HAS_ECDH)
683
   if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
7✔
684
      return BOTAN_FFI_ERROR_NULL_POINTER;
685
   }
686
   *key = nullptr;
7✔
687

688
   return ffi_guard_thunk(__func__, [=]() -> int {
7✔
689
      std::unique_ptr<Botan::ECDH_PublicKey> p_key;
7✔
690

691
      const int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
7✔
692
      if(rc == BOTAN_FFI_SUCCESS) {
7✔
693
         ffi_new_object(key, std::move(p_key));
7✔
694
      }
695

696
      return rc;
7✔
697
   });
14✔
698
#else
699
   BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
700
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
701
#endif
702
}
703

704
int botan_privkey_load_ecdh(botan_privkey_t* key, const botan_mp_t scalar, const char* curve_name) {
4✔
705
#if defined(BOTAN_HAS_ECDH)
706
   if(key == nullptr || curve_name == nullptr) {
4✔
707
      return BOTAN_FFI_ERROR_NULL_POINTER;
708
   }
709
   *key = nullptr;
4✔
710
   return ffi_guard_thunk(__func__, [=]() -> int {
4✔
711
      std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
4✔
712
      const int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
4✔
713
      if(rc == BOTAN_FFI_SUCCESS) {
4✔
714
         ffi_new_object(key, std::move(p_key));
8✔
715
      }
716
      return rc;
4✔
717
   });
8✔
718
#else
719
   BOTAN_UNUSED(key, scalar, curve_name);
720
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
721
#endif
722
}
723

724
/* SM2 specific operations */
725

726
int botan_pubkey_sm2_compute_za(
2✔
727
   uint8_t out[], size_t* out_len, const char* ident, const char* hash_algo, const botan_pubkey_t key) {
728
   if(out == nullptr || out_len == nullptr || ident == nullptr || hash_algo == nullptr || key == nullptr) {
2✔
729
      return BOTAN_FFI_ERROR_NULL_POINTER;
730
   }
731

732
#if defined(BOTAN_HAS_SM2)
733
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
734
      const Botan::Public_Key& pub_key = safe_get(key);
2✔
735
      const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
2✔
736

737
      if(ec_key == nullptr) {
2✔
738
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
739
      }
740

741
      if(ec_key->algo_name() != "SM2") {
2✔
742
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
743
      }
744

745
      const std::string ident_str(ident);
2✔
746
      std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
2✔
747

748
      const auto& pt = ec_key->_public_ec_point();
2✔
749

750
      const auto za = Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), pt);
2✔
751

752
      return write_vec_output(out, out_len, za);
2✔
753
   });
6✔
754
#else
755
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
756
#endif
757
}
758

759
int botan_pubkey_load_sm2(botan_pubkey_t* key,
3✔
760
                          const botan_mp_t public_x,
761
                          const botan_mp_t public_y,
762
                          const char* curve_name) {
763
#if defined(BOTAN_HAS_SM2)
764
   if(key == nullptr || curve_name == nullptr) {
3✔
765
      return BOTAN_FFI_ERROR_NULL_POINTER;
766
   }
767
   *key = nullptr;
3✔
768

769
   return ffi_guard_thunk(__func__, [=]() -> int {
3✔
770
      std::unique_ptr<Botan::SM2_PublicKey> p_key;
3✔
771
      if(pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name) == 0) {
3✔
772
         return ffi_new_object(key, std::move(p_key));
3✔
773
      } else {
774
         return BOTAN_FFI_ERROR_UNKNOWN_ERROR;
775
      }
776
   });
6✔
777
#else
778
   BOTAN_UNUSED(key, public_x, public_y, curve_name);
779
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
780
#endif
781
}
782

783
int botan_pubkey_load_sm2_sec1(botan_pubkey_t* key, const uint8_t sec1[], size_t sec1_len, const char* curve_name) {
4✔
784
#if defined(BOTAN_HAS_SM2)
785
   if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
4✔
786
      return BOTAN_FFI_ERROR_NULL_POINTER;
787
   }
788
   *key = nullptr;
4✔
789

790
   return ffi_guard_thunk(__func__, [=]() -> int {
4✔
791
      std::unique_ptr<Botan::SM2_PublicKey> p_key;
4✔
792

793
      const int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
4✔
794
      if(rc == BOTAN_FFI_SUCCESS) {
4✔
795
         ffi_new_object(key, std::move(p_key));
4✔
796
      }
797

798
      return rc;
4✔
799
   });
8✔
800
#else
801
   BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
802
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
803
#endif
804
}
805

806
int botan_privkey_load_sm2(botan_privkey_t* key, const botan_mp_t scalar, const char* curve_name) {
3✔
807
#if defined(BOTAN_HAS_SM2)
808
   if(key == nullptr || curve_name == nullptr) {
3✔
809
      return BOTAN_FFI_ERROR_NULL_POINTER;
810
   }
811
   *key = nullptr;
3✔
812

813
   return ffi_guard_thunk(__func__, [=]() -> int {
3✔
814
      std::unique_ptr<Botan::SM2_PrivateKey> p_key;
3✔
815
      const int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
3✔
816

817
      if(rc == BOTAN_FFI_SUCCESS) {
3✔
818
         ffi_new_object(key, std::move(p_key));
6✔
819
      }
820
      return rc;
3✔
821
   });
6✔
822
#else
823
   BOTAN_UNUSED(key, scalar, curve_name);
824
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
825
#endif
826
}
827

828
int botan_pubkey_load_sm2_enc(botan_pubkey_t* key,
1✔
829
                              const botan_mp_t public_x,
830
                              const botan_mp_t public_y,
831
                              const char* curve_name) {
832
   return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
1✔
833
}
834

835
int botan_privkey_load_sm2_enc(botan_privkey_t* key, const botan_mp_t scalar, const char* curve_name) {
1✔
836
   return botan_privkey_load_sm2(key, scalar, curve_name);
1✔
837
}
838

839
/* Ed25519 specific operations */
840

841
int botan_privkey_load_ed25519(botan_privkey_t* key, const uint8_t privkey[32]) {
1✔
842
#if defined(BOTAN_HAS_ED25519)
843
   if(key == nullptr) {
1✔
844
      return BOTAN_FFI_ERROR_NULL_POINTER;
845
   }
846
   *key = nullptr;
1✔
847
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
848
      auto ed25519 =
1✔
849
         std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(std::span{privkey, 32}));
2✔
850
      return ffi_new_object(key, std::move(ed25519));
2✔
851
   });
2✔
852
#else
853
   BOTAN_UNUSED(key, privkey);
854
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
855
#endif
856
}
857

858
int botan_pubkey_load_ed25519(botan_pubkey_t* key, const uint8_t pubkey[32]) {
1✔
859
#if defined(BOTAN_HAS_ED25519)
860
   if(key == nullptr) {
1✔
861
      return BOTAN_FFI_ERROR_NULL_POINTER;
862
   }
863
   *key = nullptr;
1✔
864
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
865
      const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
1✔
866
      auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
1✔
867
      return ffi_new_object(key, std::move(ed25519));
1✔
868
   });
3✔
869
#else
870
   BOTAN_UNUSED(key, pubkey);
871
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
872
#endif
873
}
874

875
int botan_privkey_ed25519_get_privkey(botan_privkey_t key, uint8_t output[64]) {
1✔
876
#if defined(BOTAN_HAS_ED25519)
877
   return BOTAN_FFI_VISIT(key, [=](const auto& k) {
4✔
878
      if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
879
         const auto ed_key = ed->raw_private_key_bits();
880
         if(ed_key.size() != 64) {
881
            return BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE;
882
         }
883
         Botan::copy_mem(output, ed_key.data(), ed_key.size());
884
         return BOTAN_FFI_SUCCESS;
885
      } else {
886
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
887
      }
888
   });
889
#else
890
   BOTAN_UNUSED(key, output);
891
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
892
#endif
893
}
894

895
int botan_pubkey_ed25519_get_pubkey(botan_pubkey_t key, uint8_t output[32]) {
1✔
896
#if defined(BOTAN_HAS_ED25519)
897
   return BOTAN_FFI_VISIT(key, [=](const auto& k) {
2✔
898
      if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
899
         const std::vector<uint8_t>& ed_key = ed->get_public_key();
900
         if(ed_key.size() != 32) {
901
            return BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE;
902
         }
903
         Botan::copy_mem(output, ed_key.data(), ed_key.size());
904
         return BOTAN_FFI_SUCCESS;
905
      } else {
906
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
907
      }
908
   });
909
#else
910
   BOTAN_UNUSED(key, output);
911
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
912
#endif
913
}
914

915
/* Ed448 specific operations */
916

917
int botan_privkey_load_ed448(botan_privkey_t* key, const uint8_t privkey[57]) {
1✔
918
#if defined(BOTAN_HAS_ED448)
919
   if(key == nullptr) {
1✔
920
      return BOTAN_FFI_ERROR_NULL_POINTER;
921
   }
922
   *key = nullptr;
1✔
923
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
924
      auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
1✔
925
      return ffi_new_object(key, std::move(ed448));
2✔
926
   });
2✔
927
#else
928
   BOTAN_UNUSED(key, privkey);
929
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
930
#endif
931
}
932

933
int botan_pubkey_load_ed448(botan_pubkey_t* key, const uint8_t pubkey[57]) {
1✔
934
#if defined(BOTAN_HAS_ED448)
935
   if(key == nullptr) {
1✔
936
      return BOTAN_FFI_ERROR_NULL_POINTER;
937
   }
938
   *key = nullptr;
1✔
939
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
940
      auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
1✔
941
      return ffi_new_object(key, std::move(ed448));
1✔
942
   });
2✔
943
#else
944
   BOTAN_UNUSED(key, pubkey);
945
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
946
#endif
947
}
948

949
int botan_privkey_ed448_get_privkey(botan_privkey_t key, uint8_t output[57]) {
1✔
950
#if defined(BOTAN_HAS_ED448)
951
   return BOTAN_FFI_VISIT(key, [=](const auto& k) {
4✔
952
      if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
953
         const auto ed_key = ed->raw_private_key_bits();
954
         Botan::copy_mem(std::span(output, 57), ed_key);
955
         return BOTAN_FFI_SUCCESS;
956
      } else {
957
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
958
      }
959
   });
960
#else
961
   BOTAN_UNUSED(key, output);
962
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
963
#endif
964
}
965

966
int botan_pubkey_ed448_get_pubkey(botan_pubkey_t key, uint8_t output[57]) {
1✔
967
#if defined(BOTAN_HAS_ED448)
968
   return BOTAN_FFI_VISIT(key, [=](const auto& k) {
3✔
969
      if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
970
         const auto ed_key = ed->public_key_bits();
971
         Botan::copy_mem(std::span(output, 57), ed_key);
972
         return BOTAN_FFI_SUCCESS;
973
      } else {
974
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
975
      }
976
   });
977
#else
978
   BOTAN_UNUSED(key, output);
979
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
980
#endif
981
}
982

983
/* X25519 specific operations */
984

985
int botan_privkey_load_x25519(botan_privkey_t* key, const uint8_t privkey[32]) {
1✔
986
#if defined(BOTAN_HAS_X25519)
987
   if(key == nullptr) {
1✔
988
      return BOTAN_FFI_ERROR_NULL_POINTER;
989
   }
990
   *key = nullptr;
1✔
991
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
992
      auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(std::span{privkey, 32});
1✔
993
      return ffi_new_object(key, std::move(x25519));
2✔
994
   });
2✔
995
#else
996
   BOTAN_UNUSED(key, privkey);
997
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
998
#endif
999
}
1000

1001
int botan_pubkey_load_x25519(botan_pubkey_t* key, const uint8_t pubkey[32]) {
1✔
1002
#if defined(BOTAN_HAS_X25519)
1003
   if(key == nullptr) {
1✔
1004
      return BOTAN_FFI_ERROR_NULL_POINTER;
1005
   }
1006
   *key = nullptr;
1✔
1007
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
1008
      auto x25519 = std::make_unique<Botan::X25519_PublicKey>(std::span{pubkey, 32});
1✔
1009
      return ffi_new_object(key, std::move(x25519));
1✔
1010
   });
2✔
1011
#else
1012
   BOTAN_UNUSED(key, pubkey);
1013
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1014
#endif
1015
}
1016

1017
int botan_privkey_x25519_get_privkey(botan_privkey_t key, uint8_t output[32]) {
1✔
1018
#if defined(BOTAN_HAS_X25519)
1019
   return BOTAN_FFI_VISIT(key, [=](const auto& k) {
4✔
1020
      if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
1021
         const auto x25519_key = x25519->raw_private_key_bits();
1022
         if(x25519_key.size() != 32) {
1023
            return BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE;
1024
         }
1025
         Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
1026
         return BOTAN_FFI_SUCCESS;
1027
      } else {
1028
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1029
      }
1030
   });
1031
#else
1032
   BOTAN_UNUSED(key, output);
1033
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1034
#endif
1035
}
1036

1037
int botan_pubkey_x25519_get_pubkey(botan_pubkey_t key, uint8_t output[32]) {
2✔
1038
#if defined(BOTAN_HAS_X25519)
1039
   return BOTAN_FFI_VISIT(key, [=](const auto& k) {
6✔
1040
      if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
1041
         Botan::copy_mem(std::span{output, 32}, x25519->raw_public_key_bits());
1042
         return BOTAN_FFI_SUCCESS;
1043
      } else {
1044
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1045
      }
1046
   });
1047
#else
1048
   BOTAN_UNUSED(key, output);
1049
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1050
#endif
1051
}
1052

1053
/* X448 specific operations */
1054

1055
int botan_privkey_load_x448(botan_privkey_t* key, const uint8_t privkey[56]) {
1✔
1056
#if defined(BOTAN_HAS_X448)
1057
   if(key == nullptr) {
1✔
1058
      return BOTAN_FFI_ERROR_NULL_POINTER;
1059
   }
1060
   *key = nullptr;
1✔
1061
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
1062
      auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span{privkey, 56});
1✔
1063
      return ffi_new_object(key, std::move(x448));
2✔
1064
   });
2✔
1065
#else
1066
   BOTAN_UNUSED(key, privkey);
1067
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1068
#endif
1069
}
1070

1071
int botan_pubkey_load_x448(botan_pubkey_t* key, const uint8_t pubkey[56]) {
1✔
1072
#if defined(BOTAN_HAS_X448)
1073
   if(key == nullptr) {
1✔
1074
      return BOTAN_FFI_ERROR_NULL_POINTER;
1075
   }
1076
   *key = nullptr;
1✔
1077
   return ffi_guard_thunk(__func__, [=]() -> int {
1✔
1078
      auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span{pubkey, 56});
1✔
1079
      return ffi_new_object(key, std::move(x448));
1✔
1080
   });
2✔
1081
#else
1082
   BOTAN_UNUSED(key, pubkey);
1083
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1084
#endif
1085
}
1086

1087
int botan_privkey_x448_get_privkey(botan_privkey_t key, uint8_t output[56]) {
1✔
1088
#if defined(BOTAN_HAS_X448)
1089
   return BOTAN_FFI_VISIT(key, [=](const auto& k) {
4✔
1090
      if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
1091
         const auto x448_key = x448->raw_private_key_bits();
1092
         Botan::copy_mem(std::span{output, 56}, x448_key);
1093
         return BOTAN_FFI_SUCCESS;
1094
      } else {
1095
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1096
      }
1097
   });
1098
#else
1099
   BOTAN_UNUSED(key, output);
1100
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1101
#endif
1102
}
1103

1104
int botan_pubkey_x448_get_pubkey(botan_pubkey_t key, uint8_t output[56]) {
2✔
1105
#if defined(BOTAN_HAS_X448)
1106
   return BOTAN_FFI_VISIT(key, [=](const auto& k) {
6✔
1107
      if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
1108
         Botan::copy_mem(std::span{output, 56}, x448->raw_public_key_bits());
1109
         return BOTAN_FFI_SUCCESS;
1110
      } else {
1111
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1112
      }
1113
   });
1114
#else
1115
   BOTAN_UNUSED(key, output);
1116
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1117
#endif
1118
}
1119

1120
/*
1121
* Algorithm specific key operations: Kyber
1122
*/
1123

1124
int botan_privkey_load_kyber(botan_privkey_t* key, const uint8_t privkey[], size_t key_len) {
4✔
1125
#if defined(BOTAN_HAS_KYBER)
1126
   if(key == nullptr) {
4✔
1127
      return BOTAN_FFI_ERROR_NULL_POINTER;
1128
   }
1129
   *key = nullptr;
4✔
1130

1131
   const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
12✔
1132
      if(len == 1632) {
4✔
1133
         return Botan::KyberMode::Kyber512_R3;
1✔
1134
      } else if(len == 2400) {
3✔
1135
         return Botan::KyberMode::Kyber768_R3;
2✔
1136
      } else if(len == 3168) {
1✔
1137
         return Botan::KyberMode::Kyber1024_R3;
1✔
1138
      } else {
1139
         return {};
×
1140
      }
1141
   }(key_len);
4✔
1142

1143
   if(mode.has_value()) {
4✔
1144
      return ffi_guard_thunk(__func__, [=]() -> int {
4✔
1145
         auto kyber = std::make_unique<Botan::Kyber_PrivateKey>(std::span{privkey, key_len}, *mode);
4✔
1146
         return ffi_new_object(key, std::move(kyber));
8✔
1147
      });
4✔
1148
   } else {
1149
      return BOTAN_FFI_ERROR_BAD_PARAMETER;
1150
   }
1151
#else
1152
   BOTAN_UNUSED(key, key_len, privkey);
1153
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1154
#endif
1155
}
1156

1157
int botan_pubkey_load_kyber(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len) {
4✔
1158
#if defined(BOTAN_HAS_KYBER)
1159
   if(key == nullptr) {
4✔
1160
      return BOTAN_FFI_ERROR_NULL_POINTER;
1161
   }
1162
   *key = nullptr;
4✔
1163

1164
   const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
12✔
1165
      if(len == 800) {
4✔
1166
         return Botan::KyberMode::Kyber512_R3;
1✔
1167
      } else if(len == 1184) {
3✔
1168
         return Botan::KyberMode::Kyber768_R3;
2✔
1169
      } else if(len == 1568) {
1✔
1170
         return Botan::KyberMode::Kyber1024_R3;
1✔
1171
      } else {
1172
         return {};
×
1173
      }
1174
   }(key_len);
4✔
1175

1176
   if(mode.has_value()) {
4✔
1177
      auto kyber = std::make_unique<Botan::Kyber_PublicKey>(std::span{pubkey, key_len}, *mode);
4✔
1178
      return ffi_new_object(key, std::move(kyber));
4✔
1179
   } else {
4✔
1180
      return BOTAN_FFI_ERROR_BAD_PARAMETER;
1181
   }
1182
#else
1183
   BOTAN_UNUSED(key, pubkey, key_len);
1184
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1185
#endif
1186
}
1187

1188
int botan_privkey_view_kyber_raw_key(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) {
4✔
1189
#if defined(BOTAN_HAS_KYBER)
1190
   return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
16✔
1191
      if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1192
         return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1193
      } else {
1194
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1195
      }
1196
   });
1197
#else
1198
   BOTAN_UNUSED(key, ctx, view);
1199
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1200
#endif
1201
}
1202

1203
int botan_pubkey_view_kyber_raw_key(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) {
8✔
1204
#if defined(BOTAN_HAS_KYBER)
1205
   return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
32✔
1206
      if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1207
         return invoke_view_callback(view, ctx, kyber->public_key_bits());
1208
      } else {
1209
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1210
      }
1211
   });
1212
#else
1213
   BOTAN_UNUSED(key, ctx, view);
1214
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1215
#endif
1216
}
1217

1218
/*
1219
* Algorithm specific key operations: ML-KEM
1220
*/
1221

1222
int botan_privkey_load_ml_kem(botan_privkey_t* key, const uint8_t privkey[], size_t key_len, const char* mlkem_mode) {
4✔
1223
#if defined(BOTAN_HAS_ML_KEM)
1224
   if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
4✔
1225
      return BOTAN_FFI_ERROR_NULL_POINTER;
1226
   }
1227

1228
   *key = nullptr;
4✔
1229

1230
   return ffi_guard_thunk(__func__, [=]() -> int {
4✔
1231
      auto mode = Botan::ML_KEM_Mode(mlkem_mode);
4✔
1232
      if(!mode.is_ml_kem()) {
4✔
1233
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1234
      }
1235

1236
      auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
4✔
1237
      return ffi_new_object(key, std::move(mlkem_key));
4✔
1238
   });
8✔
1239
#else
1240
   BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1241
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1242
#endif
1243
}
1244

1245
int botan_pubkey_load_ml_kem(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len, const char* mlkem_mode) {
4✔
1246
#if defined(BOTAN_HAS_ML_KEM)
1247
   if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
4✔
1248
      return BOTAN_FFI_ERROR_NULL_POINTER;
1249
   }
1250

1251
   *key = nullptr;
4✔
1252

1253
   return ffi_guard_thunk(__func__, [=]() -> int {
4✔
1254
      auto mode = Botan::ML_KEM_Mode(mlkem_mode);
4✔
1255
      if(!mode.is_ml_kem()) {
4✔
1256
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1257
      }
1258

1259
      auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
4✔
1260
      return ffi_new_object(key, std::move(mlkem_key));
4✔
1261
   });
8✔
1262
#else
1263
   BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1264
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1265
#endif
1266
}
1267

1268
/*
1269
* Algorithm specific key operations: ML-DSA
1270
*/
1271

1272
int botan_privkey_load_ml_dsa(botan_privkey_t* key, const uint8_t privkey[], size_t key_len, const char* mldsa_mode) {
4✔
1273
#if defined(BOTAN_HAS_ML_DSA)
1274
   if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
4✔
1275
      return BOTAN_FFI_ERROR_NULL_POINTER;
1276
   }
1277

1278
   *key = nullptr;
4✔
1279

1280
   return ffi_guard_thunk(__func__, [=]() -> int {
4✔
1281
      auto mode = Botan::ML_DSA_Mode(mldsa_mode);
4✔
1282
      if(!mode.is_ml_dsa()) {
4✔
1283
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1284
      }
1285

1286
      auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
4✔
1287
      return ffi_new_object(key, std::move(mldsa_key));
4✔
1288
   });
8✔
1289
#else
1290
   BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1291
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1292
#endif
1293
}
1294

1295
int botan_pubkey_load_ml_dsa(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len, const char* mldsa_mode) {
4✔
1296
#if defined(BOTAN_HAS_ML_DSA)
1297
   if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
4✔
1298
      return BOTAN_FFI_ERROR_NULL_POINTER;
1299
   }
1300

1301
   *key = nullptr;
4✔
1302

1303
   return ffi_guard_thunk(__func__, [=]() -> int {
4✔
1304
      auto mode = Botan::ML_DSA_Mode(mldsa_mode);
4✔
1305
      if(!mode.is_ml_dsa()) {
4✔
1306
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1307
      }
1308

1309
      auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
4✔
1310
      return ffi_new_object(key, std::move(mldsa_key));
4✔
1311
   });
8✔
1312
#else
1313
   BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1314
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1315
#endif
1316
}
1317

1318
/*
1319
* Algorithm specific key operations: SLH-DSA
1320
*/
1321

1322
int botan_privkey_load_slh_dsa(botan_privkey_t* key, const uint8_t privkey[], size_t key_len, const char* slhdsa_mode) {
13✔
1323
#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1324
   if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
13✔
1325
      return BOTAN_FFI_ERROR_NULL_POINTER;
1326
   }
1327

1328
   *key = nullptr;
13✔
1329

1330
   return ffi_guard_thunk(__func__, [=]() -> int {
13✔
1331
      auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
13✔
1332
      if(!mode.is_slh_dsa()) {
13✔
1333
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1334
      }
1335

1336
      auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
13✔
1337
      return ffi_new_object(key, std::move(slhdsa_key));
13✔
1338
   });
26✔
1339
#else
1340
   BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1341
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1342
#endif
1343
}
1344

1345
int botan_pubkey_load_slh_dsa(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len, const char* slhdsa_mode) {
13✔
1346
#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1347
   if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
13✔
1348
      return BOTAN_FFI_ERROR_NULL_POINTER;
1349
   }
1350

1351
   *key = nullptr;
13✔
1352

1353
   return ffi_guard_thunk(__func__, [=]() -> int {
13✔
1354
      auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
13✔
1355
      if(!mode.is_slh_dsa()) {
13✔
1356
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1357
      }
1358

1359
      auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
13✔
1360
      return ffi_new_object(key, std::move(mldsa_key));
13✔
1361
   });
26✔
1362
#else
1363
   BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1364
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1365
#endif
1366
}
1367

1368
/*
1369
* Algorithm specific key operations: FrodoKEM
1370
*/
1371

1372
int botan_privkey_load_frodokem(botan_privkey_t* key, const uint8_t privkey[], size_t key_len, const char* frodo_mode) {
13✔
1373
#if defined(BOTAN_HAS_FRODOKEM)
1374
   if(key == nullptr || privkey == nullptr || frodo_mode == nullptr) {
13✔
1375
      return BOTAN_FFI_ERROR_NULL_POINTER;
1376
   }
1377

1378
   *key = nullptr;
13✔
1379

1380
   return ffi_guard_thunk(__func__, [=]() -> int {
13✔
1381
      const auto mode = Botan::FrodoKEMMode(frodo_mode);
13✔
1382
      auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
13✔
1383
      return ffi_new_object(key, std::move(frodo_key));
26✔
1384
   });
26✔
1385
#else
1386
   BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1387
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1388
#endif
1389
}
1390

1391
int botan_pubkey_load_frodokem(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len, const char* frodo_mode) {
13✔
1392
#if defined(BOTAN_HAS_FRODOKEM)
1393
   if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
13✔
1394
      return BOTAN_FFI_ERROR_NULL_POINTER;
1395
   }
1396

1397
   *key = nullptr;
13✔
1398

1399
   return ffi_guard_thunk(__func__, [=]() -> int {
13✔
1400
      const auto mode = Botan::FrodoKEMMode(frodo_mode);
13✔
1401
      auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
13✔
1402
      return ffi_new_object(key, std::move(frodo_key));
13✔
1403
   });
26✔
1404
#else
1405
   BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1406
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1407
#endif
1408
}
1409

1410
/*
1411
* Algorithm specific key operations : Classic McEliece
1412
*/
1413

1414
int botan_privkey_load_classic_mceliece(botan_privkey_t* key,
17✔
1415
                                        const uint8_t privkey[],
1416
                                        size_t key_len,
1417
                                        const char* cmce_mode) {
1418
#if defined(BOTAN_HAS_CLASSICMCELIECE)
1419
   if(key == nullptr || privkey == nullptr || cmce_mode == nullptr) {
17✔
1420
      return BOTAN_FFI_ERROR_NULL_POINTER;
1421
   }
1422

1423
   *key = nullptr;
17✔
1424

1425
   return ffi_guard_thunk(__func__, [=]() -> int {
17✔
1426
      const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
17✔
1427
      auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
17✔
1428
      return ffi_new_object(key, std::move(cmce_key));
34✔
1429
   });
34✔
1430
#else
1431
   BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1432
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1433
#endif
1434
}
1435

1436
int botan_pubkey_load_classic_mceliece(botan_pubkey_t* key,
17✔
1437
                                       const uint8_t pubkey[],
1438
                                       size_t key_len,
1439
                                       const char* cmce_mode) {
1440
#if defined(BOTAN_HAS_CLASSICMCELIECE)
1441
   if(key == nullptr || pubkey == nullptr || cmce_mode == nullptr) {
17✔
1442
      return BOTAN_FFI_ERROR_NULL_POINTER;
1443
   }
1444

1445
   *key = nullptr;
17✔
1446

1447
   return ffi_guard_thunk(__func__, [=]() -> int {
17✔
1448
      const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
17✔
1449
      auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
17✔
1450
      return ffi_new_object(key, std::move(cmce_key));
17✔
1451
   });
34✔
1452
#else
1453
   BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1454
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1455
#endif
1456
}
1457

1458
int botan_pubkey_view_ec_public_point(const botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) {
6✔
1459
#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1460
   return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
24✔
1461
      if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1462
         auto pt = ecc->_public_ec_point().serialize_uncompressed();
1463
         return invoke_view_callback(view, ctx, pt);
1464
      } else {
1465
         return BOTAN_FFI_ERROR_BAD_PARAMETER;
1466
      }
1467
   });
1468
#else
1469
   BOTAN_UNUSED(key, view, ctx);
1470
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
1471
#endif
1472
}
1473

1474
// NOLINTEND(misc-misplaced-const)
1475

1476
int botan_privkey_create_mceliece(botan_privkey_t* key_obj, botan_rng_t rng_obj, size_t n, size_t t) {
1✔
1477
   const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
3✔
1478
   return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1✔
1479
}
1✔
1480

1481
int botan_mceies_decrypt(botan_privkey_t mce_key_obj,
×
1482
                         const char* aead,
1483
                         const uint8_t ct[],
1484
                         size_t ct_len,
1485
                         const uint8_t ad[],
1486
                         size_t ad_len,
1487
                         uint8_t out[],
1488
                         size_t* out_len) {
1489
   BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
×
1490
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
×
1491
}
1492

1493
int botan_mceies_encrypt(botan_pubkey_t mce_key_obj,
×
1494
                         botan_rng_t rng_obj,
1495
                         const char* aead,
1496
                         const uint8_t pt[],
1497
                         size_t pt_len,
1498
                         const uint8_t ad[],
1499
                         size_t ad_len,
1500
                         uint8_t out[],
1501
                         size_t* out_len) {
1502
   BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
×
1503
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
×
1504
}
1505
}
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