Botan 3.8.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_classic_mceliece (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *cmce_mode)
 
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_classic_mceliece (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *cmce_mode)
 
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 1400 of file ffi_pkey_algs.cpp.

1407 {
1408 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
1410}
#define BOTAN_UNUSED
Definition assert.h:120
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:136

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 1412 of file ffi_pkey_algs.cpp.

1420 {
1421 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1423}

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 543 of file ffi_pkey_algs.cpp.

543 {
544 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
545}
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition ffi_pkey.cpp:29

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 324 of file ffi_pkey_algs.cpp.

324 {
325#if defined(BOTAN_HAS_DSA)
326
327 if((rng_obj == nullptr) || (key == nullptr)) {
329 }
330
331 if((pbits % 64) || (qbits % 8) || (pbits < 1024) || (pbits > 3072) || (qbits < 160) || (qbits > 256)) {
333 }
334
335 return ffi_guard_thunk(__func__, [=]() -> int {
337 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
338 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
339 *key = new botan_privkey_struct(std::move(dsa));
340 return BOTAN_FFI_SUCCESS;
341 });
342#else
343 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
345#endif
346}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:130
@ BOTAN_FFI_SUCCESS
Definition ffi.h:113
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:131
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:67
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:83

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 585 of file ffi_pkey_algs.cpp.

585 {
586 if(key_obj == nullptr || param_str == nullptr) {
588 }
589 *key_obj = nullptr;
590
591 const std::string params(param_str);
592
593 if(params == "X25519" || params == "x25519" || params == "curve25519") {
594 return botan_privkey_create(key_obj, "X25519", "", rng_obj);
595 }
596
597 if(params == "X448" || params == "x448") {
598 return botan_privkey_create(key_obj, "X448", "", rng_obj);
599 }
600
601 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
602}

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 406 of file ffi_pkey_algs.cpp.

406 {
407 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
408}

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 478 of file ffi_pkey_algs.cpp.

478 {
479#if defined(BOTAN_HAS_ELGAMAL)
480 if(key == nullptr || rng_obj == nullptr) {
482 }
483 *key = nullptr;
484
485 if(pbits < 1024 || qbits < 160) {
487 }
488
489 Botan::DL_Group::PrimeType prime_type =
490 ((pbits - 1) == qbits) ? Botan::DL_Group::Strong : Botan::DL_Group::Prime_Subgroup;
491
492 return ffi_guard_thunk(__func__, [=]() -> int {
494 Botan::DL_Group group(rng, prime_type, pbits, qbits);
495 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
496 *key = new botan_privkey_struct(std::move(elg));
497 return BOTAN_FFI_SUCCESS;
498 });
499#else
500 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
502#endif
503}

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 1395 of file ffi_pkey_algs.cpp.

1395 {
1396 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1397 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1398}

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 210 of file ffi_pkey_algs.cpp.

210 {
211 if(n_bits < 1024 || n_bits > 16 * 1024) {
213 }
214
215 std::string n_str = std::to_string(n_bits);
216
217 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
218}

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 386 of file ffi_pkey_algs.cpp.

386 {
387 return botan_privkey_get_field(x, key, "x");
388}
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 778 of file ffi_pkey_algs.cpp.

778 {
779#if defined(BOTAN_HAS_ED25519)
780 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
781 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
782 const auto ed_key = ed->raw_private_key_bits();
783 if(ed_key.size() != 64) {
785 }
786 Botan::copy_mem(output, ed_key.data(), ed_key.size());
787 return BOTAN_FFI_SUCCESS;
788 } else {
790 }
791 });
792#else
793 BOTAN_UNUSED(key, output);
795#endif
796}
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition ffi.h:121
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:145
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:149

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 854 of file ffi_pkey_algs.cpp.

854 {
855#if defined(BOTAN_HAS_ED448)
856 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
857 if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
858 const auto ed_key = ed->raw_private_key_bits();
859 Botan::copy_mem(std::span(output, 57), ed_key);
860 return BOTAN_FFI_SUCCESS;
861 } else {
863 }
864 });
865#else
866 BOTAN_UNUSED(key, output);
868#endif
869}
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 198 of file ffi_pkey_algs.cpp.

198 {
199 if(field_name_cstr == nullptr) {
201 }
202
203 const std::string field_name(field_name_cstr);
204
205 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); });
206}

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_classic_mceliece()

int botan_privkey_load_classic_mceliece ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * cmce_mode )

Algorithm specific key operation: Classic McEliece

Definition at line 1333 of file ffi_pkey_algs.cpp.

1336 {
1337#if defined(BOTAN_HAS_CLASSICMCELIECE)
1338 if(key == nullptr || privkey == nullptr || cmce_mode == nullptr) {
1340 }
1341
1342 *key = nullptr;
1343
1344 return ffi_guard_thunk(__func__, [=]() -> int {
1345 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1346 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
1347 *key = new botan_privkey_struct(std::move(cmce_key));
1348 return BOTAN_FFI_SUCCESS;
1349 });
1350#else
1351 BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1353#endif
1354}
static Classic_McEliece_Parameter_Set from_string(std::string_view param_name)
Get the parameter set for a given parameter set name.

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

◆ 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 547 of file ffi_pkey_algs.cpp.

547 {
548#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
549 if(key == nullptr) {
551 }
552 *key = nullptr;
553 return ffi_guard_thunk(__func__, [=]() -> int {
554 Botan::DL_Group group(safe_get(p), safe_get(g));
555 auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
556 *key = new botan_privkey_struct(std::move(dh));
557 return BOTAN_FFI_SUCCESS;
558 });
559#else
560 BOTAN_UNUSED(key, p, g, x);
562#endif
563}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 348 of file ffi_pkey_algs.cpp.

348 {
349#if defined(BOTAN_HAS_DSA)
350 if(key == nullptr) {
352 }
353 *key = nullptr;
354
355 return ffi_guard_thunk(__func__, [=]() -> int {
356 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
357 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(group, safe_get(x));
358 *key = new botan_privkey_struct(std::move(dsa));
359 return BOTAN_FFI_SUCCESS;
360 });
361#else
362 BOTAN_UNUSED(key, p, q, g, x);
364#endif
365}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 628 of file ffi_pkey_algs.cpp.

628 {
629#if defined(BOTAN_HAS_ECDH)
630 if(key == nullptr || curve_name == nullptr) {
632 }
633 *key = nullptr;
634 return ffi_guard_thunk(__func__, [=]() -> int {
635 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
636 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
637 if(rc == BOTAN_FFI_SUCCESS) {
638 *key = new botan_privkey_struct(std::move(p_key));
639 }
640 return rc;
641 });
642#else
643 BOTAN_UNUSED(key, scalar, curve_name);
645#endif
646}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 456 of file ffi_pkey_algs.cpp.

456 {
457#if defined(BOTAN_HAS_ECDSA)
458 if(key == nullptr || curve_name == nullptr) {
460 }
461 *key = nullptr;
462
463 return ffi_guard_thunk(__func__, [=]() -> int {
464 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
465 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
466 if(rc == BOTAN_FFI_SUCCESS) {
467 *key = new botan_privkey_struct(std::move(p_key));
468 }
469 return rc;
470 });
471#else
472 BOTAN_UNUSED(key, scalar, curve_name);
474#endif
475}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 742 of file ffi_pkey_algs.cpp.

742 {
743#if defined(BOTAN_HAS_ED25519)
744 if(key == nullptr) {
746 }
747 *key = nullptr;
748 return ffi_guard_thunk(__func__, [=]() -> int {
749 auto ed25519 =
750 std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(std::span{privkey, 32}));
751 *key = new botan_privkey_struct(std::move(ed25519));
752 return BOTAN_FFI_SUCCESS;
753 });
754#else
755 BOTAN_UNUSED(key, privkey);
757#endif
758}
static Ed25519_PrivateKey from_seed(std::span< const uint8_t > seed)

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

◆ botan_privkey_load_ed448()

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

Definition at line 820 of file ffi_pkey_algs.cpp.

820 {
821#if defined(BOTAN_HAS_ED448)
822 if(key == nullptr) {
824 }
825 *key = nullptr;
826 return ffi_guard_thunk(__func__, [=]() -> int {
827 auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
828 *key = new botan_privkey_struct(std::move(ed448));
829 return BOTAN_FFI_SUCCESS;
830 });
831#else
832 BOTAN_UNUSED(key, privkey);
834#endif
835}

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_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 523 of file ffi_pkey_algs.cpp.

523 {
524#if defined(BOTAN_HAS_ELGAMAL)
525 if(key == nullptr) {
527 }
528 *key = nullptr;
529 return ffi_guard_thunk(__func__, [=]() -> int {
530 Botan::DL_Group group(safe_get(p), safe_get(g));
531 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(group, safe_get(x));
532 *key = new botan_privkey_struct(std::move(elg));
533 return BOTAN_FFI_SUCCESS;
534 });
535#else
536 BOTAN_UNUSED(key, p, g, x);
538#endif
539}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 1289 of file ffi_pkey_algs.cpp.

1289 {
1290#if defined(BOTAN_HAS_FRODOKEM)
1291 if(key == nullptr || privkey == nullptr || frodo_mode == nullptr) {
1293 }
1294
1295 *key = nullptr;
1296
1297 return ffi_guard_thunk(__func__, [=]() -> int {
1298 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1299 auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
1300 *key = new botan_privkey_struct(std::move(frodo_key));
1301 return BOTAN_FFI_SUCCESS;
1302 });
1303#else
1304 BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1306#endif
1307}

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 1033 of file ffi_pkey_algs.cpp.

1033 {
1034#if defined(BOTAN_HAS_KYBER)
1035 if(key == nullptr) {
1037 }
1038 *key = nullptr;
1039
1040 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1041 if(len == 1632) {
1043 } else if(len == 2400) {
1045 } else if(len == 3168) {
1047 } else {
1048 return {};
1049 }
1050 }(key_len);
1051
1052 if(mode.has_value()) {
1053 return ffi_guard_thunk(__func__, [=]() -> int {
1054 auto kyber = std::make_unique<Botan::Kyber_PrivateKey>(std::span{privkey, key_len}, *mode);
1055 *key = new botan_privkey_struct(std::move(kyber));
1056 return BOTAN_FFI_SUCCESS;
1057 });
1058 } else {
1060 }
1061#else
1062 BOTAN_UNUSED(key, key_len, privkey);
1064#endif
1065}

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::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 1185 of file ffi_pkey_algs.cpp.

1185 {
1186#if defined(BOTAN_HAS_ML_DSA)
1187 if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
1189 }
1190
1191 *key = nullptr;
1192
1193 return ffi_guard_thunk(__func__, [=]() -> int {
1194 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1195 if(!mode.is_ml_dsa()) {
1197 }
1198
1199 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1200 *key = new botan_privkey_struct(std::move(mldsa_key));
1201 return BOTAN_FFI_SUCCESS;
1202 });
1203#else
1204 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1206#endif
1207}
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 1133 of file ffi_pkey_algs.cpp.

1133 {
1134#if defined(BOTAN_HAS_ML_KEM)
1135 if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
1137 }
1138
1139 *key = nullptr;
1140
1141 return ffi_guard_thunk(__func__, [=]() -> int {
1142 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1143 if(!mode.is_ml_kem()) {
1145 }
1146
1147 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1148 *key = new botan_privkey_struct(std::move(mlkem_key));
1149 return BOTAN_FFI_SUCCESS;
1150 });
1151#else
1152 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1154#endif
1155}
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 220 of file ffi_pkey_algs.cpp.

220 {
221#if defined(BOTAN_HAS_RSA)
222 if(key == nullptr) {
224 }
225 *key = nullptr;
226
227 return ffi_guard_thunk(__func__, [=]() -> int {
228 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p), safe_get(rsa_q), safe_get(rsa_e));
229 *key = new botan_privkey_struct(std::move(rsa));
230 return BOTAN_FFI_SUCCESS;
231 });
232#else
233 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
235#endif
236}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 238 of file ffi_pkey_algs.cpp.

238 {
239#if defined(BOTAN_HAS_RSA)
240 if(key == nullptr || bits == nullptr) {
242 }
243 *key = nullptr;
244
245 return ffi_guard_thunk(__func__, [=]() -> int {
247 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, std::span{bits, len});
248 *key = new botan_privkey_struct(std::move(rsa));
249 return BOTAN_FFI_SUCCESS;
250 });
251#else
252 BOTAN_UNUSED(key, bits, len);
254#endif
255}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 1237 of file ffi_pkey_algs.cpp.

1237 {
1238#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1239 if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
1241 }
1242
1243 *key = nullptr;
1244
1245 return ffi_guard_thunk(__func__, [=]() -> int {
1246 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1247 if(!mode.is_slh_dsa()) {
1249 }
1250
1251 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1252 *key = new botan_privkey_struct(std::move(slhdsa_key));
1253 return BOTAN_FFI_SUCCESS;
1254 });
1255#else
1256 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1258#endif
1259}

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 707 of file ffi_pkey_algs.cpp.

707 {
708#if defined(BOTAN_HAS_SM2)
709 if(key == nullptr || curve_name == nullptr) {
711 }
712 *key = nullptr;
713
714 return ffi_guard_thunk(__func__, [=]() -> int {
715 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
716 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
717
718 if(rc == BOTAN_FFI_SUCCESS) {
719 *key = new botan_privkey_struct(std::move(p_key));
720 }
721 return rc;
722 });
723#else
724 BOTAN_UNUSED(key, scalar, curve_name);
726#endif
727}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 736 of file ffi_pkey_algs.cpp.

736 {
737 return botan_privkey_load_sm2(key, scalar, curve_name);
738}
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 890 of file ffi_pkey_algs.cpp.

890 {
891#if defined(BOTAN_HAS_X25519)
892 if(key == nullptr) {
894 }
895 *key = nullptr;
896 return ffi_guard_thunk(__func__, [=]() -> int {
897 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(std::span{privkey, 32});
898 *key = new botan_privkey_struct(std::move(x25519));
899 return BOTAN_FFI_SUCCESS;
900 });
901#else
902 BOTAN_UNUSED(key, privkey);
904#endif
905}

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_x448()

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

Definition at line 962 of file ffi_pkey_algs.cpp.

962 {
963#if defined(BOTAN_HAS_X448)
964 if(key == nullptr) {
966 }
967 *key = nullptr;
968 return ffi_guard_thunk(__func__, [=]() -> int {
969 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span{privkey, 56});
970 *key = new botan_privkey_struct(std::move(x448));
971 return BOTAN_FFI_SUCCESS;
972 });
973#else
974 BOTAN_UNUSED(key, privkey);
976#endif
977}
Point448 x448(const ScalarX448 &k, const Point448 &u)
Multiply a scalar k with a point u.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 290 of file ffi_pkey_algs.cpp.

290 {
291 return botan_privkey_get_field(d, key, "d");
292}

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 286 of file ffi_pkey_algs.cpp.

286 {
287 return botan_privkey_get_field(e, key, "e");
288}

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 282 of file ffi_pkey_algs.cpp.

282 {
283 return botan_privkey_get_field(n, key, "n");
284}

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 274 of file ffi_pkey_algs.cpp.

274 {
275 return botan_privkey_get_field(p, key, "p");
276}

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 302 of file ffi_pkey_algs.cpp.

302 {
303#if defined(BOTAN_HAS_RSA)
304 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
305 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
306 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
307 return write_vec_output(out, out_len, rsa->private_key_bits());
308 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
309 return write_str_output(out, out_len, Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
310 } else {
312 }
313 } else {
315 }
316 });
317#else
318 BOTAN_UNUSED(rsa_key, out, out_len, flags);
320#endif
321}
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1394
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1393
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:129
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:230
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:226

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 278 of file ffi_pkey_algs.cpp.

278 {
279 return botan_privkey_get_field(q, key, "q");
280}

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 1099 of file ffi_pkey_algs.cpp.

1099 {
1100#if defined(BOTAN_HAS_KYBER)
1101 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1102 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1103 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1104 } else {
1106 }
1107 });
1108#else
1109 BOTAN_UNUSED(key, ctx, view);
1111#endif
1112}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:166

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 924 of file ffi_pkey_algs.cpp.

924 {
925#if defined(BOTAN_HAS_X25519)
926 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
927 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
928 const auto x25519_key = x25519->raw_private_key_bits();
929 if(x25519_key.size() != 32) {
931 }
932 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
933 return BOTAN_FFI_SUCCESS;
934 } else {
936 }
937 });
938#else
939 BOTAN_UNUSED(key, output);
941#endif
942}

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 996 of file ffi_pkey_algs.cpp.

996 {
997#if defined(BOTAN_HAS_X448)
998 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
999 if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
1000 const auto x448_key = x448->raw_private_key_bits();
1001 Botan::copy_mem(std::span{output, 56}, x448_key);
1002 return BOTAN_FFI_SUCCESS;
1003 } else {
1005 }
1006 });
1007#else
1008 BOTAN_UNUSED(key, output);
1010#endif
1011}
A private key for the X448 key agreement scheme according to RFC 7748.
Definition x448.h:69

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 398 of file ffi_pkey_algs.cpp.

398 {
399 return botan_pubkey_get_field(g, key, "g");
400}
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 390 of file ffi_pkey_algs.cpp.

390 {
391 return botan_pubkey_get_field(p, key, "p");
392}

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 394 of file ffi_pkey_algs.cpp.

394 {
395 return botan_pubkey_get_field(q, key, "q");
396}

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 402 of file ffi_pkey_algs.cpp.

402 {
403 return botan_pubkey_get_field(y, key, "y");
404}

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 412 of file ffi_pkey_algs.cpp.

412 {
413#if defined(BOTAN_HAS_ECC_KEY)
414 return ffi_guard_thunk(__func__, [=]() -> int {
415 const Botan::Public_Key& pub_key = safe_get(key);
416 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
417
418 if(ec_key == nullptr) {
420 }
421
422 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
423 });
424#else
425 BOTAN_UNUSED(key);
427#endif
428}
bool used_explicit_encoding() const
Definition ec_group.h:263
const EC_Group & domain() const
Definition ecc_key.cpp:64

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 798 of file ffi_pkey_algs.cpp.

798 {
799#if defined(BOTAN_HAS_ED25519)
800 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
801 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
802 const std::vector<uint8_t>& ed_key = ed->get_public_key();
803 if(ed_key.size() != 32) {
805 }
806 Botan::copy_mem(output, ed_key.data(), ed_key.size());
807 return BOTAN_FFI_SUCCESS;
808 } else {
810 }
811 });
812#else
813 BOTAN_UNUSED(key, output);
815#endif
816}

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 871 of file ffi_pkey_algs.cpp.

871 {
872#if defined(BOTAN_HAS_ED448)
873 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
874 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
875 const auto ed_key = ed->public_key_bits();
876 Botan::copy_mem(std::span(output, 57), ed_key);
877 return BOTAN_FFI_SUCCESS;
878 } else {
880 }
881 });
882#else
883 BOTAN_UNUSED(key, output);
885#endif
886}
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 188 of file ffi_pkey_algs.cpp.

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

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_classic_mceliece()

int botan_pubkey_load_classic_mceliece ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * cmce_mode )

Definition at line 1356 of file ffi_pkey_algs.cpp.

1359 {
1360#if defined(BOTAN_HAS_CLASSICMCELIECE)
1361 if(key == nullptr || pubkey == nullptr || cmce_mode == nullptr) {
1363 }
1364
1365 *key = nullptr;
1366
1367 return ffi_guard_thunk(__func__, [=]() -> int {
1368 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1369 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
1370 *key = new botan_pubkey_struct(std::move(cmce_key));
1371 return BOTAN_FFI_SUCCESS;
1372 });
1373#else
1374 BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1376#endif
1377}

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

◆ 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 565 of file ffi_pkey_algs.cpp.

565 {
566#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
567 if(key == nullptr) {
569 }
570 *key = nullptr;
571 return ffi_guard_thunk(__func__, [=]() -> int {
572 Botan::DL_Group group(safe_get(p), safe_get(g));
573 auto dh = std::make_unique<Botan::DH_PublicKey>(group, safe_get(y));
574 *key = new botan_pubkey_struct(std::move(dh));
575 return BOTAN_FFI_SUCCESS;
576 });
577#else
578 BOTAN_UNUSED(key, p, g, y);
580#endif
581}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 367 of file ffi_pkey_algs.cpp.

367 {
368#if defined(BOTAN_HAS_DSA)
369 if(key == nullptr) {
371 }
372 *key = nullptr;
373
374 return ffi_guard_thunk(__func__, [=]() -> int {
375 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
376 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
377 *key = new botan_pubkey_struct(std::move(dsa));
378 return BOTAN_FFI_SUCCESS;
379 });
380#else
381 BOTAN_UNUSED(key, p, q, g, y);
383#endif
384}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 604 of file ffi_pkey_algs.cpp.

607 {
608#if defined(BOTAN_HAS_ECDH)
609 if(key == nullptr || curve_name == nullptr) {
611 }
612 *key = nullptr;
613 return ffi_guard_thunk(__func__, [=]() -> int {
614 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
615 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
616
617 if(rc == BOTAN_FFI_SUCCESS) {
618 *key = new botan_pubkey_struct(std::move(p_key));
619 }
620 return rc;
621 });
622#else
623 BOTAN_UNUSED(key, public_x, public_y, curve_name);
625#endif
626}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 430 of file ffi_pkey_algs.cpp.

433 {
434#if defined(BOTAN_HAS_ECDSA)
435 if(key == nullptr || curve_name == nullptr) {
437 }
438 *key = nullptr;
439
440 return ffi_guard_thunk(__func__, [=]() -> int {
441 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
442
443 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
444 if(rc == BOTAN_FFI_SUCCESS) {
445 *key = new botan_pubkey_struct(std::move(p_key));
446 }
447
448 return rc;
449 });
450#else
451 BOTAN_UNUSED(key, public_x, public_y, curve_name);
453#endif
454}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 760 of file ffi_pkey_algs.cpp.

760 {
761#if defined(BOTAN_HAS_ED25519)
762 if(key == nullptr) {
764 }
765 *key = nullptr;
766 return ffi_guard_thunk(__func__, [=]() -> int {
767 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
768 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
769 *key = new botan_pubkey_struct(std::move(ed25519));
770 return BOTAN_FFI_SUCCESS;
771 });
772#else
773 BOTAN_UNUSED(key, pubkey);
775#endif
776}

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_ed448()

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

Definition at line 837 of file ffi_pkey_algs.cpp.

837 {
838#if defined(BOTAN_HAS_ED448)
839 if(key == nullptr) {
841 }
842 *key = nullptr;
843 return ffi_guard_thunk(__func__, [=]() -> int {
844 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
845 *key = new botan_pubkey_struct(std::move(ed448));
846 return BOTAN_FFI_SUCCESS;
847 });
848#else
849 BOTAN_UNUSED(key, pubkey);
851#endif
852}

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_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 505 of file ffi_pkey_algs.cpp.

505 {
506#if defined(BOTAN_HAS_ELGAMAL)
507 if(key == nullptr) {
509 }
510 *key = nullptr;
511 return ffi_guard_thunk(__func__, [=]() -> int {
512 Botan::DL_Group group(safe_get(p), safe_get(g));
513 auto elg = std::make_unique<Botan::ElGamal_PublicKey>(group, safe_get(y));
514 *key = new botan_pubkey_struct(std::move(elg));
515 return BOTAN_FFI_SUCCESS;
516 });
517#else
518 BOTAN_UNUSED(key, p, g, y);
520#endif
521}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 1309 of file ffi_pkey_algs.cpp.

1309 {
1310#if defined(BOTAN_HAS_FRODOKEM)
1311 if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
1313 }
1314
1315 *key = nullptr;
1316
1317 return ffi_guard_thunk(__func__, [=]() -> int {
1318 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1319 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1320 *key = new botan_pubkey_struct(std::move(frodo_key));
1321 return BOTAN_FFI_SUCCESS;
1322 });
1323#else
1324 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1326#endif
1327}

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 1067 of file ffi_pkey_algs.cpp.

1067 {
1068#if defined(BOTAN_HAS_KYBER)
1069 if(key == nullptr) {
1071 }
1072 *key = nullptr;
1073
1074 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1075 if(len == 800) {
1077 } else if(len == 1184) {
1079 } else if(len == 1568) {
1081 } else {
1082 return {};
1083 }
1084 }(key_len);
1085
1086 if(mode.has_value()) {
1087 auto kyber = std::make_unique<Botan::Kyber_PublicKey>(std::span{pubkey, key_len}, *mode);
1088 *key = new botan_pubkey_struct(std::move(kyber));
1089 return BOTAN_FFI_SUCCESS;
1090 } else {
1092 }
1093#else
1094 BOTAN_UNUSED(key, pubkey, key_len);
1096#endif
1097}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, 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 1209 of file ffi_pkey_algs.cpp.

1209 {
1210#if defined(BOTAN_HAS_ML_DSA)
1211 if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
1213 }
1214
1215 *key = nullptr;
1216
1217 return ffi_guard_thunk(__func__, [=]() -> int {
1218 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1219 if(!mode.is_ml_dsa()) {
1221 }
1222
1223 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1224 *key = new botan_pubkey_struct(std::move(mldsa_key));
1225 return BOTAN_FFI_SUCCESS;
1226 });
1227#else
1228 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1230#endif
1231}

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 1157 of file ffi_pkey_algs.cpp.

1157 {
1158#if defined(BOTAN_HAS_ML_KEM)
1159 if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
1161 }
1162
1163 *key = nullptr;
1164
1165 return ffi_guard_thunk(__func__, [=]() -> int {
1166 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1167 if(!mode.is_ml_kem()) {
1169 }
1170
1171 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1172 *key = new botan_pubkey_struct(std::move(mlkem_key));
1173 return BOTAN_FFI_SUCCESS;
1174 });
1175#else
1176 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1178#endif
1179}

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 257 of file ffi_pkey_algs.cpp.

257 {
258#if defined(BOTAN_HAS_RSA)
259 if(key == nullptr) {
261 }
262 *key = nullptr;
263 return ffi_guard_thunk(__func__, [=]() -> int {
264 auto rsa = std::make_unique<Botan::RSA_PublicKey>(safe_get(n), safe_get(e));
265 *key = new botan_pubkey_struct(std::move(rsa));
266 return BOTAN_FFI_SUCCESS;
267 });
268#else
269 BOTAN_UNUSED(key, n, e);
271#endif
272}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 1261 of file ffi_pkey_algs.cpp.

1261 {
1262#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1263 if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
1265 }
1266
1267 *key = nullptr;
1268
1269 return ffi_guard_thunk(__func__, [=]() -> int {
1270 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1271 if(!mode.is_slh_dsa()) {
1273 }
1274
1275 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1276 *key = new botan_pubkey_struct(std::move(mldsa_key));
1277 return BOTAN_FFI_SUCCESS;
1278 });
1279#else
1280 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1282#endif
1283}

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 683 of file ffi_pkey_algs.cpp.

686 {
687#if defined(BOTAN_HAS_SM2)
688 if(key == nullptr || curve_name == nullptr) {
690 }
691 *key = nullptr;
692
693 return ffi_guard_thunk(__func__, [=]() -> int {
694 std::unique_ptr<Botan::SM2_PublicKey> p_key;
695 if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name)) {
696 *key = new botan_pubkey_struct(std::move(p_key));
697 return BOTAN_FFI_SUCCESS;
698 }
700 });
701#else
702 BOTAN_UNUSED(key, public_x, public_y, curve_name);
704#endif
705}
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:144

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 729 of file ffi_pkey_algs.cpp.

732 {
733 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
734}
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 907 of file ffi_pkey_algs.cpp.

907 {
908#if defined(BOTAN_HAS_X25519)
909 if(key == nullptr) {
911 }
912 *key = nullptr;
913 return ffi_guard_thunk(__func__, [=]() -> int {
914 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(std::span{pubkey, 32});
915 *key = new botan_pubkey_struct(std::move(x25519));
916 return BOTAN_FFI_SUCCESS;
917 });
918#else
919 BOTAN_UNUSED(key, pubkey);
921#endif
922}

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_x448()

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

Definition at line 979 of file ffi_pkey_algs.cpp.

979 {
980#if defined(BOTAN_HAS_X448)
981 if(key == nullptr) {
983 }
984 *key = nullptr;
985 return ffi_guard_thunk(__func__, [=]() -> int {
986 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span{pubkey, 56});
987 *key = new botan_pubkey_struct(std::move(x448));
988 return BOTAN_FFI_SUCCESS;
989 });
990#else
991 BOTAN_UNUSED(key, pubkey);
993#endif
994}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 294 of file ffi_pkey_algs.cpp.

294 {
295 return botan_pubkey_get_field(e, key, "e");
296}

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 298 of file ffi_pkey_algs.cpp.

298 {
299 return botan_pubkey_get_field(n, key, "n");
300}

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 650 of file ffi_pkey_algs.cpp.

651 {
652 if(out == nullptr || out_len == nullptr || ident == nullptr || hash_algo == nullptr || key == nullptr) {
654 }
655
656#if defined(BOTAN_HAS_SM2)
657 return ffi_guard_thunk(__func__, [=]() -> int {
658 const Botan::Public_Key& pub_key = safe_get(key);
659 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
660
661 if(ec_key == nullptr) {
663 }
664
665 if(ec_key->algo_name() != "SM2") {
667 }
668
669 const std::string ident_str(ident);
670 std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
671
672 const auto& pt = ec_key->_public_ec_point();
673
674 const auto za = Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), pt);
675
676 return write_vec_output(out, out_len, za);
677 });
678#else
680#endif
681}
virtual std::string algo_name() const =0
const EC_AffinePoint & _public_ec_point() const
Definition ecc_key.cpp:76
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_AffinePoint &pubkey)
Definition sm2.cpp:68

References Botan::EC_PublicKey::_public_ec_point(), 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_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 1379 of file ffi_pkey_algs.cpp.

1379 {
1380#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1381 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1382 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1383 auto pt = ecc->_public_ec_point().serialize_uncompressed();
1384 return invoke_view_callback(view, ctx, pt);
1385 } else {
1387 }
1388 });
1389#else
1390 BOTAN_UNUSED(key, view, ctx);
1392#endif
1393}

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

◆ 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 1114 of file ffi_pkey_algs.cpp.

1114 {
1115#if defined(BOTAN_HAS_KYBER)
1116 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1117 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1118 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1119 } else {
1121 }
1122 });
1123#else
1124 BOTAN_UNUSED(key, ctx, view);
1126#endif
1127}

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 944 of file ffi_pkey_algs.cpp.

944 {
945#if defined(BOTAN_HAS_X25519)
946 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
947 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
948 Botan::copy_mem(std::span{output, 32}, x25519->raw_public_key_bits());
949 return BOTAN_FFI_SUCCESS;
950 } else {
952 }
953 });
954#else
955 BOTAN_UNUSED(key, output);
957#endif
958}

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_x448_get_pubkey()

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

Definition at line 1013 of file ffi_pkey_algs.cpp.

1013 {
1014#if defined(BOTAN_HAS_X448)
1015 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1016 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
1017 Botan::copy_mem(std::span{output, 56}, x448->raw_public_key_bits());
1018 return BOTAN_FFI_SUCCESS;
1019 } else {
1021 }
1022 });
1023#else
1024 BOTAN_UNUSED(key, output);
1026#endif
1027}
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().