Botan 2.19.2
Crypto and TLS for C&
Functions
ffi_pkey_algs.cpp File Reference
#include <botan/ffi.h>
#include <botan/hash.h>
#include <botan/pem.h>
#include <botan/internal/ffi_util.h>
#include <botan/internal/ffi_pkey.h>
#include <botan/internal/ffi_rng.h>
#include <botan/internal/ffi_mp.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_get_field (botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
 
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_elgamal (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
 
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_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_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_x25519_get_privkey (botan_privkey_t key, uint8_t output[32])
 
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_ed25519_get_pubkey (botan_pubkey_t key, uint8_t output[32])
 
int botan_pubkey_get_field (botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
 
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_elgamal (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
 
int botan_pubkey_load_rsa (botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
 
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_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_x25519_get_pubkey (botan_pubkey_t key, uint8_t output[32])
 

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

939 {
940 return ffi_guard_thunk(__func__, [=]() -> int {
941 Botan::Private_Key& key = safe_get(mce_key_obj);
942
943#if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
944 Botan::McEliece_PrivateKey* mce = dynamic_cast<Botan::McEliece_PrivateKey*>(&key);
945 if(!mce)
947
948 const Botan::secure_vector<uint8_t> pt = mceies_decrypt(*mce, ct, ct_len, ad, ad_len, aead);
949 return write_vec_output(out, out_len, pt);
950#else
952#endif
953 });
954 }
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:83
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:78
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
secure_vector< uint8_t > mceies_decrypt(const McEliece_PrivateKey &privkey, const uint8_t ct[], size_t ct_len, const uint8_t ad[], size_t ad_len, const std::string &algo)
Definition: mceies.cpp:70
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, Botan_FFI::ffi_guard_thunk(), Botan::mceies_decrypt(), Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

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

962 {
963 return ffi_guard_thunk(__func__, [=]() -> int {
964 Botan::Public_Key& key = safe_get(mce_key_obj);
966
967#if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
968 Botan::McEliece_PublicKey* mce = dynamic_cast<Botan::McEliece_PublicKey*>(&key);
969 if(!mce)
971
972 Botan::secure_vector<uint8_t> ct = mceies_encrypt(*mce, pt, pt_len, ad, ad_len, rng, aead);
973 return write_vec_output(out, out_len, ct);
974#else
976#endif
977 });
978 }
secure_vector< uint8_t > mceies_encrypt(const McEliece_PublicKey &pubkey, const uint8_t pt[], size_t pt_len, const uint8_t ad[], size_t ad_len, RandomNumberGenerator &rng, const std::string &algo)
Definition: mceies.cpp:35

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, Botan_FFI::ffi_guard_thunk(), Botan::mceies_encrypt(), Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

◆ botan_privkey_create_dh()

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

Definition at line 580 of file ffi_pkey_algs.cpp.

581 {
582 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
583 }
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition: ffi_pkey.cpp:26

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

384 {
385#if defined(BOTAN_HAS_DSA)
386
387 if ((rng_obj == nullptr) || (key == nullptr))
389
390 if ((pbits % 64) || (qbits % 8) ||
391 (pbits < 1024) || (pbits > 3072) ||
392 (qbits < 160) || (qbits > 256)) {
394 }
395
396 return ffi_guard_thunk(__func__, [=]() -> int {
398 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
399 *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(rng, group));
400 return BOTAN_FFI_SUCCESS;
401 });
402#else
403 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
405#endif
406 }
#define BOTAN_UNUSED(...)
Definition: assert.h:142
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:77
@ BOTAN_FFI_SUCCESS
Definition: ffi.h:63

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

621 {
622 if(param_str == nullptr)
624
625 const std::string params(param_str);
626
627 if(params == "curve25519")
628 return botan_privkey_create(key_obj, "Curve25519", "", rng_obj);
629
630 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
631 }

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

469 {
470 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
471 }

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

519 {
520#if defined(BOTAN_HAS_ELGAMAL)
521
522 if ((rng_obj == nullptr) || (key == nullptr))
524
525 if ((pbits < 1024) || (qbits<160)) {
527 }
528
529 Botan::DL_Group::PrimeType prime_type = ((pbits-1) == qbits)
532
533 return ffi_guard_thunk(__func__, [=]() -> int {
535 Botan::DL_Group group(rng, prime_type, pbits, qbits);
536 *key = new botan_privkey_struct(new Botan::ElGamal_PrivateKey(rng, group));
537 return BOTAN_FFI_SUCCESS;
538 });
539#else
540 BOTAN_UNUSED(key, rng_obj, pbits);
542#endif
543 }

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

929 {
930 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
931 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
932 }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213

References botan_privkey_create(), and Botan::ASN1::to_string().

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

259 {
260 if(n_bits < 1024 || n_bits > 16*1024)
262
263 std::string n_str = std::to_string(n_bits);
264
265 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
266 }

References BOTAN_FFI_ERROR_BAD_PARAMETER, botan_privkey_create(), and Botan::ASN1::to_string().

◆ botan_privkey_dsa_get_x()

int botan_privkey_dsa_get_x ( botan_mp_t  x,
botan_privkey_t  key 
)

Definition at line 443 of file ffi_pkey_algs.cpp.

444 {
445 return botan_privkey_get_field(x, key, "x");
446 }
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 798 of file ffi_pkey_algs.cpp.

800 {
801#if defined(BOTAN_HAS_ED25519)
802 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
803 if(Botan::Ed25519_PrivateKey* ed = dynamic_cast<Botan::Ed25519_PrivateKey*>(&k))
804 {
805 const Botan::secure_vector<uint8_t>& ed_key = ed->get_private_key();
806 if(ed_key.size() != 64)
808 Botan::copy_mem(output, ed_key.data(), ed_key.size());
809 return BOTAN_FFI_SUCCESS;
810 }
811 else
812 {
814 }
815 });
816#else
817 BOTAN_UNUSED(key, output);
819#endif
820 }
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:69
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:133

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, 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 242 of file ffi_pkey_algs.cpp.

245 {
246 if(field_name_cstr == nullptr)
248
249 const std::string field_name(field_name_cstr);
250
251 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
252 safe_get(output) = privkey_get_field(k, field_name);
253 });
254 }

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, 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_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 585 of file ffi_pkey_algs.cpp.

587 {
588#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
589 *key = nullptr;
590 return ffi_guard_thunk(__func__, [=]() -> int {
591 Botan::Null_RNG null_rng;
592 Botan::DL_Group group(safe_get(p), safe_get(g));
593 *key = new botan_privkey_struct(new Botan::DH_PrivateKey(null_rng, group, safe_get(x)));
594 return BOTAN_FFI_SUCCESS;
595 });
596#else
597 BOTAN_UNUSED(key, p, g, x);
599#endif
600 }

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

410 {
411#if defined(BOTAN_HAS_DSA)
412 *key = nullptr;
413
414 return ffi_guard_thunk(__func__, [=]() -> int {
415 Botan::Null_RNG null_rng;
416 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
417 *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(null_rng, group, safe_get(x)));
418 return BOTAN_FFI_SUCCESS;
419 });
420#else
421 BOTAN_UNUSED(key, p, q, g, x);
423#endif
424 }

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

656 {
657#if defined(BOTAN_HAS_ECDH)
658 return ffi_guard_thunk(__func__, [=]() -> int {
659 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
660 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
661 if(rc == BOTAN_FFI_SUCCESS)
662 *key = new botan_privkey_struct(p_key.release());
663 return rc;
664 });
665#else
666 BOTAN_UNUSED(key, scalar, curve_name);
668#endif
669 }

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

499 {
500#if defined(BOTAN_HAS_ECDSA)
501 return ffi_guard_thunk(__func__, [=]() -> int {
502 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
503 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
504 if(rc == BOTAN_FFI_SUCCESS)
505 *key = new botan_privkey_struct(p_key.release());
506 return rc;
507 });
508#else
509 BOTAN_UNUSED(key, scalar, curve_name);
511#endif
512 }

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

768 {
769#if defined(BOTAN_HAS_ED25519)
770 *key = nullptr;
771 return ffi_guard_thunk(__func__, [=]() -> int {
772 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
773 *key = new botan_privkey_struct(new Botan::Ed25519_PrivateKey(privkey_vec));
774 return BOTAN_FFI_SUCCESS;
775 });
776#else
777 BOTAN_UNUSED(key, privkey);
779#endif
780 }

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

563 {
564#if defined(BOTAN_HAS_ELGAMAL)
565 *key = nullptr;
566 return ffi_guard_thunk(__func__, [=]() -> int {
567 Botan::Null_RNG null_rng;
568 Botan::DL_Group group(safe_get(p), safe_get(g));
569 *key = new botan_privkey_struct(new Botan::ElGamal_PrivateKey(null_rng, group, safe_get(x)));
570 return BOTAN_FFI_SUCCESS;
571 });
572#else
573 BOTAN_UNUSED(key, p, g, x);
575#endif
576 }

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

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

270 {
271#if defined(BOTAN_HAS_RSA)
272 *key = nullptr;
273
274 return ffi_guard_thunk(__func__, [=]() -> int {
275 *key = new botan_privkey_struct(new Botan::RSA_PrivateKey(safe_get(rsa_p),
276 safe_get(rsa_q),
277 safe_get(rsa_e)));
278 return BOTAN_FFI_SUCCESS;
279 });
280#else
281 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
283#endif
284 }

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

289 {
290#if defined(BOTAN_HAS_RSA)
291 *key = nullptr;
292
293 Botan::secure_vector<uint8_t> src(bits, bits + len);
294 return ffi_guard_thunk(__func__, [=]() -> int {
296 *key = new botan_privkey_struct(new Botan::RSA_PrivateKey(alg_id, src));
297 return BOTAN_FFI_SUCCESS;
298 });
299#else
300 BOTAN_UNUSED(key, bits, len);
302#endif
303 }

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

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

Definition at line 730 of file ffi_pkey_algs.cpp.

733 {
734#if defined(BOTAN_HAS_SM2)
735 return ffi_guard_thunk(__func__, [=]() -> int {
736 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
737 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
738
739 if(rc == BOTAN_FFI_SUCCESS)
740 *key = new botan_privkey_struct(p_key.release());
741 return rc;
742 });
743#else
744 BOTAN_UNUSED(key, scalar, curve_name);
746#endif
747 }

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

760 {
761 return botan_privkey_load_sm2(key, scalar, curve_name);
762 }
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 848 of file ffi_pkey_algs.cpp.

850 {
851#if defined(BOTAN_HAS_X25519)
852 *key = nullptr;
853 return ffi_guard_thunk(__func__, [=]() -> int {
854 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
855 *key = new botan_privkey_struct(new Botan::X25519_PrivateKey(privkey_vec));
856 return BOTAN_FFI_SUCCESS;
857 });
858#else
859 BOTAN_UNUSED(key, privkey);
861#endif
862 }

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

341 {
342 return botan_privkey_get_field(d, key, "d");
343 }

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

336 {
337 return botan_privkey_get_field(e, key, "e");
338 }

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

331 {
332 return botan_privkey_get_field(n, key, "n");
333 }

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

321 {
322 return botan_privkey_get_field(p, key, "p");
323 }

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

358 {
359#if defined(BOTAN_HAS_RSA)
360 return BOTAN_FFI_DO(Botan::Private_Key, rsa_key, k, {
361 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k))
362 {
364 return write_vec_output(out, out_len, rsa->private_key_bits());
366 return write_str_output(out, out_len, Botan::PEM_Code::encode(rsa->private_key_bits(),
367 "RSA PRIVATE KEY"));
368 else
370 }
371 else
372 {
374 }
375 });
376#else
377 BOTAN_UNUSED(rsa_key, out, out_len);
379#endif
380 }
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:1061
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:1060
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:76
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43
Flags flags(Flag flags)
Definition: p11.h:860
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, BOTAN_UNUSED, Botan::PEM_Code::encode(), Botan::PKCS11::flags(), 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 325 of file ffi_pkey_algs.cpp.

326 {
327 return botan_privkey_get_field(q, key, "q");
328 }

References botan_privkey_get_field().

◆ botan_privkey_x25519_get_privkey()

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

Definition at line 880 of file ffi_pkey_algs.cpp.

882 {
883#if defined(BOTAN_HAS_X25519)
884 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
885 if(Botan::X25519_PrivateKey* x25519 = dynamic_cast<Botan::X25519_PrivateKey*>(&k))
886 {
887 const Botan::secure_vector<uint8_t>& x25519_key = x25519->get_x();
888 if(x25519_key.size() != 32)
890 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
891 return BOTAN_FFI_SUCCESS;
892 }
893 else
894 {
896 }
897 });
898#else
899 BOTAN_UNUSED(key, output);
901#endif
902 }

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, 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 458 of file ffi_pkey_algs.cpp.

459 {
460 return botan_pubkey_get_field(g, key, "g");
461 }
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 448 of file ffi_pkey_algs.cpp.

449 {
450 return botan_pubkey_get_field(p, key, "p");
451 }

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

454 {
455 return botan_pubkey_get_field(q, key, "q");
456 }

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

464 {
465 return botan_pubkey_get_field(y, key, "y");
466 }

References botan_pubkey_get_field().

◆ botan_pubkey_ed25519_get_pubkey()

int botan_pubkey_ed25519_get_pubkey ( botan_pubkey_t  key,
uint8_t  output[32] 
)

Definition at line 822 of file ffi_pkey_algs.cpp.

824 {
825#if defined(BOTAN_HAS_ED25519)
826 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
827 if(Botan::Ed25519_PublicKey* ed = dynamic_cast<Botan::Ed25519_PublicKey*>(&k))
828 {
829 const std::vector<uint8_t>& ed_key = ed->get_public_key();
830 if(ed_key.size() != 32)
832 Botan::copy_mem(output, ed_key.data(), ed_key.size());
833 return BOTAN_FFI_SUCCESS;
834 }
835 else
836 {
838 }
839 });
840#else
841 BOTAN_UNUSED(key, output);
843#endif
844 }

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, 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 228 of file ffi_pkey_algs.cpp.

231 {
232 if(field_name_cstr == nullptr)
234
235 const std::string field_name(field_name_cstr);
236
237 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
238 safe_get(output) = pubkey_get_field(k, field_name);
239 });
240 }

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, 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_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 602 of file ffi_pkey_algs.cpp.

604 {
605#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
606 *key = nullptr;
607 return ffi_guard_thunk(__func__, [=]() -> int {
608 Botan::DL_Group group(safe_get(p), safe_get(g));
609 *key = new botan_pubkey_struct(new Botan::DH_PublicKey(group, safe_get(y)));
610 return BOTAN_FFI_SUCCESS;
611 });
612#else
613 BOTAN_UNUSED(key, p, g, y);
615#endif
616 }

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

428 {
429#if defined(BOTAN_HAS_DSA)
430 *key = nullptr;
431
432 return ffi_guard_thunk(__func__, [=]() -> int {
433 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
434 *key = new botan_pubkey_struct(new Botan::DSA_PublicKey(group, safe_get(y)));
435 return BOTAN_FFI_SUCCESS;
436 });
437#else
438 BOTAN_UNUSED(key, p, q, g, y);
440#endif
441 }

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

637 {
638#if defined(BOTAN_HAS_ECDH)
639 return ffi_guard_thunk(__func__, [=]() -> int {
640 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
641 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
642
643 if(rc == BOTAN_FFI_SUCCESS)
644 *key = new botan_pubkey_struct(p_key.release());
645 return rc;
646 });
647#else
648 BOTAN_UNUSED(key, public_x, public_y, curve_name);
650#endif
651 }

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

479 {
480#if defined(BOTAN_HAS_ECDSA)
481 return ffi_guard_thunk(__func__, [=]() -> int {
482 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
483
484 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
485 if(rc == BOTAN_FFI_SUCCESS)
486 *key = new botan_pubkey_struct(p_key.release());
487
488 return rc;
489 });
490#else
491 BOTAN_UNUSED(key, public_x, public_y, curve_name);
493#endif
494 }

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

784 {
785#if defined(BOTAN_HAS_ED25519)
786 *key = nullptr;
787 return ffi_guard_thunk(__func__, [=]() -> int {
788 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
789 *key = new botan_pubkey_struct(new Botan::Ed25519_PublicKey(pubkey_vec));
790 return BOTAN_FFI_SUCCESS;
791 });
792#else
793 BOTAN_UNUSED(key, pubkey);
795#endif
796 }

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

547 {
548#if defined(BOTAN_HAS_ELGAMAL)
549 *key = nullptr;
550 return ffi_guard_thunk(__func__, [=]() -> int {
551 Botan::DL_Group group(safe_get(p), safe_get(g));
552 *key = new botan_pubkey_struct(new Botan::ElGamal_PublicKey(group, safe_get(y)));
553 return BOTAN_FFI_SUCCESS;
554 });
555#else
556 BOTAN_UNUSED(key, p, g, y);
558#endif
559 }

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

◆ botan_pubkey_load_rsa()

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

Definition at line 305 of file ffi_pkey_algs.cpp.

307 {
308#if defined(BOTAN_HAS_RSA)
309 *key = nullptr;
310 return ffi_guard_thunk(__func__, [=]() -> int {
311 *key = new botan_pubkey_struct(new Botan::RSA_PublicKey(safe_get(n), safe_get(e)));
312 return BOTAN_FFI_SUCCESS;
313 });
314#else
315 BOTAN_UNUSED(key, n, e);
317#endif
318 }

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

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

713 {
714#if defined(BOTAN_HAS_SM2)
715 return ffi_guard_thunk(__func__, [=]() -> int {
716 std::unique_ptr<Botan::SM2_PublicKey> p_key;
717 if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
718 {
719 *key = new botan_pubkey_struct(p_key.release());
720 return BOTAN_FFI_SUCCESS;
721 }
723 });
724#else
725 BOTAN_UNUSED(key, public_x, public_y, curve_name);
727#endif
728 }
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:90

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

753 {
754 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
755 }
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 864 of file ffi_pkey_algs.cpp.

866 {
867#if defined(BOTAN_HAS_X25519)
868 *key = nullptr;
869 return ffi_guard_thunk(__func__, [=]() -> int {
870 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
871 *key = new botan_pubkey_struct(new Botan::X25519_PublicKey(pubkey_vec));
872 return BOTAN_FFI_SUCCESS;
873 });
874#else
875 BOTAN_UNUSED(key, pubkey);
877#endif
878 }

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

346 {
347 return botan_pubkey_get_field(e, key, "e");
348 }

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

351 {
352 return botan_pubkey_get_field(n, key, "n");
353 }

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

678 {
679 if(out == nullptr || out_len == nullptr)
681 if(ident == nullptr || hash_algo == nullptr || key == nullptr)
683
684#if defined(BOTAN_HAS_SM2)
685 return ffi_guard_thunk(__func__, [=]() -> int {
686 const Botan::Public_Key& pub_key = safe_get(key);
687 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
688
689 if(ec_key == nullptr)
691
692 if(ec_key->algo_name() != "SM2")
694
695 const std::string ident_str(ident);
696 std::unique_ptr<Botan::HashFunction> hash =
698
699 const std::vector<uint8_t> za =
700 Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->public_point());
701
702 return write_vec_output(out, out_len, za);
703 });
704#else
706#endif
707 }
const EC_Group & domain() const
Definition: ecc_key.h:72
const PointGFp & public_point() const
Definition: ecc_key.h:57
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:329
virtual std::string algo_name() const =0
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, const std::string &user_id, const EC_Group &domain, const PointGFp &pubkey)
Definition: sm2.cpp:52
MechanismType hash
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22

References Botan::Public_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(), hash, hash_algo, Botan::EC_PublicKey::public_point(), Botan_FFI::safe_get(), Botan::sm2_compute_za(), and Botan_FFI::write_vec_output().

◆ botan_pubkey_x25519_get_pubkey()

int botan_pubkey_x25519_get_pubkey ( botan_pubkey_t  key,
uint8_t  output[32] 
)

Definition at line 904 of file ffi_pkey_algs.cpp.

906 {
907#if defined(BOTAN_HAS_X25519)
908 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
909 if(Botan::X25519_PublicKey* x25519 = dynamic_cast<Botan::X25519_PublicKey*>(&k))
910 {
911 const std::vector<uint8_t>& x25519_key = x25519->public_value();
912 if(x25519_key.size() != 32)
914 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
915 return BOTAN_FFI_SUCCESS;
916 }
917 else
918 {
920 }
921 });
922#else
923 BOTAN_UNUSED(key, output);
925#endif
926 }

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