Botan 3.6.1
Crypto and TLS for C&
ffi_pkey_algs.cpp File Reference
#include <botan/ffi.h>
#include <botan/hash.h>
#include <botan/pem.h>
#include <botan/internal/ffi_mp.h>
#include <botan/internal/ffi_pkey.h>
#include <botan/internal/ffi_rng.h>
#include <botan/internal/ffi_util.h>

Go to the source code of this file.

Functions

int botan_mceies_decrypt (botan_privkey_t mce_key_obj, const char *aead, const uint8_t ct[], size_t ct_len, const uint8_t ad[], size_t ad_len, uint8_t out[], size_t *out_len)
 
int botan_mceies_encrypt (botan_pubkey_t mce_key_obj, botan_rng_t rng_obj, const char *aead, const uint8_t pt[], size_t pt_len, const uint8_t ad[], size_t ad_len, uint8_t out[], size_t *out_len)
 
int botan_privkey_create_dh (botan_privkey_t *key_obj, botan_rng_t rng_obj, const char *param_str)
 
int botan_privkey_create_dsa (botan_privkey_t *key, botan_rng_t rng_obj, size_t pbits, size_t qbits)
 
int botan_privkey_create_ecdh (botan_privkey_t *key_obj, botan_rng_t rng_obj, const char *param_str)
 
int botan_privkey_create_ecdsa (botan_privkey_t *key_obj, botan_rng_t rng_obj, const char *param_str)
 
int botan_privkey_create_elgamal (botan_privkey_t *key, botan_rng_t rng_obj, size_t pbits, size_t qbits)
 
int botan_privkey_create_mceliece (botan_privkey_t *key_obj, botan_rng_t rng_obj, size_t n, size_t t)
 
int botan_privkey_create_rsa (botan_privkey_t *key_obj, botan_rng_t rng_obj, size_t n_bits)
 
int botan_privkey_dsa_get_x (botan_mp_t x, botan_privkey_t key)
 
int botan_privkey_ed25519_get_privkey (botan_privkey_t key, uint8_t output[64])
 
int botan_privkey_ed448_get_privkey (botan_privkey_t key, uint8_t output[57])
 
int botan_privkey_get_field (botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
 
int botan_privkey_load_dh (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
 
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)
 
int botan_privkey_load_ecdh (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_ecdsa (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_ed25519 (botan_privkey_t *key, const uint8_t privkey[32])
 
int botan_privkey_load_ed448 (botan_privkey_t *key, const uint8_t privkey[57])
 
int botan_privkey_load_elgamal (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
 
int botan_privkey_load_frodokem (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *frodo_mode)
 
int botan_privkey_load_kyber (botan_privkey_t *key, const uint8_t privkey[], size_t key_len)
 
int botan_privkey_load_ml_dsa (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *mldsa_mode)
 
int botan_privkey_load_ml_kem (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *mlkem_mode)
 
int botan_privkey_load_rsa (botan_privkey_t *key, botan_mp_t rsa_p, botan_mp_t rsa_q, botan_mp_t rsa_e)
 
int botan_privkey_load_rsa_pkcs1 (botan_privkey_t *key, const uint8_t bits[], size_t len)
 
int botan_privkey_load_slh_dsa (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *slhdsa_mode)
 
int botan_privkey_load_sm2 (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_sm2_enc (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_x25519 (botan_privkey_t *key, const uint8_t privkey[32])
 
int botan_privkey_load_x448 (botan_privkey_t *key, const uint8_t privkey[56])
 
int botan_privkey_rsa_get_d (botan_mp_t d, botan_privkey_t key)
 
int botan_privkey_rsa_get_e (botan_mp_t e, botan_privkey_t key)
 
int botan_privkey_rsa_get_n (botan_mp_t n, botan_privkey_t key)
 
int botan_privkey_rsa_get_p (botan_mp_t p, botan_privkey_t key)
 
int botan_privkey_rsa_get_privkey (botan_privkey_t rsa_key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_privkey_rsa_get_q (botan_mp_t q, botan_privkey_t key)
 
int botan_privkey_view_kyber_raw_key (botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_x25519_get_privkey (botan_privkey_t key, uint8_t output[32])
 
int botan_privkey_x448_get_privkey (botan_privkey_t key, uint8_t output[56])
 
int botan_pubkey_dsa_get_g (botan_mp_t g, botan_pubkey_t key)
 
int botan_pubkey_dsa_get_p (botan_mp_t p, botan_pubkey_t key)
 
int botan_pubkey_dsa_get_q (botan_mp_t q, botan_pubkey_t key)
 
int botan_pubkey_dsa_get_y (botan_mp_t y, botan_pubkey_t key)
 
int botan_pubkey_ecc_key_used_explicit_encoding (botan_pubkey_t key)
 
int botan_pubkey_ed25519_get_pubkey (botan_pubkey_t key, uint8_t output[32])
 
int botan_pubkey_ed448_get_pubkey (botan_pubkey_t key, uint8_t output[57])
 
int botan_pubkey_get_field (botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
 
int botan_pubkey_load_dh (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
 
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)
 
int botan_pubkey_load_ecdh (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_ecdsa (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_ed25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
 
int botan_pubkey_load_ed448 (botan_pubkey_t *key, const uint8_t pubkey[57])
 
int botan_pubkey_load_elgamal (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
 
int botan_pubkey_load_frodokem (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *frodo_mode)
 
int botan_pubkey_load_kyber (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len)
 
int botan_pubkey_load_ml_dsa (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *mldsa_mode)
 
int botan_pubkey_load_ml_kem (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *mlkem_mode)
 
int botan_pubkey_load_rsa (botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
 
int botan_pubkey_load_slh_dsa (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *slhdsa_mode)
 
int botan_pubkey_load_sm2 (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_sm2_enc (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_x25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
 
int botan_pubkey_load_x448 (botan_pubkey_t *key, const uint8_t pubkey[56])
 
int botan_pubkey_rsa_get_e (botan_mp_t e, botan_pubkey_t key)
 
int botan_pubkey_rsa_get_n (botan_mp_t n, botan_pubkey_t key)
 
int botan_pubkey_sm2_compute_za (uint8_t out[], size_t *out_len, const char *ident, const char *hash_algo, const botan_pubkey_t key)
 
int botan_pubkey_view_ec_public_point (const botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pubkey_view_kyber_raw_key (botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pubkey_x25519_get_pubkey (botan_pubkey_t key, uint8_t output[32])
 
int botan_pubkey_x448_get_pubkey (botan_pubkey_t key, uint8_t output[56])
 

Function Documentation

◆ botan_mceies_decrypt()

int botan_mceies_decrypt ( botan_privkey_t mce_key_obj,
const char * aead,
const uint8_t ct[],
size_t ct_len,
const uint8_t ad[],
size_t ad_len,
uint8_t out[],
size_t * out_len )

Definition at line 1267 of file ffi_pkey_algs.cpp.

1274 {
1275 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
1277}
#define BOTAN_UNUSED
Definition assert.h:118
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:135

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_mceies_encrypt()

int botan_mceies_encrypt ( botan_pubkey_t mce_key_obj,
botan_rng_t rng_obj,
const char * aead,
const uint8_t pt[],
size_t pt_len,
const uint8_t ad[],
size_t ad_len,
uint8_t out[],
size_t * out_len )

Definition at line 1279 of file ffi_pkey_algs.cpp.

1287 {
1288 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1290}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_privkey_create_dh()

int botan_privkey_create_dh ( botan_privkey_t * key_obj,
botan_rng_t rng_obj,
const char * param_str )

Definition at line 501 of file ffi_pkey_algs.cpp.

501 {
502 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
503}
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition ffi_pkey.cpp:27

References botan_privkey_create().

◆ botan_privkey_create_dsa()

int botan_privkey_create_dsa ( botan_privkey_t * key,
botan_rng_t rng,
size_t pbits,
size_t qbits )

Generates DSA key pair. Gives to a caller control over key length and order of a subgroup 'q'.

Parameters
keyhandler to the resulting key
rnginitialized PRNG
pbitslength of the key in bits. Must be between in range (1024, 3072) and multiple of 64. Bit size of the prime 'p'
qbitsorder of the subgroup. Must be in range (160, 256) and multiple of 8
Returns
BOTAN_FFI_SUCCESS Success, ‘key’ initialized with DSA key
BOTAN_FFI_ERROR_NULL_POINTER either ‘key’ or ‘rng’ is NULL
BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either ‘pbits’ or ‘qbits’
BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

Definition at line 304 of file ffi_pkey_algs.cpp.

304 {
305#if defined(BOTAN_HAS_DSA)
306
307 if((rng_obj == nullptr) || (key == nullptr)) {
309 }
310
311 if((pbits % 64) || (qbits % 8) || (pbits < 1024) || (pbits > 3072) || (qbits < 160) || (qbits > 256)) {
313 }
314
315 return ffi_guard_thunk(__func__, [=]() -> int {
317 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
318 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
319 *key = new botan_privkey_struct(std::move(dsa));
320 return BOTAN_FFI_SUCCESS;
321 });
322#else
323 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
325#endif
326}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:129
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:130
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:63
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition ffi.cpp:118

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::DL_Group::Prime_Subgroup, and Botan_FFI::safe_get().

◆ botan_privkey_create_ecdh()

int botan_privkey_create_ecdh ( botan_privkey_t * key_obj,
botan_rng_t rng_obj,
const char * param_str )

Definition at line 537 of file ffi_pkey_algs.cpp.

537 {
538 if(param_str == nullptr) {
540 }
541
542 const std::string params(param_str);
543
544 if(params == "x25519" || params == "curve25519") {
545 return botan_privkey_create(key_obj, "X25519", "", rng_obj);
546 }
547
548 if(params == "x448") {
549 return botan_privkey_create(key_obj, "X448", "", rng_obj);
550 }
551
552 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
553}

References BOTAN_FFI_ERROR_NULL_POINTER, and botan_privkey_create().

◆ botan_privkey_create_ecdsa()

int botan_privkey_create_ecdsa ( botan_privkey_t * key_obj,
botan_rng_t rng_obj,
const char * param_str )

Definition at line 380 of file ffi_pkey_algs.cpp.

380 {
381 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
382}

References botan_privkey_create().

◆ botan_privkey_create_elgamal()

int botan_privkey_create_elgamal ( botan_privkey_t * key,
botan_rng_t rng,
size_t pbits,
size_t qbits )

Generates ElGamal key pair. Caller has a control over key length and order of a subgroup 'q'. Function is able to use two types of primes:

  • if pbits-1 == qbits then safe primes are used for key generation
  • otherwise generation uses group of prime order
Parameters
keyhandler to the resulting key
rnginitialized PRNG
pbitslength of the key in bits. Must be at least 1024
qbitsorder of the subgroup. Must be at least 160
Returns
BOTAN_FFI_SUCCESS Success, ‘key’ initialized with DSA key
BOTAN_FFI_ERROR_NULL_POINTER either ‘key’ or ‘rng’ is NULL
BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either ‘pbits’ or ‘qbits’
BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

Definition at line 442 of file ffi_pkey_algs.cpp.

442 {
443#if defined(BOTAN_HAS_ELGAMAL)
444
445 if((rng_obj == nullptr) || (key == nullptr)) {
447 }
448
449 if((pbits < 1024) || (qbits < 160)) {
451 }
452
453 Botan::DL_Group::PrimeType prime_type =
454 ((pbits - 1) == qbits) ? Botan::DL_Group::Strong : Botan::DL_Group::Prime_Subgroup;
455
456 return ffi_guard_thunk(__func__, [=]() -> int {
458 Botan::DL_Group group(rng, prime_type, pbits, qbits);
459 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
460 *key = new botan_privkey_struct(std::move(elg));
461 return BOTAN_FFI_SUCCESS;
462 });
463#else
464 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
466#endif
467}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::DL_Group::Prime_Subgroup, Botan_FFI::safe_get(), and Botan::DL_Group::Strong.

◆ botan_privkey_create_mceliece()

int botan_privkey_create_mceliece ( botan_privkey_t * key_obj,
botan_rng_t rng_obj,
size_t n,
size_t t )

Definition at line 1262 of file ffi_pkey_algs.cpp.

1262 {
1263 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1264 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1265}

References botan_privkey_create().

◆ botan_privkey_create_rsa()

int botan_privkey_create_rsa ( botan_privkey_t * key_obj,
botan_rng_t rng_obj,
size_t n_bits )

Definition at line 199 of file ffi_pkey_algs.cpp.

199 {
200 if(n_bits < 1024 || n_bits > 16 * 1024) {
202 }
203
204 std::string n_str = std::to_string(n_bits);
205
206 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
207}

References BOTAN_FFI_ERROR_BAD_PARAMETER, and botan_privkey_create().

◆ botan_privkey_dsa_get_x()

int botan_privkey_dsa_get_x ( botan_mp_t x,
botan_privkey_t key )

Definition at line 360 of file ffi_pkey_algs.cpp.

360 {
361 return botan_privkey_get_field(x, key, "x");
362}
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

References botan_privkey_get_field().

◆ botan_privkey_ed25519_get_privkey()

int botan_privkey_ed25519_get_privkey ( botan_privkey_t key,
uint8_t output[64] )

Definition at line 706 of file ffi_pkey_algs.cpp.

706 {
707#if defined(BOTAN_HAS_ED25519)
708 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
709 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
710 const auto ed_key = ed->raw_private_key_bits();
711 if(ed_key.size() != 64)
713 Botan::copy_mem(output, ed_key.data(), ed_key.size());
714 return BOTAN_FFI_SUCCESS;
715 } else {
717 }
718 });
719#else
720 BOTAN_UNUSED(key, output);
722#endif
723}
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition ffi.h:120
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:124
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:146

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::copy_mem().

◆ botan_privkey_ed448_get_privkey()

int botan_privkey_ed448_get_privkey ( botan_privkey_t key,
uint8_t output[57] )

Definition at line 774 of file ffi_pkey_algs.cpp.

774 {
775#if defined(BOTAN_HAS_ED448)
776 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
777 if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
778 const auto ed_key = ed->raw_private_key_bits();
779 Botan::copy_mem(std::span(output, 57), ed_key);
780 return BOTAN_FFI_SUCCESS;
781 } else {
783 }
784 });
785#else
786 BOTAN_UNUSED(key, output);
788#endif
789}
A private key for Ed448/Ed448ph according to RFC 8032.
Definition ed448.h:83

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::copy_mem().

◆ botan_privkey_get_field()

int botan_privkey_get_field ( botan_mp_t output,
botan_privkey_t key,
const char * field_name_cstr )

Definition at line 187 of file ffi_pkey_algs.cpp.

187 {
188 if(field_name_cstr == nullptr) {
190 }
191
192 const std::string field_name(field_name_cstr);
193
194 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); });
195}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

Referenced by botan_privkey_dsa_get_x(), botan_privkey_rsa_get_d(), botan_privkey_rsa_get_e(), botan_privkey_rsa_get_n(), botan_privkey_rsa_get_p(), and botan_privkey_rsa_get_q().

◆ botan_privkey_load_dh()

int botan_privkey_load_dh ( botan_privkey_t * key,
botan_mp_t p,
botan_mp_t g,
botan_mp_t x )

Definition at line 505 of file ffi_pkey_algs.cpp.

505 {
506#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
507 *key = nullptr;
508 return ffi_guard_thunk(__func__, [=]() -> int {
509 Botan::DL_Group group(safe_get(p), safe_get(g));
510 auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
511 *key = new botan_privkey_struct(std::move(dh));
512 return BOTAN_FFI_SUCCESS;
513 });
514#else
515 BOTAN_UNUSED(key, p, g, x);
517#endif
518}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_privkey_load_dsa()

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 )

Definition at line 328 of file ffi_pkey_algs.cpp.

328 {
329#if defined(BOTAN_HAS_DSA)
330 *key = nullptr;
331
332 return ffi_guard_thunk(__func__, [=]() -> int {
333 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
334 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(group, safe_get(x));
335 *key = new botan_privkey_struct(std::move(dsa));
336 return BOTAN_FFI_SUCCESS;
337 });
338#else
339 BOTAN_UNUSED(key, p, q, g, x);
341#endif
342}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_privkey_load_ecdh()

int botan_privkey_load_ecdh ( botan_privkey_t * key,
const botan_mp_t scalar,
const char * curve_name )

Definition at line 575 of file ffi_pkey_algs.cpp.

575 {
576#if defined(BOTAN_HAS_ECDH)
577 return ffi_guard_thunk(__func__, [=]() -> int {
578 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
579 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
580 if(rc == BOTAN_FFI_SUCCESS) {
581 *key = new botan_privkey_struct(std::move(p_key));
582 }
583 return rc;
584 });
585#else
586 BOTAN_UNUSED(key, scalar, curve_name);
588#endif
589}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_privkey_load_ecdsa()

int botan_privkey_load_ecdsa ( botan_privkey_t * key,
const botan_mp_t scalar,
const char * curve_name )

Definition at line 425 of file ffi_pkey_algs.cpp.

425 {
426#if defined(BOTAN_HAS_ECDSA)
427 return ffi_guard_thunk(__func__, [=]() -> int {
428 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
429 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
430 if(rc == BOTAN_FFI_SUCCESS) {
431 *key = new botan_privkey_struct(std::move(p_key));
432 }
433 return rc;
434 });
435#else
436 BOTAN_UNUSED(key, scalar, curve_name);
438#endif
439}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_privkey_load_ed25519()

int botan_privkey_load_ed25519 ( botan_privkey_t * key,
const uint8_t privkey[32] )

Definition at line 676 of file ffi_pkey_algs.cpp.

676 {
677#if defined(BOTAN_HAS_ED25519)
678 *key = nullptr;
679 return ffi_guard_thunk(__func__, [=]() -> int {
680 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
681 auto ed25519 = std::make_unique<Botan::Ed25519_PrivateKey>(privkey_vec);
682 *key = new botan_privkey_struct(std::move(ed25519));
683 return BOTAN_FFI_SUCCESS;
684 });
685#else
686 BOTAN_UNUSED(key, privkey);
688#endif
689}
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_privkey_load_ed448()

int botan_privkey_load_ed448 ( botan_privkey_t * key,
const uint8_t privkey[57] )

Definition at line 746 of file ffi_pkey_algs.cpp.

746 {
747#if defined(BOTAN_HAS_ED448)
748 *key = nullptr;
749 return ffi_guard_thunk(__func__, [=]() -> int {
750 auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
751 *key = new botan_privkey_struct(std::move(ed448));
752 return BOTAN_FFI_SUCCESS;
753 });
754#else
755 BOTAN_UNUSED(key, privkey);
757#endif
758}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_privkey_load_elgamal()

int botan_privkey_load_elgamal ( botan_privkey_t * key,
botan_mp_t p,
botan_mp_t g,
botan_mp_t x )

Loads ElGamal private key

Parameters
keyvariable populated with key material
pprime order of a Z_p group
ggroup generator
xprivate key
Precondition
key is NULL on input
Postcondition
function allocates memory and assigns to ‘key’
Returns
0 on success, a negative value on failure

Definition at line 484 of file ffi_pkey_algs.cpp.

484 {
485#if defined(BOTAN_HAS_ELGAMAL)
486 *key = nullptr;
487 return ffi_guard_thunk(__func__, [=]() -> int {
488 Botan::DL_Group group(safe_get(p), safe_get(g));
489 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(group, safe_get(x));
490 *key = new botan_privkey_struct(std::move(elg));
491 return BOTAN_FFI_SUCCESS;
492 });
493#else
494 BOTAN_UNUSED(key, p, g, x);
496#endif
497}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_privkey_load_frodokem()

int botan_privkey_load_frodokem ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * frodo_mode )

Algorithm specific key operation: FrodoKEM

Definition at line 1206 of file ffi_pkey_algs.cpp.

1206 {
1207#if defined(BOTAN_HAS_FRODOKEM)
1208 if(key == nullptr || privkey == nullptr || frodo_mode == nullptr) {
1210 }
1211
1212 *key = nullptr;
1213
1214 return ffi_guard_thunk(__func__, [=]() -> int {
1215 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1216 auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
1217 *key = new botan_privkey_struct(std::move(frodo_key));
1218 return BOTAN_FFI_SUCCESS;
1219 });
1220#else
1221 BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1223#endif
1224}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_privkey_load_kyber()

int botan_privkey_load_kyber ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len )

Definition at line 946 of file ffi_pkey_algs.cpp.

946 {
947#if defined(BOTAN_HAS_KYBER)
948 *key = nullptr;
949 switch(key_len) {
950 case 1632:
951 return ffi_guard_thunk(__func__, [=]() -> int {
952 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 1632);
953 auto kyber512 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber512_R3);
954 *key = new botan_privkey_struct(std::move(kyber512));
955 return BOTAN_FFI_SUCCESS;
956 });
957 case 2400:
958 return ffi_guard_thunk(__func__, [=]() -> int {
959 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 2400);
960 auto kyber768 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber768_R3);
961 *key = new botan_privkey_struct(std::move(kyber768));
962 return BOTAN_FFI_SUCCESS;
963 });
964 case 3168:
965 return ffi_guard_thunk(__func__, [=]() -> int {
966 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 3168);
967 auto kyber1024 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber1024_R3);
968 *key = new botan_privkey_struct(std::move(kyber1024));
969 return BOTAN_FFI_SUCCESS;
970 });
971 default:
972 BOTAN_UNUSED(key, privkey, key_len);
974 }
975#else
976 BOTAN_UNUSED(key, key_len, privkey);
978#endif
979}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::KyberMode::Kyber1024_R3, Botan::KyberMode::Kyber512_R3, and Botan::KyberMode::Kyber768_R3.

◆ botan_privkey_load_ml_dsa()

int botan_privkey_load_ml_dsa ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * mldsa_mode )

Definition at line 1102 of file ffi_pkey_algs.cpp.

1102 {
1103#if defined(BOTAN_HAS_ML_DSA)
1104 if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
1106 }
1107
1108 *key = nullptr;
1109
1110 return ffi_guard_thunk(__func__, [=]() -> int {
1111 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1112 if(!mode.is_ml_dsa()) {
1114 }
1115
1116 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1117 *key = new botan_privkey_struct(std::move(mldsa_key));
1118 return BOTAN_FFI_SUCCESS;
1119 });
1120#else
1121 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1123#endif
1124}
DilithiumMode ML_DSA_Mode
Definition ml_dsa.h:21

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_privkey_load_ml_kem()

int botan_privkey_load_ml_kem ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * mlkem_mode )

Definition at line 1050 of file ffi_pkey_algs.cpp.

1050 {
1051#if defined(BOTAN_HAS_ML_KEM)
1052 if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
1054 }
1055
1056 *key = nullptr;
1057
1058 return ffi_guard_thunk(__func__, [=]() -> int {
1059 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1060 if(!mode.is_ml_kem()) {
1062 }
1063
1064 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1065 *key = new botan_privkey_struct(std::move(mlkem_key));
1066 return BOTAN_FFI_SUCCESS;
1067 });
1068#else
1069 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1071#endif
1072}
KyberMode ML_KEM_Mode
Definition ml_kem.h:21

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_privkey_load_rsa()

int botan_privkey_load_rsa ( botan_privkey_t * key,
botan_mp_t rsa_p,
botan_mp_t rsa_q,
botan_mp_t rsa_e )

Definition at line 209 of file ffi_pkey_algs.cpp.

209 {
210#if defined(BOTAN_HAS_RSA)
211 *key = nullptr;
212
213 return ffi_guard_thunk(__func__, [=]() -> int {
214 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p), safe_get(rsa_q), safe_get(rsa_e));
215 *key = new botan_privkey_struct(std::move(rsa));
216 return BOTAN_FFI_SUCCESS;
217 });
218#else
219 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
221#endif
222}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_privkey_load_rsa_pkcs1()

int botan_privkey_load_rsa_pkcs1 ( botan_privkey_t * key,
const uint8_t bits[],
size_t len )

Definition at line 224 of file ffi_pkey_algs.cpp.

224 {
225#if defined(BOTAN_HAS_RSA)
226 *key = nullptr;
227
228 Botan::secure_vector<uint8_t> src(bits, bits + len);
229 return ffi_guard_thunk(__func__, [=]() -> int {
231 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, src);
232 *key = new botan_privkey_struct(std::move(rsa));
233 return BOTAN_FFI_SUCCESS;
234 });
235#else
236 BOTAN_UNUSED(key, bits, len);
238#endif
239}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan::AlgorithmIdentifier::USE_NULL_PARAM.

◆ botan_privkey_load_slh_dsa()

int botan_privkey_load_slh_dsa ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * slhdsa_mode )

Definition at line 1154 of file ffi_pkey_algs.cpp.

1154 {
1155#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1156 if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
1158 }
1159
1160 *key = nullptr;
1161
1162 return ffi_guard_thunk(__func__, [=]() -> int {
1163 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1164 if(!mode.is_slh_dsa()) {
1166 }
1167
1168 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1169 *key = new botan_privkey_struct(std::move(slhdsa_key));
1170 return BOTAN_FFI_SUCCESS;
1171 });
1172#else
1173 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1175#endif
1176}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_privkey_load_sm2()

int botan_privkey_load_sm2 ( botan_privkey_t * key,
const botan_mp_t scalar,
const char * curve_name )

Definition at line 646 of file ffi_pkey_algs.cpp.

646 {
647#if defined(BOTAN_HAS_SM2)
648 return ffi_guard_thunk(__func__, [=]() -> int {
649 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
650 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
651
652 if(rc == BOTAN_FFI_SUCCESS) {
653 *key = new botan_privkey_struct(std::move(p_key));
654 }
655 return rc;
656 });
657#else
658 BOTAN_UNUSED(key, scalar, curve_name);
660#endif
661}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

Referenced by botan_privkey_load_sm2_enc().

◆ botan_privkey_load_sm2_enc()

int botan_privkey_load_sm2_enc ( botan_privkey_t * key,
const botan_mp_t scalar,
const char * curve_name )

Definition at line 670 of file ffi_pkey_algs.cpp.

670 {
671 return botan_privkey_load_sm2(key, scalar, curve_name);
672}
int botan_privkey_load_sm2(botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)

References botan_privkey_load_sm2().

◆ botan_privkey_load_x25519()

int botan_privkey_load_x25519 ( botan_privkey_t * key,
const uint8_t privkey[32] )

Definition at line 810 of file ffi_pkey_algs.cpp.

810 {
811#if defined(BOTAN_HAS_X25519)
812 *key = nullptr;
813 return ffi_guard_thunk(__func__, [=]() -> int {
814 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
815 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(privkey_vec);
816 *key = new botan_privkey_struct(std::move(x25519));
817 return BOTAN_FFI_SUCCESS;
818 });
819#else
820 BOTAN_UNUSED(key, privkey);
822#endif
823}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_privkey_load_x448()

int botan_privkey_load_x448 ( botan_privkey_t * key,
const uint8_t privkey[56] )

Definition at line 880 of file ffi_pkey_algs.cpp.

880 {
881#if defined(BOTAN_HAS_X448)
882 *key = nullptr;
883 return ffi_guard_thunk(__func__, [=]() -> int {
884 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span(privkey, 56));
885 *key = new botan_privkey_struct(std::move(x448));
886 return BOTAN_FFI_SUCCESS;
887 });
888#else
889 BOTAN_UNUSED(key, privkey);
891#endif
892}
Point448 x448(const ScalarX448 &k, const Point448 &u)
Multiply a scalar k with a point u.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_privkey_rsa_get_d()

int botan_privkey_rsa_get_d ( botan_mp_t d,
botan_privkey_t key )

Definition at line 271 of file ffi_pkey_algs.cpp.

271 {
272 return botan_privkey_get_field(d, key, "d");
273}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_e()

int botan_privkey_rsa_get_e ( botan_mp_t e,
botan_privkey_t key )

Definition at line 267 of file ffi_pkey_algs.cpp.

267 {
268 return botan_privkey_get_field(e, key, "e");
269}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_n()

int botan_privkey_rsa_get_n ( botan_mp_t n,
botan_privkey_t key )

Definition at line 263 of file ffi_pkey_algs.cpp.

263 {
264 return botan_privkey_get_field(n, key, "n");
265}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_p()

int botan_privkey_rsa_get_p ( botan_mp_t p,
botan_privkey_t key )

Definition at line 255 of file ffi_pkey_algs.cpp.

255 {
256 return botan_privkey_get_field(p, key, "p");
257}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_privkey()

int botan_privkey_rsa_get_privkey ( botan_privkey_t rsa_key,
uint8_t out[],
size_t * out_len,
uint32_t flags )

Definition at line 283 of file ffi_pkey_algs.cpp.

283 {
284#if defined(BOTAN_HAS_RSA)
285 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
286 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
288 return write_vec_output(out, out_len, rsa->private_key_bits());
289 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
290 return write_str_output(out, out_len, Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
291 else
293 } else {
295 }
296 });
297#else
298 BOTAN_UNUSED(rsa_key, out, out_len, flags);
300#endif
301}
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1181
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1180
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:128
std::string encode(const uint8_t der[], size_t length, std::string_view label, size_t width)
Definition pem.cpp:39
int write_str_output(uint8_t out[], size_t *out_len, std::string_view str)
Definition ffi_util.h:205
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:201

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, BOTAN_UNUSED, Botan::PEM_Code::encode(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

◆ botan_privkey_rsa_get_q()

int botan_privkey_rsa_get_q ( botan_mp_t q,
botan_privkey_t key )

Definition at line 259 of file ffi_pkey_algs.cpp.

259 {
260 return botan_privkey_get_field(q, key, "q");
261}

References botan_privkey_get_field().

◆ botan_privkey_view_kyber_raw_key()

int botan_privkey_view_kyber_raw_key ( botan_privkey_t key,
botan_view_ctx ctx,
botan_view_bin_fn view )

Definition at line 1016 of file ffi_pkey_algs.cpp.

1016 {
1017#if defined(BOTAN_HAS_KYBER)
1018 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1019 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1020 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1021 } else {
1023 }
1024 });
1025#else
1026 BOTAN_UNUSED(key, ctx, view);
1028#endif
1029}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:146

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::invoke_view_callback().

◆ botan_privkey_x25519_get_privkey()

int botan_privkey_x25519_get_privkey ( botan_privkey_t key,
uint8_t output[32] )

Definition at line 840 of file ffi_pkey_algs.cpp.

840 {
841#if defined(BOTAN_HAS_X25519)
842 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
843 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
844 const auto x25519_key = x25519->raw_private_key_bits();
845 if(x25519_key.size() != 32)
847 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
848 return BOTAN_FFI_SUCCESS;
849 } else {
851 }
852 });
853#else
854 BOTAN_UNUSED(key, output);
856#endif
857}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::copy_mem().

◆ botan_privkey_x448_get_privkey()

int botan_privkey_x448_get_privkey ( botan_privkey_t key,
uint8_t output[56] )

Definition at line 908 of file ffi_pkey_algs.cpp.

908 {
909#if defined(BOTAN_HAS_X448)
910 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
911 if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
912 const auto x448_key = x448->raw_private_key_bits();
913 Botan::copy_mem(std::span(output, 56), x448_key);
914 return BOTAN_FFI_SUCCESS;
915 } else {
917 }
918 });
919#else
920 BOTAN_UNUSED(key, output);
922#endif
923}
A private key for the X448 key agreement scheme according to RFC 7748.
Definition x448.h:67

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::copy_mem().

◆ botan_pubkey_dsa_get_g()

int botan_pubkey_dsa_get_g ( botan_mp_t g,
botan_pubkey_t key )

Definition at line 372 of file ffi_pkey_algs.cpp.

372 {
373 return botan_pubkey_get_field(g, key, "g");
374}
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_p()

int botan_pubkey_dsa_get_p ( botan_mp_t p,
botan_pubkey_t key )

Definition at line 364 of file ffi_pkey_algs.cpp.

364 {
365 return botan_pubkey_get_field(p, key, "p");
366}

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_q()

int botan_pubkey_dsa_get_q ( botan_mp_t q,
botan_pubkey_t key )

Definition at line 368 of file ffi_pkey_algs.cpp.

368 {
369 return botan_pubkey_get_field(q, key, "q");
370}

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_y()

int botan_pubkey_dsa_get_y ( botan_mp_t y,
botan_pubkey_t key )

Definition at line 376 of file ffi_pkey_algs.cpp.

376 {
377 return botan_pubkey_get_field(y, key, "y");
378}

References botan_pubkey_get_field().

◆ botan_pubkey_ecc_key_used_explicit_encoding()

int botan_pubkey_ecc_key_used_explicit_encoding ( botan_pubkey_t key)

Definition at line 386 of file ffi_pkey_algs.cpp.

386 {
387#if defined(BOTAN_HAS_ECC_KEY)
388 return ffi_guard_thunk(__func__, [=]() -> int {
389 const Botan::Public_Key& pub_key = safe_get(key);
390 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
391
392 if(ec_key == nullptr) {
394 }
395
396 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
397 });
398#else
399 BOTAN_UNUSED(key);
401#endif
402}
bool used_explicit_encoding() const
Definition ec_group.h:199
const EC_Group & domain() const
Definition ecc_key.cpp:59

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, Botan::EC_PublicKey::domain(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::EC_Group::used_explicit_encoding().

◆ botan_pubkey_ed25519_get_pubkey()

int botan_pubkey_ed25519_get_pubkey ( botan_pubkey_t key,
uint8_t output[32] )

Definition at line 725 of file ffi_pkey_algs.cpp.

725 {
726#if defined(BOTAN_HAS_ED25519)
727 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
728 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
729 const std::vector<uint8_t>& ed_key = ed->get_public_key();
730 if(ed_key.size() != 32)
732 Botan::copy_mem(output, ed_key.data(), ed_key.size());
733 return BOTAN_FFI_SUCCESS;
734 } else {
736 }
737 });
738#else
739 BOTAN_UNUSED(key, output);
741#endif
742}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::copy_mem().

◆ botan_pubkey_ed448_get_pubkey()

int botan_pubkey_ed448_get_pubkey ( botan_pubkey_t key,
uint8_t output[57] )

Definition at line 791 of file ffi_pkey_algs.cpp.

791 {
792#if defined(BOTAN_HAS_ED448)
793 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
794 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
795 const auto ed_key = ed->public_key_bits();
796 Botan::copy_mem(std::span(output, 57), ed_key);
797 return BOTAN_FFI_SUCCESS;
798 } else {
800 }
801 });
802#else
803 BOTAN_UNUSED(key, output);
805#endif
806}
A public key for Ed448/Ed448ph according to RFC 8032.
Definition ed448.h:27

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::copy_mem().

◆ botan_pubkey_get_field()

int botan_pubkey_get_field ( botan_mp_t output,
botan_pubkey_t key,
const char * field_name_cstr )

Definition at line 177 of file ffi_pkey_algs.cpp.

177 {
178 if(field_name_cstr == nullptr) {
180 }
181
182 const std::string field_name(field_name_cstr);
183
184 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); });
185}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

Referenced by botan_pubkey_dsa_get_g(), botan_pubkey_dsa_get_p(), botan_pubkey_dsa_get_q(), botan_pubkey_dsa_get_y(), botan_pubkey_rsa_get_e(), and botan_pubkey_rsa_get_n().

◆ botan_pubkey_load_dh()

int botan_pubkey_load_dh ( botan_pubkey_t * key,
botan_mp_t p,
botan_mp_t g,
botan_mp_t y )

Loads Diffie Hellman public key

Parameters
keyvariable populated with key material
pprime order of a Z_p group
ggroup generator
ypublic key
Precondition
key is NULL on input
Postcondition
function allocates memory and assigns to ‘key’
Returns
0 on success, a negative value on failure

Definition at line 520 of file ffi_pkey_algs.cpp.

520 {
521#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
522 *key = nullptr;
523 return ffi_guard_thunk(__func__, [=]() -> int {
524 Botan::DL_Group group(safe_get(p), safe_get(g));
525 auto dh = std::make_unique<Botan::DH_PublicKey>(group, safe_get(y));
526 *key = new botan_pubkey_struct(std::move(dh));
527 return BOTAN_FFI_SUCCESS;
528 });
529#else
530 BOTAN_UNUSED(key, p, g, y);
532#endif
533}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_pubkey_load_dsa()

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 )

Definition at line 344 of file ffi_pkey_algs.cpp.

344 {
345#if defined(BOTAN_HAS_DSA)
346 *key = nullptr;
347
348 return ffi_guard_thunk(__func__, [=]() -> int {
349 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
350 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
351 *key = new botan_pubkey_struct(std::move(dsa));
352 return BOTAN_FFI_SUCCESS;
353 });
354#else
355 BOTAN_UNUSED(key, p, q, g, y);
357#endif
358}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_pubkey_load_ecdh()

int botan_pubkey_load_ecdh ( botan_pubkey_t * key,
const botan_mp_t public_x,
const botan_mp_t public_y,
const char * curve_name )

Definition at line 555 of file ffi_pkey_algs.cpp.

558 {
559#if defined(BOTAN_HAS_ECDH)
560 return ffi_guard_thunk(__func__, [=]() -> int {
561 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
562 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
563
564 if(rc == BOTAN_FFI_SUCCESS) {
565 *key = new botan_pubkey_struct(std::move(p_key));
566 }
567 return rc;
568 });
569#else
570 BOTAN_UNUSED(key, public_x, public_y, curve_name);
572#endif
573}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_pubkey_load_ecdsa()

int botan_pubkey_load_ecdsa ( botan_pubkey_t * key,
const botan_mp_t public_x,
const botan_mp_t public_y,
const char * curve_name )

Definition at line 404 of file ffi_pkey_algs.cpp.

407 {
408#if defined(BOTAN_HAS_ECDSA)
409 return ffi_guard_thunk(__func__, [=]() -> int {
410 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
411
412 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
413 if(rc == BOTAN_FFI_SUCCESS) {
414 *key = new botan_pubkey_struct(std::move(p_key));
415 }
416
417 return rc;
418 });
419#else
420 BOTAN_UNUSED(key, public_x, public_y, curve_name);
422#endif
423}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_pubkey_load_ed25519()

int botan_pubkey_load_ed25519 ( botan_pubkey_t * key,
const uint8_t pubkey[32] )

Definition at line 691 of file ffi_pkey_algs.cpp.

691 {
692#if defined(BOTAN_HAS_ED25519)
693 *key = nullptr;
694 return ffi_guard_thunk(__func__, [=]() -> int {
695 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
696 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
697 *key = new botan_pubkey_struct(std::move(ed25519));
698 return BOTAN_FFI_SUCCESS;
699 });
700#else
701 BOTAN_UNUSED(key, pubkey);
703#endif
704}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_pubkey_load_ed448()

int botan_pubkey_load_ed448 ( botan_pubkey_t * key,
const uint8_t pubkey[57] )

Definition at line 760 of file ffi_pkey_algs.cpp.

760 {
761#if defined(BOTAN_HAS_ED448)
762 *key = nullptr;
763 return ffi_guard_thunk(__func__, [=]() -> int {
764 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
765 *key = new botan_pubkey_struct(std::move(ed448));
766 return BOTAN_FFI_SUCCESS;
767 });
768#else
769 BOTAN_UNUSED(key, pubkey);
771#endif
772}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_pubkey_load_elgamal()

int botan_pubkey_load_elgamal ( botan_pubkey_t * key,
botan_mp_t p,
botan_mp_t g,
botan_mp_t y )

Loads ElGamal public key

Parameters
keyvariable populated with key material
pprime order of a Z_p group
ggroup generator
ypublic key
Precondition
key is NULL on input
Postcondition
function allocates memory and assigns to ‘key’
Returns
0 on success, a negative value on failure

Definition at line 469 of file ffi_pkey_algs.cpp.

469 {
470#if defined(BOTAN_HAS_ELGAMAL)
471 *key = nullptr;
472 return ffi_guard_thunk(__func__, [=]() -> int {
473 Botan::DL_Group group(safe_get(p), safe_get(g));
474 auto elg = std::make_unique<Botan::ElGamal_PublicKey>(group, safe_get(y));
475 *key = new botan_pubkey_struct(std::move(elg));
476 return BOTAN_FFI_SUCCESS;
477 });
478#else
479 BOTAN_UNUSED(key, p, g, y);
481#endif
482}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_pubkey_load_frodokem()

int botan_pubkey_load_frodokem ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * frodo_mode )

Definition at line 1226 of file ffi_pkey_algs.cpp.

1226 {
1227#if defined(BOTAN_HAS_FRODOKEM)
1228 if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
1230 }
1231
1232 *key = nullptr;
1233
1234 return ffi_guard_thunk(__func__, [=]() -> int {
1235 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1236 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1237 *key = new botan_pubkey_struct(std::move(frodo_key));
1238 return BOTAN_FFI_SUCCESS;
1239 });
1240#else
1241 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1243#endif
1244}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_pubkey_load_kyber()

int botan_pubkey_load_kyber ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len )

Definition at line 981 of file ffi_pkey_algs.cpp.

981 {
982#if defined(BOTAN_HAS_KYBER)
983 *key = nullptr;
984 switch(key_len) {
985 case 800:
986 return ffi_guard_thunk(__func__, [=]() -> int {
987 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 800);
988 auto kyber512 = std::make_unique<Botan::Kyber_PublicKey>(pubkey_vec, Botan::KyberMode::Kyber512_R3);
989 *key = new botan_pubkey_struct(std::move(kyber512));
990 return BOTAN_FFI_SUCCESS;
991 });
992 case 1184:
993 return ffi_guard_thunk(__func__, [=]() -> int {
994 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 1184);
995 auto kyber768 = std::make_unique<Botan::Kyber_PublicKey>(pubkey_vec, Botan::KyberMode::Kyber768_R3);
996 *key = new botan_pubkey_struct(std::move(kyber768));
997 return BOTAN_FFI_SUCCESS;
998 });
999 case 1568:
1000 return ffi_guard_thunk(__func__, [=]() -> int {
1001 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 1568);
1002 auto kyber1024 = std::make_unique<Botan::Kyber_PublicKey>(pubkey_vec, Botan::KyberMode::Kyber1024_R3);
1003 *key = new botan_pubkey_struct(std::move(kyber1024));
1004 return BOTAN_FFI_SUCCESS;
1005 });
1006 default:
1007 BOTAN_UNUSED(key, pubkey, key_len);
1009 }
1010#else
1011 BOTAN_UNUSED(key, pubkey, key_len);
1013#endif
1014}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::KyberMode::Kyber1024_R3, Botan::KyberMode::Kyber512_R3, and Botan::KyberMode::Kyber768_R3.

◆ botan_pubkey_load_ml_dsa()

int botan_pubkey_load_ml_dsa ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * mldsa_mode )

Definition at line 1126 of file ffi_pkey_algs.cpp.

1126 {
1127#if defined(BOTAN_HAS_ML_DSA)
1128 if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
1130 }
1131
1132 *key = nullptr;
1133
1134 return ffi_guard_thunk(__func__, [=]() -> int {
1135 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1136 if(!mode.is_ml_dsa()) {
1138 }
1139
1140 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1141 *key = new botan_pubkey_struct(std::move(mldsa_key));
1142 return BOTAN_FFI_SUCCESS;
1143 });
1144#else
1145 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1147#endif
1148}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_pubkey_load_ml_kem()

int botan_pubkey_load_ml_kem ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * mlkem_mode )

Definition at line 1074 of file ffi_pkey_algs.cpp.

1074 {
1075#if defined(BOTAN_HAS_ML_KEM)
1076 if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
1078 }
1079
1080 *key = nullptr;
1081
1082 return ffi_guard_thunk(__func__, [=]() -> int {
1083 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1084 if(!mode.is_ml_kem()) {
1086 }
1087
1088 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1089 *key = new botan_pubkey_struct(std::move(mlkem_key));
1090 return BOTAN_FFI_SUCCESS;
1091 });
1092#else
1093 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1095#endif
1096}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_pubkey_load_rsa()

int botan_pubkey_load_rsa ( botan_pubkey_t * key,
botan_mp_t n,
botan_mp_t e )

Definition at line 241 of file ffi_pkey_algs.cpp.

241 {
242#if defined(BOTAN_HAS_RSA)
243 *key = nullptr;
244 return ffi_guard_thunk(__func__, [=]() -> int {
245 auto rsa = std::make_unique<Botan::RSA_PublicKey>(safe_get(n), safe_get(e));
246 *key = new botan_pubkey_struct(std::move(rsa));
247 return BOTAN_FFI_SUCCESS;
248 });
249#else
250 BOTAN_UNUSED(key, n, e);
252#endif
253}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_pubkey_load_slh_dsa()

int botan_pubkey_load_slh_dsa ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * slhdsa_mode )

Definition at line 1178 of file ffi_pkey_algs.cpp.

1178 {
1179#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1180 if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
1182 }
1183
1184 *key = nullptr;
1185
1186 return ffi_guard_thunk(__func__, [=]() -> int {
1187 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1188 if(!mode.is_slh_dsa()) {
1190 }
1191
1192 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1193 *key = new botan_pubkey_struct(std::move(mldsa_key));
1194 return BOTAN_FFI_SUCCESS;
1195 });
1196#else
1197 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1199#endif
1200}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_pubkey_load_sm2()

int botan_pubkey_load_sm2 ( botan_pubkey_t * key,
const botan_mp_t public_x,
const botan_mp_t public_y,
const char * curve_name )

Definition at line 627 of file ffi_pkey_algs.cpp.

630 {
631#if defined(BOTAN_HAS_SM2)
632 return ffi_guard_thunk(__func__, [=]() -> int {
633 std::unique_ptr<Botan::SM2_PublicKey> p_key;
634 if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name)) {
635 *key = new botan_pubkey_struct(std::move(p_key));
636 return BOTAN_FFI_SUCCESS;
637 }
639 });
640#else
641 BOTAN_UNUSED(key, public_x, public_y, curve_name);
643#endif
644}
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:143

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

Referenced by botan_pubkey_load_sm2_enc().

◆ botan_pubkey_load_sm2_enc()

int botan_pubkey_load_sm2_enc ( botan_pubkey_t * key,
const botan_mp_t public_x,
const botan_mp_t public_y,
const char * curve_name )

Definition at line 663 of file ffi_pkey_algs.cpp.

666 {
667 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
668}
int botan_pubkey_load_sm2(botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)

References botan_pubkey_load_sm2().

◆ botan_pubkey_load_x25519()

int botan_pubkey_load_x25519 ( botan_pubkey_t * key,
const uint8_t pubkey[32] )

Definition at line 825 of file ffi_pkey_algs.cpp.

825 {
826#if defined(BOTAN_HAS_X25519)
827 *key = nullptr;
828 return ffi_guard_thunk(__func__, [=]() -> int {
829 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
830 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(pubkey_vec);
831 *key = new botan_pubkey_struct(std::move(x25519));
832 return BOTAN_FFI_SUCCESS;
833 });
834#else
835 BOTAN_UNUSED(key, pubkey);
837#endif
838}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_pubkey_load_x448()

int botan_pubkey_load_x448 ( botan_pubkey_t * key,
const uint8_t pubkey[56] )

Definition at line 894 of file ffi_pkey_algs.cpp.

894 {
895#if defined(BOTAN_HAS_X448)
896 *key = nullptr;
897 return ffi_guard_thunk(__func__, [=]() -> int {
898 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span(pubkey, 56));
899 *key = new botan_pubkey_struct(std::move(x448));
900 return BOTAN_FFI_SUCCESS;
901 });
902#else
903 BOTAN_UNUSED(key, pubkey);
905#endif
906}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan_FFI::ffi_guard_thunk().

◆ botan_pubkey_rsa_get_e()

int botan_pubkey_rsa_get_e ( botan_mp_t e,
botan_pubkey_t key )

Definition at line 275 of file ffi_pkey_algs.cpp.

275 {
276 return botan_pubkey_get_field(e, key, "e");
277}

References botan_pubkey_get_field().

◆ botan_pubkey_rsa_get_n()

int botan_pubkey_rsa_get_n ( botan_mp_t n,
botan_pubkey_t key )

Definition at line 279 of file ffi_pkey_algs.cpp.

279 {
280 return botan_pubkey_get_field(n, key, "n");
281}

References botan_pubkey_get_field().

◆ botan_pubkey_sm2_compute_za()

int botan_pubkey_sm2_compute_za ( uint8_t out[],
size_t * out_len,
const char * ident,
const char * hash_algo,
const botan_pubkey_t key )

Definition at line 593 of file ffi_pkey_algs.cpp.

594 {
595 if(out == nullptr || out_len == nullptr) {
597 }
598 if(ident == nullptr || hash_algo == nullptr || key == nullptr) {
600 }
601
602#if defined(BOTAN_HAS_SM2)
603 return ffi_guard_thunk(__func__, [=]() -> int {
604 const Botan::Public_Key& pub_key = safe_get(key);
605 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
606
607 if(ec_key == nullptr) {
609 }
610
611 if(ec_key->algo_name() != "SM2") {
613 }
614
615 const std::string ident_str(ident);
616 std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
617
618 const std::vector<uint8_t> za = Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->public_point());
619
620 return write_vec_output(out, out_len, za);
621 });
622#else
624#endif
625}
virtual std::string algo_name() const =0
const EC_Point & public_point() const
Definition ecc_key.cpp:64
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:298
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, std::string_view user_id, const EC_Group &group, const EC_Point &point)
Definition sm2.cpp:244

References Botan::Asymmetric_Key::algo_name(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, Botan::HashFunction::create_or_throw(), Botan::EC_PublicKey::domain(), Botan_FFI::ffi_guard_thunk(), Botan::EC_PublicKey::public_point(), Botan_FFI::safe_get(), Botan::sm2_compute_za(), and Botan_FFI::write_vec_output().

◆ botan_pubkey_view_ec_public_point()

int botan_pubkey_view_ec_public_point ( botan_pubkey_t key,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the uncompressed public point associated with the key

Definition at line 1246 of file ffi_pkey_algs.cpp.

1246 {
1247#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1248 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1249 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1250 auto pt = ecc->public_point().encode(Botan::EC_Point_Format::Uncompressed);
1251 return invoke_view_callback(view, ctx, pt);
1252 } else {
1254 }
1255 });
1256#else
1257 BOTAN_UNUSED(key, view, ctx);
1259#endif
1260}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::invoke_view_callback(), and Botan::Uncompressed.

◆ botan_pubkey_view_kyber_raw_key()

int botan_pubkey_view_kyber_raw_key ( botan_pubkey_t key,
botan_view_ctx ctx,
botan_view_bin_fn view )

Definition at line 1031 of file ffi_pkey_algs.cpp.

1031 {
1032#if defined(BOTAN_HAS_KYBER)
1033 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1034 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1035 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1036 } else {
1038 }
1039 });
1040#else
1041 BOTAN_UNUSED(key, ctx, view);
1043#endif
1044}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::invoke_view_callback().

◆ botan_pubkey_x25519_get_pubkey()

int botan_pubkey_x25519_get_pubkey ( botan_pubkey_t key,
uint8_t output[32] )

Definition at line 859 of file ffi_pkey_algs.cpp.

859 {
860#if defined(BOTAN_HAS_X25519)
861 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
862 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
863 const std::vector<uint8_t>& x25519_key = x25519->public_value();
864 if(x25519_key.size() != 32)
866 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
867 return BOTAN_FFI_SUCCESS;
868 } else {
870 }
871 });
872#else
873 BOTAN_UNUSED(key, output);
875#endif
876}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::copy_mem().

◆ botan_pubkey_x448_get_pubkey()

int botan_pubkey_x448_get_pubkey ( botan_pubkey_t key,
uint8_t output[56] )

Definition at line 925 of file ffi_pkey_algs.cpp.

925 {
926#if defined(BOTAN_HAS_X448)
927 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
928 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
929 const std::vector<uint8_t>& x448_key = x448->public_value();
930 Botan::copy_mem(std::span(output, 56), x448_key);
931 return BOTAN_FFI_SUCCESS;
932 } else {
934 }
935 });
936#else
937 BOTAN_UNUSED(key, output);
939#endif
940}
A public key for the X448 key agreement scheme according to RFC 7748.
Definition x448.h:19

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::copy_mem().