Botan 3.0.0
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_view_ec_public_point (const 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])
 

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

904 {
905 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
907 }
#define BOTAN_UNUSED(...)
Definition: assert.h:141
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:91

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

915 {
916 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
918 }

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

518 {
519 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
520 }
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 316 of file ffi_pkey_algs.cpp.

317 {
318#if defined(BOTAN_HAS_DSA)
319
320 if ((rng_obj == nullptr) || (key == nullptr))
322
323 if ((pbits % 64) || (qbits % 8) ||
324 (pbits < 1024) || (pbits > 3072) ||
325 (qbits < 160) || (qbits > 256)) {
327 }
328
329 return ffi_guard_thunk(__func__, [=]() -> int {
331 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
332 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
333 *key = new botan_privkey_struct(std::move(dsa));
334 return BOTAN_FFI_SUCCESS;
335 });
336#else
337 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
339#endif
340 }
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:85
@ BOTAN_FFI_SUCCESS
Definition: ffi.h:70
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:86
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:69
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition: ffi.cpp:120

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

559 {
560 if(param_str == nullptr)
562
563 const std::string params(param_str);
564
565 if(params == "curve25519")
566 return botan_privkey_create(key_obj, "Curve25519", "", rng_obj);
567
568 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
569 }

References BOTAN_FFI_ERROR_NULL_POINTER, and botan_privkey_create().

◆ botan_privkey_create_ecdsa()

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

Definition at line 403 of file ffi_pkey_algs.cpp.

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

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

454 {
455#if defined(BOTAN_HAS_ELGAMAL)
456
457 if ((rng_obj == nullptr) || (key == nullptr))
459
460 if ((pbits < 1024) || (qbits<160)) {
462 }
463
464 Botan::DL_Group::PrimeType prime_type = ((pbits-1) == qbits)
467
468 return ffi_guard_thunk(__func__, [=]() -> int {
470 Botan::DL_Group group(rng, prime_type, pbits, qbits);
471 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
472 *key = new botan_privkey_struct(std::move(elg));
473 return BOTAN_FFI_SUCCESS;
474 });
475#else
476 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
478#endif
479 }

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

894 {
895 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
896 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
897 }

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

188 {
189 if(n_bits < 1024 || n_bits > 16*1024)
191
192 std::string n_str = std::to_string(n_bits);
193
194 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
195 }

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

379 {
380 return botan_privkey_get_field(x, key, "x");
381 }
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 738 of file ffi_pkey_algs.cpp.

740 {
741#if defined(BOTAN_HAS_ED25519)
742 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
743 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k))
744 {
745 const auto ed_key = ed->raw_private_key_bits();
746 if(ed_key.size() != 64)
748 Botan::copy_mem(output, ed_key.data(), ed_key.size());
749 return BOTAN_FFI_SUCCESS;
750 }
751 else
752 {
754 }
755 });
756#else
757 BOTAN_UNUSED(key, output);
759#endif
760 }
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:76
#define BOTAN_FFI_VISIT(obj, lambda)
Definition: ffi_util.h:126
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:126

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

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

Definition at line 171 of file ffi_pkey_algs.cpp.

174 {
175 if(field_name_cstr == nullptr)
177
178 const std::string field_name(field_name_cstr);
179
180 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
181 safe_get(output) = privkey_get_field(k, field_name);
182 });
183 }

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

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

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

344 {
345#if defined(BOTAN_HAS_DSA)
346 *key = nullptr;
347
348 return ffi_guard_thunk(__func__, [=]() -> int {
349 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
350 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(group, safe_get(x));
351 *key = new botan_privkey_struct(std::move(dsa));
352 return BOTAN_FFI_SUCCESS;
353 });
354#else
355 BOTAN_UNUSED(key, p, q, g, x);
357#endif
358 }

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

594 {
595#if defined(BOTAN_HAS_ECDH)
596 return ffi_guard_thunk(__func__, [=]() -> int {
597 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
598 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
599 if(rc == BOTAN_FFI_SUCCESS)
600 *key = new botan_privkey_struct(std::move(p_key));
601 return rc;
602 });
603#else
604 BOTAN_UNUSED(key, scalar, curve_name);
606#endif
607 }

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

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

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

706 {
707#if defined(BOTAN_HAS_ED25519)
708 *key = nullptr;
709 return ffi_guard_thunk(__func__, [=]() -> int {
710 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
711 auto ed25519 = std::make_unique<Botan::Ed25519_PrivateKey>(privkey_vec);
712 *key = new botan_privkey_struct(std::move(ed25519));
713 return BOTAN_FFI_SUCCESS;
714 });
715#else
716 BOTAN_UNUSED(key, privkey);
718#endif
719 }
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64

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

500 {
501#if defined(BOTAN_HAS_ELGAMAL)
502 *key = nullptr;
503 return ffi_guard_thunk(__func__, [=]() -> int {
504 Botan::DL_Group group(safe_get(p), safe_get(g));
505 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(group, safe_get(x));
506 *key = new botan_privkey_struct(std::move(elg));
507 return BOTAN_FFI_SUCCESS;
508 });
509#else
510 BOTAN_UNUSED(key, p, g, x);
512#endif
513 }

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

199 {
200#if defined(BOTAN_HAS_RSA)
201 *key = nullptr;
202
203 return ffi_guard_thunk(__func__, [=]() -> int {
204
205 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p),
206 safe_get(rsa_q),
207 safe_get(rsa_e));
208 *key = new botan_privkey_struct(std::move(rsa));
209 return BOTAN_FFI_SUCCESS;
210 });
211#else
212 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
214#endif
215 }

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

220 {
221#if defined(BOTAN_HAS_RSA)
222 *key = nullptr;
223
224 Botan::secure_vector<uint8_t> src(bits, bits + len);
225 return ffi_guard_thunk(__func__, [=]() -> int {
227 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, src);
228 *key = new botan_privkey_struct(std::move(rsa));
229 return BOTAN_FFI_SUCCESS;
230 });
231#else
232 BOTAN_UNUSED(key, bits, len);
234#endif
235 }

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

671 {
672#if defined(BOTAN_HAS_SM2)
673 return ffi_guard_thunk(__func__, [=]() -> int {
674 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
675 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
676
677 if(rc == BOTAN_FFI_SUCCESS)
678 *key = new botan_privkey_struct(std::move(p_key));
679 return rc;
680 });
681#else
682 BOTAN_UNUSED(key, scalar, curve_name);
684#endif
685 }

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

698 {
699 return botan_privkey_load_sm2(key, scalar, curve_name);
700 }
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 788 of file ffi_pkey_algs.cpp.

790 {
791#if defined(BOTAN_HAS_X25519)
792 *key = nullptr;
793 return ffi_guard_thunk(__func__, [=]() -> int {
794 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
795 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(privkey_vec);
796 *key = new botan_privkey_struct(std::move(x25519));
797 return BOTAN_FFI_SUCCESS;
798 });
799#else
800 BOTAN_UNUSED(key, privkey);
802#endif
803 }

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

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

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

269 {
270 return botan_privkey_get_field(e, key, "e");
271 }

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

264 {
265 return botan_privkey_get_field(n, key, "n");
266 }

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

254 {
255 return botan_privkey_get_field(p, key, "p");
256 }

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

291 {
292#if defined(BOTAN_HAS_RSA)
293 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
294 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k))
295 {
297 return write_vec_output(out, out_len, rsa->private_key_bits());
298 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
299 return write_str_output(out, out_len, Botan::PEM_Code::encode(rsa->private_key_bits(),
300 "RSA PRIVATE KEY"));
301 else
303 }
304 else
305 {
307 }
308 });
309#else
310 BOTAN_UNUSED(rsa_key, out, out_len, flags);
312#endif
313 }
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:1123
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:1122
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:84
std::string encode(const uint8_t der[], size_t length, std::string_view label, size_t width)
Definition: pem.cpp:42
int write_str_output(uint8_t out[], size_t *out_len, std::string_view str)
Definition: ffi_util.h:219
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:214

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

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

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

824 {
825#if defined(BOTAN_HAS_X25519)
826 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
827 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k))
828 {
829 const auto x25519_key = x25519->raw_private_key_bits();
830 if(x25519_key.size() != 32)
832 Botan::copy_mem(output, x25519_key.data(), x25519_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_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_dsa_get_g()

int botan_pubkey_dsa_get_g ( botan_mp_t  g,
botan_pubkey_t  key 
)

Definition at line 393 of file ffi_pkey_algs.cpp.

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

384 {
385 return botan_pubkey_get_field(p, key, "p");
386 }

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

389 {
390 return botan_pubkey_get_field(q, key, "q");
391 }

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

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

References botan_pubkey_get_field(), and y.

◆ botan_pubkey_ed25519_get_pubkey()

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

Definition at line 762 of file ffi_pkey_algs.cpp.

764 {
765#if defined(BOTAN_HAS_ED25519)
766 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
767 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k))
768 {
769 const std::vector<uint8_t>& ed_key = ed->get_public_key();
770 if(ed_key.size() != 32)
772 Botan::copy_mem(output, ed_key.data(), ed_key.size());
773 return BOTAN_FFI_SUCCESS;
774 }
775 else
776 {
778 }
779 });
780#else
781 BOTAN_UNUSED(key, output);
783#endif
784 }

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

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

Definition at line 157 of file ffi_pkey_algs.cpp.

160 {
161 if(field_name_cstr == nullptr)
163
164 const std::string field_name(field_name_cstr);
165
166 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
167 safe_get(output) = pubkey_get_field(k, field_name);
168 });
169 }

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

541 {
542#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
543 *key = nullptr;
544 return ffi_guard_thunk(__func__, [=]() -> int {
545 Botan::DL_Group group(safe_get(p), safe_get(g));
546 auto dh = std::make_unique<Botan::DH_PublicKey>(group, safe_get(y));
547 *key = new botan_pubkey_struct(std::move(dh));
548 return BOTAN_FFI_SUCCESS;
549 });
550#else
551 BOTAN_UNUSED(key, p, g, y);
553#endif
554 }

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

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

362 {
363#if defined(BOTAN_HAS_DSA)
364 *key = nullptr;
365
366 return ffi_guard_thunk(__func__, [=]() -> int {
367 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
368 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
369 *key = new botan_pubkey_struct(std::move(dsa));
370 return BOTAN_FFI_SUCCESS;
371 });
372#else
373 BOTAN_UNUSED(key, p, q, g, y);
375#endif
376 }

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

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

575 {
576#if defined(BOTAN_HAS_ECDH)
577 return ffi_guard_thunk(__func__, [=]() -> int {
578 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
579 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
580
581 if(rc == BOTAN_FFI_SUCCESS)
582 *key = new botan_pubkey_struct(std::move(p_key));
583 return rc;
584 });
585#else
586 BOTAN_UNUSED(key, public_x, public_y, curve_name);
588#endif
589 }

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

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

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

723 {
724#if defined(BOTAN_HAS_ED25519)
725 *key = nullptr;
726 return ffi_guard_thunk(__func__, [=]() -> int {
727 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
728 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
729 *key = new botan_pubkey_struct(std::move(ed25519));
730 return BOTAN_FFI_SUCCESS;
731 });
732#else
733 BOTAN_UNUSED(key, pubkey);
735#endif
736 }

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

483 {
484#if defined(BOTAN_HAS_ELGAMAL)
485 *key = nullptr;
486 return ffi_guard_thunk(__func__, [=]() -> int {
487 Botan::DL_Group group(safe_get(p), safe_get(g));
488 auto elg = std::make_unique<Botan::ElGamal_PublicKey>(group, safe_get(y));
489 *key = new botan_pubkey_struct(std::move(elg));
490 return BOTAN_FFI_SUCCESS;
491 });
492#else
493 BOTAN_UNUSED(key, p, g, y);
495#endif
496 }

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

◆ botan_pubkey_load_rsa()

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

Definition at line 237 of file ffi_pkey_algs.cpp.

239 {
240#if defined(BOTAN_HAS_RSA)
241 *key = nullptr;
242 return ffi_guard_thunk(__func__, [=]() -> int {
243 auto rsa = std::make_unique<Botan::RSA_PublicKey>(safe_get(n), safe_get(e));
244 *key = new botan_pubkey_struct(std::move(rsa));
245 return BOTAN_FFI_SUCCESS;
246 });
247#else
248 BOTAN_UNUSED(key, n, e);
250#endif
251 }

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

651 {
652#if defined(BOTAN_HAS_SM2)
653 return ffi_guard_thunk(__func__, [=]() -> int {
654 std::unique_ptr<Botan::SM2_PublicKey> p_key;
655 if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
656 {
657 *key = new botan_pubkey_struct(std::move(p_key));
658 return BOTAN_FFI_SUCCESS;
659 }
661 });
662#else
663 BOTAN_UNUSED(key, public_x, public_y, curve_name);
665#endif
666 }
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:98

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

691 {
692 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
693 }
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 805 of file ffi_pkey_algs.cpp.

807 {
808#if defined(BOTAN_HAS_X25519)
809 *key = nullptr;
810 return ffi_guard_thunk(__func__, [=]() -> int {
811 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
812 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(pubkey_vec);
813 *key = new botan_pubkey_struct(std::move(x25519));
814 return BOTAN_FFI_SUCCESS;
815 });
816#else
817 BOTAN_UNUSED(key, pubkey);
819#endif
820 }

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 278 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.

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

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

616 {
617 if(out == nullptr || out_len == nullptr)
619 if(ident == nullptr || hash_algo == nullptr || key == nullptr)
621
622#if defined(BOTAN_HAS_SM2)
623 return ffi_guard_thunk(__func__, [=]() -> int {
624 const Botan::Public_Key& pub_key = safe_get(key);
625 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
626
627 if(ec_key == nullptr)
629
630 if(ec_key->algo_name() != "SM2")
632
633 const std::string ident_str(ident);
634 std::unique_ptr<Botan::HashFunction> hash =
636
637 const std::vector<uint8_t> za =
638 Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->public_point());
639
640 return write_vec_output(out, out_len, za);
641 });
642#else
644#endif
645 }
virtual std::string algo_name() const =0
const EC_Group & domain() const
Definition: ecc_key.h:56
const EC_Point & public_point() const
Definition: ecc_key.h:41
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition: hash.cpp:320
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, std::string_view user_id, const EC_Group &domain, const EC_Point &pubkey)
Definition: sm2.cpp:57

References 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::EC_PublicKey::public_point(), 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 ( const 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 870 of file ffi_pkey_algs.cpp.

874 {
875#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
876 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
877 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k))
878 {
879 auto pt = ecc->public_point().encode(Botan::EC_Point_Format::Uncompressed);
880 return invoke_view_callback(view, ctx, pt);
881 }
882 else
883 {
885 }
886 });
887#else
888 BOTAN_UNUSED(key, view, ctx);
890#endif
891 }
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:148

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

◆ botan_pubkey_x25519_get_pubkey()

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

Definition at line 846 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_PublicKey*>(&k))
852 {
853 const std::vector<uint8_t>& x25519_key = x25519->public_value();
854 if(x25519_key.size() != 32)
856 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
857 return BOTAN_FFI_SUCCESS;
858 }
859 else
860 {
862 }
863 });
864#else
865 BOTAN_UNUSED(key, output);
867#endif
868 }
BOTAN_DIAGNOSTIC_POP typedef Curve25519_PublicKey X25519_PublicKey
Definition: curve25519.h:117

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, Botan::copy_mem(), and Botan::X25519_PublicKey.