Botan 3.11.0
Crypto and TLS for C&
ffi_pkey_algs.cpp File Reference
#include <botan/ffi.h>
#include <botan/assert.h>
#include <botan/ec_group.h>
#include <botan/hash.h>
#include <botan/mem_ops.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_rsa_pkcs1 (botan_pubkey_t *key, const uint8_t bits[], size_t len)
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 1480 of file ffi_pkey_algs.cpp.

1487 {
1488 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
1490}
#define BOTAN_UNUSED
Definition assert.h:144
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:140

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

1500 {
1501 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1503}

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

597 {
598 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
599}
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition ffi_pkey.cpp:30

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

359 {
360#if defined(BOTAN_HAS_DSA)
361
362 if((rng_obj == nullptr) || (key == nullptr)) {
364 }
365
366 if((pbits % 64 != 0) || (qbits % 8 != 0) || (pbits < 1024) || (pbits > 3072) || (qbits < 160) || (qbits > 256)) {
368 }
369
370 return ffi_guard_thunk(__func__, [=]() -> int {
372 const Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
373 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
374 return ffi_new_object(key, std::move(dsa));
375 });
376#else
377 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
379#endif
380}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:133
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:134
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 637 of file ffi_pkey_algs.cpp.

637 {
638 if(key_obj == nullptr || param_str == nullptr) {
640 }
641 *key_obj = nullptr;
642
643 const std::string params(param_str);
644
645 if(params == "X25519" || params == "x25519" || params == "curve25519") {
646 return botan_privkey_create(key_obj, "X25519", "", rng_obj);
647 }
648
649 if(params == "X448" || params == "x448") {
650 return botan_privkey_create(key_obj, "X448", "", rng_obj);
651 }
652
653 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
654}

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

438 {
439 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
440}

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

535 {
536#if defined(BOTAN_HAS_ELGAMAL)
537 if(key == nullptr || rng_obj == nullptr) {
539 }
540 *key = nullptr;
541
542 if(pbits < 1024 || qbits < 160) {
544 }
545
546 const Botan::DL_Group::PrimeType prime_type =
547 ((pbits - 1) == qbits) ? Botan::DL_Group::Strong : Botan::DL_Group::Prime_Subgroup;
548
549 return ffi_guard_thunk(__func__, [=]() -> int {
551 const Botan::DL_Group group(rng, prime_type, pbits, qbits);
552 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
553 return ffi_new_object(key, std::move(elg));
554 });
555#else
556 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
558#endif
559}

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

1475 {
1476 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1477 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1478}

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

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

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

418 {
419 return botan_privkey_get_field(x, key, "x");
420}
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 874 of file ffi_pkey_algs.cpp.

874 {
875#if defined(BOTAN_HAS_ED25519)
876 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
877 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
878 const auto ed_key = ed->raw_private_key_bits();
879 if(ed_key.size() != 64) {
881 }
882 Botan::copy_mem(output, ed_key.data(), ed_key.size());
883 return BOTAN_FFI_SUCCESS;
884 } else {
886 }
887 });
888#else
889 BOTAN_UNUSED(key, output);
891#endif
892}
@ BOTAN_FFI_SUCCESS
Definition ffi.h:116
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition ffi.h:124
#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:144

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 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_PrivateKey*>(&k)) {
952 const auto ed_key = ed->raw_private_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 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 215 of file ffi_pkey_algs.cpp.

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

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

1416 {
1417#if defined(BOTAN_HAS_CLASSICMCELIECE)
1418 if(key == nullptr || privkey == nullptr || cmce_mode == nullptr) {
1420 }
1421
1422 *key = nullptr;
1423
1424 return ffi_guard_thunk(__func__, [=]() -> int {
1425 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1426 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
1427 return ffi_new_object(key, std::move(cmce_key));
1428 });
1429#else
1430 BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1432#endif
1433}
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 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 const Botan::DL_Group group(safe_get(p), safe_get(g));
609 auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
610 return ffi_new_object(key, std::move(dh));
611 });
612#else
613 BOTAN_UNUSED(key, p, g, x);
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_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 382 of file ffi_pkey_algs.cpp.

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

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

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

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

513 {
514#if defined(BOTAN_HAS_ECDSA)
515 if(key == nullptr || curve_name == nullptr) {
517 }
518 *key = nullptr;
519
520 return ffi_guard_thunk(__func__, [=]() -> int {
521 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
522 const int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
523 if(rc == BOTAN_FFI_SUCCESS) {
524 ffi_new_object(key, std::move(p_key));
525 }
526 return rc;
527 });
528#else
529 BOTAN_UNUSED(key, scalar, curve_name);
531#endif
532}

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 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 auto ed25519 =
848 std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(std::span{privkey, 32}));
849 return ffi_new_object(key, std::move(ed25519));
850 });
851#else
852 BOTAN_UNUSED(key, privkey);
854#endif
855}
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 916 of file ffi_pkey_algs.cpp.

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

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

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

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

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

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

1123 {
1124#if defined(BOTAN_HAS_KYBER)
1125 if(key == nullptr) {
1127 }
1128 *key = nullptr;
1129
1130 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1131 if(len == 1632) {
1133 } else if(len == 2400) {
1135 } else if(len == 3168) {
1137 } else {
1138 return {};
1139 }
1140 }(key_len);
1141
1142 if(mode.has_value()) {
1143 return ffi_guard_thunk(__func__, [=]() -> int {
1144 auto kyber = std::make_unique<Botan::Kyber_PrivateKey>(std::span{privkey, key_len}, *mode);
1145 return ffi_new_object(key, std::move(kyber));
1146 });
1147 } else {
1149 }
1150#else
1151 BOTAN_UNUSED(key, key_len, privkey);
1153#endif
1154}

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

1271 {
1272#if defined(BOTAN_HAS_ML_DSA)
1273 if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
1275 }
1276
1277 *key = nullptr;
1278
1279 return ffi_guard_thunk(__func__, [=]() -> int {
1280 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1281 if(!mode.is_ml_dsa()) {
1283 }
1284
1285 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1286 return ffi_new_object(key, std::move(mldsa_key));
1287 });
1288#else
1289 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1291#endif
1292}
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 1221 of file ffi_pkey_algs.cpp.

1221 {
1222#if defined(BOTAN_HAS_ML_KEM)
1223 if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
1225 }
1226
1227 *key = nullptr;
1228
1229 return ffi_guard_thunk(__func__, [=]() -> int {
1230 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1231 if(!mode.is_ml_kem()) {
1233 }
1234
1235 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1236 return ffi_new_object(key, std::move(mlkem_key));
1237 });
1238#else
1239 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1241#endif
1242}
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 237 of file ffi_pkey_algs.cpp.

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

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

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

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

1321 {
1322#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1323 if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
1325 }
1326
1327 *key = nullptr;
1328
1329 return ffi_guard_thunk(__func__, [=]() -> int {
1330 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1331 if(!mode.is_slh_dsa()) {
1333 }
1334
1335 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1336 return ffi_new_object(key, std::move(slhdsa_key));
1337 });
1338#else
1339 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1341#endif
1342}

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

805 {
806#if defined(BOTAN_HAS_SM2)
807 if(key == nullptr || curve_name == nullptr) {
809 }
810 *key = nullptr;
811
812 return ffi_guard_thunk(__func__, [=]() -> int {
813 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
814 const int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
815
816 if(rc == BOTAN_FFI_SUCCESS) {
817 ffi_new_object(key, std::move(p_key));
818 }
819 return rc;
820 });
821#else
822 BOTAN_UNUSED(key, scalar, curve_name);
824#endif
825}

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

834 {
835 return botan_privkey_load_sm2(key, scalar, curve_name);
836}
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 984 of file ffi_pkey_algs.cpp.

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

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

1054 {
1055#if defined(BOTAN_HAS_X448)
1056 if(key == nullptr) {
1058 }
1059 *key = nullptr;
1060 return ffi_guard_thunk(__func__, [=]() -> int {
1061 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span{privkey, 56});
1062 return ffi_new_object(key, std::move(x448));
1063 });
1064#else
1065 BOTAN_UNUSED(key, privkey);
1067#endif
1068}
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 322 of file ffi_pkey_algs.cpp.

322 {
323 return botan_privkey_get_field(d, key, "d");
324}

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

318 {
319 return botan_privkey_get_field(e, key, "e");
320}

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

314 {
315 return botan_privkey_get_field(n, key, "n");
316}

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

306 {
307 return botan_privkey_get_field(p, key, "p");
308}

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

334 {
335#if defined(BOTAN_HAS_RSA)
336 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
337 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
338 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
339 return write_vec_output(out, out_len, rsa->private_key_bits());
340 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
341 // TODO define new generic functions for this
342 return write_str_output(reinterpret_cast<char*>(out),
343 out_len,
344 Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
345 } else {
347 }
348 } else {
350 }
351 });
352#else
353 BOTAN_UNUSED(rsa_key, out, out_len, flags);
355#endif
356}
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1511
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1510
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:132
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 310 of file ffi_pkey_algs.cpp.

310 {
311 return botan_privkey_get_field(q, key, "q");
312}

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

1187 {
1188#if defined(BOTAN_HAS_KYBER)
1189 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1190 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1191 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1192 } else {
1194 }
1195 });
1196#else
1197 BOTAN_UNUSED(key, ctx, view);
1199#endif
1200}
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 1016 of file ffi_pkey_algs.cpp.

1016 {
1017#if defined(BOTAN_HAS_X25519)
1018 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1019 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
1020 const auto x25519_key = x25519->raw_private_key_bits();
1021 if(x25519_key.size() != 32) {
1023 }
1024 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
1025 return BOTAN_FFI_SUCCESS;
1026 } else {
1028 }
1029 });
1030#else
1031 BOTAN_UNUSED(key, output);
1033#endif
1034}

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 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_PrivateKey*>(&k)) {
1090 const auto x448_key = x448->raw_private_key_bits();
1091 Botan::copy_mem(std::span{output, 56}, x448_key);
1092 return BOTAN_FFI_SUCCESS;
1093 } else {
1095 }
1096 });
1097#else
1098 BOTAN_UNUSED(key, output);
1100#endif
1101}
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 430 of file ffi_pkey_algs.cpp.

430 {
431 return botan_pubkey_get_field(g, key, "g");
432}
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 422 of file ffi_pkey_algs.cpp.

422 {
423 return botan_pubkey_get_field(p, key, "p");
424}

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

426 {
427 return botan_pubkey_get_field(q, key, "q");
428}

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

434 {
435 return botan_pubkey_get_field(y, key, "y");
436}

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

444 {
445#if defined(BOTAN_HAS_ECC_KEY)
446 return ffi_guard_thunk(__func__, [=]() -> int {
447 const Botan::Public_Key& pub_key = safe_get(key);
448 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
449
450 if(ec_key == nullptr) {
452 }
453
454 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
455 });
456#else
457 BOTAN_UNUSED(key);
459#endif
460}
bool used_explicit_encoding() const
Definition ec_group.h:262
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 894 of file ffi_pkey_algs.cpp.

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

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

965 {
966#if defined(BOTAN_HAS_ED448)
967 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
968 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
969 const auto ed_key = ed->public_key_bits();
970 Botan::copy_mem(std::span(output, 57), ed_key);
971 return BOTAN_FFI_SUCCESS;
972 } else {
974 }
975 });
976#else
977 BOTAN_UNUSED(key, output);
979#endif
980}
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 205 of file ffi_pkey_algs.cpp.

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

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

1438 {
1439#if defined(BOTAN_HAS_CLASSICMCELIECE)
1440 if(key == nullptr || pubkey == nullptr || cmce_mode == nullptr) {
1442 }
1443
1444 *key = nullptr;
1445
1446 return ffi_guard_thunk(__func__, [=]() -> int {
1447 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1448 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
1449 return ffi_new_object(key, std::move(cmce_key));
1450 });
1451#else
1452 BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1454#endif
1455}

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

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

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

400 {
401#if defined(BOTAN_HAS_DSA)
402 if(key == nullptr) {
404 }
405 *key = nullptr;
406
407 return ffi_guard_thunk(__func__, [=]() -> int {
408 const Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
409 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
410 return ffi_new_object(key, std::move(dsa));
411 });
412#else
413 BOTAN_UNUSED(key, p, q, g, y);
415#endif
416}

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

659 {
660#if defined(BOTAN_HAS_ECDH)
661 if(key == nullptr || curve_name == nullptr) {
663 }
664 *key = nullptr;
665 return ffi_guard_thunk(__func__, [=]() -> int {
666 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
667 const int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
668
669 if(rc == BOTAN_FFI_SUCCESS) {
670 ffi_new_object(key, std::move(p_key));
671 }
672 return rc;
673 });
674#else
675 BOTAN_UNUSED(key, public_x, public_y, curve_name);
677#endif
678}

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

680 {
681#if defined(BOTAN_HAS_ECDH)
682 if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
684 }
685 *key = nullptr;
686
687 return ffi_guard_thunk(__func__, [=]() -> int {
688 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
689
690 const int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
691 if(rc == BOTAN_FFI_SUCCESS) {
692 ffi_new_object(key, std::move(p_key));
693 }
694
695 return rc;
696 });
697#else
698 BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
700#endif
701}

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

467 {
468#if defined(BOTAN_HAS_ECDSA)
469 if(key == nullptr || curve_name == nullptr) {
471 }
472 *key = nullptr;
473
474 return ffi_guard_thunk(__func__, [=]() -> int {
475 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
476
477 const int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
478 if(rc == BOTAN_FFI_SUCCESS) {
479 ffi_new_object(key, std::move(p_key));
480 }
481
482 return rc;
483 });
484#else
485 BOTAN_UNUSED(key, public_x, public_y, curve_name);
487#endif
488}

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

490 {
491#if defined(BOTAN_HAS_ECDSA)
492 if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
494 }
495 *key = nullptr;
496
497 return ffi_guard_thunk(__func__, [=]() -> int {
498 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
499
500 const int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
501 if(rc == BOTAN_FFI_SUCCESS) {
502 ffi_new_object(key, std::move(p_key));
503 }
504
505 return rc;
506 });
507#else
508 BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
510#endif
511}

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

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

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

932 {
933#if defined(BOTAN_HAS_ED448)
934 if(key == nullptr) {
936 }
937 *key = nullptr;
938 return ffi_guard_thunk(__func__, [=]() -> int {
939 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
940 return ffi_new_object(key, std::move(ed448));
941 });
942#else
943 BOTAN_UNUSED(key, pubkey);
945#endif
946}

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 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 const Botan::DL_Group group(safe_get(p), safe_get(g));
569 auto elg = std::make_unique<Botan::ElGamal_PublicKey>(group, safe_get(y));
570 return ffi_new_object(key, std::move(elg));
571 });
572#else
573 BOTAN_UNUSED(key, p, g, y);
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_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 1390 of file ffi_pkey_algs.cpp.

1390 {
1391#if defined(BOTAN_HAS_FRODOKEM)
1392 if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
1394 }
1395
1396 *key = nullptr;
1397
1398 return ffi_guard_thunk(__func__, [=]() -> int {
1399 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1400 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1401 return ffi_new_object(key, std::move(frodo_key));
1402 });
1403#else
1404 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1406#endif
1407}

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

1156 {
1157#if defined(BOTAN_HAS_KYBER)
1158 if(key == nullptr) {
1160 }
1161 *key = nullptr;
1162
1163 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1164 if(len == 800) {
1166 } else if(len == 1184) {
1168 } else if(len == 1568) {
1170 } else {
1171 return {};
1172 }
1173 }(key_len);
1174
1175 if(mode.has_value()) {
1176 auto kyber = std::make_unique<Botan::Kyber_PublicKey>(std::span{pubkey, key_len}, *mode);
1177 return ffi_new_object(key, std::move(kyber));
1178 } else {
1180 }
1181#else
1182 BOTAN_UNUSED(key, pubkey, key_len);
1184#endif
1185}

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

1294 {
1295#if defined(BOTAN_HAS_ML_DSA)
1296 if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
1298 }
1299
1300 *key = nullptr;
1301
1302 return ffi_guard_thunk(__func__, [=]() -> int {
1303 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1304 if(!mode.is_ml_dsa()) {
1306 }
1307
1308 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1309 return ffi_new_object(key, std::move(mldsa_key));
1310 });
1311#else
1312 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1314#endif
1315}

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

1244 {
1245#if defined(BOTAN_HAS_ML_KEM)
1246 if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
1248 }
1249
1250 *key = nullptr;
1251
1252 return ffi_guard_thunk(__func__, [=]() -> int {
1253 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1254 if(!mode.is_ml_kem()) {
1256 }
1257
1258 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1259 return ffi_new_object(key, std::move(mlkem_key));
1260 });
1261#else
1262 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1264#endif
1265}

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

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

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

int botan_pubkey_load_rsa_pkcs1 ( botan_pubkey_t * key,
const uint8_t bits[],
size_t len )

Definition at line 288 of file ffi_pkey_algs.cpp.

288 {
289#if defined(BOTAN_HAS_RSA)
290 if(key == nullptr || bits == nullptr) {
292 }
293 *key = nullptr;
294
295 return ffi_guard_thunk(__func__, [=]() -> int {
297 auto rsa = std::make_unique<Botan::RSA_PublicKey>(alg_id, std::span{bits, len});
298 return ffi_new_object(key, std::move(rsa));
299 });
300#else
301 BOTAN_UNUSED(key, bits, len);
303#endif
304}

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

1344 {
1345#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1346 if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
1348 }
1349
1350 *key = nullptr;
1351
1352 return ffi_guard_thunk(__func__, [=]() -> int {
1353 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1354 if(!mode.is_slh_dsa()) {
1356 }
1357
1358 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1359 return ffi_new_object(key, std::move(mldsa_key));
1360 });
1361#else
1362 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1364#endif
1365}

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

761 {
762#if defined(BOTAN_HAS_SM2)
763 if(key == nullptr || curve_name == nullptr) {
765 }
766 *key = nullptr;
767
768 return ffi_guard_thunk(__func__, [=]() -> int {
769 std::unique_ptr<Botan::SM2_PublicKey> p_key;
770 if(pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name) == 0) {
771 return ffi_new_object(key, std::move(p_key));
772 } else {
774 }
775 });
776#else
777 BOTAN_UNUSED(key, public_x, public_y, curve_name);
779#endif
780}
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:148

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

830 {
831 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
832}
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 782 of file ffi_pkey_algs.cpp.

782 {
783#if defined(BOTAN_HAS_SM2)
784 if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
786 }
787 *key = nullptr;
788
789 return ffi_guard_thunk(__func__, [=]() -> int {
790 std::unique_ptr<Botan::SM2_PublicKey> p_key;
791
792 const int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
793 if(rc == BOTAN_FFI_SUCCESS) {
794 ffi_new_object(key, std::move(p_key));
795 }
796
797 return rc;
798 });
799#else
800 BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
802#endif
803}

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

1000 {
1001#if defined(BOTAN_HAS_X25519)
1002 if(key == nullptr) {
1004 }
1005 *key = nullptr;
1006 return ffi_guard_thunk(__func__, [=]() -> int {
1007 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(std::span{pubkey, 32});
1008 return ffi_new_object(key, std::move(x25519));
1009 });
1010#else
1011 BOTAN_UNUSED(key, pubkey);
1013#endif
1014}

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

1070 {
1071#if defined(BOTAN_HAS_X448)
1072 if(key == nullptr) {
1074 }
1075 *key = nullptr;
1076 return ffi_guard_thunk(__func__, [=]() -> int {
1077 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span{pubkey, 56});
1078 return ffi_new_object(key, std::move(x448));
1079 });
1080#else
1081 BOTAN_UNUSED(key, pubkey);
1083#endif
1084}

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

326 {
327 return botan_pubkey_get_field(e, key, "e");
328}

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

330 {
331 return botan_pubkey_get_field(n, key, "n");
332}

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

726 {
727 if(out == nullptr || out_len == nullptr || ident == nullptr || hash_algo == nullptr || key == nullptr) {
729 }
730
731#if defined(BOTAN_HAS_SM2)
732 return ffi_guard_thunk(__func__, [=]() -> int {
733 const Botan::Public_Key& pub_key = safe_get(key);
734 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
735
736 if(ec_key == nullptr) {
738 }
739
740 if(ec_key->algo_name() != "SM2") {
742 }
743
744 const std::string ident_str(ident);
745 std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
746
747 const auto& pt = ec_key->_public_ec_point();
748
749 const auto za = Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), pt);
750
751 return write_vec_output(out, out_len, za);
752 });
753#else
755#endif
756}
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:82

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

1457 {
1458#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1459 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1460 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1461 auto pt = ecc->_public_ec_point().serialize_uncompressed();
1462 return invoke_view_callback(view, ctx, pt);
1463 } else {
1465 }
1466 });
1467#else
1468 BOTAN_UNUSED(key, view, ctx);
1470#endif
1471}

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

1202 {
1203#if defined(BOTAN_HAS_KYBER)
1204 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1205 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1206 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1207 } else {
1209 }
1210 });
1211#else
1212 BOTAN_UNUSED(key, ctx, view);
1214#endif
1215}

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

1036 {
1037#if defined(BOTAN_HAS_X25519)
1038 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1039 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
1040 Botan::copy_mem(std::span{output, 32}, x25519->raw_public_key_bits());
1041 return BOTAN_FFI_SUCCESS;
1042 } else {
1044 }
1045 });
1046#else
1047 BOTAN_UNUSED(key, output);
1049#endif
1050}

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

1103 {
1104#if defined(BOTAN_HAS_X448)
1105 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1106 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
1107 Botan::copy_mem(std::span{output, 56}, x448->raw_public_key_bits());
1108 return BOTAN_FFI_SUCCESS;
1109 } else {
1111 }
1112 });
1113#else
1114 BOTAN_UNUSED(key, output);
1116#endif
1117}
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().