Botan 3.10.0
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_ecdh_sec1 (botan_pubkey_t *key, const uint8_t sec1[], size_t sec1_len, 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_ecdsa_sec1 (botan_pubkey_t *key, const uint8_t sec1[], size_t sec1_len, 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_sm2_sec1 (botan_pubkey_t *key, const uint8_t sec1[], size_t sec1_len, 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 1463 of file ffi_pkey_algs.cpp.

1470 {
1471 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
1473}
#define BOTAN_UNUSED
Definition assert.h:144
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:138

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

1483 {
1484 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1486}

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

580 {
581 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
582}
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_obj,
size_t pbits,
size_t qbits )

Definition at line 342 of file ffi_pkey_algs.cpp.

342 {
343#if defined(BOTAN_HAS_DSA)
344
345 if((rng_obj == nullptr) || (key == nullptr)) {
347 }
348
349 if((pbits % 64 != 0) || (qbits % 8 != 0) || (pbits < 1024) || (pbits > 3072) || (qbits < 160) || (qbits > 256)) {
351 }
352
353 return ffi_guard_thunk(__func__, [=]() -> int {
355 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
356 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
357 return ffi_new_object(key, std::move(dsa));
358 });
359#else
360 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
362#endif
363}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:132
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:133
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:79
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:178
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 620 of file ffi_pkey_algs.cpp.

620 {
621 if(key_obj == nullptr || param_str == nullptr) {
623 }
624 *key_obj = nullptr;
625
626 const std::string params(param_str);
627
628 if(params == "X25519" || params == "x25519" || params == "curve25519") {
629 return botan_privkey_create(key_obj, "X25519", "", rng_obj);
630 }
631
632 if(params == "X448" || params == "x448") {
633 return botan_privkey_create(key_obj, "X448", "", rng_obj);
634 }
635
636 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
637}

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

421 {
422 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
423}

References botan_privkey_create().

◆ botan_privkey_create_elgamal()

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

Definition at line 518 of file ffi_pkey_algs.cpp.

518 {
519#if defined(BOTAN_HAS_ELGAMAL)
520 if(key == nullptr || rng_obj == nullptr) {
522 }
523 *key = nullptr;
524
525 if(pbits < 1024 || qbits < 160) {
527 }
528
529 Botan::DL_Group::PrimeType prime_type =
530 ((pbits - 1) == qbits) ? Botan::DL_Group::Strong : Botan::DL_Group::Prime_Subgroup;
531
532 return ffi_guard_thunk(__func__, [=]() -> int {
534 Botan::DL_Group group(rng, prime_type, pbits, qbits);
535 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
536 return ffi_new_object(key, std::move(elg));
537 });
538#else
539 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
541#endif
542}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1458 of file ffi_pkey_algs.cpp.

1458 {
1459 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1460 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1461}

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

228 {
229 if(n_bits < 1024 || n_bits > 16 * 1024) {
231 }
232
233 std::string n_str = std::to_string(n_bits);
234
235 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
236}

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

401 {
402 return botan_privkey_get_field(x, key, "x");
403}
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 857 of file ffi_pkey_algs.cpp.

857 {
858#if defined(BOTAN_HAS_ED25519)
859 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
860 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
861 const auto ed_key = ed->raw_private_key_bits();
862 if(ed_key.size() != 64) {
864 }
865 Botan::copy_mem(output, ed_key.data(), ed_key.size());
866 return BOTAN_FFI_SUCCESS;
867 } else {
869 }
870 });
871#else
872 BOTAN_UNUSED(key, output);
874#endif
875}
@ BOTAN_FFI_SUCCESS
Definition ffi.h:115
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition ffi.h:123
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:145

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

931 {
932#if defined(BOTAN_HAS_ED448)
933 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
934 if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
935 const auto ed_key = ed->raw_private_key_bits();
936 Botan::copy_mem(std::span(output, 57), ed_key);
937 return BOTAN_FFI_SUCCESS;
938 } else {
940 }
941 });
942#else
943 BOTAN_UNUSED(key, output);
945#endif
946}
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 216 of file ffi_pkey_algs.cpp.

216 {
217 if(field_name_cstr == nullptr) {
219 }
220
221 const std::string field_name(field_name_cstr);
222
223 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); });
224}

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

1399 {
1400#if defined(BOTAN_HAS_CLASSICMCELIECE)
1401 if(key == nullptr || privkey == nullptr || cmce_mode == nullptr) {
1403 }
1404
1405 *key = nullptr;
1406
1407 return ffi_guard_thunk(__func__, [=]() -> int {
1408 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1409 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
1410 return ffi_new_object(key, std::move(cmce_key));
1411 });
1412#else
1413 BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1415#endif
1416}
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_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 584 of file ffi_pkey_algs.cpp.

584 {
585#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
586 if(key == nullptr) {
588 }
589 *key = nullptr;
590 return ffi_guard_thunk(__func__, [=]() -> int {
591 Botan::DL_Group group(safe_get(p), safe_get(g));
592 auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
593 return ffi_new_object(key, std::move(dh));
594 });
595#else
596 BOTAN_UNUSED(key, p, g, x);
598#endif
599}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 365 of file ffi_pkey_algs.cpp.

365 {
366#if defined(BOTAN_HAS_DSA)
367 if(key == nullptr) {
369 }
370 *key = nullptr;
371
372 return ffi_guard_thunk(__func__, [=]() -> int {
373 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
374 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(group, safe_get(x));
375 return ffi_new_object(key, std::move(dsa));
376 });
377#else
378 BOTAN_UNUSED(key, p, q, g, x);
380#endif
381}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 686 of file ffi_pkey_algs.cpp.

686 {
687#if defined(BOTAN_HAS_ECDH)
688 if(key == nullptr || curve_name == nullptr) {
690 }
691 *key = nullptr;
692 return ffi_guard_thunk(__func__, [=]() -> int {
693 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
694 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
695 if(rc == BOTAN_FFI_SUCCESS) {
696 ffi_new_object(key, std::move(p_key));
697 }
698 return rc;
699 });
700#else
701 BOTAN_UNUSED(key, scalar, curve_name);
703#endif
704}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 496 of file ffi_pkey_algs.cpp.

496 {
497#if defined(BOTAN_HAS_ECDSA)
498 if(key == nullptr || curve_name == nullptr) {
500 }
501 *key = nullptr;
502
503 return ffi_guard_thunk(__func__, [=]() -> int {
504 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
505 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
506 if(rc == BOTAN_FFI_SUCCESS) {
507 ffi_new_object(key, std::move(p_key));
508 }
509 return rc;
510 });
511#else
512 BOTAN_UNUSED(key, scalar, curve_name);
514#endif
515}

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

◆ botan_privkey_load_ed25519()

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

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 */ int botan_pubkey_load_dh(botan_pubkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t y);

/* Algorithm specific key operations: ElGamal 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 */ int botan_pubkey_load_elgamal(botan_pubkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t y);

/** 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 */ int botan_privkey_load_elgamal(botan_privkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t x);

/* Algorithm specific key operations: Ed25519

Definition at line 823 of file ffi_pkey_algs.cpp.

823 {
824#if defined(BOTAN_HAS_ED25519)
825 if(key == nullptr) {
827 }
828 *key = nullptr;
829 return ffi_guard_thunk(__func__, [=]() -> int {
830 auto ed25519 =
831 std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(std::span{privkey, 32}));
832 return ffi_new_object(key, std::move(ed25519));
833 });
834#else
835 BOTAN_UNUSED(key, privkey);
837#endif
838}
static Ed25519_PrivateKey from_seed(std::span< const uint8_t > seed)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 899 of file ffi_pkey_algs.cpp.

899 {
900#if defined(BOTAN_HAS_ED448)
901 if(key == nullptr) {
903 }
904 *key = nullptr;
905 return ffi_guard_thunk(__func__, [=]() -> int {
906 auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
907 return ffi_new_object(key, std::move(ed448));
908 });
909#else
910 BOTAN_UNUSED(key, privkey);
912#endif
913}

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

◆ 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 )

Definition at line 561 of file ffi_pkey_algs.cpp.

561 {
562#if defined(BOTAN_HAS_ELGAMAL)
563 if(key == nullptr) {
565 }
566 *key = nullptr;
567 return ffi_guard_thunk(__func__, [=]() -> int {
568 Botan::DL_Group group(safe_get(p), safe_get(g));
569 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(group, safe_get(x));
570 return ffi_new_object(key, std::move(elg));
571 });
572#else
573 BOTAN_UNUSED(key, p, g, x);
575#endif
576}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1354 of file ffi_pkey_algs.cpp.

1354 {
1355#if defined(BOTAN_HAS_FRODOKEM)
1356 if(key == nullptr || privkey == nullptr || frodo_mode == nullptr) {
1358 }
1359
1360 *key = nullptr;
1361
1362 return ffi_guard_thunk(__func__, [=]() -> int {
1363 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1364 auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
1365 return ffi_new_object(key, std::move(frodo_key));
1366 });
1367#else
1368 BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1370#endif
1371}

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

◆ botan_privkey_load_kyber()

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

Definition at line 1106 of file ffi_pkey_algs.cpp.

1106 {
1107#if defined(BOTAN_HAS_KYBER)
1108 if(key == nullptr) {
1110 }
1111 *key = nullptr;
1112
1113 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1114 if(len == 1632) {
1116 } else if(len == 2400) {
1118 } else if(len == 3168) {
1120 } else {
1121 return {};
1122 }
1123 }(key_len);
1124
1125 if(mode.has_value()) {
1126 return ffi_guard_thunk(__func__, [=]() -> int {
1127 auto kyber = std::make_unique<Botan::Kyber_PrivateKey>(std::span{privkey, key_len}, *mode);
1128 return ffi_new_object(key, std::move(kyber));
1129 });
1130 } else {
1132 }
1133#else
1134 BOTAN_UNUSED(key, key_len, privkey);
1136#endif
1137}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1254 of file ffi_pkey_algs.cpp.

1254 {
1255#if defined(BOTAN_HAS_ML_DSA)
1256 if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
1258 }
1259
1260 *key = nullptr;
1261
1262 return ffi_guard_thunk(__func__, [=]() -> int {
1263 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1264 if(!mode.is_ml_dsa()) {
1266 }
1267
1268 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1269 return ffi_new_object(key, std::move(mldsa_key));
1270 });
1271#else
1272 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1274#endif
1275}
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_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

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

1204 {
1205#if defined(BOTAN_HAS_ML_KEM)
1206 if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
1208 }
1209
1210 *key = nullptr;
1211
1212 return ffi_guard_thunk(__func__, [=]() -> int {
1213 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1214 if(!mode.is_ml_kem()) {
1216 }
1217
1218 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1219 return ffi_new_object(key, std::move(mlkem_key));
1220 });
1221#else
1222 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1224#endif
1225}
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_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

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

238 {
239#if defined(BOTAN_HAS_RSA)
240 if(key == nullptr) {
242 }
243 *key = nullptr;
244
245 return ffi_guard_thunk(__func__, [=]() -> int {
246 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p), safe_get(rsa_q), safe_get(rsa_e));
247 return ffi_new_object(key, std::move(rsa));
248 });
249#else
250 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
252#endif
253}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 255 of file ffi_pkey_algs.cpp.

255 {
256#if defined(BOTAN_HAS_RSA)
257 if(key == nullptr || bits == nullptr) {
259 }
260 *key = nullptr;
261
262 return ffi_guard_thunk(__func__, [=]() -> int {
264 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, std::span{bits, len});
265 return ffi_new_object(key, std::move(rsa));
266 });
267#else
268 BOTAN_UNUSED(key, bits, len);
270#endif
271}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1304 of file ffi_pkey_algs.cpp.

1304 {
1305#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1306 if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
1308 }
1309
1310 *key = nullptr;
1311
1312 return ffi_guard_thunk(__func__, [=]() -> int {
1313 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1314 if(!mode.is_slh_dsa()) {
1316 }
1317
1318 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1319 return ffi_new_object(key, std::move(slhdsa_key));
1320 });
1321#else
1322 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1324#endif
1325}

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

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

788 {
789#if defined(BOTAN_HAS_SM2)
790 if(key == nullptr || curve_name == nullptr) {
792 }
793 *key = nullptr;
794
795 return ffi_guard_thunk(__func__, [=]() -> int {
796 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
797 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
798
799 if(rc == BOTAN_FFI_SUCCESS) {
800 ffi_new_object(key, std::move(p_key));
801 }
802 return rc;
803 });
804#else
805 BOTAN_UNUSED(key, scalar, curve_name);
807#endif
808}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 817 of file ffi_pkey_algs.cpp.

817 {
818 return botan_privkey_load_sm2(key, scalar, curve_name);
819}
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 967 of file ffi_pkey_algs.cpp.

967 {
968#if defined(BOTAN_HAS_X25519)
969 if(key == nullptr) {
971 }
972 *key = nullptr;
973 return ffi_guard_thunk(__func__, [=]() -> int {
974 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(std::span{privkey, 32});
975 return ffi_new_object(key, std::move(x25519));
976 });
977#else
978 BOTAN_UNUSED(key, privkey);
980#endif
981}

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

◆ botan_privkey_load_x448()

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

Definition at line 1037 of file ffi_pkey_algs.cpp.

1037 {
1038#if defined(BOTAN_HAS_X448)
1039 if(key == nullptr) {
1041 }
1042 *key = nullptr;
1043 return ffi_guard_thunk(__func__, [=]() -> int {
1044 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span{privkey, 56});
1045 return ffi_new_object(key, std::move(x448));
1046 });
1047#else
1048 BOTAN_UNUSED(key, privkey);
1050#endif
1051}
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_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

◆ botan_privkey_rsa_get_d()

int botan_privkey_rsa_get_d ( botan_mp_t d,
botan_privkey_t key )

Definition at line 305 of file ffi_pkey_algs.cpp.

305 {
306 return botan_privkey_get_field(d, key, "d");
307}

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

301 {
302 return botan_privkey_get_field(e, key, "e");
303}

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

297 {
298 return botan_privkey_get_field(n, key, "n");
299}

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

289 {
290 return botan_privkey_get_field(p, key, "p");
291}

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

317 {
318#if defined(BOTAN_HAS_RSA)
319 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
320 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
321 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
322 return write_vec_output(out, out_len, rsa->private_key_bits());
323 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
324 // TODO define new generic functions for this
325 return write_str_output(reinterpret_cast<char*>(out),
326 out_len,
327 Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
328 } else {
330 }
331 } else {
333 }
334 });
335#else
336 BOTAN_UNUSED(rsa_key, out, out_len, flags);
338#endif
339}
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1419
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1418
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:131
std::string encode(const uint8_t der[], size_t length, std::string_view label, size_t width)
Definition pem.cpp:39
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:261
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:265

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

293 {
294 return botan_privkey_get_field(q, key, "q");
295}

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

1170 {
1171#if defined(BOTAN_HAS_KYBER)
1172 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1173 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1174 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1175 } else {
1177 }
1178 });
1179#else
1180 BOTAN_UNUSED(key, ctx, view);
1182#endif
1183}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:187

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

999 {
1000#if defined(BOTAN_HAS_X25519)
1001 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1002 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
1003 const auto x25519_key = x25519->raw_private_key_bits();
1004 if(x25519_key.size() != 32) {
1006 }
1007 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
1008 return BOTAN_FFI_SUCCESS;
1009 } else {
1011 }
1012 });
1013#else
1014 BOTAN_UNUSED(key, output);
1016#endif
1017}

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

1069 {
1070#if defined(BOTAN_HAS_X448)
1071 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1072 if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
1073 const auto x448_key = x448->raw_private_key_bits();
1074 Botan::copy_mem(std::span{output, 56}, x448_key);
1075 return BOTAN_FFI_SUCCESS;
1076 } else {
1078 }
1079 });
1080#else
1081 BOTAN_UNUSED(key, output);
1083#endif
1084}
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 413 of file ffi_pkey_algs.cpp.

413 {
414 return botan_pubkey_get_field(g, key, "g");
415}
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 405 of file ffi_pkey_algs.cpp.

405 {
406 return botan_pubkey_get_field(p, key, "p");
407}

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

409 {
410 return botan_pubkey_get_field(q, key, "q");
411}

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

417 {
418 return botan_pubkey_get_field(y, key, "y");
419}

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

427 {
428#if defined(BOTAN_HAS_ECC_KEY)
429 return ffi_guard_thunk(__func__, [=]() -> int {
430 const Botan::Public_Key& pub_key = safe_get(key);
431 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
432
433 if(ec_key == nullptr) {
435 }
436
437 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
438 });
439#else
440 BOTAN_UNUSED(key);
442#endif
443}
bool used_explicit_encoding() const
Definition ec_group.h:270
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 877 of file ffi_pkey_algs.cpp.

877 {
878#if defined(BOTAN_HAS_ED25519)
879 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
880 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
881 const std::vector<uint8_t>& ed_key = ed->get_public_key();
882 if(ed_key.size() != 32) {
884 }
885 Botan::copy_mem(output, ed_key.data(), ed_key.size());
886 return BOTAN_FFI_SUCCESS;
887 } else {
889 }
890 });
891#else
892 BOTAN_UNUSED(key, output);
894#endif
895}

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

948 {
949#if defined(BOTAN_HAS_ED448)
950 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
951 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
952 const auto ed_key = ed->public_key_bits();
953 Botan::copy_mem(std::span(output, 57), ed_key);
954 return BOTAN_FFI_SUCCESS;
955 } else {
957 }
958 });
959#else
960 BOTAN_UNUSED(key, output);
962#endif
963}
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 206 of file ffi_pkey_algs.cpp.

206 {
207 if(field_name_cstr == nullptr) {
209 }
210
211 const std::string field_name(field_name_cstr);
212
213 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); });
214}

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

1421 {
1422#if defined(BOTAN_HAS_CLASSICMCELIECE)
1423 if(key == nullptr || pubkey == nullptr || cmce_mode == nullptr) {
1425 }
1426
1427 *key = nullptr;
1428
1429 return ffi_guard_thunk(__func__, [=]() -> int {
1430 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1431 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
1432 return ffi_new_object(key, std::move(cmce_key));
1433 });
1434#else
1435 BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1437#endif
1438}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 )

Definition at line 601 of file ffi_pkey_algs.cpp.

601 {
602#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
603 if(key == nullptr) {
605 }
606 *key = nullptr;
607 return ffi_guard_thunk(__func__, [=]() -> int {
608 Botan::DL_Group group(safe_get(p), safe_get(g));
609 auto dh = std::make_unique<Botan::DH_PublicKey>(group, safe_get(y));
610 return ffi_new_object(key, std::move(dh));
611 });
612#else
613 BOTAN_UNUSED(key, p, g, y);
615#endif
616}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 383 of file ffi_pkey_algs.cpp.

383 {
384#if defined(BOTAN_HAS_DSA)
385 if(key == nullptr) {
387 }
388 *key = nullptr;
389
390 return ffi_guard_thunk(__func__, [=]() -> int {
391 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
392 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
393 return ffi_new_object(key, std::move(dsa));
394 });
395#else
396 BOTAN_UNUSED(key, p, q, g, y);
398#endif
399}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 639 of file ffi_pkey_algs.cpp.

642 {
643#if defined(BOTAN_HAS_ECDH)
644 if(key == nullptr || curve_name == nullptr) {
646 }
647 *key = nullptr;
648 return ffi_guard_thunk(__func__, [=]() -> int {
649 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
650 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
651
652 if(rc == BOTAN_FFI_SUCCESS) {
653 ffi_new_object(key, std::move(p_key));
654 }
655 return rc;
656 });
657#else
658 BOTAN_UNUSED(key, public_x, public_y, curve_name);
660#endif
661}

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

◆ botan_pubkey_load_ecdh_sec1()

int botan_pubkey_load_ecdh_sec1 ( botan_pubkey_t * key,
const uint8_t sec1[],
size_t sec1_len,
const char * curve_name )

Definition at line 663 of file ffi_pkey_algs.cpp.

663 {
664#if defined(BOTAN_HAS_ECDH)
665 if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
667 }
668 *key = nullptr;
669
670 return ffi_guard_thunk(__func__, [=]() -> int {
671 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
672
673 int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
674 if(rc == BOTAN_FFI_SUCCESS) {
675 ffi_new_object(key, std::move(p_key));
676 }
677
678 return rc;
679 });
680#else
681 BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
683#endif
684}

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

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

450 {
451#if defined(BOTAN_HAS_ECDSA)
452 if(key == nullptr || curve_name == nullptr) {
454 }
455 *key = nullptr;
456
457 return ffi_guard_thunk(__func__, [=]() -> int {
458 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
459
460 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
461 if(rc == BOTAN_FFI_SUCCESS) {
462 ffi_new_object(key, std::move(p_key));
463 }
464
465 return rc;
466 });
467#else
468 BOTAN_UNUSED(key, public_x, public_y, curve_name);
470#endif
471}

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

◆ botan_pubkey_load_ecdsa_sec1()

int botan_pubkey_load_ecdsa_sec1 ( botan_pubkey_t * key,
const uint8_t sec1[],
size_t sec1_len,
const char * curve_name )

Definition at line 473 of file ffi_pkey_algs.cpp.

473 {
474#if defined(BOTAN_HAS_ECDSA)
475 if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
477 }
478 *key = nullptr;
479
480 return ffi_guard_thunk(__func__, [=]() -> int {
481 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
482
483 int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
484 if(rc == BOTAN_FFI_SUCCESS) {
485 ffi_new_object(key, std::move(p_key));
486 }
487
488 return rc;
489 });
490#else
491 BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
493#endif
494}

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

◆ botan_pubkey_load_ed25519()

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

Definition at line 840 of file ffi_pkey_algs.cpp.

840 {
841#if defined(BOTAN_HAS_ED25519)
842 if(key == nullptr) {
844 }
845 *key = nullptr;
846 return ffi_guard_thunk(__func__, [=]() -> int {
847 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
848 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
849 return ffi_new_object(key, std::move(ed25519));
850 });
851#else
852 BOTAN_UNUSED(key, pubkey);
854#endif
855}

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

◆ botan_pubkey_load_ed448()

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

Definition at line 915 of file ffi_pkey_algs.cpp.

915 {
916#if defined(BOTAN_HAS_ED448)
917 if(key == nullptr) {
919 }
920 *key = nullptr;
921 return ffi_guard_thunk(__func__, [=]() -> int {
922 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
923 return ffi_new_object(key, std::move(ed448));
924 });
925#else
926 BOTAN_UNUSED(key, pubkey);
928#endif
929}

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

◆ 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 )

Definition at line 544 of file ffi_pkey_algs.cpp.

544 {
545#if defined(BOTAN_HAS_ELGAMAL)
546 if(key == nullptr) {
548 }
549 *key = nullptr;
550 return ffi_guard_thunk(__func__, [=]() -> int {
551 Botan::DL_Group group(safe_get(p), safe_get(g));
552 auto elg = std::make_unique<Botan::ElGamal_PublicKey>(group, safe_get(y));
553 return ffi_new_object(key, std::move(elg));
554 });
555#else
556 BOTAN_UNUSED(key, p, g, y);
558#endif
559}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1373 of file ffi_pkey_algs.cpp.

1373 {
1374#if defined(BOTAN_HAS_FRODOKEM)
1375 if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
1377 }
1378
1379 *key = nullptr;
1380
1381 return ffi_guard_thunk(__func__, [=]() -> int {
1382 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1383 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1384 return ffi_new_object(key, std::move(frodo_key));
1385 });
1386#else
1387 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1389#endif
1390}

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

◆ botan_pubkey_load_kyber()

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

Definition at line 1139 of file ffi_pkey_algs.cpp.

1139 {
1140#if defined(BOTAN_HAS_KYBER)
1141 if(key == nullptr) {
1143 }
1144 *key = nullptr;
1145
1146 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1147 if(len == 800) {
1149 } else if(len == 1184) {
1151 } else if(len == 1568) {
1153 } else {
1154 return {};
1155 }
1156 }(key_len);
1157
1158 if(mode.has_value()) {
1159 auto kyber = std::make_unique<Botan::Kyber_PublicKey>(std::span{pubkey, key_len}, *mode);
1160 return ffi_new_object(key, std::move(kyber));
1161 } else {
1163 }
1164#else
1165 BOTAN_UNUSED(key, pubkey, key_len);
1167#endif
1168}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), 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 1277 of file ffi_pkey_algs.cpp.

1277 {
1278#if defined(BOTAN_HAS_ML_DSA)
1279 if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
1281 }
1282
1283 *key = nullptr;
1284
1285 return ffi_guard_thunk(__func__, [=]() -> int {
1286 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1287 if(!mode.is_ml_dsa()) {
1289 }
1290
1291 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1292 return ffi_new_object(key, std::move(mldsa_key));
1293 });
1294#else
1295 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1297#endif
1298}

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

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

1227 {
1228#if defined(BOTAN_HAS_ML_KEM)
1229 if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
1231 }
1232
1233 *key = nullptr;
1234
1235 return ffi_guard_thunk(__func__, [=]() -> int {
1236 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1237 if(!mode.is_ml_kem()) {
1239 }
1240
1241 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1242 return ffi_new_object(key, std::move(mlkem_key));
1243 });
1244#else
1245 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1247#endif
1248}

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

◆ botan_pubkey_load_rsa()

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

Definition at line 273 of file ffi_pkey_algs.cpp.

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1327 of file ffi_pkey_algs.cpp.

1327 {
1328#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1329 if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
1331 }
1332
1333 *key = nullptr;
1334
1335 return ffi_guard_thunk(__func__, [=]() -> int {
1336 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1337 if(!mode.is_slh_dsa()) {
1339 }
1340
1341 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1342 return ffi_new_object(key, std::move(mldsa_key));
1343 });
1344#else
1345 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1347#endif
1348}

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

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

744 {
745#if defined(BOTAN_HAS_SM2)
746 if(key == nullptr || curve_name == nullptr) {
748 }
749 *key = nullptr;
750
751 return ffi_guard_thunk(__func__, [=]() -> int {
752 std::unique_ptr<Botan::SM2_PublicKey> p_key;
753 if(pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name) == 0) {
754 return ffi_new_object(key, std::move(p_key));
755 } else {
757 }
758 });
759#else
760 BOTAN_UNUSED(key, public_x, public_y, curve_name);
762#endif
763}
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:146

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 810 of file ffi_pkey_algs.cpp.

813 {
814 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
815}
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_sm2_sec1()

int botan_pubkey_load_sm2_sec1 ( botan_pubkey_t * key,
const uint8_t sec1[],
size_t sec1_len,
const char * curve_name )

Definition at line 765 of file ffi_pkey_algs.cpp.

765 {
766#if defined(BOTAN_HAS_SM2)
767 if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
769 }
770 *key = nullptr;
771
772 return ffi_guard_thunk(__func__, [=]() -> int {
773 std::unique_ptr<Botan::SM2_PublicKey> p_key;
774
775 int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
776 if(rc == BOTAN_FFI_SUCCESS) {
777 ffi_new_object(key, std::move(p_key));
778 }
779
780 return rc;
781 });
782#else
783 BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
785#endif
786}

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

◆ botan_pubkey_load_x25519()

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

Definition at line 983 of file ffi_pkey_algs.cpp.

983 {
984#if defined(BOTAN_HAS_X25519)
985 if(key == nullptr) {
987 }
988 *key = nullptr;
989 return ffi_guard_thunk(__func__, [=]() -> int {
990 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(std::span{pubkey, 32});
991 return ffi_new_object(key, std::move(x25519));
992 });
993#else
994 BOTAN_UNUSED(key, pubkey);
996#endif
997}

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

◆ botan_pubkey_load_x448()

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

Definition at line 1053 of file ffi_pkey_algs.cpp.

1053 {
1054#if defined(BOTAN_HAS_X448)
1055 if(key == nullptr) {
1057 }
1058 *key = nullptr;
1059 return ffi_guard_thunk(__func__, [=]() -> int {
1060 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span{pubkey, 56});
1061 return ffi_new_object(key, std::move(x448));
1062 });
1063#else
1064 BOTAN_UNUSED(key, pubkey);
1066#endif
1067}

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

◆ botan_pubkey_rsa_get_e()

int botan_pubkey_rsa_get_e ( botan_mp_t e,
botan_pubkey_t key )

Definition at line 309 of file ffi_pkey_algs.cpp.

309 {
310 return botan_pubkey_get_field(e, key, "e");
311}

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

313 {
314 return botan_pubkey_get_field(n, key, "n");
315}

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

709 {
710 if(out == nullptr || out_len == nullptr || ident == nullptr || hash_algo == nullptr || key == nullptr) {
712 }
713
714#if defined(BOTAN_HAS_SM2)
715 return ffi_guard_thunk(__func__, [=]() -> int {
716 const Botan::Public_Key& pub_key = safe_get(key);
717 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
718
719 if(ec_key == nullptr) {
721 }
722
723 if(ec_key->algo_name() != "SM2") {
725 }
726
727 const std::string ident_str(ident);
728 std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
729
730 const auto& pt = ec_key->_public_ec_point();
731
732 const auto za = Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), pt);
733
734 return write_vec_output(out, out_len, za);
735 });
736#else
738#endif
739}
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:308
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:67

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

1440 {
1441#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1442 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1443 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1444 auto pt = ecc->_public_ec_point().serialize_uncompressed();
1445 return invoke_view_callback(view, ctx, pt);
1446 } else {
1448 }
1449 });
1450#else
1451 BOTAN_UNUSED(key, view, ctx);
1453#endif
1454}

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

1185 {
1186#if defined(BOTAN_HAS_KYBER)
1187 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1188 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1189 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1190 } else {
1192 }
1193 });
1194#else
1195 BOTAN_UNUSED(key, ctx, view);
1197#endif
1198}

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

1019 {
1020#if defined(BOTAN_HAS_X25519)
1021 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1022 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
1023 Botan::copy_mem(std::span{output, 32}, x25519->raw_public_key_bits());
1024 return BOTAN_FFI_SUCCESS;
1025 } else {
1027 }
1028 });
1029#else
1030 BOTAN_UNUSED(key, output);
1032#endif
1033}

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

1086 {
1087#if defined(BOTAN_HAS_X448)
1088 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1089 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
1090 Botan::copy_mem(std::span{output, 56}, x448->raw_public_key_bits());
1091 return BOTAN_FFI_SUCCESS;
1092 } else {
1094 }
1095 });
1096#else
1097 BOTAN_UNUSED(key, output);
1099#endif
1100}
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().