Botan  2.4.0
Crypto and TLS for C++11
Functions
ffi_pkey_algs.cpp File Reference
#include <botan/ffi.h>
#include <botan/hash.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_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_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_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_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_q (botan_mp_t q, botan_privkey_t key)
 
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_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)
 

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

References BOTAN_CURRENT_FUNCTION, 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().

782  {
783  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
784  Botan::Private_Key& key = safe_get(mce_key_obj);
785 
786 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
787  Botan::McEliece_PrivateKey* mce = dynamic_cast<Botan::McEliece_PrivateKey*>(&key);
788  if(!mce)
790 
791  const Botan::secure_vector<uint8_t> pt = mceies_decrypt(*mce, ct, ct_len, ad, ad_len, aead);
792  return write_vec_output(out, out_len, pt);
793 #else
795 #endif
796  });
797  }
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:71
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

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

References BOTAN_CURRENT_FUNCTION, 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().

805  {
806  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
807  Botan::Public_Key& key = safe_get(mce_key_obj);
808  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
809 
810 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
811  Botan::McEliece_PublicKey* mce = dynamic_cast<Botan::McEliece_PublicKey*>(&key);
812  if(!mce)
814 
815  Botan::secure_vector<uint8_t> ct = mceies_encrypt(*mce, pt, pt_len, ad, ad_len, rng, aead);
816  return write_vec_output(out, out_len, ct);
817 #else
819 #endif
820  });
821  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
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:34
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

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

References botan_privkey_create().

481  {
482  return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
483  }
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

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

References BOTAN_FFI_ERROR_NULL_POINTER, and botan_privkey_create().

521  {
522  if(param_str == nullptr)
524 
525  const std::string params(param_str);
526 
527  if(params == "curve25519")
528  return botan_privkey_create(key_obj, "Curve25519", "", rng_obj);
529 
530  return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
531  }
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
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

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

References botan_privkey_create().

398  {
399  return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
400  }
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

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

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

772  {
773  const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
774  return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
775  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108
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

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

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

258  {
259  if(n_bits < 1024 || n_bits > 16*1024)
261 
262  std::string n_str = std::to_string(n_bits);
263 
264  return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
265  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108
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
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

◆ botan_privkey_dsa_get_x()

int botan_privkey_dsa_get_x ( botan_mp_t  x,
botan_privkey_t  key 
)

Definition at line 372 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

373  {
374  return botan_privkey_get_field(x, key, "x");
375  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_ed25519_get_privkey()

int botan_privkey_ed25519_get_privkey ( botan_privkey_t  key,
uint8_t  output[64] 
)

Definition at line 723 of file ffi_pkey_algs.cpp.

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

725  {
726 #if defined(BOTAN_HAS_ED25519)
727  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
728  if(Botan::Ed25519_PrivateKey* ed = dynamic_cast<Botan::Ed25519_PrivateKey*>(&k))
729  {
730  const Botan::secure_vector<uint8_t>& ed_key = ed->get_private_key();
731  if(ed_key.size() != 64)
733  Botan::copy_mem(output, ed_key.data(), ed_key.size());
734  return BOTAN_FFI_SUCCESS;
735  }
736  else
737  {
739  }
740  });
741 #else
742  BOTAN_UNUSED(key, output);
744 #endif
745  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:97
#define BOTAN_UNUSED(...)
Definition: assert.h:106
#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:144
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

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

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

244  {
245  if(field_name_cstr == nullptr)
247 
248  const std::string field_name(field_name_cstr);
249 
250  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
251  safe_get(output) = privkey_get_field(k, field_name);
252  });
253  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

487  {
488 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
489  *key = nullptr;
490  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
491  Botan::Null_RNG null_rng;
492  Botan::DL_Group group(safe_get(p), safe_get(g));
493  *key = new botan_privkey_struct(new Botan::DH_PrivateKey(null_rng, group, safe_get(x)));
494  return BOTAN_FFI_SUCCESS;
495  });
496 #else
497  BOTAN_UNUSED(key, p, g, x);
499 #endif
500  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

339  {
340 #if defined(BOTAN_HAS_DSA)
341  *key = nullptr;
342 
343  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
344  Botan::Null_RNG null_rng;
345  Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
346  *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(null_rng, group, safe_get(x)));
347  return BOTAN_FFI_SUCCESS;
348  });
349 #else
350  BOTAN_UNUSED(key, p, q, g, x);
352 #endif
353  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

556  {
557 #if defined(BOTAN_HAS_ECDH)
558  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
559  std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
560  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
561  if(rc == BOTAN_FFI_SUCCESS)
562  *key = new botan_privkey_struct(p_key.release());
563  return rc;
564  });
565 #else
566  BOTAN_UNUSED(key, scalar, curve_name);
568 #endif
569  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

428  {
429 #if defined(BOTAN_HAS_ECDSA)
430  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
431  std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
432  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
433  if(rc == BOTAN_FFI_SUCCESS)
434  *key = new botan_privkey_struct(p_key.release());
435  return rc;
436  });
437 #else
438  BOTAN_UNUSED(key, scalar, curve_name);
440 #endif
441  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_load_ed25519()

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

Definition at line 691 of file ffi_pkey_algs.cpp.

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

693  {
694 #if defined(BOTAN_HAS_ED25519)
695  *key = nullptr;
696  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
697  const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
698  *key = new botan_privkey_struct(new Botan::Ed25519_PrivateKey(privkey_vec));
699  return BOTAN_FFI_SUCCESS;
700  });
701 #else
702  BOTAN_UNUSED(key, privkey);
704 #endif
705  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88

◆ botan_privkey_load_elgamal()

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

Definition at line 461 of file ffi_pkey_algs.cpp.

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

463  {
464 #if defined(BOTAN_HAS_ELGAMAL)
465  *key = nullptr;
466  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
467  Botan::Null_RNG null_rng;
468  Botan::DL_Group group(safe_get(p), safe_get(g));
469  *key = new botan_privkey_struct(new Botan::ElGamal_PrivateKey(null_rng, group, safe_get(x)));
470  return BOTAN_FFI_SUCCESS;
471  });
472 #else
473  BOTAN_UNUSED(key, p, g, x);
475 #endif
476  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

269  {
270 #if defined(BOTAN_HAS_RSA)
271  *key = nullptr;
272 
273  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
274  *key = new botan_privkey_struct(new Botan::RSA_PrivateKey(safe_get(rsa_p),
275  safe_get(rsa_q),
276  safe_get(rsa_e)));
277  return BOTAN_FFI_SUCCESS;
278  });
279 #else
280  BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
282 #endif
283  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

633  {
634 #if defined(BOTAN_HAS_SM2)
635  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
636  std::unique_ptr<Botan::SM2_Signature_PrivateKey> p_key;
637  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
638 
639  if(rc == BOTAN_FFI_SUCCESS)
640  *key = new botan_privkey_struct(p_key.release());
641  return rc;
642  });
643 #else
644  BOTAN_UNUSED(key, scalar, curve_name);
646 #endif
647  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

673  {
674 #if defined(BOTAN_HAS_SM2)
675  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
676  std::unique_ptr<Botan::SM2_Encryption_PrivateKey> p_key;
677  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
678 
679  if(rc == BOTAN_FFI_SUCCESS)
680  *key = new botan_privkey_struct(p_key.release());
681  return rc;
682  });
683 #else
684  BOTAN_UNUSED(key, scalar, curve_name);
686 #endif
687  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_rsa_get_d()

int botan_privkey_rsa_get_d ( botan_mp_t  d,
botan_privkey_t  key 
)

Definition at line 320 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

321  {
322  return botan_privkey_get_field(d, key, "d");
323  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_rsa_get_e()

int botan_privkey_rsa_get_e ( botan_mp_t  e,
botan_privkey_t  key 
)

Definition at line 315 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

316  {
317  return botan_privkey_get_field(e, key, "e");
318  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_rsa_get_n()

int botan_privkey_rsa_get_n ( botan_mp_t  n,
botan_privkey_t  key 
)

Definition at line 310 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

311  {
312  return botan_privkey_get_field(n, key, "n");
313  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_rsa_get_p()

int botan_privkey_rsa_get_p ( botan_mp_t  p,
botan_privkey_t  key 
)

Definition at line 300 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

301  {
302  return botan_privkey_get_field(p, key, "p");
303  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_rsa_get_q()

int botan_privkey_rsa_get_q ( botan_mp_t  q,
botan_privkey_t  key 
)

Definition at line 305 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

306  {
307  return botan_privkey_get_field(q, key, "q");
308  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_pubkey_dsa_get_g()

int botan_pubkey_dsa_get_g ( botan_mp_t  g,
botan_pubkey_t  key 
)

Definition at line 387 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

388  {
389  return botan_pubkey_get_field(g, key, "g");
390  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_dsa_get_p()

int botan_pubkey_dsa_get_p ( botan_mp_t  p,
botan_pubkey_t  key 
)

Definition at line 377 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

378  {
379  return botan_pubkey_get_field(p, key, "p");
380  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_dsa_get_q()

int botan_pubkey_dsa_get_q ( botan_mp_t  q,
botan_pubkey_t  key 
)

Definition at line 382 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

383  {
384  return botan_pubkey_get_field(q, key, "q");
385  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_dsa_get_y()

int botan_pubkey_dsa_get_y ( botan_mp_t  y,
botan_pubkey_t  key 
)

Definition at line 392 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

393  {
394  return botan_pubkey_get_field(y, key, "y");
395  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_ed25519_get_pubkey()

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

Definition at line 747 of file ffi_pkey_algs.cpp.

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

749  {
750 #if defined(BOTAN_HAS_ED25519)
751  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
752  if(Botan::Ed25519_PublicKey* ed = dynamic_cast<Botan::Ed25519_PublicKey*>(&k))
753  {
754  const std::vector<uint8_t>& ed_key = ed->get_public_key();
755  if(ed_key.size() != 32)
757  Botan::copy_mem(output, ed_key.data(), ed_key.size());
758  return BOTAN_FFI_SUCCESS;
759  }
760  else
761  {
763  }
764  });
765 #else
766  BOTAN_UNUSED(key, output);
768 #endif
769  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:97
#define BOTAN_UNUSED(...)
Definition: assert.h:106
#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:144
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

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

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

230  {
231  if(field_name_cstr == nullptr)
233 
234  const std::string field_name(field_name_cstr);
235 
236  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
237  safe_get(output) = pubkey_get_field(k, field_name);
238  });
239  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_load_dh()

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

Definition at line 502 of file ffi_pkey_algs.cpp.

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

504  {
505 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
506  *key = nullptr;
507  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
508  Botan::DL_Group group(safe_get(p), safe_get(g));
509  *key = new botan_pubkey_struct(new Botan::DH_PublicKey(group, safe_get(y)));
510  return BOTAN_FFI_SUCCESS;
511  });
512 #else
513  BOTAN_UNUSED(key, p, g, y);
515 #endif
516  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

357  {
358 #if defined(BOTAN_HAS_DSA)
359  *key = nullptr;
360 
361  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
362  Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
363  *key = new botan_pubkey_struct(new Botan::DSA_PublicKey(group, safe_get(y)));
364  return BOTAN_FFI_SUCCESS;
365  });
366 #else
367  BOTAN_UNUSED(key, p, q, g, y);
369 #endif
370  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

537  {
538 #if defined(BOTAN_HAS_ECDH)
539  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
540  std::unique_ptr<Botan::ECDH_PublicKey> p_key;
541  int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
542 
543  if(rc == BOTAN_FFI_SUCCESS)
544  *key = new botan_pubkey_struct(p_key.release());
545  return rc;
546  });
547 #else
548  BOTAN_UNUSED(key, public_x, public_y, curve_name);
550 #endif
551  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

408  {
409 #if defined(BOTAN_HAS_ECDSA)
410  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
411  std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
412 
413  int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
414  if(rc == BOTAN_FFI_SUCCESS)
415  *key = new botan_pubkey_struct(p_key.release());
416 
417  return rc;
418  });
419 #else
420  BOTAN_UNUSED(key, public_x, public_y, curve_name);
422 #endif
423  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_ed25519()

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

Definition at line 707 of file ffi_pkey_algs.cpp.

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

709  {
710 #if defined(BOTAN_HAS_ED25519)
711  *key = nullptr;
712  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
713  const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
714  *key = new botan_pubkey_struct(new Botan::Ed25519_PublicKey(pubkey_vec));
715  return BOTAN_FFI_SUCCESS;
716  });
717 #else
718  BOTAN_UNUSED(key, pubkey);
720 #endif
721  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_elgamal()

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

Definition at line 445 of file ffi_pkey_algs.cpp.

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

447  {
448 #if defined(BOTAN_HAS_ELGAMAL)
449  *key = nullptr;
450  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
451  Botan::DL_Group group(safe_get(p), safe_get(g));
452  *key = new botan_pubkey_struct(new Botan::ElGamal_PublicKey(group, safe_get(y)));
453  return BOTAN_FFI_SUCCESS;
454  });
455 #else
456  BOTAN_UNUSED(key, p, g, y);
458 #endif
459  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_rsa()

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

Definition at line 285 of file ffi_pkey_algs.cpp.

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

287  {
288 #if defined(BOTAN_HAS_RSA)
289  *key = nullptr;
290  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
291  *key = new botan_pubkey_struct(new Botan::RSA_PublicKey(safe_get(n), safe_get(e)));
292  return BOTAN_FFI_SUCCESS;
293  });
294 #else
295  BOTAN_UNUSED(key, n, e);
297 #endif
298  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

References BOTAN_CURRENT_FUNCTION, 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().

613  {
614 #if defined(BOTAN_HAS_SM2)
615  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
616  std::unique_ptr<Botan::SM2_Signature_PublicKey> p_key;
617  if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
618  {
619  *key = new botan_pubkey_struct(p_key.release());
620  return BOTAN_FFI_SUCCESS;
621  }
623  });
624 #else
625  BOTAN_UNUSED(key, public_x, public_y, curve_name);
627 #endif
628  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:152
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

References BOTAN_CURRENT_FUNCTION, 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().

653  {
654 #if defined(BOTAN_HAS_SM2)
655  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
656  std::unique_ptr<Botan::SM2_Encryption_PublicKey> p_key;
657  if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
658  {
659  *key = new botan_pubkey_struct(p_key.release());
660  return BOTAN_FFI_SUCCESS;
661  }
663  });
664 #else
665  BOTAN_UNUSED(key, public_x, public_y, curve_name);
667 #endif
668  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:152
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_rsa_get_e()

int botan_pubkey_rsa_get_e ( botan_mp_t  e,
botan_pubkey_t  key 
)

Definition at line 325 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

326  {
327  return botan_pubkey_get_field(e, key, "e");
328  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_rsa_get_n()

int botan_pubkey_rsa_get_n ( botan_mp_t  n,
botan_pubkey_t  key 
)

Definition at line 330 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

331  {
332  return botan_pubkey_get_field(n, key, "n");
333  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

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

References Botan::Public_Key::algo_name(), BOTAN_CURRENT_FUNCTION, 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, Botan::EC_PublicKey::public_point(), Botan_FFI::safe_get(), Botan::sm2_compute_za(), and Botan_FFI::write_vec_output().

578  {
579  if(out == nullptr || out_len == nullptr)
581  if(ident == nullptr || hash_algo == nullptr || key == nullptr)
583 
584 #if defined(BOTAN_HAS_SM2)
585  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
586  const Botan::Public_Key& pub_key = safe_get(key);
587  const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
588 
589  if(ec_key == nullptr)
591 
592  if(ec_key->algo_name() != "SM2_Sig" && ec_key->algo_name() != "SM2_Enc")
594 
595  const std::string ident_str(ident);
596  std::unique_ptr<Botan::HashFunction> hash =
598 
599  const std::vector<uint8_t> za =
600  Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->public_point());
601 
602  return write_vec_output(out, out_len, za);
603  });
604 #else
606 #endif
607  }
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:345
const PointGFp & public_point() const
Definition: ecc_key.h:57
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
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:43
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
const EC_Group & domain() const
Definition: ecc_key.h:72
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147
MechanismType hash
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148