Botan 3.9.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_ecdsa (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
int botan_pubkey_load_ed25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
int botan_pubkey_load_ed448 (botan_pubkey_t *key, const uint8_t pubkey[57])
int botan_pubkey_load_elgamal (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
int botan_pubkey_load_frodokem (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *frodo_mode)
int botan_pubkey_load_kyber (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len)
int botan_pubkey_load_ml_dsa (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *mldsa_mode)
int botan_pubkey_load_ml_kem (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *mlkem_mode)
int botan_pubkey_load_rsa (botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
int botan_pubkey_load_slh_dsa (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *slhdsa_mode)
int botan_pubkey_load_sm2 (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
int botan_pubkey_load_sm2_enc (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
int botan_pubkey_load_x25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
int botan_pubkey_load_x448 (botan_pubkey_t *key, const uint8_t pubkey[56])
int botan_pubkey_rsa_get_e (botan_mp_t e, botan_pubkey_t key)
int botan_pubkey_rsa_get_n (botan_mp_t n, botan_pubkey_t key)
int botan_pubkey_sm2_compute_za (uint8_t out[], size_t *out_len, const char *ident, const char *hash_algo, const botan_pubkey_t key)
int botan_pubkey_view_ec_public_point (const botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_pubkey_view_kyber_raw_key (botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_pubkey_x25519_get_pubkey (botan_pubkey_t key, uint8_t output[32])
int botan_pubkey_x448_get_pubkey (botan_pubkey_t key, uint8_t output[56])

Function Documentation

◆ botan_mceies_decrypt()

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

Definition at line 1376 of file ffi_pkey_algs.cpp.

1383 {
1384 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
1386}
#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 1388 of file ffi_pkey_algs.cpp.

1396 {
1397 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1399}

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

539 {
540 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
541}
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 324 of file ffi_pkey_algs.cpp.

324 {
325#if defined(BOTAN_HAS_DSA)
326
327 if((rng_obj == nullptr) || (key == nullptr)) {
329 }
330
331 if((pbits % 64 != 0) || (qbits % 8 != 0) || (pbits < 1024) || (pbits > 3072) || (qbits < 160) || (qbits > 256)) {
333 }
334
335 return ffi_guard_thunk(__func__, [=]() -> int {
337 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
338 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
339 return ffi_new_object(key, std::move(dsa));
340 });
341#else
342 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
344#endif
345}
@ 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 579 of file ffi_pkey_algs.cpp.

579 {
580 if(key_obj == nullptr || param_str == nullptr) {
582 }
583 *key_obj = nullptr;
584
585 const std::string params(param_str);
586
587 if(params == "X25519" || params == "x25519" || params == "curve25519") {
588 return botan_privkey_create(key_obj, "X25519", "", rng_obj);
589 }
590
591 if(params == "X448" || params == "x448") {
592 return botan_privkey_create(key_obj, "X448", "", rng_obj);
593 }
594
595 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
596}

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

403 {
404 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
405}

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

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

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

1371 {
1372 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1373 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1374}

References botan_privkey_create().

◆ botan_privkey_create_rsa()

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

Definition at line 210 of file ffi_pkey_algs.cpp.

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

References BOTAN_FFI_ERROR_BAD_PARAMETER, and botan_privkey_create().

◆ botan_privkey_dsa_get_x()

int botan_privkey_dsa_get_x ( botan_mp_t x,
botan_privkey_t key )

Definition at line 383 of file ffi_pkey_algs.cpp.

383 {
384 return botan_privkey_get_field(x, key, "x");
385}
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 770 of file ffi_pkey_algs.cpp.

770 {
771#if defined(BOTAN_HAS_ED25519)
772 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
773 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
774 const auto ed_key = ed->raw_private_key_bits();
775 if(ed_key.size() != 64) {
777 }
778 Botan::copy_mem(output, ed_key.data(), ed_key.size());
779 return BOTAN_FFI_SUCCESS;
780 } else {
782 }
783 });
784#else
785 BOTAN_UNUSED(key, output);
787#endif
788}
@ 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 844 of file ffi_pkey_algs.cpp.

844 {
845#if defined(BOTAN_HAS_ED448)
846 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
847 if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
848 const auto ed_key = ed->raw_private_key_bits();
849 Botan::copy_mem(std::span(output, 57), ed_key);
850 return BOTAN_FFI_SUCCESS;
851 } else {
853 }
854 });
855#else
856 BOTAN_UNUSED(key, output);
858#endif
859}
A private key for Ed448/Ed448ph according to RFC 8032.
Definition ed448.h:83

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

◆ botan_privkey_get_field()

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

Definition at line 198 of file ffi_pkey_algs.cpp.

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

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

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

◆ botan_privkey_load_classic_mceliece()

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

Algorithm specific key operation: Classic McEliece

Definition at line 1309 of file ffi_pkey_algs.cpp.

1312 {
1313#if defined(BOTAN_HAS_CLASSICMCELIECE)
1314 if(key == nullptr || privkey == nullptr || cmce_mode == nullptr) {
1316 }
1317
1318 *key = nullptr;
1319
1320 return ffi_guard_thunk(__func__, [=]() -> int {
1321 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1322 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
1323 return ffi_new_object(key, std::move(cmce_key));
1324 });
1325#else
1326 BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1328#endif
1329}
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 543 of file ffi_pkey_algs.cpp.

543 {
544#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
545 if(key == nullptr) {
547 }
548 *key = nullptr;
549 return ffi_guard_thunk(__func__, [=]() -> int {
550 Botan::DL_Group group(safe_get(p), safe_get(g));
551 auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
552 return ffi_new_object(key, std::move(dh));
553 });
554#else
555 BOTAN_UNUSED(key, p, g, x);
557#endif
558}

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

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

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

622 {
623#if defined(BOTAN_HAS_ECDH)
624 if(key == nullptr || curve_name == nullptr) {
626 }
627 *key = nullptr;
628 return ffi_guard_thunk(__func__, [=]() -> int {
629 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
630 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
631 if(rc == BOTAN_FFI_SUCCESS) {
632 ffi_new_object(key, std::move(p_key));
633 }
634 return rc;
635 });
636#else
637 BOTAN_UNUSED(key, scalar, curve_name);
639#endif
640}

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

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

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

736 {
737#if defined(BOTAN_HAS_ED25519)
738 if(key == nullptr) {
740 }
741 *key = nullptr;
742 return ffi_guard_thunk(__func__, [=]() -> int {
743 auto ed25519 =
744 std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(std::span{privkey, 32}));
745 return ffi_new_object(key, std::move(ed25519));
746 });
747#else
748 BOTAN_UNUSED(key, privkey);
750#endif
751}
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 812 of file ffi_pkey_algs.cpp.

812 {
813#if defined(BOTAN_HAS_ED448)
814 if(key == nullptr) {
816 }
817 *key = nullptr;
818 return ffi_guard_thunk(__func__, [=]() -> int {
819 auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
820 return ffi_new_object(key, std::move(ed448));
821 });
822#else
823 BOTAN_UNUSED(key, privkey);
825#endif
826}

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

520 {
521#if defined(BOTAN_HAS_ELGAMAL)
522 if(key == nullptr) {
524 }
525 *key = nullptr;
526 return ffi_guard_thunk(__func__, [=]() -> int {
527 Botan::DL_Group group(safe_get(p), safe_get(g));
528 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(group, safe_get(x));
529 return ffi_new_object(key, std::move(elg));
530 });
531#else
532 BOTAN_UNUSED(key, p, g, x);
534#endif
535}

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

1267 {
1268#if defined(BOTAN_HAS_FRODOKEM)
1269 if(key == nullptr || privkey == nullptr || frodo_mode == nullptr) {
1271 }
1272
1273 *key = nullptr;
1274
1275 return ffi_guard_thunk(__func__, [=]() -> int {
1276 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1277 auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
1278 return ffi_new_object(key, std::move(frodo_key));
1279 });
1280#else
1281 BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1283#endif
1284}

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

1019 {
1020#if defined(BOTAN_HAS_KYBER)
1021 if(key == nullptr) {
1023 }
1024 *key = nullptr;
1025
1026 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1027 if(len == 1632) {
1029 } else if(len == 2400) {
1031 } else if(len == 3168) {
1033 } else {
1034 return {};
1035 }
1036 }(key_len);
1037
1038 if(mode.has_value()) {
1039 return ffi_guard_thunk(__func__, [=]() -> int {
1040 auto kyber = std::make_unique<Botan::Kyber_PrivateKey>(std::span{privkey, key_len}, *mode);
1041 return ffi_new_object(key, std::move(kyber));
1042 });
1043 } else {
1045 }
1046#else
1047 BOTAN_UNUSED(key, key_len, privkey);
1049#endif
1050}

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

1167 {
1168#if defined(BOTAN_HAS_ML_DSA)
1169 if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
1171 }
1172
1173 *key = nullptr;
1174
1175 return ffi_guard_thunk(__func__, [=]() -> int {
1176 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1177 if(!mode.is_ml_dsa()) {
1179 }
1180
1181 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1182 return ffi_new_object(key, std::move(mldsa_key));
1183 });
1184#else
1185 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1187#endif
1188}
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 1117 of file ffi_pkey_algs.cpp.

1117 {
1118#if defined(BOTAN_HAS_ML_KEM)
1119 if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
1121 }
1122
1123 *key = nullptr;
1124
1125 return ffi_guard_thunk(__func__, [=]() -> int {
1126 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1127 if(!mode.is_ml_kem()) {
1129 }
1130
1131 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1132 return ffi_new_object(key, std::move(mlkem_key));
1133 });
1134#else
1135 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1137#endif
1138}
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 220 of file ffi_pkey_algs.cpp.

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

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

237 {
238#if defined(BOTAN_HAS_RSA)
239 if(key == nullptr || bits == nullptr) {
241 }
242 *key = nullptr;
243
244 return ffi_guard_thunk(__func__, [=]() -> int {
246 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, std::span{bits, len});
247 return ffi_new_object(key, std::move(rsa));
248 });
249#else
250 BOTAN_UNUSED(key, bits, len);
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::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 1217 of file ffi_pkey_algs.cpp.

1217 {
1218#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1219 if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
1221 }
1222
1223 *key = nullptr;
1224
1225 return ffi_guard_thunk(__func__, [=]() -> int {
1226 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1227 if(!mode.is_slh_dsa()) {
1229 }
1230
1231 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1232 return ffi_new_object(key, std::move(slhdsa_key));
1233 });
1234#else
1235 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1237#endif
1238}

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

701 {
702#if defined(BOTAN_HAS_SM2)
703 if(key == nullptr || curve_name == nullptr) {
705 }
706 *key = nullptr;
707
708 return ffi_guard_thunk(__func__, [=]() -> int {
709 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
710 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
711
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().

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

730 {
731 return botan_privkey_load_sm2(key, scalar, curve_name);
732}
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 880 of file ffi_pkey_algs.cpp.

880 {
881#if defined(BOTAN_HAS_X25519)
882 if(key == nullptr) {
884 }
885 *key = nullptr;
886 return ffi_guard_thunk(__func__, [=]() -> int {
887 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(std::span{privkey, 32});
888 return ffi_new_object(key, std::move(x25519));
889 });
890#else
891 BOTAN_UNUSED(key, privkey);
893#endif
894}

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

950 {
951#if defined(BOTAN_HAS_X448)
952 if(key == nullptr) {
954 }
955 *key = nullptr;
956 return ffi_guard_thunk(__func__, [=]() -> int {
957 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span{privkey, 56});
958 return ffi_new_object(key, std::move(x448));
959 });
960#else
961 BOTAN_UNUSED(key, privkey);
963#endif
964}
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 287 of file ffi_pkey_algs.cpp.

287 {
288 return botan_privkey_get_field(d, key, "d");
289}

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

283 {
284 return botan_privkey_get_field(e, key, "e");
285}

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

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

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

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

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

299 {
300#if defined(BOTAN_HAS_RSA)
301 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
302 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
303 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
304 return write_vec_output(out, out_len, rsa->private_key_bits());
305 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
306 // TODO define new generic functions for this
307 return write_str_output(reinterpret_cast<char*>(out),
308 out_len,
309 Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
310 } else {
312 }
313 } else {
315 }
316 });
317#else
318 BOTAN_UNUSED(rsa_key, out, out_len, flags);
320#endif
321}
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1398
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1397
@ 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:247
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:251

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

275 {
276 return botan_privkey_get_field(q, key, "q");
277}

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

1083 {
1084#if defined(BOTAN_HAS_KYBER)
1085 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1086 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1087 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1088 } else {
1090 }
1091 });
1092#else
1093 BOTAN_UNUSED(key, ctx, view);
1095#endif
1096}
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 912 of file ffi_pkey_algs.cpp.

912 {
913#if defined(BOTAN_HAS_X25519)
914 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
915 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
916 const auto x25519_key = x25519->raw_private_key_bits();
917 if(x25519_key.size() != 32) {
919 }
920 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
921 return BOTAN_FFI_SUCCESS;
922 } else {
924 }
925 });
926#else
927 BOTAN_UNUSED(key, output);
929#endif
930}

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

982 {
983#if defined(BOTAN_HAS_X448)
984 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
985 if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
986 const auto x448_key = x448->raw_private_key_bits();
987 Botan::copy_mem(std::span{output, 56}, x448_key);
988 return BOTAN_FFI_SUCCESS;
989 } else {
991 }
992 });
993#else
994 BOTAN_UNUSED(key, output);
996#endif
997}
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 395 of file ffi_pkey_algs.cpp.

395 {
396 return botan_pubkey_get_field(g, key, "g");
397}
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 387 of file ffi_pkey_algs.cpp.

387 {
388 return botan_pubkey_get_field(p, key, "p");
389}

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

391 {
392 return botan_pubkey_get_field(q, key, "q");
393}

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

399 {
400 return botan_pubkey_get_field(y, key, "y");
401}

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

409 {
410#if defined(BOTAN_HAS_ECC_KEY)
411 return ffi_guard_thunk(__func__, [=]() -> int {
412 const Botan::Public_Key& pub_key = safe_get(key);
413 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
414
415 if(ec_key == nullptr) {
417 }
418
419 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
420 });
421#else
422 BOTAN_UNUSED(key);
424#endif
425}
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 790 of file ffi_pkey_algs.cpp.

790 {
791#if defined(BOTAN_HAS_ED25519)
792 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
793 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
794 const std::vector<uint8_t>& ed_key = ed->get_public_key();
795 if(ed_key.size() != 32) {
797 }
798 Botan::copy_mem(output, ed_key.data(), ed_key.size());
799 return BOTAN_FFI_SUCCESS;
800 } else {
802 }
803 });
804#else
805 BOTAN_UNUSED(key, output);
807#endif
808}

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

861 {
862#if defined(BOTAN_HAS_ED448)
863 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
864 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
865 const auto ed_key = ed->public_key_bits();
866 Botan::copy_mem(std::span(output, 57), ed_key);
867 return BOTAN_FFI_SUCCESS;
868 } else {
870 }
871 });
872#else
873 BOTAN_UNUSED(key, output);
875#endif
876}
A public key for Ed448/Ed448ph according to RFC 8032.
Definition ed448.h:27

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

◆ botan_pubkey_get_field()

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

Definition at line 188 of file ffi_pkey_algs.cpp.

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

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

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

◆ botan_pubkey_load_classic_mceliece()

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

Definition at line 1331 of file ffi_pkey_algs.cpp.

1334 {
1335#if defined(BOTAN_HAS_CLASSICMCELIECE)
1336 if(key == nullptr || pubkey == nullptr || cmce_mode == nullptr) {
1338 }
1339
1340 *key = nullptr;
1341
1342 return ffi_guard_thunk(__func__, [=]() -> int {
1343 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1344 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
1345 return ffi_new_object(key, std::move(cmce_key));
1346 });
1347#else
1348 BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1350#endif
1351}

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

560 {
561#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
562 if(key == nullptr) {
564 }
565 *key = nullptr;
566 return ffi_guard_thunk(__func__, [=]() -> int {
567 Botan::DL_Group group(safe_get(p), safe_get(g));
568 auto dh = std::make_unique<Botan::DH_PublicKey>(group, safe_get(y));
569 return ffi_new_object(key, std::move(dh));
570 });
571#else
572 BOTAN_UNUSED(key, p, g, y);
574#endif
575}

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 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_PublicKey>(group, safe_get(y));
375 return ffi_new_object(key, std::move(dsa));
376 });
377#else
378 BOTAN_UNUSED(key, p, q, g, y);
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_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 598 of file ffi_pkey_algs.cpp.

601 {
602#if defined(BOTAN_HAS_ECDH)
603 if(key == nullptr || curve_name == nullptr) {
605 }
606 *key = nullptr;
607 return ffi_guard_thunk(__func__, [=]() -> int {
608 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
609 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
610
611 if(rc == BOTAN_FFI_SUCCESS) {
612 ffi_new_object(key, std::move(p_key));
613 }
614 return rc;
615 });
616#else
617 BOTAN_UNUSED(key, public_x, public_y, curve_name);
619#endif
620}

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

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

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

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

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

Definition at line 753 of file ffi_pkey_algs.cpp.

753 {
754#if defined(BOTAN_HAS_ED25519)
755 if(key == nullptr) {
757 }
758 *key = nullptr;
759 return ffi_guard_thunk(__func__, [=]() -> int {
760 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
761 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
762 return ffi_new_object(key, std::move(ed25519));
763 });
764#else
765 BOTAN_UNUSED(key, pubkey);
767#endif
768}

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

828 {
829#if defined(BOTAN_HAS_ED448)
830 if(key == nullptr) {
832 }
833 *key = nullptr;
834 return ffi_guard_thunk(__func__, [=]() -> int {
835 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
836 return ffi_new_object(key, std::move(ed448));
837 });
838#else
839 BOTAN_UNUSED(key, pubkey);
841#endif
842}

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

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

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

1286 {
1287#if defined(BOTAN_HAS_FRODOKEM)
1288 if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
1290 }
1291
1292 *key = nullptr;
1293
1294 return ffi_guard_thunk(__func__, [=]() -> int {
1295 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1296 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1297 return ffi_new_object(key, std::move(frodo_key));
1298 });
1299#else
1300 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1302#endif
1303}

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

1052 {
1053#if defined(BOTAN_HAS_KYBER)
1054 if(key == nullptr) {
1056 }
1057 *key = nullptr;
1058
1059 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1060 if(len == 800) {
1062 } else if(len == 1184) {
1064 } else if(len == 1568) {
1066 } else {
1067 return {};
1068 }
1069 }(key_len);
1070
1071 if(mode.has_value()) {
1072 auto kyber = std::make_unique<Botan::Kyber_PublicKey>(std::span{pubkey, key_len}, *mode);
1073 return ffi_new_object(key, std::move(kyber));
1074 } else {
1076 }
1077#else
1078 BOTAN_UNUSED(key, pubkey, key_len);
1080#endif
1081}

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

1190 {
1191#if defined(BOTAN_HAS_ML_DSA)
1192 if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
1194 }
1195
1196 *key = nullptr;
1197
1198 return ffi_guard_thunk(__func__, [=]() -> int {
1199 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1200 if(!mode.is_ml_dsa()) {
1202 }
1203
1204 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1205 return ffi_new_object(key, std::move(mldsa_key));
1206 });
1207#else
1208 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1210#endif
1211}

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

1140 {
1141#if defined(BOTAN_HAS_ML_KEM)
1142 if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
1144 }
1145
1146 *key = nullptr;
1147
1148 return ffi_guard_thunk(__func__, [=]() -> int {
1149 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1150 if(!mode.is_ml_kem()) {
1152 }
1153
1154 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1155 return ffi_new_object(key, std::move(mlkem_key));
1156 });
1157#else
1158 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1160#endif
1161}

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

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

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

1240 {
1241#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1242 if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
1244 }
1245
1246 *key = nullptr;
1247
1248 return ffi_guard_thunk(__func__, [=]() -> int {
1249 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1250 if(!mode.is_slh_dsa()) {
1252 }
1253
1254 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1255 return ffi_new_object(key, std::move(mldsa_key));
1256 });
1257#else
1258 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1260#endif
1261}

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

680 {
681#if defined(BOTAN_HAS_SM2)
682 if(key == nullptr || curve_name == nullptr) {
684 }
685 *key = nullptr;
686
687 return ffi_guard_thunk(__func__, [=]() -> int {
688 std::unique_ptr<Botan::SM2_PublicKey> p_key;
689 if(pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name) == 0) {
690 return ffi_new_object(key, std::move(p_key));
691 } else {
693 }
694 });
695#else
696 BOTAN_UNUSED(key, public_x, public_y, curve_name);
698#endif
699}
@ 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 723 of file ffi_pkey_algs.cpp.

726 {
727 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
728}
int botan_pubkey_load_sm2(botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)

References botan_pubkey_load_sm2().

◆ botan_pubkey_load_x25519()

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

Definition at line 896 of file ffi_pkey_algs.cpp.

896 {
897#if defined(BOTAN_HAS_X25519)
898 if(key == nullptr) {
900 }
901 *key = nullptr;
902 return ffi_guard_thunk(__func__, [=]() -> int {
903 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(std::span{pubkey, 32});
904 return ffi_new_object(key, std::move(x25519));
905 });
906#else
907 BOTAN_UNUSED(key, pubkey);
909#endif
910}

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

966 {
967#if defined(BOTAN_HAS_X448)
968 if(key == nullptr) {
970 }
971 *key = nullptr;
972 return ffi_guard_thunk(__func__, [=]() -> int {
973 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span{pubkey, 56});
974 return ffi_new_object(key, std::move(x448));
975 });
976#else
977 BOTAN_UNUSED(key, pubkey);
979#endif
980}

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

291 {
292 return botan_pubkey_get_field(e, key, "e");
293}

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

295 {
296 return botan_pubkey_get_field(n, key, "n");
297}

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

645 {
646 if(out == nullptr || out_len == nullptr || ident == nullptr || hash_algo == nullptr || key == nullptr) {
648 }
649
650#if defined(BOTAN_HAS_SM2)
651 return ffi_guard_thunk(__func__, [=]() -> int {
652 const Botan::Public_Key& pub_key = safe_get(key);
653 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
654
655 if(ec_key == nullptr) {
657 }
658
659 if(ec_key->algo_name() != "SM2") {
661 }
662
663 const std::string ident_str(ident);
664 std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
665
666 const auto& pt = ec_key->_public_ec_point();
667
668 const auto za = Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), pt);
669
670 return write_vec_output(out, out_len, za);
671 });
672#else
674#endif
675}
virtual std::string algo_name() const =0
const EC_AffinePoint & _public_ec_point() const
Definition ecc_key.cpp:76
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:298
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, std::string_view user_id, const EC_Group &group, const EC_AffinePoint &pubkey)
Definition sm2.cpp:68

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

◆ botan_pubkey_view_ec_public_point()

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

View the uncompressed public point associated with the key

Definition at line 1353 of file ffi_pkey_algs.cpp.

1353 {
1354#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1355 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1356 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1357 auto pt = ecc->_public_ec_point().serialize_uncompressed();
1358 return invoke_view_callback(view, ctx, pt);
1359 } else {
1361 }
1362 });
1363#else
1364 BOTAN_UNUSED(key, view, ctx);
1366#endif
1367}

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

1098 {
1099#if defined(BOTAN_HAS_KYBER)
1100 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1101 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1102 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1103 } else {
1105 }
1106 });
1107#else
1108 BOTAN_UNUSED(key, ctx, view);
1110#endif
1111}

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

932 {
933#if defined(BOTAN_HAS_X25519)
934 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
935 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
936 Botan::copy_mem(std::span{output, 32}, x25519->raw_public_key_bits());
937 return BOTAN_FFI_SUCCESS;
938 } else {
940 }
941 });
942#else
943 BOTAN_UNUSED(key, output);
945#endif
946}

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

999 {
1000#if defined(BOTAN_HAS_X448)
1001 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1002 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
1003 Botan::copy_mem(std::span{output, 56}, x448->raw_public_key_bits());
1004 return BOTAN_FFI_SUCCESS;
1005 } else {
1007 }
1008 });
1009#else
1010 BOTAN_UNUSED(key, output);
1012#endif
1013}
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().