Botan 3.7.1
Crypto and TLS for C&
ffi.h File Reference

Public Header. More...

#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_API_VERSION   20240408
 
#define BOTAN_FFI_DEPRECATED(msg)
 
#define BOTAN_FFI_EXPORT(maj, min)
 
#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_PRIVKEY_EXPORT_FLAG_RAW   2
 
#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 struct botan_tpm2_crypto_backend_state_struct * botan_tpm2_crypto_backend_state_t
 
typedef struct botan_tpm2_ctx_struct * botan_tpm2_ctx_t
 
typedef struct botan_tpm2_session_struct * botan_tpm2_session_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_TPM_ERROR = -78 , 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

int botan_base64_decode (const char *base64_str, size_t in_len, uint8_t *out, size_t *out_len)
 
int botan_base64_encode (const uint8_t *x, size_t len, char *out, size_t *out_len)
 
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)
 
int botan_bcrypt_is_valid (const char *pass, const char *hash)
 
int botan_block_cipher_block_size (botan_block_cipher_t bc)
 
int botan_block_cipher_clear (botan_block_cipher_t bc)
 
int botan_block_cipher_decrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
 
int botan_block_cipher_destroy (botan_block_cipher_t bc)
 
int botan_block_cipher_encrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
 
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)
 
int botan_block_cipher_init (botan_block_cipher_t *bc, const char *cipher_name)
 
int botan_block_cipher_name (botan_block_cipher_t cipher, char *name, size_t *name_len)
 
int botan_block_cipher_set_key (botan_block_cipher_t bc, const uint8_t key[], size_t len)
 
int botan_cipher_clear (botan_cipher_t hash)
 
int botan_cipher_destroy (botan_cipher_t cipher)
 
int botan_cipher_get_default_nonce_length (botan_cipher_t cipher, size_t *nl)
 
int botan_cipher_get_ideal_update_granularity (botan_cipher_t cipher, size_t *ug)
 
int botan_cipher_get_keyspec (botan_cipher_t, size_t *min_keylen, size_t *max_keylen, size_t *mod_keylen)
 
int botan_cipher_get_tag_length (botan_cipher_t cipher, size_t *tag_size)
 
int botan_cipher_get_update_granularity (botan_cipher_t cipher, size_t *ug)
 
int botan_cipher_init (botan_cipher_t *cipher, const char *name, uint32_t flags)
 
int botan_cipher_is_authenticated (botan_cipher_t cipher)
 
int botan_cipher_name (botan_cipher_t cipher, char *name, size_t *name_len)
 
int botan_cipher_output_length (botan_cipher_t cipher, size_t in_len, size_t *out_len)
 
int botan_cipher_query_keylen (botan_cipher_t, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
 
int botan_cipher_requires_entire_message (botan_cipher_t cipher)
 
int botan_cipher_reset (botan_cipher_t cipher)
 
int botan_cipher_set_associated_data (botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
 
int botan_cipher_set_key (botan_cipher_t cipher, const uint8_t *key, size_t key_len)
 
int botan_cipher_start (botan_cipher_t cipher, const uint8_t *nonce, size_t nonce_len)
 
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/Decrypt some data and/or finalize the encryption/decryption.
 
int botan_cipher_valid_nonce_length (botan_cipher_t cipher, size_t nl)
 
int botan_constant_time_compare (const uint8_t *x, const uint8_t *y, size_t len)
 
const char * botan_error_description (int err)
 
const char * botan_error_last_exception_message (void)
 
uint32_t botan_ffi_api_version (void)
 
int botan_ffi_supports_api (uint32_t api_version)
 
int botan_fpe_decrypt (botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
 
int botan_fpe_destroy (botan_fpe_t fpe)
 
int botan_fpe_encrypt (botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
 
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)
 
int botan_hash_block_size (botan_hash_t hash, size_t *block_size)
 
int botan_hash_clear (botan_hash_t hash)
 
int botan_hash_copy_state (botan_hash_t *dest, botan_hash_t source)
 
int botan_hash_destroy (botan_hash_t hash)
 
int botan_hash_final (botan_hash_t hash, uint8_t out[])
 
int botan_hash_init (botan_hash_t *hash, const char *hash_name, uint32_t flags)
 
int botan_hash_name (botan_hash_t hash, char *name, size_t *name_len)
 
int botan_hash_output_length (botan_hash_t hash, size_t *output_length)
 
int botan_hash_update (botan_hash_t hash, const uint8_t *in, size_t in_len)
 
int botan_hex_decode (const char *hex_str, size_t in_len, uint8_t *out, size_t *out_len)
 
int botan_hex_encode (const uint8_t *x, size_t len, char *out, uint32_t flags)
 
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)
 
int botan_hotp_destroy (botan_hotp_t hotp)
 
int botan_hotp_generate (botan_hotp_t hotp, uint32_t *hotp_code, uint64_t hotp_counter)
 
int botan_hotp_init (botan_hotp_t *hotp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits)
 
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)
 
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)
 
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)
 
int botan_mac_clear (botan_mac_t mac)
 
int botan_mac_destroy (botan_mac_t mac)
 
int botan_mac_final (botan_mac_t mac, uint8_t out[])
 
int botan_mac_get_keyspec (botan_mac_t mac, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
 
int botan_mac_init (botan_mac_t *mac, const char *mac_name, uint32_t flags)
 
int botan_mac_name (botan_mac_t mac, char *name, size_t *name_len)
 
int botan_mac_output_length (botan_mac_t mac, size_t *output_length)
 
int botan_mac_set_key (botan_mac_t mac, const uint8_t *key, size_t key_len)
 
int botan_mac_set_nonce (botan_mac_t mac, const uint8_t *nonce, size_t nonce_len)
 
int botan_mac_update (botan_mac_t mac, const uint8_t *buf, size_t len)
 
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)
 
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)
 
int botan_mp_add (botan_mp_t result, botan_mp_t x, botan_mp_t y)
 
int botan_mp_add_u32 (botan_mp_t result, botan_mp_t x, uint32_t y)
 
int botan_mp_clear (botan_mp_t mp)
 
int botan_mp_clear_bit (botan_mp_t n, size_t bit)
 
int botan_mp_cmp (int *result, botan_mp_t x, botan_mp_t y)
 
int botan_mp_destroy (botan_mp_t mp)
 
int botan_mp_div (botan_mp_t quotient, botan_mp_t remainder, botan_mp_t x, botan_mp_t y)
 
int botan_mp_equal (botan_mp_t x, botan_mp_t y)
 
int botan_mp_flip_sign (botan_mp_t mp)
 
int botan_mp_from_bin (botan_mp_t mp, const uint8_t vec[], size_t vec_len)
 
int botan_mp_gcd (botan_mp_t out, botan_mp_t x, botan_mp_t y)
 
int botan_mp_get_bit (botan_mp_t n, size_t bit)
 
int botan_mp_init (botan_mp_t *mp)
 
int botan_mp_is_even (botan_mp_t mp)
 
int botan_mp_is_negative (botan_mp_t mp)
 
int botan_mp_is_odd (botan_mp_t mp)
 
int botan_mp_is_positive (botan_mp_t mp)
 
int botan_mp_is_prime (botan_mp_t n, botan_rng_t rng, size_t test_prob)
 
int botan_mp_is_zero (botan_mp_t mp)
 
int botan_mp_lshift (botan_mp_t out, botan_mp_t in, size_t shift)
 
int botan_mp_mod_inverse (botan_mp_t out, botan_mp_t in, botan_mp_t modulus)
 
int botan_mp_mod_mul (botan_mp_t result, botan_mp_t x, botan_mp_t y, botan_mp_t mod)
 
int botan_mp_mul (botan_mp_t result, botan_mp_t x, botan_mp_t y)
 
int botan_mp_num_bits (botan_mp_t n, size_t *bits)
 
int botan_mp_num_bytes (botan_mp_t n, size_t *bytes)
 
int botan_mp_powmod (botan_mp_t out, botan_mp_t base, botan_mp_t exponent, botan_mp_t modulus)
 
int botan_mp_rand_bits (botan_mp_t rand_out, botan_rng_t rng, size_t bits)
 
int botan_mp_rand_range (botan_mp_t rand_out, botan_rng_t rng, botan_mp_t lower_bound, botan_mp_t upper_bound)
 
int botan_mp_rshift (botan_mp_t out, botan_mp_t in, size_t shift)
 
int botan_mp_set_bit (botan_mp_t n, size_t bit)
 
int botan_mp_set_from_int (botan_mp_t mp, int initial_value)
 
int botan_mp_set_from_mp (botan_mp_t dest, botan_mp_t source)
 
int botan_mp_set_from_radix_str (botan_mp_t dest, const char *str, size_t radix)
 
int botan_mp_set_from_str (botan_mp_t dest, const char *str)
 
int botan_mp_sub (botan_mp_t result, botan_mp_t x, botan_mp_t y)
 
int botan_mp_sub_u32 (botan_mp_t result, botan_mp_t x, uint32_t y)
 
int botan_mp_swap (botan_mp_t x, botan_mp_t y)
 
int botan_mp_to_bin (botan_mp_t mp, uint8_t vec[])
 
int botan_mp_to_hex (botan_mp_t mp, char *out)
 
int botan_mp_to_str (botan_mp_t mp, uint8_t base, char *out, size_t *out_len)
 
int botan_mp_to_uint32 (botan_mp_t mp, uint32_t *val)
 
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)
 
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)
 
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)
 
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)
 
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)
 
int botan_pk_op_decrypt_create (botan_pk_op_decrypt_t *op, botan_privkey_t key, const char *padding, uint32_t flags)
 
int botan_pk_op_decrypt_destroy (botan_pk_op_decrypt_t op)
 
int botan_pk_op_decrypt_output_length (botan_pk_op_decrypt_t op, size_t ctext_len, size_t *ptext_len)
 
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)
 
int botan_pk_op_encrypt_create (botan_pk_op_encrypt_t *op, botan_pubkey_t key, const char *padding, uint32_t flags)
 
int botan_pk_op_encrypt_destroy (botan_pk_op_encrypt_t op)
 
int botan_pk_op_encrypt_output_length (botan_pk_op_encrypt_t op, size_t ptext_len, size_t *ctext_len)
 
int botan_pk_op_kem_decrypt_create (botan_pk_op_kem_decrypt_t *op, botan_privkey_t key, const char *kdf)
 
int botan_pk_op_kem_decrypt_destroy (botan_pk_op_kem_decrypt_t op)
 
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)
 
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)
 
int botan_pk_op_kem_encrypt_create (botan_pk_op_kem_encrypt_t *op, botan_pubkey_t key, const char *kdf)
 
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)
 
int botan_pk_op_kem_encrypt_destroy (botan_pk_op_kem_encrypt_t op)
 
int botan_pk_op_kem_encrypt_encapsulated_key_length (botan_pk_op_kem_encrypt_t op, size_t *output_encapsulated_key_length)
 
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)
 
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)
 
int botan_pk_op_key_agreement_create (botan_pk_op_ka_t *op, botan_privkey_t key, const char *kdf, uint32_t flags)
 
int botan_pk_op_key_agreement_destroy (botan_pk_op_ka_t op)
 
int botan_pk_op_key_agreement_export_public (botan_privkey_t key, uint8_t out[], size_t *out_len)
 
int botan_pk_op_key_agreement_size (botan_pk_op_ka_t op, size_t *out_len)
 
int botan_pk_op_key_agreement_view_public (botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pk_op_sign_create (botan_pk_op_sign_t *op, botan_privkey_t key, const char *hash_and_padding, uint32_t flags)
 
int botan_pk_op_sign_destroy (botan_pk_op_sign_t op)
 
int botan_pk_op_sign_finish (botan_pk_op_sign_t op, botan_rng_t rng, uint8_t sig[], size_t *sig_len)
 
int botan_pk_op_sign_output_length (botan_pk_op_sign_t op, size_t *olen)
 
int botan_pk_op_sign_update (botan_pk_op_sign_t op, const uint8_t in[], size_t in_len)
 
int botan_pk_op_verify_create (botan_pk_op_verify_t *op, botan_pubkey_t key, const char *hash_and_padding, uint32_t flags)
 
int botan_pk_op_verify_destroy (botan_pk_op_verify_t op)
 
int botan_pk_op_verify_finish (botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len)
 
int botan_pk_op_verify_update (botan_pk_op_verify_t op, const uint8_t in[], size_t in_len)
 
int botan_pkcs_hash_id (const char *hash_name, uint8_t pkcs_id[], size_t *pkcs_id_len)
 
int botan_privkey_algo_name (botan_privkey_t key, char out[], size_t *out_len)
 
int botan_privkey_check_key (botan_privkey_t key, botan_rng_t rng, uint32_t flags)
 
int botan_privkey_create (botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
 
int botan_privkey_create_dh (botan_privkey_t *key, botan_rng_t rng, const char *param)
 
int botan_privkey_create_dsa (botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
 
int botan_privkey_create_ecdh (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
int botan_privkey_create_ecdsa (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
int botan_privkey_create_elgamal (botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
 
int botan_privkey_create_mceliece (botan_privkey_t *key, botan_rng_t rng, size_t n, size_t t)
 
int botan_privkey_create_rsa (botan_privkey_t *key, botan_rng_t rng, size_t n_bits)
 
int botan_privkey_destroy (botan_privkey_t key)
 
int botan_privkey_dsa_get_x (botan_mp_t n, botan_privkey_t key)
 
int botan_privkey_ed25519_get_privkey (botan_privkey_t key, uint8_t output[64])
 
int botan_privkey_ed448_get_privkey (botan_privkey_t key, uint8_t output[57])
 
int botan_privkey_export (botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
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)
 
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)
 
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)
 
int botan_privkey_export_pubkey (botan_pubkey_t *out, botan_privkey_t in)
 
int botan_privkey_get_field (botan_mp_t output, botan_privkey_t key, const char *field_name)
 
int botan_privkey_load (botan_privkey_t *key, botan_rng_t rng, const uint8_t bits[], size_t len, const char *password)
 
int botan_privkey_load_classic_mceliece (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *cmce_mode)
 
int botan_privkey_load_dh (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
 
int botan_privkey_load_dsa (botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t x)
 
int botan_privkey_load_ecdh (botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_ecdsa (botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_ed25519 (botan_privkey_t *key, const uint8_t privkey[32])
 
int botan_privkey_load_ed448 (botan_privkey_t *key, const uint8_t privkey[57])
 
int botan_privkey_load_elgamal (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
 
int botan_privkey_load_frodokem (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *frodo_mode)
 
int botan_privkey_load_kyber (botan_privkey_t *key, const uint8_t privkey[], size_t key_len)
 
int botan_privkey_load_ml_dsa (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *mldsa_mode)
 
int botan_privkey_load_ml_kem (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *mlkem_mode)
 
int botan_privkey_load_rsa (botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t e)
 
int botan_privkey_load_rsa_pkcs1 (botan_privkey_t *key, const uint8_t bits[], size_t len)
 
int botan_privkey_load_slh_dsa (botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *slhdsa_mode)
 
int botan_privkey_load_sm2 (botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_sm2_enc (botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_x25519 (botan_privkey_t *key, const uint8_t privkey[32])
 
int botan_privkey_load_x448 (botan_privkey_t *key, const uint8_t privkey[56])
 
int botan_privkey_rsa_get_d (botan_mp_t d, botan_privkey_t rsa_key)
 
int botan_privkey_rsa_get_e (botan_mp_t e, botan_privkey_t rsa_key)
 
int botan_privkey_rsa_get_n (botan_mp_t n, botan_privkey_t rsa_key)
 
int botan_privkey_rsa_get_p (botan_mp_t p, botan_privkey_t rsa_key)
 
int botan_privkey_rsa_get_privkey (botan_privkey_t rsa_key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_privkey_rsa_get_q (botan_mp_t q, botan_privkey_t rsa_key)
 
int botan_privkey_view_der (botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
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)
 
int botan_privkey_view_encrypted_der_timed (botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_view_encrypted_pem (botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_iterations, botan_view_ctx ctx, botan_view_str_fn view)
 
int botan_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)
 
int botan_privkey_view_kyber_raw_key (botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_view_pem (botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
 
int botan_privkey_view_raw (botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_privkey_x25519_get_privkey (botan_privkey_t key, uint8_t output[32])
 
int botan_privkey_x448_get_privkey (botan_privkey_t key, uint8_t output[56])
 
int botan_pubkey_algo_name (botan_pubkey_t key, char out[], size_t *out_len)
 
int botan_pubkey_check_key (botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
 
int botan_pubkey_destroy (botan_pubkey_t key)
 
int botan_pubkey_dsa_get_g (botan_mp_t d, botan_pubkey_t key)
 
int botan_pubkey_dsa_get_p (botan_mp_t p, botan_pubkey_t key)
 
int botan_pubkey_dsa_get_q (botan_mp_t q, botan_pubkey_t key)
 
int botan_pubkey_dsa_get_y (botan_mp_t y, botan_pubkey_t key)
 
int botan_pubkey_ecc_key_used_explicit_encoding (botan_pubkey_t key)
 
int botan_pubkey_ed25519_get_pubkey (botan_pubkey_t key, uint8_t pubkey[32])
 
int botan_pubkey_ed448_get_pubkey (botan_pubkey_t key, uint8_t pubkey[57])
 
int botan_pubkey_estimated_strength (botan_pubkey_t key, size_t *estimate)
 
int botan_pubkey_export (botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_pubkey_fingerprint (botan_pubkey_t key, const char *hash, uint8_t out[], size_t *out_len)
 
int botan_pubkey_get_field (botan_mp_t output, botan_pubkey_t key, const char *field_name)
 
int botan_pubkey_load (botan_pubkey_t *key, const uint8_t bits[], size_t len)
 
int botan_pubkey_load_classic_mceliece (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *cmce_mode)
 
int botan_pubkey_load_dh (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
 
int botan_pubkey_load_dsa (botan_pubkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t y)
 
int botan_pubkey_load_ecdh (botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_ecdsa (botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_ed25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
 
int botan_pubkey_load_ed448 (botan_pubkey_t *key, const uint8_t pubkey[57])
 
int botan_pubkey_load_elgamal (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
 
int botan_pubkey_load_frodokem (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *frodo_mode)
 
int botan_pubkey_load_kyber (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len)
 
int botan_pubkey_load_ml_dsa (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *mldsa_mode)
 
int botan_pubkey_load_ml_kem (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *mlkem_mode)
 
int botan_pubkey_load_rsa (botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
 
int botan_pubkey_load_slh_dsa (botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *slhdsa_mode)
 
int botan_pubkey_load_sm2 (botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_sm2_enc (botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_x25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
 
int botan_pubkey_load_x448 (botan_pubkey_t *key, const uint8_t pubkey[56])
 
int botan_pubkey_rsa_get_e (botan_mp_t e, botan_pubkey_t rsa_key)
 
int botan_pubkey_rsa_get_n (botan_mp_t n, botan_pubkey_t rsa_key)
 
int botan_pubkey_sm2_compute_za (uint8_t out[], size_t *out_len, const char *ident, const char *hash_algo, botan_pubkey_t key)
 
int botan_pubkey_view_der (botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pubkey_view_ec_public_point (botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pubkey_view_kyber_raw_key (botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pubkey_view_pem (botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
 
int botan_pubkey_view_raw (botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pubkey_x25519_get_pubkey (botan_pubkey_t key, uint8_t pubkey[32])
 
int botan_pubkey_x448_get_pubkey (botan_pubkey_t key, uint8_t pubkey[56])
 
int 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_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)
 
int botan_rng_add_entropy (botan_rng_t rng, const uint8_t *entropy, size_t entropy_len)
 
int botan_rng_destroy (botan_rng_t rng)
 
int botan_rng_get (botan_rng_t rng, uint8_t *out, size_t out_len)
 
int botan_rng_init (botan_rng_t *rng, const char *rng_type)
 
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))
 
int botan_rng_reseed (botan_rng_t rng, size_t bits)
 
int botan_rng_reseed_from_rng (botan_rng_t rng, botan_rng_t source_rng, size_t bits)
 
int botan_same_mem (const uint8_t *x, const uint8_t *y, size_t len)
 
int botan_scrub_mem (void *mem, size_t bytes)
 
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)
 
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)
 
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)
 
int botan_srp6_group_size (const char *group_id, size_t *group_p_bytes)
 
int botan_srp6_server_session_destroy (botan_srp6_server_session_t srp6)
 
int botan_srp6_server_session_init (botan_srp6_server_session_t *srp6)
 
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)
 
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)
 
int botan_system_rng_get (uint8_t *out, size_t out_len)
 
int botan_totp_check (botan_totp_t totp, uint32_t totp_code, uint64_t timestamp, size_t acceptable_clock_drift)
 
int botan_totp_destroy (botan_totp_t totp)
 
int botan_totp_generate (botan_totp_t totp, uint32_t *totp_code, uint64_t timestamp)
 
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)
 
int botan_tpm2_crypto_backend_state_destroy (botan_tpm2_crypto_backend_state_t cbs)
 
int botan_tpm2_ctx_destroy (botan_tpm2_ctx_t ctx)
 
int botan_tpm2_ctx_enable_crypto_backend (botan_tpm2_ctx_t ctx, botan_rng_t rng)
 
int botan_tpm2_ctx_from_esys (botan_tpm2_ctx_t *ctx_out, struct ESYS_CONTEXT *esys_ctx)
 
int botan_tpm2_ctx_init (botan_tpm2_ctx_t *ctx_out, const char *tcti_nameconf)
 
int botan_tpm2_ctx_init_ex (botan_tpm2_ctx_t *ctx_out, const char *tcti_name, const char *tcti_conf)
 
int botan_tpm2_enable_crypto_backend (botan_tpm2_crypto_backend_state_t *cbs_out, struct ESYS_CONTEXT *esys_ctx, botan_rng_t rng)
 
int botan_tpm2_rng_init (botan_rng_t *rng_out, botan_tpm2_ctx_t ctx, botan_tpm2_session_t s1, botan_tpm2_session_t s2, botan_tpm2_session_t s3)
 
int botan_tpm2_session_destroy (botan_tpm2_session_t session)
 
int botan_tpm2_supports_crypto_backend ()
 
int botan_tpm2_unauthenticated_session_init (botan_tpm2_session_t *session_out, botan_tpm2_ctx_t ctx)
 
uint32_t botan_version_datestamp (void)
 
uint32_t botan_version_major (void)
 
uint32_t botan_version_minor (void)
 
uint32_t botan_version_patch (void)
 
const char * botan_version_string (void)
 
int botan_x509_cert_allowed_usage (botan_x509_cert_t cert, unsigned int key_usage)
 
int botan_x509_cert_destroy (botan_x509_cert_t cert)
 
int botan_x509_cert_dup (botan_x509_cert_t *new_cert, botan_x509_cert_t cert)
 
int botan_x509_cert_get_authority_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_fingerprint (botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
 
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)
 
int botan_x509_cert_get_public_key (botan_x509_cert_t cert, botan_pubkey_t *key)
 
int botan_x509_cert_get_public_key_bits (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_serial_number (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
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)
 
int botan_x509_cert_get_subject_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_time_expires (botan_x509_cert_t cert, char out[], size_t *out_len)
 
int botan_x509_cert_get_time_starts (botan_x509_cert_t cert, char out[], size_t *out_len)
 
int botan_x509_cert_hostname_match (botan_x509_cert_t cert, const char *hostname)
 
int botan_x509_cert_load (botan_x509_cert_t *cert_obj, const uint8_t cert[], size_t cert_len)
 
int botan_x509_cert_load_file (botan_x509_cert_t *cert_obj, const char *filename)
 
int botan_x509_cert_not_after (botan_x509_cert_t cert, uint64_t *time_since_epoch)
 
int botan_x509_cert_not_before (botan_x509_cert_t cert, uint64_t *time_since_epoch)
 
int botan_x509_cert_to_string (botan_x509_cert_t cert, char out[], size_t *out_len)
 
const char * botan_x509_cert_validation_status (int code)
 
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)
 
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)
 
int botan_x509_cert_view_as_string (botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_str_fn view)
 
int botan_x509_cert_view_public_key_bits (botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_x509_crl_destroy (botan_x509_crl_t crl)
 
int botan_x509_crl_load (botan_x509_crl_t *crl_obj, const uint8_t crl_bits[], size_t crl_bits_len)
 
int botan_x509_crl_load_file (botan_x509_crl_t *crl_obj, const char *crl_path)
 
int botan_x509_is_revoked (botan_x509_crl_t crl, botan_x509_cert_t cert)
 
int botan_zfec_decode (size_t K, size_t N, const size_t *indexes, uint8_t *const *inputs, size_t shareSize, uint8_t **outputs)
 
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 1112 of file ffi.h.

Referenced by botan_privkey_check_key(), and botan_pubkey_check_key().

◆ BOTAN_CIPHER_INIT_FLAG_DECRYPT

#define BOTAN_CIPHER_INIT_FLAG_DECRYPT   1

Definition at line 542 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_ENCRYPT

#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0

Definition at line 541 of file ffi.h.

Referenced by botan_cipher_init().

◆ BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION

#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION   1

Definition at line 540 of file ffi.h.

Referenced by botan_cipher_init().

◆ BOTAN_CIPHER_UPDATE_FLAG_FINAL

#define BOTAN_CIPHER_UPDATE_FLAG_FINAL   (1U << 0)

Definition at line 635 of file ffi.h.

Referenced by botan_cipher_update().

◆ BOTAN_FFI_API_VERSION

#define BOTAN_FFI_API_VERSION   20240408

The compile time API version. This matches the value of botan_ffi_api_version. This can be used for compile-time checking if a particular feature is available.

Note this same value is also reflected in BOTAN_HAS_FFI in build.h, however that declaration is not visible here since this header is intentionally free-standing, depending only on a few C standard library headers.

Definition at line 71 of file ffi.h.

◆ BOTAN_FFI_DEPRECATED

#define BOTAN_FFI_DEPRECATED ( msg)

Definition at line 104 of file ffi.h.

◆ BOTAN_FFI_EXPORT

#define BOTAN_FFI_EXPORT ( maj,
min )

BOTAN_FFI_EXPORT indicates public FFI functions.

The arguments to the macro are to indicate the version that that particular FFI function was first available

Definition at line 89 of file ffi.h.

◆ BOTAN_FFI_HEX_LOWER_CASE

#define BOTAN_FFI_HEX_LOWER_CASE   1

Definition at line 237 of file ffi.h.

Referenced by botan_hex_encode().

◆ BOTAN_FPE_FLAG_FE1_COMPAT_MODE

#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE   1

Definition at line 2100 of file ffi.h.

Referenced by botan_fpe_fe1_init().

◆ BOTAN_PRIVKEY_EXPORT_FLAG_DER

◆ BOTAN_PRIVKEY_EXPORT_FLAG_PEM

◆ BOTAN_PRIVKEY_EXPORT_FLAG_RAW

#define BOTAN_PRIVKEY_EXPORT_FLAG_RAW   2

Definition at line 1184 of file ffi.h.

Referenced by botan_privkey_export(), and botan_pubkey_export().

◆ BOTAN_PUBKEY_DER_FORMAT_SIGNATURE

#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE   1

Typedef Documentation

◆ botan_block_cipher_t

typedef struct botan_block_cipher_struct* botan_block_cipher_t

Definition at line 836 of file ffi.h.

◆ botan_cipher_t

typedef struct botan_cipher_struct* botan_cipher_t

Definition at line 538 of file ffi.h.

◆ botan_fpe_t

typedef struct botan_fpe_struct* botan_fpe_t

Format Preserving Encryption

Definition at line 2098 of file ffi.h.

◆ botan_hash_t

typedef struct botan_hash_struct* botan_hash_t

Definition at line 362 of file ffi.h.

◆ botan_hotp_t

typedef struct botan_hotp_struct* botan_hotp_t

HOTP

Definition at line 2026 of file ffi.h.

◆ botan_mac_t

typedef struct botan_mac_struct* botan_mac_t

Definition at line 442 of file ffi.h.

◆ botan_mp_t

typedef struct botan_mp_struct* botan_mp_t

Definition at line 902 of file ffi.h.

◆ botan_pk_op_decrypt_t

typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t

Definition at line 1666 of file ffi.h.

◆ botan_pk_op_encrypt_t

typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t

Definition at line 1642 of file ffi.h.

◆ botan_pk_op_ka_t

typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t

Definition at line 1728 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 1787 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 1757 of file ffi.h.

◆ botan_pk_op_sign_t

typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t

Definition at line 1689 of file ffi.h.

◆ botan_pk_op_verify_t

typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t

Definition at line 1709 of file ffi.h.

◆ botan_privkey_t

typedef struct botan_privkey_struct* botan_privkey_t

Definition at line 1099 of file ffi.h.

◆ botan_pubkey_t

typedef struct botan_pubkey_struct* botan_pubkey_t

Definition at line 1319 of file ffi.h.

◆ botan_rng_t

typedef struct botan_rng_struct* botan_rng_t

RNG type

Definition at line 272 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 2121 of file ffi.h.

◆ botan_totp_t

typedef struct botan_totp_struct* botan_totp_t

TOTP

Definition at line 2058 of file ffi.h.

◆ botan_tpm2_crypto_backend_state_t

typedef struct botan_tpm2_crypto_backend_state_struct* botan_tpm2_crypto_backend_state_t

TPM2 crypto backend state object

Definition at line 2289 of file ffi.h.

◆ botan_tpm2_ctx_t

typedef struct botan_tpm2_ctx_struct* botan_tpm2_ctx_t

TPM2 context

Definition at line 2279 of file ffi.h.

◆ botan_tpm2_session_t

typedef struct botan_tpm2_session_struct* botan_tpm2_session_t

TPM2 session

Definition at line 2284 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 155 of file ffi.h.

◆ botan_view_ctx

typedef void* botan_view_ctx

Definition at line 146 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 164 of file ffi.h.

◆ botan_x509_cert_t

typedef struct botan_x509_cert_struct* botan_x509_cert_t

Definition at line 1851 of file ffi.h.

◆ botan_x509_crl_t

typedef struct botan_x509_crl_struct* botan_x509_crl_t

Definition at line 1949 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_TPM_ERROR 
BOTAN_FFI_ERROR_UNKNOWN_ERROR 

Definition at line 113 of file ffi.h.

113 {
116
119
122
127
134
137
142
144};
@ BOTAN_FFI_ERROR_TPM_ERROR
Definition ffi.h:141
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:135
@ BOTAN_FFI_ERROR_INVALID_KEY_LENGTH
Definition ffi.h:132
@ BOTAN_FFI_ERROR_KEY_NOT_SET
Definition ffi.h:131
@ BOTAN_FFI_ERROR_TLS_ERROR
Definition ffi.h:138
@ BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition ffi.h:123
@ BOTAN_FFI_ERROR_OUT_OF_MEMORY
Definition ffi.h:124
@ BOTAN_FFI_ERROR_INTERNAL_ERROR
Definition ffi.h:126
@ BOTAN_FFI_INVALID_VERIFIER
Definition ffi.h:115
@ BOTAN_FFI_ERROR_INVALID_OBJECT
Definition ffi.h:136
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:143
@ BOTAN_FFI_ERROR_HTTP_ERROR
Definition ffi.h:139
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:128
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition ffi.h:117
@ BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR
Definition ffi.h:121
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:129
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114
@ BOTAN_FFI_ERROR_SYSTEM_ERROR
Definition ffi.h:125
@ BOTAN_FFI_ERROR_ROUGHTIME_ERROR
Definition ffi.h:140
@ BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
Definition ffi.h:133
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition ffi.h:120
@ BOTAN_FFI_ERROR_BAD_MAC
Definition ffi.h:118
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:130

◆ 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 1898 of file ffi.h.

1898 {
1899 NO_CONSTRAINTS = 0,
1900 DIGITAL_SIGNATURE = 32768,
1901 NON_REPUDIATION = 16384,
1902 KEY_ENCIPHERMENT = 8192,
1903 DATA_ENCIPHERMENT = 4096,
1904 KEY_AGREEMENT = 2048,
1905 KEY_CERT_SIGN = 1024,
1906 CRL_SIGN = 512,
1907 ENCIPHER_ONLY = 256,
1908 DECIPHER_ONLY = 128
1909};
@ KEY_ENCIPHERMENT
Definition ffi.h:1902
@ NO_CONSTRAINTS
Definition ffi.h:1899
@ CRL_SIGN
Definition ffi.h:1906
@ DIGITAL_SIGNATURE
Definition ffi.h:1900
@ KEY_AGREEMENT
Definition ffi.h:1904
@ DATA_ENCIPHERMENT
Definition ffi.h:1903
@ KEY_CERT_SIGN
Definition ffi.h:1905
@ ENCIPHER_ONLY
Definition ffi.h:1907
@ NON_REPUDIATION
Definition ffi.h:1901
@ DECIPHER_ONLY
Definition ffi.h:1908

Function Documentation

◆ botan_base64_decode()

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 345 of file ffi.cpp.

345 {
346 return ffi_guard_thunk(__func__, [=]() -> int {
347 if(*out_len < Botan::base64_decode_max_output(in_len)) {
348 *out_len = Botan::base64_decode_max_output(in_len);
350 }
351
352 *out_len = Botan::base64_decode(out, std::string(base64_str, in_len));
353 return BOTAN_FFI_SUCCESS;
354 });
355}
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition ffi.cpp:128
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:168
size_t base64_decode_max_output(size_t input_length)
Definition base64.cpp:200

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

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

Perform base64 encoding

Definition at line 338 of file ffi.cpp.

338 {
339 return ffi_guard_thunk(__func__, [=]() -> int {
340 const std::string base64 = Botan::base64_encode(in, len);
341 return Botan_FFI::write_str_output(out, out_len, base64);
342 });
343}
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:160

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

◆ botan_bcrypt_generate()

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

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

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
const SIMD_8x32 & b

References BOTAN_FFI_VISIT.

◆ botan_block_cipher_clear()

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

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

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

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

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 }
95 if(out_maximum_keylength) {
96 *out_maximum_keylength = bc.maximum_keylength();
97 }
98 if(out_keylength_modulo) {
99 *out_keylength_modulo = bc.key_spec().keylength_multiple();
100 }
101 });
102}

References BOTAN_FFI_VISIT.

◆ botan_block_cipher_init()

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

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

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

int botan_cipher_clear ( botan_cipher_t hash)

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

Definition at line 118 of file ffi_cipher.cpp.

118 {
119 return BOTAN_FFI_VISIT(cipher, [](auto& c) { c.clear(); });
120}

References BOTAN_FFI_VISIT.

◆ botan_cipher_destroy()

int botan_cipher_destroy ( botan_cipher_t cipher)

Destroy the cipher object

Returns
0 if success, error if invalid object handle

Definition at line 114 of file ffi_cipher.cpp.

114 {
115 return BOTAN_FFI_CHECKED_DELETE(cipher);
116}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_cipher_get_default_nonce_length()

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 302 of file ffi_cipher.cpp.

302 {
303 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *nl = c.default_nonce_length(); });
304}

References BOTAN_FFI_VISIT.

◆ botan_cipher_get_ideal_update_granularity()

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 310 of file ffi_cipher.cpp.

310 {
311 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *ug = c.ideal_granularity(); });
312}

References BOTAN_FFI_VISIT.

◆ botan_cipher_get_keyspec()

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 141 of file ffi_cipher.cpp.

144 {
145 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) {
146 if(out_minimum_keylength) {
147 *out_minimum_keylength = c.key_spec().minimum_keylength();
148 }
149 if(out_maximum_keylength) {
150 *out_maximum_keylength = c.key_spec().maximum_keylength();
151 }
152 if(out_keylength_modulo) {
153 *out_keylength_modulo = c.key_spec().keylength_multiple();
154 }
155 });
156}

References BOTAN_FFI_VISIT.

◆ botan_cipher_get_tag_length()

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 314 of file ffi_cipher.cpp.

314 {
315 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *tl = c.tag_size(); });
316}

References BOTAN_FFI_VISIT.

◆ botan_cipher_get_update_granularity()

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 306 of file ffi_cipher.cpp.

306 {
307 return BOTAN_FFI_VISIT(cipher, [=](const auto& /*c*/) { *ug = cipher->update_size(); });
308}

References BOTAN_FFI_VISIT.

◆ botan_cipher_init()

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

Initialize a cipher object

Definition at line 96 of file ffi_cipher.cpp.

96 {
97 return ffi_guard_thunk(__func__, [=]() -> int {
100
101 std::unique_ptr<Botan::Cipher_Mode> mode(Botan::Cipher_Mode::create(cipher_name, dir));
102 if(!mode) {
104 }
105
106 const size_t update_size = ffi_choose_update_size(*mode);
107 const size_t ideal_update_size = std::max(mode->ideal_granularity(), update_size);
108
109 *cipher = new botan_cipher_struct(std::move(mode), update_size, ideal_update_size);
110 return BOTAN_FFI_SUCCESS;
111 });
112}
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:541
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
Definition ffi.h:540
Flags flags(Flag flags)
Definition p11.h:838

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

int botan_cipher_is_authenticated ( botan_cipher_t cipher)

Returns 1 iff the cipher provides authentication as well as confidentiality.

Definition at line 318 of file ffi_cipher.cpp.

318 {
319 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.authenticated() ? 1 : 0; });
320}

References BOTAN_FFI_VISIT.

◆ botan_cipher_name()

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

Return the name of the cipher object

Definition at line 326 of file ffi_cipher.cpp.

326 {
327 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return write_str_output(name, name_len, c.name()); });
328}

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

◆ botan_cipher_output_length()

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 126 of file ffi_cipher.cpp.

126 {
127 if(out_len == nullptr) {
129 }
130
131 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *out_len = c.output_length(in_len); });
132}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_cipher_query_keylen()

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 134 of file ffi_cipher.cpp.

134 {
135 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) {
136 *out_minimum_keylength = c.key_spec().minimum_keylength();
137 *out_maximum_keylength = c.key_spec().maximum_keylength();
138 });
139}

References BOTAN_FFI_VISIT.

◆ botan_cipher_requires_entire_message()

int botan_cipher_requires_entire_message ( botan_cipher_t cipher)

Returns 1 iff the cipher requires the entire message before any encryption or decryption can be performed. No output data will be produced in botan_cipher_update() until the final flag is set.

Definition at line 322 of file ffi_cipher.cpp.

322 {
323 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.requires_entire_message() ? 1 : 0; });
324}

References BOTAN_FFI_VISIT.

◆ botan_cipher_reset()

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 122 of file ffi_cipher.cpp.

122 {
123 return BOTAN_FFI_VISIT(cipher, [](auto& c) { c.reset(); });
124}

References BOTAN_FFI_VISIT.

◆ botan_cipher_set_associated_data()

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

288 {
289 return BOTAN_FFI_VISIT(cipher, [=](auto& c) {
290 if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(&c)) {
291 aead->set_associated_data(ad, ad_len);
292 return BOTAN_FFI_SUCCESS;
293 }
295 });
296}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_cipher_set_key()

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 158 of file ffi_cipher.cpp.

158 {
159 return BOTAN_FFI_VISIT(cipher, [=](auto& c) { c.set_key(key, key_len); });
160}

References BOTAN_FFI_VISIT.

◆ botan_cipher_start()

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 162 of file ffi_cipher.cpp.

162 {
163 return ffi_guard_thunk(__func__, [=]() -> int {
164 Botan::Cipher_Mode& cipher = safe_get(cipher_obj);
165 cipher.start(nonce, nonce_len);
166 return BOTAN_FFI_SUCCESS;
167 });
168}
void start(std::span< const uint8_t > nonce)
Definition cipher_mode.h:97

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

◆ botan_cipher_update()

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/Decrypt some data and/or finalize the encryption/decryption.

This encrypts as many bytes from input_bytes into output_bytes as possible. Unless BOTAN_CIPHER_UPDATE_FLAG_FINAL is set, this function will consume bytes in multiples of botan_cipher_get_update_granularity(). input_consumed and output_written will be set accordingly and it is the caller's responsibility to adapt their buffers accordingly before calling this function again. Note that, unless BOTAN_CIPHER_UPDATE_FLAG_FINAL is set, the cipher will at most generate input_size output bytes.

Eventually, the caller must set the BOTAN_CIPHER_UPDATE_FLAG_FINAL flag to indicate that no more input will be provided. This will cause the cipher to consume all given input bytes and produce the final output; or return a BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE error if the given output buffer was too small. In the latter case, output_written will be set to the required buffer size. Calling again with BOTAN_CIPHER_UPDATE_FLAG_FINAL, a big enough buffer and no further input will then produce the final output.

Note that some ciphers require the entire message to be provided before any output is produced.

See also
botan_cipher_requires_entire_message().

Definition at line 170 of file ffi_cipher.cpp.

177 {
178 return ffi_guard_thunk(__func__, [=]() -> int {
179 using namespace Botan;
180 Cipher_Mode& cipher = safe_get(cipher_obj);
181 secure_vector<uint8_t>& mbuf = cipher_obj->buf();
182
183 // If the cipher object's internal buffer contains residual data from
184 // a previous invocation, we can be sure that botan_cipher_update() was
185 // called with the final flag set but not enough buffer space was provided
186 // to accommodate the final output.
187 const bool was_finished_before = !mbuf.empty();
188 const bool final_input = (flags & BOTAN_CIPHER_UPDATE_FLAG_FINAL);
189
190 // Bring the output variables into a defined state.
191 *output_written = 0;
192 *input_consumed = 0;
193
194 // Once the final flag was set once, it must always be set for
195 // consecutive invocations.
196 if(was_finished_before && !final_input) {
198 }
199
200 // If the final flag was set in a previous invocation, no more input
201 // data can be processed.
202 if(was_finished_before && input_size > 0) {
204 }
205
206 // Make sure that we always clear the internal buffer before returning
207 // or aborting this invocation due to an exception.
208 auto clean_buffer = scoped_cleanup([&mbuf] { mbuf.clear(); });
209
210 if(final_input) {
211 // If the final flag is set for the first time, we need to process the
212 // remaining input data and then finalize the cipher object.
213 if(!was_finished_before) {
214 *input_consumed = input_size;
215 mbuf.resize(input_size);
216 copy_mem(mbuf, std::span(input, input_size));
217
218 try {
219 cipher.finish(mbuf);
222 }
223 }
224
225 // At this point, the cipher object is finalized (potentially in a
226 // previous invocation) and we can copy the final output to the caller.
227 *output_written = mbuf.size();
228
229 // Not enough space to copy the final output out to the caller.
230 // Inform them how much space we need for a successful operation.
231 if(output_size < mbuf.size()) {
232 // This is the only place where mbuf is not cleared before returning.
233 clean_buffer.disengage();
235 }
236
237 // Copy the final output to the caller, mbuf is cleared afterwards.
238 copy_mem(std::span(output, mbuf.size()), mbuf);
239 } else {
240 // Process data in a streamed fashion without finalizing. No data is
241 // ever retained in the cipher object's internal buffer. If we run out
242 // of either input data or output capacity, we stop and report that not
243 // all bytes were processed via *output_written and *input_consumed.
244
245 BufferSlicer in({input, input_size});
246 BufferStuffer out({output, output_size});
247
248 // Helper function to do blockwise processing of data.
249 auto blockwise_update = [&](const size_t granularity) {
250 if(granularity == 0) {
251 return;
252 }
253
254 const size_t expected_output_per_iteration = cipher.requires_entire_message() ? 0 : granularity;
255 mbuf.resize(granularity);
256
257 while(in.remaining() >= granularity && out.remaining_capacity() >= expected_output_per_iteration) {
258 copy_mem(mbuf, in.take(granularity));
259 const auto written_bytes = cipher.process(mbuf);
260 BOTAN_DEBUG_ASSERT(written_bytes == expected_output_per_iteration);
261 if(written_bytes > 0) {
262 BOTAN_ASSERT_NOMSG(written_bytes <= granularity);
263 copy_mem(out.next(written_bytes), std::span(mbuf).first(written_bytes));
264 }
265 }
266 };
267
268 // First, process as much data as possible in chunks of ideal granularity
269 blockwise_update(cipher_obj->ideal_update_size());
270
271 // Then process the remaining bytes in chunks of update_size() or, in one go
272 // if update_size() is equal to 1 --> i.e. likely a stream cipher.
273 const bool is_stream_cipher = (cipher_obj->update_size() == 1);
274 const size_t tail_granularity =
275 is_stream_cipher ? std::min(in.remaining(), out.remaining_capacity()) : cipher_obj->update_size();
276 BOTAN_DEBUG_ASSERT(tail_granularity < cipher_obj->ideal_update_size());
277 blockwise_update(tail_granularity);
278
279 // Inform the caller about the amount of data processed.
280 *output_written = output_size - out.remaining_capacity();
281 *input_consumed = input_size - in.remaining();
282 }
283
284 return BOTAN_FFI_SUCCESS;
285 });
286}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:98
Helper class to ease in-place marshalling of concatenated fixed-length values.
Definition stl_util.h:142
void finish(secure_vector< uint8_t > &final_block, size_t offset=0)
virtual bool requires_entire_message() const
size_t process(std::span< uint8_t > msg)
Helper class to create a RAII-style cleanup callback.
Definition stl_util.h:354
#define BOTAN_CIPHER_UPDATE_FLAG_FINAL
Definition ffi.h:635
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:147

References BOTAN_ASSERT_NOMSG, BOTAN_CIPHER_UPDATE_FLAG_FINAL, BOTAN_DEBUG_ASSERT, BOTAN_FFI_ERROR_BAD_MAC, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan::Cipher_Mode::finish(), Botan::Cipher_Mode::process(), Botan::Cipher_Mode::requires_entire_message(), and Botan_FFI::safe_get().

◆ botan_cipher_valid_nonce_length()

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 298 of file ffi_cipher.cpp.

298 {
299 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.valid_nonce_length(nl) ? 1 : 0; });
300}

References BOTAN_FFI_VISIT.

◆ botan_constant_time_compare()

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 308 of file ffi.cpp.

308 {
309 auto same = Botan::CT::is_equal(x, y, len);
310 // Return 0 if same or -1 otherwise
311 return static_cast<int>(same.select(1, 0)) - 1;
312}
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:788

References Botan::CT::is_equal().

Referenced by botan_same_mem().

◆ botan_error_description()

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 156 of file ffi.cpp.

156 {
157 switch(err) {
159 return "OK";
160
162 return "Invalid verifier";
163
165 return "Invalid input";
166
168 return "Invalid authentication code";
169
171 return "Insufficient buffer space";
172
174 return "String conversion error";
175
177 return "Exception thrown";
178
180 return "Out of memory";
181
183 return "Error while calling system API";
184
186 return "Internal error";
187
189 return "Bad flag";
190
192 return "Null pointer argument";
193
195 return "Bad parameter";
196
198 return "Key not set on object";
199
201 return "Invalid key length";
202
204 return "Invalid object state";
205
207 return "Not implemented";
208
210 return "Invalid object handle";
211
213 return "TLS error";
214
216 return "HTTP error";
217
219 return "Unknown error";
220
221 default:
222 return "Unknown error";
223 }
224}

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

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 152 of file ffi.cpp.

152 {
153 return g_last_exception_what.c_str();
154}

◆ botan_ffi_api_version()

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 229 of file ffi.cpp.

229 {
230 return BOTAN_HAS_FFI;
231}
#define BOTAN_HAS_FFI
Definition build.h:253

References BOTAN_HAS_FFI.

◆ botan_ffi_supports_api()

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 233 of file ffi.cpp.

233 {
234 // This is the API introduced in 3.4
235 if(api_version == 20240408) {
236 return BOTAN_FFI_SUCCESS;
237 }
238
239 // This is the API introduced in 3.2
240 if(api_version == 20231009) {
241 return BOTAN_FFI_SUCCESS;
242 }
243
244 // This is the API introduced in 3.1
245 if(api_version == 20230711) {
246 return BOTAN_FFI_SUCCESS;
247 }
248
249 // This is the API introduced in 3.0
250 if(api_version == 20230403) {
251 return BOTAN_FFI_SUCCESS;
252 }
253
254 // This is the API introduced in 2.18
255 if(api_version == 20210220) {
256 return BOTAN_FFI_SUCCESS;
257 }
258
259 // This is the API introduced in 2.13
260 if(api_version == 20191214) {
261 return BOTAN_FFI_SUCCESS;
262 }
263
264 // This is the API introduced in 2.8
265 if(api_version == 20180713) {
266 return BOTAN_FFI_SUCCESS;
267 }
268
269 // This is the API introduced in 2.3
270 if(api_version == 20170815) {
271 return BOTAN_FFI_SUCCESS;
272 }
273
274 // This is the API introduced in 2.1
275 if(api_version == 20170327) {
276 return BOTAN_FFI_SUCCESS;
277 }
278
279 // This is the API introduced in 2.0
280 if(api_version == 20150515) {
281 return BOTAN_FFI_SUCCESS;
282 }
283
284 // Something else:
285 return -1;
286}

References BOTAN_FFI_SUCCESS.

◆ botan_fpe_decrypt()

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

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

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

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:2100

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

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

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

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

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

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

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:107

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

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

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

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

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 331 of file ffi.cpp.

331 {
332 return ffi_guard_thunk(__func__, [=]() -> int {
333 const std::vector<uint8_t> bin = Botan::hex_decode(hex_str, in_len);
334 return Botan_FFI::write_vec_output(out, out_len, bin);
335 });
336}
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:73

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

◆ botan_hex_encode()

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 323 of file ffi.cpp.

323 {
324 return ffi_guard_thunk(__func__, [=]() -> int {
325 const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
326 Botan::hex_encode(out, in, len, uppercase);
327 return BOTAN_FFI_SUCCESS;
328 });
329}
#define BOTAN_FFI_HEX_LOWER_CASE
Definition ffi.h:237
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition hex.cpp:35

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

◆ botan_hotp_check()

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
78 return (resp.first == true) ? BOTAN_FFI_SUCCESS : BOTAN_FFI_INVALID_VERIFIER;
79 });
80
81#else
82 BOTAN_UNUSED(hotp, next_hotp_counter, hotp_code, hotp_counter, resync_range);
84#endif
85}

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

◆ botan_hotp_destroy()

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

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

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

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:202

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

◆ botan_key_unwrap3394()

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

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

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

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

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

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 }
75 if(out_maximum_keylength) {
76 *out_maximum_keylength = m.maximum_keylength();
77 }
78 if(out_keylength_modulo) {
79 *out_keylength_modulo = m.key_spec().keylength_multiple();
80 }
81 });
82}

References BOTAN_FFI_VISIT.

◆ botan_mac_init()

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:51

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

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

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

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

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

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

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

1334 {
1335 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
1337}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_mceies_encrypt()

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

1347 {
1348 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1350}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_mp_add()

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

Definition at line 119 of file ffi_mp.cpp.

119 {
120 return BOTAN_FFI_VISIT(result, [=](auto& res) {
121 if(result == x) {
122 res += safe_get(y);
123 } else {
124 res = safe_get(x) + safe_get(y);
125 }
126 });
127}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_add_u32()

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

Definition at line 139 of file ffi_mp.cpp.

139 {
140 return BOTAN_FFI_VISIT(result, [=](auto& res) {
141 if(result == x) {
142 res += static_cast<Botan::word>(y);
143 } else {
144 res = safe_get(x) + static_cast<Botan::word>(y);
145 }
146 });
147}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_clear()

int botan_mp_clear ( botan_mp_t mp)

Set the MPI to zero

Definition at line 34 of file ffi_mp.cpp.

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

References BOTAN_FFI_VISIT.

◆ botan_mp_clear_bit()

int botan_mp_clear_bit ( botan_mp_t n,
size_t bit )

Clear the specified bit

Definition at line 253 of file ffi_mp.cpp.

253 {
254 return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.clear_bit(bit); });
255}

References BOTAN_FFI_VISIT.

◆ botan_mp_cmp()

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

Definition at line 193 of file ffi_mp.cpp.

193 {
194 return BOTAN_FFI_VISIT(x_w, [=](auto& x) { *result = x.cmp(safe_get(y_w)); });
195}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_destroy()

int botan_mp_destroy ( botan_mp_t mp)

Destroy (deallocate) an MPI

Returns
0 if success, error if invalid object handle

Definition at line 115 of file ffi_mp.cpp.

115 {
116 return BOTAN_FFI_CHECKED_DELETE(mp);
117}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_mp_div()

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

Definition at line 169 of file ffi_mp.cpp.

169 {
170 return BOTAN_FFI_VISIT(quotient, [=](auto& q) {
173 safe_get(remainder) = r;
174 });
175}
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition divide.cpp:219

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

◆ botan_mp_equal()

int botan_mp_equal ( botan_mp_t x,
botan_mp_t y )

Definition at line 177 of file ffi_mp.cpp.

177 {
178 return BOTAN_FFI_VISIT(x_w, [=](const auto& x) -> int { return x == safe_get(y_w); });
179}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_flip_sign()

int botan_mp_flip_sign ( botan_mp_t mp)

Definition at line 77 of file ffi_mp.cpp.

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

References BOTAN_FFI_VISIT.

◆ botan_mp_from_bin()

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

Definition at line 81 of file ffi_mp.cpp.

81 {
82 return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn._assign_from_bytes({bin, bin_len}); });
83}

References BOTAN_FFI_VISIT.

◆ botan_mp_gcd()

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

Definition at line 237 of file ffi_mp.cpp.

237 {
238 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = Botan::gcd(safe_get(x), safe_get(y)); });
239}
BigInt gcd(const BigInt &a, const BigInt &b)
Definition numthry.cpp:193

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

◆ botan_mp_get_bit()

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 245 of file ffi_mp.cpp.

245 {
246 return BOTAN_FFI_VISIT(mp, [=](const auto& n) -> int { return n.get_bit(bit); });
247}

References BOTAN_FFI_VISIT.

◆ botan_mp_init()

int botan_mp_init ( botan_mp_t * mp)

Initialize an MPI

Definition at line 22 of file ffi_mp.cpp.

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

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

◆ botan_mp_is_even()

int botan_mp_is_even ( botan_mp_t mp)

Definition at line 189 of file ffi_mp.cpp.

189 {
190 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_even(); });
191}

References BOTAN_FFI_VISIT.

◆ botan_mp_is_negative()

int botan_mp_is_negative ( botan_mp_t mp)

Return 1 iff mp is less than 0

Definition at line 69 of file ffi_mp.cpp.

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

References BOTAN_FFI_VISIT.

◆ botan_mp_is_odd()

int botan_mp_is_odd ( botan_mp_t mp)

Definition at line 185 of file ffi_mp.cpp.

185 {
186 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_odd(); });
187}

References BOTAN_FFI_VISIT.

◆ botan_mp_is_positive()

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 73 of file ffi_mp.cpp.

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

References BOTAN_FFI_VISIT.

◆ botan_mp_is_prime()

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

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

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

◆ botan_mp_is_zero()

int botan_mp_is_zero ( 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_zero(); });
183}

References BOTAN_FFI_VISIT.

◆ botan_mp_lshift()

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

Definition at line 207 of file ffi_mp.cpp.

207 {
208 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) << shift; });
209}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_mod_inverse()

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

Definition at line 215 of file ffi_mp.cpp.

215 {
216 return BOTAN_FFI_VISIT(out, [=](auto& o) {
218 });
219}
static BigInt zero()
Definition bigint.h:50
std::optional< BigInt > inverse_mod_general(const BigInt &x, const BigInt &mod)
Definition mod_inv.cpp:177

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

◆ botan_mp_mod_mul()

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

Definition at line 221 of file ffi_mp.cpp.

221 {
222 return BOTAN_FFI_VISIT(out, [=](auto& o) {
224 o = reducer.multiply(safe_get(x), safe_get(y));
225 });
226}
static Modular_Reducer for_secret_modulus(const BigInt &m)
Definition reducer.cpp:32

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

◆ botan_mp_mul()

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

Definition at line 159 of file ffi_mp.cpp.

159 {
160 return BOTAN_FFI_VISIT(result, [=](auto& res) {
161 if(result == x) {
162 res *= safe_get(y);
163 } else {
164 res = safe_get(x) * safe_get(y);
165 }
166 });
167}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_num_bits()

int botan_mp_num_bits ( botan_mp_t n,
size_t * bits )

Return the number of significant bits in the MPI

Definition at line 257 of file ffi_mp.cpp.

257 {
258 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bits = n.bits(); });
259}

References BOTAN_FFI_VISIT.

◆ botan_mp_num_bytes()

int botan_mp_num_bytes ( botan_mp_t n,
size_t * bytes )

Return the number of significant bytes in the MPI

Definition at line 261 of file ffi_mp.cpp.

261 {
262 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bytes = n.bytes(); });
263}

References BOTAN_FFI_VISIT.

◆ botan_mp_powmod()

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

Definition at line 202 of file ffi_mp.cpp.

202 {
203 return BOTAN_FFI_VISIT(
204 out, [=](auto& o) { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
205}
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition numthry.cpp:284

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

◆ botan_mp_rand_bits()

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

Definition at line 228 of file ffi_mp.cpp.

228 {
229 return BOTAN_FFI_VISIT(rng, [=](auto& r) { safe_get(rand_out).randomize(r, bits); });
230}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_rand_range()

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 232 of file ffi_mp.cpp.

232 {
233 return BOTAN_FFI_VISIT(
234 rng, [=](auto& r) { safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
235}
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()

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

Definition at line 211 of file ffi_mp.cpp.

211 {
212 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) >> shift; });
213}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_set_bit()

int botan_mp_set_bit ( botan_mp_t n,
size_t bit )

Set the specified bit

Definition at line 249 of file ffi_mp.cpp.

249 {
250 return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.set_bit(bit); });
251}

References BOTAN_FFI_VISIT.

◆ botan_mp_set_from_int()

int botan_mp_set_from_int ( botan_mp_t mp,
int initial_value )

Set the MPI value from an int

Definition at line 38 of file ffi_mp.cpp.

38 {
39 return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn = Botan::BigInt::from_s32(initial_value); });
40}
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()

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 65 of file ffi_mp.cpp.

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

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_set_from_radix_str()

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 46 of file ffi_mp.cpp.

46 {
47 return BOTAN_FFI_VISIT(mp, [=](auto& bn) {
49 if(radix == 10) {
51 } else if(radix == 16) {
53 } else {
55 }
56
57 const uint8_t* bytes = Botan::cast_char_ptr_to_uint8(str);
58 const size_t len = strlen(str);
59
60 bn = Botan::BigInt(bytes, len, base);
61 return BOTAN_FFI_SUCCESS;
62 });
63}
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition mem_ops.h:274

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

int botan_mp_set_from_str ( botan_mp_t dest,
const char * str )

Set the MPI value from a string

Definition at line 42 of file ffi_mp.cpp.

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

References BOTAN_FFI_VISIT.

◆ botan_mp_sub()

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

Definition at line 129 of file ffi_mp.cpp.

129 {
130 return BOTAN_FFI_VISIT(result, [=](auto& res) {
131 if(result == x) {
132 res -= safe_get(y);
133 } else {
134 res = safe_get(x) - safe_get(y);
135 }
136 });
137}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_sub_u32()

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

Definition at line 149 of file ffi_mp.cpp.

149 {
150 return BOTAN_FFI_VISIT(result, [=](auto& res) {
151 if(result == x) {
152 res -= static_cast<Botan::word>(y);
153 } else {
154 res = safe_get(x) - static_cast<Botan::word>(y);
155 }
156 });
157}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_swap()

int botan_mp_swap ( botan_mp_t x,
botan_mp_t y )

Definition at line 197 of file ffi_mp.cpp.

197 {
198 return BOTAN_FFI_VISIT(x_w, [=](auto& x) { x.swap(safe_get(y_w)); });
199}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_to_bin()

int botan_mp_to_bin ( botan_mp_t mp,
uint8_t vec[] )

Definition at line 104 of file ffi_mp.cpp.

104 {
105 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { bn.serialize_to(std::span{vec, bn.bytes()}); });
106}

References BOTAN_FFI_VISIT.

◆ botan_mp_to_hex()

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 85 of file ffi_mp.cpp.

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

References BOTAN_FFI_VISIT.

◆ botan_mp_to_str()

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 92 of file ffi_mp.cpp.

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

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

◆ botan_mp_to_uint32()

int botan_mp_to_uint32 ( botan_mp_t mp,
uint32_t * val )

Definition at line 108 of file ffi_mp.cpp.

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

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_nist_kw_dec()

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

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

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

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

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

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

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

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

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

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:1687

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

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

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

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

Definition at line 313 of file ffi_pk_op.cpp.

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

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

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 354 of file ffi_pk_op.cpp.

354 {
355 return BOTAN_FFI_CHECKED_DELETE(op);
356}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_kem_decrypt_shared_key()

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 338 of file ffi_pk_op.cpp.

345 {
346 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
347 const auto shared_key =
348 kem.decrypt(encapsulated_key, encapsulated_key_len, desired_shared_key_len, salt, salt_len);
349
350 return write_vec_output(shared_key_out, shared_key_len, shared_key);
351 });
352}

References BOTAN_FFI_VISIT, and Botan_FFI::write_vec_output().

◆ botan_pk_op_kem_decrypt_shared_key_length()

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 325 of file ffi_pk_op.cpp.

327 {
328 if(output_shared_key_length == nullptr) {
330 }
331
332 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
333 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
334 return BOTAN_FFI_SUCCESS;
335 });
336}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_kem_encrypt_create()

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

Definition at line 250 of file ffi_pk_op.cpp.

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

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

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 291 of file ffi_pk_op.cpp.

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

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

◆ botan_pk_op_kem_encrypt_destroy()

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 262 of file ffi_pk_op.cpp.

262 {
263 return BOTAN_FFI_CHECKED_DELETE(op);
264}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_kem_encrypt_encapsulated_key_length()

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 279 of file ffi_pk_op.cpp.

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

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_kem_encrypt_shared_key_length()

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 266 of file ffi_pk_op.cpp.

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

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_key_agreement()

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 237 of file ffi_pk_op.cpp.

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

References BOTAN_FFI_VISIT, and Botan_FFI::write_vec_output().

◆ botan_pk_op_key_agreement_create()

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 192 of file ffi_pk_op.cpp.

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

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

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 209 of file ffi_pk_op.cpp.

209 {
210 return BOTAN_FFI_CHECKED_DELETE(op);
211}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_key_agreement_export_public()

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

Definition at line 213 of file ffi_pk_op.cpp.

213 {
214 return copy_view_bin(out, out_len, botan_pk_op_key_agreement_view_public, key);
215}
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()

int botan_pk_op_key_agreement_size ( botan_pk_op_ka_t op,
size_t * out_len )

Definition at line 227 of file ffi_pk_op.cpp.

227 {
228 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
229 if(out_len == nullptr) {
231 }
232 *out_len = o.agreed_value_size();
233 return BOTAN_FFI_SUCCESS;
234 });
235}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_key_agreement_view_public()

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

Definition at line 217 of file ffi_pk_op.cpp.

217 {
218 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
219 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k)) {
220 return invoke_view_callback(view, ctx, kak->public_value());
221 } else {
223 }
224 });
225}
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()

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:31

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

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

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

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

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

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

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

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 });
190}

References BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_verify_update()

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

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 356 of file ffi_pkey.cpp.

356 {
357#if defined(BOTAN_HAS_HASH_ID)
358 return ffi_guard_thunk(__func__, [=]() -> int {
359 const std::vector<uint8_t> hash_id = Botan::pkcs_hash_id(hash_name);
360 return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
361 });
362#else
363 BOTAN_UNUSED(hash_name, pkcs_id, pkcs_id_len);
365#endif
366}
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()

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

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:1112

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

◆ botan_privkey_create()

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:487

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

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

Definition at line 506 of file ffi_pkey_algs.cpp.

506 {
507 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
508}
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()

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

309 {
310#if defined(BOTAN_HAS_DSA)
311
312 if((rng_obj == nullptr) || (key == nullptr)) {
314 }
315
316 if((pbits % 64) || (qbits % 8) || (pbits < 1024) || (pbits > 3072) || (qbits < 160) || (qbits > 256)) {
318 }
319
320 return ffi_guard_thunk(__func__, [=]() -> int {
322 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
323 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
324 *key = new botan_privkey_struct(std::move(dsa));
325 return BOTAN_FFI_SUCCESS;
326 });
327#else
328 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
330#endif
331}

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

◆ botan_privkey_create_ecdh()

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

Definition at line 542 of file ffi_pkey_algs.cpp.

542 {
543 if(param_str == nullptr) {
545 }
546
547 const std::string params(param_str);
548
549 if(params == "x25519" || params == "curve25519") {
550 return botan_privkey_create(key_obj, "X25519", "", rng_obj);
551 }
552
553 if(params == "x448") {
554 return botan_privkey_create(key_obj, "X448", "", rng_obj);
555 }
556
557 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
558}

References BOTAN_FFI_ERROR_NULL_POINTER, and botan_privkey_create().

◆ botan_privkey_create_ecdsa()

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

Definition at line 385 of file ffi_pkey_algs.cpp.

385 {
386 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
387}

References botan_privkey_create().

◆ botan_privkey_create_elgamal()

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

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

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

Definition at line 447 of file ffi_pkey_algs.cpp.

447 {
448#if defined(BOTAN_HAS_ELGAMAL)
449
450 if((rng_obj == nullptr) || (key == nullptr)) {
452 }
453
454 if((pbits < 1024) || (qbits < 160)) {
456 }
457
458 Botan::DL_Group::PrimeType prime_type =
459 ((pbits - 1) == qbits) ? Botan::DL_Group::Strong : Botan::DL_Group::Prime_Subgroup;
460
461 return ffi_guard_thunk(__func__, [=]() -> int {
463 Botan::DL_Group group(rng, prime_type, pbits, qbits);
464 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
465 *key = new botan_privkey_struct(std::move(elg));
466 return BOTAN_FFI_SUCCESS;
467 });
468#else
469 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
471#endif
472}

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

◆ botan_privkey_create_mceliece()

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

Definition at line 1322 of file ffi_pkey_algs.cpp.

1322 {
1323 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1324 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1325}

References botan_privkey_create().

◆ botan_privkey_create_rsa()

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

Definition at line 203 of file ffi_pkey_algs.cpp.

203 {
204 if(n_bits < 1024 || n_bits > 16 * 1024) {
206 }
207
208 std::string n_str = std::to_string(n_bits);
209
210 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
211}

References BOTAN_FFI_ERROR_BAD_PARAMETER, and botan_privkey_create().

◆ botan_privkey_destroy()

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

int botan_privkey_dsa_get_x ( botan_mp_t n,
botan_privkey_t key )

Definition at line 365 of file ffi_pkey_algs.cpp.

365 {
366 return botan_privkey_get_field(x, key, "x");
367}
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

References botan_privkey_get_field().

◆ botan_privkey_ed25519_get_privkey()

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

Definition at line 712 of file ffi_pkey_algs.cpp.

712 {
713#if defined(BOTAN_HAS_ED25519)
714 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
715 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
716 const auto ed_key = ed->raw_private_key_bits();
717 if(ed_key.size() != 64) {
719 }
720 Botan::copy_mem(output, ed_key.data(), ed_key.size());
721 return BOTAN_FFI_SUCCESS;
722 } else {
724 }
725 });
726#else
727 BOTAN_UNUSED(key, output);
729#endif
730}

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

int botan_privkey_ed448_get_privkey ( botan_privkey_t key,
uint8_t output[57] )

Definition at line 782 of file ffi_pkey_algs.cpp.

782 {
783#if defined(BOTAN_HAS_ED448)
784 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
785 if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
786 const auto ed_key = ed->raw_private_key_bits();
787 Botan::copy_mem(std::span(output, 57), ed_key);
788 return BOTAN_FFI_SUCCESS;
789 } else {
791 }
792 });
793#else
794 BOTAN_UNUSED(key, output);
796#endif
797}
A private key for Ed448/Ed448ph according to RFC 8032.
Definition ed448.h:83

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

◆ botan_privkey_export()

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 161 of file ffi_pkey.cpp.

161 {
162 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
163 return copy_view_bin(out, out_len, botan_privkey_view_der, key);
164 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
165 return copy_view_str(out, out_len, botan_privkey_view_pem, key);
166 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
167 return copy_view_bin(out, out_len, botan_privkey_view_raw, key);
168 } else {
170 }
171}
#define BOTAN_PRIVKEY_EXPORT_FLAG_RAW
Definition ffi.h:1184
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1183
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1182
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:173
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:183
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:178
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_EXPORT_FLAG_RAW, botan_privkey_view_der(), botan_privkey_view_pem(), botan_privkey_view_raw(), Botan_FFI::copy_view_bin(), and Botan_FFI::copy_view_str().

◆ botan_privkey_export_encrypted()

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 188 of file ffi_pkey.cpp.

194 {
195 return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
196}
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:275

References botan_privkey_export_encrypted_pbkdf_iter().

◆ botan_privkey_export_encrypted_pbkdf_iter()

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 275 of file ffi_pkey.cpp.

283 {
284 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
285 return copy_view_bin(
286 out, out_len, botan_privkey_view_encrypted_der, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
287 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
288 return copy_view_str(
289 out, out_len, botan_privkey_view_encrypted_pem, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
290 } else {
292 }
293}
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:295
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:320

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

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 198 of file ffi_pkey.cpp.

207 {
208 if(pbkdf_iters_out) {
209 *pbkdf_iters_out = 0;
210 }
211
212 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
213 return copy_view_bin(
214 out, out_len, botan_privkey_view_encrypted_der_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
215 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
216 return copy_view_str(
217 out, out_len, botan_privkey_view_encrypted_pem_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
218 } else {
220 }
221}
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:223
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:249

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

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

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

Definition at line 191 of file ffi_pkey_algs.cpp.

191 {
192 if(field_name_cstr == nullptr) {
194 }
195
196 const std::string field_name(field_name_cstr);
197
198 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); });
199}

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

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

int botan_privkey_load_classic_mceliece ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * cmce_mode )

Algorithm specific key operation: Classic McEliece

Definition at line 1260 of file ffi_pkey_algs.cpp.

1263 {
1264#if defined(BOTAN_HAS_CLASSICMCELIECE)
1265 if(key == nullptr || privkey == nullptr || cmce_mode == nullptr) {
1267 }
1268
1269 *key = nullptr;
1270
1271 return ffi_guard_thunk(__func__, [=]() -> int {
1272 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1273 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
1274 *key = new botan_privkey_struct(std::move(cmce_key));
1275 return BOTAN_FFI_SUCCESS;
1276 });
1277#else
1278 BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1280#endif
1281}
static Classic_McEliece_Parameter_Set from_string(std::string_view param_name)
Get the parameter set for a given parameter set name.

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

◆ botan_privkey_load_dh()

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

Definition at line 510 of file ffi_pkey_algs.cpp.

510 {
511#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
512 *key = nullptr;
513 return ffi_guard_thunk(__func__, [=]() -> int {
514 Botan::DL_Group group(safe_get(p), safe_get(g));
515 auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
516 *key = new botan_privkey_struct(std::move(dh));
517 return BOTAN_FFI_SUCCESS;
518 });
519#else
520 BOTAN_UNUSED(key, p, g, x);
522#endif
523}

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

◆ botan_privkey_load_dsa()

int botan_privkey_load_dsa ( botan_privkey_t * key,
botan_mp_t p,
botan_mp_t q,
botan_mp_t g,
botan_mp_t x )

Definition at line 333 of file ffi_pkey_algs.cpp.

333 {
334#if defined(BOTAN_HAS_DSA)
335 *key = nullptr;
336
337 return ffi_guard_thunk(__func__, [=]() -> int {
338 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
339 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(group, safe_get(x));
340 *key = new botan_privkey_struct(std::move(dsa));
341 return BOTAN_FFI_SUCCESS;
342 });
343#else
344 BOTAN_UNUSED(key, p, q, g, x);
346#endif
347}

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

◆ botan_privkey_load_ecdh()

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

Definition at line 580 of file ffi_pkey_algs.cpp.

580 {
581#if defined(BOTAN_HAS_ECDH)
582 return ffi_guard_thunk(__func__, [=]() -> int {
583 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
584 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
585 if(rc == BOTAN_FFI_SUCCESS) {
586 *key = new botan_privkey_struct(std::move(p_key));
587 }
588 return rc;
589 });
590#else
591 BOTAN_UNUSED(key, scalar, curve_name);
593#endif
594}

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

◆ botan_privkey_load_ecdsa()

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

Definition at line 430 of file ffi_pkey_algs.cpp.

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

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

◆ botan_privkey_load_ed25519()

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

Definition at line 682 of file ffi_pkey_algs.cpp.

682 {
683#if defined(BOTAN_HAS_ED25519)
684 *key = nullptr;
685 return ffi_guard_thunk(__func__, [=]() -> int {
686 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
687 auto ed25519 = std::make_unique<Botan::Ed25519_PrivateKey>(privkey_vec);
688 *key = new botan_privkey_struct(std::move(ed25519));
689 return BOTAN_FFI_SUCCESS;
690 });
691#else
692 BOTAN_UNUSED(key, privkey);
694#endif
695}

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

◆ botan_privkey_load_ed448()

int botan_privkey_load_ed448 ( botan_privkey_t * key,
const uint8_t privkey[57] )

Definition at line 754 of file ffi_pkey_algs.cpp.

754 {
755#if defined(BOTAN_HAS_ED448)
756 *key = nullptr;
757 return ffi_guard_thunk(__func__, [=]() -> int {
758 auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
759 *key = new botan_privkey_struct(std::move(ed448));
760 return BOTAN_FFI_SUCCESS;
761 });
762#else
763 BOTAN_UNUSED(key, privkey);
765#endif
766}

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

◆ botan_privkey_load_elgamal()

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

Loads ElGamal private key

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

Definition at line 489 of file ffi_pkey_algs.cpp.

489 {
490#if defined(BOTAN_HAS_ELGAMAL)
491 *key = nullptr;
492 return ffi_guard_thunk(__func__, [=]() -> int {
493 Botan::DL_Group group(safe_get(p), safe_get(g));
494 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(group, safe_get(x));
495 *key = new botan_privkey_struct(std::move(elg));
496 return BOTAN_FFI_SUCCESS;
497 });
498#else
499 BOTAN_UNUSED(key, p, g, x);
501#endif
502}

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

◆ botan_privkey_load_frodokem()

int botan_privkey_load_frodokem ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * frodo_mode )

Algorithm specific key operation: FrodoKEM

Definition at line 1216 of file ffi_pkey_algs.cpp.

1216 {
1217#if defined(BOTAN_HAS_FRODOKEM)
1218 if(key == nullptr || privkey == nullptr || frodo_mode == nullptr) {
1220 }
1221
1222 *key = nullptr;
1223
1224 return ffi_guard_thunk(__func__, [=]() -> int {
1225 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1226 auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
1227 *key = new botan_privkey_struct(std::move(frodo_key));
1228 return BOTAN_FFI_SUCCESS;
1229 });
1230#else
1231 BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1233#endif
1234}

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

◆ botan_privkey_load_kyber()

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

Definition at line 956 of file ffi_pkey_algs.cpp.

956 {
957#if defined(BOTAN_HAS_KYBER)
958 *key = nullptr;
959 switch(key_len) {
960 case 1632:
961 return ffi_guard_thunk(__func__, [=]() -> int {
962 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 1632);
963 auto kyber512 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber512_R3);
964 *key = new botan_privkey_struct(std::move(kyber512));
965 return BOTAN_FFI_SUCCESS;
966 });
967 case 2400:
968 return ffi_guard_thunk(__func__, [=]() -> int {
969 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 2400);
970 auto kyber768 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber768_R3);
971 *key = new botan_privkey_struct(std::move(kyber768));
972 return BOTAN_FFI_SUCCESS;
973 });
974 case 3168:
975 return ffi_guard_thunk(__func__, [=]() -> int {
976 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 3168);
977 auto kyber1024 = std::make_unique<Botan::Kyber_PrivateKey>(privkey_vec, Botan::KyberMode::Kyber1024_R3);
978 *key = new botan_privkey_struct(std::move(kyber1024));
979 return BOTAN_FFI_SUCCESS;
980 });
981 default:
982 BOTAN_UNUSED(key, privkey, key_len);
984 }
985#else
986 BOTAN_UNUSED(key, key_len, privkey);
988#endif
989}

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

int botan_privkey_load_ml_dsa ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * mldsa_mode )

Definition at line 1112 of file ffi_pkey_algs.cpp.

1112 {
1113#if defined(BOTAN_HAS_ML_DSA)
1114 if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
1116 }
1117
1118 *key = nullptr;
1119
1120 return ffi_guard_thunk(__func__, [=]() -> int {
1121 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1122 if(!mode.is_ml_dsa()) {
1124 }
1125
1126 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1127 *key = new botan_privkey_struct(std::move(mldsa_key));
1128 return BOTAN_FFI_SUCCESS;
1129 });
1130#else
1131 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1133#endif
1134}
DilithiumMode ML_DSA_Mode
Definition ml_dsa.h:21

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

◆ botan_privkey_load_ml_kem()

int botan_privkey_load_ml_kem ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * mlkem_mode )

Definition at line 1060 of file ffi_pkey_algs.cpp.

1060 {
1061#if defined(BOTAN_HAS_ML_KEM)
1062 if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
1064 }
1065
1066 *key = nullptr;
1067
1068 return ffi_guard_thunk(__func__, [=]() -> int {
1069 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1070 if(!mode.is_ml_kem()) {
1072 }
1073
1074 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1075 *key = new botan_privkey_struct(std::move(mlkem_key));
1076 return BOTAN_FFI_SUCCESS;
1077 });
1078#else
1079 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1081#endif
1082}
KyberMode ML_KEM_Mode
Definition ml_kem.h:21

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

◆ botan_privkey_load_rsa()

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

Definition at line 213 of file ffi_pkey_algs.cpp.

213 {
214#if defined(BOTAN_HAS_RSA)
215 *key = nullptr;
216
217 return ffi_guard_thunk(__func__, [=]() -> int {
218 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p), safe_get(rsa_q), safe_get(rsa_e));
219 *key = new botan_privkey_struct(std::move(rsa));
220 return BOTAN_FFI_SUCCESS;
221 });
222#else
223 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
225#endif
226}

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

◆ botan_privkey_load_rsa_pkcs1()

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

Definition at line 228 of file ffi_pkey_algs.cpp.

228 {
229#if defined(BOTAN_HAS_RSA)
230 *key = nullptr;
231
232 Botan::secure_vector<uint8_t> src(bits, bits + len);
233 return ffi_guard_thunk(__func__, [=]() -> int {
235 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, src);
236 *key = new botan_privkey_struct(std::move(rsa));
237 return BOTAN_FFI_SUCCESS;
238 });
239#else
240 BOTAN_UNUSED(key, bits, len);
242#endif
243}

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

int botan_privkey_load_slh_dsa ( botan_privkey_t * key,
const uint8_t privkey[],
size_t key_len,
const char * slhdsa_mode )

Definition at line 1164 of file ffi_pkey_algs.cpp.

1164 {
1165#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1166 if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
1168 }
1169
1170 *key = nullptr;
1171
1172 return ffi_guard_thunk(__func__, [=]() -> int {
1173 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1174 if(!mode.is_slh_dsa()) {
1176 }
1177
1178 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1179 *key = new botan_privkey_struct(std::move(slhdsa_key));
1180 return BOTAN_FFI_SUCCESS;
1181 });
1182#else
1183 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1185#endif
1186}

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

◆ botan_privkey_load_sm2()

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

Definition at line 652 of file ffi_pkey_algs.cpp.

652 {
653#if defined(BOTAN_HAS_SM2)
654 return ffi_guard_thunk(__func__, [=]() -> int {
655 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
656 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
657
658 if(rc == BOTAN_FFI_SUCCESS) {
659 *key = new botan_privkey_struct(std::move(p_key));
660 }
661 return rc;
662 });
663#else
664 BOTAN_UNUSED(key, scalar, curve_name);
666#endif
667}

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

Referenced by botan_privkey_load_sm2_enc().

◆ botan_privkey_load_sm2_enc()

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

Definition at line 676 of file ffi_pkey_algs.cpp.

676 {
677 return botan_privkey_load_sm2(key, scalar, curve_name);
678}
int botan_privkey_load_sm2(botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)

References botan_privkey_load_sm2().

◆ botan_privkey_load_x25519()

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

Definition at line 818 of file ffi_pkey_algs.cpp.

818 {
819#if defined(BOTAN_HAS_X25519)
820 *key = nullptr;
821 return ffi_guard_thunk(__func__, [=]() -> int {
822 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
823 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(privkey_vec);
824 *key = new botan_privkey_struct(std::move(x25519));
825 return BOTAN_FFI_SUCCESS;
826 });
827#else
828 BOTAN_UNUSED(key, privkey);
830#endif
831}

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

◆ botan_privkey_load_x448()

int botan_privkey_load_x448 ( botan_privkey_t * key,
const uint8_t privkey[56] )

Definition at line 890 of file ffi_pkey_algs.cpp.

890 {
891#if defined(BOTAN_HAS_X448)
892 *key = nullptr;
893 return ffi_guard_thunk(__func__, [=]() -> int {
894 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span(privkey, 56));
895 *key = new botan_privkey_struct(std::move(x448));
896 return BOTAN_FFI_SUCCESS;
897 });
898#else
899 BOTAN_UNUSED(key, privkey);
901#endif
902}
Point448 x448(const ScalarX448 &k, const Point448 &u)
Multiply a scalar k with a point u.

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

◆ botan_privkey_rsa_get_d()

int botan_privkey_rsa_get_d ( botan_mp_t d,
botan_privkey_t rsa_key )

Definition at line 275 of file ffi_pkey_algs.cpp.

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

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_e()

int botan_privkey_rsa_get_e ( botan_mp_t e,
botan_privkey_t rsa_key )

Definition at line 271 of file ffi_pkey_algs.cpp.

271 {
272 return botan_privkey_get_field(e, key, "e");
273}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_n()

int botan_privkey_rsa_get_n ( botan_mp_t n,
botan_privkey_t rsa_key )

Definition at line 267 of file ffi_pkey_algs.cpp.

267 {
268 return botan_privkey_get_field(n, key, "n");
269}

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_p()

int botan_privkey_rsa_get_p ( botan_mp_t p,
botan_privkey_t rsa_key )

Definition at line 259 of file ffi_pkey_algs.cpp.

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

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_privkey()

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

Definition at line 287 of file ffi_pkey_algs.cpp.

287 {
288#if defined(BOTAN_HAS_RSA)
289 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
290 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
291 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
292 return write_vec_output(out, out_len, rsa->private_key_bits());
293 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
294 return write_str_output(out, out_len, Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
295 } else {
297 }
298 } else {
300 }
301 });
302#else
303 BOTAN_UNUSED(rsa_key, out, out_len, flags);
305#endif
306}
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()

int botan_privkey_rsa_get_q ( botan_mp_t q,
botan_privkey_t rsa_key )

Definition at line 263 of file ffi_pkey_algs.cpp.

263 {
264 return botan_privkey_get_field(q, key, "q");
265}

References botan_privkey_get_field().

◆ botan_privkey_view_der()

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 173 of file ffi_pkey.cpp.

173 {
174 return BOTAN_FFI_VISIT(
175 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::BER_encode(k)); });
176}
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()

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 295 of file ffi_pkey.cpp.

302 {
303 if(passphrase == nullptr) {
305 }
306
307 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
309
310 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
311 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
312 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
313
314 auto pkcs8 = Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
315
316 return invoke_view_callback(view, ctx, pkcs8);
317 });
318}
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()

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 223 of file ffi_pkey.cpp.

230 {
231 if(passphrase == nullptr) {
233 }
234
235 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
236 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
238
239 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
240 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
241
242 auto pkcs8 =
243 Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
244
245 return invoke_view_callback(view, ctx, pkcs8);
246 });
247}
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()

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 320 of file ffi_pkey.cpp.

327 {
328 if(passphrase == nullptr) {
330 }
331
332 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
334
335 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
336 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
337 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
338
339 auto pkcs8 = Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
340
341 return invoke_view_callback(view, ctx, pkcs8);
342 });
343}
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()

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 249 of file ffi_pkey.cpp.

256 {
257 if(passphrase == nullptr) {
259 }
260
261 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
262 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
264
265 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
266 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
267
268 auto pkcs8 =
269 Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
270
271 return invoke_view_callback(view, ctx, pkcs8);
272 });
273}
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()

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

Definition at line 1026 of file ffi_pkey_algs.cpp.

1026 {
1027#if defined(BOTAN_HAS_KYBER)
1028 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1029 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1030 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1031 } else {
1033 }
1034 });
1035#else
1036 BOTAN_UNUSED(key, ctx, view);
1038#endif
1039}

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

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 178 of file ffi_pkey.cpp.

178 {
179 return BOTAN_FFI_VISIT(
180 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::PEM_encode(k)); });
181}
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_view_raw()

int botan_privkey_view_raw ( botan_privkey_t key,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the private key's raw encoding

Definition at line 183 of file ffi_pkey.cpp.

183 {
184 return BOTAN_FFI_VISIT(
185 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_private_key_bits()); });
186}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

Referenced by botan_privkey_export().

◆ botan_privkey_x25519_get_privkey()

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

Definition at line 848 of file ffi_pkey_algs.cpp.

848 {
849#if defined(BOTAN_HAS_X25519)
850 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
851 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
852 const auto x25519_key = x25519->raw_private_key_bits();
853 if(x25519_key.size() != 32) {
855 }
856 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
857 return BOTAN_FFI_SUCCESS;
858 } else {
860 }
861 });
862#else
863 BOTAN_UNUSED(key, output);
865#endif
866}

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

int botan_privkey_x448_get_privkey ( botan_privkey_t key,
uint8_t output[56] )

Definition at line 918 of file ffi_pkey_algs.cpp.

918 {
919#if defined(BOTAN_HAS_X448)
920 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
921 if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
922 const auto x448_key = x448->raw_private_key_bits();
923 Botan::copy_mem(std::span(output, 56), x448_key);
924 return BOTAN_FFI_SUCCESS;
925 } else {
927 }
928 });
929#else
930 BOTAN_UNUSED(key, output);
932#endif
933}
A private key for the X448 key agreement scheme according to RFC 7748.
Definition x448.h:67

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

◆ botan_pubkey_algo_name()

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

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

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

int botan_pubkey_dsa_get_g ( botan_mp_t d,
botan_pubkey_t key )

Definition at line 377 of file ffi_pkey_algs.cpp.

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

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_p()

int botan_pubkey_dsa_get_p ( botan_mp_t p,
botan_pubkey_t key )

Definition at line 369 of file ffi_pkey_algs.cpp.

369 {
370 return botan_pubkey_get_field(p, key, "p");
371}

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_q()

int botan_pubkey_dsa_get_q ( botan_mp_t q,
botan_pubkey_t key )

Definition at line 373 of file ffi_pkey_algs.cpp.

373 {
374 return botan_pubkey_get_field(q, key, "q");
375}

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_y()

int botan_pubkey_dsa_get_y ( botan_mp_t y,
botan_pubkey_t key )

Definition at line 381 of file ffi_pkey_algs.cpp.

381 {
382 return botan_pubkey_get_field(y, key, "y");
383}

References botan_pubkey_get_field().

◆ botan_pubkey_ecc_key_used_explicit_encoding()

int botan_pubkey_ecc_key_used_explicit_encoding ( botan_pubkey_t key)

Definition at line 391 of file ffi_pkey_algs.cpp.

391 {
392#if defined(BOTAN_HAS_ECC_KEY)
393 return ffi_guard_thunk(__func__, [=]() -> int {
394 const Botan::Public_Key& pub_key = safe_get(key);
395 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
396
397 if(ec_key == nullptr) {
399 }
400
401 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
402 });
403#else
404 BOTAN_UNUSED(key);
406#endif
407}
bool used_explicit_encoding() const
Definition ec_group.h:263
const EC_Group & domain() const
Definition ecc_key.cpp:63

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

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

Definition at line 732 of file ffi_pkey_algs.cpp.

732 {
733#if defined(BOTAN_HAS_ED25519)
734 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
735 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
736 const std::vector<uint8_t>& ed_key = ed->get_public_key();
737 if(ed_key.size() != 32) {
739 }
740 Botan::copy_mem(output, ed_key.data(), ed_key.size());
741 return BOTAN_FFI_SUCCESS;
742 } else {
744 }
745 });
746#else
747 BOTAN_UNUSED(key, output);
749#endif
750}

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

int botan_pubkey_ed448_get_pubkey ( botan_pubkey_t key,
uint8_t pubkey[57] )

Definition at line 799 of file ffi_pkey_algs.cpp.

799 {
800#if defined(BOTAN_HAS_ED448)
801 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
802 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
803 const auto ed_key = ed->public_key_bits();
804 Botan::copy_mem(std::span(output, 57), ed_key);
805 return BOTAN_FFI_SUCCESS;
806 } else {
808 }
809 });
810#else
811 BOTAN_UNUSED(key, output);
813#endif
814}
A public key for Ed448/Ed448ph according to RFC 8032.
Definition ed448.h:27

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

◆ botan_pubkey_estimated_strength()

int botan_pubkey_estimated_strength ( botan_pubkey_t key,
size_t * estimate )

Definition at line 345 of file ffi_pkey.cpp.

345 {
346 return BOTAN_FFI_VISIT(key, [=](const auto& k) { *estimate = k.estimated_strength(); });
347}

References BOTAN_FFI_VISIT.

◆ botan_pubkey_export()

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 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
140 return copy_view_bin(out, out_len, botan_pubkey_view_raw, key);
141 } else {
143 }
144}
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:151
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:146
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:156

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

◆ botan_pubkey_fingerprint()

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

Definition at line 349 of file ffi_pkey.cpp.

349 {
350 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
351 auto h = Botan::HashFunction::create_or_throw(hash_fn);
352 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
353 });
354}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:298

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

◆ botan_pubkey_get_field()

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

Definition at line 181 of file ffi_pkey_algs.cpp.

181 {
182 if(field_name_cstr == nullptr) {
184 }
185
186 const std::string field_name(field_name_cstr);
187
188 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); });
189}

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

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

int botan_pubkey_load_classic_mceliece ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * cmce_mode )

Definition at line 1283 of file ffi_pkey_algs.cpp.

1286 {
1287#if defined(BOTAN_HAS_CLASSICMCELIECE)
1288 if(key == nullptr || pubkey == nullptr || cmce_mode == nullptr) {
1290 }
1291
1292 *key = nullptr;
1293
1294 return ffi_guard_thunk(__func__, [=]() -> int {
1295 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1296 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
1297 *key = new botan_pubkey_struct(std::move(cmce_key));
1298 return BOTAN_FFI_SUCCESS;
1299 });
1300#else
1301 BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1303#endif
1304}

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

◆ botan_pubkey_load_dh()

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

Loads Diffie Hellman public key

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

Definition at line 525 of file ffi_pkey_algs.cpp.

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

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

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

349 {
350#if defined(BOTAN_HAS_DSA)
351 *key = nullptr;
352
353 return ffi_guard_thunk(__func__, [=]() -> int {
354 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
355 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
356 *key = new botan_pubkey_struct(std::move(dsa));
357 return BOTAN_FFI_SUCCESS;
358 });
359#else
360 BOTAN_UNUSED(key, p, q, g, y);
362#endif
363}

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

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

563 {
564#if defined(BOTAN_HAS_ECDH)
565 return ffi_guard_thunk(__func__, [=]() -> int {
566 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
567 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
568
569 if(rc == BOTAN_FFI_SUCCESS) {
570 *key = new botan_pubkey_struct(std::move(p_key));
571 }
572 return rc;
573 });
574#else
575 BOTAN_UNUSED(key, public_x, public_y, curve_name);
577#endif
578}

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

◆ botan_pubkey_load_ecdsa()

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

Definition at line 409 of file ffi_pkey_algs.cpp.

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

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

◆ botan_pubkey_load_ed25519()

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

Definition at line 697 of file ffi_pkey_algs.cpp.

697 {
698#if defined(BOTAN_HAS_ED25519)
699 *key = nullptr;
700 return ffi_guard_thunk(__func__, [=]() -> int {
701 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
702 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
703 *key = new botan_pubkey_struct(std::move(ed25519));
704 return BOTAN_FFI_SUCCESS;
705 });
706#else
707 BOTAN_UNUSED(key, pubkey);
709#endif
710}

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

◆ botan_pubkey_load_ed448()

int botan_pubkey_load_ed448 ( botan_pubkey_t * key,
const uint8_t pubkey[57] )

Definition at line 768 of file ffi_pkey_algs.cpp.

768 {
769#if defined(BOTAN_HAS_ED448)
770 *key = nullptr;
771 return ffi_guard_thunk(__func__, [=]() -> int {
772 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
773 *key = new botan_pubkey_struct(std::move(ed448));
774 return BOTAN_FFI_SUCCESS;
775 });
776#else
777 BOTAN_UNUSED(key, pubkey);
779#endif
780}

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

◆ botan_pubkey_load_elgamal()

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

Loads ElGamal public key

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

Definition at line 474 of file ffi_pkey_algs.cpp.

474 {
475#if defined(BOTAN_HAS_ELGAMAL)
476 *key = nullptr;
477 return ffi_guard_thunk(__func__, [=]() -> int {
478 Botan::DL_Group group(safe_get(p), safe_get(g));
479 auto elg = std::make_unique<Botan::ElGamal_PublicKey>(group, safe_get(y));
480 *key = new botan_pubkey_struct(std::move(elg));
481 return BOTAN_FFI_SUCCESS;
482 });
483#else
484 BOTAN_UNUSED(key, p, g, y);
486#endif
487}

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

◆ botan_pubkey_load_frodokem()

int botan_pubkey_load_frodokem ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * frodo_mode )

Definition at line 1236 of file ffi_pkey_algs.cpp.

1236 {
1237#if defined(BOTAN_HAS_FRODOKEM)
1238 if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
1240 }
1241
1242 *key = nullptr;
1243
1244 return ffi_guard_thunk(__func__, [=]() -> int {
1245 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1246 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1247 *key = new botan_pubkey_struct(std::move(frodo_key));
1248 return BOTAN_FFI_SUCCESS;
1249 });
1250#else
1251 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1253#endif
1254}

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

◆ botan_pubkey_load_kyber()

int botan_pubkey_load_kyber ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len )

Definition at line 991 of file ffi_pkey_algs.cpp.

991 {
992#if defined(BOTAN_HAS_KYBER)
993 *key = nullptr;
994 switch(key_len) {
995 case 800:
996 return ffi_guard_thunk(__func__, [=]() -> int {
997 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 800);
998 auto kyber512 = std::make_unique<Botan::Kyber_PublicKey>(pubkey_vec, Botan::KyberMode::Kyber512_R3);
999 *key = new botan_pubkey_struct(std::move(kyber512));
1000 return BOTAN_FFI_SUCCESS;
1001 });
1002 case 1184:
1003 return ffi_guard_thunk(__func__, [=]() -> int {
1004 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 1184);
1005 auto kyber768 = std::make_unique<Botan::Kyber_PublicKey>(pubkey_vec, Botan::KyberMode::Kyber768_R3);
1006 *key = new botan_pubkey_struct(std::move(kyber768));
1007 return BOTAN_FFI_SUCCESS;
1008 });
1009 case 1568:
1010 return ffi_guard_thunk(__func__, [=]() -> int {
1011 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 1568);
1012 auto kyber1024 = std::make_unique<Botan::Kyber_PublicKey>(pubkey_vec, Botan::KyberMode::Kyber1024_R3);
1013 *key = new botan_pubkey_struct(std::move(kyber1024));
1014 return BOTAN_FFI_SUCCESS;
1015 });
1016 default:
1017 BOTAN_UNUSED(key, pubkey, key_len);
1019 }
1020#else
1021 BOTAN_UNUSED(key, pubkey, key_len);
1023#endif
1024}

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

int botan_pubkey_load_ml_dsa ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * mldsa_mode )

Definition at line 1136 of file ffi_pkey_algs.cpp.

1136 {
1137#if defined(BOTAN_HAS_ML_DSA)
1138 if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
1140 }
1141
1142 *key = nullptr;
1143
1144 return ffi_guard_thunk(__func__, [=]() -> int {
1145 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1146 if(!mode.is_ml_dsa()) {
1148 }
1149
1150 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1151 *key = new botan_pubkey_struct(std::move(mldsa_key));
1152 return BOTAN_FFI_SUCCESS;
1153 });
1154#else
1155 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1157#endif
1158}

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

◆ botan_pubkey_load_ml_kem()

int botan_pubkey_load_ml_kem ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * mlkem_mode )

Definition at line 1084 of file ffi_pkey_algs.cpp.

1084 {
1085#if defined(BOTAN_HAS_ML_KEM)
1086 if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
1088 }
1089
1090 *key = nullptr;
1091
1092 return ffi_guard_thunk(__func__, [=]() -> int {
1093 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1094 if(!mode.is_ml_kem()) {
1096 }
1097
1098 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1099 *key = new botan_pubkey_struct(std::move(mlkem_key));
1100 return BOTAN_FFI_SUCCESS;
1101 });
1102#else
1103 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1105#endif
1106}

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

◆ botan_pubkey_load_rsa()

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

Definition at line 245 of file ffi_pkey_algs.cpp.

245 {
246#if defined(BOTAN_HAS_RSA)
247 *key = nullptr;
248 return ffi_guard_thunk(__func__, [=]() -> int {
249 auto rsa = std::make_unique<Botan::RSA_PublicKey>(safe_get(n), safe_get(e));
250 *key = new botan_pubkey_struct(std::move(rsa));
251 return BOTAN_FFI_SUCCESS;
252 });
253#else
254 BOTAN_UNUSED(key, n, e);
256#endif
257}

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

◆ botan_pubkey_load_slh_dsa()

int botan_pubkey_load_slh_dsa ( botan_pubkey_t * key,
const uint8_t pubkey[],
size_t key_len,
const char * slhdsa_mode )

Definition at line 1188 of file ffi_pkey_algs.cpp.

1188 {
1189#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1190 if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
1192 }
1193
1194 *key = nullptr;
1195
1196 return ffi_guard_thunk(__func__, [=]() -> int {
1197 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1198 if(!mode.is_slh_dsa()) {
1200 }
1201
1202 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1203 *key = new botan_pubkey_struct(std::move(mldsa_key));
1204 return BOTAN_FFI_SUCCESS;
1205 });
1206#else
1207 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1209#endif
1210}

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

◆ botan_pubkey_load_sm2()

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

Definition at line 633 of file ffi_pkey_algs.cpp.

636 {
637#if defined(BOTAN_HAS_SM2)
638 return ffi_guard_thunk(__func__, [=]() -> int {
639 std::unique_ptr<Botan::SM2_PublicKey> p_key;
640 if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name)) {
641 *key = new botan_pubkey_struct(std::move(p_key));
642 return BOTAN_FFI_SUCCESS;
643 }
645 });
646#else
647 BOTAN_UNUSED(key, public_x, public_y, curve_name);
649#endif
650}

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

Referenced by botan_pubkey_load_sm2_enc().

◆ botan_pubkey_load_sm2_enc()

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

Definition at line 669 of file ffi_pkey_algs.cpp.

672 {
673 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
674}
int botan_pubkey_load_sm2(botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)

References botan_pubkey_load_sm2().

◆ botan_pubkey_load_x25519()

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

Definition at line 833 of file ffi_pkey_algs.cpp.

833 {
834#if defined(BOTAN_HAS_X25519)
835 *key = nullptr;
836 return ffi_guard_thunk(__func__, [=]() -> int {
837 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
838 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(pubkey_vec);
839 *key = new botan_pubkey_struct(std::move(x25519));
840 return BOTAN_FFI_SUCCESS;
841 });
842#else
843 BOTAN_UNUSED(key, pubkey);
845#endif
846}

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

◆ botan_pubkey_load_x448()

int botan_pubkey_load_x448 ( botan_pubkey_t * key,
const uint8_t pubkey[56] )

Definition at line 904 of file ffi_pkey_algs.cpp.

904 {
905#if defined(BOTAN_HAS_X448)
906 *key = nullptr;
907 return ffi_guard_thunk(__func__, [=]() -> int {
908 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span(pubkey, 56));
909 *key = new botan_pubkey_struct(std::move(x448));
910 return BOTAN_FFI_SUCCESS;
911 });
912#else
913 BOTAN_UNUSED(key, pubkey);
915#endif
916}

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

◆ botan_pubkey_rsa_get_e()

int botan_pubkey_rsa_get_e ( botan_mp_t e,
botan_pubkey_t rsa_key )

Definition at line 279 of file ffi_pkey_algs.cpp.

279 {
280 return botan_pubkey_get_field(e, key, "e");
281}

References botan_pubkey_get_field().

◆ botan_pubkey_rsa_get_n()

int botan_pubkey_rsa_get_n ( botan_mp_t n,
botan_pubkey_t rsa_key )

Definition at line 283 of file ffi_pkey_algs.cpp.

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

References botan_pubkey_get_field().

◆ botan_pubkey_sm2_compute_za()

int botan_pubkey_sm2_compute_za ( uint8_t out[],
size_t * out_len,
const char * ident,
const char * hash_algo,
botan_pubkey_t key )

Definition at line 598 of file ffi_pkey_algs.cpp.

599 {
600 if(out == nullptr || out_len == nullptr) {
602 }
603 if(ident == nullptr || hash_algo == nullptr || key == nullptr) {
605 }
606
607#if defined(BOTAN_HAS_SM2)
608 return ffi_guard_thunk(__func__, [=]() -> int {
609 const Botan::Public_Key& pub_key = safe_get(key);
610 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
611
612 if(ec_key == nullptr) {
614 }
615
616 if(ec_key->algo_name() != "SM2") {
618 }
619
620 const std::string ident_str(ident);
621 std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
622
623 const std::vector<uint8_t> za =
624 Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->_public_ec_point());
625
626 return write_vec_output(out, out_len, za);
627 });
628#else
630#endif
631}
virtual std::string algo_name() const =0
const EC_AffinePoint & _public_ec_point() const
Definition ecc_key.cpp:75
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, std::string_view user_id, const EC_Group &group, const EC_AffinePoint &pubkey)
Definition sm2.cpp:68

References Botan::EC_PublicKey::_public_ec_point(), Botan::Asymmetric_Key::algo_name(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, Botan::HashFunction::create_or_throw(), Botan::EC_PublicKey::domain(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::sm2_compute_za(), and Botan_FFI::write_vec_output().

◆ botan_pubkey_view_der()

int botan_pubkey_view_der ( botan_pubkey_t key,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the public key's DER encoding

Definition at line 146 of file ffi_pkey.cpp.

146 {
147 return BOTAN_FFI_VISIT(
148 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::X509::BER_encode(k)); });
149}
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition x509_key.h:23

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

Referenced by botan_pubkey_export().

◆ botan_pubkey_view_ec_public_point()

int botan_pubkey_view_ec_public_point ( botan_pubkey_t key,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the uncompressed public point associated with the key

Definition at line 1306 of file ffi_pkey_algs.cpp.

1306 {
1307#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1308 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1309 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1310 auto pt = ecc->_public_ec_point().serialize_uncompressed();
1311 return invoke_view_callback(view, ctx, pt);
1312 } else {
1314 }
1315 });
1316#else
1317 BOTAN_UNUSED(key, view, ctx);
1319#endif
1320}

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

◆ botan_pubkey_view_kyber_raw_key()

int botan_pubkey_view_kyber_raw_key ( botan_pubkey_t key,
botan_view_ctx ctx,
botan_view_bin_fn view )

Definition at line 1041 of file ffi_pkey_algs.cpp.

1041 {
1042#if defined(BOTAN_HAS_KYBER)
1043 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1044 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1045 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1046 } else {
1048 }
1049 });
1050#else
1051 BOTAN_UNUSED(key, ctx, view);
1053#endif
1054}

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

◆ botan_pubkey_view_pem()

int botan_pubkey_view_pem ( botan_pubkey_t key,
botan_view_ctx ctx,
botan_view_str_fn view )

View the public key's PEM encoding

Definition at line 151 of file ffi_pkey.cpp.

151 {
152 return BOTAN_FFI_VISIT(
153 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::X509::PEM_encode(k)); });
154}
std::string PEM_encode(const Public_Key &key)
Definition x509_key.cpp:21

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

Referenced by botan_pubkey_export().

◆ botan_pubkey_view_raw()

int botan_pubkey_view_raw ( botan_pubkey_t key,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the public key's raw encoding

Definition at line 156 of file ffi_pkey.cpp.

156 {
157 return BOTAN_FFI_VISIT(
158 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_public_key_bits()); });
159}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

Referenced by botan_pubkey_export().

◆ botan_pubkey_x25519_get_pubkey()

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

Definition at line 868 of file ffi_pkey_algs.cpp.

868 {
869#if defined(BOTAN_HAS_X25519)
870 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
871 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
872 const std::vector<uint8_t>& x25519_key = x25519->public_value();
873 if(x25519_key.size() != 32) {
875 }
876 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
877 return BOTAN_FFI_SUCCESS;
878 } else {
880 }
881 });
882#else
883 BOTAN_UNUSED(key, output);
885#endif
886}

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

int botan_pubkey_x448_get_pubkey ( botan_pubkey_t key,
uint8_t pubkey[56] )

Definition at line 935 of file ffi_pkey_algs.cpp.

935 {
936#if defined(BOTAN_HAS_X448)
937 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
938 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
939 const std::vector<uint8_t>& x448_key = x448->public_value();
940 Botan::copy_mem(std::span(output, 56), x448_key);
941 return BOTAN_FFI_SUCCESS;
942 } else {
944 }
945 });
946#else
947 BOTAN_UNUSED(key, output);
949#endif
950}
A public key for the X448 key agreement scheme according to RFC 7748.
Definition x448.h:19

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

◆ botan_pwdhash()

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

Definition at line 53 of file ffi_kdf.cpp.

62 {
63 if(algo == nullptr || password == nullptr) {
65 }
66
67 if(password_len == 0) {
68 password_len = std::strlen(password);
69 }
70
71 return ffi_guard_thunk(__func__, [=]() -> int {
72 auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
73
74 if(!pwdhash_fam) {
76 }
77
78 auto pwdhash = pwdhash_fam->from_params(param1, param2, param3);
79
80 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
81
82 return BOTAN_FFI_SUCCESS;
83 });
84}
static std::unique_ptr< PasswordHashFamily > create(std::string_view algo_spec, std::string_view provider="")
Definition pwdhash.cpp:54

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

Referenced by botan_pbkdf(), and botan_scrypt().

◆ botan_pwdhash_timed()

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 * passphrase,
size_t passphrase_len,
const uint8_t salt[],
size_t salt_len )

Definition at line 86 of file ffi_kdf.cpp.

96 {
97 if(algo == nullptr || password == nullptr) {
99 }
100
101 if(password_len == 0) {
102 password_len = std::strlen(password);
103 }
104
105 return ffi_guard_thunk(__func__, [=]() -> int {
106 auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
107
108 if(!pwdhash_fam) {
110 }
111
112 auto pwdhash = pwdhash_fam->tune(out_len, std::chrono::milliseconds(msec));
113
114 if(param1) {
115 *param1 = pwdhash->iterations();
116 }
117 if(param2) {
118 *param2 = pwdhash->parallelism();
119 }
120 if(param3) {
121 *param3 = pwdhash->memory_param();
122 }
123
124 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
125
126 return BOTAN_FFI_SUCCESS;
127 });
128}

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

Referenced by botan_pbkdf_timed().

◆ botan_rng_add_entropy()

int botan_rng_add_entropy ( botan_rng_t rng,
const uint8_t * entropy,
size_t entropy_len )

Add some seed material to a random number generator

Parameters
rngrng object
entropythe data to add
entropy_lenlength of entropy buffer
Returns
0 on success, a negative value on failure

Definition at line 181 of file ffi_rng.cpp.

181 {
182 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.add_entropy(input, len); });
183}

References BOTAN_FFI_VISIT.

◆ botan_rng_destroy()

int botan_rng_destroy ( botan_rng_t rng)

Frees all resources of the random number generator object

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

Definition at line 162 of file ffi_rng.cpp.

162 {
163 return BOTAN_FFI_CHECKED_DELETE(rng);
164}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_rng_get()

int botan_rng_get ( botan_rng_t rng,
uint8_t * out,
size_t out_len )

Get random bytes from a random number generator

Parameters
rngrng object
outoutput buffer of size out_len
out_lennumber of requested bytes
Returns
0 on success, negative on failure

Definition at line 166 of file ffi_rng.cpp.

166 {
167 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.randomize(out, out_len); });
168}

References BOTAN_FFI_VISIT.

◆ botan_rng_init()

int botan_rng_init ( botan_rng_t * rng,
const char * rng_type )

Initialize a random number generator object

Parameters
rngrng object
rng_typetype of the rng, possible values: "system": system RNG "esdm-full": ESDM RNG (fully seeded) "esdm-pr": ESDM RNG (w. prediction resistance) "user": userspace RNG "user-threadsafe": userspace RNG, with internal locking "rdrand": directly read RDRAND Set rng_type to null to let the library choose some default.

Definition at line 33 of file ffi_rng.cpp.

33 {
34 return ffi_guard_thunk(__func__, [=]() -> int {
35 if(rng_out == nullptr) {
37 }
38
39 const std::string rng_type_s(rng_type ? rng_type : "system");
40
41 std::unique_ptr<Botan::RandomNumberGenerator> rng;
42
43 if(rng_type_s == "system") {
44 rng = std::make_unique<Botan::System_RNG>();
45 } else if(rng_type_s == "user" || rng_type_s == "user-threadsafe") {
46 rng = std::make_unique<Botan::AutoSeeded_RNG>();
47 } else if(rng_type_s == "null") {
48 rng = std::make_unique<Botan::Null_RNG>();
49 }
50#if defined(BOTAN_HAS_PROCESSOR_RNG)
51 else if((rng_type_s == "rdrand" || rng_type_s == "hwrng") && Botan::Processor_RNG::available()) {
52 rng = std::make_unique<Botan::Processor_RNG>();
53 }
54#endif
55#if defined(BOTAN_HAS_JITTER_RNG)
56 else if(rng_type_s == "jitter") {
57 rng = std::make_unique<Botan::Jitter_RNG>();
58 }
59#endif
60#if defined(BOTAN_HAS_ESDM_RNG)
61 else if(rng_type_s == "esdm-full") {
62 rng = std::make_unique<Botan::ESDM_RNG>(false);
63 } else if(rng_type_s == "esdm-pr") {
64 rng = std::make_unique<Botan::ESDM_RNG>(true);
65 }
66#endif
67
68 if(!rng) {
70 }
71
72 *rng_out = new botan_rng_struct(std::move(rng));
73 return BOTAN_FFI_SUCCESS;
74 });
75}

References Botan::Processor_RNG::available(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and Botan_FFI::ffi_guard_thunk().

◆ botan_rng_init_custom()

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

Initialize a custom random number generator from a set of callback functions

Parameters
rng_outrng object to create
rng_namename of the rng
contextAn application-specific context passed to the callback functions
get_cbCallback for getting random bytes from the rng, return 0 for success
add_entropy_cbCallback for adding entropy to the rng, return 0 for success, may be NULL
destroy_cbCallback called when rng is destroyed, may be NULL

Definition at line 77 of file ffi_rng.cpp.

82 {
83 return ffi_guard_thunk(__func__, [=]() -> int {
84 if(rng_out == nullptr) {
86 }
87
88 if(rng_name == nullptr) {
90 }
91
92 if(get_cb == nullptr) {
94 }
95
96 class Custom_RNG : public Botan::RandomNumberGenerator {
97 public:
98 Custom_RNG(std::string_view name,
99 void* context,
100 int (*get_cb)(void* context, uint8_t* out, size_t out_len),
101 int (*add_entropy_cb)(void* context, const uint8_t input[], size_t length),
102 void (*destroy_cb)(void* context)) :
103 m_name(name) {
104 m_context = context;
105 m_get_cb = get_cb;
106 m_add_entropy_cb = add_entropy_cb;
107 m_destroy_cb = destroy_cb;
108 }
109
110 ~Custom_RNG() override {
111 if(m_destroy_cb) {
112 m_destroy_cb(m_context);
113 }
114 }
115
116 Custom_RNG(const Custom_RNG& other) = delete;
117 Custom_RNG(Custom_RNG&& other) = delete;
118 Custom_RNG& operator=(const Custom_RNG& other) = delete;
119 Custom_RNG& operator=(Custom_RNG&& other) = delete;
120
121 protected:
122 void fill_bytes_with_input(std::span<uint8_t> output, std::span<const uint8_t> input) override {
123 if(accepts_input() && !input.empty()) {
124 int rc = m_add_entropy_cb(m_context, input.data(), input.size());
125 if(rc) {
126 throw Botan::Invalid_State("Failed to add entropy via C callback, rc=" + std::to_string(rc));
127 }
128 }
129
130 if(!output.empty()) {
131 int rc = m_get_cb(m_context, output.data(), output.size());
132 if(rc) {
133 throw Botan::Invalid_State("Failed to get random from C callback, rc=" + std::to_string(rc));
134 }
135 }
136 }
137
138 public:
139 bool accepts_input() const override { return m_add_entropy_cb != nullptr; }
140
141 std::string name() const override { return m_name; }
142
143 void clear() override {}
144
145 bool is_seeded() const override { return true; }
146
147 private:
148 std::string m_name;
149 void* m_context;
150 std::function<int(void* context, uint8_t* out, size_t out_len)> m_get_cb;
151 std::function<int(void* context, const uint8_t input[], size_t length)> m_add_entropy_cb;
152 std::function<void(void* context)> m_destroy_cb;
153 };
154
155 auto rng = std::make_unique<Custom_RNG>(rng_name, context, get_cb, add_entropy_cb, destroy_cb);
156
157 *rng_out = new botan_rng_struct(std::move(rng));
158 return BOTAN_FFI_SUCCESS;
159 });
160}

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

◆ botan_rng_reseed()

int botan_rng_reseed ( botan_rng_t rng,
size_t bits )

Reseed a random number generator Uses the System_RNG as a seed generator.

Parameters
rngrng object
bitsnumber of bits to reseed with
Returns
0 on success, a negative value on failure

Definition at line 177 of file ffi_rng.cpp.

177 {
178 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.reseed_from_rng(Botan::system_rng(), bits); });
179}

References BOTAN_FFI_VISIT, and Botan::system_rng().

◆ botan_rng_reseed_from_rng()

int botan_rng_reseed_from_rng ( botan_rng_t rng,
botan_rng_t source_rng,
size_t bits )

Reseed a random number generator

Parameters
rngrng object
source_rngthe rng that will be read from
bitsnumber of bits to reseed with
Returns
0 on success, a negative value on failure

Definition at line 185 of file ffi_rng.cpp.

185 {
186 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.reseed_from_rng(safe_get(source_rng), bits); });
187}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_same_mem()

int botan_same_mem ( const uint8_t * x,
const uint8_t * y,
size_t len )

Deprecated equivalent to botan_constant_time_compare

Definition at line 314 of file ffi.cpp.

314 {
315 return botan_constant_time_compare(x, y, len);
316}
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition ffi.cpp:308

References botan_constant_time_compare().

◆ botan_scrub_mem()

int botan_scrub_mem ( void * mem,
size_t bytes )

Clear out memory using a system specific approach to bypass elision by the compiler (currently using RtlSecureZeroMemory or tricks with volatile pointers).

Definition at line 318 of file ffi.cpp.

318 {
319 Botan::secure_scrub_memory(mem, bytes);
320 return BOTAN_FFI_SUCCESS;
321}
void secure_scrub_memory(void *ptr, size_t n)
Definition mem_utils.cpp:19

References BOTAN_FFI_SUCCESS, and Botan::secure_scrub_memory().

◆ botan_scrypt()

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 )

Derive a key using scrypt Deprecated; use botan_pwdhash("Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);

Definition at line 146 of file ffi_kdf.cpp.

153 {
154 return botan_pwdhash("Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);
155}

References botan_pwdhash().

◆ botan_srp6_client_agree()

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 )

SRP6a Client side

Parameters
usernamethe username we are attempting login for
passwordthe password we are attempting to use
group_idspecifies the shared SRP group
hash_idspecifies a secure hash function
saltis the salt value sent by the server
salt_lenthe length of salt
Bis the server's public value
B_lenis the server's public value length
rng_objis a random number generator object
Aout buffer to store the SRP-6 A value
A_lenSRP-6 A verifier value length
Kout buffer to store the symmetric value
K_lensymmetric key length
Returns
0 on success, negative on failure

Definition at line 143 of file ffi_srp6.cpp.

155 {
156#if defined(BOTAN_HAS_SRP6)
157 return ffi_guard_thunk(__func__, [=]() -> int {
158 if(!identity || !password || !salt || !group_id || !hash_id || !b || !rng_obj) {
160 }
161 try {
162 std::vector<uint8_t> saltv(salt, salt + salt_len);
164 auto b_bn = Botan::BigInt::from_bytes({b, b_len});
165 auto [A_bn, K_sk] = Botan::srp6_client_agree(identity, password, group_id, hash_id, saltv, b_bn, rng);
166 auto ret_a = write_vec_output(A, A_len, A_bn.serialize());
167 auto ret_k = write_vec_output(K, K_len, K_sk.bits_of());
168 if(ret_a != BOTAN_FFI_SUCCESS) {
169 return ret_a;
170 }
171 if(ret_k != BOTAN_FFI_SUCCESS) {
172 return ret_k;
173 }
174 return BOTAN_FFI_SUCCESS;
175 } catch(Botan::Lookup_Error&) {
177 }
178 });
179#else
180 BOTAN_UNUSED(identity, password, group_id, hash_id, rng_obj);
181 BOTAN_UNUSED(salt, salt_len, b, b_len, A, A_len, K, K_len);
183#endif
184}
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition bigint.cpp:95
std::pair< BigInt, SymmetricKey > srp6_client_agree(std::string_view identifier, std::string_view password, std::string_view group_id, std::string_view hash_id, const std::vector< uint8_t > &salt, const BigInt &B, RandomNumberGenerator &rng)
Definition srp6.cpp:64

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::BigInt::from_bytes(), Botan_FFI::safe_get(), Botan::srp6_client_agree(), and Botan_FFI::write_vec_output().

◆ botan_srp6_generate_verifier()

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 )

Generate a new SRP-6 verifier

Parameters
identifiera username or other client identifier
passwordthe secret used to authenticate user
salta randomly chosen value, at least 128 bits long
salt_lenthe length of salt
group_idspecifies the shared SRP group
hash_idspecifies a secure hash function
verifierout buffer to store the SRP-6 verifier value
verifier_lenSRP-6 verifier value length
Returns
0 on success, negative on failure

Definition at line 115 of file ffi_srp6.cpp.

122 {
123#if defined(BOTAN_HAS_SRP6)
124 return ffi_guard_thunk(__func__, [=]() -> int {
125 if(!username || !password || !salt || !group_id || !hash_id) {
127 }
128 try {
129 std::vector<uint8_t> salt_vec(salt, salt + salt_len);
130 auto verifier_bn = Botan::srp6_generate_verifier(username, password, salt_vec, group_id, hash_id);
131 return write_vec_output(verifier, verifier_len, verifier_bn.serialize());
132 } catch(Botan::Lookup_Error&) {
134 }
135 });
136#else
137 BOTAN_UNUSED(username, password, group_id, hash_id);
138 BOTAN_UNUSED(salt, salt_len, verifier, verifier_len);
140#endif
141}
BigInt srp6_generate_verifier(std::string_view identifier, std::string_view password, const std::vector< uint8_t > &salt, std::string_view group_id, std::string_view hash_id)
Definition srp6.cpp:127

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::srp6_generate_verifier(), and Botan_FFI::write_vec_output().

◆ botan_srp6_group_size()

int botan_srp6_group_size ( const char * group_id,
size_t * group_p_bytes )

Return the size, in bytes, of the prime associated with group_id

Definition at line 47 of file ffi_srp6.cpp.

47 {
48#if defined(BOTAN_HAS_SRP6)
49 if(group_id == nullptr || group_p_bytes == nullptr) {
51 }
52
53 return ffi_guard_thunk(__func__, [=]() -> int {
54 auto group = Botan::DL_Group::from_name(group_id);
55 *group_p_bytes = group.p_bytes();
56 return BOTAN_FFI_SUCCESS;
57 });
58#else
59 BOTAN_UNUSED(group_id, group_p_bytes);
61#endif
62}
static DL_Group from_name(std::string_view name)
Definition dl_group.cpp:212

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

◆ botan_srp6_server_session_destroy()

int botan_srp6_server_session_destroy ( botan_srp6_server_session_t srp6)

Frees all resources of the SRP-6 server session object

Parameters
srp6SRP-6 server session object
Returns
0 if success, error if invalid object handle

Definition at line 43 of file ffi_srp6.cpp.

43 {
44 return BOTAN_FFI_CHECKED_DELETE(srp6);
45}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_srp6_server_session_init()

int botan_srp6_server_session_init ( botan_srp6_server_session_t * srp6)

Initialize an SRP-6 server session object

Parameters
srp6SRP-6 server session object

Definition at line 31 of file ffi_srp6.cpp.

31 {
32#if defined(BOTAN_HAS_SRP6)
33 return ffi_guard_thunk(__func__, [=]() -> int {
34 *srp6 = new botan_srp6_server_session_struct(std::make_unique<Botan::SRP6_Server_Session>());
35 return BOTAN_FFI_SUCCESS;
36 });
37#else
38 BOTAN_UNUSED(srp6);
40#endif
41}

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

◆ botan_srp6_server_session_step1()

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 )

SRP-6 Server side step 1

Parameters
srp6SRP-6 server session object
verifierthe verification value saved from client registration
verifier_lenSRP-6 verifier value length
group_idthe SRP group id
hash_idthe SRP hash in use
rng_obja random number generator object
B_pubout buffer to store the SRP-6 B value
B_pub_lenSRP-6 B value length
Returns
0 on success, negative on failure

◆ botan_srp6_server_session_step2()

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 )

SRP-6 Server side step 2

Parameters
srp6SRP-6 server session object
Athe client's value
A_lenthe client's value length
keyout buffer to store the symmetric key value
key_lensymmetric key length
Returns
0 on success, negative on failure

Definition at line 94 of file ffi_srp6.cpp.

95 {
96#if defined(BOTAN_HAS_SRP6)
97 return BOTAN_FFI_VISIT(srp6, [=](auto& s) -> int {
98 if(!a) {
100 }
101 try {
102 Botan::BigInt a_bn = Botan::BigInt::from_bytes({a, a_len});
103 auto key_sk = s.step2(a_bn);
104 return write_vec_output(key, key_len, key_sk.bits_of());
105 } catch(Botan::Decoding_Error&) {
107 }
108 });
109#else
110 BOTAN_UNUSED(srp6, a, a_len, key, key_len);
112#endif
113}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::BigInt::from_bytes(), and Botan_FFI::write_vec_output().

◆ botan_system_rng_get()

int botan_system_rng_get ( uint8_t * out,
size_t out_len )

Get random bytes from system random number generator

Parameters
outoutput buffer of size out_len
out_lennumber of requested bytes
Returns
0 on success, negative on failure

Definition at line 170 of file ffi_rng.cpp.

170 {
171 return ffi_guard_thunk(__func__, [=]() -> int {
172 Botan::system_rng().randomize(out, out_len);
173 return BOTAN_FFI_SUCCESS;
174 });
175}
void randomize(std::span< uint8_t > output)
Definition rng.h:53

References BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan::RandomNumberGenerator::randomize(), and Botan::system_rng().

◆ botan_totp_check()

int botan_totp_check ( botan_totp_t totp,
uint32_t totp_code,
uint64_t timestamp,
size_t acceptable_clock_drift )

Verify a TOTP code

Parameters
totpthe TOTP object
totp_codethe presented OTP
timestampthe current local timestamp
acceptable_clock_driftspecifies the acceptable amount of clock drift (in terms of time steps) between the two hosts.

Definition at line 69 of file ffi_totp.cpp.

69 {
70#if defined(BOTAN_HAS_TOTP)
71 return BOTAN_FFI_VISIT(totp, [=](auto& t) {
72 const bool ok = t.verify_totp(totp_code, timestamp, acceptable_clock_drift);
74 });
75
76#else
77 BOTAN_UNUSED(totp, totp_code, timestamp, acceptable_clock_drift);
79#endif
80}

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

◆ botan_totp_destroy()

int botan_totp_destroy ( botan_totp_t totp)

Destroy a TOTP instance

Returns
0 if success, error if invalid object handle

Definition at line 46 of file ffi_totp.cpp.

46 {
47#if defined(BOTAN_HAS_TOTP)
48 return BOTAN_FFI_CHECKED_DELETE(totp);
49#else
50 BOTAN_UNUSED(totp);
52#endif
53}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_totp_generate()

int botan_totp_generate ( botan_totp_t totp,
uint32_t * totp_code,
uint64_t timestamp )

Generate a TOTP code for the provided timestamp

Parameters
totpthe TOTP object
totp_codethe OTP code will be written here
timestampthe current local timestamp

Definition at line 55 of file ffi_totp.cpp.

55 {
56#if defined(BOTAN_HAS_TOTP)
57 if(totp == nullptr || totp_code == nullptr) {
59 }
60
61 return BOTAN_FFI_VISIT(totp, [=](auto& t) { *totp_code = t.generate_totp(timestamp); });
62
63#else
64 BOTAN_UNUSED(totp, totp_code, timestamp);
66#endif
67}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_totp_init()

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 )

Initialize a TOTP instance

Definition at line 25 of file ffi_totp.cpp.

26 {
27 if(totp == nullptr || key == nullptr || hash_algo == nullptr) {
29 }
30
31 *totp = nullptr;
32
33#if defined(BOTAN_HAS_TOTP)
34 return ffi_guard_thunk(__func__, [=]() -> int {
35 auto otp = std::make_unique<Botan::TOTP>(key, key_len, hash_algo, digits, time_step);
36 *totp = new botan_totp_struct(std::move(otp));
37
38 return BOTAN_FFI_SUCCESS;
39 });
40#else
41 BOTAN_UNUSED(totp, key, key_len, hash_algo, digits, time_step);
43#endif
44}

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

◆ botan_tpm2_crypto_backend_state_destroy()

int botan_tpm2_crypto_backend_state_destroy ( botan_tpm2_crypto_backend_state_t cbs)

Frees all resouces of a TPM2 Crypto Callback State Note that this does not attempt to de-register the crypto backend, it just frees the resource pointed to by cbs. Use the ESAPI function Esys_SetCryptoCallbacks(ctx, nullptr) to deregister manually.

Parameters
cbsTPM2 Crypto Callback State
Returns
0 on success

Definition at line 207 of file ffi_tpm2.cpp.

207 {
208#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
209 return BOTAN_FFI_CHECKED_DELETE(cbs);
210#else
211 BOTAN_UNUSED(cbs);
213#endif
214}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_tpm2_ctx_destroy()

int botan_tpm2_ctx_destroy ( botan_tpm2_ctx_t ctx)

Frees all resouces of a TPM2 context

Parameters
ctxTPM2 context
Returns
0 on success

Definition at line 175 of file ffi_tpm2.cpp.

175 {
176#if defined(BOTAN_HAS_TPM2)
177 return BOTAN_FFI_CHECKED_DELETE(ctx);
178#else
179 BOTAN_UNUSED(ctx);
181#endif
182}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_tpm2_ctx_enable_crypto_backend()

int botan_tpm2_ctx_enable_crypto_backend ( botan_tpm2_ctx_t ctx,
botan_rng_t rng )

Enable Botan's TSS2 crypto backend that replaces the cryptographic functions required for the communication with the TPM with implementations provided by Botan instead of using TSS' defaults OpenSSL or mbedTLS. Note that the provided rng should not be dependent on the TPM and the caller must ensure that it remains usable for the lifetime of the ctx.

Parameters
ctxTPM2 context
rngrandom number generator to be used by the crypto backend

Definition at line 152 of file ffi_tpm2.cpp.

152 {
153#if defined(BOTAN_HAS_TPM2)
154 return BOTAN_FFI_VISIT(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int {
156
157 // The lifetime of the RNG used for the crypto backend should be managed
158 // by the TPM2::Context. Here, we just need to trust the user that they
159 // keep the passed-in RNG instance intact for the lifetime of the context.
160 std::shared_ptr<Botan::RandomNumberGenerator> rng_ptr(&rng_ref, [](auto*) {});
161 ctx_wrapper.ctx->use_botan_crypto_backend(rng_ptr);
162 return BOTAN_FFI_SUCCESS;
163 });
164#else
165 BOTAN_UNUSED(ctx, rng);
167#endif
168}

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

◆ botan_tpm2_ctx_from_esys()

int botan_tpm2_ctx_from_esys ( botan_tpm2_ctx_t * ctx_out,
struct ESYS_CONTEXT * esys_ctx )

Wrap an existing ESYS_CONTEXT for use in Botan. Note that destroying the created botan_tpm2_ctx_t won't finalize esys_ctx

Parameters
ctx_outoutput TPM2 context
esys_ctxESYS_CONTEXT to wrap
Returns
0 on success

Definition at line 134 of file ffi_tpm2.cpp.

134 {
135#if defined(BOTAN_HAS_TPM2)
136 return ffi_guard_thunk(__func__, [=]() -> int {
137 if(ctx_out == nullptr || esys_ctx == nullptr) {
139 }
140
141 auto ctx = std::make_unique<botan_tpm2_ctx_wrapper>();
142 ctx->ctx = Botan::TPM2::Context::create(esys_ctx);
143 *ctx_out = new botan_tpm2_ctx_struct(std::move(ctx));
144 return BOTAN_FFI_SUCCESS;
145 });
146#else
147 BOTAN_UNUSED(ctx_out, esys_ctx);
149#endif
150}
static std::shared_ptr< Context > create(const std::string &tcti_nameconf)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan::TPM2::Context::create(), and Botan_FFI::ffi_guard_thunk().

◆ botan_tpm2_ctx_init()

int botan_tpm2_ctx_init ( botan_tpm2_ctx_t * ctx_out,
const char * tcti_nameconf )

Initialize a TPM2 context

Parameters
ctx_outoutput TPM2 context
tcti_nameconfTCTI config (may be nullptr)
Returns
0 on success

Definition at line 74 of file ffi_tpm2.cpp.

74 {
75#if defined(BOTAN_HAS_TPM2)
76 return ffi_guard_thunk(__func__, [=]() -> int {
77 if(ctx_out == nullptr) {
79 }
80 auto ctx = std::make_unique<botan_tpm2_ctx_wrapper>();
81
82 auto tcti = [=]() -> std::optional<std::string> {
83 if(tcti_nameconf == nullptr) {
84 return {};
85 } else {
86 return std::string(tcti_nameconf);
87 }
88 }();
89
90 ctx->ctx = Botan::TPM2::Context::create(std::move(tcti));
91 *ctx_out = new botan_tpm2_ctx_struct(std::move(ctx));
92 return BOTAN_FFI_SUCCESS;
93 });
94#else
95 BOTAN_UNUSED(ctx_out, tcti_nameconf);
97#endif
98}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan::TPM2::Context::create(), and Botan_FFI::ffi_guard_thunk().

◆ botan_tpm2_ctx_init_ex()

int botan_tpm2_ctx_init_ex ( botan_tpm2_ctx_t * ctx_out,
const char * tcti_name,
const char * tcti_conf )

Initialize a TPM2 context

Parameters
ctx_outoutput TPM2 context
tcti_nameTCTI name (may be nullptr)
tcti_confTCTI config (may be nullptr)
Returns
0 on success

Definition at line 100 of file ffi_tpm2.cpp.

100 {
101#if defined(BOTAN_HAS_TPM2)
102 return ffi_guard_thunk(__func__, [=]() -> int {
103 if(ctx_out == nullptr) {
105 }
106 auto ctx = std::make_unique<botan_tpm2_ctx_wrapper>();
107
108 auto tcti_name_str = [=]() -> std::optional<std::string> {
109 if(tcti_name == nullptr) {
110 return {};
111 } else {
112 return std::string(tcti_name);
113 }
114 }();
115
116 auto tcti_conf_str = [=]() -> std::optional<std::string> {
117 if(tcti_conf == nullptr) {
118 return {};
119 } else {
120 return std::string(tcti_conf);
121 }
122 }();
123
124 ctx->ctx = Botan::TPM2::Context::create(std::move(tcti_name_str), std::move(tcti_conf_str));
125 *ctx_out = new botan_tpm2_ctx_struct(std::move(ctx));
126 return BOTAN_FFI_SUCCESS;
127 });
128#else
129 BOTAN_UNUSED(ctx_out, tcti_name, tcti_conf);
131#endif
132}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan::TPM2::Context::create(), and Botan_FFI::ffi_guard_thunk().

◆ botan_tpm2_enable_crypto_backend()

int botan_tpm2_enable_crypto_backend ( botan_tpm2_crypto_backend_state_t * cbs_out,
struct ESYS_CONTEXT * esys_ctx,
botan_rng_t rng )

Use this if you just need Botan's crypto backend but do not want to wrap any other ESYS functionality using Botan's TPM2 wrapper. A Crypto Backend State is created that the user needs to keep alive for as long as the crypto backend is used and needs to be destroyed after. Note that the provided rng should not be dependent on the TPM and the caller must ensure that it remains usable for the lifetime of the esys_ctx.

Parameters
cbs_outTo be created Crypto Backend State
esys_ctxTPM2 context
rngrandom number generator to be used by the crypto backend

Definition at line 184 of file ffi_tpm2.cpp.

186 {
187#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
188 return ffi_guard_thunk(__func__, [=]() -> int {
189 if(cbs_out == nullptr || esys_ctx == nullptr) {
191 }
192
194
195 // Here, we just need to trust the user that they keep the passed-in RNG
196 // instance intact for the lifetime of the context.
197 std::shared_ptr<Botan::RandomNumberGenerator> rng_ptr(&rng_ref, [](auto*) {});
198 *cbs_out = new botan_tpm2_crypto_backend_state_struct(Botan::TPM2::use_botan_crypto_backend(esys_ctx, rng_ptr));
199 return BOTAN_FFI_SUCCESS;
200 });
201#else
202 BOTAN_UNUSED(cbs_out, esys_ctx, rng);
204#endif
205}
std::unique_ptr< CryptoCallbackState > use_botan_crypto_backend(ESYS_CONTEXT *context, const std::shared_ptr< Botan::RandomNumberGenerator > &rng)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::TPM2::use_botan_crypto_backend().

◆ botan_tpm2_rng_init()

int botan_tpm2_rng_init ( botan_rng_t * rng_out,
botan_tpm2_ctx_t ctx,
botan_tpm2_session_t s1,
botan_tpm2_session_t s2,
botan_tpm2_session_t s3 )

Initialize a random number generator object via TPM2

Parameters
rng_outrng object to create
ctxTPM2 context
s1the first session to use (optional, may be nullptr)
s2the second session to use (optional, may be nullptr)
s3the third session to use (optional, may be nullptr)

Definition at line 216 of file ffi_tpm2.cpp.

220 {
221#if defined(BOTAN_HAS_TPM2)
222 return BOTAN_FFI_VISIT(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int {
223 if(rng_out == nullptr) {
225 }
226
227 *rng_out = new botan_rng_struct(
228 std::make_unique<Botan::TPM2::RandomNumberGenerator>(ctx_wrapper.ctx, sessions(s1, s2, s3)));
229 return BOTAN_FFI_SUCCESS;
230 });
231#else
232 BOTAN_UNUSED(rng_out, ctx, s1, s2, s3);
234#endif
235}

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

◆ botan_tpm2_session_destroy()

int botan_tpm2_session_destroy ( botan_tpm2_session_t session)

Create an unauthenticated session for use with TPM2

Parameters
sessionthe session object to destroy

Definition at line 255 of file ffi_tpm2.cpp.

255 {
256#if defined(BOTAN_HAS_TPM2)
257 return BOTAN_FFI_CHECKED_DELETE(session);
258#else
259 BOTAN_UNUSED(session);
261#endif
262}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_tpm2_supports_crypto_backend()

int botan_tpm2_supports_crypto_backend ( )

Checks if Botan's TSS2 crypto backend can be used in this build

Returns
1 if the crypto backend can be enabled

Definition at line 66 of file ffi_tpm2.cpp.

66 {
67#if defined(BOTAN_HAS_TPM2)
69#else
70 return 0;
71#endif
72}
static bool supports_botan_crypto_backend() noexcept

References Botan::TPM2::Context::supports_botan_crypto_backend().

◆ botan_tpm2_unauthenticated_session_init()

int botan_tpm2_unauthenticated_session_init ( botan_tpm2_session_t * session_out,
botan_tpm2_ctx_t ctx )

Create an unauthenticated session for use with TPM2

Parameters
session_outthe session object to create
ctxTPM2 context

Definition at line 237 of file ffi_tpm2.cpp.

237 {
238#if defined(BOTAN_HAS_TPM2)
239 return BOTAN_FFI_VISIT(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int {
240 if(session_out == nullptr) {
242 }
243
244 auto session = std::make_unique<botan_tpm2_session_wrapper>();
245 session->session = Botan::TPM2::Session::unauthenticated_session(ctx_wrapper.ctx);
246 *session_out = new botan_tpm2_session_struct(std::move(session));
247 return BOTAN_FFI_SUCCESS;
248 });
249#else
250 BOTAN_UNUSED(session_out, ctx);
252#endif
253}
static std::shared_ptr< Session > unauthenticated_session(const std::shared_ptr< Context > &ctx, std::string_view sym_algo="CFB(AES-256)", std::string_view hash_algo="SHA-256")

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::TPM2::Session::unauthenticated_session().

◆ botan_version_datestamp()

uint32_t botan_version_datestamp ( void )

Return the date this version was released as an integer, or 0 if an unreleased version

Definition at line 304 of file ffi.cpp.

304 {
306}
uint32_t version_datestamp()
Definition version.cpp:75

References Botan::version_datestamp().

◆ botan_version_major()

uint32_t botan_version_major ( void )

Return the major version of the library

Definition at line 292 of file ffi.cpp.

292 {
293 return Botan::version_major();
294}
uint32_t version_major()
Definition version.cpp:82

References Botan::version_major().

◆ botan_version_minor()

uint32_t botan_version_minor ( void )

Return the minor version of the library

Definition at line 296 of file ffi.cpp.

296 {
297 return Botan::version_minor();
298}
uint32_t version_minor()
Definition version.cpp:86

References Botan::version_minor().

◆ botan_version_patch()

uint32_t botan_version_patch ( void )

Return the patch version of the library

Definition at line 300 of file ffi.cpp.

300 {
301 return Botan::version_patch();
302}
uint32_t version_patch()
Definition version.cpp:90

References Botan::version_patch().

◆ botan_version_string()

const char * botan_version_string ( void )

Return a free-form version string, e.g., 2.0.0

Definition at line 288 of file ffi.cpp.

288 {
289 return Botan::version_cstr();
290}
const char * version_cstr()
Definition version.cpp:33

References Botan::version_cstr().

◆ botan_x509_cert_allowed_usage()

int botan_x509_cert_allowed_usage ( botan_x509_cert_t cert,
unsigned int key_usage )

Definition at line 151 of file ffi_cert.cpp.

151 {
152#if defined(BOTAN_HAS_X509_CERTIFICATES)
153 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
154 const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
155 if(c.allowed_usage(k)) {
156 return BOTAN_FFI_SUCCESS;
157 }
158 return 1;
159 });
160#else
161 BOTAN_UNUSED(cert, key_usage);
163#endif
164}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_destroy()

int botan_x509_cert_destroy ( botan_x509_cert_t cert)
Returns
0 if success, error if invalid object handle

Definition at line 166 of file ffi_cert.cpp.

166 {
167#if defined(BOTAN_HAS_X509_CERTIFICATES)
168 return BOTAN_FFI_CHECKED_DELETE(cert);
169#else
170 BOTAN_UNUSED(cert);
172#endif
173}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_cert_dup()

int botan_x509_cert_dup ( botan_x509_cert_t * new_cert,
botan_x509_cert_t cert )

Definition at line 48 of file ffi_cert.cpp.

48 {
49 if(!cert_obj) {
51 }
52
53#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
54
55 return ffi_guard_thunk(__func__, [=]() -> int {
56 auto c = std::make_unique<Botan::X509_Certificate>(safe_get(cert));
57 *cert_obj = new botan_x509_cert_struct(std::move(c));
58 return BOTAN_FFI_SUCCESS;
59 });
60
61#else
62 BOTAN_UNUSED(cert);
64#endif
65}

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

◆ botan_x509_cert_get_authority_key_id()

int botan_x509_cert_get_authority_key_id ( botan_x509_cert_t cert,
uint8_t out[],
size_t * out_len )

Definition at line 231 of file ffi_cert.cpp.

231 {
232#if defined(BOTAN_HAS_X509_CERTIFICATES)
233 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.authority_key_id()); });
234#else
235 BOTAN_UNUSED(cert, out, out_len);
237#endif
238}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_vec_output().

◆ botan_x509_cert_get_fingerprint()

int botan_x509_cert_get_fingerprint ( botan_x509_cert_t cert,
const char * hash,
uint8_t out[],
size_t * out_len )

Definition at line 222 of file ffi_cert.cpp.

222 {
223#if defined(BOTAN_HAS_X509_CERTIFICATES)
224 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_str_output(out, out_len, c.fingerprint(hash)); });
225#else
226 BOTAN_UNUSED(cert, hash, out, out_len);
228#endif
229}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_str_output().

◆ botan_x509_cert_get_issuer_dn()

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 )

Definition at line 104 of file ffi_cert.cpp.

105 {
106#if defined(BOTAN_HAS_X509_CERTIFICATES)
107 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
108 auto issuer_info = c.issuer_info(key);
109 if(index < issuer_info.size()) {
110 return write_str_output(out, out_len, c.issuer_info(key).at(index));
111 } else {
113 }
114 });
115#else
116 BOTAN_UNUSED(cert, key, index, out, out_len);
118#endif
119}

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

◆ botan_x509_cert_get_public_key()

int botan_x509_cert_get_public_key ( botan_x509_cert_t cert,
botan_pubkey_t * key )

Definition at line 85 of file ffi_cert.cpp.

85 {
86 if(key == nullptr) {
88 }
89
90 *key = nullptr;
91
92#if defined(BOTAN_HAS_X509_CERTIFICATES)
93 return ffi_guard_thunk(__func__, [=]() -> int {
94 auto public_key = safe_get(cert).subject_public_key();
95 *key = new botan_pubkey_struct(std::move(public_key));
96 return BOTAN_FFI_SUCCESS;
97 });
98#else
99 BOTAN_UNUSED(cert);
101#endif
102}

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

◆ botan_x509_cert_get_public_key_bits()

int botan_x509_cert_get_public_key_bits ( botan_x509_cert_t cert,
uint8_t out[],
size_t * out_len )

Definition at line 249 of file ffi_cert.cpp.

249 {
250 return copy_view_bin(out, out_len, botan_x509_cert_view_public_key_bits, cert);
251}
int botan_x509_cert_view_public_key_bits(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_cert.cpp:253

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

◆ botan_x509_cert_get_serial_number()

int botan_x509_cert_get_serial_number ( botan_x509_cert_t cert,
uint8_t out[],
size_t * out_len )

Definition at line 213 of file ffi_cert.cpp.

213 {
214#if defined(BOTAN_HAS_X509_CERTIFICATES)
215 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.serial_number()); });
216#else
217 BOTAN_UNUSED(cert, out, out_len);
219#endif
220}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_vec_output().

◆ botan_x509_cert_get_subject_dn()

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 )

Definition at line 121 of file ffi_cert.cpp.

122 {
123#if defined(BOTAN_HAS_X509_CERTIFICATES)
124 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
125 auto subject_info = c.subject_info(key);
126 if(index < subject_info.size()) {
127 return write_str_output(out, out_len, c.subject_info(key).at(index));
128 } else {
130 }
131 });
132#else
133 BOTAN_UNUSED(cert, key, index, out, out_len);
135#endif
136}

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

◆ botan_x509_cert_get_subject_key_id()

int botan_x509_cert_get_subject_key_id ( botan_x509_cert_t cert,
uint8_t out[],
size_t * out_len )

Definition at line 240 of file ffi_cert.cpp.

240 {
241#if defined(BOTAN_HAS_X509_CERTIFICATES)
242 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.subject_key_id()); });
243#else
244 BOTAN_UNUSED(cert, out, out_len);
246#endif
247}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_vec_output().

◆ botan_x509_cert_get_time_expires()

int botan_x509_cert_get_time_expires ( botan_x509_cert_t cert,
char out[],
size_t * out_len )

Definition at line 185 of file ffi_cert.cpp.

185 {
186#if defined(BOTAN_HAS_X509_CERTIFICATES)
187 return BOTAN_FFI_VISIT(cert,
188 [=](const auto& c) { return write_str_output(out, out_len, c.not_after().to_string()); });
189#else
190 BOTAN_UNUSED(cert, out, out_len);
192#endif
193}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_str_output().

◆ botan_x509_cert_get_time_starts()

int botan_x509_cert_get_time_starts ( botan_x509_cert_t cert,
char out[],
size_t * out_len )

Definition at line 175 of file ffi_cert.cpp.

175 {
176#if defined(BOTAN_HAS_X509_CERTIFICATES)
177 return BOTAN_FFI_VISIT(cert,
178 [=](const auto& c) { return write_str_output(out, out_len, c.not_before().to_string()); });
179#else
180 BOTAN_UNUSED(cert, out, out_len);
182#endif
183}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_str_output().

◆ botan_x509_cert_hostname_match()

int botan_x509_cert_hostname_match ( botan_x509_cert_t cert,
const char * hostname )

Check if the certificate matches the specified hostname via alternative name or CN match. RFC 5280 wildcards also supported.

Definition at line 263 of file ffi_cert.cpp.

263 {
264 if(hostname == nullptr) {
266 }
267
268#if defined(BOTAN_HAS_X509_CERTIFICATES)
269 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return c.matches_dns_name(hostname) ? 0 : -1; });
270#else
271 BOTAN_UNUSED(cert);
273#endif
274}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_load()

int botan_x509_cert_load ( botan_x509_cert_t * cert_obj,
const uint8_t cert[],
size_t cert_len )

Definition at line 67 of file ffi_cert.cpp.

67 {
68 if(!cert_obj || !cert_bits) {
70 }
71
72#if defined(BOTAN_HAS_X509_CERTIFICATES)
73 return ffi_guard_thunk(__func__, [=]() -> int {
74 Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
75 auto c = std::make_unique<Botan::X509_Certificate>(bits);
76 *cert_obj = new botan_x509_cert_struct(std::move(c));
77 return BOTAN_FFI_SUCCESS;
78 });
79#else
80 BOTAN_UNUSED(cert_bits_len);
82#endif
83}

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

◆ botan_x509_cert_load_file()

int botan_x509_cert_load_file ( botan_x509_cert_t * cert_obj,
const char * filename )

Definition at line 30 of file ffi_cert.cpp.

30 {
31 if(!cert_obj || !cert_path) {
33 }
34
35#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
36
37 return ffi_guard_thunk(__func__, [=]() -> int {
38 auto c = std::make_unique<Botan::X509_Certificate>(cert_path);
39 *cert_obj = new botan_x509_cert_struct(std::move(c));
40 return BOTAN_FFI_SUCCESS;
41 });
42
43#else
45#endif
46}

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

◆ botan_x509_cert_not_after()

int botan_x509_cert_not_after ( botan_x509_cert_t cert,
uint64_t * time_since_epoch )

Definition at line 204 of file ffi_cert.cpp.

204 {
205#if defined(BOTAN_HAS_X509_CERTIFICATES)
206 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_after().time_since_epoch(); });
207#else
208 BOTAN_UNUSED(cert, time_since_epoch);
210#endif
211}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_not_before()

int botan_x509_cert_not_before ( botan_x509_cert_t cert,
uint64_t * time_since_epoch )

Definition at line 195 of file ffi_cert.cpp.

195 {
196#if defined(BOTAN_HAS_X509_CERTIFICATES)
197 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_before().time_since_epoch(); });
198#else
199 BOTAN_UNUSED(cert, time_since_epoch);
201#endif
202}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_to_string()

int botan_x509_cert_to_string ( botan_x509_cert_t cert,
char out[],
size_t * out_len )

Definition at line 138 of file ffi_cert.cpp.

138 {
139 return copy_view_str(reinterpret_cast<uint8_t*>(out), out_len, botan_x509_cert_view_as_string, cert);
140}
int botan_x509_cert_view_as_string(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_cert.cpp:142

References botan_x509_cert_view_as_string(), and Botan_FFI::copy_view_str().

◆ botan_x509_cert_validation_status()

const char * botan_x509_cert_validation_status ( int code)

Returns a pointer to a static character string explaining the status code, or else NULL if unknown.

Definition at line 343 of file ffi_cert.cpp.

343 {
344 if(code < 0) {
345 return nullptr;
346 }
347
348#if defined(BOTAN_HAS_X509_CERTIFICATES)
350 return Botan::to_string(sc);
351#else
352 return nullptr;
353#endif
354}
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13
Certificate_Status_Code
Definition pkix_enums.h:20

References Botan::to_string().

◆ botan_x509_cert_verify()

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 )

Returns 0 if the validation was successful, 1 if validation failed, and negative on error. A status code with details is written to *validation_result

Intermediates or trusted lists can be null Trusted path can be null

Definition at line 276 of file ffi_cert.cpp.

285 {
286 if(required_strength == 0) {
287 required_strength = 110;
288 }
289
290#if defined(BOTAN_HAS_X509_CERTIFICATES)
291 return ffi_guard_thunk(__func__, [=]() -> int {
292 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
294 const auto validation_time = reference_time == 0
295 ? std::chrono::system_clock::now()
296 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
297
298 std::vector<Botan::X509_Certificate> end_certs;
299 end_certs.push_back(safe_get(cert));
300 for(size_t i = 0; i != intermediates_len; ++i) {
301 end_certs.push_back(safe_get(intermediates[i]));
302 }
303
304 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
305 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
306 std::vector<Botan::Certificate_Store*> trusted_roots;
307
308 if(trusted_path && *trusted_path) {
309 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
310 trusted_roots.push_back(trusted_from_path.get());
311 }
312
313 if(trusted_len > 0) {
314 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
315 for(size_t i = 0; i != trusted_len; ++i) {
316 trusted_extra->add_certificate(safe_get(trusted[i]));
317 }
318 trusted_roots.push_back(trusted_extra.get());
319 }
320
321 Botan::Path_Validation_Restrictions restrictions(false, required_strength);
322
323 auto validation_result =
324 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
325
326 if(result_code) {
327 *result_code = static_cast<int>(validation_result.result());
328 }
329
330 if(validation_result.successful_validation()) {
331 return 0;
332 } else {
333 return 1;
334 }
335 });
336#else
337 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
338 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time);
340#endif
341}
Path_Validation_Result x509_path_validate(const std::vector< X509_Certificate > &end_certs, const Path_Validation_Restrictions &restrictions, const std::vector< Certificate_Store * > &trusted_roots, std::string_view hostname, Usage_Type usage, std::chrono::system_clock::time_point ref_time, std::chrono::milliseconds ocsp_timeout, const std::vector< std::optional< OCSP::Response > > &ocsp_resp)
Definition x509path.cpp:882
Usage_Type
Definition x509cert.h:22

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::UNSPECIFIED, and Botan::x509_path_validate().

◆ botan_x509_cert_verify_with_crl()

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 )

Different flavor of botan_x509_cert_verify, supports revocation lists. CRLs are passed as an array, same as intermediates and trusted CAs

Definition at line 417 of file ffi_cert.cpp.

428 {
429 if(required_strength == 0) {
430 required_strength = 110;
431 }
432
433#if defined(BOTAN_HAS_X509_CERTIFICATES)
434 return ffi_guard_thunk(__func__, [=]() -> int {
435 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
437 const auto validation_time = reference_time == 0
438 ? std::chrono::system_clock::now()
439 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
440
441 std::vector<Botan::X509_Certificate> end_certs;
442 end_certs.push_back(safe_get(cert));
443 for(size_t i = 0; i != intermediates_len; ++i) {
444 end_certs.push_back(safe_get(intermediates[i]));
445 }
446
447 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
448 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
449 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_crls;
450 std::vector<Botan::Certificate_Store*> trusted_roots;
451
452 if(trusted_path && *trusted_path) {
453 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
454 trusted_roots.push_back(trusted_from_path.get());
455 }
456
457 if(trusted_len > 0) {
458 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
459 for(size_t i = 0; i != trusted_len; ++i) {
460 trusted_extra->add_certificate(safe_get(trusted[i]));
461 }
462 trusted_roots.push_back(trusted_extra.get());
463 }
464
465 if(crls_len > 0) {
466 trusted_crls = std::make_unique<Botan::Certificate_Store_In_Memory>();
467 for(size_t i = 0; i != crls_len; ++i) {
468 trusted_crls->add_crl(safe_get(crls[i]));
469 }
470 trusted_roots.push_back(trusted_crls.get());
471 }
472
473 Botan::Path_Validation_Restrictions restrictions(false, required_strength);
474
475 auto validation_result =
476 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
477
478 if(result_code) {
479 *result_code = static_cast<int>(validation_result.result());
480 }
481
482 if(validation_result.successful_validation()) {
483 return 0;
484 } else {
485 return 1;
486 }
487 });
488#else
489 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
490 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time, crls, crls_len);
492#endif
493}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::UNSPECIFIED, and Botan::x509_path_validate().

◆ botan_x509_cert_view_as_string()

int botan_x509_cert_view_as_string ( botan_x509_cert_t cert,
botan_view_ctx ctx,
botan_view_str_fn view )

Definition at line 142 of file ffi_cert.cpp.

142 {
143#if defined(BOTAN_HAS_X509_CERTIFICATES)
144 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return invoke_view_callback(view, ctx, c.to_string()); });
145#else
146 BOTAN_UNUSED(cert, ctx, view);
148#endif
149}

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

Referenced by botan_x509_cert_to_string().

◆ botan_x509_cert_view_public_key_bits()

int botan_x509_cert_view_public_key_bits ( botan_x509_cert_t cert,
botan_view_ctx ctx,
botan_view_bin_fn view )

Definition at line 253 of file ffi_cert.cpp.

253 {
254#if defined(BOTAN_HAS_X509_CERTIFICATES)
255 return BOTAN_FFI_VISIT(cert,
256 [=](const auto& c) { return invoke_view_callback(view, ctx, c.subject_public_key_bits()); });
257#else
258 BOTAN_UNUSED(cert, ctx, view);
260#endif
261}

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

Referenced by botan_x509_cert_get_public_key_bits().

◆ botan_x509_crl_destroy()

int botan_x509_crl_destroy ( botan_x509_crl_t crl)

Definition at line 398 of file ffi_cert.cpp.

398 {
399#if defined(BOTAN_HAS_X509_CERTIFICATES)
400 return BOTAN_FFI_CHECKED_DELETE(crl);
401#else
402 BOTAN_UNUSED(crl);
404#endif
405}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_crl_load()

int botan_x509_crl_load ( botan_x509_crl_t * crl_obj,
const uint8_t crl_bits[],
size_t crl_bits_len )

Definition at line 380 of file ffi_cert.cpp.

380 {
381 if(!crl_obj || !crl_bits) {
383 }
384
385#if defined(BOTAN_HAS_X509_CERTIFICATES)
386 return ffi_guard_thunk(__func__, [=]() -> int {
387 Botan::DataSource_Memory bits(crl_bits, crl_bits_len);
388 auto c = std::make_unique<Botan::X509_CRL>(bits);
389 *crl_obj = new botan_x509_crl_struct(std::move(c));
390 return BOTAN_FFI_SUCCESS;
391 });
392#else
393 BOTAN_UNUSED(crl_bits_len);
395#endif
396}

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

◆ botan_x509_crl_load_file()

int botan_x509_crl_load_file ( botan_x509_crl_t * crl_obj,
const char * crl_path )

Definition at line 362 of file ffi_cert.cpp.

362 {
363 if(!crl_obj || !crl_path) {
365 }
366
367#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
368
369 return ffi_guard_thunk(__func__, [=]() -> int {
370 auto c = std::make_unique<Botan::X509_CRL>(crl_path);
371 *crl_obj = new botan_x509_crl_struct(std::move(c));
372 return BOTAN_FFI_SUCCESS;
373 });
374
375#else
377#endif
378}

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

◆ botan_x509_is_revoked()

int botan_x509_is_revoked ( botan_x509_crl_t crl,
botan_x509_cert_t cert )

Given a CRL and a certificate, check if the certificate is revoked on that particular CRL

Definition at line 407 of file ffi_cert.cpp.

407 {
408#if defined(BOTAN_HAS_X509_CERTIFICATES)
409 return BOTAN_FFI_VISIT(crl, [=](const auto& c) { return c.is_revoked(safe_get(cert)) ? 0 : -1; });
410#else
411 BOTAN_UNUSED(cert);
412 BOTAN_UNUSED(crl);
414#endif
415}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::safe_get().

◆ botan_zfec_decode()

int botan_zfec_decode ( size_t K,
size_t N,
const size_t * indexes,
uint8_t *const * inputs,
size_t shareSize,
uint8_t ** outputs )

Decode some previously encoded shares using certain ZFEC parameters.

Parameters
Kthe number of shares needed for recovery
Nthe total number of shares
indexesThe index into the encoder's outputs for the corresponding element of the inputs array. Must be of length K.
inputsK previously encoded shares to decode
shareSizethe length in bytes of each input
outputsAn out parameter pointing to a fully allocated array of size [K][shareSize]. For all k in range, a decoded block will written to the memory starting at outputs[k][0].
Returns
0 on success, negative on failure

Definition at line 31 of file ffi_zfec.cpp.

32 {
33#if defined(BOTAN_HAS_ZFEC)
34 return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
35 std::map<size_t, const uint8_t*> shares;
36 for(size_t k = 0; k < K; ++k) {
37 shares.insert(std::pair<size_t, const uint8_t*>(indexes[k], inputs[k]));
38 }
40 shares, shareSize, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
41 std::copy(block, block + blockSize, outputs[index]);
42 });
43 return BOTAN_FFI_SUCCESS;
44 });
45#else
46 BOTAN_UNUSED(K, N, indexes, inputs, shareSize, outputs);
48#endif
49}
void decode_shares(const std::map< size_t, const uint8_t * > &shares, size_t share_size, const output_cb_t &output_cb) const
Definition zfec.cpp:442
size_t blockSize

References blockSize, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan::ZFEC::decode_shares(), and Botan_FFI::ffi_guard_thunk().

◆ botan_zfec_encode()

int botan_zfec_encode ( size_t K,
size_t N,
const uint8_t * input,
size_t size,
uint8_t ** outputs )

ZFEC Encode some bytes with certain ZFEC parameters.

Parameters
Kthe number of shares needed for recovery
Nthe number of shares generated
inputthe data to FEC
sizethe length in bytes of input, which must be a multiple of K
outputsAn out parameter pointing to a fully allocated array of size [N][size / K]. For all n in range, an encoded block will be written to the memory starting at outputs[n][0].
Returns
0 on success, negative on failure

Definition at line 17 of file ffi_zfec.cpp.

17 {
18#if defined(BOTAN_HAS_ZFEC)
19 return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
20 Botan::ZFEC(K, N).encode(input, size, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
21 std::copy(block, block + blockSize, outputs[index]);
22 });
23 return BOTAN_FFI_SUCCESS;
24 });
25#else
26 BOTAN_UNUSED(K, N, input, size, outputs);
28#endif
29}
void encode(const uint8_t input[], size_t size, const output_cb_t &output_cb) const
Definition zfec.cpp:399

References blockSize, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan::ZFEC::encode(), and Botan_FFI::ffi_guard_thunk().