Botan  2.6.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_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_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 830 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().

835  {
836  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
837  Botan::Private_Key& key = safe_get(mce_key_obj);
838 
839 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
840  Botan::McEliece_PrivateKey* mce = dynamic_cast<Botan::McEliece_PrivateKey*>(&key);
841  if(!mce)
843 
844  const Botan::secure_vector<uint8_t> pt = mceies_decrypt(*mce, ct, ct_len, ad, ad_len, aead);
845  return write_vec_output(out, out_len, pt);
846 #else
848 #endif
849  });
850  }
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:69
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
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

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

858  {
859  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
860  Botan::Public_Key& key = safe_get(mce_key_obj);
861  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
862 
863 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
864  Botan::McEliece_PublicKey* mce = dynamic_cast<Botan::McEliece_PublicKey*>(&key);
865  if(!mce)
867 
868  Botan::secure_vector<uint8_t> ct = mceies_encrypt(*mce, pt, pt_len, ad, ad_len, rng, aead);
869  return write_vec_output(out, out_len, ct);
870 #else
872 #endif
873  });
874  }
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
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

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

References botan_privkey_create().

534  {
535  return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
536  }
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_dsa()

int botan_privkey_create_dsa ( botan_privkey_t key,
botan_rng_t  rng_obj,
size_t  pbits,
size_t  qbits 
)

Definition at line 336 of file ffi_pkey_algs.cpp.

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

337  {
338 #if defined(BOTAN_HAS_DSA)
339 
340  if ((rng_obj == nullptr) || (key == nullptr))
342 
343  if ((pbits % 64) || (qbits % 8) ||
344  (pbits < 1024) || (pbits > 3072) ||
345  (qbits < 160) || (qbits > 256)) {
347  }
348 
349  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
350  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
351  Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
352  *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(rng, group));
353  return BOTAN_FFI_SUCCESS;
354  });
355 #else
356  BOTAN_UNUSED(key, rng_obj, pbits, qbits);
358 #endif
359  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

References BOTAN_FFI_ERROR_NULL_POINTER, and botan_privkey_create().

574  {
575  if(param_str == nullptr)
577 
578  const std::string params(param_str);
579 
580  if(params == "curve25519")
581  return botan_privkey_create(key_obj, "Curve25519", "", rng_obj);
582 
583  return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
584  }
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_ecdsa()

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

Definition at line 421 of file ffi_pkey_algs.cpp.

References botan_privkey_create().

422  {
423  return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
424  }
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_elgamal()

int botan_privkey_create_elgamal ( botan_privkey_t key,
botan_rng_t  rng_obj,
size_t  pbits,
size_t  qbits 
)

Definition at line 468 of file ffi_pkey_algs.cpp.

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

472  {
473 #if defined(BOTAN_HAS_ELGAMAL)
474 
475  if ((rng_obj == nullptr) || (key == nullptr))
477 
478  if ((pbits < 1024) || (qbits<160)) {
480  }
481 
482  Botan::DL_Group::PrimeType prime_type = ((pbits-1) == qbits)
485 
486  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
487  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
488  Botan::DL_Group group(rng, prime_type, pbits, qbits);
489  *key = new botan_privkey_struct(new Botan::ElGamal_PrivateKey(rng, group));
490  return BOTAN_FFI_SUCCESS;
491  });
492 #else
493  BOTAN_UNUSED(key, rng_obj, pbits);
495 #endif
496  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

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

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

825  {
826  const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
827  return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
828  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:145
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:145
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_dsa_get_x()

int botan_privkey_dsa_get_x ( botan_mp_t  x,
botan_privkey_t  key 
)

Definition at line 396 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

397  {
398  return botan_privkey_get_field(x, key, "x");
399  }
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 776 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().

778  {
779 #if defined(BOTAN_HAS_ED25519)
780  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
781  if(Botan::Ed25519_PrivateKey* ed = dynamic_cast<Botan::Ed25519_PrivateKey*>(&k))
782  {
783  const Botan::secure_vector<uint8_t>& ed_key = ed->get_private_key();
784  if(ed_key.size() != 64)
786  Botan::copy_mem(output, ed_key.data(), ed_key.size());
787  return BOTAN_FFI_SUCCESS;
788  }
789  else
790  {
792  }
793  });
794 #else
795  BOTAN_UNUSED(key, output);
797 #endif
798  }
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:108
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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

◆ 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_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 538 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().

540  {
541 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
542  *key = nullptr;
543  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
544  Botan::Null_RNG null_rng;
545  Botan::DL_Group group(safe_get(p), safe_get(g));
546  *key = new botan_privkey_struct(new Botan::DH_PrivateKey(null_rng, group, safe_get(x)));
547  return BOTAN_FFI_SUCCESS;
548  });
549 #else
550  BOTAN_UNUSED(key, p, g, x);
552 #endif
553  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 361 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().

363  {
364 #if defined(BOTAN_HAS_DSA)
365  *key = nullptr;
366 
367  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
368  Botan::Null_RNG null_rng;
369  Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
370  *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(null_rng, group, safe_get(x)));
371  return BOTAN_FFI_SUCCESS;
372  });
373 #else
374  BOTAN_UNUSED(key, p, q, g, x);
376 #endif
377  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 606 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().

609  {
610 #if defined(BOTAN_HAS_ECDH)
611  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
612  std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
613  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
614  if(rc == BOTAN_FFI_SUCCESS)
615  *key = new botan_privkey_struct(p_key.release());
616  return rc;
617  });
618 #else
619  BOTAN_UNUSED(key, scalar, curve_name);
621 #endif
622  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 449 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().

452  {
453 #if defined(BOTAN_HAS_ECDSA)
454  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
455  std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
456  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
457  if(rc == BOTAN_FFI_SUCCESS)
458  *key = new botan_privkey_struct(p_key.release());
459  return rc;
460  });
461 #else
462  BOTAN_UNUSED(key, scalar, curve_name);
464 #endif
465  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 744 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().

746  {
747 #if defined(BOTAN_HAS_ED25519)
748  *key = nullptr;
749  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
750  const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
751  *key = new botan_privkey_struct(new Botan::Ed25519_PrivateKey(privkey_vec));
752  return BOTAN_FFI_SUCCESS;
753  });
754 #else
755  BOTAN_UNUSED(key, privkey);
757 #endif
758  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
#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 514 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().

516  {
517 #if defined(BOTAN_HAS_ELGAMAL)
518  *key = nullptr;
519  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
520  Botan::Null_RNG null_rng;
521  Botan::DL_Group group(safe_get(p), safe_get(g));
522  *key = new botan_privkey_struct(new Botan::ElGamal_PrivateKey(null_rng, group, safe_get(x)));
523  return BOTAN_FFI_SUCCESS;
524  });
525 #else
526  BOTAN_UNUSED(key, p, g, x);
528 #endif
529  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 683 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().

686  {
687 #if defined(BOTAN_HAS_SM2)
688  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
689  std::unique_ptr<Botan::SM2_Signature_PrivateKey> p_key;
690  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
691 
692  if(rc == BOTAN_FFI_SUCCESS)
693  *key = new botan_privkey_struct(p_key.release());
694  return rc;
695  });
696 #else
697  BOTAN_UNUSED(key, scalar, curve_name);
699 #endif
700  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 723 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().

726  {
727 #if defined(BOTAN_HAS_SM2)
728  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
729  std::unique_ptr<Botan::SM2_Encryption_PrivateKey> p_key;
730  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
731 
732  if(rc == BOTAN_FFI_SUCCESS)
733  *key = new botan_privkey_struct(p_key.release());
734  return rc;
735  });
736 #else
737  BOTAN_UNUSED(key, scalar, curve_name);
739 #endif
740  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 411 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

412  {
413  return botan_pubkey_get_field(g, key, "g");
414  }
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 401 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

402  {
403  return botan_pubkey_get_field(p, key, "p");
404  }
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 406 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

407  {
408  return botan_pubkey_get_field(q, key, "q");
409  }
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 416 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

417  {
418  return botan_pubkey_get_field(y, key, "y");
419  }
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 800 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().

802  {
803 #if defined(BOTAN_HAS_ED25519)
804  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
805  if(Botan::Ed25519_PublicKey* ed = dynamic_cast<Botan::Ed25519_PublicKey*>(&k))
806  {
807  const std::vector<uint8_t>& ed_key = ed->get_public_key();
808  if(ed_key.size() != 32)
810  Botan::copy_mem(output, ed_key.data(), ed_key.size());
811  return BOTAN_FFI_SUCCESS;
812  }
813  else
814  {
816  }
817  });
818 #else
819  BOTAN_UNUSED(key, output);
821 #endif
822  }
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:108
#define BOTAN_UNUSED(...)
Definition: assert.h:117
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ 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_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 555 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().

557  {
558 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
559  *key = nullptr;
560  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
561  Botan::DL_Group group(safe_get(p), safe_get(g));
562  *key = new botan_pubkey_struct(new Botan::DH_PublicKey(group, safe_get(y)));
563  return BOTAN_FFI_SUCCESS;
564  });
565 #else
566  BOTAN_UNUSED(key, p, g, y);
568 #endif
569  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 379 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().

381  {
382 #if defined(BOTAN_HAS_DSA)
383  *key = nullptr;
384 
385  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
386  Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
387  *key = new botan_pubkey_struct(new Botan::DSA_PublicKey(group, safe_get(y)));
388  return BOTAN_FFI_SUCCESS;
389  });
390 #else
391  BOTAN_UNUSED(key, p, q, g, y);
393 #endif
394  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 586 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().

590  {
591 #if defined(BOTAN_HAS_ECDH)
592  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
593  std::unique_ptr<Botan::ECDH_PublicKey> p_key;
594  int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
595 
596  if(rc == BOTAN_FFI_SUCCESS)
597  *key = new botan_pubkey_struct(p_key.release());
598  return rc;
599  });
600 #else
601  BOTAN_UNUSED(key, public_x, public_y, curve_name);
603 #endif
604  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 428 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().

432  {
433 #if defined(BOTAN_HAS_ECDSA)
434  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
435  std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
436 
437  int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
438  if(rc == BOTAN_FFI_SUCCESS)
439  *key = new botan_pubkey_struct(p_key.release());
440 
441  return rc;
442  });
443 #else
444  BOTAN_UNUSED(key, public_x, public_y, curve_name);
446 #endif
447  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 760 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().

762  {
763 #if defined(BOTAN_HAS_ED25519)
764  *key = nullptr;
765  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
766  const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
767  *key = new botan_pubkey_struct(new Botan::Ed25519_PublicKey(pubkey_vec));
768  return BOTAN_FFI_SUCCESS;
769  });
770 #else
771  BOTAN_UNUSED(key, pubkey);
773 #endif
774  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
#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 498 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().

500  {
501 #if defined(BOTAN_HAS_ELGAMAL)
502  *key = nullptr;
503  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
504  Botan::DL_Group group(safe_get(p), safe_get(g));
505  *key = new botan_pubkey_struct(new Botan::ElGamal_PublicKey(group, safe_get(y)));
506  return BOTAN_FFI_SUCCESS;
507  });
508 #else
509  BOTAN_UNUSED(key, p, g, y);
511 #endif
512  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 662 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().

666  {
667 #if defined(BOTAN_HAS_SM2)
668  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
669  std::unique_ptr<Botan::SM2_Signature_PublicKey> p_key;
670  if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
671  {
672  *key = new botan_pubkey_struct(p_key.release());
673  return BOTAN_FFI_SUCCESS;
674  }
676  });
677 #else
678  BOTAN_UNUSED(key, public_x, public_y, curve_name);
680 #endif
681  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 702 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().

706  {
707 #if defined(BOTAN_HAS_SM2)
708  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
709  std::unique_ptr<Botan::SM2_Encryption_PublicKey> p_key;
710  if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
711  {
712  *key = new botan_pubkey_struct(p_key.release());
713  return BOTAN_FFI_SUCCESS;
714  }
716  });
717 #else
718  BOTAN_UNUSED(key, public_x, public_y, curve_name);
720 #endif
721  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_UNUSED(...)
Definition: assert.h:117
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 626 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, hash_algo, Botan::EC_PublicKey::public_point(), Botan_FFI::safe_get(), Botan::sm2_compute_za(), and Botan_FFI::write_vec_output().

631  {
632  if(out == nullptr || out_len == nullptr)
634  if(ident == nullptr || hash_algo == nullptr || key == nullptr)
636 
637 #if defined(BOTAN_HAS_SM2)
638  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
639  const Botan::Public_Key& pub_key = safe_get(key);
640  const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
641 
642  if(ec_key == nullptr)
644 
645  if(ec_key->algo_name() != "SM2_Sig" && ec_key->algo_name() != "SM2_Enc")
647 
648  const std::string ident_str(ident);
649  std::unique_ptr<Botan::HashFunction> hash =
651 
652  const std::vector<uint8_t> za =
653  Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->public_point());
654 
655  return write_vec_output(out, out_len, za);
656  });
657 #else
659 #endif
660  }
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:44
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
const EC_Group & domain() const
Definition: ecc_key.h:72
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:23
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
MechanismType hash