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

Go to the source code of this file.

Functions

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

Function Documentation

◆ botan_mceies_decrypt()

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

Definition at line 1327 of file ffi_pkey_algs.cpp.

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_mceies_encrypt()

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

Definition at line 1339 of file ffi_pkey_algs.cpp.

1347 {
1348 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1350}

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

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

References botan_privkey_create().

◆ botan_privkey_create_dsa()

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

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

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

Definition at line 309 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_create_ecdh()

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

Definition at line 542 of file ffi_pkey_algs.cpp.

542 {
543 if(param_str == nullptr) {
545 }
546
547 const std::string params(param_str);
548
549 if(params == "x25519" || params == "curve25519") {
550 return botan_privkey_create(key_obj, "X25519", "", rng_obj);
551 }
552
553 if(params == "x448") {
554 return botan_privkey_create(key_obj, "X448", "", rng_obj);
555 }
556
557 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
558}

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

385 {
386 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
387}

References botan_privkey_create().

◆ botan_privkey_create_elgamal()

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

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

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

Definition at line 447 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_create_mceliece()

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

Definition at line 1322 of file ffi_pkey_algs.cpp.

1322 {
1323 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1324 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1325}

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

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

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

365 {
366 return botan_privkey_get_field(x, key, "x");
367}
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 712 of file ffi_pkey_algs.cpp.

712 {
713#if defined(BOTAN_HAS_ED25519)
714 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
715 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
716 const auto ed_key = ed->raw_private_key_bits();
717 if(ed_key.size() != 64) {
719 }
720 Botan::copy_mem(output, ed_key.data(), ed_key.size());
721 return BOTAN_FFI_SUCCESS;
722 } else {
724 }
725 });
726#else
727 BOTAN_UNUSED(key, output);
729#endif
730}
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition ffi.h:120
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:124
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:147

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

782 {
783#if defined(BOTAN_HAS_ED448)
784 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
785 if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
786 const auto ed_key = ed->raw_private_key_bits();
787 Botan::copy_mem(std::span(output, 57), ed_key);
788 return BOTAN_FFI_SUCCESS;
789 } else {
791 }
792 });
793#else
794 BOTAN_UNUSED(key, output);
796#endif
797}
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 191 of file ffi_pkey_algs.cpp.

191 {
192 if(field_name_cstr == nullptr) {
194 }
195
196 const std::string field_name(field_name_cstr);
197
198 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); });
199}

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

1263 {
1264#if defined(BOTAN_HAS_CLASSICMCELIECE)
1265 if(key == nullptr || privkey == nullptr || cmce_mode == nullptr) {
1267 }
1268
1269 *key = nullptr;
1270
1271 return ffi_guard_thunk(__func__, [=]() -> int {
1272 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1273 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
1274 *key = new botan_privkey_struct(std::move(cmce_key));
1275 return BOTAN_FFI_SUCCESS;
1276 });
1277#else
1278 BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1280#endif
1281}
static Classic_McEliece_Parameter_Set from_string(std::string_view param_name)
Get the parameter set for a given parameter set name.

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

◆ botan_privkey_load_dh()

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

Definition at line 510 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_load_dsa()

int botan_privkey_load_dsa ( botan_privkey_t * key,
botan_mp_t p,
botan_mp_t q,
botan_mp_t g,
botan_mp_t x )

Definition at line 333 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_load_ecdh()

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

Definition at line 580 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_load_ecdsa()

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

Definition at line 430 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_load_ed25519()

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

Definition at line 682 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_load_ed448()

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

Definition at line 754 of file ffi_pkey_algs.cpp.

754 {
755#if defined(BOTAN_HAS_ED448)
756 *key = nullptr;
757 return ffi_guard_thunk(__func__, [=]() -> int {
758 auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
759 *key = new botan_privkey_struct(std::move(ed448));
760 return BOTAN_FFI_SUCCESS;
761 });
762#else
763 BOTAN_UNUSED(key, privkey);
765#endif
766}

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

◆ botan_privkey_load_elgamal()

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

Loads ElGamal private key

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

Definition at line 489 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_load_frodokem()

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

Algorithm specific key operation: FrodoKEM

Definition at line 1216 of file ffi_pkey_algs.cpp.

1216 {
1217#if defined(BOTAN_HAS_FRODOKEM)
1218 if(key == nullptr || privkey == nullptr || frodo_mode == nullptr) {
1220 }
1221
1222 *key = nullptr;
1223
1224 return ffi_guard_thunk(__func__, [=]() -> int {
1225 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1226 auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
1227 *key = new botan_privkey_struct(std::move(frodo_key));
1228 return BOTAN_FFI_SUCCESS;
1229 });
1230#else
1231 BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1233#endif
1234}

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

◆ botan_privkey_load_kyber()

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

Definition at line 956 of file ffi_pkey_algs.cpp.

956 {
957#if defined(BOTAN_HAS_KYBER)
958 *key = nullptr;
959 switch(key_len) {
960 case 1632:
961 return ffi_guard_thunk(__func__, [=]() -> int {
962 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 1632);
963 auto kyber512 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber512_R3);
964 *key = new botan_privkey_struct(std::move(kyber512));
965 return BOTAN_FFI_SUCCESS;
966 });
967 case 2400:
968 return ffi_guard_thunk(__func__, [=]() -> int {
969 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 2400);
970 auto kyber768 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber768_R3);
971 *key = new botan_privkey_struct(std::move(kyber768));
972 return BOTAN_FFI_SUCCESS;
973 });
974 case 3168:
975 return ffi_guard_thunk(__func__, [=]() -> int {
976 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 3168);
977 auto kyber1024 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber1024_R3);
978 *key = new botan_privkey_struct(std::move(kyber1024));
979 return BOTAN_FFI_SUCCESS;
980 });
981 default:
982 BOTAN_UNUSED(key, privkey, key_len);
984 }
985#else
986 BOTAN_UNUSED(key, key_len, privkey);
988#endif
989}

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

◆ botan_privkey_load_ml_dsa()

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

Definition at line 1112 of file ffi_pkey_algs.cpp.

1112 {
1113#if defined(BOTAN_HAS_ML_DSA)
1114 if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
1116 }
1117
1118 *key = nullptr;
1119
1120 return ffi_guard_thunk(__func__, [=]() -> int {
1121 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1122 if(!mode.is_ml_dsa()) {
1124 }
1125
1126 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1127 *key = new botan_privkey_struct(std::move(mldsa_key));
1128 return BOTAN_FFI_SUCCESS;
1129 });
1130#else
1131 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1133#endif
1134}
DilithiumMode ML_DSA_Mode
Definition ml_dsa.h:21

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

◆ botan_privkey_load_ml_kem()

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

Definition at line 1060 of file ffi_pkey_algs.cpp.

1060 {
1061#if defined(BOTAN_HAS_ML_KEM)
1062 if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
1064 }
1065
1066 *key = nullptr;
1067
1068 return ffi_guard_thunk(__func__, [=]() -> int {
1069 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1070 if(!mode.is_ml_kem()) {
1072 }
1073
1074 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1075 *key = new botan_privkey_struct(std::move(mlkem_key));
1076 return BOTAN_FFI_SUCCESS;
1077 });
1078#else
1079 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1081#endif
1082}
KyberMode ML_KEM_Mode
Definition ml_kem.h:21

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

◆ botan_privkey_load_rsa()

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

Definition at line 213 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_load_rsa_pkcs1()

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

Definition at line 228 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_load_slh_dsa()

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

Definition at line 1164 of file ffi_pkey_algs.cpp.

1164 {
1165#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1166 if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
1168 }
1169
1170 *key = nullptr;
1171
1172 return ffi_guard_thunk(__func__, [=]() -> int {
1173 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1174 if(!mode.is_slh_dsa()) {
1176 }
1177
1178 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1179 *key = new botan_privkey_struct(std::move(slhdsa_key));
1180 return BOTAN_FFI_SUCCESS;
1181 });
1182#else
1183 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1185#endif
1186}

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

◆ botan_privkey_load_sm2()

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

Definition at line 652 of file ffi_pkey_algs.cpp.

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

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

Referenced by botan_privkey_load_sm2_enc().

◆ botan_privkey_load_sm2_enc()

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

Definition at line 676 of file ffi_pkey_algs.cpp.

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

818 {
819#if defined(BOTAN_HAS_X25519)
820 *key = nullptr;
821 return ffi_guard_thunk(__func__, [=]() -> int {
822 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
823 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(privkey_vec);
824 *key = new botan_privkey_struct(std::move(x25519));
825 return BOTAN_FFI_SUCCESS;
826 });
827#else
828 BOTAN_UNUSED(key, privkey);
830#endif
831}

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

◆ botan_privkey_load_x448()

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

Definition at line 890 of file ffi_pkey_algs.cpp.

890 {
891#if defined(BOTAN_HAS_X448)
892 *key = nullptr;
893 return ffi_guard_thunk(__func__, [=]() -> int {
894 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span(privkey, 56));
895 *key = new botan_privkey_struct(std::move(x448));
896 return BOTAN_FFI_SUCCESS;
897 });
898#else
899 BOTAN_UNUSED(key, privkey);
901#endif
902}
Point448 x448(const ScalarX448 &k, const Point448 &u)
Multiply a scalar k with a point u.

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

◆ botan_privkey_rsa_get_d()

int botan_privkey_rsa_get_d ( botan_mp_t d,
botan_privkey_t key )

Definition at line 275 of file ffi_pkey_algs.cpp.

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

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

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

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

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

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

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

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

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

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

◆ botan_privkey_rsa_get_q()

int botan_privkey_rsa_get_q ( botan_mp_t q,
botan_privkey_t key )

Definition at line 263 of file ffi_pkey_algs.cpp.

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

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

1026 {
1027#if defined(BOTAN_HAS_KYBER)
1028 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1029 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1030 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1031 } else {
1033 }
1034 });
1035#else
1036 BOTAN_UNUSED(key, ctx, view);
1038#endif
1039}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:146

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

◆ botan_privkey_x25519_get_privkey()

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

Definition at line 848 of file ffi_pkey_algs.cpp.

848 {
849#if defined(BOTAN_HAS_X25519)
850 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
851 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
852 const auto x25519_key = x25519->raw_private_key_bits();
853 if(x25519_key.size() != 32) {
855 }
856 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
857 return BOTAN_FFI_SUCCESS;
858 } else {
860 }
861 });
862#else
863 BOTAN_UNUSED(key, output);
865#endif
866}

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

918 {
919#if defined(BOTAN_HAS_X448)
920 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
921 if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
922 const auto x448_key = x448->raw_private_key_bits();
923 Botan::copy_mem(std::span(output, 56), x448_key);
924 return BOTAN_FFI_SUCCESS;
925 } else {
927 }
928 });
929#else
930 BOTAN_UNUSED(key, output);
932#endif
933}
A private key for the X448 key agreement scheme according to RFC 7748.
Definition x448.h:67

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

◆ botan_pubkey_dsa_get_g()

int botan_pubkey_dsa_get_g ( botan_mp_t g,
botan_pubkey_t key )

Definition at line 377 of file ffi_pkey_algs.cpp.

377 {
378 return botan_pubkey_get_field(g, key, "g");
379}
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 369 of file ffi_pkey_algs.cpp.

369 {
370 return botan_pubkey_get_field(p, key, "p");
371}

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

373 {
374 return botan_pubkey_get_field(q, key, "q");
375}

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

381 {
382 return botan_pubkey_get_field(y, key, "y");
383}

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

391 {
392#if defined(BOTAN_HAS_ECC_KEY)
393 return ffi_guard_thunk(__func__, [=]() -> int {
394 const Botan::Public_Key& pub_key = safe_get(key);
395 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
396
397 if(ec_key == nullptr) {
399 }
400
401 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
402 });
403#else
404 BOTAN_UNUSED(key);
406#endif
407}
bool used_explicit_encoding() const
Definition ec_group.h:263
const EC_Group & domain() const
Definition ecc_key.cpp:63

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

732 {
733#if defined(BOTAN_HAS_ED25519)
734 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
735 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
736 const std::vector<uint8_t>& ed_key = ed->get_public_key();
737 if(ed_key.size() != 32) {
739 }
740 Botan::copy_mem(output, ed_key.data(), ed_key.size());
741 return BOTAN_FFI_SUCCESS;
742 } else {
744 }
745 });
746#else
747 BOTAN_UNUSED(key, output);
749#endif
750}

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

799 {
800#if defined(BOTAN_HAS_ED448)
801 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
802 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
803 const auto ed_key = ed->public_key_bits();
804 Botan::copy_mem(std::span(output, 57), ed_key);
805 return BOTAN_FFI_SUCCESS;
806 } else {
808 }
809 });
810#else
811 BOTAN_UNUSED(key, output);
813#endif
814}
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 181 of file ffi_pkey_algs.cpp.

181 {
182 if(field_name_cstr == nullptr) {
184 }
185
186 const std::string field_name(field_name_cstr);
187
188 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); });
189}

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

1286 {
1287#if defined(BOTAN_HAS_CLASSICMCELIECE)
1288 if(key == nullptr || pubkey == nullptr || cmce_mode == nullptr) {
1290 }
1291
1292 *key = nullptr;
1293
1294 return ffi_guard_thunk(__func__, [=]() -> int {
1295 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1296 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
1297 *key = new botan_pubkey_struct(std::move(cmce_key));
1298 return BOTAN_FFI_SUCCESS;
1299 });
1300#else
1301 BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1303#endif
1304}

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

◆ botan_pubkey_load_dh()

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

Loads Diffie Hellman public key

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

Definition at line 525 of file ffi_pkey_algs.cpp.

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

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

◆ botan_pubkey_load_dsa()

int botan_pubkey_load_dsa ( botan_pubkey_t * key,
botan_mp_t p,
botan_mp_t q,
botan_mp_t g,
botan_mp_t y )

Definition at line 349 of file ffi_pkey_algs.cpp.

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

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

◆ botan_pubkey_load_ecdh()

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

Definition at line 560 of file ffi_pkey_algs.cpp.

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

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

◆ botan_pubkey_load_ecdsa()

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

Definition at line 409 of file ffi_pkey_algs.cpp.

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

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

◆ botan_pubkey_load_ed25519()

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

Definition at line 697 of file ffi_pkey_algs.cpp.

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

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

◆ botan_pubkey_load_ed448()

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

Definition at line 768 of file ffi_pkey_algs.cpp.

768 {
769#if defined(BOTAN_HAS_ED448)
770 *key = nullptr;
771 return ffi_guard_thunk(__func__, [=]() -> int {
772 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
773 *key = new botan_pubkey_struct(std::move(ed448));
774 return BOTAN_FFI_SUCCESS;
775 });
776#else
777 BOTAN_UNUSED(key, pubkey);
779#endif
780}

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

◆ botan_pubkey_load_elgamal()

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

Loads ElGamal public key

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

Definition at line 474 of file ffi_pkey_algs.cpp.

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

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

◆ botan_pubkey_load_frodokem()

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

Definition at line 1236 of file ffi_pkey_algs.cpp.

1236 {
1237#if defined(BOTAN_HAS_FRODOKEM)
1238 if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
1240 }
1241
1242 *key = nullptr;
1243
1244 return ffi_guard_thunk(__func__, [=]() -> int {
1245 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1246 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1247 *key = new botan_pubkey_struct(std::move(frodo_key));
1248 return BOTAN_FFI_SUCCESS;
1249 });
1250#else
1251 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1253#endif
1254}

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

◆ botan_pubkey_load_kyber()

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

Definition at line 991 of file ffi_pkey_algs.cpp.

991 {
992#if defined(BOTAN_HAS_KYBER)
993 *key = nullptr;
994 switch(key_len) {
995 case 800:
996 return ffi_guard_thunk(__func__, [=]() -> int {
997 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 800);
998 auto kyber512 = std::make_unique<Botan::Kyber_PublicKey>(pubkey_vec, Botan::KyberMode::Kyber512_R3);
999 *key = new botan_pubkey_struct(std::move(kyber512));
1000 return BOTAN_FFI_SUCCESS;
1001 });
1002 case 1184:
1003 return ffi_guard_thunk(__func__, [=]() -> int {
1004 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 1184);
1005 auto kyber768 = std::make_unique<Botan::Kyber_PublicKey>(pubkey_vec, Botan::KyberMode::Kyber768_R3);
1006 *key = new botan_pubkey_struct(std::move(kyber768));
1007 return BOTAN_FFI_SUCCESS;
1008 });
1009 case 1568:
1010 return ffi_guard_thunk(__func__, [=]() -> int {
1011 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 1568);
1012 auto kyber1024 = std::make_unique<Botan::Kyber_PublicKey>(pubkey_vec, Botan::KyberMode::Kyber1024_R3);
1013 *key = new botan_pubkey_struct(std::move(kyber1024));
1014 return BOTAN_FFI_SUCCESS;
1015 });
1016 default:
1017 BOTAN_UNUSED(key, pubkey, key_len);
1019 }
1020#else
1021 BOTAN_UNUSED(key, pubkey, key_len);
1023#endif
1024}

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

◆ botan_pubkey_load_ml_dsa()

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

Definition at line 1136 of file ffi_pkey_algs.cpp.

1136 {
1137#if defined(BOTAN_HAS_ML_DSA)
1138 if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
1140 }
1141
1142 *key = nullptr;
1143
1144 return ffi_guard_thunk(__func__, [=]() -> int {
1145 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1146 if(!mode.is_ml_dsa()) {
1148 }
1149
1150 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1151 *key = new botan_pubkey_struct(std::move(mldsa_key));
1152 return BOTAN_FFI_SUCCESS;
1153 });
1154#else
1155 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1157#endif
1158}

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

◆ botan_pubkey_load_ml_kem()

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

Definition at line 1084 of file ffi_pkey_algs.cpp.

1084 {
1085#if defined(BOTAN_HAS_ML_KEM)
1086 if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
1088 }
1089
1090 *key = nullptr;
1091
1092 return ffi_guard_thunk(__func__, [=]() -> int {
1093 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1094 if(!mode.is_ml_kem()) {
1096 }
1097
1098 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1099 *key = new botan_pubkey_struct(std::move(mlkem_key));
1100 return BOTAN_FFI_SUCCESS;
1101 });
1102#else
1103 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1105#endif
1106}

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

◆ botan_pubkey_load_rsa()

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

Definition at line 245 of file ffi_pkey_algs.cpp.

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

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

◆ botan_pubkey_load_slh_dsa()

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

Definition at line 1188 of file ffi_pkey_algs.cpp.

1188 {
1189#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1190 if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
1192 }
1193
1194 *key = nullptr;
1195
1196 return ffi_guard_thunk(__func__, [=]() -> int {
1197 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1198 if(!mode.is_slh_dsa()) {
1200 }
1201
1202 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1203 *key = new botan_pubkey_struct(std::move(mldsa_key));
1204 return BOTAN_FFI_SUCCESS;
1205 });
1206#else
1207 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1209#endif
1210}

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

◆ botan_pubkey_load_sm2()

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

Definition at line 633 of file ffi_pkey_algs.cpp.

636 {
637#if defined(BOTAN_HAS_SM2)
638 return ffi_guard_thunk(__func__, [=]() -> int {
639 std::unique_ptr<Botan::SM2_PublicKey> p_key;
640 if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name)) {
641 *key = new botan_pubkey_struct(std::move(p_key));
642 return BOTAN_FFI_SUCCESS;
643 }
645 });
646#else
647 BOTAN_UNUSED(key, public_x, public_y, curve_name);
649#endif
650}
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:143

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

Referenced by botan_pubkey_load_sm2_enc().

◆ botan_pubkey_load_sm2_enc()

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

Definition at line 669 of file ffi_pkey_algs.cpp.

672 {
673 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
674}
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 833 of file ffi_pkey_algs.cpp.

833 {
834#if defined(BOTAN_HAS_X25519)
835 *key = nullptr;
836 return ffi_guard_thunk(__func__, [=]() -> int {
837 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
838 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(pubkey_vec);
839 *key = new botan_pubkey_struct(std::move(x25519));
840 return BOTAN_FFI_SUCCESS;
841 });
842#else
843 BOTAN_UNUSED(key, pubkey);
845#endif
846}

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

◆ botan_pubkey_load_x448()

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

Definition at line 904 of file ffi_pkey_algs.cpp.

904 {
905#if defined(BOTAN_HAS_X448)
906 *key = nullptr;
907 return ffi_guard_thunk(__func__, [=]() -> int {
908 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span(pubkey, 56));
909 *key = new botan_pubkey_struct(std::move(x448));
910 return BOTAN_FFI_SUCCESS;
911 });
912#else
913 BOTAN_UNUSED(key, pubkey);
915#endif
916}

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

◆ botan_pubkey_rsa_get_e()

int botan_pubkey_rsa_get_e ( botan_mp_t e,
botan_pubkey_t key )

Definition at line 279 of file ffi_pkey_algs.cpp.

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

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

283 {
284 return botan_pubkey_get_field(n, key, "n");
285}

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

599 {
600 if(out == nullptr || out_len == nullptr) {
602 }
603 if(ident == nullptr || hash_algo == nullptr || key == nullptr) {
605 }
606
607#if defined(BOTAN_HAS_SM2)
608 return ffi_guard_thunk(__func__, [=]() -> int {
609 const Botan::Public_Key& pub_key = safe_get(key);
610 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
611
612 if(ec_key == nullptr) {
614 }
615
616 if(ec_key->algo_name() != "SM2") {
618 }
619
620 const std::string ident_str(ident);
621 std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
622
623 const std::vector<uint8_t> za =
624 Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->_public_ec_point());
625
626 return write_vec_output(out, out_len, za);
627 });
628#else
630#endif
631}
virtual std::string algo_name() const =0
const EC_AffinePoint & _public_ec_point() const
Definition ecc_key.cpp:75
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 1306 of file ffi_pkey_algs.cpp.

1306 {
1307#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1308 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1309 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1310 auto pt = ecc->_public_ec_point().serialize_uncompressed();
1311 return invoke_view_callback(view, ctx, pt);
1312 } else {
1314 }
1315 });
1316#else
1317 BOTAN_UNUSED(key, view, ctx);
1319#endif
1320}

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

1041 {
1042#if defined(BOTAN_HAS_KYBER)
1043 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1044 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1045 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1046 } else {
1048 }
1049 });
1050#else
1051 BOTAN_UNUSED(key, ctx, view);
1053#endif
1054}

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

868 {
869#if defined(BOTAN_HAS_X25519)
870 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
871 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
872 const std::vector<uint8_t>& x25519_key = x25519->public_value();
873 if(x25519_key.size() != 32) {
875 }
876 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
877 return BOTAN_FFI_SUCCESS;
878 } else {
880 }
881 });
882#else
883 BOTAN_UNUSED(key, output);
885#endif
886}

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

◆ botan_pubkey_x448_get_pubkey()

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

Definition at line 935 of file ffi_pkey_algs.cpp.

935 {
936#if defined(BOTAN_HAS_X448)
937 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
938 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
939 const std::vector<uint8_t>& x448_key = x448->public_value();
940 Botan::copy_mem(std::span(output, 56), x448_key);
941 return BOTAN_FFI_SUCCESS;
942 } else {
944 }
945 });
946#else
947 BOTAN_UNUSED(key, output);
949#endif
950}
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().