Botan 3.2.0
Crypto and TLS for C&
Macros | Typedefs | Enumerations | Functions
ffi.h File Reference

Public Header. More...

#include <botan/build.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS   1
 
#define BOTAN_CIPHER_INIT_FLAG_DECRYPT   1
 
#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0
 
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION   1
 
#define BOTAN_CIPHER_UPDATE_FLAG_FINAL   (1U << 0)
 
#define BOTAN_FFI_DEPRECATED(msg)
 
#define BOTAN_FFI_EXPORT(maj, min)   BOTAN_DLL
 
#define BOTAN_FFI_HEX_LOWER_CASE   1
 
#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE   1
 
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER   0
 
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM   1
 
#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE   1
 

Typedefs

typedef struct botan_block_cipher_struct * botan_block_cipher_t
 
typedef struct botan_cipher_struct * botan_cipher_t
 
typedef struct botan_fpe_struct * botan_fpe_t
 
typedef struct botan_hash_struct * botan_hash_t
 
typedef struct botan_hotp_struct * botan_hotp_t
 
typedef struct botan_mac_struct * botan_mac_t
 
typedef struct botan_mp_struct * botan_mp_t
 
typedef struct botan_pk_op_decrypt_struct * botan_pk_op_decrypt_t
 
typedef struct botan_pk_op_encrypt_struct * botan_pk_op_encrypt_t
 
typedef struct botan_pk_op_ka_struct * botan_pk_op_ka_t
 
typedef struct botan_pk_op_kem_decrypt_struct * botan_pk_op_kem_decrypt_t
 
typedef struct botan_pk_op_kem_encrypt_struct * botan_pk_op_kem_encrypt_t
 
typedef struct botan_pk_op_sign_struct * botan_pk_op_sign_t
 
typedef struct botan_pk_op_verify_struct * botan_pk_op_verify_t
 
typedef struct botan_privkey_struct * botan_privkey_t
 
typedef struct botan_pubkey_struct * botan_pubkey_t
 
typedef struct botan_rng_struct * botan_rng_t
 
typedef struct botan_srp6_server_session_struct * botan_srp6_server_session_t
 
typedef struct botan_totp_struct * botan_totp_t
 
typedef int(* botan_view_bin_fn) (botan_view_ctx view_ctx, const uint8_t *data, size_t len)
 
typedef void * botan_view_ctx
 
typedef int(* botan_view_str_fn) (botan_view_ctx view_ctx, const char *str, size_t len)
 
typedef struct botan_x509_cert_struct * botan_x509_cert_t
 
typedef struct botan_x509_crl_struct * botan_x509_crl_t
 

Enumerations

enum  BOTAN_FFI_ERROR {
  BOTAN_FFI_SUCCESS = 0 , BOTAN_FFI_INVALID_VERIFIER = 1 , BOTAN_FFI_ERROR_INVALID_INPUT = -1 , BOTAN_FFI_ERROR_BAD_MAC = -2 ,
  BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE = -10 , BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR = -11 , BOTAN_FFI_ERROR_EXCEPTION_THROWN = -20 , BOTAN_FFI_ERROR_OUT_OF_MEMORY = -21 ,
  BOTAN_FFI_ERROR_SYSTEM_ERROR = -22 , BOTAN_FFI_ERROR_INTERNAL_ERROR = -23 , BOTAN_FFI_ERROR_BAD_FLAG = -30 , BOTAN_FFI_ERROR_NULL_POINTER = -31 ,
  BOTAN_FFI_ERROR_BAD_PARAMETER = -32 , BOTAN_FFI_ERROR_KEY_NOT_SET = -33 , BOTAN_FFI_ERROR_INVALID_KEY_LENGTH = -34 , BOTAN_FFI_ERROR_INVALID_OBJECT_STATE = -35 ,
  BOTAN_FFI_ERROR_NOT_IMPLEMENTED = -40 , BOTAN_FFI_ERROR_INVALID_OBJECT = -50 , BOTAN_FFI_ERROR_TLS_ERROR = -75 , BOTAN_FFI_ERROR_HTTP_ERROR = -76 ,
  BOTAN_FFI_ERROR_ROUGHTIME_ERROR = -77 , BOTAN_FFI_ERROR_UNKNOWN_ERROR = -100
}
 
enum  botan_x509_cert_key_constraints {
  NO_CONSTRAINTS = 0 , DIGITAL_SIGNATURE = 32768 , NON_REPUDIATION = 16384 , KEY_ENCIPHERMENT = 8192 ,
  DATA_ENCIPHERMENT = 4096 , KEY_AGREEMENT = 2048 , KEY_CERT_SIGN = 1024 , CRL_SIGN = 512 ,
  ENCIPHER_ONLY = 256 , DECIPHER_ONLY = 128
}
 

Functions

BOTAN_DLL int botan_base64_decode (const char *base64_str, size_t in_len, uint8_t *out, size_t *out_len)
 
BOTAN_DLL int botan_base64_encode (const uint8_t *x, size_t len, char *out, size_t *out_len)
 
BOTAN_DLL int botan_bcrypt_generate (uint8_t *out, size_t *out_len, const char *password, botan_rng_t rng, size_t work_factor, uint32_t flags)
 
BOTAN_DLL int botan_bcrypt_is_valid (const char *pass, const char *hash)
 
BOTAN_DLL int botan_block_cipher_block_size (botan_block_cipher_t bc)
 
BOTAN_DLL int botan_block_cipher_clear (botan_block_cipher_t bc)
 
BOTAN_DLL int botan_block_cipher_decrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
 
BOTAN_DLL int botan_block_cipher_destroy (botan_block_cipher_t bc)
 
BOTAN_DLL int botan_block_cipher_encrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
 
BOTAN_DLL int botan_block_cipher_get_keyspec (botan_block_cipher_t cipher, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
 
BOTAN_DLL int botan_block_cipher_init (botan_block_cipher_t *bc, const char *cipher_name)
 
BOTAN_DLL int botan_block_cipher_name (botan_block_cipher_t cipher, char *name, size_t *name_len)
 
BOTAN_DLL int botan_block_cipher_set_key (botan_block_cipher_t bc, const uint8_t key[], size_t len)
 
BOTAN_DLL int botan_cipher_clear (botan_cipher_t hash)
 
BOTAN_DLL int botan_cipher_destroy (botan_cipher_t cipher)
 
BOTAN_DLL int botan_cipher_get_default_nonce_length (botan_cipher_t cipher, size_t *nl)
 
BOTAN_DLL int botan_cipher_get_ideal_update_granularity (botan_cipher_t cipher, size_t *ug)
 
BOTAN_DLL int botan_cipher_get_keyspec (botan_cipher_t, size_t *min_keylen, size_t *max_keylen, size_t *mod_keylen)
 
BOTAN_DLL int botan_cipher_get_tag_length (botan_cipher_t cipher, size_t *tag_size)
 
BOTAN_DLL int botan_cipher_get_update_granularity (botan_cipher_t cipher, size_t *ug)
 
BOTAN_DLL int botan_cipher_init (botan_cipher_t *cipher, const char *name, uint32_t flags)
 
BOTAN_DLL int botan_cipher_name (botan_cipher_t cipher, char *name, size_t *name_len)
 
BOTAN_DLL int botan_cipher_output_length (botan_cipher_t cipher, size_t in_len, size_t *out_len)
 
BOTAN_DLL int botan_cipher_query_keylen (botan_cipher_t, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
 
BOTAN_DLL int botan_cipher_reset (botan_cipher_t cipher)
 
BOTAN_DLL int botan_cipher_set_associated_data (botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
 
BOTAN_DLL int botan_cipher_set_key (botan_cipher_t cipher, const uint8_t *key, size_t key_len)
 
BOTAN_DLL int botan_cipher_start (botan_cipher_t cipher, const uint8_t *nonce, size_t nonce_len)
 
BOTAN_DLL int botan_cipher_update (botan_cipher_t cipher, uint32_t flags, uint8_t output[], size_t output_size, size_t *output_written, const uint8_t input_bytes[], size_t input_size, size_t *input_consumed)
 
BOTAN_DLL int botan_cipher_valid_nonce_length (botan_cipher_t cipher, size_t nl)
 
BOTAN_DLL int botan_constant_time_compare (const uint8_t *x, const uint8_t *y, size_t len)
 
BOTAN_DLL const char * botan_error_description (int err)
 
BOTAN_DLL const char * botan_error_last_exception_message (void)
 
BOTAN_DLL uint32_t botan_ffi_api_version (void)
 
BOTAN_DLL int botan_ffi_supports_api (uint32_t api_version)
 
BOTAN_DLL int botan_fpe_decrypt (botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
 
BOTAN_DLL int botan_fpe_destroy (botan_fpe_t fpe)
 
BOTAN_DLL int botan_fpe_encrypt (botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
 
BOTAN_DLL int botan_fpe_fe1_init (botan_fpe_t *fpe, botan_mp_t n, const uint8_t key[], size_t key_len, size_t rounds, uint32_t flags)
 
BOTAN_DLL int botan_hash_block_size (botan_hash_t hash, size_t *block_size)
 
BOTAN_DLL int botan_hash_clear (botan_hash_t hash)
 
BOTAN_DLL int botan_hash_copy_state (botan_hash_t *dest, botan_hash_t source)
 
BOTAN_DLL int botan_hash_destroy (botan_hash_t hash)
 
BOTAN_DLL int botan_hash_final (botan_hash_t hash, uint8_t out[])
 
BOTAN_DLL int botan_hash_init (botan_hash_t *hash, const char *hash_name, uint32_t flags)
 
BOTAN_DLL int botan_hash_name (botan_hash_t hash, char *name, size_t *name_len)
 
BOTAN_DLL int botan_hash_output_length (botan_hash_t hash, size_t *output_length)
 
BOTAN_DLL int botan_hash_update (botan_hash_t hash, const uint8_t *in, size_t in_len)
 
BOTAN_DLL int botan_hex_decode (const char *hex_str, size_t in_len, uint8_t *out, size_t *out_len)
 
BOTAN_DLL int botan_hex_encode (const uint8_t *x, size_t len, char *out, uint32_t flags)
 
BOTAN_DLL int botan_hotp_check (botan_hotp_t hotp, uint64_t *next_hotp_counter, uint32_t hotp_code, uint64_t hotp_counter, size_t resync_range)
 
BOTAN_DLL int botan_hotp_destroy (botan_hotp_t hotp)
 
BOTAN_DLL int botan_hotp_generate (botan_hotp_t hotp, uint32_t *hotp_code, uint64_t hotp_counter)
 
BOTAN_DLL int botan_hotp_init (botan_hotp_t *hotp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits)
 
BOTAN_DLL int botan_kdf (const char *kdf_algo, uint8_t out[], size_t out_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len)
 
BOTAN_DLL int botan_key_unwrap3394 (const uint8_t wrapped_key[], size_t wrapped_key_len, const uint8_t kek[], size_t kek_len, uint8_t key[], size_t *key_len)
 
BOTAN_DLL int botan_key_wrap3394 (const uint8_t key[], size_t key_len, const uint8_t kek[], size_t kek_len, uint8_t wrapped_key[], size_t *wrapped_key_len)
 
BOTAN_DLL int botan_mac_clear (botan_mac_t mac)
 
BOTAN_DLL int botan_mac_destroy (botan_mac_t mac)
 
BOTAN_DLL int botan_mac_final (botan_mac_t mac, uint8_t out[])
 
BOTAN_DLL int botan_mac_get_keyspec (botan_mac_t mac, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
 
BOTAN_DLL int botan_mac_init (botan_mac_t *mac, const char *mac_name, uint32_t flags)
 
BOTAN_DLL int botan_mac_name (botan_mac_t mac, char *name, size_t *name_len)
 
BOTAN_DLL int botan_mac_output_length (botan_mac_t mac, size_t *output_length)
 
BOTAN_DLL int botan_mac_set_key (botan_mac_t mac, const uint8_t *key, size_t key_len)
 
BOTAN_DLL int botan_mac_set_nonce (botan_mac_t mac, const uint8_t *nonce, size_t nonce_len)
 
BOTAN_DLL int botan_mac_update (botan_mac_t mac, const uint8_t *buf, size_t len)
 
BOTAN_DLL int botan_mceies_decrypt (botan_privkey_t mce_key, const char *aead, const uint8_t ct[], size_t ct_len, const uint8_t ad[], size_t ad_len, uint8_t pt[], size_t *pt_len)
 
BOTAN_DLL int botan_mceies_encrypt (botan_pubkey_t mce_key, botan_rng_t rng, const char *aead, const uint8_t pt[], size_t pt_len, const uint8_t ad[], size_t ad_len, uint8_t ct[], size_t *ct_len)
 
BOTAN_DLL int botan_mp_add (botan_mp_t result, botan_mp_t x, botan_mp_t y)
 
BOTAN_DLL int botan_mp_add_u32 (botan_mp_t result, botan_mp_t x, uint32_t y)
 
BOTAN_DLL int botan_mp_clear (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_clear_bit (botan_mp_t n, size_t bit)
 
BOTAN_DLL int botan_mp_cmp (int *result, botan_mp_t x, botan_mp_t y)
 
BOTAN_DLL int botan_mp_destroy (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_div (botan_mp_t quotient, botan_mp_t remainder, botan_mp_t x, botan_mp_t y)
 
BOTAN_DLL int botan_mp_equal (botan_mp_t x, botan_mp_t y)
 
BOTAN_DLL int botan_mp_flip_sign (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_from_bin (botan_mp_t mp, const uint8_t vec[], size_t vec_len)
 
BOTAN_DLL int botan_mp_gcd (botan_mp_t out, botan_mp_t x, botan_mp_t y)
 
BOTAN_DLL int botan_mp_get_bit (botan_mp_t n, size_t bit)
 
BOTAN_DLL int botan_mp_init (botan_mp_t *mp)
 
BOTAN_DLL int botan_mp_is_even (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_is_negative (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_is_odd (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_is_positive (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_is_prime (botan_mp_t n, botan_rng_t rng, size_t test_prob)
 
BOTAN_DLL int botan_mp_is_zero (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_lshift (botan_mp_t out, botan_mp_t in, size_t shift)
 
BOTAN_DLL int botan_mp_mod_inverse (botan_mp_t out, botan_mp_t in, botan_mp_t modulus)
 
BOTAN_DLL int botan_mp_mod_mul (botan_mp_t result, botan_mp_t x, botan_mp_t y, botan_mp_t mod)
 
BOTAN_DLL int botan_mp_mul (botan_mp_t result, botan_mp_t x, botan_mp_t y)
 
BOTAN_DLL int botan_mp_num_bits (botan_mp_t n, size_t *bits)
 
BOTAN_DLL int botan_mp_num_bytes (botan_mp_t n, size_t *bytes)
 
BOTAN_DLL int botan_mp_powmod (botan_mp_t out, botan_mp_t base, botan_mp_t exponent, botan_mp_t modulus)
 
BOTAN_DLL int botan_mp_rand_bits (botan_mp_t rand_out, botan_rng_t rng, size_t bits)
 
BOTAN_DLL int botan_mp_rand_range (botan_mp_t rand_out, botan_rng_t rng, botan_mp_t lower_bound, botan_mp_t upper_bound)
 
BOTAN_DLL int botan_mp_rshift (botan_mp_t out, botan_mp_t in, size_t shift)
 
BOTAN_DLL int botan_mp_set_bit (botan_mp_t n, size_t bit)
 
BOTAN_DLL int botan_mp_set_from_int (botan_mp_t mp, int initial_value)
 
BOTAN_DLL int botan_mp_set_from_mp (botan_mp_t dest, botan_mp_t source)
 
BOTAN_DLL int botan_mp_set_from_radix_str (botan_mp_t dest, const char *str, size_t radix)
 
BOTAN_DLL int botan_mp_set_from_str (botan_mp_t dest, const char *str)
 
BOTAN_DLL int botan_mp_sub (botan_mp_t result, botan_mp_t x, botan_mp_t y)
 
BOTAN_DLL int botan_mp_sub_u32 (botan_mp_t result, botan_mp_t x, uint32_t y)
 
BOTAN_DLL int botan_mp_swap (botan_mp_t x, botan_mp_t y)
 
BOTAN_DLL int botan_mp_to_bin (botan_mp_t mp, uint8_t vec[])
 
BOTAN_DLL int botan_mp_to_hex (botan_mp_t mp, char *out)
 
BOTAN_DLL int botan_mp_to_str (botan_mp_t mp, uint8_t base, char *out, size_t *out_len)
 
BOTAN_DLL int botan_mp_to_uint32 (botan_mp_t mp, uint32_t *val)
 
BOTAN_DLL int botan_nist_kw_dec (const char *cipher_algo, int padded, const uint8_t wrapped_key[], size_t wrapped_key_len, const uint8_t kek[], size_t kek_len, uint8_t key[], size_t *key_len)
 
BOTAN_DLL int botan_nist_kw_enc (const char *cipher_algo, int padded, const uint8_t key[], size_t key_len, const uint8_t kek[], size_t kek_len, uint8_t wrapped_key[], size_t *wrapped_key_len)
 
BOTAN_DLL int botan_pbkdf (const char *pbkdf_algo, uint8_t out[], size_t out_len, const char *passphrase, const uint8_t salt[], size_t salt_len, size_t iterations)
 
BOTAN_DLL int botan_pbkdf_timed (const char *pbkdf_algo, uint8_t out[], size_t out_len, const char *passphrase, const uint8_t salt[], size_t salt_len, size_t milliseconds_to_run, size_t *out_iterations_used)
 
BOTAN_DLL int botan_pk_op_decrypt (botan_pk_op_decrypt_t op, uint8_t out[], size_t *out_len, const uint8_t ciphertext[], size_t ciphertext_len)
 
BOTAN_DLL int botan_pk_op_decrypt_create (botan_pk_op_decrypt_t *op, botan_privkey_t key, const char *padding, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_decrypt_destroy (botan_pk_op_decrypt_t op)
 
BOTAN_DLL int botan_pk_op_decrypt_output_length (botan_pk_op_decrypt_t op, size_t ctext_len, size_t *ptext_len)
 
BOTAN_DLL int botan_pk_op_encrypt (botan_pk_op_encrypt_t op, botan_rng_t rng, uint8_t out[], size_t *out_len, const uint8_t plaintext[], size_t plaintext_len)
 
BOTAN_DLL int botan_pk_op_encrypt_create (botan_pk_op_encrypt_t *op, botan_pubkey_t key, const char *padding, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_encrypt_destroy (botan_pk_op_encrypt_t op)
 
BOTAN_DLL int botan_pk_op_encrypt_output_length (botan_pk_op_encrypt_t op, size_t ptext_len, size_t *ctext_len)
 
BOTAN_DLL int botan_pk_op_kem_decrypt_create (botan_pk_op_kem_decrypt_t *op, botan_privkey_t key, const char *kdf)
 
BOTAN_DLL int botan_pk_op_kem_decrypt_destroy (botan_pk_op_kem_decrypt_t op)
 
BOTAN_DLL int botan_pk_op_kem_decrypt_shared_key (botan_pk_op_kem_decrypt_t op, const uint8_t salt[], size_t salt_len, const uint8_t encapsulated_key[], size_t encapsulated_key_len, size_t desired_shared_key_len, uint8_t shared_key[], size_t *shared_key_len)
 
BOTAN_DLL int botan_pk_op_kem_decrypt_shared_key_length (botan_pk_op_kem_decrypt_t op, size_t desired_shared_key_length, size_t *output_shared_key_length)
 
BOTAN_DLL int botan_pk_op_kem_encrypt_create (botan_pk_op_kem_encrypt_t *op, botan_pubkey_t key, const char *kdf)
 
BOTAN_DLL int botan_pk_op_kem_encrypt_create_shared_key (botan_pk_op_kem_encrypt_t op, botan_rng_t rng, const uint8_t salt[], size_t salt_len, size_t desired_shared_key_len, uint8_t shared_key[], size_t *shared_key_len, uint8_t encapsulated_key[], size_t *encapsulated_key_len)
 
BOTAN_DLL int botan_pk_op_kem_encrypt_destroy (botan_pk_op_kem_encrypt_t op)
 
BOTAN_DLL int botan_pk_op_kem_encrypt_encapsulated_key_length (botan_pk_op_kem_encrypt_t op, size_t *output_encapsulated_key_length)
 
BOTAN_DLL int botan_pk_op_kem_encrypt_shared_key_length (botan_pk_op_kem_encrypt_t op, size_t desired_shared_key_length, size_t *output_shared_key_length)
 
BOTAN_DLL int botan_pk_op_key_agreement (botan_pk_op_ka_t op, uint8_t out[], size_t *out_len, const uint8_t other_key[], size_t other_key_len, const uint8_t salt[], size_t salt_len)
 
BOTAN_DLL int botan_pk_op_key_agreement_create (botan_pk_op_ka_t *op, botan_privkey_t key, const char *kdf, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_key_agreement_destroy (botan_pk_op_ka_t op)
 
BOTAN_DLL int botan_pk_op_key_agreement_export_public (botan_privkey_t key, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_pk_op_key_agreement_size (botan_pk_op_ka_t op, size_t *out_len)
 
BOTAN_DLL int botan_pk_op_key_agreement_view_public (botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
BOTAN_DLL int botan_pk_op_sign_create (botan_pk_op_sign_t *op, botan_privkey_t key, const char *hash_and_padding, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_sign_destroy (botan_pk_op_sign_t op)
 
BOTAN_DLL int botan_pk_op_sign_finish (botan_pk_op_sign_t op, botan_rng_t rng, uint8_t sig[], size_t *sig_len)
 
BOTAN_DLL int botan_pk_op_sign_output_length (botan_pk_op_sign_t op, size_t *olen)
 
BOTAN_DLL int botan_pk_op_sign_update (botan_pk_op_sign_t op, const uint8_t in[], size_t in_len)
 
BOTAN_DLL int botan_pk_op_verify_create (botan_pk_op_verify_t *op, botan_pubkey_t key, const char *hash_and_padding, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_verify_destroy (botan_pk_op_verify_t op)
 
BOTAN_DLL int botan_pk_op_verify_finish (botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len)
 
BOTAN_DLL int botan_pk_op_verify_update (botan_pk_op_verify_t op, const uint8_t in[], size_t in_len)
 
BOTAN_DLL int botan_pkcs_hash_id (const char *hash_name, uint8_t pkcs_id[], size_t *pkcs_id_len)
 
BOTAN_DLL int botan_privkey_algo_name (botan_privkey_t key, char out[], size_t *out_len)
 
BOTAN_DLL int botan_privkey_check_key (botan_privkey_t key, botan_rng_t rng, uint32_t flags)
 
BOTAN_DLL int botan_privkey_create (botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
 
BOTAN_DLL int botan_privkey_create_dh (botan_privkey_t *key, botan_rng_t rng, const char *param)
 
BOTAN_DLL int botan_privkey_create_dsa (botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
 
BOTAN_DLL int botan_privkey_create_ecdh (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
BOTAN_DLL int botan_privkey_create_ecdsa (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
BOTAN_DLL int botan_privkey_create_elgamal (botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
 
BOTAN_DLL int botan_privkey_create_mceliece (botan_privkey_t *key, botan_rng_t rng, size_t n, size_t t)
 
BOTAN_DLL int botan_privkey_create_rsa (botan_privkey_t *key, botan_rng_t rng, size_t n_bits)
 
BOTAN_DLL int botan_privkey_destroy (botan_privkey_t key)
 
BOTAN_DLL int botan_privkey_dsa_get_x (botan_mp_t n, botan_privkey_t key)
 
BOTAN_DLL int botan_privkey_ed25519_get_privkey (botan_privkey_t key, uint8_t output[64])
 
BOTAN_DLL int botan_privkey_export (botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
BOTAN_DLL int botan_privkey_export_encrypted (botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, const char *encryption_algo, uint32_t flags)
 
BOTAN_DLL 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_iterations, const char *cipher_algo, const char *pbkdf_algo, uint32_t flags)
 
BOTAN_DLL 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_runtime, size_t *pbkdf_iterations_out, const char *cipher_algo, const char *pbkdf_algo, uint32_t flags)
 
BOTAN_DLL int botan_privkey_export_pubkey (botan_pubkey_t *out, botan_privkey_t in)
 
BOTAN_DLL int botan_privkey_get_field (botan_mp_t output, botan_privkey_t key, const char *field_name)
 
BOTAN_DLL int botan_privkey_load (botan_privkey_t *key, botan_rng_t rng, const uint8_t bits[], size_t len, const char *password)
 
BOTAN_DLL int botan_privkey_load_dh (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_privkey_load_ecdh (botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
 
BOTAN_DLL int botan_privkey_load_ecdsa (botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
 
BOTAN_DLL int botan_privkey_load_ed25519 (botan_privkey_t *key, const uint8_t privkey[32])
 
BOTAN_DLL int botan_privkey_load_elgamal (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
 
BOTAN_DLL int botan_privkey_load_kyber (botan_privkey_t *key, const uint8_t privkey[], size_t key_len)
 
BOTAN_DLL int botan_privkey_load_rsa (botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t e)
 
BOTAN_DLL int botan_privkey_load_rsa_pkcs1 (botan_privkey_t *key, const uint8_t bits[], size_t len)
 
BOTAN_DLL int botan_privkey_load_sm2 (botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
 
BOTAN_DLL int botan_privkey_load_sm2_enc (botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
 
BOTAN_DLL int botan_privkey_load_x25519 (botan_privkey_t *key, const uint8_t privkey[32])
 
BOTAN_DLL int botan_privkey_rsa_get_d (botan_mp_t d, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_privkey_rsa_get_e (botan_mp_t e, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_privkey_rsa_get_n (botan_mp_t n, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_privkey_rsa_get_p (botan_mp_t p, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_privkey_rsa_get_privkey (botan_privkey_t rsa_key, uint8_t out[], size_t *out_len, uint32_t flags)
 
BOTAN_DLL int botan_privkey_rsa_get_q (botan_mp_t q, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_privkey_view_der (botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
BOTAN_DLL 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)
 
BOTAN_DLL 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)
 
BOTAN_DLL 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)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_privkey_view_kyber_raw_key (botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
BOTAN_DLL int botan_privkey_view_pem (botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
 
BOTAN_DLL int botan_privkey_x25519_get_privkey (botan_privkey_t key, uint8_t output[32])
 
BOTAN_DLL int botan_pubkey_algo_name (botan_pubkey_t key, char out[], size_t *out_len)
 
BOTAN_DLL int botan_pubkey_check_key (botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
 
BOTAN_DLL int botan_pubkey_destroy (botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_dsa_get_g (botan_mp_t d, botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_dsa_get_p (botan_mp_t p, botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_dsa_get_q (botan_mp_t q, botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_dsa_get_y (botan_mp_t y, botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_ecc_key_used_explicit_encoding (botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_ed25519_get_pubkey (botan_pubkey_t key, uint8_t pubkey[32])
 
BOTAN_DLL int botan_pubkey_estimated_strength (botan_pubkey_t key, size_t *estimate)
 
BOTAN_DLL int botan_pubkey_export (botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
BOTAN_DLL int botan_pubkey_fingerprint (botan_pubkey_t key, const char *hash, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_pubkey_get_field (botan_mp_t output, botan_pubkey_t key, const char *field_name)
 
BOTAN_DLL int botan_pubkey_load (botan_pubkey_t *key, const uint8_t bits[], size_t len)
 
BOTAN_DLL int botan_pubkey_load_dh (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_pubkey_load_ecdh (botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
 
BOTAN_DLL int botan_pubkey_load_ecdsa (botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
 
BOTAN_DLL int botan_pubkey_load_ed25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
 
BOTAN_DLL int botan_pubkey_load_elgamal (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
 
BOTAN_DLL int botan_pubkey_load_kyber (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len)
 
BOTAN_DLL int botan_pubkey_load_rsa (botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
 
BOTAN_DLL int botan_pubkey_load_sm2 (botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
 
BOTAN_DLL int botan_pubkey_load_sm2_enc (botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
 
BOTAN_DLL int botan_pubkey_load_x25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
 
BOTAN_DLL int botan_pubkey_rsa_get_e (botan_mp_t e, botan_pubkey_t rsa_key)
 
BOTAN_DLL int botan_pubkey_rsa_get_n (botan_mp_t n, botan_pubkey_t rsa_key)
 
BOTAN_DLL int botan_pubkey_sm2_compute_za (uint8_t out[], size_t *out_len, const char *ident, const char *hash_algo, botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_view_der (botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
BOTAN_DLL int botan_pubkey_view_ec_public_point (botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
BOTAN_DLL int botan_pubkey_view_kyber_raw_key (botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
BOTAN_DLL int botan_pubkey_view_pem (botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
 
BOTAN_DLL int botan_pubkey_x25519_get_pubkey (botan_pubkey_t key, uint8_t pubkey[32])
 
int BOTAN_DLL botan_pwdhash (const char *algo, size_t param1, size_t param2, size_t param3, uint8_t out[], size_t out_len, const char *passphrase, size_t passphrase_len, const uint8_t salt[], size_t salt_len)
 
int BOTAN_DLL botan_pwdhash_timed (const char *algo, uint32_t msec, size_t *param1, size_t *param2, size_t *param3, uint8_t out[], size_t out_len, const char *passphrase, size_t passphrase_len, const uint8_t salt[], size_t salt_len)
 
BOTAN_DLL int botan_rng_add_entropy (botan_rng_t rng, const uint8_t *entropy, size_t entropy_len)
 
BOTAN_DLL int botan_rng_destroy (botan_rng_t rng)
 
BOTAN_DLL int botan_rng_get (botan_rng_t rng, uint8_t *out, size_t out_len)
 
BOTAN_DLL int botan_rng_init (botan_rng_t *rng, const char *rng_type)
 
BOTAN_DLL int botan_rng_init_custom (botan_rng_t *rng_out, const char *rng_name, void *context, int(*get_cb)(void *context, uint8_t *out, size_t out_len), int(*add_entropy_cb)(void *context, const uint8_t input[], size_t length), void(*destroy_cb)(void *context))
 
BOTAN_DLL int botan_rng_reseed (botan_rng_t rng, size_t bits)
 
BOTAN_DLL int botan_rng_reseed_from_rng (botan_rng_t rng, botan_rng_t source_rng, size_t bits)
 
BOTAN_DLL int botan_same_mem (const uint8_t *x, const uint8_t *y, size_t len)
 
BOTAN_DLL int botan_scrub_mem (void *mem, size_t bytes)
 
BOTAN_DLL int botan_scrypt (uint8_t out[], size_t out_len, const char *passphrase, const uint8_t salt[], size_t salt_len, size_t N, size_t r, size_t p)
 
BOTAN_DLL int botan_srp6_client_agree (const char *username, const char *password, const char *group_id, const char *hash_id, const uint8_t salt[], size_t salt_len, const uint8_t B[], size_t B_len, botan_rng_t rng_obj, uint8_t A[], size_t *A_len, uint8_t K[], size_t *K_len)
 
BOTAN_DLL int botan_srp6_generate_verifier (const char *identifier, const char *password, const uint8_t salt[], size_t salt_len, const char *group_id, const char *hash_id, uint8_t verifier[], size_t *verifier_len)
 
BOTAN_DLL int botan_srp6_group_size (const char *group_id, size_t *group_p_bytes)
 
BOTAN_DLL int botan_srp6_server_session_destroy (botan_srp6_server_session_t srp6)
 
BOTAN_DLL int botan_srp6_server_session_init (botan_srp6_server_session_t *srp6)
 
BOTAN_DLL int botan_srp6_server_session_step1 (botan_srp6_server_session_t srp6, const uint8_t verifier[], size_t verifier_len, const char *group_id, const char *hash_id, botan_rng_t rng_obj, uint8_t B_pub[], size_t *B_pub_len)
 
BOTAN_DLL int botan_srp6_server_session_step2 (botan_srp6_server_session_t srp6, const uint8_t A[], size_t A_len, uint8_t key[], size_t *key_len)
 
BOTAN_DLL int botan_system_rng_get (uint8_t *out, size_t out_len)
 
BOTAN_DLL int botan_totp_check (botan_totp_t totp, uint32_t totp_code, uint64_t timestamp, size_t acceptable_clock_drift)
 
BOTAN_DLL int botan_totp_destroy (botan_totp_t totp)
 
BOTAN_DLL int botan_totp_generate (botan_totp_t totp, uint32_t *totp_code, uint64_t timestamp)
 
BOTAN_DLL int botan_totp_init (botan_totp_t *totp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits, size_t time_step)
 
BOTAN_DLL uint32_t botan_version_datestamp (void)
 
BOTAN_DLL uint32_t botan_version_major (void)
 
BOTAN_DLL uint32_t botan_version_minor (void)
 
BOTAN_DLL uint32_t botan_version_patch (void)
 
BOTAN_DLL const char * botan_version_string (void)
 
BOTAN_DLL int botan_x509_cert_allowed_usage (botan_x509_cert_t cert, unsigned int key_usage)
 
BOTAN_DLL int botan_x509_cert_destroy (botan_x509_cert_t cert)
 
BOTAN_DLL int botan_x509_cert_dup (botan_x509_cert_t *new_cert, botan_x509_cert_t cert)
 
BOTAN_DLL int botan_x509_cert_get_authority_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_fingerprint (botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_issuer_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_public_key (botan_x509_cert_t cert, botan_pubkey_t *key)
 
BOTAN_DLL int botan_x509_cert_get_public_key_bits (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_serial_number (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_subject_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_subject_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_time_expires (botan_x509_cert_t cert, char out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_time_starts (botan_x509_cert_t cert, char out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_hostname_match (botan_x509_cert_t cert, const char *hostname)
 
BOTAN_DLL int botan_x509_cert_load (botan_x509_cert_t *cert_obj, const uint8_t cert[], size_t cert_len)
 
BOTAN_DLL int botan_x509_cert_load_file (botan_x509_cert_t *cert_obj, const char *filename)
 
BOTAN_DLL int botan_x509_cert_not_after (botan_x509_cert_t cert, uint64_t *time_since_epoch)
 
BOTAN_DLL int botan_x509_cert_not_before (botan_x509_cert_t cert, uint64_t *time_since_epoch)
 
BOTAN_DLL int botan_x509_cert_to_string (botan_x509_cert_t cert, char out[], size_t *out_len)
 
BOTAN_DLL const char * botan_x509_cert_validation_status (int code)
 
BOTAN_DLL int botan_x509_cert_verify (int *validation_result, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const char *trusted_path, size_t required_strength, const char *hostname, uint64_t reference_time)
 
BOTAN_DLL int botan_x509_cert_verify_with_crl (int *validation_result, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const botan_x509_crl_t *crls, size_t crls_len, const char *trusted_path, size_t required_strength, const char *hostname, uint64_t reference_time)
 
BOTAN_DLL int botan_x509_cert_view_as_string (botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_str_fn view)
 
BOTAN_DLL int botan_x509_cert_view_public_key_bits (botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_bin_fn view)
 
BOTAN_DLL int botan_x509_crl_destroy (botan_x509_crl_t crl)
 
BOTAN_DLL int botan_x509_crl_load (botan_x509_crl_t *crl_obj, const uint8_t crl_bits[], size_t crl_bits_len)
 
BOTAN_DLL int botan_x509_crl_load_file (botan_x509_crl_t *crl_obj, const char *crl_path)
 
BOTAN_DLL int botan_x509_is_revoked (botan_x509_crl_t crl, botan_x509_cert_t cert)
 
BOTAN_DLL int botan_zfec_decode (size_t K, size_t N, const size_t *indexes, uint8_t *const *inputs, size_t shareSize, uint8_t **outputs)
 
BOTAN_DLL int botan_zfec_encode (size_t K, size_t N, const uint8_t *input, size_t size, uint8_t **outputs)
 

Detailed Description

Public Header.

Definition in file ffi.h.

Macro Definition Documentation

◆ BOTAN_CHECK_KEY_EXPENSIVE_TESTS

#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS   1

Definition at line 1053 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_DECRYPT

#define BOTAN_CIPHER_INIT_FLAG_DECRYPT   1

Definition at line 514 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_ENCRYPT

#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0

Definition at line 513 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION

#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION   1

Definition at line 512 of file ffi.h.

◆ BOTAN_CIPHER_UPDATE_FLAG_FINAL

#define BOTAN_CIPHER_UPDATE_FLAG_FINAL   (1U << 0)

Definition at line 595 of file ffi.h.

◆ BOTAN_FFI_DEPRECATED

#define BOTAN_FFI_DEPRECATED (   msg)

Definition at line 79 of file ffi.h.

◆ BOTAN_FFI_EXPORT

#define BOTAN_FFI_EXPORT (   maj,
  min 
)    BOTAN_DLL

Notes the version that this FFI function was first added

Definition at line 66 of file ffi.h.

◆ BOTAN_FFI_HEX_LOWER_CASE

#define BOTAN_FFI_HEX_LOWER_CASE   1

Definition at line 211 of file ffi.h.

◆ BOTAN_FPE_FLAG_FE1_COMPAT_MODE

#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE   1

Definition at line 1948 of file ffi.h.

◆ BOTAN_PRIVKEY_EXPORT_FLAG_DER

#define BOTAN_PRIVKEY_EXPORT_FLAG_DER   0

Definition at line 1123 of file ffi.h.

◆ BOTAN_PRIVKEY_EXPORT_FLAG_PEM

#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM   1

Definition at line 1124 of file ffi.h.

◆ BOTAN_PUBKEY_DER_FORMAT_SIGNATURE

#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE   1

Definition at line 1535 of file ffi.h.

Typedef Documentation

◆ botan_block_cipher_t

typedef struct botan_block_cipher_struct* botan_block_cipher_t

Definition at line 777 of file ffi.h.

◆ botan_cipher_t

typedef struct botan_cipher_struct* botan_cipher_t

Definition at line 510 of file ffi.h.

◆ botan_fpe_t

typedef struct botan_fpe_struct* botan_fpe_t

Format Preserving Encryption

Definition at line 1946 of file ffi.h.

◆ botan_hash_t

typedef struct botan_hash_struct* botan_hash_t

Definition at line 334 of file ffi.h.

◆ botan_hotp_t

typedef struct botan_hotp_struct* botan_hotp_t

HOTP

Definition at line 1874 of file ffi.h.

◆ botan_mac_t

typedef struct botan_mac_struct* botan_mac_t

Definition at line 414 of file ffi.h.

◆ botan_mp_t

typedef struct botan_mp_struct* botan_mp_t

Definition at line 843 of file ffi.h.

◆ botan_pk_op_decrypt_t

typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t

Definition at line 1514 of file ffi.h.

◆ botan_pk_op_encrypt_t

typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t

Definition at line 1490 of file ffi.h.

◆ botan_pk_op_ka_t

typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t

Definition at line 1576 of file ffi.h.

◆ botan_pk_op_kem_decrypt_t

typedef struct botan_pk_op_kem_decrypt_struct* botan_pk_op_kem_decrypt_t

Definition at line 1635 of file ffi.h.

◆ botan_pk_op_kem_encrypt_t

typedef struct botan_pk_op_kem_encrypt_struct* botan_pk_op_kem_encrypt_t

Definition at line 1605 of file ffi.h.

◆ botan_pk_op_sign_t

typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t

Definition at line 1537 of file ffi.h.

◆ botan_pk_op_verify_t

typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t

Definition at line 1557 of file ffi.h.

◆ botan_privkey_t

typedef struct botan_privkey_struct* botan_privkey_t

Definition at line 1040 of file ffi.h.

◆ botan_pubkey_t

typedef struct botan_pubkey_struct* botan_pubkey_t

Definition at line 1254 of file ffi.h.

◆ botan_rng_t

typedef struct botan_rng_struct* botan_rng_t

RNG type

Definition at line 246 of file ffi.h.

◆ botan_srp6_server_session_t

typedef struct botan_srp6_server_session_struct* botan_srp6_server_session_t

SRP-6 Server Session type

Definition at line 1969 of file ffi.h.

◆ botan_totp_t

typedef struct botan_totp_struct* botan_totp_t

TOTP

Definition at line 1906 of file ffi.h.

◆ botan_view_bin_fn

typedef int(* botan_view_bin_fn) (botan_view_ctx view_ctx, const uint8_t *data, size_t len)

Viewer function for binary data

Parameters
view_ctxsome application context
datathe binary data
lenthe length of data in bytes

Definition at line 129 of file ffi.h.

◆ botan_view_ctx

typedef void* botan_view_ctx

Definition at line 120 of file ffi.h.

◆ botan_view_str_fn

typedef int(* botan_view_str_fn) (botan_view_ctx view_ctx, const char *str, size_t len)

Viewer function for string data

Parameters
view_ctxsome application context
strthe null terminated string
lenthe length of string including the null terminator

Definition at line 138 of file ffi.h.

◆ botan_x509_cert_t

typedef struct botan_x509_cert_struct* botan_x509_cert_t

Definition at line 1699 of file ffi.h.

◆ botan_x509_crl_t

typedef struct botan_x509_crl_struct* botan_x509_crl_t

Definition at line 1797 of file ffi.h.

Enumeration Type Documentation

◆ BOTAN_FFI_ERROR

Error codes

If you add a new value here be sure to also add it in botan_error_description

Enumerator
BOTAN_FFI_SUCCESS 
BOTAN_FFI_INVALID_VERIFIER 
BOTAN_FFI_ERROR_INVALID_INPUT 
BOTAN_FFI_ERROR_BAD_MAC 
BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE 
BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR 
BOTAN_FFI_ERROR_EXCEPTION_THROWN 
BOTAN_FFI_ERROR_OUT_OF_MEMORY 
BOTAN_FFI_ERROR_SYSTEM_ERROR 
BOTAN_FFI_ERROR_INTERNAL_ERROR 
BOTAN_FFI_ERROR_BAD_FLAG 
BOTAN_FFI_ERROR_NULL_POINTER 
BOTAN_FFI_ERROR_BAD_PARAMETER 
BOTAN_FFI_ERROR_KEY_NOT_SET 
BOTAN_FFI_ERROR_INVALID_KEY_LENGTH 
BOTAN_FFI_ERROR_INVALID_OBJECT_STATE 
BOTAN_FFI_ERROR_NOT_IMPLEMENTED 
BOTAN_FFI_ERROR_INVALID_OBJECT 
BOTAN_FFI_ERROR_TLS_ERROR 
BOTAN_FFI_ERROR_HTTP_ERROR 
BOTAN_FFI_ERROR_ROUGHTIME_ERROR 
BOTAN_FFI_ERROR_UNKNOWN_ERROR 

Definition at line 88 of file ffi.h.

88 {
91
94
97
102
109
112
116
118};
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:110
@ BOTAN_FFI_ERROR_INVALID_KEY_LENGTH
Definition ffi.h:107
@ BOTAN_FFI_ERROR_KEY_NOT_SET
Definition ffi.h:106
@ BOTAN_FFI_ERROR_TLS_ERROR
Definition ffi.h:113
@ BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition ffi.h:98
@ BOTAN_FFI_ERROR_OUT_OF_MEMORY
Definition ffi.h:99
@ BOTAN_FFI_ERROR_INTERNAL_ERROR
Definition ffi.h:101
@ BOTAN_FFI_INVALID_VERIFIER
Definition ffi.h:90
@ BOTAN_FFI_ERROR_INVALID_OBJECT
Definition ffi.h:111
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:117
@ BOTAN_FFI_ERROR_HTTP_ERROR
Definition ffi.h:114
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:103
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition ffi.h:92
@ BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR
Definition ffi.h:96
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:104
@ BOTAN_FFI_SUCCESS
Definition ffi.h:89
@ BOTAN_FFI_ERROR_SYSTEM_ERROR
Definition ffi.h:100
@ BOTAN_FFI_ERROR_ROUGHTIME_ERROR
Definition ffi.h:115
@ BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
Definition ffi.h:108
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition ffi.h:95
@ BOTAN_FFI_ERROR_BAD_MAC
Definition ffi.h:93
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:105

◆ botan_x509_cert_key_constraints

Enumerator
NO_CONSTRAINTS 
DIGITAL_SIGNATURE 
NON_REPUDIATION 
KEY_ENCIPHERMENT 
DATA_ENCIPHERMENT 
KEY_AGREEMENT 
KEY_CERT_SIGN 
CRL_SIGN 
ENCIPHER_ONLY 
DECIPHER_ONLY 

Definition at line 1746 of file ffi.h.

1746 {
1747 NO_CONSTRAINTS = 0,
1748 DIGITAL_SIGNATURE = 32768,
1749 NON_REPUDIATION = 16384,
1750 KEY_ENCIPHERMENT = 8192,
1751 DATA_ENCIPHERMENT = 4096,
1752 KEY_AGREEMENT = 2048,
1753 KEY_CERT_SIGN = 1024,
1754 CRL_SIGN = 512,
1755 ENCIPHER_ONLY = 256,
1756 DECIPHER_ONLY = 128
1757};
@ KEY_ENCIPHERMENT
Definition ffi.h:1750
@ NO_CONSTRAINTS
Definition ffi.h:1747
@ CRL_SIGN
Definition ffi.h:1754
@ DIGITAL_SIGNATURE
Definition ffi.h:1748
@ KEY_AGREEMENT
Definition ffi.h:1752
@ DATA_ENCIPHERMENT
Definition ffi.h:1751
@ KEY_CERT_SIGN
Definition ffi.h:1753
@ ENCIPHER_ONLY
Definition ffi.h:1755
@ NON_REPUDIATION
Definition ffi.h:1749
@ DECIPHER_ONLY
Definition ffi.h:1756

Function Documentation

◆ botan_base64_decode()

BOTAN_DLL int botan_base64_decode ( const char *  base64_str,
size_t  in_len,
uint8_t *  out,
size_t *  out_len 
)

Perform base64 decoding

Definition at line 327 of file ffi.cpp.

327 {
328 return ffi_guard_thunk(__func__, [=]() -> int {
329 if(*out_len < Botan::base64_decode_max_output(in_len)) {
330 *out_len = Botan::base64_decode_max_output(in_len);
332 }
333
334 *out_len = Botan::base64_decode(out, std::string(base64_str, in_len));
335 return BOTAN_FFI_SUCCESS;
336 });
337}
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition ffi.cpp:115
size_t base64_decode(uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
Definition base64.cpp:154
size_t base64_decode_max_output(size_t input_length)
Definition base64.cpp:186

References Botan::base64_decode(), Botan::base64_decode_max_output(), BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_SUCCESS, and Botan_FFI::ffi_guard_thunk().

◆ botan_base64_encode()

BOTAN_DLL int botan_base64_encode ( const uint8_t *  x,
size_t  len,
char *  out,
size_t *  out_len 
)

Perform base64 encoding

Definition at line 320 of file ffi.cpp.

320 {
321 return ffi_guard_thunk(__func__, [=]() -> int {
322 const std::string base64 = Botan::base64_encode(in, len);
323 return Botan_FFI::write_str_output(out, out_len, base64);
324 });
325}
int write_str_output(uint8_t out[], size_t *out_len, std::string_view str)
Definition ffi_util.h:205
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition base64.cpp:146

References Botan::base64_encode(), Botan_FFI::ffi_guard_thunk(), and Botan_FFI::write_str_output().

◆ botan_bcrypt_generate()

BOTAN_DLL int botan_bcrypt_generate ( uint8_t *  out,
size_t *  out_len,
const char *  password,
botan_rng_t  rng,
size_t  work_factor,
uint32_t  flags 
)

Create a password hash using Bcrypt

Parameters
outbuffer holding the password hash, should be of length 64 bytes
out_lenthe desired output length in bytes
passwordthe password
rnga random number generator
work_factorhow much work to do to slow down guessing attacks
flagsshould be 0 in current API revision, all other uses are reserved and return BOTAN_FFI_ERROR_BAD_FLAG
Returns
0 on success, a negative value on failure

Output is formatted bcrypt $2a$...

Definition at line 157 of file ffi_kdf.cpp.

158 {
159#if defined(BOTAN_HAS_BCRYPT)
160 return ffi_guard_thunk(__func__, [=]() -> int {
161 if(out == nullptr || out_len == nullptr || pass == nullptr) {
163 }
164
165 if(flags != 0) {
167 }
168
169 if(wf < 4 || wf > 18) {
171 }
172
173 if(*out_len < 61) {
174 *out_len = 61;
176 }
177
179 const std::string bcrypt = Botan::generate_bcrypt(pass, rng, static_cast<uint16_t>(wf));
180 return write_str_output(out, out_len, bcrypt);
181 });
182#else
183 BOTAN_UNUSED(out, out_len, pass, rng_obj, wf, flags);
185#endif
186}
#define BOTAN_UNUSED
Definition assert.h:118
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:63
std::string generate_bcrypt(std::string_view pass, RandomNumberGenerator &rng, uint16_t work_factor, char version)
Definition bcrypt.cpp:144

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::generate_bcrypt(), Botan_FFI::safe_get(), and Botan_FFI::write_str_output().

◆ botan_bcrypt_is_valid()

BOTAN_DLL int botan_bcrypt_is_valid ( const char *  pass,
const char *  hash 
)

Check a previously created password hash

Parameters
passthe password to check against
hashthe stored hash to check against
Returns
0 if if this password/hash combination is valid, 1 if the combination is not valid (but otherwise well formed), negative on error

Definition at line 188 of file ffi_kdf.cpp.

188 {
189#if defined(BOTAN_HAS_BCRYPT)
190 return ffi_guard_thunk(__func__, [=]() -> int {
192 });
193#else
194 BOTAN_UNUSED(pass, hash);
196#endif
197}
bool check_bcrypt(std::string_view pass, std::string_view hash)
Definition bcrypt.cpp:159

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan::check_bcrypt(), and Botan_FFI::ffi_guard_thunk().

◆ botan_block_cipher_block_size()

BOTAN_DLL int botan_block_cipher_block_size ( botan_block_cipher_t  bc)

Return the positive block size of this block cipher, or negative to indicate an error

Definition at line 61 of file ffi_block.cpp.

61 {
62 return BOTAN_FFI_VISIT(bc, [](const auto& b) { return static_cast<int>(b.block_size()); });
63}
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:124

References BOTAN_FFI_VISIT.

◆ botan_block_cipher_clear()

BOTAN_DLL int botan_block_cipher_clear ( botan_block_cipher_t  bc)

Reinitializes the block cipher

Returns
0 on success, a negative value on failure

Definition at line 43 of file ffi_block.cpp.

43 {
44 return BOTAN_FFI_VISIT(bc, [](auto& b) { b.clear(); });
45}

References BOTAN_FFI_VISIT.

◆ botan_block_cipher_decrypt_blocks()

BOTAN_DLL int botan_block_cipher_decrypt_blocks ( botan_block_cipher_t  bc,
const uint8_t  in[],
uint8_t  out[],
size_t  blocks 
)

Decrypt one or more blocks with the cipher

Definition at line 72 of file ffi_block.cpp.

72 {
73 if(in == nullptr || out == nullptr) {
75 }
76 return BOTAN_FFI_VISIT(bc, [=](const auto& b) { b.decrypt_n(in, out, blocks); });
77}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_block_cipher_destroy()

BOTAN_DLL int botan_block_cipher_destroy ( botan_block_cipher_t  bc)

Destroy a block cipher object

Returns
0 if success, error if invalid object handle

Destroy a block cipher object

Definition at line 39 of file ffi_block.cpp.

39 {
40 return BOTAN_FFI_CHECKED_DELETE(bc);
41}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:143

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_block_cipher_encrypt_blocks()

BOTAN_DLL int botan_block_cipher_encrypt_blocks ( botan_block_cipher_t  bc,
const uint8_t  in[],
uint8_t  out[],
size_t  blocks 
)

Encrypt one or more blocks with the cipher

Definition at line 65 of file ffi_block.cpp.

65 {
66 if(in == nullptr || out == nullptr) {
68 }
69 return BOTAN_FFI_VISIT(bc, [=](const auto& b) { b.encrypt_n(in, out, blocks); });
70}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_block_cipher_get_keyspec()

BOTAN_DLL int botan_block_cipher_get_keyspec ( botan_block_cipher_t  cipher,
size_t *  out_minimum_keylength,
size_t *  out_maximum_keylength,
size_t *  out_keylength_modulo 
)

Get the key length limits of this block cipher

Parameters
cipherthe object to read
out_minimum_keylengthif non-NULL, will be set to minimum keylength of cipher
out_maximum_keylengthif non-NULL, will be set to maximum keylength of cipher
out_keylength_moduloif non-NULL will be set to byte multiple of valid keys

Definition at line 87 of file ffi_block.cpp.

90 {
91 return BOTAN_FFI_VISIT(cipher, [=](const auto& bc) {
92 if(out_minimum_keylength)
93 *out_minimum_keylength = bc.minimum_keylength();
94 if(out_maximum_keylength)
95 *out_maximum_keylength = bc.maximum_keylength();
96 if(out_keylength_modulo)
97 *out_keylength_modulo = bc.key_spec().keylength_multiple();
98 });
99}

References BOTAN_FFI_VISIT.

◆ botan_block_cipher_init()

BOTAN_DLL int botan_block_cipher_init ( botan_block_cipher_t bc,
const char *  cipher_name 
)

Initialize a block cipher object

Definition at line 18 of file ffi_block.cpp.

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(bc == nullptr || bc_name == nullptr || *bc_name == 0) {
22 }
23
24 *bc = nullptr;
25
26 auto cipher = Botan::BlockCipher::create(bc_name);
27 if(cipher == nullptr) {
29 }
30
31 *bc = new botan_block_cipher_struct(std::move(cipher));
32 return BOTAN_FFI_SUCCESS;
33 });
34}
static std::unique_ptr< BlockCipher > create(std::string_view algo_spec, std::string_view provider="")

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::BlockCipher::create(), and Botan_FFI::ffi_guard_thunk().

◆ botan_block_cipher_name()

BOTAN_DLL int botan_block_cipher_name ( botan_block_cipher_t  cipher,
char *  name,
size_t *  name_len 
)

Get the name of this block cipher

Parameters
cipherthe object to read
nameoutput buffer
name_lenon input, the length of buffer, on success the number of bytes written

Definition at line 79 of file ffi_block.cpp.

79 {
80 if(name_len == nullptr) {
82 }
83
84 return BOTAN_FFI_VISIT(cipher, [=](const auto& bc) { return write_str_output(name, name_len, bc.name()); });
85}
std::string name

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, name, and Botan_FFI::write_str_output().

◆ botan_block_cipher_set_key()

BOTAN_DLL int botan_block_cipher_set_key ( botan_block_cipher_t  bc,
const uint8_t  key[],
size_t  len 
)

Set the key for a block cipher instance

Definition at line 50 of file ffi_block.cpp.

50 {
51 if(key == nullptr) {
53 }
54 return BOTAN_FFI_VISIT(bc, [=](auto& b) { b.set_key(key, len); });
55}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_cipher_clear()

BOTAN_DLL int botan_cipher_clear ( botan_cipher_t  hash)

Reset the key, nonce, AD and all other state on this cipher object

Definition at line 84 of file ffi_cipher.cpp.

84 {
85 return BOTAN_FFI_VISIT(cipher, [](auto& c) { c.clear(); });
86}

References BOTAN_FFI_VISIT.

◆ botan_cipher_destroy()

BOTAN_DLL int botan_cipher_destroy ( botan_cipher_t  cipher)

Destroy the cipher object

Returns
0 if success, error if invalid object handle

Definition at line 80 of file ffi_cipher.cpp.

80 {
81 return BOTAN_FFI_CHECKED_DELETE(cipher);
82}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_cipher_get_default_nonce_length()

BOTAN_DLL int botan_cipher_get_default_nonce_length ( botan_cipher_t  cipher,
size_t *  nl 
)

Get the default nonce length of this cipher

Definition at line 228 of file ffi_cipher.cpp.

228 {
229 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *nl = c.default_nonce_length(); });
230}

References BOTAN_FFI_VISIT.

◆ botan_cipher_get_ideal_update_granularity()

BOTAN_DLL int botan_cipher_get_ideal_update_granularity ( botan_cipher_t  cipher,
size_t *  ug 
)

Return the ideal update granularity of the cipher. This is some multiple of the update granularity, reflecting possibilities for optimization.

Definition at line 236 of file ffi_cipher.cpp.

236 {
237 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *ug = c.ideal_granularity(); });
238}

References BOTAN_FFI_VISIT.

◆ botan_cipher_get_keyspec()

BOTAN_DLL int botan_cipher_get_keyspec ( botan_cipher_t  cipher,
size_t *  min_keylen,
size_t *  max_keylen,
size_t *  mod_keylen 
)

Get information about the supported key lengths.

Definition at line 107 of file ffi_cipher.cpp.

110 {
111 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) {
112 if(out_minimum_keylength)
113 *out_minimum_keylength = c.key_spec().minimum_keylength();
114 if(out_maximum_keylength)
115 *out_maximum_keylength = c.key_spec().maximum_keylength();
116 if(out_keylength_modulo)
117 *out_keylength_modulo = c.key_spec().keylength_multiple();
118 });
119}

References BOTAN_FFI_VISIT.

◆ botan_cipher_get_tag_length()

BOTAN_DLL int botan_cipher_get_tag_length ( botan_cipher_t  cipher,
size_t *  tag_size 
)

Get the tag length of the cipher (0 for non-AEAD modes)

Definition at line 240 of file ffi_cipher.cpp.

240 {
241 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *tl = c.tag_size(); });
242}

References BOTAN_FFI_VISIT.

◆ botan_cipher_get_update_granularity()

BOTAN_DLL int botan_cipher_get_update_granularity ( botan_cipher_t  cipher,
size_t *  ug 
)

Return the update granularity of the cipher; botan_cipher_update must be called with blocks of this size, except for the final.

Definition at line 232 of file ffi_cipher.cpp.

232 {
233 return BOTAN_FFI_VISIT(cipher, [=](const auto& /*c*/) { *ug = cipher->update_size(); });
234}

References BOTAN_FFI_VISIT.

◆ botan_cipher_init()

BOTAN_DLL int botan_cipher_init ( botan_cipher_t cipher,
const char *  name,
uint32_t  flags 
)

Initialize a cipher object

Definition at line 63 of file ffi_cipher.cpp.

63 {
64 return ffi_guard_thunk(__func__, [=]() -> int {
67
68 std::unique_ptr<Botan::Cipher_Mode> mode(Botan::Cipher_Mode::create(cipher_name, dir));
69 if(!mode) {
71 }
72
73 const size_t update_size = ffi_choose_update_size(*mode);
74
75 *cipher = new botan_cipher_struct(std::move(mode), update_size);
76 return BOTAN_FFI_SUCCESS;
77 });
78}
static std::unique_ptr< Cipher_Mode > create(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT
Definition ffi.h:513
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
Definition ffi.h:512
Flags flags(Flag flags)
Definition p11.h:836

References BOTAN_CIPHER_INIT_FLAG_ENCRYPT, BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, Botan::Cipher_Mode::create(), Botan::Decryption, Botan::Encryption, and Botan_FFI::ffi_guard_thunk().

◆ botan_cipher_name()

BOTAN_DLL int botan_cipher_name ( botan_cipher_t  cipher,
char *  name,
size_t *  name_len 
)

Return the name of the cipher object

Definition at line 244 of file ffi_cipher.cpp.

244 {
245 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return write_str_output(name, name_len, c.name()); });
246}

References BOTAN_FFI_VISIT, name, and Botan_FFI::write_str_output().

◆ botan_cipher_output_length()

BOTAN_DLL int botan_cipher_output_length ( botan_cipher_t  cipher,
size_t  in_len,
size_t *  out_len 
)

Return the output length of this cipher, for a particular input length.

Definition at line 92 of file ffi_cipher.cpp.

92 {
93 if(out_len == nullptr) {
95 }
96
97 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *out_len = c.output_length(in_len); });
98}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_cipher_query_keylen()

BOTAN_DLL int botan_cipher_query_keylen ( botan_cipher_t  cipher,
size_t *  out_minimum_keylength,
size_t *  out_maximum_keylength 
)

Get information about the key lengths. Prefer botan_cipher_get_keyspec

Definition at line 100 of file ffi_cipher.cpp.

100 {
101 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) {
102 *out_minimum_keylength = c.key_spec().minimum_keylength();
103 *out_maximum_keylength = c.key_spec().maximum_keylength();
104 });
105}

References BOTAN_FFI_VISIT.

◆ botan_cipher_reset()

BOTAN_DLL int botan_cipher_reset ( botan_cipher_t  cipher)

Reset the message specific state for this cipher. Without resetting the keys, this resets the nonce, and any state associated with any message bits that have been processed so far.

It is conceptually equivalent to calling botan_cipher_clear followed by botan_cipher_set_key with the original key.

Definition at line 88 of file ffi_cipher.cpp.

88 {
89 return BOTAN_FFI_VISIT(cipher, [](auto& c) { c.reset(); });
90}

References BOTAN_FFI_VISIT.

◆ botan_cipher_set_associated_data()

BOTAN_DLL int botan_cipher_set_associated_data ( botan_cipher_t  cipher,
const uint8_t *  ad,
size_t  ad_len 
)

Set the associated data. Will fail if cipher is not an AEAD

Definition at line 214 of file ffi_cipher.cpp.

214 {
215 return BOTAN_FFI_VISIT(cipher, [=](auto& c) {
216 if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(&c)) {
217 aead->set_associated_data(ad, ad_len);
218 return BOTAN_FFI_SUCCESS;
219 }
221 });
222}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_cipher_set_key()

BOTAN_DLL int botan_cipher_set_key ( botan_cipher_t  cipher,
const uint8_t *  key,
size_t  key_len 
)

Set the key for this cipher object

Definition at line 121 of file ffi_cipher.cpp.

121 {
122 return BOTAN_FFI_VISIT(cipher, [=](auto& c) { c.set_key(key, key_len); });
123}

References BOTAN_FFI_VISIT.

◆ botan_cipher_start()

BOTAN_DLL int botan_cipher_start ( botan_cipher_t  cipher,
const uint8_t *  nonce,
size_t  nonce_len 
)

Begin processing a new message using the provided nonce

Definition at line 125 of file ffi_cipher.cpp.

125 {
126 return ffi_guard_thunk(__func__, [=]() -> int {
127 Botan::Cipher_Mode& cipher = safe_get(cipher_obj);
128 cipher.start(nonce, nonce_len);
129 return BOTAN_FFI_SUCCESS;
130 });
131}
void start(std::span< const uint8_t > nonce)
Definition cipher_mode.h:89

References BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::Cipher_Mode::start().

◆ botan_cipher_update()

BOTAN_DLL int botan_cipher_update ( botan_cipher_t  cipher,
uint32_t  flags,
uint8_t  output[],
size_t  output_size,
size_t *  output_written,
const uint8_t  input_bytes[],
size_t  input_size,
size_t *  input_consumed 
)

Encrypt some data

Definition at line 133 of file ffi_cipher.cpp.

140 {
141 return ffi_guard_thunk(__func__, [=]() -> int {
142 size_t input_size = orig_input_size;
143 size_t output_size = orig_output_size;
144 const uint8_t* input = input_ptr;
145 uint8_t* output = output_ptr;
146
147 using namespace Botan;
148 Cipher_Mode& cipher = safe_get(cipher_obj);
149 secure_vector<uint8_t>& mbuf = cipher_obj->buf();
150
151 const bool final_input = (flags & BOTAN_CIPHER_UPDATE_FLAG_FINAL);
152
153 if(final_input) {
154 mbuf.assign(input, input + input_size);
155 *input_consumed = input_size;
156 *output_written = 0;
157
158 try {
159 cipher.finish(mbuf);
162 }
163
164 *output_written = mbuf.size();
165
166 if(mbuf.size() <= output_size) {
167 copy_mem(output, mbuf.data(), mbuf.size());
168 mbuf.clear();
169 return BOTAN_FFI_SUCCESS;
170 }
171
172 return -1;
173 }
174
175 if(input_size == 0) {
176 // Currently must take entire buffer in this case
177 *output_written = mbuf.size();
178 if(output_size >= mbuf.size()) {
179 copy_mem(output, mbuf.data(), mbuf.size());
180 mbuf.clear();
181 return BOTAN_FFI_SUCCESS;
182 }
183
184 return -1;
185 }
186
187 const size_t ud = cipher_obj->update_size();
188
189 mbuf.resize(ud);
190 size_t taken = 0, written = 0;
191
192 while(input_size >= ud && output_size >= ud) {
193 // FIXME we can use process here and avoid the copy
194 copy_mem(mbuf.data(), input, ud);
195 cipher.update(mbuf);
196
197 input_size -= ud;
198 copy_mem(output, mbuf.data(), ud);
199 input += ud;
200 taken += ud;
201
202 output_size -= ud;
203 output += ud;
204 written += ud;
205 }
206
207 *output_written = written;
208 *input_consumed = taken;
209
210 return BOTAN_FFI_SUCCESS;
211 });
212}
void finish(secure_vector< uint8_t > &final_block, size_t offset=0)
void update(T &buffer, size_t offset=0)
#define BOTAN_CIPHER_UPDATE_FLAG_FINAL
Definition ffi.h:595
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:120
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61

References BOTAN_CIPHER_UPDATE_FLAG_FINAL, BOTAN_FFI_ERROR_BAD_MAC, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan::Cipher_Mode::finish(), Botan_FFI::safe_get(), and Botan::Cipher_Mode::update().

◆ botan_cipher_valid_nonce_length()

BOTAN_DLL int botan_cipher_valid_nonce_length ( botan_cipher_t  cipher,
size_t  nl 
)

Return if the specified nonce length is valid for this cipher

Definition at line 224 of file ffi_cipher.cpp.

224 {
225 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.valid_nonce_length(nl) ? 1 : 0; });
226}

References BOTAN_FFI_VISIT.

◆ botan_constant_time_compare()

BOTAN_DLL int botan_constant_time_compare ( const uint8_t *  x,
const uint8_t *  y,
size_t  len 
)

Returns 0 if x[0..len] == y[0..len], or otherwise -1

Definition at line 292 of file ffi.cpp.

292 {
293 return Botan::constant_time_compare(x, y, len) ? 0 : -1;
294}
bool constant_time_compare(const uint8_t x[], const uint8_t y[], size_t len)
Definition mem_ops.h:80

References Botan::constant_time_compare().

Referenced by botan_same_mem().

◆ botan_error_description()

BOTAN_DLL const char * botan_error_description ( int  err)

Convert an error code into a string. Returns "Unknown error" if the error code is not a known one.

Definition at line 145 of file ffi.cpp.

145 {
146 switch(err) {
148 return "OK";
149
151 return "Invalid verifier";
152
154 return "Invalid input";
155
157 return "Invalid authentication code";
158
160 return "Insufficient buffer space";
161
163 return "String conversion error";
164
166 return "Exception thrown";
167
169 return "Out of memory";
170
172 return "Error while calling system API";
173
175 return "Internal error";
176
178 return "Bad flag";
179
181 return "Null pointer argument";
182
184 return "Bad parameter";
185
187 return "Key not set on object";
188
190 return "Invalid key length";
191
193 return "Invalid object state";
194
196 return "Not implemented";
197
199 return "Invalid object handle";
200
202 return "TLS error";
203
205 return "HTTP error";
206
208 return "Unknown error";
209
210 default:
211 return "Unknown error";
212 }
213}

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_BAD_MAC, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_EXCEPTION_THROWN, BOTAN_FFI_ERROR_HTTP_ERROR, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_INTERNAL_ERROR, BOTAN_FFI_ERROR_INVALID_INPUT, BOTAN_FFI_ERROR_INVALID_KEY_LENGTH, BOTAN_FFI_ERROR_INVALID_OBJECT, BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, BOTAN_FFI_ERROR_KEY_NOT_SET, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_MEMORY, BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR, BOTAN_FFI_ERROR_SYSTEM_ERROR, BOTAN_FFI_ERROR_TLS_ERROR, BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_FFI_INVALID_VERIFIER, and BOTAN_FFI_SUCCESS.

◆ botan_error_last_exception_message()

BOTAN_DLL const char * botan_error_last_exception_message ( void  )

Return the message of the last exception caught in this thread.

This pointer can/will be reallocated or overwritten the next time this thread calls any other Botan FFI function and must be copied to persistent storage first.

Definition at line 141 of file ffi.cpp.

141 {
142 return g_last_exception_what.c_str();
143}
thread_local std::string g_last_exception_what
Definition ffi.cpp:21

References Botan_FFI::g_last_exception_what.

◆ botan_ffi_api_version()

BOTAN_DLL uint32_t botan_ffi_api_version ( void  )

Return the version of the currently supported FFI API. This is expressed in the form YYYYMMDD of the release date of this version of the API.

Definition at line 218 of file ffi.cpp.

218 {
219 return BOTAN_HAS_FFI;
220}
#define BOTAN_HAS_FFI
Definition build.h:215

References BOTAN_HAS_FFI.

◆ botan_ffi_supports_api()

BOTAN_DLL int botan_ffi_supports_api ( uint32_t  api_version)

Return 0 (ok) if the version given is one this library supports. botan_ffi_supports_api(botan_ffi_api_version()) will always return 0.

Definition at line 222 of file ffi.cpp.

222 {
223 // This is the API introduced in 3.2
224 if(api_version == 20231009) {
225 return BOTAN_FFI_SUCCESS;
226 }
227
228 // This is the API introduced in 3.1
229 if(api_version == 20230711) {
230 return BOTAN_FFI_SUCCESS;
231 }
232
233 // This is the API introduced in 3.0
234 if(api_version == 20230403) {
235 return BOTAN_FFI_SUCCESS;
236 }
237
238 // This is the API introduced in 2.18
239 if(api_version == 20210220) {
240 return BOTAN_FFI_SUCCESS;
241 }
242
243 // This is the API introduced in 2.13
244 if(api_version == 20191214) {
245 return BOTAN_FFI_SUCCESS;
246 }
247
248 // This is the API introduced in 2.8
249 if(api_version == 20180713) {
250 return BOTAN_FFI_SUCCESS;
251 }
252
253 // This is the API introduced in 2.3
254 if(api_version == 20170815) {
255 return BOTAN_FFI_SUCCESS;
256 }
257
258 // This is the API introduced in 2.1
259 if(api_version == 20170327) {
260 return BOTAN_FFI_SUCCESS;
261 }
262
263 // This is the API introduced in 2.0
264 if(api_version == 20150515) {
265 return BOTAN_FFI_SUCCESS;
266 }
267
268 // Something else:
269 return -1;
270}

References BOTAN_FFI_SUCCESS.

◆ botan_fpe_decrypt()

BOTAN_DLL int botan_fpe_decrypt ( botan_fpe_t  fpe,
botan_mp_t  x,
const uint8_t  tweak[],
size_t  tweak_len 
)

Definition at line 78 of file ffi_fpe.cpp.

78 {
79#if defined(BOTAN_HAS_FPE_FE1)
80 return ffi_guard_thunk(__func__, [=]() {
81 Botan::BigInt r = safe_get(fpe).decrypt(safe_get(x), tweak, tweak_len);
82 safe_get(x) = r;
83 return BOTAN_FFI_SUCCESS;
84 });
85
86#else
87 BOTAN_UNUSED(fpe, x, tweak, tweak_len);
89#endif
90}

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

◆ botan_fpe_destroy()

BOTAN_DLL int botan_fpe_destroy ( botan_fpe_t  fpe)
Returns
0 if success, error if invalid object handle

Definition at line 56 of file ffi_fpe.cpp.

56 {
57#if defined(BOTAN_HAS_FPE_FE1)
58 return BOTAN_FFI_CHECKED_DELETE(fpe);
59#else
60 BOTAN_UNUSED(fpe);
62#endif
63}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_fpe_encrypt()

BOTAN_DLL int botan_fpe_encrypt ( botan_fpe_t  fpe,
botan_mp_t  x,
const uint8_t  tweak[],
size_t  tweak_len 
)

Definition at line 65 of file ffi_fpe.cpp.

65 {
66#if defined(BOTAN_HAS_FPE_FE1)
67 return ffi_guard_thunk(__func__, [=]() {
68 Botan::BigInt r = safe_get(fpe).encrypt(safe_get(x), tweak, tweak_len);
69 safe_get(x) = r;
70 return BOTAN_FFI_SUCCESS;
71 });
72#else
73 BOTAN_UNUSED(fpe, x, tweak, tweak_len);
75#endif
76}

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

◆ botan_fpe_fe1_init()

BOTAN_DLL int botan_fpe_fe1_init ( botan_fpe_t fpe,
botan_mp_t  n,
const uint8_t  key[],
size_t  key_len,
size_t  rounds,
uint32_t  flags 
)

Definition at line 27 of file ffi_fpe.cpp.

28 {
29#if defined(BOTAN_HAS_FPE_FE1)
30 return ffi_guard_thunk(__func__, [=]() {
31 if(fpe == nullptr || key == nullptr) {
33 }
34
35 *fpe = nullptr;
36
37 if(flags != 0 && flags != BOTAN_FPE_FLAG_FE1_COMPAT_MODE) {
39 }
40
41 const bool compat_mode = (flags & BOTAN_FPE_FLAG_FE1_COMPAT_MODE);
42
43 std::unique_ptr<Botan::FPE_FE1> fpe_obj(new Botan::FPE_FE1(safe_get(n), rounds, compat_mode));
44
45 fpe_obj->set_key(key, key_len);
46
47 *fpe = new botan_fpe_struct(std::move(fpe_obj));
48 return BOTAN_FFI_SUCCESS;
49 });
50#else
51 BOTAN_UNUSED(fpe, n, key, key_len, rounds, flags);
53#endif
54}
#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE
Definition ffi.h:1948

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

◆ botan_hash_block_size()

BOTAN_DLL int botan_hash_block_size ( botan_hash_t  hash,
size_t *  block_size 
)

Writes the block size of the hash function to *block_size

Parameters
hashhash object
block_sizeoutput buffer to hold the hash function output length
Returns
0 on success, a negative value on failure

Definition at line 48 of file ffi_hash.cpp.

48 {
49 if(out == nullptr) {
51 }
52 return BOTAN_FFI_VISIT(hash, [=](const auto& h) { *out = h.hash_block_size(); });
53}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_hash_clear()

BOTAN_DLL int botan_hash_clear ( botan_hash_t  hash)

Reinitializes the state of the hash computation. A hash can be computed (with update/final) immediately.

Parameters
hashhash object
Returns
0 on success, a negative value on failure

Definition at line 55 of file ffi_hash.cpp.

55 {
56 return BOTAN_FFI_VISIT(hash, [](auto& h) { h.clear(); });
57}

References BOTAN_FFI_VISIT.

◆ botan_hash_copy_state()

BOTAN_DLL int botan_hash_copy_state ( botan_hash_t dest,
botan_hash_t  source 
)

Copy the state of a hash function object

Parameters
destdestination hash object
sourcesource hash object
Returns
0 on success, a negative value on failure

Definition at line 78 of file ffi_hash.cpp.

78 {
79 return BOTAN_FFI_VISIT(source, [=](const auto& src) { *dest = new botan_hash_struct(src.copy_state()); });
80}

References BOTAN_FFI_VISIT.

◆ botan_hash_destroy()

BOTAN_DLL int botan_hash_destroy ( botan_hash_t  hash)

Frees all resources of the hash object

Parameters
hashhash object
Returns
0 if success, error if invalid object handle

Definition at line 37 of file ffi_hash.cpp.

37 {
38 return BOTAN_FFI_CHECKED_DELETE(hash);
39}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_hash_final()

BOTAN_DLL int botan_hash_final ( botan_hash_t  hash,
uint8_t  out[] 
)

Finalizes the hash computation and writes the output to out[0:botan_hash_output_length()] then reinitializes for computing another digest as if botan_hash_clear had been called.

Parameters
hashhash object
outoutput buffer
Returns
0 on success, a negative value on failure

Definition at line 71 of file ffi_hash.cpp.

71 {
72 if(out == nullptr) {
74 }
75 return BOTAN_FFI_VISIT(hash, [=](auto& h) { h.final(out); });
76}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_hash_init()

BOTAN_DLL int botan_hash_init ( botan_hash_t hash,
const char *  hash_name,
uint32_t  flags 
)

Initialize a hash function object

Parameters
hashhash object
hash_namename of the hash function, e.g., "SHA-384"
flagsshould be 0 in current API revision, all other uses are reserved and return BOTAN_FFI_ERROR_BAD_FLAG

Definition at line 18 of file ffi_hash.cpp.

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(hash == nullptr || hash_name == nullptr || *hash_name == 0) {
22 }
23 if(flags != 0) {
25 }
26
27 auto h = Botan::HashFunction::create(hash_name);
28 if(h == nullptr) {
30 }
31
32 *hash = new botan_hash_struct(std::move(h));
33 return BOTAN_FFI_SUCCESS;
34 });
35}
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:103

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::HashFunction::create(), and Botan_FFI::ffi_guard_thunk().

◆ botan_hash_name()

BOTAN_DLL int botan_hash_name ( botan_hash_t  hash,
char *  name,
size_t *  name_len 
)

Get the name of this hash function

Parameters
hashthe object to read
nameoutput buffer
name_lenon input, the length of buffer, on success the number of bytes written

Definition at line 82 of file ffi_hash.cpp.

82 {
83 if(name_len == nullptr) {
85 }
86
87 return BOTAN_FFI_VISIT(hash, [=](const auto& h) { return write_str_output(name, name_len, h.name()); });
88}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, name, and Botan_FFI::write_str_output().

◆ botan_hash_output_length()

BOTAN_DLL int botan_hash_output_length ( botan_hash_t  hash,
size_t *  output_length 
)

Writes the output length of the hash function to *output_length

Parameters
hashhash object
output_lengthoutput buffer to hold the hash function output length
Returns
0 on success, a negative value on failure

Definition at line 41 of file ffi_hash.cpp.

41 {
42 if(out == nullptr) {
44 }
45 return BOTAN_FFI_VISIT(hash, [=](const auto& h) { *out = h.output_length(); });
46}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_hash_update()

BOTAN_DLL int botan_hash_update ( botan_hash_t  hash,
const uint8_t *  in,
size_t  in_len 
)

Send more input to the hash function

Parameters
hashhash object
ininput buffer
in_lennumber of bytes to read from the input buffer
Returns
0 on success, a negative value on failure

Definition at line 59 of file ffi_hash.cpp.

59 {
60 if(len == 0) {
61 return 0;
62 }
63
64 if(buf == nullptr) {
66 }
67
68 return BOTAN_FFI_VISIT(hash, [=](auto& h) { h.update(buf, len); });
69}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_hex_decode()

BOTAN_DLL int botan_hex_decode ( const char *  hex_str,
size_t  in_len,
uint8_t *  out,
size_t *  out_len 
)

Perform hex decoding

Parameters
hex_stra string of hex chars (whitespace is ignored)
in_lenthe length of hex_str
outthe output buffer should be at least strlen(hex_str)/2 bytes
out_lenthe size of the output buffer on input, set to the number of bytes written
Returns
0 on success, a negative value on failure

Definition at line 313 of file ffi.cpp.

313 {
314 return ffi_guard_thunk(__func__, [=]() -> int {
315 const std::vector<uint8_t> bin = Botan::hex_decode(hex_str, in_len);
316 return Botan_FFI::write_vec_output(out, out_len, bin);
317 });
318}
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:201
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition hex.cpp:81

References Botan_FFI::ffi_guard_thunk(), Botan::hex_decode(), and Botan_FFI::write_vec_output().

◆ botan_hex_encode()

BOTAN_DLL int botan_hex_encode ( const uint8_t *  x,
size_t  len,
char *  out,
uint32_t  flags 
)

Perform hex encoding

Parameters
xis some binary data
lenlength of x in bytes
outan array of at least x*2 bytes
flagsflags out be upper or lower case?
Returns
0 on success, a negative value on failure

Definition at line 305 of file ffi.cpp.

305 {
306 return ffi_guard_thunk(__func__, [=]() -> int {
307 const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
308 Botan::hex_encode(out, in, len, uppercase);
309 return BOTAN_FFI_SUCCESS;
310 });
311}
#define BOTAN_FFI_HEX_LOWER_CASE
Definition ffi.h:211
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition hex.cpp:33

References BOTAN_FFI_HEX_LOWER_CASE, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan::hex_encode().

◆ botan_hotp_check()

BOTAN_DLL int botan_hotp_check ( botan_hotp_t  hotp,
uint64_t *  next_hotp_counter,
uint32_t  hotp_code,
uint64_t  hotp_counter,
size_t  resync_range 
)

Verify a HOTP code

Definition at line 68 of file ffi_hotp.cpp.

69 {
70#if defined(BOTAN_HAS_HOTP)
71 return BOTAN_FFI_VISIT(hotp, [=](auto& h) {
72 auto resp = h.verify_hotp(hotp_code, hotp_counter, resync_range);
73
74 if(next_hotp_counter)
75 *next_hotp_counter = resp.second;
76
77 return (resp.first == true) ? BOTAN_FFI_SUCCESS : BOTAN_FFI_INVALID_VERIFIER;
78 });
79
80#else
81 BOTAN_UNUSED(hotp, next_hotp_counter, hotp_code, hotp_counter, resync_range);
83#endif
84}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_hotp_destroy()

BOTAN_DLL int botan_hotp_destroy ( botan_hotp_t  hotp)

Destroy a HOTP instance

Returns
0 if success, error if invalid object handle

Definition at line 45 of file ffi_hotp.cpp.

45 {
46#if defined(BOTAN_HAS_HOTP)
47 return BOTAN_FFI_CHECKED_DELETE(hotp);
48#else
49 BOTAN_UNUSED(hotp);
51#endif
52}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_hotp_generate()

BOTAN_DLL int botan_hotp_generate ( botan_hotp_t  hotp,
uint32_t *  hotp_code,
uint64_t  hotp_counter 
)

Generate a HOTP code for the provided counter

Definition at line 54 of file ffi_hotp.cpp.

54 {
55#if defined(BOTAN_HAS_HOTP)
56 if(hotp == nullptr || hotp_code == nullptr) {
58 }
59
60 return BOTAN_FFI_VISIT(hotp, [=](auto& h) { *hotp_code = h.generate_hotp(hotp_counter); });
61
62#else
63 BOTAN_UNUSED(hotp, hotp_code, hotp_counter);
65#endif
66}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_hotp_init()

BOTAN_DLL int botan_hotp_init ( botan_hotp_t hotp,
const uint8_t  key[],
size_t  key_len,
const char *  hash_algo,
size_t  digits 
)

Initialize a HOTP instance

Definition at line 25 of file ffi_hotp.cpp.

25 {
26 if(hotp == nullptr || key == nullptr || hash_algo == nullptr) {
28 }
29
30 *hotp = nullptr;
31
32#if defined(BOTAN_HAS_HOTP)
33 return ffi_guard_thunk(__func__, [=]() -> int {
34 auto otp = std::make_unique<Botan::HOTP>(key, key_len, hash_algo, digits);
35 *hotp = new botan_hotp_struct(std::move(otp));
36
37 return BOTAN_FFI_SUCCESS;
38 });
39#else
40 BOTAN_UNUSED(hotp, key, key_len, hash_algo, digits);
42#endif
43}

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

◆ botan_kdf()

BOTAN_DLL int botan_kdf ( const char *  kdf_algo,
uint8_t  out[],
size_t  out_len,
const uint8_t  secret[],
size_t  secret_len,
const uint8_t  salt[],
size_t  salt_len,
const uint8_t  label[],
size_t  label_len 
)

Derive a key

Parameters
kdf_algoKDF algorithm, e.g., "SP800-56C"
outbuffer holding the derived key, must be of length out_len
out_lenthe desired output length in bytes
secretthe secret input
secret_lensize of secret in bytes
salta diversifier
salt_lensize of salt in bytes
labelpurpose for the derived keying material
label_lensize of label in bytes
Returns
0 on success, a negative value on failure

Definition at line 130 of file ffi_kdf.cpp.

138 {
139 return ffi_guard_thunk(__func__, [=]() -> int {
140 auto kdf = Botan::KDF::create_or_throw(kdf_algo);
141 kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
142 return BOTAN_FFI_SUCCESS;
143 });
144}
static std::unique_ptr< KDF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition kdf.cpp:193

References BOTAN_FFI_SUCCESS, Botan::KDF::create_or_throw(), and Botan_FFI::ffi_guard_thunk().

◆ botan_key_unwrap3394()

BOTAN_DLL int botan_key_unwrap3394 ( const uint8_t  wrapped_key[],
size_t  wrapped_key_len,
const uint8_t  kek[],
size_t  kek_len,
uint8_t  key[],
size_t *  key_len 
)

Definition at line 97 of file ffi_keywrap.cpp.

102 {
103 std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
104
105 return botan_nist_kw_dec(cipher_name.c_str(), 0, wrapped_key, wrapped_key_len, kek, kek_len, key, key_len);
106}
int botan_nist_kw_dec(const char *cipher_algo, int padded, const uint8_t wrapped_key[], size_t wrapped_key_len, const uint8_t kek[], size_t kek_len, uint8_t key[], size_t *key_len)

References botan_nist_kw_dec().

◆ botan_key_wrap3394()

BOTAN_DLL int botan_key_wrap3394 ( const uint8_t  key[],
size_t  key_len,
const uint8_t  kek[],
size_t  kek_len,
uint8_t  wrapped_key[],
size_t *  wrapped_key_len 
)

Key wrapping as per RFC 3394

Definition at line 86 of file ffi_keywrap.cpp.

91 {
92 std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
93
94 return botan_nist_kw_enc(cipher_name.c_str(), 0, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
95}
int botan_nist_kw_enc(const char *cipher_algo, int padded, const uint8_t key[], size_t key_len, const uint8_t kek[], size_t kek_len, uint8_t wrapped_key[], size_t *wrapped_key_len)

References botan_nist_kw_enc().

◆ botan_mac_clear()

BOTAN_DLL int botan_mac_clear ( botan_mac_t  mac)

Reinitializes the state of the MAC computation. A MAC can be computed (with update/final) immediately.

Parameters
macmac object
Returns
0 on success, a negative value on failure

Definition at line 51 of file ffi_mac.cpp.

51 {
52 return BOTAN_FFI_VISIT(mac, [](auto& m) { m.clear(); });
53}

References BOTAN_FFI_VISIT.

◆ botan_mac_destroy()

BOTAN_DLL int botan_mac_destroy ( botan_mac_t  mac)

Frees all resources of the MAC object

Parameters
macmac object
Returns
0 if success, error if invalid object handle

Definition at line 35 of file ffi_mac.cpp.

35 {
36 return BOTAN_FFI_CHECKED_DELETE(mac);
37}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_mac_final()

BOTAN_DLL int botan_mac_final ( botan_mac_t  mac,
uint8_t  out[] 
)

Finalizes the MAC computation and writes the output to out[0:botan_mac_output_length()] then reinitializes for computing another MAC as if botan_mac_clear had been called.

Parameters
macmac object
outoutput buffer
Returns
0 on success, a negative value on failure

Definition at line 59 of file ffi_mac.cpp.

59 {
60 return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.final(out); });
61}

References BOTAN_FFI_VISIT.

◆ botan_mac_get_keyspec()

BOTAN_DLL int botan_mac_get_keyspec ( botan_mac_t  mac,
size_t *  out_minimum_keylength,
size_t *  out_maximum_keylength,
size_t *  out_keylength_modulo 
)

Get the key length limits of this auth code

Parameters
macthe object to read
out_minimum_keylengthif non-NULL, will be set to minimum keylength of MAC
out_maximum_keylengthif non-NULL, will be set to maximum keylength of MAC
out_keylength_moduloif non-NULL will be set to byte multiple of valid keys

Definition at line 67 of file ffi_mac.cpp.

70 {
71 return BOTAN_FFI_VISIT(mac, [=](auto& m) {
72 if(out_minimum_keylength)
73 *out_minimum_keylength = m.minimum_keylength();
74 if(out_maximum_keylength)
75 *out_maximum_keylength = m.maximum_keylength();
76 if(out_keylength_modulo)
77 *out_keylength_modulo = m.key_spec().keylength_multiple();
78 });
79}

References BOTAN_FFI_VISIT.

◆ botan_mac_init()

BOTAN_DLL int botan_mac_init ( botan_mac_t mac,
const char *  mac_name,
uint32_t  flags 
)

Initialize a message authentication code object

Parameters
macmac object
mac_namename of the hash function, e.g., "HMAC(SHA-384)"
flagsshould be 0 in current API revision, all other uses are reserved and return a negative value (error code)
Returns
0 on success, a negative value on failure

Definition at line 18 of file ffi_mac.cpp.

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(!mac || !mac_name || flags != 0) {
22 }
23
24 std::unique_ptr<Botan::MessageAuthenticationCode> m = Botan::MessageAuthenticationCode::create(mac_name);
25
26 if(m == nullptr) {
28 }
29
30 *mac = new botan_mac_struct(std::move(m));
31 return BOTAN_FFI_SUCCESS;
32 });
33}
static std::unique_ptr< MessageAuthenticationCode > create(std::string_view algo_spec, std::string_view provider="")
Definition mac.cpp:50

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::MessageAuthenticationCode::create(), and Botan_FFI::ffi_guard_thunk().

◆ botan_mac_name()

BOTAN_DLL int botan_mac_name ( botan_mac_t  mac,
char *  name,
size_t *  name_len 
)

Get the name of this MAC

Parameters
macthe object to read
nameoutput buffer
name_lenon input, the length of buffer, on success the number of bytes written

Definition at line 63 of file ffi_mac.cpp.

63 {
64 return BOTAN_FFI_VISIT(mac, [=](const auto& m) { return write_str_output(name, name_len, m.name()); });
65}

References BOTAN_FFI_VISIT, name, and Botan_FFI::write_str_output().

◆ botan_mac_output_length()

BOTAN_DLL int botan_mac_output_length ( botan_mac_t  mac,
size_t *  output_length 
)

Writes the output length of the message authentication code to *output_length

Parameters
macmac object
output_lengthoutput buffer to hold the MAC output length
Returns
0 on success, a negative value on failure

Definition at line 47 of file ffi_mac.cpp.

47 {
48 return BOTAN_FFI_VISIT(mac, [=](const auto& m) { *out = m.output_length(); });
49}

References BOTAN_FFI_VISIT.

◆ botan_mac_set_key()

BOTAN_DLL int botan_mac_set_key ( botan_mac_t  mac,
const uint8_t *  key,
size_t  key_len 
)

Sets the key on the MAC

Parameters
macmac object
keybuffer holding the key
key_lensize of the key buffer in bytes
Returns
0 on success, a negative value on failure

Definition at line 39 of file ffi_mac.cpp.

39 {
40 return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.set_key(key, key_len); });
41}

References BOTAN_FFI_VISIT.

◆ botan_mac_set_nonce()

BOTAN_DLL int botan_mac_set_nonce ( botan_mac_t  mac,
const uint8_t *  nonce,
size_t  nonce_len 
)

Sets the nonce on the MAC

Parameters
macmac object
noncebuffer holding the key
nonce_lensize of the key buffer in bytes
Returns
0 on success, a negative value on failure

Definition at line 43 of file ffi_mac.cpp.

43 {
44 return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.start(nonce, nonce_len); });
45}

References BOTAN_FFI_VISIT.

◆ botan_mac_update()

BOTAN_DLL int botan_mac_update ( botan_mac_t  mac,
const uint8_t *  buf,
size_t  len 
)

Send more input to the message authentication code

Parameters
macmac object
bufinput buffer
lennumber of bytes to read from the input buffer
Returns
0 on success, a negative value on failure

Definition at line 55 of file ffi_mac.cpp.

55 {
56 return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.update(buf, len); });
57}

References BOTAN_FFI_VISIT.

◆ botan_mceies_decrypt()

BOTAN_DLL int botan_mceies_decrypt ( botan_privkey_t  mce_key,
const char *  aead,
const uint8_t  ct[],
size_t  ct_len,
const uint8_t  ad[],
size_t  ad_len,
uint8_t  pt[],
size_t *  pt_len 
)

Definition at line 907 of file ffi_pkey_algs.cpp.

914 {
915 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
917}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_mceies_encrypt()

BOTAN_DLL int botan_mceies_encrypt ( botan_pubkey_t  mce_key,
botan_rng_t  rng,
const char *  aead,
const uint8_t  pt[],
size_t  pt_len,
const uint8_t  ad[],
size_t  ad_len,
uint8_t  ct[],
size_t *  ct_len 
)

Definition at line 919 of file ffi_pkey_algs.cpp.

927 {
928 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
930}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_mp_add()

BOTAN_DLL int botan_mp_add ( botan_mp_t  result,
botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 116 of file ffi_mp.cpp.

116 {
117 return BOTAN_FFI_VISIT(result, [=](auto& res) {
118 if(result == x)
119 res += safe_get(y);
120 else
121 res = safe_get(x) + safe_get(y);
122 });
123}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_add_u32()

BOTAN_DLL int botan_mp_add_u32 ( botan_mp_t  result,
botan_mp_t  x,
uint32_t  y 
)

Definition at line 134 of file ffi_mp.cpp.

134 {
135 return BOTAN_FFI_VISIT(result, [=](auto& res) {
136 if(result == x)
137 res += static_cast<Botan::word>(y);
138 else
139 res = safe_get(x) + static_cast<Botan::word>(y);
140 });
141}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_clear()

BOTAN_DLL int botan_mp_clear ( botan_mp_t  mp)

Set the MPI to zero

Definition at line 33 of file ffi_mp.cpp.

33 {
34 return BOTAN_FFI_VISIT(mp, [](auto& bn) { bn.clear(); });
35}

References BOTAN_FFI_VISIT.

◆ botan_mp_clear_bit()

BOTAN_DLL int botan_mp_clear_bit ( botan_mp_t  n,
size_t  bit 
)

Clear the specified bit

Definition at line 243 of file ffi_mp.cpp.

243 {
244 return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.clear_bit(bit); });
245}

References BOTAN_FFI_VISIT.

◆ botan_mp_cmp()

BOTAN_DLL int botan_mp_cmp ( int *  result,
botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 185 of file ffi_mp.cpp.

185 {
186 return BOTAN_FFI_VISIT(x_w, [=](auto& x) { *result = x.cmp(safe_get(y_w)); });
187}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_destroy()

BOTAN_DLL int botan_mp_destroy ( botan_mp_t  mp)

Destroy (deallocate) an MPI

Returns
0 if success, error if invalid object handle

Definition at line 112 of file ffi_mp.cpp.

112 {
113 return BOTAN_FFI_CHECKED_DELETE(mp);
114}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_mp_div()

BOTAN_DLL int botan_mp_div ( botan_mp_t  quotient,
botan_mp_t  remainder,
botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 161 of file ffi_mp.cpp.

161 {
162 return BOTAN_FFI_VISIT(quotient, [=](auto& q) {
165 safe_get(remainder) = r;
166 });
167}
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition divide.cpp:155

References BOTAN_FFI_VISIT, Botan_FFI::safe_get(), and Botan::vartime_divide().

◆ botan_mp_equal()

BOTAN_DLL int botan_mp_equal ( botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 169 of file ffi_mp.cpp.

169 {
170 return BOTAN_FFI_VISIT(x_w, [=](const auto& x) -> int { return x == safe_get(y_w); });
171}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_flip_sign()

BOTAN_DLL int botan_mp_flip_sign ( botan_mp_t  mp)

Definition at line 75 of file ffi_mp.cpp.

75 {
76 return BOTAN_FFI_VISIT(mp, [](auto& bn) { bn.flip_sign(); });
77}

References BOTAN_FFI_VISIT.

◆ botan_mp_from_bin()

BOTAN_DLL int botan_mp_from_bin ( botan_mp_t  mp,
const uint8_t  vec[],
size_t  vec_len 
)

Definition at line 79 of file ffi_mp.cpp.

79 {
80 return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn.binary_decode(bin, bin_len); });
81}

References BOTAN_FFI_VISIT.

◆ botan_mp_gcd()

BOTAN_DLL int botan_mp_gcd ( botan_mp_t  out,
botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 227 of file ffi_mp.cpp.

227 {
228 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = Botan::gcd(safe_get(x), safe_get(y)); });
229}
BigInt gcd(const BigInt &a, const BigInt &b)
Definition numthry.cpp:214

References BOTAN_FFI_VISIT, Botan::gcd(), and Botan_FFI::safe_get().

◆ botan_mp_get_bit()

BOTAN_DLL int botan_mp_get_bit ( botan_mp_t  n,
size_t  bit 
)

Returns 0 if specified bit of n is not set Returns 1 if specified bit of n is set Returns negative number on error

Definition at line 235 of file ffi_mp.cpp.

235 {
236 return BOTAN_FFI_VISIT(mp, [=](const auto& n) -> int { return n.get_bit(bit); });
237}

References BOTAN_FFI_VISIT.

◆ botan_mp_init()

BOTAN_DLL int botan_mp_init ( botan_mp_t mp)

Initialize an MPI

Definition at line 21 of file ffi_mp.cpp.

21 {
22 return ffi_guard_thunk(__func__, [=]() -> int {
23 if(mp_out == nullptr) {
25 }
26
27 auto mp = std::make_unique<Botan::BigInt>();
28 *mp_out = new botan_mp_struct(std::move(mp));
29 return BOTAN_FFI_SUCCESS;
30 });
31}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and Botan_FFI::ffi_guard_thunk().

◆ botan_mp_is_even()

BOTAN_DLL int botan_mp_is_even ( botan_mp_t  mp)

Definition at line 181 of file ffi_mp.cpp.

181 {
182 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_even(); });
183}

References BOTAN_FFI_VISIT.

◆ botan_mp_is_negative()

BOTAN_DLL int botan_mp_is_negative ( botan_mp_t  mp)

Return 1 iff mp is less than 0

Definition at line 67 of file ffi_mp.cpp.

67 {
68 return BOTAN_FFI_VISIT(mp, [](const auto& bn) { return bn.is_negative() ? 1 : 0; });
69}

References BOTAN_FFI_VISIT.

◆ botan_mp_is_odd()

BOTAN_DLL int botan_mp_is_odd ( botan_mp_t  mp)

Definition at line 177 of file ffi_mp.cpp.

177 {
178 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_odd(); });
179}

References BOTAN_FFI_VISIT.

◆ botan_mp_is_positive()

BOTAN_DLL int botan_mp_is_positive ( botan_mp_t  mp)

This function should have been named mp_is_non_negative. Returns 1 iff mp is greater than or equal to zero. Use botan_mp_is_negative to detect negative numbers, botan_mp_is_zero to check for zero.

Definition at line 71 of file ffi_mp.cpp.

71 {
72 return BOTAN_FFI_VISIT(mp, [](const auto& bn) { return bn.is_positive() ? 1 : 0; });
73}

References BOTAN_FFI_VISIT.

◆ botan_mp_is_prime()

BOTAN_DLL int botan_mp_is_prime ( botan_mp_t  n,
botan_rng_t  rng,
size_t  test_prob 
)

Returns 0 if n is not prime Returns 1 if n is prime Returns negative number on error

Definition at line 231 of file ffi_mp.cpp.

231 {
232 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; });
233}
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition numthry.cpp:362

References BOTAN_FFI_VISIT, Botan::is_prime(), and Botan_FFI::safe_get().

◆ botan_mp_is_zero()

BOTAN_DLL int botan_mp_is_zero ( botan_mp_t  mp)

Definition at line 173 of file ffi_mp.cpp.

173 {
174 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_zero(); });
175}

References BOTAN_FFI_VISIT.

◆ botan_mp_lshift()

BOTAN_DLL int botan_mp_lshift ( botan_mp_t  out,
botan_mp_t  in,
size_t  shift 
)

Definition at line 199 of file ffi_mp.cpp.

199 {
200 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) << shift; });
201}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_mod_inverse()

BOTAN_DLL int botan_mp_mod_inverse ( botan_mp_t  out,
botan_mp_t  in,
botan_mp_t  modulus 
)

Definition at line 207 of file ffi_mp.cpp.

207 {
208 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); });
209}
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition mod_inv.cpp:178

References BOTAN_FFI_VISIT, Botan::inverse_mod(), and Botan_FFI::safe_get().

◆ botan_mp_mod_mul()

BOTAN_DLL int botan_mp_mod_mul ( botan_mp_t  result,
botan_mp_t  x,
botan_mp_t  y,
botan_mp_t  mod 
)

Definition at line 211 of file ffi_mp.cpp.

211 {
212 return BOTAN_FFI_VISIT(out, [=](auto& o) {
213 Botan::Modular_Reducer reducer(safe_get(modulus));
214 o = reducer.multiply(safe_get(x), safe_get(y));
215 });
216}

References BOTAN_FFI_VISIT, Botan::Modular_Reducer::multiply(), and Botan_FFI::safe_get().

◆ botan_mp_mul()

BOTAN_DLL int botan_mp_mul ( botan_mp_t  result,
botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 152 of file ffi_mp.cpp.

152 {
153 return BOTAN_FFI_VISIT(result, [=](auto& res) {
154 if(result == x)
155 res *= safe_get(y);
156 else
157 res = safe_get(x) * safe_get(y);
158 });
159}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_num_bits()

BOTAN_DLL int botan_mp_num_bits ( botan_mp_t  n,
size_t *  bits 
)

Return the number of significant bits in the MPI

Definition at line 247 of file ffi_mp.cpp.

247 {
248 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bits = n.bits(); });
249}

References BOTAN_FFI_VISIT.

◆ botan_mp_num_bytes()

BOTAN_DLL int botan_mp_num_bytes ( botan_mp_t  n,
size_t *  bytes 
)

Return the number of significant bytes in the MPI

Definition at line 251 of file ffi_mp.cpp.

251 {
252 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bytes = n.bytes(); });
253}

References BOTAN_FFI_VISIT.

◆ botan_mp_powmod()

BOTAN_DLL int botan_mp_powmod ( botan_mp_t  out,
botan_mp_t  base,
botan_mp_t  exponent,
botan_mp_t  modulus 
)

Definition at line 194 of file ffi_mp.cpp.

194 {
195 return BOTAN_FFI_VISIT(
196 out, [=](auto& o) { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
197}
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition numthry.cpp:291

References BOTAN_FFI_VISIT, Botan::power_mod(), and Botan_FFI::safe_get().

◆ botan_mp_rand_bits()

BOTAN_DLL int botan_mp_rand_bits ( botan_mp_t  rand_out,
botan_rng_t  rng,
size_t  bits 
)

Definition at line 218 of file ffi_mp.cpp.

218 {
219 return BOTAN_FFI_VISIT(rng, [=](auto& r) { safe_get(rand_out).randomize(r, bits); });
220}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_rand_range()

BOTAN_DLL int botan_mp_rand_range ( botan_mp_t  rand_out,
botan_rng_t  rng,
botan_mp_t  lower_bound,
botan_mp_t  upper_bound 
)

Definition at line 222 of file ffi_mp.cpp.

222 {
223 return BOTAN_FFI_VISIT(
224 rng, [=](auto& r) { safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
225}
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
Definition big_rand.cpp:43

References BOTAN_FFI_VISIT, Botan::BigInt::random_integer(), and Botan_FFI::safe_get().

◆ botan_mp_rshift()

BOTAN_DLL int botan_mp_rshift ( botan_mp_t  out,
botan_mp_t  in,
size_t  shift 
)

Definition at line 203 of file ffi_mp.cpp.

203 {
204 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) >> shift; });
205}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_set_bit()

BOTAN_DLL int botan_mp_set_bit ( botan_mp_t  n,
size_t  bit 
)

Set the specified bit

Definition at line 239 of file ffi_mp.cpp.

239 {
240 return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.set_bit(bit); });
241}

References BOTAN_FFI_VISIT.

◆ botan_mp_set_from_int()

BOTAN_DLL int botan_mp_set_from_int ( botan_mp_t  mp,
int  initial_value 
)

Set the MPI value from an int

Definition at line 37 of file ffi_mp.cpp.

37 {
38 return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn = Botan::BigInt::from_s32(initial_value); });
39}
static BigInt from_s32(int32_t n)
Definition bigint.cpp:49

References BOTAN_FFI_VISIT, and Botan::BigInt::from_s32().

◆ botan_mp_set_from_mp()

BOTAN_DLL int botan_mp_set_from_mp ( botan_mp_t  dest,
botan_mp_t  source 
)

Set the MPI value from another MP object

Definition at line 63 of file ffi_mp.cpp.

63 {
64 return BOTAN_FFI_VISIT(dest, [=](auto& bn) { bn = safe_get(source); });
65}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_set_from_radix_str()

BOTAN_DLL int botan_mp_set_from_radix_str ( botan_mp_t  dest,
const char *  str,
size_t  radix 
)

Set the MPI value from a string with arbitrary radix. For arbitrary being 10 or 16.

Definition at line 45 of file ffi_mp.cpp.

45 {
46 return BOTAN_FFI_VISIT(mp, [=](auto& bn) {
48 if(radix == 10)
50 else if(radix == 16)
52 else
54
55 const uint8_t* bytes = Botan::cast_char_ptr_to_uint8(str);
56 const size_t len = strlen(str);
57
58 bn = Botan::BigInt(bytes, len, base);
59 return BOTAN_FFI_SUCCESS;
60 });
61}
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition mem_ops.h:177

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, Botan::cast_char_ptr_to_uint8(), Botan::BigInt::Decimal, and Botan::BigInt::Hexadecimal.

◆ botan_mp_set_from_str()

BOTAN_DLL int botan_mp_set_from_str ( botan_mp_t  dest,
const char *  str 
)

Set the MPI value from a string

Definition at line 41 of file ffi_mp.cpp.

41 {
42 return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn = Botan::BigInt(str); });
43}

References BOTAN_FFI_VISIT.

◆ botan_mp_sub()

BOTAN_DLL int botan_mp_sub ( botan_mp_t  result,
botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 125 of file ffi_mp.cpp.

125 {
126 return BOTAN_FFI_VISIT(result, [=](auto& res) {
127 if(result == x)
128 res -= safe_get(y);
129 else
130 res = safe_get(x) - safe_get(y);
131 });
132}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_sub_u32()

BOTAN_DLL int botan_mp_sub_u32 ( botan_mp_t  result,
botan_mp_t  x,
uint32_t  y 
)

Definition at line 143 of file ffi_mp.cpp.

143 {
144 return BOTAN_FFI_VISIT(result, [=](auto& res) {
145 if(result == x)
146 res -= static_cast<Botan::word>(y);
147 else
148 res = safe_get(x) - static_cast<Botan::word>(y);
149 });
150}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_swap()

BOTAN_DLL int botan_mp_swap ( botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 189 of file ffi_mp.cpp.

189 {
190 return BOTAN_FFI_VISIT(x_w, [=](auto& x) { x.swap(safe_get(y_w)); });
191}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_to_bin()

BOTAN_DLL int botan_mp_to_bin ( botan_mp_t  mp,
uint8_t  vec[] 
)

Definition at line 101 of file ffi_mp.cpp.

101 {
102 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { bn.binary_encode(vec); });
103}

References BOTAN_FFI_VISIT.

◆ botan_mp_to_hex()

BOTAN_DLL int botan_mp_to_hex ( botan_mp_t  mp,
char *  out 
)

Convert the MPI to a hex string. Writes botan_mp_num_bytes(mp)*2 + 1 bytes

Definition at line 83 of file ffi_mp.cpp.

83 {
84 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) {
85 const std::string hex = bn.to_hex_string();
86 std::memcpy(out, hex.c_str(), 1 + hex.size());
87 });
88}

References BOTAN_FFI_VISIT.

◆ botan_mp_to_str()

BOTAN_DLL int botan_mp_to_str ( botan_mp_t  mp,
uint8_t  base,
char *  out,
size_t *  out_len 
)

Convert the MPI to a string. Currently base == 10 and base == 16 are supported.

Definition at line 90 of file ffi_mp.cpp.

90 {
91 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) -> int {
92 if(digit_base == 0 || digit_base == 10)
93 return write_str_output(out, out_len, bn.to_dec_string());
94 else if(digit_base == 16)
95 return write_str_output(out, out_len, bn.to_hex_string());
96 else
98 });
99}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_VISIT, and Botan_FFI::write_str_output().

◆ botan_mp_to_uint32()

BOTAN_DLL int botan_mp_to_uint32 ( botan_mp_t  mp,
uint32_t *  val 
)

Definition at line 105 of file ffi_mp.cpp.

105 {
106 if(val == nullptr) {
108 }
109 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { *val = bn.to_u32bit(); });
110}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_nist_kw_dec()

BOTAN_DLL int botan_nist_kw_dec ( const char *  cipher_algo,
int  padded,
const uint8_t  wrapped_key[],
size_t  wrapped_key_len,
const uint8_t  kek[],
size_t  kek_len,
uint8_t  key[],
size_t *  key_len 
)

Definition at line 53 of file ffi_keywrap.cpp.

60 {
61#if defined(BOTAN_HAS_NIST_KEYWRAP)
62 return ffi_guard_thunk(__func__, [=]() -> int {
63 if(padded != 0 && padded != 1) {
65 }
66
67 auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
68 bc->set_key(kek, kek_len);
69
71
72 if(padded == 0) {
73 output = Botan::nist_key_unwrap(wrapped_key, wrapped_key_len, *bc);
74 } else {
75 output = Botan::nist_key_unwrap_padded(wrapped_key, wrapped_key_len, *bc);
76 }
77
78 return write_vec_output(key, key_len, output);
79 });
80#else
81 BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
83#endif
84}
static std::unique_ptr< BlockCipher > create_or_throw(std::string_view algo_spec, std::string_view provider="")
secure_vector< uint8_t > nist_key_unwrap_padded(const uint8_t input[], size_t input_len, const BlockCipher &bc)
secure_vector< uint8_t > nist_key_unwrap(const uint8_t input[], size_t input_len, const BlockCipher &bc)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, Botan::BlockCipher::create_or_throw(), Botan_FFI::ffi_guard_thunk(), Botan::nist_key_unwrap(), Botan::nist_key_unwrap_padded(), and Botan_FFI::write_vec_output().

Referenced by botan_key_unwrap3394().

◆ botan_nist_kw_enc()

BOTAN_DLL int botan_nist_kw_enc ( const char *  cipher_algo,
int  padded,
const uint8_t  key[],
size_t  key_len,
const uint8_t  kek[],
size_t  kek_len,
uint8_t  wrapped_key[],
size_t *  wrapped_key_len 
)

Definition at line 21 of file ffi_keywrap.cpp.

28 {
29#if defined(BOTAN_HAS_NIST_KEYWRAP)
30 return ffi_guard_thunk(__func__, [=]() -> int {
31 if(padded != 0 && padded != 1) {
33 }
34 auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
35 bc->set_key(kek, kek_len);
36
37 std::vector<uint8_t> output;
38
39 if(padded == 0) {
40 output = Botan::nist_key_wrap(key, key_len, *bc);
41 } else {
42 output = Botan::nist_key_wrap_padded(key, key_len, *bc);
43 }
44
45 return write_vec_output(wrapped_key, wrapped_key_len, output);
46 });
47#else
48 BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
50#endif
51}
std::vector< uint8_t > nist_key_wrap(const uint8_t input[], size_t input_len, const BlockCipher &bc)
std::vector< uint8_t > nist_key_wrap_padded(const uint8_t input[], size_t input_len, const BlockCipher &bc)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, Botan::BlockCipher::create_or_throw(), Botan_FFI::ffi_guard_thunk(), Botan::nist_key_wrap(), Botan::nist_key_wrap_padded(), and Botan_FFI::write_vec_output().

Referenced by botan_key_wrap3394().

◆ botan_pbkdf()

BOTAN_DLL int botan_pbkdf ( const char *  pbkdf_algo,
uint8_t  out[],
size_t  out_len,
const char *  passphrase,
const uint8_t  salt[],
size_t  salt_len,
size_t  iterations 
)

Definition at line 22 of file ffi_kdf.cpp.

28 {
29 return botan_pwdhash(algo, iterations, 0, 0, out, out_len, pass, 0, salt, salt_len);
30}
int botan_pwdhash(const char *algo, size_t param1, size_t param2, size_t param3, uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len)
Definition ffi_kdf.cpp:53

References botan_pwdhash().

◆ botan_pbkdf_timed()

BOTAN_DLL int botan_pbkdf_timed ( const char *  pbkdf_algo,
uint8_t  out[],
size_t  out_len,
const char *  passphrase,
const uint8_t  salt[],
size_t  salt_len,
size_t  milliseconds_to_run,
size_t *  out_iterations_used 
)

Derive a key from a passphrase, running until msec time has elapsed.

Parameters
pbkdf_algoPBKDF algorithm, e.g., "PBKDF2(SHA-256)"
outbuffer to store the derived key, must be of out_len bytes
out_lenthe desired length of the key to produce
passphrasethe password to derive the key from
salta randomly chosen salt
salt_lenlength of salt in bytes
milliseconds_to_runif iterations is zero, then instead the PBKDF is run until milliseconds_to_run milliseconds has passed
out_iterations_usedset to the number iterations executed
Returns
0 on success, a negative value on failure

Deprecated: use

botan_pwdhash_timed(pbkdf_algo, static_cast<uint32_t>(ms_to_run), iterations_used, nullptr, nullptr, out, out_len, password, 0, salt, salt_len);

Definition at line 32 of file ffi_kdf.cpp.

39 {
40 return botan_pwdhash_timed(algo,
41 static_cast<uint32_t>(ms_to_run),
42 iterations_used,
43 nullptr,
44 nullptr,
45 out,
46 out_len,
47 password,
48 0,
49 salt,
50 salt_len);
51}
int botan_pwdhash_timed(const char *algo, uint32_t msec, size_t *param1, size_t *param2, size_t *param3, uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len)
Definition ffi_kdf.cpp:86

References botan_pwdhash_timed().

◆ botan_pk_op_decrypt()

BOTAN_DLL int botan_pk_op_decrypt ( botan_pk_op_decrypt_t  op,
uint8_t  out[],
size_t *  out_len,
const uint8_t  ciphertext[],
size_t  ciphertext_len 
)

Definition at line 103 of file ffi_pk_op.cpp.

104 {
105 return BOTAN_FFI_VISIT(
106 op, [=](const auto& o) { return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len)); });
107}

References BOTAN_FFI_VISIT, and Botan_FFI::write_vec_output().

◆ botan_pk_op_decrypt_create()

BOTAN_DLL int botan_pk_op_decrypt_create ( botan_pk_op_decrypt_t op,
botan_privkey_t  key,
const char *  padding,
uint32_t  flags 
)

Definition at line 71 of file ffi_pk_op.cpp.

74 {
75 if(op == nullptr) {
77 }
78
79 if(flags != 0) {
81 }
82
83 return ffi_guard_thunk(__func__, [=]() -> int {
84 *op = nullptr;
85
86 auto pk = std::make_unique<Botan::PK_Decryptor_EME>(safe_get(key_obj), Botan::system_rng(), padding);
87 *op = new botan_pk_op_decrypt_struct(std::move(pk));
88 return BOTAN_FFI_SUCCESS;
89 });
90}
RandomNumberGenerator & system_rng()

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::system_rng().

◆ botan_pk_op_decrypt_destroy()

BOTAN_DLL int botan_pk_op_decrypt_destroy ( botan_pk_op_decrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 92 of file ffi_pk_op.cpp.

92 {
93 return BOTAN_FFI_CHECKED_DELETE(op);
94}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_decrypt_output_length()

BOTAN_DLL int botan_pk_op_decrypt_output_length ( botan_pk_op_decrypt_t  op,
size_t  ctext_len,
size_t *  ptext_len 
)

Definition at line 96 of file ffi_pk_op.cpp.

96 {
97 if(ptext_len == nullptr) {
99 }
100 return BOTAN_FFI_VISIT(op, [=](const auto& o) { *ptext_len = o.plaintext_length(ctext_len); });
101}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_pk_op_encrypt()

BOTAN_DLL int botan_pk_op_encrypt ( botan_pk_op_encrypt_t  op,
botan_rng_t  rng,
uint8_t  out[],
size_t *  out_len,
const uint8_t  plaintext[],
size_t  plaintext_len 
)

Definition at line 57 of file ffi_pk_op.cpp.

62 {
63 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
64 return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
65 });
66}

References BOTAN_FFI_VISIT, Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

◆ botan_pk_op_encrypt_create()

BOTAN_DLL int botan_pk_op_encrypt_create ( botan_pk_op_encrypt_t op,
botan_pubkey_t  key,
const char *  padding,
uint32_t  flags 
)

Definition at line 28 of file ffi_pk_op.cpp.

28 {
29 if(op == nullptr) {
31 }
32
33 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
35 }
36
37 return ffi_guard_thunk(__func__, [=]() -> int {
38 *op = nullptr;
39
40 auto pk = std::make_unique<Botan::PK_Encryptor_EME>(safe_get(key_obj), Botan::system_rng(), padding);
41 *op = new botan_pk_op_encrypt_struct(std::move(pk));
42 return BOTAN_FFI_SUCCESS;
43 });
44}
#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE
Definition ffi.h:1535

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::system_rng().

◆ botan_pk_op_encrypt_destroy()

BOTAN_DLL int botan_pk_op_encrypt_destroy ( botan_pk_op_encrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 46 of file ffi_pk_op.cpp.

46 {
47 return BOTAN_FFI_CHECKED_DELETE(op);
48}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_encrypt_output_length()

BOTAN_DLL int botan_pk_op_encrypt_output_length ( botan_pk_op_encrypt_t  op,
size_t  ptext_len,
size_t *  ctext_len 
)

Definition at line 50 of file ffi_pk_op.cpp.

50 {
51 if(ctext_len == nullptr) {
53 }
54 return BOTAN_FFI_VISIT(op, [=](const auto& o) { *ctext_len = o.ciphertext_length(ptext_len); });
55}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_pk_op_kem_decrypt_create()

BOTAN_DLL int botan_pk_op_kem_decrypt_create ( botan_pk_op_kem_decrypt_t op,
botan_privkey_t  key,
const char *  kdf 
)

Definition at line 309 of file ffi_pk_op.cpp.

309 {
310 if(op == nullptr || padding == nullptr) {
312 }
313
314 return ffi_guard_thunk(__func__, [=]() -> int {
315 auto pk = std::make_unique<Botan::PK_KEM_Decryptor>(safe_get(key_obj), Botan::system_rng(), padding);
316 *op = new botan_pk_op_kem_decrypt_struct(std::move(pk));
317 return BOTAN_FFI_SUCCESS;
318 });
319}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::system_rng().

◆ botan_pk_op_kem_decrypt_destroy()

BOTAN_DLL int botan_pk_op_kem_decrypt_destroy ( botan_pk_op_kem_decrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 350 of file ffi_pk_op.cpp.

350 {
351 return BOTAN_FFI_CHECKED_DELETE(op);
352}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_kem_decrypt_shared_key()

BOTAN_DLL int botan_pk_op_kem_decrypt_shared_key ( botan_pk_op_kem_decrypt_t  op,
const uint8_t  salt[],
size_t  salt_len,
const uint8_t  encapsulated_key[],
size_t  encapsulated_key_len,
size_t  desired_shared_key_len,
uint8_t  shared_key[],
size_t *  shared_key_len 
)

Definition at line 334 of file ffi_pk_op.cpp.

341 {
342 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
343 const auto shared_key =
344 kem.decrypt(encapsulated_key, encapsulated_key_len, desired_shared_key_len, salt, salt_len);
345
346 write_vec_output(shared_key_out, shared_key_len, shared_key);
347 });
348}

References BOTAN_FFI_VISIT, and Botan_FFI::write_vec_output().

◆ botan_pk_op_kem_decrypt_shared_key_length()

BOTAN_DLL int botan_pk_op_kem_decrypt_shared_key_length ( botan_pk_op_kem_decrypt_t  op,
size_t  desired_shared_key_length,
size_t *  output_shared_key_length 
)

Definition at line 321 of file ffi_pk_op.cpp.

323 {
324 if(output_shared_key_length == nullptr) {
326 }
327
328 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
329 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
330 return BOTAN_FFI_SUCCESS;
331 });
332}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_kem_encrypt_create()

BOTAN_DLL int botan_pk_op_kem_encrypt_create ( botan_pk_op_kem_encrypt_t op,
botan_pubkey_t  key,
const char *  kdf 
)

Definition at line 247 of file ffi_pk_op.cpp.

247 {
248 if(op == nullptr || padding == nullptr) {
250 }
251
252 return ffi_guard_thunk(__func__, [=]() -> int {
253 auto pk = std::make_unique<Botan::PK_KEM_Encryptor>(safe_get(key_obj), padding);
254 *op = new botan_pk_op_kem_encrypt_struct(std::move(pk));
255 return BOTAN_FFI_SUCCESS;
256 });
257}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_pk_op_kem_encrypt_create_shared_key()

BOTAN_DLL int botan_pk_op_kem_encrypt_create_shared_key ( botan_pk_op_kem_encrypt_t  op,
botan_rng_t  rng,
const uint8_t  salt[],
size_t  salt_len,
size_t  desired_shared_key_len,
uint8_t  shared_key[],
size_t *  shared_key_len,
uint8_t  encapsulated_key[],
size_t *  encapsulated_key_len 
)

Definition at line 288 of file ffi_pk_op.cpp.

296 {
297 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
298 const auto result = kem.encrypt(safe_get(rng), desired_shared_key_len, {salt, salt_len});
299
300 int rc = write_vec_output(encapsulated_key_out, encapsulated_key_len, result.encapsulated_shared_key());
301
302 if(rc != 0)
303 return rc;
304
305 return write_vec_output(shared_key_out, shared_key_len, result.shared_key());
306 });
307}

References BOTAN_FFI_VISIT, Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

◆ botan_pk_op_kem_encrypt_destroy()

BOTAN_DLL int botan_pk_op_kem_encrypt_destroy ( botan_pk_op_kem_encrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 259 of file ffi_pk_op.cpp.

259 {
260 return BOTAN_FFI_CHECKED_DELETE(op);
261}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_kem_encrypt_encapsulated_key_length()

BOTAN_DLL int botan_pk_op_kem_encrypt_encapsulated_key_length ( botan_pk_op_kem_encrypt_t  op,
size_t *  output_encapsulated_key_length 
)

Definition at line 276 of file ffi_pk_op.cpp.

277 {
278 if(output_encapsulated_key_length == nullptr) {
280 }
281
282 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
283 *output_encapsulated_key_length = kem.encapsulated_key_length();
284 return BOTAN_FFI_SUCCESS;
285 });
286}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_kem_encrypt_shared_key_length()

BOTAN_DLL int botan_pk_op_kem_encrypt_shared_key_length ( botan_pk_op_kem_encrypt_t  op,
size_t  desired_shared_key_length,
size_t *  output_shared_key_length 
)

Definition at line 263 of file ffi_pk_op.cpp.

265 {
266 if(output_shared_key_length == nullptr) {
268 }
269
270 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
271 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
272 return BOTAN_FFI_SUCCESS;
273 });
274}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_key_agreement()

BOTAN_DLL int botan_pk_op_key_agreement ( botan_pk_op_ka_t  op,
uint8_t  out[],
size_t *  out_len,
const uint8_t  other_key[],
size_t  other_key_len,
const uint8_t  salt[],
size_t  salt_len 
)

Definition at line 234 of file ffi_pk_op.cpp.

240 {
241 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
242 auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
243 return write_vec_output(out, out_len, k);
244 });
245}

References BOTAN_FFI_VISIT, and Botan_FFI::write_vec_output().

◆ botan_pk_op_key_agreement_create()

BOTAN_DLL int botan_pk_op_key_agreement_create ( botan_pk_op_ka_t op,
botan_privkey_t  key,
const char *  kdf,
uint32_t  flags 
)

Definition at line 191 of file ffi_pk_op.cpp.

191 {
192 if(op == nullptr) {
194 }
195
196 if(flags != 0) {
198 }
199
200 return ffi_guard_thunk(__func__, [=]() -> int {
201 *op = nullptr;
202 auto pk = std::make_unique<Botan::PK_Key_Agreement>(safe_get(key_obj), Botan::system_rng(), kdf);
203 *op = new botan_pk_op_ka_struct(std::move(pk));
204 return BOTAN_FFI_SUCCESS;
205 });
206}

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::system_rng().

◆ botan_pk_op_key_agreement_destroy()

BOTAN_DLL int botan_pk_op_key_agreement_destroy ( botan_pk_op_ka_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 208 of file ffi_pk_op.cpp.

208 {
209 return BOTAN_FFI_CHECKED_DELETE(op);
210}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_key_agreement_export_public()

BOTAN_DLL int botan_pk_op_key_agreement_export_public ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 212 of file ffi_pk_op.cpp.

212 {
213 return copy_view_bin(out, out_len, botan_pk_op_key_agreement_view_public, key);
214}
int botan_pk_op_key_agreement_view_public(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:163

References botan_pk_op_key_agreement_view_public(), and Botan_FFI::copy_view_bin().

◆ botan_pk_op_key_agreement_size()

BOTAN_DLL int botan_pk_op_key_agreement_size ( botan_pk_op_ka_t  op,
size_t *  out_len 
)

Definition at line 225 of file ffi_pk_op.cpp.

225 {
226 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
227 if(out_len == nullptr)
229 *out_len = o.agreed_value_size();
230 return BOTAN_FFI_SUCCESS;
231 });
232}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_key_agreement_view_public()

BOTAN_DLL int botan_pk_op_key_agreement_view_public ( botan_privkey_t  key,
botan_view_ctx  ctx,
botan_view_bin_fn  view 
)

Definition at line 216 of file ffi_pk_op.cpp.

216 {
217 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
218 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
219 return invoke_view_callback(view, ctx, kak->public_value());
220 else
222 });
223}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:146

References BOTAN_FFI_ERROR_INVALID_INPUT, BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

Referenced by botan_pk_op_key_agreement_export_public().

◆ botan_pk_op_sign_create()

BOTAN_DLL int botan_pk_op_sign_create ( botan_pk_op_sign_t op,
botan_privkey_t  key,
const char *  hash_and_padding,
uint32_t  flags 
)

Definition at line 112 of file ffi_pk_op.cpp.

112 {
113 if(op == nullptr) {
115 }
116
117 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
119 }
120
121 return ffi_guard_thunk(__func__, [=]() -> int {
122 *op = nullptr;
123
126
127 auto pk = std::make_unique<Botan::PK_Signer>(safe_get(key_obj), Botan::system_rng(), hash, format);
128 *op = new botan_pk_op_sign_struct(std::move(pk));
129 return BOTAN_FFI_SUCCESS;
130 });
131}
Signature_Format
Definition pk_keys.h:29

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DerSequence, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::Standard, and Botan::system_rng().

◆ botan_pk_op_sign_destroy()

BOTAN_DLL int botan_pk_op_sign_destroy ( botan_pk_op_sign_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 133 of file ffi_pk_op.cpp.

133 {
134 return BOTAN_FFI_CHECKED_DELETE(op);
135}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_sign_finish()

BOTAN_DLL int botan_pk_op_sign_finish ( botan_pk_op_sign_t  op,
botan_rng_t  rng,
uint8_t  sig[],
size_t *  sig_len 
)

Definition at line 149 of file ffi_pk_op.cpp.

149 {
150 return BOTAN_FFI_VISIT(op, [=](auto& o) { return write_vec_output(out, out_len, o.signature(safe_get(rng_obj))); });
151}

References BOTAN_FFI_VISIT, Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

◆ botan_pk_op_sign_output_length()

BOTAN_DLL int botan_pk_op_sign_output_length ( botan_pk_op_sign_t  op,
size_t *  olen 
)

Definition at line 137 of file ffi_pk_op.cpp.

137 {
138 if(sig_len == nullptr) {
140 }
141
142 return BOTAN_FFI_VISIT(op, [=](const auto& o) { *sig_len = o.signature_length(); });
143}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_pk_op_sign_update()

BOTAN_DLL int botan_pk_op_sign_update ( botan_pk_op_sign_t  op,
const uint8_t  in[],
size_t  in_len 
)

Definition at line 145 of file ffi_pk_op.cpp.

145 {
146 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
147}

References BOTAN_FFI_VISIT.

◆ botan_pk_op_verify_create()

BOTAN_DLL int botan_pk_op_verify_create ( botan_pk_op_verify_t op,
botan_pubkey_t  key,
const char *  hash_and_padding,
uint32_t  flags 
)

Definition at line 153 of file ffi_pk_op.cpp.

153 {
154 if(op == nullptr) {
156 }
157
158 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
160 }
161
162 return ffi_guard_thunk(__func__, [=]() -> int {
163 *op = nullptr;
166 auto pk = std::make_unique<Botan::PK_Verifier>(safe_get(key_obj), hash, format);
167 *op = new botan_pk_op_verify_struct(std::move(pk));
168 return BOTAN_FFI_SUCCESS;
169 });
170}

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DerSequence, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::Standard.

◆ botan_pk_op_verify_destroy()

BOTAN_DLL int botan_pk_op_verify_destroy ( botan_pk_op_verify_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 172 of file ffi_pk_op.cpp.

172 {
173 return BOTAN_FFI_CHECKED_DELETE(op);
174}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_verify_finish()

BOTAN_DLL int botan_pk_op_verify_finish ( botan_pk_op_verify_t  op,
const uint8_t  sig[],
size_t  sig_len 
)

Definition at line 180 of file ffi_pk_op.cpp.

180 {
181 return BOTAN_FFI_VISIT(op, [=](auto& o) {
182 const bool legit = o.check_signature(sig, sig_len);
183
184 if(legit)
185 return BOTAN_FFI_SUCCESS;
186 else
188 });
189}

References BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_verify_update()

BOTAN_DLL int botan_pk_op_verify_update ( botan_pk_op_verify_t  op,
const uint8_t  in[],
size_t  in_len 
)

Definition at line 176 of file ffi_pk_op.cpp.

176 {
177 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
178}

References BOTAN_FFI_VISIT.

◆ botan_pkcs_hash_id()

BOTAN_DLL int botan_pkcs_hash_id ( const char *  hash_name,
uint8_t  pkcs_id[],
size_t *  pkcs_id_len 
)

Signature Scheme Utility Functions

Definition at line 342 of file ffi_pkey.cpp.

342 {
343#if defined(BOTAN_HAS_HASH_ID)
344 return ffi_guard_thunk(__func__, [=]() -> int {
345 const std::vector<uint8_t> hash_id = Botan::pkcs_hash_id(hash_name);
346 return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
347 });
348#else
349 BOTAN_UNUSED(hash_name, pkcs_id, pkcs_id_len);
351#endif
352}
int write_output(uint8_t out[], size_t *out_len, const uint8_t buf[], size_t buf_len)
Definition ffi_util.h:181
std::vector< uint8_t > pkcs_hash_id(std::string_view name)
Definition hash_id.cpp:78

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::pkcs_hash_id(), and Botan_FFI::write_output().

◆ botan_privkey_algo_name()

BOTAN_DLL int botan_privkey_algo_name ( botan_privkey_t  key,
char  out[],
size_t *  out_len 
)

Definition at line 111 of file ffi_pkey.cpp.

111 {
112 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
113}

References BOTAN_FFI_VISIT, and Botan_FFI::write_str_output().

◆ botan_privkey_check_key()

BOTAN_DLL int botan_privkey_check_key ( botan_privkey_t  key,
botan_rng_t  rng,
uint32_t  flags 
)

Definition at line 127 of file ffi_pkey.cpp.

127 {
128 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
129 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
130 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
131 });
132}
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition ffi.h:1053

References BOTAN_CHECK_KEY_EXPENSIVE_TESTS, BOTAN_FFI_ERROR_INVALID_INPUT, BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_privkey_create()

BOTAN_DLL int botan_privkey_create ( botan_privkey_t key,
const char *  algo_name,
const char *  algo_params,
botan_rng_t  rng 
)

Create a new private key

Parameters
keythe new object will be placed here
algo_namesomething like "RSA" or "ECDSA"
algo_paramsis specific to the algorithm. For RSA, specifies the modulus bit length. For ECC is the name of the curve.
rnga random number generator

Definition at line 27 of file ffi_pkey.cpp.

30 {
31 return ffi_guard_thunk(__func__, [=]() -> int {
32 if(key_obj == nullptr) {
34 }
35
36 *key_obj = nullptr;
37 if(rng_obj == nullptr) {
39 }
40
42 std::unique_ptr<Botan::Private_Key> key(
43 Botan::create_private_key(algo_name ? algo_name : "RSA", rng, algo_params ? algo_params : ""));
44
45 if(key) {
46 *key_obj = new botan_privkey_struct(std::move(key));
47 return BOTAN_FFI_SUCCESS;
48 } else {
50 }
51 });
52}
std::unique_ptr< Private_Key > create_private_key(std::string_view alg_name, RandomNumberGenerator &rng, std::string_view params, std::string_view provider)
Definition pk_algs.cpp:358

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::create_private_key(), Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

Referenced by botan_privkey_create_dh(), botan_privkey_create_ecdh(), botan_privkey_create_ecdsa(), botan_privkey_create_mceliece(), and botan_privkey_create_rsa().

◆ botan_privkey_create_dh()

BOTAN_DLL int botan_privkey_create_dh ( botan_privkey_t key,
botan_rng_t  rng,
const char *  param 
)

Definition at line 473 of file ffi_pkey_algs.cpp.

473 {
474 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
475}
BOTAN_DLL int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition ffi_pkey.cpp:27

References botan_privkey_create().

◆ botan_privkey_create_dsa()

BOTAN_DLL int botan_privkey_create_dsa ( botan_privkey_t key,
botan_rng_t  rng,
size_t  pbits,
size_t  qbits 
)

Generates DSA key pair. Gives to a caller control over key length and order of a subgroup 'q'.

Parameters
keyhandler to the resulting key
rnginitialized PRNG
pbitslength of the key in bits. Must be between in range (1024, 3072) and multiple of 64. Bit size of the prime 'p'
qbitsorder of the subgroup. Must be in range (160, 256) and multiple of 8
Returns
BOTAN_FFI_SUCCESS Success, ‘key’ initialized with DSA key
BOTAN_FFI_ERROR_NULL_POINTER either ‘key’ or ‘rng’ is NULL
BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either ‘pbits’ or ‘qbits’
BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

Definition at line 276 of file ffi_pkey_algs.cpp.

276 {
277#if defined(BOTAN_HAS_DSA)
278
279 if((rng_obj == nullptr) || (key == nullptr)) {
281 }
282
283 if((pbits % 64) || (qbits % 8) || (pbits < 1024) || (pbits > 3072) || (qbits < 160) || (qbits > 256)) {
285 }
286
287 return ffi_guard_thunk(__func__, [=]() -> int {
289 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
290 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
291 *key = new botan_privkey_struct(std::move(dsa));
292 return BOTAN_FFI_SUCCESS;
293 });
294#else
295 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
297#endif
298}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::DL_Group::Prime_Subgroup, and Botan_FFI::safe_get().

◆ botan_privkey_create_ecdh()

BOTAN_DLL int botan_privkey_create_ecdh ( botan_privkey_t key,
botan_rng_t  rng,
const char *  params 
)

Definition at line 509 of file ffi_pkey_algs.cpp.

509 {
510 if(param_str == nullptr) {
512 }
513
514 const std::string params(param_str);
515
516 if(params == "curve25519") {
517 return botan_privkey_create(key_obj, "Curve25519", "", rng_obj);
518 }
519
520 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
521}

References BOTAN_FFI_ERROR_NULL_POINTER, and botan_privkey_create().

◆ botan_privkey_create_ecdsa()

BOTAN_DLL int botan_privkey_create_ecdsa ( botan_privkey_t key,
botan_rng_t  rng,
const char *  params 
)

Definition at line 352 of file ffi_pkey_algs.cpp.

352 {
353 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
354}

References botan_privkey_create().

◆ botan_privkey_create_elgamal()

BOTAN_DLL int botan_privkey_create_elgamal ( botan_privkey_t key,
botan_rng_t  rng,
size_t  pbits,
size_t  qbits 
)

Generates ElGamal key pair. Caller has a control over key length and order of a subgroup 'q'. Function is able to use two types of primes:

  • if pbits-1 == qbits then safe primes are used for key generation
  • otherwise generation uses group of prime order
Parameters
keyhandler to the resulting key
rnginitialized PRNG
pbitslength of the key in bits. Must be at least 1024
qbitsorder of the subgroup. Must be at least 160
Returns
BOTAN_FFI_SUCCESS Success, ‘key’ initialized with DSA key
BOTAN_FFI_ERROR_NULL_POINTER either ‘key’ or ‘rng’ is NULL
BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either ‘pbits’ or ‘qbits’
BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

Definition at line 414 of file ffi_pkey_algs.cpp.

414 {
415#if defined(BOTAN_HAS_ELGAMAL)
416
417 if((rng_obj == nullptr) || (key == nullptr)) {
419 }
420
421 if((pbits < 1024) || (qbits < 160)) {
423 }
424
425 Botan::DL_Group::PrimeType prime_type =
427
428 return ffi_guard_thunk(__func__, [=]() -> int {
430 Botan::DL_Group group(rng, prime_type, pbits, qbits);
431 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
432 *key = new botan_privkey_struct(std::move(elg));
433 return BOTAN_FFI_SUCCESS;
434 });
435#else
436 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
438#endif
439}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::DL_Group::Prime_Subgroup, Botan_FFI::safe_get(), and Botan::DL_Group::Strong.

◆ botan_privkey_create_mceliece()

BOTAN_DLL int botan_privkey_create_mceliece ( botan_privkey_t key,
botan_rng_t  rng,
size_t  n,
size_t  t 
)

Definition at line 902 of file ffi_pkey_algs.cpp.

902 {
903 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
904 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
905}

References botan_privkey_create().

◆ botan_privkey_create_rsa()

BOTAN_DLL int botan_privkey_create_rsa ( botan_privkey_t key,
botan_rng_t  rng,
size_t  n_bits 
)

Definition at line 171 of file ffi_pkey_algs.cpp.

171 {
172 if(n_bits < 1024 || n_bits > 16 * 1024) {
174 }
175
176 std::string n_str = std::to_string(n_bits);
177
178 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
179}

References BOTAN_FFI_ERROR_BAD_PARAMETER, and botan_privkey_create().

◆ botan_privkey_destroy()

BOTAN_DLL int botan_privkey_destroy ( botan_privkey_t  key)
Returns
0 if success, error if invalid object handle

Definition at line 79 of file ffi_pkey.cpp.

79 {
80 return BOTAN_FFI_CHECKED_DELETE(key);
81}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_privkey_dsa_get_x()

BOTAN_DLL int botan_privkey_dsa_get_x ( botan_mp_t  n,
botan_privkey_t  key 
)

Definition at line 332 of file ffi_pkey_algs.cpp.

332 {
333 return botan_privkey_get_field(x, key, "x");
334}
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

References botan_privkey_get_field().

◆ botan_privkey_ed25519_get_privkey()

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

Definition at line 674 of file ffi_pkey_algs.cpp.

674 {
675#if defined(BOTAN_HAS_ED25519)
676 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
677 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
678 const auto ed_key = ed->raw_private_key_bits();
679 if(ed_key.size() != 64)
681 Botan::copy_mem(output, ed_key.data(), ed_key.size());
682 return BOTAN_FFI_SUCCESS;
683 } else {
685 }
686 });
687#else
688 BOTAN_UNUSED(key, output);
690#endif
691}

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

◆ botan_privkey_export()

BOTAN_DLL int botan_privkey_export ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len,
uint32_t  flags 
)

On input *out_len is number of bytes in out[] On output *out_len is number of bytes written (or required) If out is not big enough no output is written, *out_len is set and 1 is returned Returns 0 on success and sets If some other error occurs a negative integer is returned.

Definition at line 154 of file ffi_pkey.cpp.

154 {
155 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
156 return copy_view_bin(out, out_len, botan_privkey_view_der, key);
157 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
158 return copy_view_str(out, out_len, botan_privkey_view_pem, key);
159 } else {
161 }
162}
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1124
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1123
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:164
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:169
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:171

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, botan_privkey_view_der(), botan_privkey_view_pem(), Botan_FFI::copy_view_bin(), and Botan_FFI::copy_view_str().

◆ botan_privkey_export_encrypted()

BOTAN_DLL int botan_privkey_export_encrypted ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len,
botan_rng_t  rng,
const char *  passphrase,
const char *  encryption_algo,
uint32_t  flags 
)

Set encryption_algo to NULL or "" to have the library choose a default (recommended)

Definition at line 174 of file ffi_pkey.cpp.

180 {
181 return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
182}
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)
Definition ffi_pkey.cpp:261

References botan_privkey_export_encrypted_pbkdf_iter().

◆ botan_privkey_export_encrypted_pbkdf_iter()

BOTAN_DLL 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_iterations,
const char *  cipher_algo,
const char *  pbkdf_algo,
uint32_t  flags 
)

Export a private key using the specified number of iterations.

Definition at line 261 of file ffi_pkey.cpp.

269 {
270 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
271 return copy_view_bin(
272 out, out_len, botan_privkey_view_encrypted_der, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
273 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
274 return copy_view_str(
275 out, out_len, botan_privkey_view_encrypted_pem, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
276 } else {
278 }
279}
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)
Definition ffi_pkey.cpp:281
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)
Definition ffi_pkey.cpp:306

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, botan_privkey_view_encrypted_der(), botan_privkey_view_encrypted_pem(), Botan_FFI::copy_view_bin(), and Botan_FFI::copy_view_str().

Referenced by botan_privkey_export_encrypted().

◆ botan_privkey_export_encrypted_pbkdf_msec()

BOTAN_DLL 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_runtime,
size_t *  pbkdf_iterations_out,
const char *  cipher_algo,
const char *  pbkdf_algo,
uint32_t  flags 
)

Definition at line 184 of file ffi_pkey.cpp.

193 {
194 if(pbkdf_iters_out) {
195 *pbkdf_iters_out = 0;
196 }
197
198 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
199 return copy_view_bin(
200 out, out_len, botan_privkey_view_encrypted_der_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
201 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
202 return copy_view_str(
203 out, out_len, botan_privkey_view_encrypted_pem_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
204 } else {
206 }
207}
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)
Definition ffi_pkey.cpp:209
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)
Definition ffi_pkey.cpp:235

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, botan_privkey_view_encrypted_der_timed(), botan_privkey_view_encrypted_pem_timed(), Botan_FFI::copy_view_bin(), and Botan_FFI::copy_view_str().

◆ botan_privkey_export_pubkey()

BOTAN_DLL int botan_privkey_export_pubkey ( botan_pubkey_t out,
botan_privkey_t  in 
)

Definition at line 103 of file ffi_pkey.cpp.

103 {
104 return ffi_guard_thunk(__func__, [=]() -> int {
105 auto public_key = safe_get(key_obj).public_key();
106 *pubout = new botan_pubkey_struct(std::move(public_key));
107 return BOTAN_FFI_SUCCESS;
108 });
109}

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

◆ botan_privkey_get_field()

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

Definition at line 159 of file ffi_pkey_algs.cpp.

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

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

Referenced by botan_privkey_dsa_get_x(), botan_privkey_rsa_get_d(), botan_privkey_rsa_get_e(), botan_privkey_rsa_get_n(), botan_privkey_rsa_get_p(), and botan_privkey_rsa_get_q().

◆ botan_privkey_load()

BOTAN_DLL int botan_privkey_load ( botan_privkey_t key,
botan_rng_t  rng,
const uint8_t  bits[],
size_t  len,
const char *  password 
)

Input currently assumed to be PKCS #8 structure; Set password to NULL to indicate no encryption expected Starting in 2.8.0, the rng parameter is unused and may be set to null

Definition at line 54 of file ffi_pkey.cpp.

55 {
56 BOTAN_UNUSED(rng_obj);
57
58 *key = nullptr;
59
60 return ffi_guard_thunk(__func__, [=]() -> int {
61 Botan::DataSource_Memory src(bits, len);
62
63 std::unique_ptr<Botan::Private_Key> pkcs8;
64
65 if(password == nullptr) {
66 pkcs8 = Botan::PKCS8::load_key(src);
67 } else {
68 pkcs8 = Botan::PKCS8::load_key(src, std::string(password));
69 }
70
71 if(pkcs8) {
72 *key = new botan_privkey_struct(std::move(pkcs8));
73 return BOTAN_FFI_SUCCESS;
74 }
76 });
77}
std::unique_ptr< Private_Key > load_key(DataSource &source, const std::function< std::string()> &get_pass)
Definition pkcs8.cpp:316

References BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan::PKCS8::load_key().

◆ botan_privkey_load_dh()

BOTAN_DLL int botan_privkey_load_dh ( botan_privkey_t key,
botan_mp_t  p,
botan_mp_t  g,
botan_mp_t  x 
)

Definition at line 477 of file ffi_pkey_algs.cpp.

477 {
478#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
479 *key = nullptr;
480 return ffi_guard_thunk(__func__, [=]() -> int {
481 Botan::DL_Group group(safe_get(p), safe_get(g));
482 auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
483 *key = new botan_privkey_struct(std::move(dh));
484 return BOTAN_FFI_SUCCESS;
485 });
486#else
487 BOTAN_UNUSED(key, p, g, x);
489#endif
490}

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

◆ botan_privkey_load_dsa()

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

300 {
301#if defined(BOTAN_HAS_DSA)
302 *key = nullptr;
303
304 return ffi_guard_thunk(__func__, [=]() -> int {
305 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
306 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(group, safe_get(x));
307 *key = new botan_privkey_struct(std::move(dsa));
308 return BOTAN_FFI_SUCCESS;
309 });
310#else
311 BOTAN_UNUSED(key, p, q, g, x);
313#endif
314}

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

◆ botan_privkey_load_ecdh()

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

Definition at line 543 of file ffi_pkey_algs.cpp.

543 {
544#if defined(BOTAN_HAS_ECDH)
545 return ffi_guard_thunk(__func__, [=]() -> int {
546 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
547 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
548 if(rc == BOTAN_FFI_SUCCESS) {
549 *key = new botan_privkey_struct(std::move(p_key));
550 }
551 return rc;
552 });
553#else
554 BOTAN_UNUSED(key, scalar, curve_name);
556#endif
557}

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

◆ botan_privkey_load_ecdsa()

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

Definition at line 397 of file ffi_pkey_algs.cpp.

397 {
398#if defined(BOTAN_HAS_ECDSA)
399 return ffi_guard_thunk(__func__, [=]() -> int {
400 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
401 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
402 if(rc == BOTAN_FFI_SUCCESS) {
403 *key = new botan_privkey_struct(std::move(p_key));
404 }
405 return rc;
406 });
407#else
408 BOTAN_UNUSED(key, scalar, curve_name);
410#endif
411}

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

◆ botan_privkey_load_ed25519()

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

Definition at line 644 of file ffi_pkey_algs.cpp.

644 {
645#if defined(BOTAN_HAS_ED25519)
646 *key = nullptr;
647 return ffi_guard_thunk(__func__, [=]() -> int {
648 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
649 auto ed25519 = std::make_unique<Botan::Ed25519_PrivateKey>(privkey_vec);
650 *key = new botan_privkey_struct(std::move(ed25519));
651 return BOTAN_FFI_SUCCESS;
652 });
653#else
654 BOTAN_UNUSED(key, privkey);
656#endif
657}

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

◆ botan_privkey_load_elgamal()

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

Loads ElGamal private key

Parameters
keyvariable populated with key material
pprime order of a Z_p group
ggroup generator
xprivate key
Precondition
key is NULL on input
Postcondition
function allocates memory and assigns to ‘key’
Returns
0 on success, a negative value on failure

Definition at line 456 of file ffi_pkey_algs.cpp.

456 {
457#if defined(BOTAN_HAS_ELGAMAL)
458 *key = nullptr;
459 return ffi_guard_thunk(__func__, [=]() -> int {
460 Botan::DL_Group group(safe_get(p), safe_get(g));
461 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(group, safe_get(x));
462 *key = new botan_privkey_struct(std::move(elg));
463 return BOTAN_FFI_SUCCESS;
464 });
465#else
466 BOTAN_UNUSED(key, p, g, x);
468#endif
469}

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

◆ botan_privkey_load_kyber()

BOTAN_DLL int botan_privkey_load_kyber ( botan_privkey_t key,
const uint8_t  privkey[],
size_t  key_len 
)

Definition at line 786 of file ffi_pkey_algs.cpp.

786 {
787#if defined(BOTAN_HAS_KYBER)
788 *key = nullptr;
789 switch(key_len) {
790 case 1632:
791 return ffi_guard_thunk(__func__, [=]() -> int {
792 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 1632);
793 auto kyber512 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber512_R3);
794 *key = new botan_privkey_struct(std::move(kyber512));
795 return BOTAN_FFI_SUCCESS;
796 });
797 case 2400:
798 return ffi_guard_thunk(__func__, [=]() -> int {
799 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 2400);
800 auto kyber768 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber768_R3);
801 *key = new botan_privkey_struct(std::move(kyber768));
802 return BOTAN_FFI_SUCCESS;
803 });
804 case 3168:
805 return ffi_guard_thunk(__func__, [=]() -> int {
806 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 3168);
807 auto kyber1024 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber1024_R3);
808 *key = new botan_privkey_struct(std::move(kyber1024));
809 return BOTAN_FFI_SUCCESS;
810 });
811 default:
812 BOTAN_UNUSED(key, privkey, key_len);
814 }
815#else
816 BOTAN_UNUSED(key, privkey);
818#endif
819}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::KyberMode::Kyber1024_R3, Botan::KyberMode::Kyber512_R3, and Botan::KyberMode::Kyber768_R3.

◆ botan_privkey_load_rsa()

BOTAN_DLL int botan_privkey_load_rsa ( botan_privkey_t key,
botan_mp_t  p,
botan_mp_t  q,
botan_mp_t  e 
)

Definition at line 181 of file ffi_pkey_algs.cpp.

181 {
182#if defined(BOTAN_HAS_RSA)
183 *key = nullptr;
184
185 return ffi_guard_thunk(__func__, [=]() -> int {
186 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p), safe_get(rsa_q), safe_get(rsa_e));
187 *key = new botan_privkey_struct(std::move(rsa));
188 return BOTAN_FFI_SUCCESS;
189 });
190#else
191 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
193#endif
194}

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

◆ botan_privkey_load_rsa_pkcs1()

BOTAN_DLL int botan_privkey_load_rsa_pkcs1 ( botan_privkey_t key,
const uint8_t  bits[],
size_t  len 
)

Definition at line 196 of file ffi_pkey_algs.cpp.

196 {
197#if defined(BOTAN_HAS_RSA)
198 *key = nullptr;
199
200 Botan::secure_vector<uint8_t> src(bits, bits + len);
201 return ffi_guard_thunk(__func__, [=]() -> int {
203 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, src);
204 *key = new botan_privkey_struct(std::move(rsa));
205 return BOTAN_FFI_SUCCESS;
206 });
207#else
208 BOTAN_UNUSED(key, bits, len);
210#endif
211}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan::AlgorithmIdentifier::USE_NULL_PARAM.

◆ botan_privkey_load_sm2()

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

Definition at line 614 of file ffi_pkey_algs.cpp.

614 {
615#if defined(BOTAN_HAS_SM2)
616 return ffi_guard_thunk(__func__, [=]() -> int {
617 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
618 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
619
620 if(rc == BOTAN_FFI_SUCCESS) {
621 *key = new botan_privkey_struct(std::move(p_key));
622 }
623 return rc;
624 });
625#else
626 BOTAN_UNUSED(key, scalar, curve_name);
628#endif
629}

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

Referenced by botan_privkey_load_sm2_enc().

◆ botan_privkey_load_sm2_enc()

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

Definition at line 638 of file ffi_pkey_algs.cpp.

638 {
639 return botan_privkey_load_sm2(key, scalar, curve_name);
640}
int botan_privkey_load_sm2(botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)

References botan_privkey_load_sm2().

◆ botan_privkey_load_x25519()

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

Definition at line 714 of file ffi_pkey_algs.cpp.

714 {
715#if defined(BOTAN_HAS_X25519)
716 *key = nullptr;
717 return ffi_guard_thunk(__func__, [=]() -> int {
718 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
719 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(privkey_vec);
720 *key = new botan_privkey_struct(std::move(x25519));
721 return BOTAN_FFI_SUCCESS;
722 });
723#else
724 BOTAN_UNUSED(key, privkey);
726#endif
727}

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

◆ botan_privkey_rsa_get_d()

BOTAN_DLL int botan_privkey_rsa_get_d ( botan_mp_t  d,
botan_privkey_t  rsa_key 
)

Definition at line 243 of file ffi_pkey_algs.cpp.

243 {
244 return botan_privkey_get_field(d, key, "d");
245}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_e()

BOTAN_DLL int botan_privkey_rsa_get_e ( botan_mp_t  e,
botan_privkey_t  rsa_key 
)

Definition at line 239 of file ffi_pkey_algs.cpp.

239 {
240 return botan_privkey_get_field(e, key, "e");
241}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_n()

BOTAN_DLL int botan_privkey_rsa_get_n ( botan_mp_t  n,
botan_privkey_t  rsa_key 
)

Definition at line 235 of file ffi_pkey_algs.cpp.

235 {
236 return botan_privkey_get_field(n, key, "n");
237}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_p()

BOTAN_DLL int botan_privkey_rsa_get_p ( botan_mp_t  p,
botan_privkey_t  rsa_key 
)

Definition at line 227 of file ffi_pkey_algs.cpp.

227 {
228 return botan_privkey_get_field(p, key, "p");
229}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_privkey()

BOTAN_DLL int botan_privkey_rsa_get_privkey ( botan_privkey_t  rsa_key,
uint8_t  out[],
size_t *  out_len,
uint32_t  flags 
)

Definition at line 255 of file ffi_pkey_algs.cpp.

255 {
256#if defined(BOTAN_HAS_RSA)
257 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
258 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
260 return write_vec_output(out, out_len, rsa->private_key_bits());
261 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
262 return write_str_output(out, out_len, Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
263 else
265 } else {
267 }
268 });
269#else
270 BOTAN_UNUSED(rsa_key, out, out_len, flags);
272#endif
273}
std::string encode(const uint8_t der[], size_t length, std::string_view label, size_t width)
Definition pem.cpp:39

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, BOTAN_UNUSED, Botan::PEM_Code::encode(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

◆ botan_privkey_rsa_get_q()

BOTAN_DLL int botan_privkey_rsa_get_q ( botan_mp_t  q,
botan_privkey_t  rsa_key 
)

Definition at line 231 of file ffi_pkey_algs.cpp.

231 {
232 return botan_privkey_get_field(q, key, "q");
233}

References botan_privkey_get_field().

◆ botan_privkey_view_der()

BOTAN_DLL int botan_privkey_view_der ( botan_privkey_t  key,
botan_view_ctx  ctx,
botan_view_bin_fn  view 
)

View the private key's DER encoding

Definition at line 164 of file ffi_pkey.cpp.

164 {
165 return BOTAN_FFI_VISIT(
166 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::BER_encode(k)); });
167}
std::vector< uint8_t > BER_encode(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, std::chrono::milliseconds msec, std::string_view pbe_algo)
Definition pkcs8.cpp:163

References Botan::PKCS8::BER_encode(), BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

Referenced by botan_privkey_export().

◆ botan_privkey_view_encrypted_der()

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

View the encryption of a private key (binary DER encoding)

Set cipher_algo, pbkdf_algo to NULL to use defaults Set pbkdf_iterations to 0 to use defaults

Definition at line 281 of file ffi_pkey.cpp.

288 {
289 if(passphrase == nullptr) {
291 }
292
293 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
295
296 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
297 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
298 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
299
300 auto pkcs8 = Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
301
302 return invoke_view_callback(view, ctx, pkcs8);
303 });
304}
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)
Definition pkcs8.cpp:203

References Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::invoke_view_callback(), and Botan_FFI::safe_get().

Referenced by botan_privkey_export_encrypted_pbkdf_iter().

◆ botan_privkey_view_encrypted_der_timed()

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

View the encryption of a private key (binary DER encoding)

Set cipher_algo, pbkdf_algo to NULL to use defaults

Definition at line 209 of file ffi_pkey.cpp.

216 {
217 if(passphrase == nullptr) {
219 }
220
221 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
222 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
224
225 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
226 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
227
228 auto pkcs8 =
229 Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
230
231 return invoke_view_callback(view, ctx, pkcs8);
232 });
233}
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)
Definition pkcs8.cpp:246

References Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::invoke_view_callback(), and Botan_FFI::safe_get().

Referenced by botan_privkey_export_encrypted_pbkdf_msec().

◆ botan_privkey_view_encrypted_pem()

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

View the encryption of a private key (PEM encoding)

Set cipher_algo, pbkdf_algo to NULL to use defaults Set pbkdf_iterations to 0 to use defaults

Definition at line 306 of file ffi_pkey.cpp.

313 {
314 if(passphrase == nullptr) {
316 }
317
318 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
320
321 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
322 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
323 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
324
325 auto pkcs8 = Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
326
327 return invoke_view_callback(view, ctx, pkcs8);
328 });
329}
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)
Definition pkcs8.cpp:233

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::invoke_view_callback(), Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(), and Botan_FFI::safe_get().

Referenced by botan_privkey_export_encrypted_pbkdf_iter().

◆ botan_privkey_view_encrypted_pem_timed()

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

View the encryption of a private key (PEM encoding)

Set cipher_algo, pbkdf_algo to NULL to use defaults

Definition at line 235 of file ffi_pkey.cpp.

242 {
243 if(passphrase == nullptr) {
245 }
246
247 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
248 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
250
251 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
252 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
253
254 auto pkcs8 =
255 Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
256
257 return invoke_view_callback(view, ctx, pkcs8);
258 });
259}
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)
Definition pkcs8.cpp:280

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::invoke_view_callback(), Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(), and Botan_FFI::safe_get().

Referenced by botan_privkey_export_encrypted_pbkdf_msec().

◆ botan_privkey_view_kyber_raw_key()

BOTAN_DLL int botan_privkey_view_kyber_raw_key ( botan_privkey_t  key,
botan_view_ctx  ctx,
botan_view_bin_fn  view 
)

Definition at line 856 of file ffi_pkey_algs.cpp.

856 {
857#if defined(BOTAN_HAS_KYBER)
858 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
859 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
860 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
861 } else {
863 }
864 });
865#else
866 BOTAN_UNUSED(key, ctx, view);
868#endif
869}

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

◆ botan_privkey_view_pem()

BOTAN_DLL int botan_privkey_view_pem ( botan_privkey_t  key,
botan_view_ctx  ctx,
botan_view_str_fn  view 
)

View the private key's PEM encoding

Definition at line 169 of file ffi_pkey.cpp.

169 {
170 return BOTAN_FFI_VISIT(
171 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::PEM_encode(k)); });
172}
std::string PEM_encode(const Private_Key &key)
Definition pkcs8.cpp:118

References BOTAN_FFI_VISIT, Botan_FFI::invoke_view_callback(), and Botan::PKCS8::PEM_encode().

Referenced by botan_privkey_export().

◆ botan_privkey_x25519_get_privkey()

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

Definition at line 744 of file ffi_pkey_algs.cpp.

744 {
745#if defined(BOTAN_HAS_X25519)
746 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
747 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
748 const auto x25519_key = x25519->raw_private_key_bits();
749 if(x25519_key.size() != 32)
751 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
752 return BOTAN_FFI_SUCCESS;
753 } else {
755 }
756 });
757#else
758 BOTAN_UNUSED(key, output);
760#endif
761}

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

◆ botan_pubkey_algo_name()

BOTAN_DLL int botan_pubkey_algo_name ( botan_pubkey_t  key,
char  out[],
size_t *  out_len 
)

Definition at line 115 of file ffi_pkey.cpp.

115 {
116 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
117}

References BOTAN_FFI_VISIT, and Botan_FFI::write_str_output().

◆ botan_pubkey_check_key()

BOTAN_DLL int botan_pubkey_check_key ( botan_pubkey_t  key,
botan_rng_t  rng,
uint32_t  flags 
)

Returns 0 if key is valid, negative if invalid key or some other error

Definition at line 119 of file ffi_pkey.cpp.

119 {
120 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
121
122 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
123 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
124 });
125}

References BOTAN_CHECK_KEY_EXPENSIVE_TESTS, BOTAN_FFI_ERROR_INVALID_INPUT, BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_pubkey_destroy()

BOTAN_DLL int botan_pubkey_destroy ( botan_pubkey_t  key)
Returns
0 if success, error if invalid object handle

Definition at line 99 of file ffi_pkey.cpp.

99 {
100 return BOTAN_FFI_CHECKED_DELETE(key);
101}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pubkey_dsa_get_g()

BOTAN_DLL int botan_pubkey_dsa_get_g ( botan_mp_t  d,
botan_pubkey_t  key 
)

Definition at line 344 of file ffi_pkey_algs.cpp.

344 {
345 return botan_pubkey_get_field(g, key, "g");
346}
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_p()

BOTAN_DLL int botan_pubkey_dsa_get_p ( botan_mp_t  p,
botan_pubkey_t  key 
)

Definition at line 336 of file ffi_pkey_algs.cpp.

336 {
337 return botan_pubkey_get_field(p, key, "p");
338}

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_q()

BOTAN_DLL int botan_pubkey_dsa_get_q ( botan_mp_t  q,
botan_pubkey_t  key 
)

Definition at line 340 of file ffi_pkey_algs.cpp.

340 {
341 return botan_pubkey_get_field(q, key, "q");
342}

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_y()

BOTAN_DLL int botan_pubkey_dsa_get_y ( botan_mp_t  y,
botan_pubkey_t  key 
)

Definition at line 348 of file ffi_pkey_algs.cpp.

348 {
349 return botan_pubkey_get_field(y, key, "y");
350}

References botan_pubkey_get_field().

◆ botan_pubkey_ecc_key_used_explicit_encoding()

BOTAN_DLL int botan_pubkey_ecc_key_used_explicit_encoding ( botan_pubkey_t  key)

Definition at line 358 of file ffi_pkey_algs.cpp.

358 {
359#if defined(BOTAN_HAS_ECC_KEY)
360 return ffi_guard_thunk(__func__, [=]() -> int {
361 const Botan::Public_Key& pub_key = safe_get(key);
362 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
363
364 if(ec_key == nullptr) {
366 }
367
368 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
369 });
370#else
371 BOTAN_UNUSED(key);
373#endif
374}
bool used_explicit_encoding() const
Definition ec_group.h:359
const EC_Group & domain() const
Definition ecc_key.h:54

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, Botan::EC_PublicKey::domain(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::EC_Group::used_explicit_encoding().

◆ botan_pubkey_ed25519_get_pubkey()

BOTAN_DLL int botan_pubkey_ed25519_get_pubkey ( botan_pubkey_t  key,
uint8_t  pubkey[32] 
)

Definition at line 693 of file ffi_pkey_algs.cpp.

693 {
694#if defined(BOTAN_HAS_ED25519)
695 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
696 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
697 const std::vector<uint8_t>& ed_key = ed->get_public_key();
698 if(ed_key.size() != 32)
700 Botan::copy_mem(output, ed_key.data(), ed_key.size());
701 return BOTAN_FFI_SUCCESS;
702 } else {
704 }
705 });
706#else
707 BOTAN_UNUSED(key, output);
709#endif
710}

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

◆ botan_pubkey_estimated_strength()

BOTAN_DLL int botan_pubkey_estimated_strength ( botan_pubkey_t  key,
size_t *  estimate 
)

Definition at line 331 of file ffi_pkey.cpp.

331 {
332 return BOTAN_FFI_VISIT(key, [=](const auto& k) { *estimate = k.estimated_strength(); });
333}

References BOTAN_FFI_VISIT.

◆ botan_pubkey_export()

BOTAN_DLL int botan_pubkey_export ( botan_pubkey_t  key,
uint8_t  out[],
size_t *  out_len,
uint32_t  flags 
)

Definition at line 134 of file ffi_pkey.cpp.

134 {
135 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
136 return copy_view_bin(out, out_len, botan_pubkey_view_der, key);
137 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
138 return copy_view_str(out, out_len, botan_pubkey_view_pem, key);
139 } else {
141 }
142}
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:149
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:144

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, botan_pubkey_view_der(), botan_pubkey_view_pem(), Botan_FFI::copy_view_bin(), and Botan_FFI::copy_view_str().

◆ botan_pubkey_fingerprint()

BOTAN_DLL int botan_pubkey_fingerprint ( botan_pubkey_t  key,
const char *  hash,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 335 of file ffi_pkey.cpp.

335 {
336 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
337 auto h = Botan::HashFunction::create_or_throw(hash_fn);
338 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
339 });
340}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:288

References BOTAN_FFI_VISIT, Botan::HashFunction::create_or_throw(), and Botan_FFI::write_vec_output().

◆ botan_pubkey_get_field()

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

Definition at line 149 of file ffi_pkey_algs.cpp.

149 {
150 if(field_name_cstr == nullptr) {
152 }
153
154 const std::string field_name(field_name_cstr);
155
156 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); });
157}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

Referenced by botan_pubkey_dsa_get_g(), botan_pubkey_dsa_get_p(), botan_pubkey_dsa_get_q(), botan_pubkey_dsa_get_y(), botan_pubkey_rsa_get_e(), and botan_pubkey_rsa_get_n().

◆ botan_pubkey_load()

BOTAN_DLL int botan_pubkey_load ( botan_pubkey_t key,
const uint8_t  bits[],
size_t  len 
)

Definition at line 83 of file ffi_pkey.cpp.

83 {
84 *key = nullptr;
85
86 return ffi_guard_thunk(__func__, [=]() -> int {
87 Botan::DataSource_Memory src(bits, bits_len);
88 std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src));
89
90 if(pubkey == nullptr) {
92 }
93
94 *key = new botan_pubkey_struct(std::move(pubkey));
95 return BOTAN_FFI_SUCCESS;
96 });
97}
std::unique_ptr< Public_Key > load_key(DataSource &source)
Definition x509_key.cpp:28

References BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan::X509::load_key().

◆ botan_pubkey_load_dh()

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

Loads Diffie Hellman public key

Parameters
keyvariable populated with key material
pprime order of a Z_p group
ggroup generator
ypublic key
Precondition
key is NULL on input
Postcondition
function allocates memory and assigns to ‘key’
Returns
0 on success, a negative value on failure

Definition at line 492 of file ffi_pkey_algs.cpp.

492 {
493#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
494 *key = nullptr;
495 return ffi_guard_thunk(__func__, [=]() -> int {
496 Botan::DL_Group group(safe_get(p), safe_get(g));
497 auto dh = std::make_unique<Botan::DH_PublicKey>(group, safe_get(y));
498 *key = new botan_pubkey_struct(std::move(dh));
499 return BOTAN_FFI_SUCCESS;
500 });
501#else
502 BOTAN_UNUSED(key, p, g, y);
504#endif
505}

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

◆ botan_pubkey_load_dsa()

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

316 {
317#if defined(BOTAN_HAS_DSA)
318 *key = nullptr;
319
320 return ffi_guard_thunk(__func__, [=]() -> int {
321 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
322 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
323 *key = new botan_pubkey_struct(std::move(dsa));
324 return BOTAN_FFI_SUCCESS;
325 });
326#else
327 BOTAN_UNUSED(key, p, q, g, y);
329#endif
330}

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

◆ botan_pubkey_load_ecdh()

BOTAN_DLL int botan_pubkey_load_ecdh ( botan_pubkey_t key,
botan_mp_t  public_x,
botan_mp_t  public_y,
const char *  curve_name 
)

Definition at line 523 of file ffi_pkey_algs.cpp.

526 {
527#if defined(BOTAN_HAS_ECDH)
528 return ffi_guard_thunk(__func__, [=]() -> int {
529 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
530 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
531
532 if(rc == BOTAN_FFI_SUCCESS) {
533 *key = new botan_pubkey_struct(std::move(p_key));
534 }
535 return rc;
536 });
537#else
538 BOTAN_UNUSED(key, public_x, public_y, curve_name);
540#endif
541}

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

◆ botan_pubkey_load_ecdsa()

BOTAN_DLL int botan_pubkey_load_ecdsa ( botan_pubkey_t key,
botan_mp_t  public_x,
botan_mp_t  public_y,
const char *  curve_name 
)

Definition at line 376 of file ffi_pkey_algs.cpp.

379 {
380#if defined(BOTAN_HAS_ECDSA)
381 return ffi_guard_thunk(__func__, [=]() -> int {
382 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
383
384 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
385 if(rc == BOTAN_FFI_SUCCESS) {
386 *key = new botan_pubkey_struct(std::move(p_key));
387 }
388
389 return rc;
390 });
391#else
392 BOTAN_UNUSED(key, public_x, public_y, curve_name);
394#endif
395}

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

◆ botan_pubkey_load_ed25519()

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

Definition at line 659 of file ffi_pkey_algs.cpp.

659 {
660#if defined(BOTAN_HAS_ED25519)
661 *key = nullptr;
662 return ffi_guard_thunk(__func__, [=]() -> int {
663 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
664 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
665 *key = new botan_pubkey_struct(std::move(ed25519));
666 return BOTAN_FFI_SUCCESS;
667 });
668#else
669 BOTAN_UNUSED(key, pubkey);
671#endif
672}

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

◆ botan_pubkey_load_elgamal()

BOTAN_DLL int botan_pubkey_load_elgamal ( botan_pubkey_t key,
botan_mp_t  p,
botan_mp_t