Botan 3.11.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   20260303
#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_entry_struct * botan_x509_crl_entry_t
typedef struct botan_x509_crl_struct * botan_x509_crl_t
typedef struct botan_x509_general_name_struct * botan_x509_general_name_t
typedef struct botan_xof_struct * botan_xof_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_OUT_OF_RANGE = -36 , 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
}
enum  botan_x509_crl_reason_code {
  BOTAN_CRL_ENTRY_UNSPECIFIED = 0 , BOTAN_CRL_ENTRY_KEY_COMPROMISE = 1 , BOTAN_CRL_ENTRY_CA_COMPROMISE = 2 , BOTAN_CRL_ENTRY_AFFILIATION_CHANGED = 3 ,
  BOTAN_CRL_ENTRY_SUPERSEDED = 4 , BOTAN_CRL_ENTRY_CESSATION_OF_OPERATION = 5 , BOTAN_CRL_ENTRY_CERTIFICATE_HOLD = 6 , BOTAN_CRL_ENTRY_REMOVE_FROM_CRL = 8 ,
  BOTAN_CRL_ENTRY_PRIVILEGE_WITHDRAWN = 9 , BOTAN_CRL_ENTRY_AA_COMPROMISE = 10
}
enum  botan_x509_general_name_types {
  BOTAN_X509_OTHER_NAME = 0 , BOTAN_X509_EMAIL_ADDRESS = 1 , BOTAN_X509_DNS_NAME = 2 , BOTAN_X509_DIRECTORY_NAME = 4 ,
  BOTAN_X509_URI = 6 , BOTAN_X509_IP_ADDRESS = 7
}
enum  botan_x509_value_type {
  BOTAN_X509_SERIAL_NUMBER = 0 , BOTAN_X509_SUBJECT_DN_BITS = 1 , BOTAN_X509_ISSUER_DN_BITS = 2 , BOTAN_X509_SUBJECT_KEY_IDENTIFIER = 3 ,
  BOTAN_X509_AUTHORITY_KEY_IDENTIFIER = 4 , BOTAN_X509_PUBLIC_KEY_PKCS8_BITS = 200 , BOTAN_X509_TBS_DATA_BITS = 201 , BOTAN_X509_SIGNATURE_SCHEME_BITS = 202 ,
  BOTAN_X509_SIGNATURE_BITS = 203 , BOTAN_X509_DER_ENCODING = 300 , BOTAN_X509_PEM_ENCODING = 301 , BOTAN_X509_CRL_DISTRIBUTION_URLS = 400 ,
  BOTAN_X509_OCSP_RESPONDER_URLS = 401 , BOTAN_X509_CA_ISSUERS_URLS = 402
}

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_unregister (botan_asn1_oid_t oid)
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 radix, char *out, size_t *out_len)
int botan_mp_to_uint32 (botan_mp_t mp, uint32_t *val)
int botan_mp_view_bin (botan_mp_t mp, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_mp_view_hex (botan_mp_t mp, botan_view_ctx ctx, botan_view_str_fn view)
int botan_mp_view_str (botan_mp_t mp, uint8_t radix, botan_view_ctx ctx, botan_view_str_fn view)
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_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_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_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_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_ecdh_sec1 (botan_pubkey_t *key, const uint8_t sec1[], size_t sec1_len, 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_ecdsa_sec1 (botan_pubkey_t *key, const uint8_t sec1[], size_t sec1_len, 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_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_rsa_pkcs1 (botan_pubkey_t *key, const uint8_t bits[], size_t len)
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_sm2_sec1 (botan_pubkey_t *key, const uint8_t sec1[], size_t sec1_len, 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_extended_usage_oid (botan_x509_cert_t cert, botan_asn1_oid_t oid)
int botan_x509_cert_allowed_extended_usage_str (botan_x509_cert_t cert, const char *oid)
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_excluded_name_constraints (botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *constraint)
int botan_x509_cert_excluded_name_constraints_count (botan_x509_cert_t cert, size_t *count)
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_issuer_dn_count (botan_x509_cert_t cert, const char *key, size_t *count)
int botan_x509_cert_get_path_length_constraint (botan_x509_cert_t cert, size_t *path_limit)
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_dn_count (botan_x509_cert_t cert, const char *key, size_t *count)
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_is_ca (botan_x509_cert_t cert)
int botan_x509_cert_issuer_alternative_names (botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *alt_name)
int botan_x509_cert_issuer_alternative_names_count (botan_x509_cert_t cert, size_t *count)
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_permitted_name_constraints (botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *constraint)
int botan_x509_cert_permitted_name_constraints_count (botan_x509_cert_t cert, size_t *count)
int botan_x509_cert_serial_number (botan_x509_cert_t cert, botan_mp_t *serial_number)
int botan_x509_cert_subject_alternative_names (botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *alt_name)
int botan_x509_cert_subject_alternative_names_count (botan_x509_cert_t cert, size_t *count)
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_binary_values (botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_cert_view_binary_values_count (botan_x509_cert_t cert, botan_x509_value_type value_type, size_t *count)
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_cert_view_string_values (botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view)
int botan_x509_cert_view_string_values_count (botan_x509_cert_t cert, botan_x509_value_type value_type, size_t *count)
int botan_x509_crl_create (botan_x509_crl_t *crl_obj, botan_rng_t rng, botan_x509_cert_t ca_cert, botan_privkey_t ca_key, uint64_t issue_time, uint32_t next_update, const char *hash_fn, const char *padding)
int botan_x509_crl_destroy (botan_x509_crl_t crl)
int botan_x509_crl_entries (botan_x509_crl_t crl, size_t index, botan_x509_crl_entry_t *entry)
int botan_x509_crl_entries_count (botan_x509_crl_t crl, size_t *count)
int botan_x509_crl_entry_create (botan_x509_crl_entry_t *entry, botan_x509_cert_t cert, int reason_code)
int botan_x509_crl_entry_destroy (botan_x509_crl_entry_t entry)
int botan_x509_crl_entry_reason (botan_x509_crl_entry_t entry, int *reason_code)
int botan_x509_crl_entry_revocation_date (botan_x509_crl_entry_t entry, uint64_t *time_since_epoch)
int botan_x509_crl_entry_serial_number (botan_x509_crl_entry_t entry, botan_mp_t *serial_number)
int botan_x509_crl_entry_view_serial_number (botan_x509_crl_entry_t entry, botan_view_ctx ctx, botan_view_bin_fn view)
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_crl_next_update (botan_x509_crl_t crl, uint64_t *time_since_epoch)
int botan_x509_crl_this_update (botan_x509_crl_t crl, uint64_t *time_since_epoch)
int botan_x509_crl_update (botan_x509_crl_t *crl_obj, botan_x509_crl_t last_crl, botan_rng_t rng, botan_x509_cert_t ca_cert, botan_privkey_t ca_key, uint64_t issue_time, uint32_t next_update, const botan_x509_crl_entry_t *new_entries, size_t new_entries_len, const char *hash_fn, const char *padding)
int botan_x509_crl_verify_signature (botan_x509_crl_t crl, botan_pubkey_t key)
int botan_x509_crl_view_binary_values (botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_crl_view_binary_values_count (botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t *count)
int botan_x509_crl_view_string_values (botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view)
int botan_x509_crl_view_string_values_count (botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t *count)
int botan_x509_general_name_destroy (botan_x509_general_name_t alt_names)
int botan_x509_general_name_get_type (botan_x509_general_name_t name, unsigned int *type)
int botan_x509_general_name_view_binary_value (botan_x509_general_name_t name, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_general_name_view_string_value (botan_x509_general_name_t name, botan_view_ctx ctx, botan_view_str_fn view)
int botan_x509_is_revoked (botan_x509_crl_t crl, botan_x509_cert_t cert)
int botan_xof_accepts_input (botan_xof_t xof)
int botan_xof_block_size (botan_xof_t xof, size_t *block_size)
int botan_xof_clear (botan_xof_t xof)
int botan_xof_copy_state (botan_xof_t *dest, botan_xof_t source)
int botan_xof_destroy (botan_xof_t xof)
int botan_xof_init (botan_xof_t *xof, const char *xof_name, uint32_t flags)
int botan_xof_name (botan_xof_t xof, char *name, size_t *name_len)
int botan_xof_output (botan_xof_t xof, uint8_t *out, size_t out_len)
int botan_xof_update (botan_xof_t xof, const uint8_t *in, size_t in_len)
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 1440 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 641 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_ENCRYPT

#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0

Definition at line 640 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 639 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 734 of file ffi.h.

Referenced by botan_cipher_update().

◆ BOTAN_FFI_API_VERSION

#define BOTAN_FFI_API_VERSION   20260303

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

◆ BOTAN_FFI_DEPRECATED

#define BOTAN_FFI_DEPRECATED ( msg)

Definition at line 106 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 91 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 249 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 2852 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 1512 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 1224 of file ffi.h.

◆ botan_block_cipher_t

typedef struct botan_block_cipher_struct* botan_block_cipher_t

Definition at line 937 of file ffi.h.

◆ botan_cipher_t

typedef struct botan_cipher_struct* botan_cipher_t

Definition at line 637 of file ffi.h.

◆ botan_ec_group_t

typedef struct botan_ec_group_struct* botan_ec_group_t

Definition at line 1273 of file ffi.h.

◆ botan_fpe_t

typedef struct botan_fpe_struct* botan_fpe_t

Format Preserving Encryption

Definition at line 2850 of file ffi.h.

◆ botan_hash_t

typedef struct botan_hash_struct* botan_hash_t

Definition at line 461 of file ffi.h.

◆ botan_hotp_t

typedef struct botan_hotp_struct* botan_hotp_t

HOTP

Definition at line 2778 of file ffi.h.

◆ botan_mac_t

typedef struct botan_mac_struct* botan_mac_t

Definition at line 541 of file ffi.h.

◆ botan_mp_t

typedef struct botan_mp_struct* botan_mp_t

Definition at line 1003 of file ffi.h.

◆ botan_pk_op_decrypt_t

typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t

Definition at line 2046 of file ffi.h.

◆ botan_pk_op_encrypt_t

typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t

Definition at line 2022 of file ffi.h.

◆ botan_pk_op_ka_t

typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t

Definition at line 2108 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 2167 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 2137 of file ffi.h.

◆ botan_pk_op_sign_t

typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t

Definition at line 2069 of file ffi.h.

◆ botan_pk_op_verify_t

typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t

Definition at line 2089 of file ffi.h.

◆ botan_privkey_t

typedef struct botan_privkey_struct* botan_privkey_t

Definition at line 1417 of file ffi.h.

◆ botan_pubkey_t

typedef struct botan_pubkey_struct* botan_pubkey_t

Definition at line 1650 of file ffi.h.

◆ botan_rng_t

typedef struct botan_rng_struct* botan_rng_t

RNG type

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

◆ botan_totp_t

typedef struct botan_totp_struct* botan_totp_t

TOTP

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

◆ botan_tpm2_ctx_t

typedef struct botan_tpm2_ctx_struct* botan_tpm2_ctx_t

TPM2 context

Definition at line 3031 of file ffi.h.

◆ botan_tpm2_session_t

typedef struct botan_tpm2_session_struct* botan_tpm2_session_t

TPM2 session

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

◆ botan_view_ctx

typedef void* botan_view_ctx

The application provided context for a view function

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

◆ botan_x509_cert_t

typedef struct botan_x509_cert_struct* botan_x509_cert_t

Definition at line 2231 of file ffi.h.

◆ botan_x509_crl_entry_t

typedef struct botan_x509_crl_entry_struct* botan_x509_crl_entry_t

Definition at line 2546 of file ffi.h.

◆ botan_x509_crl_t

typedef struct botan_x509_crl_struct* botan_x509_crl_t

Definition at line 2545 of file ffi.h.

◆ botan_x509_general_name_t

typedef struct botan_x509_general_name_struct* botan_x509_general_name_t

Definition at line 2414 of file ffi.h.

◆ botan_xof_t

typedef struct botan_xof_struct* botan_xof_t

Definition at line 383 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_OUT_OF_RANGE 
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 115 of file ffi.h.

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

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

2373 {
2374 NO_CONSTRAINTS = 0,
2375 DIGITAL_SIGNATURE = 32768,
2376 NON_REPUDIATION = 16384,
2377 KEY_ENCIPHERMENT = 8192,
2378 DATA_ENCIPHERMENT = 4096,
2379 KEY_AGREEMENT = 2048,
2380 KEY_CERT_SIGN = 1024,
2381 CRL_SIGN = 512,
2382 ENCIPHER_ONLY = 256,
2383 DECIPHER_ONLY = 128
2384};
@ KEY_ENCIPHERMENT
Definition ffi.h:2377
@ NO_CONSTRAINTS
Definition ffi.h:2374
@ CRL_SIGN
Definition ffi.h:2381
@ DIGITAL_SIGNATURE
Definition ffi.h:2375
@ KEY_AGREEMENT
Definition ffi.h:2379
@ DATA_ENCIPHERMENT
Definition ffi.h:2378
@ KEY_CERT_SIGN
Definition ffi.h:2380
@ ENCIPHER_ONLY
Definition ffi.h:2382
@ NON_REPUDIATION
Definition ffi.h:2376
@ DECIPHER_ONLY
Definition ffi.h:2383

◆ botan_x509_crl_reason_code

Enumerator
BOTAN_CRL_ENTRY_UNSPECIFIED 
BOTAN_CRL_ENTRY_KEY_COMPROMISE 
BOTAN_CRL_ENTRY_CA_COMPROMISE 
BOTAN_CRL_ENTRY_AFFILIATION_CHANGED 
BOTAN_CRL_ENTRY_SUPERSEDED 
BOTAN_CRL_ENTRY_CESSATION_OF_OPERATION 
BOTAN_CRL_ENTRY_CERTIFICATE_HOLD 
BOTAN_CRL_ENTRY_REMOVE_FROM_CRL 
BOTAN_CRL_ENTRY_PRIVILEGE_WITHDRAWN 
BOTAN_CRL_ENTRY_AA_COMPROMISE 

Definition at line 2577 of file ffi.h.

2577 {
2588};
@ BOTAN_CRL_ENTRY_PRIVILEGE_WITHDRAWN
Definition ffi.h:2586
@ BOTAN_CRL_ENTRY_UNSPECIFIED
Definition ffi.h:2578
@ BOTAN_CRL_ENTRY_SUPERSEDED
Definition ffi.h:2582
@ BOTAN_CRL_ENTRY_CERTIFICATE_HOLD
Definition ffi.h:2584
@ BOTAN_CRL_ENTRY_CESSATION_OF_OPERATION
Definition ffi.h:2583
@ BOTAN_CRL_ENTRY_CA_COMPROMISE
Definition ffi.h:2580
@ BOTAN_CRL_ENTRY_REMOVE_FROM_CRL
Definition ffi.h:2585
@ BOTAN_CRL_ENTRY_AA_COMPROMISE
Definition ffi.h:2587
@ BOTAN_CRL_ENTRY_KEY_COMPROMISE
Definition ffi.h:2579
@ BOTAN_CRL_ENTRY_AFFILIATION_CHANGED
Definition ffi.h:2581

◆ botan_x509_general_name_types

GeneralName type identifiers as defined in RFC 5280 A.2 (GeneralName ::= CHOICE) Type identifiers that are omitted here are (currently) not supported. Also, there is currently no way to access OTHER_NAME values via the FFI.

Enumerator
BOTAN_X509_OTHER_NAME 
BOTAN_X509_EMAIL_ADDRESS 
BOTAN_X509_DNS_NAME 
BOTAN_X509_DIRECTORY_NAME 
BOTAN_X509_URI 
BOTAN_X509_IP_ADDRESS 

Definition at line 2421 of file ffi.h.

2421 {
2426 BOTAN_X509_URI = 6,
2428};
@ BOTAN_X509_DNS_NAME
Definition ffi.h:2424
@ BOTAN_X509_DIRECTORY_NAME
Definition ffi.h:2425
@ BOTAN_X509_OTHER_NAME
Definition ffi.h:2422
@ BOTAN_X509_EMAIL_ADDRESS
Definition ffi.h:2423
@ BOTAN_X509_IP_ADDRESS
Definition ffi.h:2427
@ BOTAN_X509_URI
Definition ffi.h:2426

◆ botan_x509_value_type

Generic values that may be retrieved from X.509 certificates or CRLs via the generic getter functions.

When extending this list the existing entries must stay backward-compatible to remain ABI compatible across versions. Therefore, new values must be added to the end of this list.

See:

Enumerator
BOTAN_X509_SERIAL_NUMBER 
BOTAN_X509_SUBJECT_DN_BITS 

singleton binary big-endian encoding

BOTAN_X509_ISSUER_DN_BITS 

singleton binary DER encoding of the subject distinguished name

BOTAN_X509_SUBJECT_KEY_IDENTIFIER 

singleton binary DER encoding of the issuer distinguished name

BOTAN_X509_AUTHORITY_KEY_IDENTIFIER 

singleton binary encoding

BOTAN_X509_PUBLIC_KEY_PKCS8_BITS 

singleton binary encoding

BOTAN_X509_TBS_DATA_BITS 

singleton binary DER encoding of the PKCS#8 public key

BOTAN_X509_SIGNATURE_SCHEME_BITS 

singleton binary DER encoding

BOTAN_X509_SIGNATURE_BITS 

singleton binary DER encoding of the algorithm identifier

BOTAN_X509_DER_ENCODING 

singleton binary signature bits

BOTAN_X509_PEM_ENCODING 

singleton binary DER encoding of the whole object

BOTAN_X509_CRL_DISTRIBUTION_URLS 

singleton string value PEM encoding of the whole object

BOTAN_X509_OCSP_RESPONDER_URLS 

multi-value string of the CRL distribution points

BOTAN_X509_CA_ISSUERS_URLS 

multi-value string of the OCSP responder URLs

Definition at line 2246 of file ffi.h.

2246 {
2247 BOTAN_X509_SERIAL_NUMBER = 0, /** singleton binary big-endian encoding */
2248 BOTAN_X509_SUBJECT_DN_BITS = 1, /** singleton binary DER encoding of the subject distinguished name */
2249 BOTAN_X509_ISSUER_DN_BITS = 2, /** singleton binary DER encoding of the issuer distinguished name */
2250 BOTAN_X509_SUBJECT_KEY_IDENTIFIER = 3, /** singleton binary encoding */
2251 BOTAN_X509_AUTHORITY_KEY_IDENTIFIER = 4, /** singleton binary encoding */
2252
2253 BOTAN_X509_PUBLIC_KEY_PKCS8_BITS = 200, /** singleton binary DER encoding of the PKCS#8 public key */
2254 BOTAN_X509_TBS_DATA_BITS = 201, /** singleton binary DER encoding */
2255 BOTAN_X509_SIGNATURE_SCHEME_BITS = 202, /** singleton binary DER encoding of the algorithm identifier */
2256 BOTAN_X509_SIGNATURE_BITS = 203, /** singleton binary signature bits */
2257
2258 BOTAN_X509_DER_ENCODING = 300, /** singleton binary DER encoding of the whole object */
2259 BOTAN_X509_PEM_ENCODING = 301, /** singleton string value PEM encoding of the whole object */
2260
2261 BOTAN_X509_CRL_DISTRIBUTION_URLS = 400, /** multi-value string of the CRL distribution points */
2262 BOTAN_X509_OCSP_RESPONDER_URLS = 401, /** multi-value string of the OCSP responder URLs */
2263 BOTAN_X509_CA_ISSUERS_URLS = 402, /** multi-value string of the CA issuer URLs */
botan_x509_value_type
Definition ffi.h:2246
@ BOTAN_X509_AUTHORITY_KEY_IDENTIFIER
Definition ffi.h:2251
@ BOTAN_X509_SUBJECT_KEY_IDENTIFIER
Definition ffi.h:2250
@ BOTAN_X509_TBS_DATA_BITS
Definition ffi.h:2254
@ BOTAN_X509_SIGNATURE_BITS
Definition ffi.h:2256
@ BOTAN_X509_PUBLIC_KEY_PKCS8_BITS
Definition ffi.h:2253
@ BOTAN_X509_DER_ENCODING
Definition ffi.h:2258
@ BOTAN_X509_PEM_ENCODING
Definition ffi.h:2259
@ BOTAN_X509_OCSP_RESPONDER_URLS
Definition ffi.h:2262
@ BOTAN_X509_SIGNATURE_SCHEME_BITS
Definition ffi.h:2255
@ BOTAN_X509_SUBJECT_DN_BITS
Definition ffi.h:2248
@ BOTAN_X509_CRL_DISTRIBUTION_URLS
Definition ffi.h:2261
@ BOTAN_X509_SERIAL_NUMBER
Definition ffi.h:2247
@ BOTAN_X509_ISSUER_DN_BITS
Definition ffi.h:2249
@ BOTAN_X509_CA_ISSUERS_URLS
Definition ffi.h:2263

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

350 {
351 return ffi_guard_thunk(__func__, [=]() -> int {
352 if(*out_len < Botan::base64_decode_max_output(in_len)) {
353 *out_len = Botan::base64_decode_max_output(in_len);
355 }
356
357 *out_len = Botan::base64_decode(out, std::string(base64_str, in_len));
358 return BOTAN_FFI_SUCCESS;
359 });
360}
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:167
size_t base64_decode_max_output(size_t input_length)
Definition base64.cpp:199

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

343 {
344 return ffi_guard_thunk(__func__, [=]() -> int {
345 const std::string base64 = Botan::base64_encode(in, len);
346 return Botan_FFI::write_str_output(out, out_len, base64);
347 });
348}
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:265
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition base64.cpp:159

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

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

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

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

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

116 {
117 return BOTAN_FFI_CHECKED_DELETE(cipher);
118}

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

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

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

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

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

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

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

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

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

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

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

99 {
100 return ffi_guard_thunk(__func__, [=]() -> int {
103
104 std::unique_ptr<Botan::Cipher_Mode> mode(Botan::Cipher_Mode::create(cipher_name, dir));
105 if(!mode) {
107 }
108
109 const size_t update_size = ffi_choose_update_size(*mode);
110 const size_t ideal_update_size = std::max(mode->ideal_granularity(), update_size);
111
112 return ffi_new_object(cipher, std::move(mode), update_size, ideal_update_size);
113 });
114}
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:640
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
Definition ffi.h:639
Flags flags(Flag flags)
Definition p11.h:1227

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

◆ botan_cipher_update()

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

Encrypt/Decrypt some data and/or finalize the encryption/decryption.

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

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

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

See also
botan_cipher_requires_entire_message().

Definition at line 172 of file ffi_cipher.cpp.

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

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

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

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

313 {
314 auto same = Botan::CT::is_equal(x, y, len);
315 // Return 0 if same or -1 otherwise
316 return static_cast<int>(same.select(1, 0)) - 1;
317}
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:798

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

189 {
190 return BOTAN_FFI_VISIT(curve1_w, [=](const auto& curve1) -> int { return curve1 == safe_get(curve2_w); });
191}

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

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

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

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

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

◆ 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 170 of file ffi_ec.cpp.

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

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

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

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

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

◆ 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 179 of file ffi_ec.cpp.

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

◆ 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 184 of file ffi_ec.cpp.

184 {
185 return botan_ec_group_get_component(
186 order, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_order(); });
187}

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

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

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

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

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

◆ botan_ec_group_unregister()

int botan_ec_group_unregister ( botan_asn1_oid_t oid)

Unregister a previously registered group.

Parameters
oidthe oid associated with the group to unregister
Returns
1 if the group was found and unregistered, else 0

Using this is discouraged for normal use. This is only useful or necessary if you are registering a very large number of distinct groups, and need to worry about memory constraints.

Definition at line 123 of file ffi_ec.cpp.

123 {
124 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int { return Botan::EC_Group::unregister(o) ? 1 : 0; });
125}
static bool unregister(const OID &oid)
Definition ec_group.cpp:582

References BOTAN_FFI_VISIT, and Botan::EC_Group::unregister().

◆ 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 127 of file ffi_ec.cpp.

127 {
128 return BOTAN_FFI_VISIT(ec_group,
129 [=](const auto& g) -> int { return invoke_view_callback(view, ctx, g.DER_encode()); });
130}
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 132 of file ffi_ec.cpp.

132 {
133 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
134 return invoke_view_callback(view, ctx, g.PEM_encode(Botan::EC_Group_Encoding::NamedCurve));
135 });
136}

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

64 {
65 // TODO(Botan4) remove this implicit algorithm choice and reject nullptr algo_name
66 if(algo_name == nullptr) {
67 return botan_ec_privkey_create(key_obj, "ECDSA", ec_group_obj, rng_obj);
68 }
69
70 return ffi_guard_thunk(__func__, [=]() -> int {
71 if(key_obj == nullptr) {
73 }
74 *key_obj = nullptr;
75
76 const Botan::EC_Group ec_group = safe_get(ec_group_obj);
78
79 if(auto key = Botan::create_ec_private_key(algo_name, ec_group, rng)) {
80 return ffi_new_object(key_obj, std::move(key));
81 } else {
83 }
84 });
85}
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:61
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:448

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

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

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_OUT_OF_RANGE, 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 138 of file ffi.cpp.

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

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

219 {
220 return BOTAN_HAS_FFI;
221}
#define BOTAN_HAS_FFI
Definition build.h:199

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

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

References BOTAN_FFI_SUCCESS.

◆ botan_fpe_decrypt()

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

Definition at line 78 of file ffi_fpe.cpp.

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

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

◆ botan_fpe_destroy()

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

Definition at line 56 of file ffi_fpe.cpp.

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

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_fpe_encrypt()

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

Definition at line 65 of file ffi_fpe.cpp.

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

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

◆ botan_fpe_fe1_init()

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

Definition at line 28 of file ffi_fpe.cpp.

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

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

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

336 {
337 return ffi_guard_thunk(__func__, [=]() -> int {
338 const std::vector<uint8_t> bin = Botan::hex_decode(hex_str, in_len);
339 return Botan_FFI::write_vec_output(out, out_len, bin);
340 });
341}
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:261
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition hex.cpp:72

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

328 {
329 return ffi_guard_thunk(__func__, [=]() -> int {
330 const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
331 Botan::hex_encode(out, in, len, uppercase);
332 return BOTAN_FFI_SUCCESS;
333 });
334}
#define BOTAN_FFI_HEX_LOWER_CASE
Definition ffi.h:249
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition hex.cpp:34

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

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

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

◆ botan_hotp_destroy()

int botan_hotp_destroy ( botan_hotp_t hotp)

Destroy a HOTP instance

Returns
0 if success, error if invalid object handle

Definition at line 44 of file ffi_hotp.cpp.

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

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

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

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

26 {
27 if(hotp == nullptr || key == nullptr || hash_algo == nullptr) {
29 }
30
31 *hotp = nullptr;
32
33#if defined(BOTAN_HAS_HOTP)
34 return ffi_guard_thunk(__func__, [=]() -> int {
35 auto otp = std::make_unique<Botan::HOTP>(key, key_len, hash_algo, digits);
36 return ffi_new_object(hotp, std::move(otp));
37 });
38#else
39 BOTAN_UNUSED(hotp, key, key_len, hash_algo, digits);
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_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 98 of file ffi_keywrap.cpp.

103 {
104 const std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
105
106 return botan_nist_kw_dec(cipher_name.c_str(), 0, wrapped_key, wrapped_key_len, kek, kek_len, key, key_len);
107}
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 87 of file ffi_keywrap.cpp.

92 {
93 const std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
94
95 return botan_nist_kw_enc(cipher_name.c_str(), 0, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
96}
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:50
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54

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

1487 {
1488 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
1490}

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

1500 {
1501 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1503}

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

144 {
145 return BOTAN_FFI_VISIT(result, [=](auto& res) {
146 if(result == x) {
147 res += safe_get(y);
148 } else {
149 res = safe_get(x) + safe_get(y);
150 }
151 });
152}

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

164 {
165 return BOTAN_FFI_VISIT(result, [=](auto& res) {
166 if(result == x) {
167 res += static_cast<Botan::word>(y);
168 } else {
169 res = safe_get(x) + static_cast<Botan::word>(y);
170 }
171 });
172}
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 35 of file ffi_mp.cpp.

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

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

278 {
279 return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.clear_bit(bit); });
280}

References BOTAN_FFI_VISIT.

◆ botan_mp_cmp()

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

Definition at line 218 of file ffi_mp.cpp.

218 {
219 return BOTAN_FFI_VISIT(x_w, [=](auto& x) { *result = x.cmp(safe_get(y_w)); });
220}

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

140 {
141 return BOTAN_FFI_CHECKED_DELETE(mp);
142}

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

194 {
195 return BOTAN_FFI_VISIT(quotient, [=](auto& q) {
198 safe_get(remainder) = r;
199 });
200}
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition divide.cpp:325

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

202 {
203 return BOTAN_FFI_VISIT(x_w, [=](const auto& x) -> int { return x == safe_get(y_w); });
204}

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

72 {
73 return BOTAN_FFI_VISIT(mp, [](auto& bn) { bn.flip_sign(); });
74}

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

76 {
77 return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn._assign_from_bytes({bin, bin_len}); });
78}

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

262 {
263 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = Botan::gcd(safe_get(x), safe_get(y)); });
264}
BigInt gcd(const BigInt &a, const BigInt &b)
Definition numthry.cpp:220

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

270 {
271 return BOTAN_FFI_VISIT(mp, [=](const auto& n) -> int { return n.get_bit(bit); });
272}

References BOTAN_FFI_VISIT.

◆ botan_mp_init()

int botan_mp_init ( botan_mp_t * mp)

Initialize an MPI

Definition at line 24 of file ffi_mp.cpp.

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

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

214 {
215 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_even(); });
216}

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

64 {
65 return BOTAN_FFI_VISIT(mp, [](const auto& bn) { return bn.is_negative() ? 1 : 0; });
66}

References BOTAN_FFI_VISIT.

◆ botan_mp_is_odd()

int botan_mp_is_odd ( botan_mp_t mp)

Definition at line 210 of file ffi_mp.cpp.

210 {
211 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_odd(); });
212}

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

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

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

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

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

206 {
207 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_zero(); });
208}

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

232 {
233 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) << shift; });
234}

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

240 {
241 return BOTAN_FFI_VISIT(out, [=](auto& o) {
243 });
244}
static BigInt zero()
Definition bigint.h:50
std::optional< BigInt > inverse_mod_general(const BigInt &x, const BigInt &mod)
Definition mod_inv.cpp:179

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

246 {
247 return BOTAN_FFI_VISIT(out, [=](auto& o) {
249 o = reducer.multiply(safe_get(x), safe_get(y));
250 });
251}
static Barrett_Reduction for_secret_modulus(const BigInt &m)
Definition barrett.cpp:23

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

184 {
185 return BOTAN_FFI_VISIT(result, [=](auto& res) {
186 if(result == x) {
187 res *= safe_get(y);
188 } else {
189 res = safe_get(x) * safe_get(y);
190 }
191 });
192}

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

282 {
283 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bits = n.bits(); });
284}

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

286 {
287 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bytes = n.bytes(); });
288}

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

227 {
228 return BOTAN_FFI_VISIT(
229 out, [=](auto& o) { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
230}
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition numthry.cpp:310

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

253 {
254 return BOTAN_FFI_VISIT(rng, [=](auto& r) { safe_get(rand_out).randomize(r, bits); });
255}

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

257 {
258 return BOTAN_FFI_VISIT(
259 rng, [=](auto& r) { safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
260}
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
Definition big_rand.cpp:44

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

236 {
237 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) >> shift; });
238}

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

274 {
275 return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.set_bit(bit); });
276}

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

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

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

60 {
61 return BOTAN_FFI_VISIT(dest, [=](auto& bn) { bn = safe_get(source); });
62}

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

47 {
48 return BOTAN_FFI_VISIT(mp, [=](auto& bn) {
49 if(radix != 10 && radix != 16) {
51 }
52
53 bn = Botan::BigInt::from_radix_digits(std::string_view(str), radix);
54 return BOTAN_FFI_SUCCESS;
55 });
56}
static BigInt from_radix_digits(std::string_view digits, size_t radix)
Definition big_code.cpp:125

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and Botan::BigInt::from_radix_digits().

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

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

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

154 {
155 return BOTAN_FFI_VISIT(result, [=](auto& res) {
156 if(result == x) {
157 res -= safe_get(y);
158 } else {
159 res = safe_get(x) - safe_get(y);
160 }
161 });
162}

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

174 {
175 return BOTAN_FFI_VISIT(result, [=](auto& res) {
176 if(result == x) {
177 res -= static_cast<Botan::word>(y);
178 } else {
179 res = safe_get(x) - static_cast<Botan::word>(y);
180 }
181 });
182}

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

222 {
223 return BOTAN_FFI_VISIT(x_w, [=](auto& x) { x.swap(safe_get(y_w)); });
224}

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

122 {
123 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { bn.serialize_to(std::span{vec, bn.bytes()}); });
124}

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 up to botan_mp_num_bytes(mp)*2 + 5 bytes

Prefer botan_mp_view_hex

Definition at line 80 of file ffi_mp.cpp.

80 {
81 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) {
82 const std::string hex = bn.to_hex_string();
83
84 // Check that we are about to write no more than the documented upper bound
85 const size_t upper_bound = 2 * bn.bytes() + 5;
86 BOTAN_ASSERT_NOMSG(hex.size() + 1 <= upper_bound);
87 std::memcpy(out, hex.c_str(), 1 + hex.size());
88 });
89}

References BOTAN_ASSERT_NOMSG, and BOTAN_FFI_VISIT.

◆ botan_mp_to_str()

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

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

Definition at line 98 of file ffi_mp.cpp.

98 {
99 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) -> int {
100 if(radix == 0 || radix == 10) {
101 return write_str_output(out, out_len, bn.to_dec_string());
102 } else if(radix == 16) {
103 return write_str_output(out, out_len, bn.to_hex_string());
104 } else {
106 }
107 });
108}

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

133 {
134 if(val == nullptr) {
136 }
137 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { *val = bn.to_u32bit(); });
138}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_mp_view_bin()

int botan_mp_view_bin ( botan_mp_t mp,
botan_view_ctx ctx,
botan_view_bin_fn view )

Definition at line 126 of file ffi_mp.cpp.

126 {
127 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) {
128 const auto bytes = bn.serialize();
129 return invoke_view_callback(view, ctx, bytes);
130 });
131}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_mp_view_hex()

int botan_mp_view_hex ( botan_mp_t mp,
botan_view_ctx ctx,
botan_view_str_fn view )

View the hex string encoding of the MPI.

Definition at line 91 of file ffi_mp.cpp.

91 {
92 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) -> int {
93 const std::string hex = bn.to_hex_string();
94 return invoke_view_callback(view, ctx, hex);
95 });
96}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_mp_view_str()

int botan_mp_view_str ( botan_mp_t mp,
uint8_t radix,
botan_view_ctx ctx,
botan_view_str_fn view )

View the MPI as a radix-N integer. Currently only radix 10 and radix 16 are supported

Definition at line 110 of file ffi_mp.cpp.

110 {
111 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) -> int {
112 if(radix == 10) {
113 return invoke_view_callback(view, ctx, bn.to_dec_string());
114 } else if(radix == 16) {
115 return invoke_view_callback(view, ctx, bn.to_hex_string());
116 } else {
118 }
119 });
120}

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

◆ 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 54 of file ffi_keywrap.cpp.

61 {
62#if defined(BOTAN_HAS_NIST_KEYWRAP)
63 return ffi_guard_thunk(__func__, [=]() -> int {
64 if(padded != 0 && padded != 1) {
66 }
67
68 auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
69 bc->set_key(kek, kek_len);
70
72
73 if(padded == 0) {
74 output = Botan::nist_key_unwrap(wrapped_key, wrapped_key_len, *bc);
75 } else {
76 output = Botan::nist_key_unwrap_padded(wrapped_key, wrapped_key_len, *bc);
77 }
78
79 return write_vec_output(key, key_len, output);
80 });
81#else
82 BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
84#endif
85}
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 22 of file ffi_keywrap.cpp.

29 {
30#if defined(BOTAN_HAS_NIST_KEYWRAP)
31 return ffi_guard_thunk(__func__, [=]() -> int {
32 if(padded != 0 && padded != 1) {
34 }
35 auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
36 bc->set_key(kek, kek_len);
37
38 std::vector<uint8_t> output;
39
40 if(padded == 0) {
41 output = Botan::nist_key_wrap(key, key_len, *bc);
42 } else {
43 output = Botan::nist_key_wrap_padded(key, key_len, *bc);
44 }
45
46 return write_vec_output(wrapped_key, wrapped_key_len, output);
47 });
48#else
49 BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
51#endif
52}
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 63 of file ffi_oid.cpp.

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

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 18 of file ffi_oid.cpp.

18 {
19 return BOTAN_FFI_CHECKED_DELETE(oid);
20}

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 59 of file ffi_oid.cpp.

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

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
oidhandle to the resulting OID
oid_strthe name of the OID to create
Returns
negative number on error, or zero on success

Definition at line 22 of file ffi_oid.cpp.

22 {
23 return ffi_guard_thunk(__func__, [=]() -> int {
24 if(oid_obj == nullptr || oid_str == nullptr) {
26 }
27 Botan::OID oid;
28 // This returns a Lookup_Error if an unknown name is passed,
29 // which would get turned into NOT_IMPLEMENTED
30 try {
31 oid = Botan::OID::from_string(oid_str);
32 } catch(Botan::Lookup_Error&) {
34 }
35 auto oid_ptr = std::make_unique<Botan::OID>(std::move(oid));
36 return ffi_new_object(oid_obj, std::move(oid_ptr));
37 });
38}
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 40 of file ffi_oid.cpp.

40 {
41 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int {
42 if(name == nullptr) {
44 }
46 return BOTAN_FFI_SUCCESS;
47 });
48}
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 54 of file ffi_oid.cpp.

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

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 50 of file ffi_oid.cpp.

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

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

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

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

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

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

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

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

33 {
34 // TODO(Botan4) remove this implicit algorithm choice and reject nullptr algo_name
35 if(algo_name == nullptr) {
36 return botan_privkey_create(key_obj, "RSA", algo_params, rng_obj);
37 }
38
39 return ffi_guard_thunk(__func__, [=]() -> int {
40 if(key_obj == nullptr) {
42 }
43
44 *key_obj = nullptr;
45 if(rng_obj == nullptr) {
47 }
48
49 const std::string params(algo_params != nullptr ? algo_params : "");
50
52
53 if(auto key = Botan::create_private_key(algo_name, rng, params)) {
54 return ffi_new_object(key_obj, std::move(key));
55 } else {
57 }
58 });
59}
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:30
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:493

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

597 {
598 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
599}
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition ffi_pkey.cpp:30

References botan_privkey_create().

◆ botan_privkey_create_ecdh()

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

Definition at line 637 of file ffi_pkey_algs.cpp.

637 {
638 if(key_obj == nullptr || param_str == nullptr) {
640 }
641 *key_obj = nullptr;
642
643 const std::string params(param_str);
644
645 if(params == "X25519" || params == "x25519" || params == "curve25519") {
646 return botan_privkey_create(key_obj, "X25519", "", rng_obj);
647 }
648
649 if(params == "X448" || params == "x448") {
650 return botan_privkey_create(key_obj, "X448", "", rng_obj);
651 }
652
653 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
654}

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

438 {
439 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
440}

References botan_privkey_create().

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

1475 {
1476 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1477 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1478}

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

227 {
228 if(n_bits < 1024 || n_bits > 16 * 1024) {
230 }
231
232 const std::string n_str = std::to_string(n_bits);
233
234 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
235}

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

112 {
113 return BOTAN_FFI_CHECKED_DELETE(key);
114}

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

418 {
419 return botan_privkey_get_field(x, key, "x");
420}
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 874 of file ffi_pkey_algs.cpp.

874 {
875#if defined(BOTAN_HAS_ED25519)
876 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
877 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
878 const auto ed_key = ed->raw_private_key_bits();
879 if(ed_key.size() != 64) {
881 }
882 Botan::copy_mem(output, ed_key.data(), ed_key.size());
883 return BOTAN_FFI_SUCCESS;
884 } else {
886 }
887 });
888#else
889 BOTAN_UNUSED(key, output);
891#endif
892}

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

948 {
949#if defined(BOTAN_HAS_ED448)
950 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
951 if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
952 const auto ed_key = ed->raw_private_key_bits();
953 Botan::copy_mem(std::span(output, 57), ed_key);
954 return BOTAN_FFI_SUCCESS;
955 } else {
957 }
958 });
959#else
960 BOTAN_UNUSED(key, output);
962#endif
963}
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 194 of file ffi_pkey.cpp.

194 {
195 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
196 return copy_view_bin(out, out_len, botan_privkey_view_der, key);
197 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
198 return copy_view_str(out, out_len, botan_privkey_view_pem, key);
199 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
200 return copy_view_bin(out, out_len, botan_privkey_view_raw, key);
201 } else {
203 }
204}
#define BOTAN_PRIVKEY_EXPORT_FLAG_RAW
Definition ffi.h:1512
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:206
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:216
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1511
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1510
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:211
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 221 of file ffi_pkey.cpp.

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

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

316 {
317 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
318 return copy_view_bin(
319 out, out_len, botan_privkey_view_encrypted_der, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
320 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
321 return copy_view_str(
322 out, out_len, botan_privkey_view_encrypted_pem, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
323 } else {
325 }
326}
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:328
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:353

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

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

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

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

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

215 {
216 if(field_name_cstr == nullptr) {
218 }
219
220 const std::string field_name(field_name_cstr);
221
222 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); });
223}

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 )

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 @returns BOTAN_FFI_ERROR_NULL_POINTER either key' or Random Number Generators' is NULL @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either pbits' or `qbits'
BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

*/ int botan_privkey_create_dsa(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 @returns BOTAN_FFI_ERROR_NULL_POINTER either key' or Random Number Generators' is NULL @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either pbits' or `qbits'
BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

*/

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

/** 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 87 of file ffi_pkey.cpp.

88 {
89 BOTAN_UNUSED(rng_obj);
90
91 *key = nullptr;
92
93 return ffi_guard_thunk(__func__, [=]() -> int {
94 Botan::DataSource_Memory src(bits, len);
95
96 std::unique_ptr<Botan::Private_Key> pkcs8;
97
98 if(password == nullptr) {
99 pkcs8 = Botan::PKCS8::load_key(src);
100 } else {
101 pkcs8 = Botan::PKCS8::load_key(src, std::string(password));
102 }
103
104 if(pkcs8) {
105 ffi_new_object(key, std::move(pkcs8));
106 return BOTAN_FFI_SUCCESS;
107 }
109 });
110}
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 1413 of file ffi_pkey_algs.cpp.

1416 {
1417#if defined(BOTAN_HAS_CLASSICMCELIECE)
1418 if(key == nullptr || privkey == nullptr || cmce_mode == nullptr) {
1420 }
1421
1422 *key = nullptr;
1423
1424 return ffi_guard_thunk(__func__, [=]() -> int {
1425 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1426 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
1427 return ffi_new_object(key, std::move(cmce_key));
1428 });
1429#else
1430 BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1432#endif
1433}
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 601 of file ffi_pkey_algs.cpp.

601 {
602#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
603 if(key == nullptr) {
605 }
606 *key = nullptr;
607 return ffi_guard_thunk(__func__, [=]() -> int {
608 const Botan::DL_Group group(safe_get(p), safe_get(g));
609 auto dh = std::make_unique<Botan::DH_PrivateKey>(group, safe_get(x));
610 return ffi_new_object(key, std::move(dh));
611 });
612#else
613 BOTAN_UNUSED(key, p, g, x);
615#endif
616}

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

382 {
383#if defined(BOTAN_HAS_DSA)
384 if(key == nullptr) {
386 }
387 *key = nullptr;
388
389 return ffi_guard_thunk(__func__, [=]() -> int {
390 const Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
391 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(group, safe_get(x));
392 return ffi_new_object(key, std::move(dsa));
393 });
394#else
395 BOTAN_UNUSED(key, p, q, g, x);
397#endif
398}

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

703 {
704#if defined(BOTAN_HAS_ECDH)
705 if(key == nullptr || curve_name == nullptr) {
707 }
708 *key = nullptr;
709 return ffi_guard_thunk(__func__, [=]() -> int {
710 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
711 const int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
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().

◆ botan_privkey_load_ecdsa()

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

Definition at line 513 of file ffi_pkey_algs.cpp.

513 {
514#if defined(BOTAN_HAS_ECDSA)
515 if(key == nullptr || curve_name == nullptr) {
517 }
518 *key = nullptr;
519
520 return ffi_guard_thunk(__func__, [=]() -> int {
521 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
522 const int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
523 if(rc == BOTAN_FFI_SUCCESS) {
524 ffi_new_object(key, std::move(p_key));
525 }
526 return rc;
527 });
528#else
529 BOTAN_UNUSED(key, scalar, curve_name);
531#endif
532}

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

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 */ int botan_pubkey_load_dh(botan_pubkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t y);

/* Algorithm specific key operations: ElGamal 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 */ int botan_pubkey_load_elgamal(botan_pubkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t y);

/** 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 */ int botan_privkey_load_elgamal(botan_privkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t x);

/* Algorithm specific key operations: Ed25519

Definition at line 840 of file ffi_pkey_algs.cpp.

840 {
841#if defined(BOTAN_HAS_ED25519)
842 if(key == nullptr) {
844 }
845 *key = nullptr;
846 return ffi_guard_thunk(__func__, [=]() -> int {
847 auto ed25519 =
848 std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(std::span{privkey, 32}));
849 return ffi_new_object(key, std::move(ed25519));
850 });
851#else
852 BOTAN_UNUSED(key, privkey);
854#endif
855}
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 916 of file ffi_pkey_algs.cpp.

916 {
917#if defined(BOTAN_HAS_ED448)
918 if(key == nullptr) {
920 }
921 *key = nullptr;
922 return ffi_guard_thunk(__func__, [=]() -> int {
923 auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
924 return ffi_new_object(key, std::move(ed448));
925 });
926#else
927 BOTAN_UNUSED(key, privkey);
929#endif
930}

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

1371 {
1372#if defined(BOTAN_HAS_FRODOKEM)
1373 if(key == nullptr || privkey == nullptr || frodo_mode == nullptr) {
1375 }
1376
1377 *key = nullptr;
1378
1379 return ffi_guard_thunk(__func__, [=]() -> int {
1380 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1381 auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
1382 return ffi_new_object(key, std::move(frodo_key));
1383 });
1384#else
1385 BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1387#endif
1388}

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

1123 {
1124#if defined(BOTAN_HAS_KYBER)
1125 if(key == nullptr) {
1127 }
1128 *key = nullptr;
1129
1130 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1131 if(len == 1632) {
1133 } else if(len == 2400) {
1135 } else if(len == 3168) {
1137 } else {
1138 return {};
1139 }
1140 }(key_len);
1141
1142 if(mode.has_value()) {
1143 return ffi_guard_thunk(__func__, [=]() -> int {
1144 auto kyber = std::make_unique<Botan::Kyber_PrivateKey>(std::span{privkey, key_len}, *mode);
1145 return ffi_new_object(key, std::move(kyber));
1146 });
1147 } else {
1149 }
1150#else
1151 BOTAN_UNUSED(key, key_len, privkey);
1153#endif
1154}

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

1271 {
1272#if defined(BOTAN_HAS_ML_DSA)
1273 if(key == nullptr || privkey == nullptr || mldsa_mode == nullptr) {
1275 }
1276
1277 *key = nullptr;
1278
1279 return ffi_guard_thunk(__func__, [=]() -> int {
1280 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1281 if(!mode.is_ml_dsa()) {
1283 }
1284
1285 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1286 return ffi_new_object(key, std::move(mldsa_key));
1287 });
1288#else
1289 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1291#endif
1292}
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 1221 of file ffi_pkey_algs.cpp.

1221 {
1222#if defined(BOTAN_HAS_ML_KEM)
1223 if(key == nullptr || privkey == nullptr || mlkem_mode == nullptr) {
1225 }
1226
1227 *key = nullptr;
1228
1229 return ffi_guard_thunk(__func__, [=]() -> int {
1230 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1231 if(!mode.is_ml_kem()) {
1233 }
1234
1235 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1236 return ffi_new_object(key, std::move(mlkem_key));
1237 });
1238#else
1239 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1241#endif
1242}
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 237 of file ffi_pkey_algs.cpp.

237 {
238#if defined(BOTAN_HAS_RSA)
239 if(key == nullptr) {
241 }
242 *key = nullptr;
243
244 return ffi_guard_thunk(__func__, [=]() -> int {
245 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p), safe_get(rsa_q), safe_get(rsa_e));
246 return ffi_new_object(key, std::move(rsa));
247 });
248#else
249 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
251#endif
252}

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

254 {
255#if defined(BOTAN_HAS_RSA)
256 if(key == nullptr || bits == nullptr) {
258 }
259 *key = nullptr;
260
261 return ffi_guard_thunk(__func__, [=]() -> int {
263 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, std::span{bits, len});
264 return ffi_new_object(key, std::move(rsa));
265 });
266#else
267 BOTAN_UNUSED(key, bits, len);
269#endif
270}

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

1321 {
1322#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1323 if(key == nullptr || privkey == nullptr || slhdsa_mode == nullptr) {
1325 }
1326
1327 *key = nullptr;
1328
1329 return ffi_guard_thunk(__func__, [=]() -> int {
1330 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1331 if(!mode.is_slh_dsa()) {
1333 }
1334
1335 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1336 return ffi_new_object(key, std::move(slhdsa_key));
1337 });
1338#else
1339 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1341#endif
1342}

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

805 {
806#if defined(BOTAN_HAS_SM2)
807 if(key == nullptr || curve_name == nullptr) {
809 }
810 *key = nullptr;
811
812 return ffi_guard_thunk(__func__, [=]() -> int {
813 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
814 const int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
815
816 if(rc == BOTAN_FFI_SUCCESS) {
817 ffi_new_object(key, std::move(p_key));
818 }
819 return rc;
820 });
821#else
822 BOTAN_UNUSED(key, scalar, curve_name);
824#endif
825}

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

834 {
835 return botan_privkey_load_sm2(key, scalar, curve_name);
836}
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 984 of file ffi_pkey_algs.cpp.

984 {
985#if defined(BOTAN_HAS_X25519)
986 if(key == nullptr) {
988 }
989 *key = nullptr;
990 return ffi_guard_thunk(__func__, [=]() -> int {
991 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(std::span{privkey, 32});
992 return ffi_new_object(key, std::move(x25519));
993 });
994#else
995 BOTAN_UNUSED(key, privkey);
997#endif
998}

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

1054 {
1055#if defined(BOTAN_HAS_X448)
1056 if(key == nullptr) {
1058 }
1059 *key = nullptr;
1060 return ffi_guard_thunk(__func__, [=]() -> int {
1061 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span{privkey, 56});
1062 return ffi_new_object(key, std::move(x448));
1063 });
1064#else
1065 BOTAN_UNUSED(key, privkey);
1067#endif
1068}
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 391 of file ffi_pkey.cpp.

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

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

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

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

322 {
323 return botan_privkey_get_field(d, key, "d");
324}

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

318 {
319 return botan_privkey_get_field(e, key, "e");
320}

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

314 {
315 return botan_privkey_get_field(n, key, "n");
316}

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

306 {
307 return botan_privkey_get_field(p, key, "p");
308}

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

334 {
335#if defined(BOTAN_HAS_RSA)
336 return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int {
337 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k)) {
338 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
339 return write_vec_output(out, out_len, rsa->private_key_bits());
340 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
341 // TODO define new generic functions for this
342 return write_str_output(reinterpret_cast<char*>(out),
343 out_len,
344 Botan::PEM_Code::encode(rsa->private_key_bits(), "RSA PRIVATE KEY"));
345 } else {
347 }
348 } else {
350 }
351 });
352#else
353 BOTAN_UNUSED(rsa_key, out, out_len, flags);
355#endif
356}
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 310 of file ffi_pkey_algs.cpp.

310 {
311 return botan_privkey_get_field(q, key, "q");
312}

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

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

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

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

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

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

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

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

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

1187 {
1188#if defined(BOTAN_HAS_KYBER)
1189 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1190 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1191 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1192 } else {
1194 }
1195 });
1196#else
1197 BOTAN_UNUSED(key, ctx, view);
1199#endif
1200}

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

211 {
212 return BOTAN_FFI_VISIT(
213 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::PEM_encode(k)); });
214}
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 216 of file ffi_pkey.cpp.

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

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

1016 {
1017#if defined(BOTAN_HAS_X25519)
1018 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1019 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
1020 const auto x25519_key = x25519->raw_private_key_bits();
1021 if(x25519_key.size() != 32) {
1023 }
1024 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
1025 return BOTAN_FFI_SUCCESS;
1026 } else {
1028 }
1029 });
1030#else
1031 BOTAN_UNUSED(key, output);
1033#endif
1034}

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

1086 {
1087#if defined(BOTAN_HAS_X448)
1088 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1089 if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
1090 const auto x448_key = x448->raw_private_key_bits();
1091 Botan::copy_mem(std::span{output, 56}, x448_key);
1092 return BOTAN_FFI_SUCCESS;
1093 } else {
1095 }
1096 });
1097#else
1098 BOTAN_UNUSED(key, output);
1100#endif
1101}
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 148 of file ffi_pkey.cpp.

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

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

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

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

132 {
133 return BOTAN_FFI_CHECKED_DELETE(key);
134}

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

430 {
431 return botan_pubkey_get_field(g, key, "g");
432}
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 422 of file ffi_pkey_algs.cpp.

422 {
423 return botan_pubkey_get_field(p, key, "p");
424}

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

426 {
427 return botan_pubkey_get_field(q, key, "q");
428}

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

434 {
435 return botan_pubkey_get_field(y, key, "y");
436}

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

444 {
445#if defined(BOTAN_HAS_ECC_KEY)
446 return ffi_guard_thunk(__func__, [=]() -> int {
447 const Botan::Public_Key& pub_key = safe_get(key);
448 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
449
450 if(ec_key == nullptr) {
452 }
453
454 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
455 });
456#else
457 BOTAN_UNUSED(key);
459#endif
460}
bool used_explicit_encoding() const
Definition ec_group.h:262
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 894 of file ffi_pkey_algs.cpp.

894 {
895#if defined(BOTAN_HAS_ED25519)
896 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
897 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
898 const std::vector<uint8_t>& ed_key = ed->get_public_key();
899 if(ed_key.size() != 32) {
901 }
902 Botan::copy_mem(output, ed_key.data(), ed_key.size());
903 return BOTAN_FFI_SUCCESS;
904 } else {
906 }
907 });
908#else
909 BOTAN_UNUSED(key, output);
911#endif
912}

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

965 {
966#if defined(BOTAN_HAS_ED448)
967 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
968 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
969 const auto ed_key = ed->public_key_bits();
970 Botan::copy_mem(std::span(output, 57), ed_key);
971 return BOTAN_FFI_SUCCESS;
972 } else {
974 }
975 });
976#else
977 BOTAN_UNUSED(key, output);
979#endif
980}
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 434 of file ffi_pkey.cpp.

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

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

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

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

438 {
439 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
440 auto h = Botan::HashFunction::create_or_throw(hash_fn);
441 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
442 });
443}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:308

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

205 {
206 if(field_name_cstr == nullptr) {
208 }
209
210 const std::string field_name(field_name_cstr);
211
212 return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); });
213}

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

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

1438 {
1439#if defined(BOTAN_HAS_CLASSICMCELIECE)
1440 if(key == nullptr || pubkey == nullptr || cmce_mode == nullptr) {
1442 }
1443
1444 *key = nullptr;
1445
1446 return ffi_guard_thunk(__func__, [=]() -> int {
1447 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1448 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
1449 return ffi_new_object(key, std::move(cmce_key));
1450 });
1451#else
1452 BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1454#endif
1455}

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

400 {
401#if defined(BOTAN_HAS_DSA)
402 if(key == nullptr) {
404 }
405 *key = nullptr;
406
407 return ffi_guard_thunk(__func__, [=]() -> int {
408 const Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
409 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
410 return ffi_new_object(key, std::move(dsa));
411 });
412#else
413 BOTAN_UNUSED(key, p, q, g, y);
415#endif
416}

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

659 {
660#if defined(BOTAN_HAS_ECDH)
661 if(key == nullptr || curve_name == nullptr) {
663 }
664 *key = nullptr;
665 return ffi_guard_thunk(__func__, [=]() -> int {
666 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
667 const int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
668
669 if(rc == BOTAN_FFI_SUCCESS) {
670 ffi_new_object(key, std::move(p_key));
671 }
672 return rc;
673 });
674#else
675 BOTAN_UNUSED(key, public_x, public_y, curve_name);
677#endif
678}

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

int botan_pubkey_load_ecdh_sec1 ( botan_pubkey_t * key,
const uint8_t sec1[],
size_t sec1_len,
const char * curve_name )

Definition at line 680 of file ffi_pkey_algs.cpp.

680 {
681#if defined(BOTAN_HAS_ECDH)
682 if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
684 }
685 *key = nullptr;
686
687 return ffi_guard_thunk(__func__, [=]() -> int {
688 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
689
690 const int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
691 if(rc == BOTAN_FFI_SUCCESS) {
692 ffi_new_object(key, std::move(p_key));
693 }
694
695 return rc;
696 });
697#else
698 BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
700#endif
701}

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

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

467 {
468#if defined(BOTAN_HAS_ECDSA)
469 if(key == nullptr || curve_name == nullptr) {
471 }
472 *key = nullptr;
473
474 return ffi_guard_thunk(__func__, [=]() -> int {
475 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
476
477 const int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
478 if(rc == BOTAN_FFI_SUCCESS) {
479 ffi_new_object(key, std::move(p_key));
480 }
481
482 return rc;
483 });
484#else
485 BOTAN_UNUSED(key, public_x, public_y, curve_name);
487#endif
488}

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

int botan_pubkey_load_ecdsa_sec1 ( botan_pubkey_t * key,
const uint8_t sec1[],
size_t sec1_len,
const char * curve_name )

Definition at line 490 of file ffi_pkey_algs.cpp.

490 {
491#if defined(BOTAN_HAS_ECDSA)
492 if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
494 }
495 *key = nullptr;
496
497 return ffi_guard_thunk(__func__, [=]() -> int {
498 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
499
500 const int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
501 if(rc == BOTAN_FFI_SUCCESS) {
502 ffi_new_object(key, std::move(p_key));
503 }
504
505 return rc;
506 });
507#else
508 BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
510#endif
511}

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

◆ botan_pubkey_load_ed25519()

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

Definition at line 857 of file ffi_pkey_algs.cpp.

857 {
858#if defined(BOTAN_HAS_ED25519)
859 if(key == nullptr) {
861 }
862 *key = nullptr;
863 return ffi_guard_thunk(__func__, [=]() -> int {
864 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
865 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
866 return ffi_new_object(key, std::move(ed25519));
867 });
868#else
869 BOTAN_UNUSED(key, pubkey);
871#endif
872}

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

932 {
933#if defined(BOTAN_HAS_ED448)
934 if(key == nullptr) {
936 }
937 *key = nullptr;
938 return ffi_guard_thunk(__func__, [=]() -> int {
939 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
940 return ffi_new_object(key, std::move(ed448));
941 });
942#else
943 BOTAN_UNUSED(key, pubkey);
945#endif
946}

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

1390 {
1391#if defined(BOTAN_HAS_FRODOKEM)
1392 if(key == nullptr || pubkey == nullptr || frodo_mode == nullptr) {
1394 }
1395
1396 *key = nullptr;
1397
1398 return ffi_guard_thunk(__func__, [=]() -> int {
1399 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1400 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1401 return ffi_new_object(key, std::move(frodo_key));
1402 });
1403#else
1404 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1406#endif
1407}

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

1156 {
1157#if defined(BOTAN_HAS_KYBER)
1158 if(key == nullptr) {
1160 }
1161 *key = nullptr;
1162
1163 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1164 if(len == 800) {
1166 } else if(len == 1184) {
1168 } else if(len == 1568) {
1170 } else {
1171 return {};
1172 }
1173 }(key_len);
1174
1175 if(mode.has_value()) {
1176 auto kyber = std::make_unique<Botan::Kyber_PublicKey>(std::span{pubkey, key_len}, *mode);
1177 return ffi_new_object(key, std::move(kyber));
1178 } else {
1180 }
1181#else
1182 BOTAN_UNUSED(key, pubkey, key_len);
1184#endif
1185}

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

1294 {
1295#if defined(BOTAN_HAS_ML_DSA)
1296 if(key == nullptr || pubkey == nullptr || mldsa_mode == nullptr) {
1298 }
1299
1300 *key = nullptr;
1301
1302 return ffi_guard_thunk(__func__, [=]() -> int {
1303 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1304 if(!mode.is_ml_dsa()) {
1306 }
1307
1308 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1309 return ffi_new_object(key, std::move(mldsa_key));
1310 });
1311#else
1312 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1314#endif
1315}

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

1244 {
1245#if defined(BOTAN_HAS_ML_KEM)
1246 if(key == nullptr || pubkey == nullptr || mlkem_mode == nullptr) {
1248 }
1249
1250 *key = nullptr;
1251
1252 return ffi_guard_thunk(__func__, [=]() -> int {
1253 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1254 if(!mode.is_ml_kem()) {
1256 }
1257
1258 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1259 return ffi_new_object(key, std::move(mlkem_key));
1260 });
1261#else
1262 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1264#endif
1265}

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

272 {
273#if defined(BOTAN_HAS_RSA)
274 if(key == nullptr) {
276 }
277 *key = nullptr;
278 return ffi_guard_thunk(__func__, [=]() -> int {
279 auto rsa = std::make_unique<Botan::RSA_PublicKey>(safe_get(n), safe_get(e));
280 return ffi_new_object(key, std::move(rsa));
281 });
282#else
283 BOTAN_UNUSED(key, n, e);
285#endif
286}

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

int botan_pubkey_load_rsa_pkcs1 ( botan_pubkey_t * key,
const uint8_t bits[],
size_t len )

Definition at line 288 of file ffi_pkey_algs.cpp.

288 {
289#if defined(BOTAN_HAS_RSA)
290 if(key == nullptr || bits == nullptr) {
292 }
293 *key = nullptr;
294
295 return ffi_guard_thunk(__func__, [=]() -> int {
297 auto rsa = std::make_unique<Botan::RSA_PublicKey>(alg_id, std::span{bits, len});
298 return ffi_new_object(key, std::move(rsa));
299 });
300#else
301 BOTAN_UNUSED(key, bits, len);
303#endif
304}

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

1344 {
1345#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1346 if(key == nullptr || pubkey == nullptr || slhdsa_mode == nullptr) {
1348 }
1349
1350 *key = nullptr;
1351
1352 return ffi_guard_thunk(__func__, [=]() -> int {
1353 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1354 if(!mode.is_slh_dsa()) {
1356 }
1357
1358 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1359 return ffi_new_object(key, std::move(mldsa_key));
1360 });
1361#else
1362 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1364#endif
1365}

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

761 {
762#if defined(BOTAN_HAS_SM2)
763 if(key == nullptr || curve_name == nullptr) {
765 }
766 *key = nullptr;
767
768 return ffi_guard_thunk(__func__, [=]() -> int {
769 std::unique_ptr<Botan::SM2_PublicKey> p_key;
770 if(pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name) == 0) {
771 return ffi_new_object(key, std::move(p_key));
772 } else {
774 }
775 });
776#else
777 BOTAN_UNUSED(key, public_x, public_y, curve_name);
779#endif
780}

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

830 {
831 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
832}
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_sm2_sec1()

int botan_pubkey_load_sm2_sec1 ( botan_pubkey_t * key,
const uint8_t sec1[],
size_t sec1_len,
const char * curve_name )

Definition at line 782 of file ffi_pkey_algs.cpp.

782 {
783#if defined(BOTAN_HAS_SM2)
784 if(key == nullptr || sec1 == nullptr || curve_name == nullptr) {
786 }
787 *key = nullptr;
788
789 return ffi_guard_thunk(__func__, [=]() -> int {
790 std::unique_ptr<Botan::SM2_PublicKey> p_key;
791
792 const int rc = pubkey_load_ec_sec1(p_key, {sec1, sec1_len}, curve_name);
793 if(rc == BOTAN_FFI_SUCCESS) {
794 ffi_new_object(key, std::move(p_key));
795 }
796
797 return rc;
798 });
799#else
800 BOTAN_UNUSED(key, sec1, sec1_len, curve_name);
802#endif
803}

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

◆ botan_pubkey_load_x25519()

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

Definition at line 1000 of file ffi_pkey_algs.cpp.

1000 {
1001#if defined(BOTAN_HAS_X25519)
1002 if(key == nullptr) {
1004 }
1005 *key = nullptr;
1006 return ffi_guard_thunk(__func__, [=]() -> int {
1007 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(std::span{pubkey, 32});
1008 return ffi_new_object(key, std::move(x25519));
1009 });
1010#else
1011 BOTAN_UNUSED(key, pubkey);
1013#endif
1014}

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

1070 {
1071#if defined(BOTAN_HAS_X448)
1072 if(key == nullptr) {
1074 }
1075 *key = nullptr;
1076 return ffi_guard_thunk(__func__, [=]() -> int {
1077 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span{pubkey, 56});
1078 return ffi_new_object(key, std::move(x448));
1079 });
1080#else
1081 BOTAN_UNUSED(key, pubkey);
1083#endif
1084}

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

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

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

326 {
327 return botan_pubkey_get_field(e, key, "e");
328}

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

330 {
331 return botan_pubkey_get_field(n, key, "n");
332}

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

726 {
727 if(out == nullptr || out_len == nullptr || ident == nullptr || hash_algo == nullptr || key == nullptr) {
729 }
730
731#if defined(BOTAN_HAS_SM2)
732 return ffi_guard_thunk(__func__, [=]() -> int {
733 const Botan::Public_Key& pub_key = safe_get(key);
734 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
735
736 if(ec_key == nullptr) {
738 }
739
740 if(ec_key->algo_name() != "SM2") {
742 }
743
744 const std::string ident_str(ident);
745 std::unique_ptr<Botan::HashFunction> hash = Botan::HashFunction::create_or_throw(hash_algo);
746
747 const auto& pt = ec_key->_public_ec_point();
748
749 const auto za = Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), pt);
750
751 return write_vec_output(out, out_len, za);
752 });
753#else
755#endif
756}
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:82

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

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

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

1457 {
1458#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1459 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1460 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1461 auto pt = ecc->_public_ec_point().serialize_uncompressed();
1462 return invoke_view_callback(view, ctx, pt);
1463 } else {
1465 }
1466 });
1467#else
1468 BOTAN_UNUSED(key, view, ctx);
1470#endif
1471}

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

1202 {
1203#if defined(BOTAN_HAS_KYBER)
1204 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1205 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1206 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1207 } else {
1209 }
1210 });
1211#else
1212 BOTAN_UNUSED(key, ctx, view);
1214#endif
1215}

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

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

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

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

1036 {
1037#if defined(BOTAN_HAS_X25519)
1038 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1039 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
1040 Botan::copy_mem(std::span{output, 32}, x25519->raw_public_key_bits());
1041 return BOTAN_FFI_SUCCESS;
1042 } else {
1044 }
1045 });
1046#else
1047 BOTAN_UNUSED(key, output);
1049#endif
1050}

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

1103 {
1104#if defined(BOTAN_HAS_X448)
1105 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1106 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
1107 Botan::copy_mem(std::span{output, 56}, x448->raw_public_key_bits());
1108 return BOTAN_FFI_SUCCESS;
1109 } else {
1111 }
1112 });
1113#else
1114 BOTAN_UNUSED(key, output);
1116#endif
1117}
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_params(out_len, 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 const 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 const 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 319 of file ffi.cpp.

319 {
320 return botan_constant_time_compare(x, y, len);
321}
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition ffi.cpp:313

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

323 {
324 Botan::secure_scrub_memory(mem, bytes);
325 return BOTAN_FFI_SUCCESS;
326}
void secure_scrub_memory(void *ptr, size_t n)
Definition mem_utils.cpp:25

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

162 {
163#if defined(BOTAN_HAS_SRP6)
164 return ffi_guard_thunk(__func__, [=]() -> int {
165 if(any_null_pointers(identity, password, salt, group_id, hash_id, b, rng_obj)) {
167 }
168 try {
169 const std::vector<uint8_t> saltv(salt, salt + salt_len);
171 auto b_bn = Botan::BigInt::from_bytes({b, b_len});
172 const auto group = Botan::DL_Group::from_name(group_id);
173 const size_t a_bits = group.exponent_bits();
174 auto [A_bn, K_sk] = Botan::srp6_client_agree(identity, password, group, hash_id, saltv, b_bn, a_bits, rng);
175 auto ret_a = write_vec_output(A, A_len, A_bn.serialize(group.p_bytes()));
176 auto ret_k = write_vec_output(K, K_len, K_sk.bits_of());
177 if(ret_a != BOTAN_FFI_SUCCESS) {
178 return ret_a;
179 }
180 if(ret_k != BOTAN_FFI_SUCCESS) {
181 return ret_k;
182 }
183 return BOTAN_FFI_SUCCESS;
184 } catch(Botan::Lookup_Error&) {
186 }
187 });
188#else
189 BOTAN_UNUSED(identity, password, group_id, hash_id, rng_obj);
190 BOTAN_UNUSED(salt, salt_len, b, b_len, A, A_len, K, K_len);
192#endif
193}
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition bigint.cpp:83
static DL_Group from_name(std::string_view name)
Definition dl_group.cpp:217
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:66

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::DL_Group::from_name(), 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 120 of file ffi_srp6.cpp.

127 {
128#if defined(BOTAN_HAS_SRP6)
129 return ffi_guard_thunk(__func__, [=]() -> int {
130 if(any_null_pointers(username, password, salt, group_id, hash_id)) {
132 }
133 try {
134 const std::vector<uint8_t> salt_vec(salt, salt + salt_len);
135 const auto group = Botan::DL_Group::from_name(group_id);
136 const size_t p_bytes = group.p_bytes();
137 auto verifier_bn = Botan::srp6_generate_verifier(username, password, salt_vec, group, hash_id);
138 return write_vec_output(verifier, verifier_len, verifier_bn.serialize(p_bytes));
139 } catch(Botan::Lookup_Error&) {
141 }
142 });
143#else
144 BOTAN_UNUSED(username, password, group_id, hash_id);
145 BOTAN_UNUSED(salt, salt_len, verifier, verifier_len);
147#endif
148}
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:129

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::DL_Group::from_name(), 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 46 of file ffi_srp6.cpp.

46 {
47#if defined(BOTAN_HAS_SRP6)
48 if(any_null_pointers(group_id, group_p_bytes)) {
50 }
51
52 return ffi_guard_thunk(__func__, [=]() -> int {
53 const auto group = Botan::DL_Group::from_name(group_id);
54 *group_p_bytes = group.p_bytes();
55 return BOTAN_FFI_SUCCESS;
56 });
57#else
58 BOTAN_UNUSED(group_id, group_p_bytes);
60#endif
61}

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

42 {
43 return BOTAN_FFI_CHECKED_DELETE(srp6);
44}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

150 {
151#if defined(BOTAN_HAS_TPM2)
152 return BOTAN_FFI_VISIT(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int {
154
155 // The lifetime of the RNG used for the crypto backend should be managed
156 // by the TPM2::Context. Here, we just need to trust the user that they
157 // keep the passed-in RNG instance intact for the lifetime of the context.
158 ctx_wrapper.ctx->use_botan_crypto_backend(std::shared_ptr<Botan::RandomNumberGenerator>(&rng_ref, [](auto*) {}));
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 133 of file ffi_tpm2.cpp.

133 {
134#if defined(BOTAN_HAS_TPM2)
135 return ffi_guard_thunk(__func__, [=]() -> int {
136 if(ctx_out == nullptr || esys_ctx == nullptr) {
138 }
139
140 auto ctx = std::make_unique<botan_tpm2_ctx_wrapper>();
141 ctx->ctx = Botan::TPM2::Context::create(esys_ctx);
142 return ffi_new_object(ctx_out, std::move(ctx));
143 });
144#else
145 BOTAN_UNUSED(ctx_out, esys_ctx);
147#endif
148}
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 75 of file ffi_tpm2.cpp.

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_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 100 of file ffi_tpm2.cpp.

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

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

67 {
68#if defined(BOTAN_HAS_TPM2)
70#else
71 return 0;
72#endif
73}
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 309 of file ffi.cpp.

309 {
311}
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 297 of file ffi.cpp.

297 {
298 return Botan::version_major();
299}
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 301 of file ffi.cpp.

301 {
302 return Botan::version_minor();
303}
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 305 of file ffi.cpp.

305 {
306 return Botan::version_patch();
307}
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 293 of file ffi.cpp.

293 {
294 return Botan::version_cstr();
295}
const char * version_cstr()
Definition version.cpp:20

References Botan::version_cstr().

◆ botan_x509_cert_allowed_extended_usage_oid()

int botan_x509_cert_allowed_extended_usage_oid ( botan_x509_cert_t cert,
botan_asn1_oid_t oid )

Check if the certificate allows the specified extended usage OID. See RFC 5280 Section 4.2.1.12 for OIDs to query for this. If no extended key usage extension is found in the certificate, this always returns "not success".

This is similar to botan_x509_cert_allowed_extended_usage_str but takes an OID object instead of a string describing the OID.

Definition at line 584 of file ffi_cert.cpp.

584 {
585#if defined(BOTAN_HAS_X509_CERTIFICATES)
586 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int { return c.has_ex_constraint(safe_get(oid)) ? 1 : 0; });
587#else
588 BOTAN_UNUSED(cert, oid);
590#endif
591}

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

◆ botan_x509_cert_allowed_extended_usage_str()

int botan_x509_cert_allowed_extended_usage_str ( botan_x509_cert_t cert,
const char * oid )

Check if the certificate allows the specified extended usage OID. See RFC 5280 Section 4.2.1.12 for OIDs to query for this. If no extended key usage extension is found in the certificate, this always returns "not success".

Typical OIDs to check for:

  • "PKIX.ServerAuth"
  • "PKIX.ClientAuth"
  • "PKIX.CodeSigning"
  • "PKIX.OCSPSigning"

The oid parameter can be either a canonical OID string or identifiers as indicated in the examples above.

Definition at line 569 of file ffi_cert.cpp.

569 {
570#if defined(BOTAN_HAS_X509_CERTIFICATES)
571 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
572 if(Botan::any_null_pointers(oid)) {
574 }
575
576 return c.has_ex_constraint(oid) ? 1 : 0;
577 });
578#else
579 BOTAN_UNUSED(cert, oid);
581#endif
582}
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_allowed_usage()

int botan_x509_cert_allowed_usage ( botan_x509_cert_t cert,
unsigned int key_usage )

Definition at line 554 of file ffi_cert.cpp.

554 {
555#if defined(BOTAN_HAS_X509_CERTIFICATES)
556 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
557 const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
558 if(c.allowed_usage(k)) {
559 return BOTAN_FFI_SUCCESS;
560 }
561 return 1;
562 });
563#else
564 BOTAN_UNUSED(cert, key_usage);
566#endif
567}

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

593 {
594#if defined(BOTAN_HAS_X509_CERTIFICATES)
595 return BOTAN_FFI_CHECKED_DELETE(cert);
596#else
597 BOTAN_UNUSED(cert);
599#endif
600}

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

186 {
187 if(cert_obj == nullptr) {
189 }
190
191#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
192
193 return ffi_guard_thunk(__func__, [=]() -> int {
194 auto c = std::make_unique<Botan::X509_Certificate>(safe_get(cert));
195 return ffi_new_object(cert_obj, std::move(c));
196 });
197
198#else
199 BOTAN_UNUSED(cert);
201#endif
202}

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

int botan_x509_cert_excluded_name_constraints ( botan_x509_cert_t cert,
size_t index,
botan_x509_general_name_t * constraint )

Extracts "excluded" name constraints from a given cert one-by-one. Returns BOTAN_FFI_ERROR_OUT_OF_RANGE if the given index is larger than the available number of "excluded" name constraints.

Definition at line 824 of file ffi_cert.cpp.

826 {
827#if defined(BOTAN_HAS_X509_CERTIFICATES)
828 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
829 if(Botan::any_null_pointers(constraint)) {
831 }
832
833 const auto& constraints = c.name_constraints().excluded();
834 if(index >= constraints.size()) {
836 }
837
838 return ffi_new_object(constraint, std::make_unique<Botan::GeneralName>(constraints[index].base()));
839 });
840#else
841 BOTAN_UNUSED(cert, index, constraint);
843#endif
844}
const std::vector< GeneralSubtree > & excluded() const
Definition pkix_types.h:433
const NameConstraints & name_constraints() const
Definition x509cert.cpp:458

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::NameConstraints::excluded(), Botan_FFI::ffi_new_object(), and Botan::X509_Certificate::name_constraints().

◆ botan_x509_cert_excluded_name_constraints_count()

int botan_x509_cert_excluded_name_constraints_count ( botan_x509_cert_t cert,
size_t * count )

Definition at line 846 of file ffi_cert.cpp.

846 {
847#if defined(BOTAN_HAS_X509_CERTIFICATES)
848 if(Botan::any_null_pointers(count)) {
850 }
851
852 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *count = c.name_constraints().excluded().size(); });
853#else
854 BOTAN_UNUSED(cert, count);
856#endif
857}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

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

678 {
679#if defined(BOTAN_HAS_X509_CERTIFICATES)
680 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.authority_key_id()); });
681#else
682 BOTAN_UNUSED(cert, out, out_len);
684#endif
685}

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

665 {
666#if defined(BOTAN_HAS_X509_CERTIFICATES)
667 // TODO(Botan4) change the type of out and remove this cast
668
669 return BOTAN_FFI_VISIT(cert, [=](const auto& c) {
670 return write_str_output(reinterpret_cast<char*>(out), out_len, c.fingerprint(hash));
671 });
672#else
673 BOTAN_UNUSED(cert, hash, out, out_len);
675#endif
676}

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 )

Enumerates the names of the given key in the issuer DN. If index is out of bounds, BOTAN_FFI_ERROR_BAD_PARAMETER is returned.

TODO(Botan4) use BOTAN_FFI_ERROR_OUT_OF_RANGE instead of BAD_PARAMETER TODO(Botan4) this should use char for the out param

Definition at line 473 of file ffi_cert.cpp.

474 {
475#if defined(BOTAN_HAS_X509_CERTIFICATES)
476 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
477 auto issuer_info = c.issuer_info(key);
478 if(index < issuer_info.size()) {
479 // TODO(Botan4) change the type of out and remove this cast
480 return write_str_output(reinterpret_cast<char*>(out), out_len, c.issuer_info(key).at(index));
481 } else {
482 return BOTAN_FFI_ERROR_BAD_PARAMETER; // TODO(Botan4): use BOTAN_FFI_ERROR_OUT_OF_RANGE
483 }
484 });
485#else
486 BOTAN_UNUSED(cert, key, index, out, out_len);
488#endif
489}

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

int botan_x509_cert_get_issuer_dn_count ( botan_x509_cert_t cert,
const char * key,
size_t * count )

Definition at line 491 of file ffi_cert.cpp.

491 {
492#if defined(BOTAN_HAS_X509_CERTIFICATES)
493 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
494 if(Botan::any_null_pointers(count)) {
496 }
497
498 *count = c.issuer_info(key).size();
499 return BOTAN_FFI_SUCCESS;
500 });
501#else
502 BOTAN_UNUSED(cert, key, count);
504#endif
505}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_get_path_length_constraint()

int botan_x509_cert_get_path_length_constraint ( botan_x509_cert_t cert,
size_t * path_limit )

Retrieves the path length constraint from the certificate. If no such constraint is present, BOTAN_FFI_ERROR_NO_VALUE is returned.

Definition at line 435 of file ffi_cert.cpp.

435 {
436#if defined(BOTAN_HAS_X509_CERTIFICATES)
437 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
438 if(Botan::any_null_pointers(path_limit)) {
440 }
441
442 if(const auto path_len = c.path_length_constraint()) {
443 *path_limit = path_len.value();
444 return BOTAN_FFI_SUCCESS;
445 } else {
447 }
448 });
449#else
450 BOTAN_UNUSED(cert, path_limit);
452#endif
453}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

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

455 {
456 if(key == nullptr) {
458 }
459
460 *key = nullptr;
461
462#if defined(BOTAN_HAS_X509_CERTIFICATES)
463 return ffi_guard_thunk(__func__, [=]() -> int {
464 auto public_key = safe_get(cert).subject_public_key();
465 return ffi_new_object(key, std::move(public_key));
466 });
467#else
468 BOTAN_UNUSED(cert);
470#endif
471}

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

696 {
697 return copy_view_bin(out, out_len, botan_x509_cert_view_public_key_bits, cert);
698}
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:700

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

640 {
641#if defined(BOTAN_HAS_X509_CERTIFICATES)
642 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.serial_number()); });
643#else
644 BOTAN_UNUSED(cert, out, out_len);
646#endif
647}

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 )

Enumerates the names of the given key in the subject DN. If index is out of bounds, BOTAN_FFI_ERROR_BAD_PARAMETER is returned.

TODO(Botan4) use BOTAN_FFI_ERROR_OUT_OF_RANGE instead of BAD_PARAMETER TODO(Botan4) this should use char for the out param

Definition at line 507 of file ffi_cert.cpp.

508 {
509#if defined(BOTAN_HAS_X509_CERTIFICATES)
510 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
511 auto subject_info = c.subject_info(key);
512 if(index < subject_info.size()) {
513 // TODO(Botan4) change the type of out and remove this cast
514 return write_str_output(reinterpret_cast<char*>(out), out_len, c.subject_info(key).at(index));
515 } else {
516 return BOTAN_FFI_ERROR_BAD_PARAMETER; // TODO(Botan4): use BOTAN_FFI_ERROR_OUT_OF_RANGE
517 }
518 });
519#else
520 BOTAN_UNUSED(cert, key, index, out, out_len);
522#endif
523}

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

int botan_x509_cert_get_subject_dn_count ( botan_x509_cert_t cert,
const char * key,
size_t * count )

Definition at line 525 of file ffi_cert.cpp.

525 {
526#if defined(BOTAN_HAS_X509_CERTIFICATES)
527 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
528 if(Botan::any_null_pointers(count)) {
530 }
531
532 *count = c.subject_info(key).size();
533 return BOTAN_FFI_SUCCESS;
534 });
535#else
536 BOTAN_UNUSED(cert, key, count);
538#endif
539}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

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

687 {
688#if defined(BOTAN_HAS_X509_CERTIFICATES)
689 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.subject_key_id()); });
690#else
691 BOTAN_UNUSED(cert, out, out_len);
693#endif
694}

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

612 {
613#if defined(BOTAN_HAS_X509_CERTIFICATES)
614 return BOTAN_FFI_VISIT(cert,
615 [=](const auto& c) { return write_str_output(out, out_len, c.not_after().to_string()); });
616#else
617 BOTAN_UNUSED(cert, out, out_len);
619#endif
620}

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

602 {
603#if defined(BOTAN_HAS_X509_CERTIFICATES)
604 return BOTAN_FFI_VISIT(cert,
605 [=](const auto& c) { return write_str_output(out, out_len, c.not_before().to_string()); });
606#else
607 BOTAN_UNUSED(cert, out, out_len);
609#endif
610}

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

937 {
938 if(hostname == nullptr) {
940 }
941
942#if defined(BOTAN_HAS_X509_CERTIFICATES)
943 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return c.matches_dns_name(hostname) ? 0 : -1; });
944#else
945 BOTAN_UNUSED(cert);
947#endif
948}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_is_ca()

int botan_x509_cert_is_ca ( botan_x509_cert_t cert)

Returns 1 iff the cert is a CA certificate

Definition at line 426 of file ffi_cert.cpp.

426 {
427#if defined(BOTAN_HAS_X509_CERTIFICATES)
428 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return c.is_CA_cert() ? 1 : 0; });
429#else
430 BOTAN_UNUSED(cert);
432#endif
433}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_issuer_alternative_names()

int botan_x509_cert_issuer_alternative_names ( botan_x509_cert_t cert,
size_t index,
botan_x509_general_name_t * alt_name )

Provides access to all "issuer alternative names", where each entry is returned as a botan_x509_general_name_t. If the given index is not within range of the available entries, BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. If cert does not contain an IssuerAlternativeNames extension, BOTAN_FFI_ERROR_NO_VALUE is returned.

Definition at line 898 of file ffi_cert.cpp.

900 {
901#if defined(BOTAN_HAS_X509_CERTIFICATES)
902 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
903 if(Botan::any_null_pointers(alt_name)) {
905 }
906
907 if(!c.v3_extensions().extension_set(Botan::OID::from_string("X509v3.IssuerAlternativeName"))) {
909 }
910
911 if(auto name = extract_general_name_at(c.issuer_alt_name(), index)) {
912 return ffi_new_object(alt_name, std::make_unique<Botan::GeneralName>(std::move(name).value()));
913 }
914
916 });
917#else
918 BOTAN_UNUSED(cert, index, alt_name);
920#endif
921}
bool extension_set(const OID &oid) const
Definition x509_ext.cpp:188
const AlternativeName & issuer_alt_name() const
Definition x509cert.cpp:575
const Extensions & v3_extensions() const
Definition x509cert.cpp:462

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::Extensions::extension_set(), Botan_FFI::ffi_new_object(), Botan::OID::from_string(), Botan::X509_Certificate::issuer_alt_name(), and Botan::X509_Certificate::v3_extensions().

◆ botan_x509_cert_issuer_alternative_names_count()

int botan_x509_cert_issuer_alternative_names_count ( botan_x509_cert_t cert,
size_t * count )

Definition at line 923 of file ffi_cert.cpp.

923 {
924#if defined(BOTAN_HAS_X509_CERTIFICATES)
925 if(Botan::any_null_pointers(count)) {
927 }
928
929 return BOTAN_FFI_VISIT(
930 cert, [=](const Botan::X509_Certificate& c) { *count = count_general_names_in(c.issuer_alt_name()); });
931#else
932 BOTAN_UNUSED(cert, count);
934#endif
935}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::X509_Certificate::issuer_alt_name().

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

204 {
205 if(cert_obj == nullptr || cert_bits == nullptr) {
207 }
208
209#if defined(BOTAN_HAS_X509_CERTIFICATES)
210 return ffi_guard_thunk(__func__, [=]() -> int {
211 Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
212 auto c = std::make_unique<Botan::X509_Certificate>(bits);
213 return ffi_new_object(cert_obj, std::move(c));
214 });
215#else
216 BOTAN_UNUSED(cert_bits_len);
218#endif
219}

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

169 {
170 if(cert_obj == nullptr || cert_path == nullptr) {
172 }
173
174#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
175
176 return ffi_guard_thunk(__func__, [=]() -> int {
177 auto c = std::make_unique<Botan::X509_Certificate>(cert_path);
178 return ffi_new_object(cert_obj, std::move(c));
179 });
180
181#else
183#endif
184}

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

631 {
632#if defined(BOTAN_HAS_X509_CERTIFICATES)
633 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_after().time_since_epoch(); });
634#else
635 BOTAN_UNUSED(cert, time_since_epoch);
637#endif
638}

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

622 {
623#if defined(BOTAN_HAS_X509_CERTIFICATES)
624 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_before().time_since_epoch(); });
625#else
626 BOTAN_UNUSED(cert, time_since_epoch);
628#endif
629}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_permitted_name_constraints()

int botan_x509_cert_permitted_name_constraints ( botan_x509_cert_t cert,
size_t index,
botan_x509_general_name_t * constraint )

Extracts "permitted" name constraints from a given cert one-by-one. Returns BOTAN_FFI_ERROR_OUT_OF_RANGE if the given index is larger than the available number of "permitted" name constraints.

Definition at line 789 of file ffi_cert.cpp.

791 {
792#if defined(BOTAN_HAS_X509_CERTIFICATES)
793 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
794 if(Botan::any_null_pointers(constraint)) {
796 }
797
798 const auto& constraints = c.name_constraints().permitted();
799 if(index >= constraints.size()) {
801 }
802
803 return ffi_new_object(constraint, std::make_unique<Botan::GeneralName>(constraints[index].base()));
804 });
805#else
806 BOTAN_UNUSED(cert, index, constraint);
808#endif
809}
const std::vector< GeneralSubtree > & permitted() const
Definition pkix_types.h:426

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), Botan::X509_Certificate::name_constraints(), and Botan::NameConstraints::permitted().

◆ botan_x509_cert_permitted_name_constraints_count()

int botan_x509_cert_permitted_name_constraints_count ( botan_x509_cert_t cert,
size_t * count )

Definition at line 811 of file ffi_cert.cpp.

811 {
812#if defined(BOTAN_HAS_X509_CERTIFICATES)
813 if(Botan::any_null_pointers(count)) {
815 }
816
817 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *count = c.name_constraints().permitted().size(); });
818#else
819 BOTAN_UNUSED(cert, count);
821#endif
822}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_serial_number()

int botan_x509_cert_serial_number ( botan_x509_cert_t cert,
botan_mp_t * serial_number )

Definition at line 649 of file ffi_cert.cpp.

649 {
650#if defined(BOTAN_HAS_X509_CERTIFICATES)
651 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
652 if(Botan::any_null_pointers(serial_number)) {
654 }
655
656 auto serial_bn = Botan::BigInt::from_bytes(c.serial_number());
657 return ffi_new_object(serial_number, std::make_unique<Botan::BigInt>(std::move(serial_bn)));
658 });
659#else
660 BOTAN_UNUSED(cert, serial_number);
662#endif
663}
const std::vector< uint8_t > & serial_number() const
Definition x509cert.cpp:402

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), Botan::BigInt::from_bytes(), and Botan::X509_Certificate::serial_number().

◆ botan_x509_cert_subject_alternative_names()

int botan_x509_cert_subject_alternative_names ( botan_x509_cert_t cert,
size_t index,
botan_x509_general_name_t * alt_name )

Provides access to all "subject alternative names", where each entry is returned as a botan_x509_general_name_t. If the given index is not within range of the available entries, BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. If cert does not contain a SubjectAlternativeNames extension, BOTAN_FFI_ERROR_NO_VALUE is returned.

Definition at line 859 of file ffi_cert.cpp.

861 {
862#if defined(BOTAN_HAS_X509_CERTIFICATES)
863 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
864 if(Botan::any_null_pointers(alt_name)) {
866 }
867
868 if(!c.v3_extensions().extension_set(Botan::OID::from_string("X509v3.SubjectAlternativeName"))) {
870 }
871
872 if(auto name = extract_general_name_at(c.subject_alt_name(), index)) {
873 return ffi_new_object(alt_name, std::make_unique<Botan::GeneralName>(std::move(name).value()));
874 }
875
877 });
878#else
879 BOTAN_UNUSED(cert, index, alt_name);
881#endif
882}
const AlternativeName & subject_alt_name() const
Definition x509cert.cpp:571

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::Extensions::extension_set(), Botan_FFI::ffi_new_object(), Botan::OID::from_string(), Botan::X509_Certificate::subject_alt_name(), and Botan::X509_Certificate::v3_extensions().

◆ botan_x509_cert_subject_alternative_names_count()

int botan_x509_cert_subject_alternative_names_count ( botan_x509_cert_t cert,
size_t * count )

Definition at line 884 of file ffi_cert.cpp.

884 {
885#if defined(BOTAN_HAS_X509_CERTIFICATES)
886 if(Botan::any_null_pointers(count)) {
888 }
889
890 return BOTAN_FFI_VISIT(
891 cert, [=](const Botan::X509_Certificate& c) { *count = count_general_names_in(c.subject_alt_name()); });
892#else
893 BOTAN_UNUSED(cert, count);
895#endif
896}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::X509_Certificate::subject_alt_name().

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

541 {
542 return copy_view_str(reinterpret_cast<uint8_t*>(out), out_len, botan_x509_cert_view_as_string, cert);
543}
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:545

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

1017 {
1018 if(code < 0) {
1019 return nullptr;
1020 }
1021
1022#if defined(BOTAN_HAS_X509_CERTIFICATES)
1024 return Botan::to_string(sc);
1025#else
1026 return nullptr;
1027#endif
1028}
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 950 of file ffi_cert.cpp.

959 {
960 if(required_strength == 0) {
961 required_strength = 110;
962 }
963
964#if defined(BOTAN_HAS_X509_CERTIFICATES)
965 return ffi_guard_thunk(__func__, [=]() -> int {
966 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
968 const auto validation_time = reference_time == 0
969 ? std::chrono::system_clock::now()
970 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
971
972 std::vector<Botan::X509_Certificate> end_certs;
973 end_certs.push_back(safe_get(cert));
974 for(size_t i = 0; i != intermediates_len; ++i) {
975 end_certs.push_back(safe_get(intermediates[i]));
976 }
977
978 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
979 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
980 std::vector<Botan::Certificate_Store*> trusted_roots;
981
982 if(trusted_path != nullptr && *trusted_path != 0) {
983 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
984 trusted_roots.push_back(trusted_from_path.get());
985 }
986
987 if(trusted_len > 0) {
988 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
989 for(size_t i = 0; i != trusted_len; ++i) {
990 trusted_extra->add_certificate(safe_get(trusted[i]));
991 }
992 trusted_roots.push_back(trusted_extra.get());
993 }
994
995 const Botan::Path_Validation_Restrictions restrictions(false, required_strength);
996
997 auto validation_result =
998 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
999
1000 if(result_code != nullptr) {
1001 *result_code = static_cast<int>(validation_result.result());
1002 }
1003
1004 if(validation_result.successful_validation()) {
1005 return 0;
1006 } else {
1007 return 1;
1008 }
1009 });
1010#else
1011 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
1012 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time);
1014#endif
1015}
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:868

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

1431 {
1432 if(required_strength == 0) {
1433 required_strength = 110;
1434 }
1435
1436#if defined(BOTAN_HAS_X509_CERTIFICATES)
1437 return ffi_guard_thunk(__func__, [=]() -> int {
1438 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
1440 const auto validation_time = reference_time == 0
1441 ? std::chrono::system_clock::now()
1442 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
1443
1444 std::vector<Botan::X509_Certificate> end_certs;
1445 end_certs.push_back(safe_get(cert));
1446 for(size_t i = 0; i != intermediates_len; ++i) {
1447 end_certs.push_back(safe_get(intermediates[i]));
1448 }
1449
1450 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
1451 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
1452 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_crls;
1453 std::vector<Botan::Certificate_Store*> trusted_roots;
1454
1455 if(trusted_path != nullptr && *trusted_path != 0) {
1456 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
1457 trusted_roots.push_back(trusted_from_path.get());
1458 }
1459
1460 if(trusted_len > 0) {
1461 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
1462 for(size_t i = 0; i != trusted_len; ++i) {
1463 trusted_extra->add_certificate(safe_get(trusted[i]));
1464 }
1465 trusted_roots.push_back(trusted_extra.get());
1466 }
1467
1468 if(crls_len > 0) {
1469 trusted_crls = std::make_unique<Botan::Certificate_Store_In_Memory>();
1470 for(size_t i = 0; i != crls_len; ++i) {
1471 trusted_crls->add_crl(safe_get(crls[i]));
1472 }
1473 trusted_roots.push_back(trusted_crls.get());
1474 }
1475
1476 const Botan::Path_Validation_Restrictions restrictions(false, required_strength);
1477
1478 auto validation_result =
1479 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
1480
1481 if(result_code != nullptr) {
1482 *result_code = static_cast<int>(validation_result.result());
1483 }
1484
1485 if(validation_result.successful_validation()) {
1486 return 0;
1487 } else {
1488 return 1;
1489 }
1490 });
1491#else
1492 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
1493 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time, crls, crls_len);
1495#endif
1496}

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

545 {
546#if defined(BOTAN_HAS_X509_CERTIFICATES)
547 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return invoke_view_callback(view, ctx, c.to_string()); });
548#else
549 BOTAN_UNUSED(cert, ctx, view);
551#endif
552}

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

int botan_x509_cert_view_binary_values ( botan_x509_cert_t cert,
botan_x509_value_type value_type,
size_t index,
botan_view_ctx ctx,
botan_view_bin_fn view )

Retrieve a specific binary value from an X.509 certificate.

For multi-values index allows enumerating the available entries, until BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an index of value "0" is expected.

Returns
BOTAN_FFI_ERROR_NO_VALUE if the provided cert does not provide the requested value_type at all or not in binary format.

Definition at line 278 of file ffi_cert.cpp.

282 {
283#if defined(BOTAN_HAS_X509_CERTIFICATES)
284 if(index != 0) {
285 // As of now there are no multi-value binary entries.
287 }
288
289 auto view = [=](std::span<const uint8_t> value) -> int {
290 if(value.empty()) {
292 } else {
293 return invoke_view_callback(view_fn, ctx, value);
294 }
295 };
296
297 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) -> int {
298 switch(value_type) {
300 return view(c.serial_number());
302 return view(c.raw_subject_dn());
304 return view(c.raw_issuer_dn());
306 return view(c.subject_key_id());
308 return view(c.authority_key_id());
310 return view(c.subject_public_key_info());
311
316 return botan_x509_object_view_value(c, value_type, index, ctx, view_fn);
317
323 }
324
326 });
327#else
328 BOTAN_UNUSED(cert, value_type, index, ctx, view_fn);
330#endif
331}
const std::vector< uint8_t > & authority_key_id() const
Definition x509cert.cpp:394
const std::vector< uint8_t > & raw_subject_dn() const
Definition x509cert.cpp:422
const std::vector< uint8_t > & subject_key_id() const
Definition x509cert.cpp:398
const std::vector< uint8_t > & raw_issuer_dn() const
Definition x509cert.cpp:418
const std::vector< uint8_t > & subject_public_key_info() const
Definition x509cert.cpp:378

References Botan::X509_Certificate::authority_key_id(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_AUTHORITY_KEY_IDENTIFIER, BOTAN_X509_CA_ISSUERS_URLS, BOTAN_X509_CRL_DISTRIBUTION_URLS, BOTAN_X509_DER_ENCODING, BOTAN_X509_ISSUER_DN_BITS, BOTAN_X509_OCSP_RESPONDER_URLS, BOTAN_X509_PEM_ENCODING, BOTAN_X509_PUBLIC_KEY_PKCS8_BITS, BOTAN_X509_SERIAL_NUMBER, BOTAN_X509_SIGNATURE_BITS, BOTAN_X509_SIGNATURE_SCHEME_BITS, BOTAN_X509_SUBJECT_DN_BITS, BOTAN_X509_SUBJECT_KEY_IDENTIFIER, BOTAN_X509_TBS_DATA_BITS, Botan_FFI::invoke_view_callback(), Botan::X509_Certificate::raw_issuer_dn(), Botan::X509_Certificate::raw_subject_dn(), Botan::X509_Certificate::serial_number(), Botan::X509_Certificate::subject_key_id(), and Botan::X509_Certificate::subject_public_key_info().

Referenced by botan_x509_cert_view_binary_values_count().

◆ botan_x509_cert_view_binary_values_count()

int botan_x509_cert_view_binary_values_count ( botan_x509_cert_t cert,
botan_x509_value_type value_type,
size_t * count )

Definition at line 333 of file ffi_cert.cpp.

333 {
334#if defined(BOTAN_HAS_X509_CERTIFICATES)
335 return enumerator_count_values(count, [=](size_t index) {
337 cert, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
338 });
339#else
340 BOTAN_UNUSED(cert, value_type, count);
342#endif
343}
int botan_x509_cert_view_binary_values(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view_fn)
Definition ffi_cert.cpp:278

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and botan_x509_cert_view_binary_values().

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

700 {
701#if defined(BOTAN_HAS_X509_CERTIFICATES)
702 return BOTAN_FFI_VISIT(cert,
703 [=](const auto& c) { return invoke_view_callback(view, ctx, c.subject_public_key_bits()); });
704#else
705 BOTAN_UNUSED(cert, ctx, view);
707#endif
708}

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

int botan_x509_cert_view_string_values ( botan_x509_cert_t cert,
botan_x509_value_type value_type,
size_t index,
botan_view_ctx ctx,
botan_view_str_fn view )

Retrieve a specific string value from an X.509 certificate.

For multi-values index allows enumerating the available entries, until BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an index of value "0" is expected.

Returns
BOTAN_FFI_ERROR_NO_VALUE if the provided cert does not provide the requested value_type at all or not in string format.

Definition at line 345 of file ffi_cert.cpp.

349 {
350#if defined(BOTAN_HAS_X509_CERTIFICATES)
351 auto enumerate = [view_fn, ctx](auto values, size_t idx) -> int {
352 if(idx >= values.size()) {
354 } else {
355 return invoke_view_callback(view_fn, ctx, values[idx]);
356 }
357 };
358
359 auto enumerate_crl_distribution_points = [view_fn, ctx](const Botan::X509_Certificate& c, size_t idx) -> int {
360 const auto* crl_dp_ext =
361 c.v3_extensions().get_extension_object_as<Botan::Cert_Extension::CRL_Distribution_Points>();
362 if(crl_dp_ext == nullptr) {
363 return BOTAN_FFI_ERROR_OUT_OF_RANGE; // essentially an empty list
364 }
365
366 const auto& dps = crl_dp_ext->distribution_points();
367 for(size_t i = idx; const auto& dp : dps) {
368 const auto& uris = dp.point().uris();
369 if(i >= uris.size()) {
370 i -= uris.size();
371 continue;
372 }
373
374 auto itr = uris.begin();
375 std::advance(itr, i);
376 return invoke_view_callback(view_fn, ctx, *itr);
377 }
378
380 };
381
382 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) -> int {
383 switch(value_type) {
385 return enumerate_crl_distribution_points(c, index);
387 return enumerate(c.ocsp_responders(), index);
389 return enumerate(c.ca_issuers(), index);
391 return botan_x509_object_view_value(c, value_type, index, ctx, view_fn);
392
404 }
405
407 });
408#else
409 BOTAN_UNUSED(cert, value_type, index, ctx, view_fn);
411#endif
412}
const std::vector< Distribution_Point > & distribution_points() const
Definition x509_ext.h:450
const std::vector< std::string > & ocsp_responders() const
Definition x509cert.cpp:551
std::vector< std::string > ca_issuers() const
Definition x509cert.cpp:555

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_AUTHORITY_KEY_IDENTIFIER, BOTAN_X509_CA_ISSUERS_URLS, BOTAN_X509_CRL_DISTRIBUTION_URLS, BOTAN_X509_DER_ENCODING, BOTAN_X509_ISSUER_DN_BITS, BOTAN_X509_OCSP_RESPONDER_URLS, BOTAN_X509_PEM_ENCODING, BOTAN_X509_PUBLIC_KEY_PKCS8_BITS, BOTAN_X509_SERIAL_NUMBER, BOTAN_X509_SIGNATURE_BITS, BOTAN_X509_SIGNATURE_SCHEME_BITS, BOTAN_X509_SUBJECT_DN_BITS, BOTAN_X509_SUBJECT_KEY_IDENTIFIER, BOTAN_X509_TBS_DATA_BITS, Botan::Cert_Extension::CRL_Distribution_Points::distribution_points(), and Botan_FFI::invoke_view_callback().

Referenced by botan_x509_cert_view_string_values_count().

◆ botan_x509_cert_view_string_values_count()

int botan_x509_cert_view_string_values_count ( botan_x509_cert_t cert,
botan_x509_value_type value_type,
size_t * count )

Definition at line 414 of file ffi_cert.cpp.

414 {
415#if defined(BOTAN_HAS_X509_CERTIFICATES)
416 return enumerator_count_values(count, [=](size_t index) {
418 cert, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
419 });
420#else
421 BOTAN_UNUSED(cert, value_type, count);
423#endif
424}
int botan_x509_cert_view_string_values(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view_fn)
Definition ffi_cert.cpp:345

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and botan_x509_cert_view_string_values().

◆ botan_x509_crl_create()

int botan_x509_crl_create ( botan_x509_crl_t * crl_obj,
botan_rng_t rng,
botan_x509_cert_t ca_cert,
botan_privkey_t ca_key,
uint64_t issue_time,
uint32_t next_update,
const char * hash_fn,
const char * padding )

Create a new CRL

Parameters
crl_objThe newly created CRL
rnga random number generator object
ca_certThe CA Certificate the CRL belongs to
ca_keyThe private key of that CA
issue_timeThe time when the CRL becomes valid
next_updateThe number of seconds after issue_time until the CRL expires
hash_fnThe hash function to use, may be null
paddingThe padding to use, may be null

Definition at line 1100 of file ffi_cert.cpp.

1107 {
1108 if(Botan::any_null_pointers(crl_obj)) {
1110 }
1111#if defined(BOTAN_HAS_X509_CERTIFICATES)
1112 return ffi_guard_thunk(__func__, [=]() -> int {
1113 auto& rng_ = safe_get(rng);
1114 auto ca = Botan::X509_CA(
1115 safe_get(ca_cert), safe_get(ca_key), default_from_ptr(hash_fn), default_from_ptr(padding), rng_);
1116 auto crl = std::make_unique<Botan::X509_CRL>(
1117 ca.new_crl(rng_, timepoint_from_timestamp(issue_time), std::chrono::seconds(next_update)));
1118 return ffi_new_object(crl_obj, std::move(crl));
1119 });
1120#else
1121 BOTAN_UNUSED(rng, ca_cert, ca_key, hash_fn, padding, issue_time, next_update);
1123#endif
1124}

References Botan::any_null_pointers(), 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_crl_destroy()

int botan_x509_crl_destroy ( botan_x509_crl_t crl)

Definition at line 1190 of file ffi_cert.cpp.

1190 {
1191#if defined(BOTAN_HAS_X509_CERTIFICATES)
1192 return BOTAN_FFI_CHECKED_DELETE(crl);
1193#else
1194 BOTAN_UNUSED(crl);
1196#endif
1197}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_crl_entries()

int botan_x509_crl_entries ( botan_x509_crl_t crl,
size_t index,
botan_x509_crl_entry_t * entry )

Allows iterating all entries of the CRL.

Parameters
crlthe CRL whose entries should be listed
indexthe index of the CRL entry to return
entryan object handle containing the CRL entry data
Returns
BOTAN_FFI_ERROR_OUT_OF_RANGE if the given index is out of range of the CRL entry list.

Definition at line 1320 of file ffi_cert.cpp.

1320 {
1321#if defined(BOTAN_HAS_X509_CERTIFICATES)
1322 return BOTAN_FFI_VISIT(crl, [=](const Botan::X509_CRL& c) -> int {
1323 const auto& entries = c.get_revoked();
1324 if(index >= entries.size()) {
1326 }
1327
1328 if(Botan::any_null_pointers(entry)) {
1330 }
1331
1332 return ffi_new_object(entry, std::make_unique<Botan::CRL_Entry>(entries[index]));
1333 });
1334#else
1335 BOTAN_UNUSED(crl, index, entry);
1337#endif
1338}
const std::vector< CRL_Entry > & get_revoked() const
Definition x509_crl.cpp:203

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), and Botan::X509_CRL::get_revoked().

◆ botan_x509_crl_entries_count()

int botan_x509_crl_entries_count ( botan_x509_crl_t crl,
size_t * count )

Definition at line 1340 of file ffi_cert.cpp.

1340 {
1341#if defined(BOTAN_HAS_X509_CERTIFICATES)
1342 if(Botan::any_null_pointers(count)) {
1344 }
1345
1346 return BOTAN_FFI_VISIT(crl, [=](const Botan::X509_CRL& c) { *count = c.get_revoked().size(); });
1347#else
1348 BOTAN_UNUSED(crl, count);
1350#endif
1351}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::X509_CRL::get_revoked().

◆ botan_x509_crl_entry_create()

int botan_x509_crl_entry_create ( botan_x509_crl_entry_t * entry,
botan_x509_cert_t cert,
int reason_code )

Create a new CRL entry that marks cert as revoked

Parameters
entryThe newly created CRL entry
certThe certificate to mark as revoked
reason_codeThe reason code for revocation

Definition at line 1126 of file ffi_cert.cpp.

1126 {
1127 if(Botan::any_null_pointers(entry)) {
1129 }
1130#if defined(BOTAN_HAS_X509_CERTIFICATES)
1131 return ffi_guard_thunk(__func__, [=]() -> int {
1132 return ffi_new_object(
1133 entry, std::make_unique<Botan::CRL_Entry>(safe_get(cert), static_cast<Botan::CRL_Code>(reason_code)));
1134 });
1135#else
1136 BOTAN_UNUSED(cert, reason_code);
1138#endif
1139}

References Botan::any_null_pointers(), 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_crl_entry_destroy()

int botan_x509_crl_entry_destroy ( botan_x509_crl_entry_t entry)

Definition at line 1353 of file ffi_cert.cpp.

1353 {
1354#if defined(BOTAN_HAS_X509_CERTIFICATES)
1355 return BOTAN_FFI_CHECKED_DELETE(entry);
1356#else
1357 BOTAN_UNUSED(entry);
1359#endif
1360}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_crl_entry_reason()

int botan_x509_crl_entry_reason ( botan_x509_crl_entry_t entry,
int * reason_code )

Return the revocation reason code for the given CRL entry. See botan_x509_crl_reason_code and RFC 5280 - 5.3.1 for possible reason codes.

Definition at line 1362 of file ffi_cert.cpp.

1362 {
1363#if defined(BOTAN_HAS_X509_CERTIFICATES)
1364 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1365 if(Botan::any_null_pointers(reason_code)) {
1367 }
1368
1369 *reason_code = static_cast<int>(e.reason_code());
1370 return BOTAN_FFI_SUCCESS;
1371 });
1372#else
1373 BOTAN_UNUSED(entry, reason_code);
1375#endif
1376}
Definition x509_crl.h:29
CRL_Code reason_code() const
Definition crl_ent.cpp:147

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::CRL_Entry::reason_code().

◆ botan_x509_crl_entry_revocation_date()

int botan_x509_crl_entry_revocation_date ( botan_x509_crl_entry_t entry,
uint64_t * time_since_epoch )

Return the revocation date for the given CRL entry as time since epoch in seconds.

Definition at line 1404 of file ffi_cert.cpp.

1404 {
1405#if defined(BOTAN_HAS_X509_CERTIFICATES)
1406 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1407 if(Botan::any_null_pointers(time_since_epoch)) {
1409 }
1410
1411 *time_since_epoch = e.expire_time().time_since_epoch();
1412 return BOTAN_FFI_SUCCESS;
1413 });
1414#else
1415 BOTAN_UNUSED(entry, time_since_epoch);
1417#endif
1418}
uint64_t time_since_epoch() const
Return time since epoch.
const X509_Time & expire_time() const
Definition crl_ent.cpp:143

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::CRL_Entry::expire_time(), and Botan::ASN1_Time::time_since_epoch().

◆ botan_x509_crl_entry_serial_number()

int botan_x509_crl_entry_serial_number ( botan_x509_crl_entry_t entry,
botan_mp_t * serial_number )

Return the serial number associated with the given CRL entry.

Definition at line 1378 of file ffi_cert.cpp.

1378 {
1379#if defined(BOTAN_HAS_X509_CERTIFICATES)
1380 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1381 if(Botan::any_null_pointers(serial_number)) {
1383 }
1384
1385 auto serial_bn = Botan::BigInt::from_bytes(e.serial_number());
1386 return ffi_new_object(serial_number, std::make_unique<Botan::BigInt>(std::move(serial_bn)));
1387 });
1388#else
1389 BOTAN_UNUSED(entry, serial_number);
1391#endif
1392}
const std::vector< uint8_t > & serial_number() const
Definition crl_ent.cpp:139

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), Botan::BigInt::from_bytes(), and Botan::CRL_Entry::serial_number().

◆ botan_x509_crl_entry_view_serial_number()

int botan_x509_crl_entry_view_serial_number ( botan_x509_crl_entry_t entry,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the serial number associated with the given CRL entry.

Definition at line 1394 of file ffi_cert.cpp.

1394 {
1395#if defined(BOTAN_HAS_X509_CERTIFICATES)
1396 return BOTAN_FFI_VISIT(
1397 entry, [=](const Botan::CRL_Entry& e) { return invoke_view_callback(view, ctx, e.serial_number()); });
1398#else
1399 BOTAN_UNUSED(entry, ctx, view);
1401#endif
1402}

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

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

1047 {
1048 if(crl_obj == nullptr || crl_bits == nullptr) {
1050 }
1051
1052#if defined(BOTAN_HAS_X509_CERTIFICATES)
1053 return ffi_guard_thunk(__func__, [=]() -> int {
1054 Botan::DataSource_Memory bits(crl_bits, crl_bits_len);
1055 auto c = std::make_unique<Botan::X509_CRL>(bits);
1056 return ffi_new_object(crl_obj, std::move(c));
1057 });
1058#else
1059 BOTAN_UNUSED(crl_bits_len);
1061#endif
1062}

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

1030 {
1031 if(crl_obj == nullptr || crl_path == nullptr) {
1033 }
1034
1035#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
1036
1037 return ffi_guard_thunk(__func__, [=]() -> int {
1038 auto c = std::make_unique<Botan::X509_CRL>(crl_path);
1039 return ffi_new_object(crl_obj, std::move(c));
1040 });
1041
1042#else
1044#endif
1045}

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

◆ botan_x509_crl_next_update()

int botan_x509_crl_next_update ( botan_x509_crl_t crl,
uint64_t * time_since_epoch )

Definition at line 1079 of file ffi_cert.cpp.

1079 {
1080#if defined(BOTAN_HAS_X509_CERTIFICATES)
1081 return BOTAN_FFI_VISIT(crl, [=](const auto& c) {
1082 const auto& time = c.next_update();
1083 if(!time.time_is_set()) {
1085 }
1086
1087 if(Botan::any_null_pointers(time_since_epoch)) {
1089 }
1090
1091 *time_since_epoch = c.next_update().time_since_epoch();
1092 return BOTAN_FFI_SUCCESS;
1093 });
1094#else
1095 BOTAN_UNUSED(crl, time_since_epoch);
1097#endif
1098}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_crl_this_update()

int botan_x509_crl_this_update ( botan_x509_crl_t crl,
uint64_t * time_since_epoch )

Definition at line 1064 of file ffi_cert.cpp.

1064 {
1065#if defined(BOTAN_HAS_X509_CERTIFICATES)
1066 return BOTAN_FFI_VISIT(crl, [=](const auto& c) {
1067 if(Botan::any_null_pointers(time_since_epoch)) {
1069 }
1070 *time_since_epoch = c.this_update().time_since_epoch();
1071 return BOTAN_FFI_SUCCESS;
1072 });
1073#else
1074 BOTAN_UNUSED(crl, time_since_epoch);
1076#endif
1077}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_crl_update()

int botan_x509_crl_update ( botan_x509_crl_t * crl_obj,
botan_x509_crl_t last_crl,
botan_rng_t rng,
botan_x509_cert_t ca_cert,
botan_privkey_t ca_key,
uint64_t issue_time,
uint32_t next_update,
const botan_x509_crl_entry_t * new_entries,
size_t new_entries_len,
const char * hash_fn,
const char * padding )

Update a CRL with new revoked entries. This does not modify the old crl, and instead creates a new one.

Parameters
crl_objThe newly created CRL
last_crlThe CRL to update
rnga random number generator object
ca_certThe CA Certificate the CRL belongs to
ca_keyThe private key of that CA
issue_timeThe time when the CRL becomes valid
next_updateThe number of seconds after issue_time until the CRL expires
new_entriesThe entries to add to the CRL
new_entries_lenThe number of entries
hash_fnThe hash function to use, may be null
paddingThe padding to use, may be null

Definition at line 1141 of file ffi_cert.cpp.

1151 {
1152 if(Botan::any_null_pointers(crl_obj)) {
1154 }
1155 if(new_entries_len > 0 && Botan::any_null_pointers(new_entries)) {
1157 }
1158#if defined(BOTAN_HAS_X509_CERTIFICATES)
1159 return ffi_guard_thunk(__func__, [=]() -> int {
1160 auto& rng_ = safe_get(rng);
1161 auto ca = Botan::X509_CA(
1162 safe_get(ca_cert), safe_get(ca_key), default_from_ptr(hash_fn), default_from_ptr(padding), rng_);
1163
1164 std::vector<Botan::CRL_Entry> entries;
1165 entries.reserve(new_entries_len);
1166 for(size_t i = 0; i < new_entries_len; i++) {
1167 entries.push_back(safe_get(new_entries[i]));
1168 }
1169
1170 auto crl = std::make_unique<Botan::X509_CRL>(ca.update_crl(
1171 safe_get(last_crl), entries, rng_, timepoint_from_timestamp(issue_time), std::chrono::seconds(next_update)));
1172 return ffi_new_object(crl_obj, std::move(crl));
1173 });
1174#else
1176 last_crl, rng, ca_cert, ca_key, hash_fn, padding, issue_time, next_update, new_entries, new_entries_len);
1178#endif
1179}

References Botan::any_null_pointers(), 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_crl_verify_signature()

int botan_x509_crl_verify_signature ( botan_x509_crl_t crl,
botan_pubkey_t key )

Definition at line 1181 of file ffi_cert.cpp.

1181 {
1182#if defined(BOTAN_HAS_X509_CERTIFICATES)
1183 return BOTAN_FFI_VISIT(crl, [=](const auto& c) -> int { return c.check_signature(safe_get(key)) ? 1 : 0; });
1184#else
1185 BOTAN_UNUSED(crl, key);
1187#endif
1188}

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

◆ botan_x509_crl_view_binary_values()

int botan_x509_crl_view_binary_values ( botan_x509_crl_t crl_obj,
botan_x509_value_type value_type,
size_t index,
botan_view_ctx ctx,
botan_view_bin_fn view )

Retrieve a specific binary value from an X.509 certificate revocation list.

For multi-values index allows enumerating the available entries, until BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an index of value "0" is expected.

Returns
BOTAN_FFI_ERROR_NO_VALUE if the provided crl_obj does not provide the requested value_type at all or not in binary format.

Definition at line 1199 of file ffi_cert.cpp.

1203 {
1204#if defined(BOTAN_HAS_X509_CERTIFICATES)
1205 if(index != 0) {
1206 // As of now there are no multi-value binary entries.
1208 }
1209
1210 auto view = [=](std::span<const uint8_t> value) -> int {
1211 if(value.empty()) {
1213 } else {
1214 return invoke_view_callback(view_fn, ctx, value);
1215 }
1216 };
1217
1218 return BOTAN_FFI_VISIT(crl_obj, [=](const Botan::X509_CRL& crl) -> int {
1219 switch(value_type) {
1221 return view(Botan::store_be(crl.crl_number()));
1223 return view(Botan::ASN1::put_in_sequence(crl.issuer_dn().get_bits()));
1225 return view(crl.authority_key_id());
1226
1231 return botan_x509_object_view_value(crl, value_type, index, ctx, view_fn);
1232
1241 }
1242
1244 });
1245#else
1246 BOTAN_UNUSED(crl_obj, value_type, index, ctx, view_fn);
1248#endif
1249}
const std::vector< uint8_t > & authority_key_id() const
Definition x509_crl.cpp:221
uint32_t crl_number() const
Definition x509_crl.cpp:228
const X509_DN & issuer_dn() const
Definition x509_crl.cpp:214
const std::vector< uint8_t > & get_bits() const
Definition pkix_types.h:82
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition asn1_obj.cpp:177
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745

References Botan::X509_CRL::authority_key_id(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_AUTHORITY_KEY_IDENTIFIER, BOTAN_X509_CA_ISSUERS_URLS, BOTAN_X509_CRL_DISTRIBUTION_URLS, BOTAN_X509_DER_ENCODING, BOTAN_X509_ISSUER_DN_BITS, BOTAN_X509_OCSP_RESPONDER_URLS, BOTAN_X509_PEM_ENCODING, BOTAN_X509_PUBLIC_KEY_PKCS8_BITS, BOTAN_X509_SERIAL_NUMBER, BOTAN_X509_SIGNATURE_BITS, BOTAN_X509_SIGNATURE_SCHEME_BITS, BOTAN_X509_SUBJECT_DN_BITS, BOTAN_X509_SUBJECT_KEY_IDENTIFIER, BOTAN_X509_TBS_DATA_BITS, Botan::X509_CRL::crl_number(), Botan::X509_DN::get_bits(), Botan_FFI::invoke_view_callback(), Botan::X509_CRL::issuer_dn(), Botan::ASN1::put_in_sequence(), and Botan::store_be().

Referenced by botan_x509_crl_view_binary_values_count().

◆ botan_x509_crl_view_binary_values_count()

int botan_x509_crl_view_binary_values_count ( botan_x509_crl_t crl_obj,
botan_x509_value_type value_type,
size_t * count )

Definition at line 1251 of file ffi_cert.cpp.

1251 {
1252#if defined(BOTAN_HAS_X509_CERTIFICATES)
1253 return enumerator_count_values(count, [=](size_t index) {
1255 crl_obj, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
1256 });
1257#else
1258 BOTAN_UNUSED(crl_obj, value_type, count);
1260#endif
1261}
int botan_x509_crl_view_binary_values(botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view_fn)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and botan_x509_crl_view_binary_values().

◆ botan_x509_crl_view_string_values()

int botan_x509_crl_view_string_values ( botan_x509_crl_t crl_obj,
botan_x509_value_type value_type,
size_t index,
botan_view_ctx ctx,
botan_view_str_fn view )

Retrieve a specific string value from an X.509 certificate revocation list.

For multi-values index allows enumerating the available entries, until BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an index of value "0" is expected.

Returns
BOTAN_FFI_ERROR_NO_VALUE if the provided crl_obj does not provide the requested value_type at all or not in string format.

Definition at line 1263 of file ffi_cert.cpp.

1267 {
1268#if defined(BOTAN_HAS_X509_CERTIFICATES)
1269 return BOTAN_FFI_VISIT(crl_obj, [=](const Botan::X509_CRL& crl) -> int {
1270 switch(value_type) {
1272 return botan_x509_object_view_value(crl, value_type, index, ctx, view);
1273
1288 }
1289
1291 });
1292#else
1293 BOTAN_UNUSED(crl_obj, value_type, index, ctx, view);
1295#endif
1296}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_AUTHORITY_KEY_IDENTIFIER, BOTAN_X509_CA_ISSUERS_URLS, BOTAN_X509_CRL_DISTRIBUTION_URLS, BOTAN_X509_DER_ENCODING, BOTAN_X509_ISSUER_DN_BITS, BOTAN_X509_OCSP_RESPONDER_URLS, BOTAN_X509_PEM_ENCODING, BOTAN_X509_PUBLIC_KEY_PKCS8_BITS, BOTAN_X509_SERIAL_NUMBER, BOTAN_X509_SIGNATURE_BITS, BOTAN_X509_SIGNATURE_SCHEME_BITS, BOTAN_X509_SUBJECT_DN_BITS, BOTAN_X509_SUBJECT_KEY_IDENTIFIER, and BOTAN_X509_TBS_DATA_BITS.

Referenced by botan_x509_crl_view_string_values_count().

◆ botan_x509_crl_view_string_values_count()

int botan_x509_crl_view_string_values_count ( botan_x509_crl_t crl_obj,
botan_x509_value_type value_type,
size_t * count )

Definition at line 1298 of file ffi_cert.cpp.

1298 {
1299#if defined(BOTAN_HAS_X509_CERTIFICATES)
1300 return enumerator_count_values(count, [=](size_t index) {
1302 crl_obj, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
1303 });
1304#else
1305 BOTAN_UNUSED(crl_obj, value_type, count);
1307#endif
1308}
int botan_x509_crl_view_string_values(botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and botan_x509_crl_view_string_values().

◆ botan_x509_general_name_destroy()

int botan_x509_general_name_destroy ( botan_x509_general_name_t alt_names)

Definition at line 780 of file ffi_cert.cpp.

780 {
781#if defined(BOTAN_HAS_X509_CERTIFICATES)
782 return BOTAN_FFI_CHECKED_DELETE(name);
783#else
784 BOTAN_UNUSED(name);
786#endif
787}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_general_name_get_type()

int botan_x509_general_name_get_type ( botan_x509_general_name_t name,
unsigned int * type )

Provides the contained type of the name and returns BOTAN_FFI_SUCCESS if that type is supported and may be retrieved via the view functions below. Otherwise BOTAN_FFI_ERROR_INVALID_OBJECT_STATE is returned.

Definition at line 710 of file ffi_cert.cpp.

710 {
711#if defined(BOTAN_HAS_X509_CERTIFICATES)
712 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) {
713 if(Botan::any_null_pointers(type)) {
715 }
716
717 const auto mapped_type = to_botan_x509_general_name_types(n.type_code());
718 if(!mapped_type.has_value()) {
720 }
721
722 *type = mapped_type.value();
723 if(*type == BOTAN_X509_OTHER_NAME /* ... viewing of other-names not supported */) {
725 }
726
727 return BOTAN_FFI_SUCCESS;
728 });
729#else
730 BOTAN_UNUSED(name, type);
732#endif
733}
X.509 GeneralName Type.
Definition pkix_types.h:274
NameType type_code() const
Definition pkix_types.h:311

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_OTHER_NAME, and Botan::GeneralName::type_code().

◆ botan_x509_general_name_view_binary_value()

int botan_x509_general_name_view_binary_value ( botan_x509_general_name_t name,
botan_view_ctx ctx,
botan_view_bin_fn view )

Views the name as a bit string or returns BOTAN_FFI_ERROR_INVALID_OBJECT_STATE if the contained GeneralName value cannot be represented as a binary string.

The types BOTAN_X509_DIRECTORY_NAME, BOTAN_X509_IP_ADDRESS may be viewed as "binary".

Definition at line 758 of file ffi_cert.cpp.

760 {
761#if defined(BOTAN_HAS_X509_CERTIFICATES)
762 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) -> int {
763 const auto type = to_botan_x509_general_name_types(n.type_code());
764 if(!type) {
766 }
767
768 if(type != BOTAN_X509_DIRECTORY_NAME && type != BOTAN_X509_IP_ADDRESS) {
770 }
771
772 return invoke_view_callback(view, ctx, n.binary_name());
773 });
774#else
775 BOTAN_UNUSED(name, ctx, view);
777#endif
778}
std::vector< uint8_t > binary_name() const

References Botan::GeneralName::binary_name(), BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_DIRECTORY_NAME, BOTAN_X509_IP_ADDRESS, Botan_FFI::invoke_view_callback(), and Botan::GeneralName::type_code().

◆ botan_x509_general_name_view_string_value()

int botan_x509_general_name_view_string_value ( botan_x509_general_name_t name,
botan_view_ctx ctx,
botan_view_str_fn view )

Views the name as a string or returns BOTAN_FFI_ERROR_INVALID_OBJECT_STATE if the contained GeneralName value cannot be represented as a string.

The types BOTAN_X509_EMAIL_ADDRESS, BOTAN_X509_DNS_NAME, BOTAN_X509_URI, BOTAN_X509_IP_ADDRESS may be viewed as "string".

Definition at line 735 of file ffi_cert.cpp.

737 {
738#if defined(BOTAN_HAS_X509_CERTIFICATES)
739 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) -> int {
740 const auto type = to_botan_x509_general_name_types(n.type_code());
741 if(!type) {
743 }
744
745 if(type != BOTAN_X509_EMAIL_ADDRESS && type != BOTAN_X509_DNS_NAME && type != BOTAN_X509_URI &&
746 type != BOTAN_X509_IP_ADDRESS) {
748 }
749
750 return invoke_view_callback(view, ctx, n.name());
751 });
752#else
753 BOTAN_UNUSED(name, ctx, view);
755#endif
756}
std::string name() const

References BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_DNS_NAME, BOTAN_X509_EMAIL_ADDRESS, BOTAN_X509_IP_ADDRESS, BOTAN_X509_URI, Botan_FFI::invoke_view_callback(), Botan::GeneralName::name(), and Botan::GeneralName::type_code().

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

1310 {
1311#if defined(BOTAN_HAS_X509_CERTIFICATES)
1312 return BOTAN_FFI_VISIT(crl, [=](const auto& c) { return c.is_revoked(safe_get(cert)) ? 0 : -1; });
1313#else
1314 BOTAN_UNUSED(cert);
1315 BOTAN_UNUSED(crl);
1317#endif
1318}

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

◆ botan_xof_accepts_input()

int botan_xof_accepts_input ( botan_xof_t xof)

Get the input/output state of this eXtendable Output Function Typically, XOFs don't accept input as soon as the first output bytes were requested.

Parameters
xofthe object to read
Returns
1 iff the XOF is still accepting input bytes

Definition at line 58 of file ffi_xof.cpp.

58 {
59 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { return xof.accepts_input() ? 1 : 0; });
60}

References BOTAN_FFI_VISIT.

◆ botan_xof_block_size()

int botan_xof_block_size ( botan_xof_t xof,
size_t * block_size )

Writes the block size of the eXtendable Output Function to *block_size

Parameters
xofXOF object
block_sizevariable to hold the XOF's block size
Returns
0 on success, a negative value on failure

Definition at line 43 of file ffi_xof.cpp.

43 {
46 }
47 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { *out = xof.block_size(); });
48}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_xof_clear()

int botan_xof_clear ( botan_xof_t xof)

Reinitializes the state of the eXtendable Output Function.

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

Definition at line 62 of file ffi_xof.cpp.

62 {
63 return BOTAN_FFI_VISIT(this_xof, [](auto& xof) { xof.clear(); });
64}

References BOTAN_FFI_VISIT.

◆ botan_xof_copy_state()

int botan_xof_copy_state ( botan_xof_t * dest,
botan_xof_t source )

Copy the state of an eXtendable Output Function

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

Definition at line 39 of file ffi_xof.cpp.

39 {
40 return BOTAN_FFI_VISIT(this_xof, [=](const auto& src) { return ffi_new_object(dest, src.copy_state()); });
41}

References BOTAN_FFI_VISIT, and Botan_FFI::ffi_new_object().

◆ botan_xof_destroy()

int botan_xof_destroy ( botan_xof_t xof)

Frees all resources of the eXtendable Output Function object

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

Definition at line 90 of file ffi_xof.cpp.

90 {
91 return BOTAN_FFI_CHECKED_DELETE(xof);
92}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_xof_init()

int botan_xof_init ( botan_xof_t * xof,
const char * xof_name,
uint32_t flags )

Initialize an eXtendable Output Function

Parameters
xofXOF object
xof_namename of the XOF, e.g., "SHAKE-128"
flagsshould be 0 in current API revision, all other uses are reserved and return BOTAN_FFI_ERROR_BAD_FLAG

Definition at line 19 of file ffi_xof.cpp.

19 {
20 return ffi_guard_thunk(__func__, [=]() -> int {
21 if(Botan::any_null_pointers(this_xof, xof_name) || *xof_name == 0) {
23 }
24 if(flags != 0) {
26 }
27
28 auto xof = Botan::XOF::create(xof_name);
29 if(xof == nullptr) {
31 }
32
33 ffi_new_object(this_xof, std::move(xof));
34 return BOTAN_FFI_SUCCESS;
35 });
36}
static std::unique_ptr< XOF > create(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:28

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

◆ botan_xof_name()

int botan_xof_name ( botan_xof_t xof,
char * name,
size_t * name_len )

Get the name of this eXtendable Output Function

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

Definition at line 50 of file ffi_xof.cpp.

50 {
51 if(Botan::any_null_pointers(name_len)) {
53 }
54
55 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { return write_str_output(name, name_len, xof.name()); });
56}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::write_str_output().

◆ botan_xof_output()

int botan_xof_output ( botan_xof_t xof,
uint8_t * out,
size_t out_len )

Generate output bytes from the eXtendable Output Function

Parameters
xofXOF object
outoutput buffer
out_lennumber of bytes to write into the output buffer
Returns
0 on success, a negative value on failure

Definition at line 78 of file ffi_xof.cpp.

78 {
79 if(out_len == 0) {
80 return 0;
81 }
82
85 }
86
87 return BOTAN_FFI_VISIT(this_xof, [=](auto& xof) { xof.output({out, out_len}); });
88}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_xof_update()

int botan_xof_update ( botan_xof_t xof,
const uint8_t * in,
size_t in_len )

Send more input to the eXtendable Output Function

Parameters
xofXOF 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 66 of file ffi_xof.cpp.

66 {
67 if(in_len == 0) {
68 return 0;
69 }
70
73 }
74
75 return BOTAN_FFI_VISIT(this_xof, [=](auto& xof) { xof.update({in, in_len}); });
76}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ 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 32 of file ffi_zfec.cpp.

33 {
34#if defined(BOTAN_HAS_ZFEC)
35 return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
36 std::map<size_t, const uint8_t*> shares;
37 for(size_t k = 0; k < K; ++k) {
38 shares.insert(std::pair<size_t, const uint8_t*>(indexes[k], inputs[k]));
39 }
41 shares, shareSize, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
42 std::copy(block, block + blockSize, outputs[index]);
43 });
44 return BOTAN_FFI_SUCCESS;
45 });
46#else
47 BOTAN_UNUSED(K, N, indexes, inputs, shareSize, outputs);
49#endif
50}
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 18 of file ffi_zfec.cpp.

18 {
19#if defined(BOTAN_HAS_ZFEC)
20 return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
21 Botan::ZFEC(K, N).encode(input, size, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
22 std::copy(block, block + blockSize, outputs[index]);
23 });
24 return BOTAN_FFI_SUCCESS;
25 });
26#else
27 BOTAN_UNUSED(K, N, input, size, outputs);
29#endif
30}
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().