Botan 3.9.0
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   20250506
#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_asn1_oid_struct * botan_asn1_oid_t
typedef struct botan_block_cipher_struct * botan_block_cipher_t
typedef struct botan_cipher_struct * botan_cipher_t
typedef struct botan_ec_group_struct * botan_ec_group_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_NO_VALUE = -3 , 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 cipher, 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 cipher, 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)
int botan_ec_group_destroy (botan_ec_group_t ec_group)
int botan_ec_group_equal (botan_ec_group_t curve1, botan_ec_group_t curve2)
int botan_ec_group_from_ber (botan_ec_group_t *ec_group, const uint8_t *ber, size_t ber_len)
int botan_ec_group_from_name (botan_ec_group_t *ec_group, const char *name)
int botan_ec_group_from_oid (botan_ec_group_t *ec_group, botan_asn1_oid_t oid)
int botan_ec_group_from_params (botan_ec_group_t *ec_group, botan_asn1_oid_t oid, botan_mp_t p, botan_mp_t a, botan_mp_t b, botan_mp_t base_x, botan_mp_t base_y, botan_mp_t order)
int botan_ec_group_from_pem (botan_ec_group_t *ec_group, const char *pem)
int botan_ec_group_get_a (botan_mp_t *a, botan_ec_group_t ec_group)
int botan_ec_group_get_b (botan_mp_t *b, botan_ec_group_t ec_group)
int botan_ec_group_get_curve_oid (botan_asn1_oid_t *oid, botan_ec_group_t ec_group)
int botan_ec_group_get_g_x (botan_mp_t *g_x, botan_ec_group_t ec_group)
int botan_ec_group_get_g_y (botan_mp_t *g_y, botan_ec_group_t ec_group)
int botan_ec_group_get_order (botan_mp_t *order, botan_ec_group_t ec_group)
int botan_ec_group_get_p (botan_mp_t *p, botan_ec_group_t ec_group)
int botan_ec_group_supports_application_specific_group (int *out)
int botan_ec_group_supports_named_group (const char *name, int *out)
int botan_ec_group_view_der (botan_ec_group_t ec_group, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_group_view_pem (botan_ec_group_t ec_group, botan_view_ctx ctx, botan_view_str_fn view)
int botan_ec_privkey_create (botan_privkey_t *key, const char *algo_name, botan_ec_group_t ec_group, botan_rng_t rng)
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_oid_cmp (int *result, botan_asn1_oid_t a, botan_asn1_oid_t b)
int botan_oid_destroy (botan_asn1_oid_t oid)
int botan_oid_equal (botan_asn1_oid_t a, botan_asn1_oid_t b)
int botan_oid_from_string (botan_asn1_oid_t *oid, const char *oid_str)
int botan_oid_register (botan_asn1_oid_t oid, const char *name)
int botan_oid_view_name (botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)
int botan_oid_view_string (botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)
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_oid (botan_asn1_oid_t *oid, botan_privkey_t key)
int botan_privkey_remaining_operations (botan_privkey_t key, uint64_t *out)
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_stateful_operation (botan_privkey_t key, int *out)
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_oid (botan_asn1_oid_t *oid, botan_pubkey_t key)
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 (void)
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 1327 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 561 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_ENCRYPT

#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0

Definition at line 560 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 559 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 654 of file ffi.h.

Referenced by botan_cipher_update().

◆ BOTAN_FFI_API_VERSION

#define BOTAN_FFI_API_VERSION   20250506

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

◆ BOTAN_FFI_DEPRECATED

#define BOTAN_FFI_DEPRECATED ( msg)

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

Referenced by botan_srp6_server_session_step1().

◆ BOTAN_FFI_HEX_LOWER_CASE

#define BOTAN_FFI_HEX_LOWER_CASE   1

Flag that can be provided to botan_hex_encode to request lower case hex

Definition at line 247 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 2359 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 1399 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_asn1_oid_t

typedef struct botan_asn1_oid_struct* botan_asn1_oid_t

Definition at line 1121 of file ffi.h.

◆ botan_block_cipher_t

typedef struct botan_block_cipher_struct* botan_block_cipher_t

Definition at line 855 of file ffi.h.

◆ botan_cipher_t

typedef struct botan_cipher_struct* botan_cipher_t

Definition at line 557 of file ffi.h.

◆ botan_ec_group_t

typedef struct botan_ec_group_struct* botan_ec_group_t

Definition at line 1170 of file ffi.h.

◆ botan_fpe_t

typedef struct botan_fpe_struct* botan_fpe_t

Format Preserving Encryption

Definition at line 2357 of file ffi.h.

◆ botan_hash_t

typedef struct botan_hash_struct* botan_hash_t

Definition at line 381 of file ffi.h.

◆ botan_hotp_t

typedef struct botan_hotp_struct* botan_hotp_t

HOTP

Definition at line 2285 of file ffi.h.

◆ botan_mac_t

typedef struct botan_mac_struct* botan_mac_t

Definition at line 461 of file ffi.h.

◆ botan_mp_t

typedef struct botan_mp_struct* botan_mp_t

Definition at line 921 of file ffi.h.

◆ botan_pk_op_decrypt_t

typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t

Definition at line 1922 of file ffi.h.

◆ botan_pk_op_encrypt_t

typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t

Definition at line 1898 of file ffi.h.

◆ botan_pk_op_ka_t

typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t

Definition at line 1984 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 2043 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 2013 of file ffi.h.

◆ botan_pk_op_sign_t

typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t

Definition at line 1945 of file ffi.h.

◆ botan_pk_op_verify_t

typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t

Definition at line 1965 of file ffi.h.

◆ botan_privkey_t

typedef struct botan_privkey_struct* botan_privkey_t

Definition at line 1304 of file ffi.h.

◆ botan_pubkey_t

typedef struct botan_pubkey_struct* botan_pubkey_t

Definition at line 1537 of file ffi.h.

◆ botan_rng_t

typedef struct botan_rng_struct* botan_rng_t

RNG type

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

◆ botan_totp_t

typedef struct botan_totp_struct* botan_totp_t

TOTP

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

◆ botan_tpm2_ctx_t

typedef struct botan_tpm2_ctx_struct* botan_tpm2_ctx_t

TPM2 context

Definition at line 2538 of file ffi.h.

◆ botan_tpm2_session_t

typedef struct botan_tpm2_session_struct* botan_tpm2_session_t

TPM2 session

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

◆ botan_view_ctx

typedef void* botan_view_ctx

The application provided context for a view function

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

◆ botan_x509_cert_t

typedef struct botan_x509_cert_struct* botan_x509_cert_t

Definition at line 2107 of file ffi.h.

◆ botan_x509_crl_t

typedef struct botan_x509_crl_struct* botan_x509_crl_t

Definition at line 2208 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_NO_VALUE 
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 114 of file ffi.h.

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

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

2157 {
2158 NO_CONSTRAINTS = 0,
2159 DIGITAL_SIGNATURE = 32768,
2160 NON_REPUDIATION = 16384,
2161 KEY_ENCIPHERMENT = 8192,
2162 DATA_ENCIPHERMENT = 4096,
2163 KEY_AGREEMENT = 2048,
2164 KEY_CERT_SIGN = 1024,
2165 CRL_SIGN = 512,
2166 ENCIPHER_ONLY = 256,
2167 DECIPHER_ONLY = 128
2168};
@ KEY_ENCIPHERMENT
Definition ffi.h:2161
@ NO_CONSTRAINTS
Definition ffi.h:2158
@ CRL_SIGN
Definition ffi.h:2165
@ DIGITAL_SIGNATURE
Definition ffi.h:2159
@ KEY_AGREEMENT
Definition ffi.h:2163
@ DATA_ENCIPHERMENT
Definition ffi.h:2162
@ KEY_CERT_SIGN
Definition ffi.h:2164
@ ENCIPHER_ONLY
Definition ffi.h:2166
@ NON_REPUDIATION
Definition ffi.h:2160
@ DECIPHER_ONLY
Definition ffi.h:2167

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

338 {
339 return ffi_guard_thunk(__func__, [=]() -> int {
340 if(*out_len < Botan::base64_decode_max_output(in_len)) {
341 *out_len = Botan::base64_decode_max_output(in_len);
343 }
344
345 *out_len = Botan::base64_decode(out, std::string(base64_str, in_len));
346 return BOTAN_FFI_SUCCESS;
347 });
348}
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95
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

Parameters
xthe input data
lenthe length of x
outthe output buffer
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::string base64 = Botan::base64_encode(in, len);
334 return Botan_FFI::write_str_output(out, out_len, base64);
335 });
336}
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:251
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$...

TOD(Botan4) this should use char for the type of out

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 // TODO(Botan4) change the type of out and remove this cast
181 return write_str_output(reinterpret_cast<char*>(out), out_len, bcrypt);
182 });
183#else
184 BOTAN_UNUSED(out, out_len, pass, rng_obj, wf, flags);
186#endif
187}
#define BOTAN_UNUSED
Definition assert.h:144
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:79
std::string generate_bcrypt(std::string_view pass, RandomNumberGenerator &rng, uint16_t work_factor, char version)
Definition bcrypt.cpp:145

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 189 of file ffi_kdf.cpp.

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

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 60 of file ffi_block.cpp.

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

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 42 of file ffi_block.cpp.

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

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 71 of file ffi_block.cpp.

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

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 38 of file ffi_block.cpp.

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

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 64 of file ffi_block.cpp.

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

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 86 of file ffi_block.cpp.

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

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 return ffi_new_object(bc, std::move(cipher));
32 });
33}
static std::unique_ptr< BlockCipher > create(std::string_view algo_spec, std::string_view provider="")
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:178

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

◆ 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 78 of file ffi_block.cpp.

78 {
79 if(name_len == nullptr) {
81 }
82
83 return BOTAN_FFI_VISIT(cipher, [=](const auto& bc) { return write_str_output(name, name_len, bc.name()); });
84}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, 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 49 of file ffi_block.cpp.

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

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

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

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

113 {
114 return BOTAN_FFI_CHECKED_DELETE(cipher);
115}

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

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

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

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

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

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

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

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

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

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

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 return ffi_new_object(cipher, std::move(mode), update_size, ideal_update_size);
110 });
111}
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:560
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
Definition ffi.h:559
Flags flags(Flag flags)
Definition p11.h:848

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

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

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

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

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

References BOTAN_FFI_VISIT, 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 125 of file ffi_cipher.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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::copy_mem(), 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 297 of file ffi_cipher.cpp.

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

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

301 {
302 auto same = Botan::CT::is_equal(x, y, len);
303 // Return 0 if same or -1 otherwise
304 return static_cast<int>(same.select(1, 0)) - 1;
305}
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:826

References Botan::CT::is_equal().

Referenced by botan_same_mem().

◆ botan_ec_group_destroy()

int botan_ec_group_destroy ( botan_ec_group_t ec_group)
Returns
negative number on error, or zero on success

Definition at line 20 of file ffi_ec.cpp.

20 {
21 return BOTAN_FFI_CHECKED_DELETE(ec_group);
22}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_ec_group_equal()

int botan_ec_group_equal ( botan_ec_group_t curve1,
botan_ec_group_t curve2 )
Returns
0 if curve1 != curve2
1 if curve1 == curve2
negative number on error

Definition at line 185 of file ffi_ec.cpp.

185 {
186 return BOTAN_FFI_VISIT(curve1_w, [=](const auto& curve1) -> int { return curve1 == safe_get(curve2_w); });
187}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_ec_group_from_ber()

int botan_ec_group_from_ber ( botan_ec_group_t * ec_group,
const uint8_t * ber,
size_t ber_len )

Decode a BER encoded ECC domain parameter set

Parameters
ec_groupthe new object will be placed here
berencoding
ber_lensize of the encoding in bytes
Returns
negative number on error, or zero on success

Definition at line 71 of file ffi_ec.cpp.

71 {
72 return ffi_guard_thunk(__func__, [=]() -> int {
73 if(ec_group == nullptr || ber == nullptr) {
75 }
76
77 Botan::EC_Group group(ber, ber_len);
78
79 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
80 return ffi_new_object(ec_group, std::move(group_ptr));
81 });
82}

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

◆ botan_ec_group_from_name()

int botan_ec_group_from_name ( botan_ec_group_t * ec_group,
const char * name )

Initialize an EC Group from a common group name (eg "secp256r1")

Parameters
ec_groupthe new object will be placed here
namea known group name
Returns
negative number on error, or zero on success

Definition at line 110 of file ffi_ec.cpp.

110 {
111 return ffi_guard_thunk(__func__, [=]() -> int {
112 if(ec_group == nullptr || name == nullptr) {
114 }
115
117
118 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
119 return ffi_new_object(ec_group, std::move(group_ptr));
120 });
121}
static EC_Group from_name(std::string_view name)
Definition ec_group.cpp:384

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan::EC_Group::from_name().

◆ botan_ec_group_from_oid()

int botan_ec_group_from_oid ( botan_ec_group_t * ec_group,
botan_asn1_oid_t oid )

Initialize an EC Group from a group named by an object identifier

Parameters
ec_groupthe new object will be placed here
oida known OID
Returns
negative number on error, or zero on success

Definition at line 97 of file ffi_ec.cpp.

97 {
98 return ffi_guard_thunk(__func__, [=]() -> int {
99 if(ec_group == nullptr) {
101 }
102
104
105 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
106 return ffi_new_object(ec_group, std::move(group_ptr));
107 });
108}
static EC_Group from_OID(const OID &oid)
Definition ec_group.cpp:373

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), Botan::EC_Group::from_OID(), and Botan_FFI::safe_get().

◆ botan_ec_group_from_params()

int botan_ec_group_from_params ( botan_ec_group_t * ec_group,
botan_asn1_oid_t oid,
botan_mp_t p,
botan_mp_t a,
botan_mp_t b,
botan_mp_t base_x,
botan_mp_t base_y,
botan_mp_t order )

Create a new EC Group from parameters

Warning
use only elliptic curve parameters that you trust
Parameters
ec_groupthe new object will be placed here
pthe elliptic curve prime (at most 521 bits)
athe elliptic curve a param
bthe elliptic curve b param
base_xthe x coordinate of the group generator
base_ythe y coordinate of the group generator
orderthe order of the group
Returns
negative number on error, or zero on success

Definition at line 50 of file ffi_ec.cpp.

57 {
58 return ffi_guard_thunk(__func__, [=]() -> int {
59 if(ec_group == nullptr) {
61 }
62
63 Botan::EC_Group group(
64 safe_get(oid), safe_get(p), safe_get(a), safe_get(b), safe_get(base_x), safe_get(base_y), safe_get(order));
65
66 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
67 return ffi_new_object(ec_group, std::move(group_ptr));
68 });
69}

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

◆ botan_ec_group_from_pem()

int botan_ec_group_from_pem ( botan_ec_group_t * ec_group,
const char * pem )

Initialize an EC Group from the PEM/ASN.1 encoding

Parameters
ec_groupthe new object will be placed here
pemencoding
Returns
negative number on error, or zero on success

Definition at line 84 of file ffi_ec.cpp.

84 {
85 return ffi_guard_thunk(__func__, [=]() -> int {
86 if(ec_group == nullptr || pem == nullptr) {
88 }
89
91
92 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
93 return ffi_new_object(ec_group, std::move(group_ptr));
94 });
95}
static EC_Group from_PEM(std::string_view pem)
Definition ec_group.cpp:427

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan::EC_Group::from_PEM().

◆ botan_ec_group_get_a()

int botan_ec_group_get_a ( botan_mp_t * a,
botan_ec_group_t ec_group )

Get the a parameter of the elliptic curve equation

Definition at line 162 of file ffi_ec.cpp.

162 {
163 return botan_ec_group_get_component(a, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_a(); });
164}

◆ botan_ec_group_get_b()

int botan_ec_group_get_b ( botan_mp_t * b,
botan_ec_group_t ec_group )

Get the b parameter of the elliptic curve equation

Definition at line 166 of file ffi_ec.cpp.

166 {
167 return botan_ec_group_get_component(b, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_b(); });
168}

◆ botan_ec_group_get_curve_oid()

int botan_ec_group_get_curve_oid ( botan_asn1_oid_t * oid,
botan_ec_group_t ec_group )

Get the curve OID of an EC Group

Definition at line 134 of file ffi_ec.cpp.

134 {
135 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
136 if(oid == nullptr) {
138 }
139 auto oid_ptr = std::make_unique<Botan::OID>(g.get_curve_oid());
140 return ffi_new_object(oid, std::move(oid_ptr));
141 });
142}

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

◆ botan_ec_group_get_g_x()

int botan_ec_group_get_g_x ( botan_mp_t * g_x,
botan_ec_group_t ec_group )

Get the x coordinate of the base point

Definition at line 170 of file ffi_ec.cpp.

170 {
171 return botan_ec_group_get_component(
172 g_x, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_g_x(); });
173}

◆ botan_ec_group_get_g_y()

int botan_ec_group_get_g_y ( botan_mp_t * g_y,
botan_ec_group_t ec_group )

Get the y coordinate of the base point

Definition at line 175 of file ffi_ec.cpp.

175 {
176 return botan_ec_group_get_component(
177 g_y, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_g_y(); });
178}

◆ botan_ec_group_get_order()

int botan_ec_group_get_order ( botan_mp_t * order,
botan_ec_group_t ec_group )

Get the order of the base point

Definition at line 180 of file ffi_ec.cpp.

180 {
181 return botan_ec_group_get_component(
182 order, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_order(); });
183}

◆ botan_ec_group_get_p()

int botan_ec_group_get_p ( botan_mp_t * p,
botan_ec_group_t ec_group )

Get the prime modulus of the field

Definition at line 158 of file ffi_ec.cpp.

158 {
159 return botan_ec_group_get_component(p, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_p(); });
160}

◆ botan_ec_group_supports_application_specific_group()

int botan_ec_group_supports_application_specific_group ( int * out)

Checks if in this build configuration it is possible to register an application specific elliptic curve and sets

Parameters
outto 1 if so, 0 otherwise
Returns
0 on success, a negative value on failure

Definition at line 24 of file ffi_ec.cpp.

24 {
25 if(out == nullptr) {
27 }
29 *out = 1;
30 } else {
31 *out = 0;
32 }
33 return BOTAN_FFI_SUCCESS;
34}
static bool supports_application_specific_group()
Definition ec_group.cpp:355

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and Botan::EC_Group::supports_application_specific_group().

◆ botan_ec_group_supports_named_group()

int botan_ec_group_supports_named_group ( const char * name,
int * out )

Checks if in this build configuration botan_ec_group_from_name(group_ptr, name) will succeed and sets

Parameters
outto 1 if so, 0 otherwise.
Returns
negative number on error, or zero on success

Definition at line 36 of file ffi_ec.cpp.

36 {
37 return ffi_guard_thunk(__func__, [=]() -> int {
38 if(name == nullptr || out == nullptr) {
40 }
42 *out = 1;
43 } else {
44 *out = 0;
45 }
46 return BOTAN_FFI_SUCCESS;
47 });
48}
static bool supports_named_group(std::string_view name)
Definition ec_group.cpp:350

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan::EC_Group::supports_named_group().

◆ botan_ec_group_view_der()

int botan_ec_group_view_der ( botan_ec_group_t ec_group,
botan_view_ctx ctx,
botan_view_bin_fn view )

View an EC Group in DER encoding

Definition at line 123 of file ffi_ec.cpp.

123 {
124 return BOTAN_FFI_VISIT(ec_group,
125 [=](const auto& g) -> int { return invoke_view_callback(view, ctx, g.DER_encode()); });
126}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:187

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_group_view_pem()

int botan_ec_group_view_pem ( botan_ec_group_t ec_group,
botan_view_ctx ctx,
botan_view_str_fn view )

View an EC Group in PEM encoding

Definition at line 128 of file ffi_ec.cpp.

128 {
129 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
130 return invoke_view_callback(view, ctx, g.PEM_encode(Botan::EC_Group_Encoding::NamedCurve));
131 });
132}

References BOTAN_FFI_VISIT, Botan_FFI::invoke_view_callback(), and Botan::NamedCurve.

◆ botan_ec_privkey_create()

int botan_ec_privkey_create ( botan_privkey_t * key,
const char * algo_name,
botan_ec_group_t ec_group,
botan_rng_t rng )

Create a new ec private key

Parameters
keythe new object will be placed here
algo_namesomething like "ECDSA" or "ECDH"
ec_groupa (possibly application specific) elliptic curve
rnga random number generator

Definition at line 60 of file ffi_pkey.cpp.

63 {
64 // TODO(Botan4) remove this implicit algorithm choice and reject nullptr algo_name
65 if(algo_name == nullptr) {
66 return botan_ec_privkey_create(key_obj, "ECDSA", ec_group_obj, rng_obj);
67 }
68
69 return ffi_guard_thunk(__func__, [=]() -> int {
70 if(key_obj == nullptr) {
72 }
73 *key_obj = nullptr;
74
75 Botan::EC_Group ec_group = safe_get(ec_group_obj);
77
78 if(auto key = Botan::create_ec_private_key(algo_name, ec_group, rng)) {
79 return ffi_new_object(key_obj, std::move(key));
80 } else {
82 }
83 });
84}
int botan_ec_privkey_create(botan_privkey_t *key_obj, const char *algo_name, botan_ec_group_t ec_group_obj, botan_rng_t rng_obj)
Definition ffi_pkey.cpp:60
std::unique_ptr< Private_Key > create_ec_private_key(std::string_view alg_name, const EC_Group &ec_group, RandomNumberGenerator &rng)
Definition pk_algs.cpp:442

References botan_ec_privkey_create(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, Botan::create_ec_private_key(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

Referenced by botan_ec_privkey_create().

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

143 {
144 switch(err) {
146 return "OK";
147
149 return "Invalid verifier";
150
152 return "Invalid input";
153
155 return "Invalid authentication code";
156
158 return "No value available";
159
161 return "Insufficient buffer space";
162
164 return "String conversion error";
165
167 return "Exception thrown";
168
170 return "Out of memory";
171
173 return "Error while calling system API";
174
176 return "Internal error";
177
179 return "Bad flag";
180
182 return "Null pointer argument";
183
185 return "Bad parameter";
186
188 return "Key not set on object";
189
191 return "Invalid key length";
192
194 return "Invalid object state";
195
197 return "Not implemented";
198
200 return "Invalid object handle";
201
203 return "TLS error";
204
206 return "HTTP error";
207
209 default:
210 return "Unknown error";
211 }
212}

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_NO_VALUE, 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 139 of file ffi.cpp.

139 {
140 return g_last_exception_what.c_str();
141}

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

217 {
218 return BOTAN_HAS_FFI;
219}
#define BOTAN_HAS_FFI
Definition build.h:196

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

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

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 77 of file ffi_fpe.cpp.

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

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 55 of file ffi_fpe.cpp.

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

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 64 of file ffi_fpe.cpp.

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

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) != 0;
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 return ffi_new_object(fpe, std::move(fpe_obj));
48 });
49#else
50 BOTAN_UNUSED(fpe, n, key, key_len, rounds, flags);
52#endif
53}
#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE
Definition ffi.h:2359

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FPE_FLAG_FE1_COMPAT_MODE, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 79 of file ffi_hash.cpp.

79 {
80 return BOTAN_FFI_VISIT(source, [=](const auto& src) { return ffi_new_object(dest, src.copy_state()); });
81}

References BOTAN_FFI_VISIT, and Botan_FFI::ffi_new_object().

◆ 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 ffi_new_object(hash, 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(), Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

◆ 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 83 of file ffi_hash.cpp.

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

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, 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 324 of file ffi.cpp.

324 {
325 return ffi_guard_thunk(__func__, [=]() -> int {
326 const std::vector<uint8_t> bin = Botan::hex_decode(hex_str, in_len);
327 return Botan_FFI::write_vec_output(out, out_len, bin);
328 });
329}
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:247
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 316 of file ffi.cpp.

316 {
317 return ffi_guard_thunk(__func__, [=]() -> int {
318 const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
319 Botan::hex_encode(out, in, len, uppercase);
320 return BOTAN_FFI_SUCCESS;
321 });
322}
#define BOTAN_FFI_HEX_LOWER_CASE
Definition ffi.h:247
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 66 of file ffi_hotp.cpp.

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

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 43 of file ffi_hotp.cpp.

43 {
44#if defined(BOTAN_HAS_HOTP)
45 return BOTAN_FFI_CHECKED_DELETE(hotp);
46#else
47 BOTAN_UNUSED(hotp);
49#endif
50}

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 52 of file ffi_hotp.cpp.

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

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 return ffi_new_object(hotp, std::move(otp));
36 });
37#else
38 BOTAN_UNUSED(hotp, key, key_len, hash_algo, digits);
40#endif
41}

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

◆ 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:204

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 52 of file ffi_mac.cpp.

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

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 36 of file ffi_mac.cpp.

36 {
37 return BOTAN_FFI_CHECKED_DELETE(mac);
38}

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 60 of file ffi_mac.cpp.

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

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 68 of file ffi_mac.cpp.

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

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(any_null_pointers(mac, mac_name)) {
22 }
23
24 if(flags != 0) {
26 }
27
28 if(auto m = Botan::MessageAuthenticationCode::create(mac_name)) {
29 return ffi_new_object(mac, std::move(m));
30 } else {
32 }
33 });
34}
static std::unique_ptr< MessageAuthenticationCode > create(std::string_view algo_spec, std::string_view provider="")
Definition mac.cpp:51
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:23

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, Botan::MessageAuthenticationCode::create(), Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

◆ 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 64 of file ffi_mac.cpp.

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

References BOTAN_FFI_VISIT, 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 48 of file ffi_mac.cpp.

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

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 40 of file ffi_mac.cpp.

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

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 44 of file ffi_mac.cpp.

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

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 56 of file ffi_mac.cpp.

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

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

1383 {
1384 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
1386}

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

1396 {
1397 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1399}

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

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

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

138 {
139 return BOTAN_FFI_VISIT(result, [=](auto& res) {
140 if(result == x) {
141 res += static_cast<Botan::word>(y);
142 } else {
143 res = safe_get(x) + static_cast<Botan::word>(y);
144 }
145 });
146}
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word
Definition types.h:119

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

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

References BOTAN_FFI_VISIT.

◆ botan_mp_cmp()

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

Definition at line 192 of file ffi_mp.cpp.

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

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

114 {
115 return BOTAN_FFI_CHECKED_DELETE(mp);
116}

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

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

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

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

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

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

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

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

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

236 {
237 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = Botan::gcd(safe_get(x), safe_get(y)); });
238}
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 244 of file ffi_mp.cpp.

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

References BOTAN_FFI_VISIT.

◆ botan_mp_init()

int botan_mp_init ( botan_mp_t * mp)

Initialize an MPI

Definition at line 23 of file ffi_mp.cpp.

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

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

◆ botan_mp_is_even()

int botan_mp_is_even ( botan_mp_t mp)

Definition at line 188 of file ffi_mp.cpp.

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

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

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

References BOTAN_FFI_VISIT.

◆ botan_mp_is_odd()

int botan_mp_is_odd ( botan_mp_t mp)

Definition at line 184 of file ffi_mp.cpp.

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

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

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

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

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

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

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

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

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

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

214 {
215 return BOTAN_FFI_VISIT(out, [=](auto& o) {
217 });
218}
static BigInt zero()
Definition bigint.h:49
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 220 of file ffi_mp.cpp.

220 {
221 return BOTAN_FFI_VISIT(out, [=](auto& o) {
223 o = reducer.multiply(safe_get(x), safe_get(y));
224 });
225}
static Barrett_Reduction for_secret_modulus(const BigInt &m)
Definition barrett.cpp:22

References BOTAN_FFI_VISIT, Botan::Barrett_Reduction::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 158 of file ffi_mp.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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
58 return BOTAN_FFI_SUCCESS;
59 });
60}
static BigInt decode(const uint8_t buf[], size_t length)
Definition bigint.h:857
std::span< const uint8_t > cstr_as_span_of_bytes(const char *s)
Definition mem_utils.h:41

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, Botan::cstr_as_span_of_bytes(), Botan::BigInt::Decimal, Botan::BigInt::decode(), 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 128 of file ffi_mp.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

int botan_oid_cmp ( int * result,
botan_asn1_oid_t a,
botan_asn1_oid_t b )

Sets

Parameters
resultto comparison result: -1 if a < b, 0 if a == b, 1 if a > b
Returns
negative number on error or zero on success

Definition at line 64 of file ffi_oid.cpp.

64 {
65 return BOTAN_FFI_VISIT(a_w, [=](auto& a) {
66 if(result == nullptr) {
68 }
69 Botan::OID b = safe_get(b_w);
70 // we don't have .cmp for OID
71 if(a == b) {
72 *result = 0;
73 } else if(a < b) {
74 *result = -1;
75 } else {
76 *result = 1;
77 }
78 return BOTAN_FFI_SUCCESS;
79 });
80}

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

◆ botan_oid_destroy()

int botan_oid_destroy ( botan_asn1_oid_t oid)
Returns
negative number on error, or zero on success

Definition at line 19 of file ffi_oid.cpp.

19 {
20 return BOTAN_FFI_CHECKED_DELETE(oid);
21}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_oid_equal()

int botan_oid_equal ( botan_asn1_oid_t a,
botan_asn1_oid_t b )
Returns
0 if a != b
1 if a == b
negative number on error

Definition at line 60 of file ffi_oid.cpp.

60 {
61 return BOTAN_FFI_VISIT(a_w, [=](const auto& a) -> int { return a == safe_get(b_w); });
62}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_oid_from_string()

int botan_oid_from_string ( botan_asn1_oid_t * oid,
const char * oid_str )

Create an OID from a string, either dot notation (e.g. '1.2.3.4') or a registered name (e.g. 'RSA')

Parameters
oidhanlder to the resulting OID
oid_strthe name of the OID to create
Returns
negative number on error, or zero on success

Definition at line 23 of file ffi_oid.cpp.

23 {
24 return ffi_guard_thunk(__func__, [=]() -> int {
25 if(oid_obj == nullptr || oid_str == nullptr) {
27 }
28 Botan::OID oid;
29 // This returns a Lookup_Error if an unknown name is passed,
30 // which would get turned into NOT_IMPLEMENTED
31 try {
32 oid = Botan::OID::from_string(oid_str);
33 } catch(Botan::Lookup_Error&) {
35 }
36 auto oid_ptr = std::make_unique<Botan::OID>(std::move(oid));
37 return ffi_new_object(oid_obj, std::move(oid_ptr));
38 });
39}
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:86

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan::OID::from_string().

◆ botan_oid_register()

int botan_oid_register ( botan_asn1_oid_t oid,
const char * name )

Registers an OID so that it may later be retrieved by name

Returns
negative number on error, or zero on success

Definition at line 41 of file ffi_oid.cpp.

41 {
42 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int {
43 if(name == nullptr) {
45 }
47 return BOTAN_FFI_SUCCESS;
48 });
49}
static void register_oid(const OID &oid, std::string_view name)
Definition asn1_oid.cpp:67

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and Botan::OID::register_oid().

◆ botan_oid_view_name()

int botan_oid_view_name ( botan_asn1_oid_t oid,
botan_view_ctx ctx,
botan_view_str_fn view )

View an OIDs registered name if it exists, else its dot notation

Definition at line 55 of file ffi_oid.cpp.

55 {
56 return BOTAN_FFI_VISIT(
57 oid, [=](const auto& o) -> int { return invoke_view_callback(view, ctx, o.to_formatted_string()); });
58}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_oid_view_string()

int botan_oid_view_string ( botan_asn1_oid_t oid,
botan_view_ctx ctx,
botan_view_str_fn view )

View an OID in dot notation

Definition at line 51 of file ffi_oid.cpp.

51 {
52 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int { return invoke_view_callback(view, ctx, o.to_string()); });
53}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

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

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

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

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

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 90 of file ffi_pk_op.cpp.

90 {
91 return BOTAN_FFI_CHECKED_DELETE(op);
92}

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

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

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

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

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 return ffi_new_object(op, std::move(pk));
42 });
43}
#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE
Definition ffi.h:1943

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 45 of file ffi_pk_op.cpp.

45 {
46 return BOTAN_FFI_CHECKED_DELETE(op);
47}

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

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

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

307 {
308 if(op == nullptr || padding == nullptr) {
310 }
311
312 return ffi_guard_thunk(__func__, [=]() -> int {
313 auto pk = std::make_unique<Botan::PK_KEM_Decryptor>(safe_get(key_obj), Botan::system_rng(), padding);
314 return ffi_new_object(op, std::move(pk));
315 });
316}

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 347 of file ffi_pk_op.cpp.

347 {
348 return BOTAN_FFI_CHECKED_DELETE(op);
349}

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

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

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

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

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

245 {
246 if(op == nullptr || padding == nullptr) {
248 }
249
250 return ffi_guard_thunk(__func__, [=]() -> int {
251 auto pk = std::make_unique<Botan::PK_KEM_Encryptor>(safe_get(key_obj), padding);
252 return ffi_new_object(op, std::move(pk));
253 });
254}

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 285 of file ffi_pk_op.cpp.

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

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

256 {
257 return BOTAN_FFI_CHECKED_DELETE(op);
258}

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

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

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

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

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

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

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

188 {
189 if(op == nullptr) {
191 }
192
193 if(flags != 0) {
195 }
196
197 return ffi_guard_thunk(__func__, [=]() -> int {
198 *op = nullptr;
199 auto pk = std::make_unique<Botan::PK_Key_Agreement>(safe_get(key_obj), Botan::system_rng(), kdf);
200 return ffi_new_object(op, std::move(pk));
201 });
202}

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 204 of file ffi_pk_op.cpp.

204 {
205 return BOTAN_FFI_CHECKED_DELETE(op);
206}

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

208 {
209 return copy_view_bin(out, out_len, botan_pk_op_key_agreement_view_public, key);
210}
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:211

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

222 {
223 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
224 if(out_len == nullptr) {
226 }
227 *out_len = o.agreed_value_size();
228 return BOTAN_FFI_SUCCESS;
229 });
230}

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

212 {
213 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
214 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k)) {
215 return invoke_view_callback(view, ctx, kak->public_value());
216 } else {
218 }
219 });
220}

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

110 {
111 if(op == nullptr) {
113 }
114
115 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
117 }
118
119 return ffi_guard_thunk(__func__, [=]() -> int {
120 *op = nullptr;
121
122 const bool use_der = (flags & BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) != 0;
124
125 auto pk = std::make_unique<Botan::PK_Signer>(safe_get(key_obj), Botan::system_rng(), hash, format);
126 return ffi_new_object(op, std::move(pk));
127 });
128}

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DerSequence, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 130 of file ffi_pk_op.cpp.

130 {
131 return BOTAN_FFI_CHECKED_DELETE(op);
132}

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

146 {
147 return BOTAN_FFI_VISIT(op, [=](auto& o) { return write_vec_output(out, out_len, o.signature(safe_get(rng_obj))); });
148}

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

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

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

142 {
143 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
144}

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

150 {
151 if(op == nullptr) {
153 }
154
155 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
157 }
158
159 return ffi_guard_thunk(__func__, [=]() -> int {
160 *op = nullptr;
161 const bool use_der = (flags & BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) != 0;
163 auto pk = std::make_unique<Botan::PK_Verifier>(safe_get(key_obj), hash, format);
164 return ffi_new_object(op, std::move(pk));
165 });
166}

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DerSequence, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 168 of file ffi_pk_op.cpp.

168 {
169 return BOTAN_FFI_CHECKED_DELETE(op);
170}

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

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

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

172 {
173 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
174}

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

444 {
445#if defined(BOTAN_HAS_HASH_ID)
446 return ffi_guard_thunk(__func__, [=]() -> int {
447 const std::vector<uint8_t> hash_id = Botan::pkcs_hash_id(hash_name);
448 return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
449 });
450#else
451 BOTAN_UNUSED(hash_name, pkcs_id, pkcs_id_len);
453#endif
454}
int write_output(T out[], size_t *out_len, const T buf[], size_t buf_len)
Definition ffi_util.h:226
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 143 of file ffi_pkey.cpp.

143 {
144 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
145}

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

159 {
160 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS) != 0;
161 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
162 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
163 });
164}
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition ffi.h:1327

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

32 {
33 // TODO(Botan4) remove this implicit algorithm choice and reject nullptr algo_name
34 if(algo_name == nullptr) {
35 return botan_privkey_create(key_obj, "RSA", algo_params, rng_obj);
36 }
37
38 return ffi_guard_thunk(__func__, [=]() -> int {
39 if(key_obj == nullptr) {
41 }
42
43 *key_obj = nullptr;
44 if(rng_obj == nullptr) {
46 }
47
48 const std::string params(algo_params != nullptr ? algo_params : "");
49
51
52 if(auto key = Botan::create_private_key(algo_name, rng, params)) {
53 return ffi_new_object(key_obj, std::move(key));
54 } else {
56 }
57 });
58}
int botan_privkey_create(botan_privkey_t *key_obj, const char *algo_name, const char *algo_params, botan_rng_t rng_obj)
Definition ffi_pkey.cpp:29
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_privkey_create(), Botan::create_private_key(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

Referenced by botan_privkey_create(), 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 539 of file ffi_pkey_algs.cpp.

539 {
540 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
541}
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition ffi_pkey.cpp:29

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

324 {
325#if defined(BOTAN_HAS_DSA)
326
327 if((rng_obj == nullptr) || (key == nullptr)) {
329 }
330
331 if((pbits % 64 != 0) || (qbits % 8 != 0) || (pbits < 1024) || (pbits > 3072) || (qbits < 160) || (qbits > 256)) {
333 }
334
335 return ffi_guard_thunk(__func__, [=]() -> int {
337 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
338 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
339 return ffi_new_object(key, std::move(dsa));
340 });
341#else
342 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
344#endif
345}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 579 of file ffi_pkey_algs.cpp.

579 {
580 if(key_obj == nullptr || param_str == nullptr) {
582 }
583 *key_obj = nullptr;
584
585 const std::string params(param_str);
586
587 if(params == "X25519" || params == "x25519" || params == "curve25519") {
588 return botan_privkey_create(key_obj, "X25519", "", rng_obj);
589 }
590
591 if(params == "X448" || params == "x448") {
592 return botan_privkey_create(key_obj, "X448", "", rng_obj);
593 }
594
595 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
596}

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

403 {
404 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
405}

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

477 {
478#if defined(BOTAN_HAS_ELGAMAL)
479 if(key == nullptr || rng_obj == nullptr) {
481 }
482 *key = nullptr;
483
484 if(pbits < 1024 || qbits < 160) {
486 }
487
488 Botan::DL_Group::PrimeType prime_type =
489 ((pbits - 1) == qbits) ? Botan::DL_Group::Strong : Botan::DL_Group::Prime_Subgroup;
490
491 return ffi_guard_thunk(__func__, [=]() -> int {
493 Botan::DL_Group group(rng, prime_type, pbits, qbits);
494 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
495 return ffi_new_object(key, std::move(elg));
496 });
497#else
498 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
500#endif
501}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1371 of file ffi_pkey_algs.cpp.

1371 {
1372 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1373 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1374}

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

210 {
211 if(n_bits < 1024 || n_bits > 16 * 1024) {
213 }
214
215 std::string n_str = std::to_string(n_bits);
216
217 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
218}

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

111 {
112 return BOTAN_FFI_CHECKED_DELETE(key);
113}

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

383 {
384 return botan_privkey_get_field(x, key, "x");
385}
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 770 of file ffi_pkey_algs.cpp.

770 {
771#if defined(BOTAN_HAS_ED25519)
772 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
773 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
774 const auto ed_key = ed->raw_private_key_bits();
775 if(ed_key.size() != 64) {
777 }
778 Botan::copy_mem(output, ed_key.data(), ed_key.size());
779 return BOTAN_FFI_SUCCESS;
780 } else {
782 }
783 });
784#else
785 BOTAN_UNUSED(key, output);
787#endif
788}

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

844 {
845#if defined(BOTAN_HAS_ED448)
846 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
847 if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
848 const auto ed_key = ed->raw_private_key_bits();
849 Botan::copy_mem(std::span(output, 57), ed_key);
850 return BOTAN_FFI_SUCCESS;
851 } else {
853 }
854 });
855#else
856 BOTAN_UNUSED(key, output);
858#endif
859}
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 193 of file ffi_pkey.cpp.

193 {
194 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
195 return copy_view_bin(out, out_len, botan_privkey_view_der, key);
196 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
197 return copy_view_str(out, out_len, botan_privkey_view_pem, key);
198 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
199 return copy_view_bin(out, out_len, botan_privkey_view_raw, key);
200 } else {
202 }
203}
#define BOTAN_PRIVKEY_EXPORT_FLAG_RAW
Definition ffi.h:1399
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:205
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:215
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1398
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1397
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:210
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:217

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

226 {
227 return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
228}
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:307

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

315 {
316 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
317 return copy_view_bin(
318 out, out_len, botan_privkey_view_encrypted_der, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
319 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
320 return copy_view_str(
321 out, out_len, botan_privkey_view_encrypted_pem, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
322 } else {
324 }
325}
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)
Definition ffi_pkey.cpp:327
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)
Definition ffi_pkey.cpp:352

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

239 {
240 if(pbkdf_iters_out != nullptr) {
241 *pbkdf_iters_out = 0;
242 }
243
244 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
245 return copy_view_bin(
246 out, out_len, botan_privkey_view_encrypted_der_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
247 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
248 return copy_view_str(
249 out, out_len, botan_privkey_view_encrypted_pem_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
250 } else {
252 }
253}
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)
Definition ffi_pkey.cpp:281
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)
Definition ffi_pkey.cpp:255

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

135 {
136 return ffi_guard_thunk(__func__, [=]() -> int {
137 auto public_key = safe_get(key_obj).public_key();
138 ffi_new_object(pubout, std::move(public_key));
139 return BOTAN_FFI_SUCCESS;
140 });
141}

References BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 198 of file ffi_pkey_algs.cpp.

198 {
199 if(field_name_cstr == nullptr) {
201 }
202
203 const std::string field_name(field_name_cstr);
204
205 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); });
206}

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

87 {
88 BOTAN_UNUSED(rng_obj);
89
90 *key = nullptr;
91
92 return ffi_guard_thunk(__func__, [=]() -> int {
93 Botan::DataSource_Memory src(bits, len);
94
95 std::unique_ptr<Botan::Private_Key> pkcs8;
96
97 if(password == nullptr) {
98 pkcs8 = Botan::PKCS8::load_key(src);
99 } else {
100 pkcs8 = Botan::PKCS8::load_key(src, std::string(password));
101 }
102
103 if(pkcs8) {
104 ffi_new_object(key, std::move(pkcs8));
105 return BOTAN_FFI_SUCCESS;
106 }
108 });
109}
std::unique_ptr< Private_Key > load_key(DataSource &source, const std::function< std::string()> &get_pass)
Definition pkcs8.cpp:314

References BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1309 of file ffi_pkey_algs.cpp.

1312 {
1313#if defined(BOTAN_HAS_CLASSICMCELIECE)
1314 if(key == nullptr || privkey == nullptr || cmce_mode == nullptr) {
1316 }
1317
1318 *key = nullptr;
1319
1320 return ffi_guard_thunk(__func__, [=]() -> int {
1321 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1322 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
1323 return ffi_new_object(key, std::move(cmce_key));
1324 });
1325#else
1326 BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1328#endif
1329}
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_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 543 of file ffi_pkey_algs.cpp.

543 {
544#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
545 if(key == nullptr) {
547 }
548 *key = nullptr;
549 return ffi_guard_thunk(__func__, [=]() -> int {
550 Botan::DL_Group group(safe_get(p), safe_get(g));
551 auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
552 return ffi_new_object(key, std::move(dh));
553 });
554#else
555 BOTAN_UNUSED(key, p, g, x);
557#endif
558}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 347 of file ffi_pkey_algs.cpp.

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 622 of file ffi_pkey_algs.cpp.

622 {
623#if defined(BOTAN_HAS_ECDH)
624 if(key == nullptr || curve_name == nullptr) {
626 }
627 *key = nullptr;
628 return ffi_guard_thunk(__func__, [=]() -> int {
629 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
630 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
631 if(rc == BOTAN_FFI_SUCCESS) {
632 ffi_new_object(key, std::move(p_key));
633 }
634 return rc;
635 });
636#else
637 BOTAN_UNUSED(key, scalar, curve_name);
639#endif
640}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 455 of file ffi_pkey_algs.cpp.

455 {
456#if defined(BOTAN_HAS_ECDSA)
457 if(key == nullptr || curve_name == nullptr) {
459 }
460 *key = nullptr;
461
462 return ffi_guard_thunk(__func__, [=]() -> int {
463 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
464 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
465 if(rc == BOTAN_FFI_SUCCESS) {
466 ffi_new_object(key, std::move(p_key));
467 }
468 return rc;
469 });
470#else
471 BOTAN_UNUSED(key, scalar, curve_name);
473#endif
474}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 736 of file ffi_pkey_algs.cpp.

736 {
737#if defined(BOTAN_HAS_ED25519)
738 if(key == nullptr) {
740 }
741 *key = nullptr;
742 return ffi_guard_thunk(__func__, [=]() -> int {
743 auto ed25519 =
744 std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(std::span{privkey, 32}));
745 return ffi_new_object(key, std::move(ed25519));
746 });
747#else
748 BOTAN_UNUSED(key, privkey);
750#endif
751}
static Ed25519_PrivateKey from_seed(std::span< const uint8_t > seed)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan::Ed25519_PrivateKey::from_seed().

◆ botan_privkey_load_ed448()

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

Definition at line 812 of file ffi_pkey_algs.cpp.

812 {
813#if defined(BOTAN_HAS_ED448)
814 if(key == nullptr) {
816 }
817 *key = nullptr;
818 return ffi_guard_thunk(__func__, [=]() -> int {
819 auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
820 return ffi_new_object(key, std::move(ed448));
821 });
822#else
823 BOTAN_UNUSED(key, privkey);
825#endif
826}

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

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

520 {
521#if defined(BOTAN_HAS_ELGAMAL)
522 if(key == nullptr) {
524 }
525 *key = nullptr;
526 return ffi_guard_thunk(__func__, [=]() -> int {
527 Botan::DL_Group group(safe_get(p), safe_get(g));
528 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(group, safe_get(x));
529 return ffi_new_object(key, std::move(elg));
530 });
531#else
532 BOTAN_UNUSED(key, p, g, x);
534#endif
535}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1267 of file ffi_pkey_algs.cpp.

1267 {
1268#if defined(BOTAN_HAS_FRODOKEM)
1269 if(key == nullptr || privkey == nullptr || frodo_mode == nullptr) {
1271 }
1272
1273 *key = nullptr;
1274
1275 return ffi_guard_thunk(__func__, [=]() -> int {
1276 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1277 auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
1278 return ffi_new_object(key, std::move(frodo_key));
1279 });
1280#else
1281 BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1283#endif
1284}

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

◆ botan_privkey_load_kyber()

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

Definition at line 1019 of file ffi_pkey_algs.cpp.

1019 {
1020#if defined(BOTAN_HAS_KYBER)
1021 if(key == nullptr) {
1023 }
1024 *key = nullptr;
1025
1026 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1027 if(len == 1632) {
1029 } else if(len == 2400) {
1031 } else if(len == 3168) {
1033 } else {
1034 return {};
1035 }
1036 }(key_len);
1037
1038 if(mode.has_value()) {
1039 return ffi_guard_thunk(__func__, [=]() -> int {
1040 auto kyber = std::make_unique<Botan::Kyber_PrivateKey>(std::span{privkey, key_len}, *mode);
1041 return ffi_new_object(key, std::move(kyber));
1042 });
1043 } else {
1045 }
1046#else
1047 BOTAN_UNUSED(key, key_len, privkey);
1049#endif
1050}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1167 of file ffi_pkey_algs.cpp.

1167 {
1168#if defined(BOTAN_HAS_ML_DSA)
1169 if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
1171 }
1172
1173 *key = nullptr;
1174
1175 return ffi_guard_thunk(__func__, [=]() -> int {
1176 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1177 if(!mode.is_ml_dsa()) {
1179 }
1180
1181 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1182 return ffi_new_object(key, std::move(mldsa_key));
1183 });
1184#else
1185 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1187#endif
1188}
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_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

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

1117 {
1118#if defined(BOTAN_HAS_ML_KEM)
1119 if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
1121 }
1122
1123 *key = nullptr;
1124
1125 return ffi_guard_thunk(__func__, [=]() -> int {
1126 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1127 if(!mode.is_ml_kem()) {
1129 }
1130
1131 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1132 return ffi_new_object(key, std::move(mlkem_key));
1133 });
1134#else
1135 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1137#endif
1138}
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_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

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

220 {
221#if defined(BOTAN_HAS_RSA)
222 if(key == nullptr) {
224 }
225 *key = nullptr;
226
227 return ffi_guard_thunk(__func__, [=]() -> int {
228 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p), safe_get(rsa_q), safe_get(rsa_e));
229 return ffi_new_object(key, std::move(rsa));
230 });
231#else
232 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
234#endif
235}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 237 of file ffi_pkey_algs.cpp.

237 {
238#if defined(BOTAN_HAS_RSA)
239 if(key == nullptr || bits == nullptr) {
241 }
242 *key = nullptr;
243
244 return ffi_guard_thunk(__func__, [=]() -> int {
246 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, std::span{bits, len});
247 return ffi_new_object(key, std::move(rsa));
248 });
249#else
250 BOTAN_UNUSED(key, bits, len);
252#endif
253}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1217 of file ffi_pkey_algs.cpp.

1217 {
1218#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1219 if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
1221 }
1222
1223 *key = nullptr;
1224
1225 return ffi_guard_thunk(__func__, [=]() -> int {
1226 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1227 if(!mode.is_slh_dsa()) {
1229 }
1230
1231 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1232 return ffi_new_object(key, std::move(slhdsa_key));
1233 });
1234#else
1235 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1237#endif
1238}

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

◆ botan_privkey_load_sm2()

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

Definition at line 701 of file ffi_pkey_algs.cpp.

701 {
702#if defined(BOTAN_HAS_SM2)
703 if(key == nullptr || curve_name == nullptr) {
705 }
706 *key = nullptr;
707
708 return ffi_guard_thunk(__func__, [=]() -> int {
709 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
710 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
711
712 if(rc == BOTAN_FFI_SUCCESS) {
713 ffi_new_object(key, std::move(p_key));
714 }
715 return rc;
716 });
717#else
718 BOTAN_UNUSED(key, scalar, curve_name);
720#endif
721}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 730 of file ffi_pkey_algs.cpp.

730 {
731 return botan_privkey_load_sm2(key, scalar, curve_name);
732}
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 880 of file ffi_pkey_algs.cpp.

880 {
881#if defined(BOTAN_HAS_X25519)
882 if(key == nullptr) {
884 }
885 *key = nullptr;
886 return ffi_guard_thunk(__func__, [=]() -> int {
887 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(std::span{privkey, 32});
888 return ffi_new_object(key, std::move(x25519));
889 });
890#else
891 BOTAN_UNUSED(key, privkey);
893#endif
894}

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

◆ botan_privkey_load_x448()

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

Definition at line 950 of file ffi_pkey_algs.cpp.

950 {
951#if defined(BOTAN_HAS_X448)
952 if(key == nullptr) {
954 }
955 *key = nullptr;
956 return ffi_guard_thunk(__func__, [=]() -> int {
957 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span{privkey, 56});
958 return ffi_new_object(key, std::move(x448));
959 });
960#else
961 BOTAN_UNUSED(key, privkey);
963#endif
964}
Point448 x448(const ScalarX448 &k, const Point448 &u)
Multiply a scalar k with a point u.

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

◆ botan_privkey_oid()

int botan_privkey_oid ( botan_asn1_oid_t * oid,
botan_privkey_t key )

Definition at line 390 of file ffi_pkey.cpp.

390 {
391 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
392 if(oid == nullptr) {
394 }
395
396 auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
397 ffi_new_object(oid, std::move(oid_ptr));
398
399 return BOTAN_FFI_SUCCESS;
400 });
401}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and Botan_FFI::ffi_new_object().

◆ botan_privkey_remaining_operations()

int botan_privkey_remaining_operations ( botan_privkey_t key,
uint64_t * out )

Gets information on many operations a (stateful) key has remaining and sets

Parameters
outto that value
Returns
0 on success, a negative value on failure or if the key is not stateful

Definition at line 418 of file ffi_pkey.cpp.

418 {
419 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
420 if(out == nullptr) {
422 }
423
424 if(auto remaining = k.remaining_operations()) {
425 *out = remaining.value();
426 return BOTAN_FFI_SUCCESS;
427 } else {
429 }
430 });
431}

References BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_privkey_rsa_get_d()

int botan_privkey_rsa_get_d ( botan_mp_t d,
botan_privkey_t rsa_key )

Definition at line 287 of file ffi_pkey_algs.cpp.

287 {
288 return botan_privkey_get_field(d, key, "d");
289}

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

283 {
284 return botan_privkey_get_field(e, key, "e");
285}

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

279 {
280 return botan_privkey_get_field(n, key, "n");
281}

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

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

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

299 {
300#if defined(BOTAN_HAS_RSA)
301 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
302 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
303 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
304 return write_vec_output(out, out_len, rsa->private_key_bits());
305 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
306 // TODO define new generic functions for this
307 return write_str_output(reinterpret_cast<char*>(out),
308 out_len,
309 Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
310 } else {
312 }
313 } else {
315 }
316 });
317#else
318 BOTAN_UNUSED(rsa_key, out, out_len, flags);
320#endif
321}
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 275 of file ffi_pkey_algs.cpp.

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

References botan_privkey_get_field().

◆ botan_privkey_stateful_operation()

int botan_privkey_stateful_operation ( botan_privkey_t key,
int * out )

Checks whether a key is stateful and sets

Parameters
outto 1 if it is, or 0 if the key is not stateful
Returns
0 on success, a negative value on failure

Definition at line 403 of file ffi_pkey.cpp.

403 {
404 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
405 if(out == nullptr) {
407 }
408
409 if(k.stateful_operation()) {
410 *out = 1;
411 } else {
412 *out = 0;
413 }
414 return BOTAN_FFI_SUCCESS;
415 });
416}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

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

205 {
206 return BOTAN_FFI_VISIT(key,
207 [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.private_key_info()); });
208}

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

334 {
335 if(passphrase == nullptr) {
337 }
338
339 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
341
342 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
343 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
344 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
345
346 auto pkcs8 = Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
347
348 return invoke_view_callback(view, ctx, pkcs8);
349 });
350}
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:201

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

262 {
263 if(passphrase == nullptr) {
265 }
266
267 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
268 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
270
271 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
272 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
273
274 auto pkcs8 =
275 Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
276
277 return invoke_view_callback(view, ctx, pkcs8);
278 });
279}
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:244

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

359 {
360 if(passphrase == nullptr) {
362 }
363
364 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
366
367 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
368 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
369 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
370
371 auto pkcs8 = Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
372
373 return invoke_view_callback(view, ctx, pkcs8);
374 });
375}
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:231

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

288 {
289 if(passphrase == nullptr) {
291 }
292
293 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
294 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
296
297 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
298 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
299
300 auto pkcs8 =
301 Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
302
303 return invoke_view_callback(view, ctx, pkcs8);
304 });
305}
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:278

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

1083 {
1084#if defined(BOTAN_HAS_KYBER)
1085 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1086 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1087 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1088 } else {
1090 }
1091 });
1092#else
1093 BOTAN_UNUSED(key, ctx, view);
1095#endif
1096}

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

210 {
211 return BOTAN_FFI_VISIT(
212 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::PEM_encode(k)); });
213}
std::string PEM_encode(const Private_Key &key)
Definition pkcs8.cpp:116

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

215 {
216 return BOTAN_FFI_VISIT(
217 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_private_key_bits()); });
218}

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

912 {
913#if defined(BOTAN_HAS_X25519)
914 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
915 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
916 const auto x25519_key = x25519->raw_private_key_bits();
917 if(x25519_key.size() != 32) {
919 }
920 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
921 return BOTAN_FFI_SUCCESS;
922 } else {
924 }
925 });
926#else
927 BOTAN_UNUSED(key, output);
929#endif
930}

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

982 {
983#if defined(BOTAN_HAS_X448)
984 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
985 if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
986 const auto x448_key = x448->raw_private_key_bits();
987 Botan::copy_mem(std::span{output, 56}, x448_key);
988 return BOTAN_FFI_SUCCESS;
989 } else {
991 }
992 });
993#else
994 BOTAN_UNUSED(key, output);
996#endif
997}
A private key for the X448 key agreement scheme according to RFC 7748.
Definition x448.h:69

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

147 {
148 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
149}

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

151 {
152 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS) != 0;
153
154 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
155 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
156 });
157}

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

131 {
132 return BOTAN_FFI_CHECKED_DELETE(key);
133}

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

395 {
396 return botan_pubkey_get_field(g, key, "g");
397}
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 387 of file ffi_pkey_algs.cpp.

387 {
388 return botan_pubkey_get_field(p, key, "p");
389}

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

391 {
392 return botan_pubkey_get_field(q, key, "q");
393}

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

399 {
400 return botan_pubkey_get_field(y, key, "y");
401}

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

409 {
410#if defined(BOTAN_HAS_ECC_KEY)
411 return ffi_guard_thunk(__func__, [=]() -> int {
412 const Botan::Public_Key& pub_key = safe_get(key);
413 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
414
415 if(ec_key == nullptr) {
417 }
418
419 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
420 });
421#else
422 BOTAN_UNUSED(key);
424#endif
425}
bool used_explicit_encoding() const
Definition ec_group.h:270
const EC_Group & domain() const
Definition ecc_key.cpp:64

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

790 {
791#if defined(BOTAN_HAS_ED25519)
792 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
793 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
794 const std::vector<uint8_t>& ed_key = ed->get_public_key();
795 if(ed_key.size() != 32) {
797 }
798 Botan::copy_mem(output, ed_key.data(), ed_key.size());
799 return BOTAN_FFI_SUCCESS;
800 } else {
802 }
803 });
804#else
805 BOTAN_UNUSED(key, output);
807#endif
808}

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

861 {
862#if defined(BOTAN_HAS_ED448)
863 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
864 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
865 const auto ed_key = ed->public_key_bits();
866 Botan::copy_mem(std::span(output, 57), ed_key);
867 return BOTAN_FFI_SUCCESS;
868 } else {
870 }
871 });
872#else
873 BOTAN_UNUSED(key, output);
875#endif
876}
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 433 of file ffi_pkey.cpp.

433 {
434 return BOTAN_FFI_VISIT(key, [=](const auto& k) { *estimate = k.estimated_strength(); });
435}

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

166 {
167 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
168 return copy_view_bin(out, out_len, botan_pubkey_view_der, key);
169 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
170 return copy_view_str(out, out_len, botan_pubkey_view_pem, key);
171 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
172 return copy_view_bin(out, out_len, botan_pubkey_view_raw, key);
173 } else {
175 }
176}
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:183
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:178
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:188

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

437 {
438 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
439 auto h = Botan::HashFunction::create_or_throw(hash_fn);
440 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
441 });
442}
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 188 of file ffi_pkey_algs.cpp.

188 {
189 if(field_name_cstr == nullptr) {
191 }
192
193 const std::string field_name(field_name_cstr);
194
195 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); });
196}

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

115 {
116 *key = nullptr;
117
118 return ffi_guard_thunk(__func__, [=]() -> int {
119 Botan::DataSource_Memory src(bits, bits_len);
120 std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src));
121
122 if(pubkey == nullptr) {
124 }
125
126 ffi_new_object(key, std::move(pubkey));
127 return BOTAN_FFI_SUCCESS;
128 });
129}
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(), Botan_FFI::ffi_new_object(), 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 1331 of file ffi_pkey_algs.cpp.

1334 {
1335#if defined(BOTAN_HAS_CLASSICMCELIECE)
1336 if(key == nullptr || pubkey == nullptr || cmce_mode == nullptr) {
1338 }
1339
1340 *key = nullptr;
1341
1342 return ffi_guard_thunk(__func__, [=]() -> int {
1343 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1344 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
1345 return ffi_new_object(key, std::move(cmce_key));
1346 });
1347#else
1348 BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1350#endif
1351}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 560 of file ffi_pkey_algs.cpp.

560 {
561#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
562 if(key == nullptr) {
564 }
565 *key = nullptr;
566 return ffi_guard_thunk(__func__, [=]() -> int {
567 Botan::DL_Group group(safe_get(p), safe_get(g));
568 auto dh = std::make_unique<Botan::DH_PublicKey>(group, safe_get(y));
569 return ffi_new_object(key, std::move(dh));
570 });
571#else
572 BOTAN_UNUSED(key, p, g, y);
574#endif
575}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 365 of file ffi_pkey_algs.cpp.

365 {
366#if defined(BOTAN_HAS_DSA)
367 if(key == nullptr) {
369 }
370 *key = nullptr;
371
372 return ffi_guard_thunk(__func__, [=]() -> int {
373 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
374 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
375 return ffi_new_object(key, std::move(dsa));
376 });
377#else
378 BOTAN_UNUSED(key, p, q, g, y);
380#endif
381}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 598 of file ffi_pkey_algs.cpp.

601 {
602#if defined(BOTAN_HAS_ECDH)
603 if(key == nullptr || curve_name == nullptr) {
605 }
606 *key = nullptr;
607 return ffi_guard_thunk(__func__, [=]() -> int {
608 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
609 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
610
611 if(rc == BOTAN_FFI_SUCCESS) {
612 ffi_new_object(key, std::move(p_key));
613 }
614 return rc;
615 });
616#else
617 BOTAN_UNUSED(key, public_x, public_y, curve_name);
619#endif
620}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 429 of file ffi_pkey_algs.cpp.

432 {
433#if defined(BOTAN_HAS_ECDSA)
434 if(key == nullptr || curve_name == nullptr) {
436 }
437 *key = nullptr;
438
439 return ffi_guard_thunk(__func__, [=]() -> int {
440 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
441
442 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
443 if(rc == BOTAN_FFI_SUCCESS) {
444 ffi_new_object(key, std::move(p_key));
445 }
446
447 return rc;
448 });
449#else
450 BOTAN_UNUSED(key, public_x, public_y, curve_name);
452#endif
453}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 753 of file ffi_pkey_algs.cpp.

753 {
754#if defined(BOTAN_HAS_ED25519)
755 if(key == nullptr) {
757 }
758 *key = nullptr;
759 return ffi_guard_thunk(__func__, [=]() -> int {
760 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
761 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
762 return ffi_new_object(key, std::move(ed25519));
763 });
764#else
765 BOTAN_UNUSED(key, pubkey);
767#endif
768}

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

◆ botan_pubkey_load_ed448()

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

Definition at line 828 of file ffi_pkey_algs.cpp.

828 {
829#if defined(BOTAN_HAS_ED448)
830 if(key == nullptr) {
832 }
833 *key = nullptr;
834 return ffi_guard_thunk(__func__, [=]() -> int {
835 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
836 return ffi_new_object(key, std::move(ed448));
837 });
838#else
839 BOTAN_UNUSED(key, pubkey);
841#endif
842}

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

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

503 {
504#if defined(BOTAN_HAS_ELGAMAL)
505 if(key == nullptr) {
507 }
508 *key = nullptr;
509 return ffi_guard_thunk(__func__, [=]() -> int {
510 Botan::DL_Group group(safe_get(p), safe_get(g));
511 auto elg = std::make_unique<Botan::ElGamal_PublicKey>(group, safe_get(y));
512 return ffi_new_object(key, std::move(elg));
513 });
514#else
515 BOTAN_UNUSED(key, p, g, y);
517#endif
518}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1286 of file ffi_pkey_algs.cpp.

1286 {
1287#if defined(BOTAN_HAS_FRODOKEM)
1288 if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
1290 }
1291
1292 *key = nullptr;
1293
1294 return ffi_guard_thunk(__func__, [=]() -> int {
1295 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1296 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1297 return ffi_new_object(key, std::move(frodo_key));
1298 });
1299#else
1300 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1302#endif
1303}

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

◆ botan_pubkey_load_kyber()

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

Definition at line 1052 of file ffi_pkey_algs.cpp.

1052 {
1053#if defined(BOTAN_HAS_KYBER)
1054 if(key == nullptr) {
1056 }
1057 *key = nullptr;
1058
1059 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1060 if(len == 800) {
1062 } else if(len == 1184) {
1064 } else if(len == 1568) {
1066 } else {
1067 return {};
1068 }
1069 }(key_len);
1070
1071 if(mode.has_value()) {
1072 auto kyber = std::make_unique<Botan::Kyber_PublicKey>(std::span{pubkey, key_len}, *mode);
1073 return ffi_new_object(key, std::move(kyber));
1074 } else {
1076 }
1077#else
1078 BOTAN_UNUSED(key, pubkey, key_len);
1080#endif
1081}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), 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 1190 of file ffi_pkey_algs.cpp.

1190 {
1191#if defined(BOTAN_HAS_ML_DSA)
1192 if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
1194 }
1195
1196 *key = nullptr;
1197
1198 return ffi_guard_thunk(__func__, [=]() -> int {
1199 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1200 if(!mode.is_ml_dsa()) {
1202 }
1203
1204 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1205 return ffi_new_object(key, std::move(mldsa_key));
1206 });
1207#else
1208 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1210#endif
1211}

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

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

1140 {
1141#if defined(BOTAN_HAS_ML_KEM)
1142 if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
1144 }
1145
1146 *key = nullptr;
1147
1148 return ffi_guard_thunk(__func__, [=]() -> int {
1149 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1150 if(!mode.is_ml_kem()) {
1152 }
1153
1154 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1155 return ffi_new_object(key, std::move(mlkem_key));
1156 });
1157#else
1158 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1160#endif
1161}

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

◆ botan_pubkey_load_rsa()

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

Definition at line 255 of file ffi_pkey_algs.cpp.

255 {
256#if defined(BOTAN_HAS_RSA)
257 if(key == nullptr) {
259 }
260 *key = nullptr;
261 return ffi_guard_thunk(__func__, [=]() -> int {
262 auto rsa = std::make_unique<Botan::RSA_PublicKey>(safe_get(n), safe_get(e));
263 return ffi_new_object(key, std::move(rsa));
264 });
265#else
266 BOTAN_UNUSED(key, n, e);
268#endif
269}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 1240 of file ffi_pkey_algs.cpp.

1240 {
1241#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1242 if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
1244 }
1245
1246 *key = nullptr;
1247
1248 return ffi_guard_thunk(__func__, [=]() -> int {
1249 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1250 if(!mode.is_slh_dsa()) {
1252 }
1253
1254 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1255 return ffi_new_object(key, std::move(mldsa_key));
1256 });
1257#else
1258 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1260#endif
1261}

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

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

680 {
681#if defined(BOTAN_HAS_SM2)
682 if(key == nullptr || curve_name == nullptr) {
684 }
685 *key = nullptr;
686
687 return ffi_guard_thunk(__func__, [=]() -> int {
688 std::unique_ptr<Botan::SM2_PublicKey> p_key;
689 if(pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name) == 0) {
690 return ffi_new_object(key, std::move(p_key));
691 } else {
693 }
694 });
695#else
696 BOTAN_UNUSED(key, public_x, public_y, curve_name);
698#endif
699}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 723 of file ffi_pkey_algs.cpp.

726 {
727 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
728}
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 896 of file ffi_pkey_algs.cpp.

896 {
897#if defined(BOTAN_HAS_X25519)
898 if(key == nullptr) {
900 }
901 *key = nullptr;
902 return ffi_guard_thunk(__func__, [=]() -> int {
903 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(std::span{pubkey, 32});
904 return ffi_new_object(key, std::move(x25519));
905 });
906#else
907 BOTAN_UNUSED(key, pubkey);
909#endif
910}

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

◆ botan_pubkey_load_x448()

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

Definition at line 966 of file ffi_pkey_algs.cpp.

966 {
967#if defined(BOTAN_HAS_X448)
968 if(key == nullptr) {
970 }
971 *key = nullptr;
972 return ffi_guard_thunk(__func__, [=]() -> int {
973 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span{pubkey, 56});
974 return ffi_new_object(key, std::move(x448));
975 });
976#else
977 BOTAN_UNUSED(key, pubkey);
979#endif
980}

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

◆ botan_pubkey_oid()

int botan_pubkey_oid ( botan_asn1_oid_t * oid,
botan_pubkey_t key )

Definition at line 377 of file ffi_pkey.cpp.

377 {
378 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
379 if(oid == nullptr) {
381 }
382
383 auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
384 ffi_new_object(oid, std::move(oid_ptr));
385
386 return BOTAN_FFI_SUCCESS;
387 });
388}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and Botan_FFI::ffi_new_object().

◆ botan_pubkey_rsa_get_e()

int botan_pubkey_rsa_get_e ( botan_mp_t e,
botan_pubkey_t rsa_key )

Definition at line 291 of file ffi_pkey_algs.cpp.

291 {
292 return botan_pubkey_get_field(e, key, "e");
293}

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

295 {
296 return botan_pubkey_get_field(n, key, "n");
297}

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

645 {
646 if(out == nullptr || out_len == nullptr || ident == nullptr || hash_algo == nullptr || key == nullptr) {
648 }
649
650#if defined(BOTAN_HAS_SM2)
651 return ffi_guard_thunk(__func__, [=]() -> int {
652 const Botan::Public_Key& pub_key = safe_get(key);
653 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
654
655 if(ec_key == nullptr) {
657 }
658
659 if(ec_key->algo_name() != "SM2") {
661 }
662
663 const std::string ident_str(ident);
664 std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
665
666 const auto& pt = ec_key->_public_ec_point();
667
668 const auto za = Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), pt);
669
670 return write_vec_output(out, out_len, za);
671 });
672#else
674#endif
675}
virtual std::string algo_name() const =0
const EC_AffinePoint & _public_ec_point() const
Definition ecc_key.cpp:76
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 178 of file ffi_pkey.cpp.

178 {
179 return BOTAN_FFI_VISIT(
180 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.subject_public_key()); });
181}

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

1353 {
1354#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1355 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1356 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1357 auto pt = ecc->_public_ec_point().serialize_uncompressed();
1358 return invoke_view_callback(view, ctx, pt);
1359 } else {
1361 }
1362 });
1363#else
1364 BOTAN_UNUSED(key, view, ctx);
1366#endif
1367}

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

1098 {
1099#if defined(BOTAN_HAS_KYBER)
1100 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1101 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1102 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1103 } else {
1105 }
1106 });
1107#else
1108 BOTAN_UNUSED(key, ctx, view);
1110#endif
1111}

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

183 {
184 return BOTAN_FFI_VISIT(
185 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::X509::PEM_encode(k)); });
186}
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 188 of file ffi_pkey.cpp.

188 {
189 return BOTAN_FFI_VISIT(
190 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_public_key_bits()); });
191}

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

932 {
933#if defined(BOTAN_HAS_X25519)
934 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
935 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
936 Botan::copy_mem(std::span{output, 32}, x25519->raw_public_key_bits());
937 return BOTAN_FFI_SUCCESS;
938 } else {
940 }
941 });
942#else
943 BOTAN_UNUSED(key, output);
945#endif
946}

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

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

Definition at line 999 of file ffi_pkey_algs.cpp.

999 {
1000#if defined(BOTAN_HAS_X448)
1001 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1002 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
1003 Botan::copy_mem(std::span{output, 56}, x448->raw_public_key_bits());
1004 return BOTAN_FFI_SUCCESS;
1005 } else {
1007 }
1008 });
1009#else
1010 BOTAN_UNUSED(key, output);
1012#endif
1013}
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 != nullptr) {
115 *param1 = pwdhash->iterations();
116 }
117 if(param2 != nullptr) {
118 *param2 = pwdhash->parallelism();
119 }
120 if(param3 != nullptr) {
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 178 of file ffi_rng.cpp.

178 {
179 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.add_entropy(input, len); });
180}

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 159 of file ffi_rng.cpp.

159 {
160 return BOTAN_FFI_CHECKED_DELETE(rng);
161}

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 163 of file ffi_rng.cpp.

163 {
164 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.randomize(out, out_len); });
165}

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 != nullptr ? 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 return ffi_new_object(rng_out, std::move(rng));
73 });
74}

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

◆ 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 76 of file ffi_rng.cpp.

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

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

◆ 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 174 of file ffi_rng.cpp.

174 {
175 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.reseed_from_rng(Botan::system_rng(), bits); });
176}

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 182 of file ffi_rng.cpp.

182 {
183 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.reseed_from_rng(safe_get(source_rng), bits); });
184}

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

307 {
308 return botan_constant_time_compare(x, y, len);
309}
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition ffi.cpp:301

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

311 {
312 Botan::secure_scrub_memory(mem, bytes);
313 return BOTAN_FFI_SUCCESS;
314}
void secure_scrub_memory(void *ptr, size_t n)
Definition mem_utils.cpp:24

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

153 {
154#if defined(BOTAN_HAS_SRP6)
155 return ffi_guard_thunk(__func__, [=]() -> int {
156 if(any_null_pointers(identity, password, salt, group_id, hash_id, b, rng_obj)) {
158 }
159 try {
160 std::vector<uint8_t> saltv(salt, salt + salt_len);
162 auto b_bn = Botan::BigInt::from_bytes({b, b_len});
163 auto [A_bn, K_sk] = Botan::srp6_client_agree(identity, password, group_id, hash_id, saltv, b_bn, rng);
164 auto ret_a = write_vec_output(A, A_len, A_bn.serialize());
165 auto ret_k = write_vec_output(K, K_len, K_sk.bits_of());
166 if(ret_a != BOTAN_FFI_SUCCESS) {
167 return ret_a;
168 }
169 if(ret_k != BOTAN_FFI_SUCCESS) {
170 return ret_k;
171 }
172 return BOTAN_FFI_SUCCESS;
173 } catch(Botan::Lookup_Error&) {
175 }
176 });
177#else
178 BOTAN_UNUSED(identity, password, group_id, hash_id, rng_obj);
179 BOTAN_UNUSED(salt, salt_len, b, b_len, A, A_len, K, K_len);
181#endif
182}
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition bigint.cpp:87
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:65

References Botan_FFI::any_null_pointers(), 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().

Referenced by botan_srp6_server_session_step1().

◆ 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 113 of file ffi_srp6.cpp.

120 {
121#if defined(BOTAN_HAS_SRP6)
122 return ffi_guard_thunk(__func__, [=]() -> int {
123 if(any_null_pointers(username, password, salt, group_id, hash_id)) {
125 }
126 try {
127 std::vector<uint8_t> salt_vec(salt, salt + salt_len);
128 auto verifier_bn = Botan::srp6_generate_verifier(username, password, salt_vec, group_id, hash_id);
129 return write_vec_output(verifier, verifier_len, verifier_bn.serialize());
130 } catch(Botan::Lookup_Error&) {
132 }
133 });
134#else
135 BOTAN_UNUSED(username, password, group_id, hash_id);
136 BOTAN_UNUSED(salt, salt_len, verifier, verifier_len);
138#endif
139}
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:128

References Botan_FFI::any_null_pointers(), 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().

Referenced by botan_srp6_server_session_step1().

◆ 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 45 of file ffi_srp6.cpp.

45 {
46#if defined(BOTAN_HAS_SRP6)
47 if(any_null_pointers(group_id, group_p_bytes)) {
49 }
50
51 return ffi_guard_thunk(__func__, [=]() -> int {
52 auto group = Botan::DL_Group::from_name(group_id);
53 *group_p_bytes = group.p_bytes();
54 return BOTAN_FFI_SUCCESS;
55 });
56#else
57 BOTAN_UNUSED(group_id, group_p_bytes);
59#endif
60}
static DL_Group from_name(std::string_view name)
Definition dl_group.cpp:217

References Botan_FFI::any_null_pointers(), 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().

Referenced by botan_srp6_server_session_step1().

◆ 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 41 of file ffi_srp6.cpp.

41 {
42 return BOTAN_FFI_CHECKED_DELETE(srp6);
43}

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(
34 __func__, [=]() -> int { return ffi_new_object(srp6, std::make_unique<Botan::SRP6_Server_Session>()); });
35#else
36 BOTAN_UNUSED(srp6);
38#endif
39}

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

◆ 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

References BOTAN_FFI_EXPORT, botan_srp6_client_agree(), botan_srp6_generate_verifier(), botan_srp6_group_size(), botan_srp6_server_session_step1(), botan_srp6_server_session_step2(), botan_zfec_decode(), and botan_zfec_encode().

Referenced by botan_srp6_server_session_step1().

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

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

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

Referenced by botan_srp6_server_session_step1().

◆ 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 167 of file ffi_rng.cpp.

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

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 67 of file ffi_totp.cpp.

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

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 44 of file ffi_totp.cpp.

44 {
45#if defined(BOTAN_HAS_TOTP)
46 return BOTAN_FFI_CHECKED_DELETE(totp);
47#else
48 BOTAN_UNUSED(totp);
50#endif
51}

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 53 of file ffi_totp.cpp.

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

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 return ffi_new_object(totp, std::move(otp));
37 });
38#else
39 BOTAN_UNUSED(totp, key, key_len, hash_algo, digits, time_step);
41#endif
42}

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

◆ 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 203 of file ffi_tpm2.cpp.

203 {
204#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
205 return BOTAN_FFI_CHECKED_DELETE(cbs);
206#else
207 BOTAN_UNUSED(cbs);
209#endif
210}

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 172 of file ffi_tpm2.cpp.

172 {
173#if defined(BOTAN_HAS_TPM2)
174 return BOTAN_FFI_CHECKED_DELETE(ctx);
175#else
176 BOTAN_UNUSED(ctx);
178#endif
179}

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 149 of file ffi_tpm2.cpp.

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

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 132 of file ffi_tpm2.cpp.

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

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

◆ 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 return ffi_new_object(ctx_out, std::move(ctx));
92 });
93#else
94 BOTAN_UNUSED(ctx_out, tcti_nameconf);
96#endif
97}

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

◆ 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 99 of file ffi_tpm2.cpp.

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

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

◆ 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 181 of file ffi_tpm2.cpp.

183 {
184#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
185 return ffi_guard_thunk(__func__, [=]() -> int {
186 if(cbs_out == nullptr || esys_ctx == nullptr) {
188 }
189
191
192 // Here, we just need to trust the user that they keep the passed-in RNG
193 // instance intact for the lifetime of the context.
194 std::shared_ptr<Botan::RandomNumberGenerator> rng_ptr(&rng_ref, [](auto*) {});
195 return ffi_new_object(cbs_out, Botan::TPM2::use_botan_crypto_backend(esys_ctx, rng_ptr));
196 });
197#else
198 BOTAN_UNUSED(cbs_out, esys_ctx, rng);
200#endif
201}
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_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 212 of file ffi_tpm2.cpp.

216 {
217#if defined(BOTAN_HAS_TPM2)
218 return BOTAN_FFI_VISIT(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int {
219 if(rng_out == nullptr) {
221 }
222
223 return ffi_new_object(
224 rng_out, std::make_unique<Botan::TPM2::RandomNumberGenerator>(ctx_wrapper.ctx, sessions(s1, s2, s3)));
225 });
226#else
227 BOTAN_UNUSED(rng_out, ctx, s1, s2, s3);
229#endif
230}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::ffi_new_object().

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

249 {
250#if defined(BOTAN_HAS_TPM2)
251 return BOTAN_FFI_CHECKED_DELETE(session);
252#else
253 BOTAN_UNUSED(session);
255#endif
256}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_tpm2_supports_crypto_backend()

int botan_tpm2_supports_crypto_backend ( void )

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

232 {
233#if defined(BOTAN_HAS_TPM2)
234 return BOTAN_FFI_VISIT(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int {
235 if(session_out == nullptr) {
237 }
238
239 auto session = std::make_unique<botan_tpm2_session_wrapper>();
240 session->session = Botan::TPM2::Session::unauthenticated_session(ctx_wrapper.ctx);
241 return ffi_new_object(session_out, std::move(session));
242 });
243#else
244 BOTAN_UNUSED(session_out, ctx);
246#endif
247}
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_VISIT, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), 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.

Returns 0 if the library was not built from an official release

Definition at line 297 of file ffi.cpp.

297 {
299}
uint32_t version_datestamp()
Definition version.cpp:32

References Botan::version_datestamp().

◆ botan_version_major()

uint32_t botan_version_major ( void )

Return the major version of the library

Definition at line 285 of file ffi.cpp.

285 {
286 return Botan::version_major();
287}
uint32_t version_major()
Definition version.cpp:55

References Botan::version_major().

◆ botan_version_minor()

uint32_t botan_version_minor ( void )

Return the minor version of the library

Definition at line 289 of file ffi.cpp.

289 {
290 return Botan::version_minor();
291}
uint32_t version_minor()
Definition version.cpp:59

References Botan::version_minor().

◆ botan_version_patch()

uint32_t botan_version_patch ( void )

Return the patch version of the library

Definition at line 293 of file ffi.cpp.

293 {
294 return Botan::version_patch();
295}
uint32_t version_patch()
Definition version.cpp:63

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

281 {
282 return Botan::version_cstr();
283}
const char * version_cstr()
Definition version.cpp:20

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 149 of file ffi_cert.cpp.

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

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 164 of file ffi_cert.cpp.

164 {
165#if defined(BOTAN_HAS_X509_CERTIFICATES)
166 return BOTAN_FFI_CHECKED_DELETE(cert);
167#else
168 BOTAN_UNUSED(cert);
170#endif
171}

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 47 of file ffi_cert.cpp.

47 {
48 if(cert_obj == nullptr) {
50 }
51
52#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
53
54 return ffi_guard_thunk(__func__, [=]() -> int {
55 auto c = std::make_unique<Botan::X509_Certificate>(safe_get(cert));
56 return ffi_new_object(cert_obj, std::move(c));
57 });
58
59#else
60 BOTAN_UNUSED(cert);
62#endif
63}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 233 of file ffi_cert.cpp.

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

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 220 of file ffi_cert.cpp.

220 {
221#if defined(BOTAN_HAS_X509_CERTIFICATES)
222 // TODO(Botan4) change the type of out and remove this cast
223
224 return BOTAN_FFI_VISIT(cert, [=](const auto& c) {
225 return write_str_output(reinterpret_cast<char*>(out), out_len, c.fingerprint(hash));
226 });
227#else
228 BOTAN_UNUSED(cert, hash, out, out_len);
230#endif
231}

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 100 of file ffi_cert.cpp.

101 {
102#if defined(BOTAN_HAS_X509_CERTIFICATES)
103 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
104 auto issuer_info = c.issuer_info(key);
105 if(index < issuer_info.size()) {
106 // TODO(Botan4) change the type of out and remove this cast
107 return write_str_output(reinterpret_cast<char*>(out), out_len, c.issuer_info(key).at(index));
108 } else {
110 }
111 });
112#else
113 BOTAN_UNUSED(cert, key, index, out, out_len);
115#endif
116}

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 82 of file ffi_cert.cpp.

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 251 of file ffi_cert.cpp.

251 {
252 return copy_view_bin(out, out_len, botan_x509_cert_view_public_key_bits, cert);
253}
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:255

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 211 of file ffi_cert.cpp.

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

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 118 of file ffi_cert.cpp.

119 {
120#if defined(BOTAN_HAS_X509_CERTIFICATES)
121 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
122 auto subject_info = c.subject_info(key);
123 if(index < subject_info.size()) {
124 // TODO(Botan4) change the type of out and remove this cast
125 return write_str_output(reinterpret_cast<char*>(out), out_len, c.subject_info(key).at(index));
126 } else {
128 }
129 });
130#else
131 BOTAN_UNUSED(cert, key, index, out, out_len);
133#endif
134}

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 242 of file ffi_cert.cpp.

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

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 183 of file ffi_cert.cpp.

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

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

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

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 265 of file ffi_cert.cpp.

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

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

65 {
66 if(cert_obj == nullptr || cert_bits == nullptr) {
68 }
69
70#if defined(BOTAN_HAS_X509_CERTIFICATES)
71 return ffi_guard_thunk(__func__, [=]() -> int {
72 Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
73 auto c = std::make_unique<Botan::X509_Certificate>(bits);
74 return ffi_new_object(cert_obj, std::move(c));
75 });
76#else
77 BOTAN_UNUSED(cert_bits_len);
79#endif
80}

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

◆ 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 == nullptr || cert_path == nullptr) {
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 return ffi_new_object(cert_obj, std::move(c));
40 });
41
42#else
44#endif
45}

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

◆ botan_x509_cert_not_after()

int botan_x509_cert_not_after ( botan_x509_cert_t cert,
uint64_t * time_since_epoch )

Definition at line 202 of file ffi_cert.cpp.

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

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 193 of file ffi_cert.cpp.

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

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 136 of file ffi_cert.cpp.

136 {
137 return copy_view_str(reinterpret_cast<uint8_t*>(out), out_len, botan_x509_cert_view_as_string, cert);
138}
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:140

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

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

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 278 of file ffi_cert.cpp.

287 {
288 if(required_strength == 0) {
289 required_strength = 110;
290 }
291
292#if defined(BOTAN_HAS_X509_CERTIFICATES)
293 return ffi_guard_thunk(__func__, [=]() -> int {
294 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
296 const auto validation_time = reference_time == 0
297 ? std::chrono::system_clock::now()
298 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
299
300 std::vector<Botan::X509_Certificate> end_certs;
301 end_certs.push_back(safe_get(cert));
302 for(size_t i = 0; i != intermediates_len; ++i) {
303 end_certs.push_back(safe_get(intermediates[i]));
304 }
305
306 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
307 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
308 std::vector<Botan::Certificate_Store*> trusted_roots;
309
310 if(trusted_path != nullptr && *trusted_path != 0) {
311 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
312 trusted_roots.push_back(trusted_from_path.get());
313 }
314
315 if(trusted_len > 0) {
316 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
317 for(size_t i = 0; i != trusted_len; ++i) {
318 trusted_extra->add_certificate(safe_get(trusted[i]));
319 }
320 trusted_roots.push_back(trusted_extra.get());
321 }
322
323 Botan::Path_Validation_Restrictions restrictions(false, required_strength);
324
325 auto validation_result =
326 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
327
328 if(result_code != nullptr) {
329 *result_code = static_cast<int>(validation_result.result());
330 }
331
332 if(validation_result.successful_validation()) {
333 return 0;
334 } else {
335 return 1;
336 }
337 });
338#else
339 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
340 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time);
342#endif
343}
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:883
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 != nullptr && *trusted_path != 0) {
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 != nullptr) {
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 140 of file ffi_cert.cpp.

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

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 255 of file ffi_cert.cpp.

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

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 381 of file ffi_cert.cpp.

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

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

◆ botan_x509_crl_load_file()

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

Definition at line 364 of file ffi_cert.cpp.

364 {
365 if(crl_obj == nullptr || crl_path == nullptr) {
367 }
368
369#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
370
371 return ffi_guard_thunk(__func__, [=]() -> int {
372 auto c = std::make_unique<Botan::X509_CRL>(crl_path);
373 return ffi_new_object(crl_obj, std::move(c));
374 });
375
376#else
378#endif
379}

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

◆ 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:445

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

Referenced by botan_srp6_server_session_step1().

◆ 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:402

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

Referenced by botan_srp6_server_session_step1().