9#include <botan/data_src.h> 
   10#include <botan/hash.h> 
   11#include <botan/pk_algs.h> 
   12#include <botan/pk_keys.h> 
   13#include <botan/pkcs8.h> 
   14#include <botan/x509_key.h> 
   15#include <botan/internal/ffi_ec.h> 
   16#include <botan/internal/ffi_oid.h> 
   17#include <botan/internal/ffi_pkey.h> 
   18#include <botan/internal/ffi_rng.h> 
   19#include <botan/internal/ffi_util.h> 
   21#if defined(BOTAN_HAS_HASH_ID) 
   22   #include <botan/internal/hash_id.h> 
   30                         const char* algo_name,
 
   31                         const char* algo_params,
 
   34   if(algo_name == 
nullptr) {
 
   39      if(key_obj == 
nullptr) {
 
   44      if(rng_obj == 
nullptr) {
 
   48      const std::string params(algo_params != 
nullptr ? algo_params : 
"");
 
 
   61                            const char* algo_name,
 
   65   if(algo_name == 
nullptr) {
 
   70      if(key_obj == 
nullptr) {
 
 
   95      std::unique_ptr<Botan::Private_Key> pkcs8;
 
   97      if(password == 
nullptr) {
 
 
  122      if(pubkey == 
nullptr) {
 
 
  137      auto public_key = 
safe_get(key_obj).public_key();
 
 
  180      key, [=](
const auto& k) -> 
int { 
return invoke_view_callback(view, ctx, k.subject_public_key()); });
 
 
  190      key, [=](
const auto& k) -> 
int { 
return invoke_view_callback(view, ctx, k.raw_public_key_bits()); });
 
 
  217      key, [=](
const auto& k) -> 
int { 
return invoke_view_callback(view, ctx, k.raw_private_key_bits()); });
 
 
  234                                              const char* passphrase,
 
  236                                              size_t* pbkdf_iters_out,
 
  238                                              const char* pbkdf_hash,
 
  240   if(pbkdf_iters_out != 
nullptr) {
 
  241      *pbkdf_iters_out = 0;
 
 
  257                                           const char* passphrase,
 
  258                                           const char* maybe_cipher,
 
  259                                           const char* maybe_pbkdf_algo,
 
  260                                           size_t pbkdf_runtime_msec,
 
  263   if(passphrase == 
nullptr) {
 
  268      const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
 
  271      const std::string cipher = (maybe_cipher ? maybe_cipher : 
"");
 
  272      const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : 
"");
 
 
  283                                           const char* passphrase,
 
  284                                           const char* maybe_cipher,
 
  285                                           const char* maybe_pbkdf_algo,
 
  286                                           size_t pbkdf_runtime_msec,
 
  289   if(passphrase == 
nullptr) {
 
  294      const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
 
  297      const std::string cipher = (maybe_cipher ? maybe_cipher : 
"");
 
  298      const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : 
"");
 
 
  311                                              const char* passphrase,
 
  314                                              const char* pbkdf_algo,
 
 
  329                                     const char* passphrase,
 
  330                                     const char* maybe_cipher,
 
  331                                     const char* maybe_pbkdf_algo,
 
  332                                     size_t maybe_pbkdf_iterations,
 
  335   if(passphrase == 
nullptr) {
 
  342      const std::string cipher = (maybe_cipher ? maybe_cipher : 
"");
 
  343      const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : 
"");
 
  344      const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
 
 
  354                                     const char* passphrase,
 
  355                                     const char* maybe_cipher,
 
  356                                     const char* maybe_pbkdf_algo,
 
  357                                     size_t maybe_pbkdf_iterations,
 
  360   if(passphrase == 
nullptr) {
 
  367      const std::string cipher = (maybe_cipher ? maybe_cipher : 
"");
 
  368      const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : 
"");
 
  369      const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
 
 
  383      auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
 
 
  396      auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
 
 
  409      if(k.stateful_operation()) {
 
 
  424      if(
auto remaining = k.remaining_operations()) {
 
  425         *out = remaining.value();
 
 
  434   return BOTAN_FFI_VISIT(key, [=](
const auto& k) { *estimate = k.estimated_strength(); });
 
 
  445#if defined(BOTAN_HAS_HASH_ID) 
  448      return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
 
 
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
 
struct botan_pubkey_struct * botan_pubkey_t
 
int botan_privkey_view_encrypted_pem_timed(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_str_fn view)
 
struct botan_asn1_oid_struct * botan_asn1_oid_t
 
struct botan_privkey_struct * botan_privkey_t
 
int botan_privkey_view_encrypted_der(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_iterations, botan_view_ctx ctx, botan_view_bin_fn view)
 
#define BOTAN_PRIVKEY_EXPORT_FLAG_RAW
 
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
 
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_view_encrypted_der_timed(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
struct botan_ec_group_struct * botan_ec_group_t
 
int botan_privkey_view_encrypted_pem(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_iterations, botan_view_ctx ctx, botan_view_str_fn view)
 
int(* botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t *data, size_t len)
 
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
 
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
 
struct botan_rng_struct * botan_rng_t
 
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
 
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
 
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
 
@ BOTAN_FFI_ERROR_BAD_FLAG
 
@ BOTAN_FFI_ERROR_INVALID_INPUT
 
@ BOTAN_FFI_ERROR_NULL_POINTER
 
@ BOTAN_FFI_ERROR_NO_VALUE
 
int(* botan_view_str_fn)(botan_view_ctx view_ctx, const char *str, size_t len)
 
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
 
int botan_privkey_export_encrypted(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng_obj, const char *pass, const char *, uint32_t flags)
 
int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags)
 
int botan_pubkey_fingerprint(botan_pubkey_t key, const char *hash_fn, uint8_t out[], size_t *out_len)
 
int botan_privkey_load(botan_privkey_t *key, botan_rng_t rng_obj, const uint8_t bits[], size_t len, const char *password)
 
int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t *estimate)
 
int botan_pkcs_hash_id(const char *hash_name, uint8_t pkcs_id[], size_t *pkcs_id_len)
 
int botan_privkey_view_encrypted_der_timed(botan_privkey_t key, botan_rng_t rng_obj, const char *passphrase, const char *maybe_cipher, const char *maybe_pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pubkey_load(botan_pubkey_t *key, const uint8_t bits[], size_t bits_len)
 
int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_privkey_view_encrypted_pem_timed(botan_privkey_t key, botan_rng_t rng_obj, const char *passphrase, const char *maybe_cipher, const char *maybe_pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_str_fn view)
 
int botan_privkey_export_encrypted_pbkdf_msec(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, uint32_t pbkdf_msec, size_t *pbkdf_iters_out, const char *cipher, const char *pbkdf_hash, uint32_t flags)
 
int botan_pubkey_oid(botan_asn1_oid_t *oid, botan_pubkey_t key)
 
int botan_privkey_view_encrypted_der(botan_privkey_t key, botan_rng_t rng_obj, const char *passphrase, const char *maybe_cipher, const char *maybe_pbkdf_algo, size_t maybe_pbkdf_iterations, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_destroy(botan_privkey_t key)
 
int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t *out_len)
 
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
 
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_stateful_operation(botan_privkey_t key, int *out)
 
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_ec_privkey_create(botan_privkey_t *key_obj, const char *algo_name, botan_ec_group_t ec_group_obj, botan_rng_t rng_obj)
 
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_remaining_operations(botan_privkey_t key, uint64_t *out)
 
int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_privkey_oid(botan_asn1_oid_t *oid, botan_privkey_t key)
 
int botan_pubkey_destroy(botan_pubkey_t key)
 
int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t *out_len)
 
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_create(botan_privkey_t *key_obj, const char *algo_name, const char *algo_params, botan_rng_t rng_obj)
 
int botan_privkey_export_pubkey(botan_pubkey_t *pubout, botan_privkey_t key_obj)
 
int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
 
int botan_privkey_export_encrypted_pbkdf_iter(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, size_t pbkdf_iter, const char *cipher, const char *pbkdf_algo, uint32_t flags)
 
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
 
int botan_privkey_view_encrypted_pem(botan_privkey_t key, botan_rng_t rng_obj, const char *passphrase, const char *maybe_cipher, const char *maybe_pbkdf_algo, size_t maybe_pbkdf_iterations, botan_view_ctx ctx, botan_view_str_fn view)
 
#define BOTAN_FFI_VISIT(obj, lambda)
 
#define BOTAN_FFI_CHECKED_DELETE(o)
 
std::string PEM_encode_encrypted_pbkdf_iter(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, size_t pbkdf_iterations, std::string_view cipher, std::string_view pbkdf_hash)
 
std::string PEM_encode(const Private_Key &key)
 
std::string PEM_encode_encrypted_pbkdf_msec(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, std::chrono::milliseconds pbkdf_msec, size_t *pbkdf_iterations, std::string_view cipher, std::string_view pbkdf_hash)
 
std::vector< uint8_t > BER_encode_encrypted_pbkdf_iter(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, size_t pbkdf_iterations, std::string_view cipher, std::string_view pbkdf_hash)
 
std::vector< uint8_t > BER_encode_encrypted_pbkdf_msec(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, std::chrono::milliseconds pbkdf_msec, size_t *pbkdf_iterations, std::string_view cipher, std::string_view pbkdf_hash)
 
std::unique_ptr< Private_Key > load_key(DataSource &source, const std::function< std::string()> &get_pass)
 
std::unique_ptr< Public_Key > load_key(DataSource &source)
 
std::string PEM_encode(const Public_Key &key)
 
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
 
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
 
T & safe_get(botan_struct< T, M > *p)
 
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
 
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
 
int write_output(T out[], size_t *out_len, const T buf[], size_t buf_len)
 
int ffi_guard_thunk(const char *func_name, T thunk)
 
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
 
int write_str_output(char out[], size_t *out_len, const std::string &str)
 
std::unique_ptr< Private_Key > create_private_key(std::string_view alg_name, RandomNumberGenerator &rng, std::string_view params, std::string_view provider)
 
std::vector< uint8_t > pkcs_hash_id(std::string_view name)
 
std::unique_ptr< Private_Key > create_ec_private_key(std::string_view alg_name, const EC_Group &ec_group, RandomNumberGenerator &rng)