Botan 3.13.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   20260811
#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_ec_point_struct * botan_ec_point_t
typedef struct botan_ec_scalar_struct * botan_ec_scalar_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_spake2p_params_struct * botan_spake2p_params_t
typedef struct botan_spake2p_prover_struct * botan_spake2p_prover_t
typedef struct botan_spake2p_verifier_struct * botan_spake2p_verifier_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_point_add (botan_ec_point_t *result, botan_ec_point_t x, botan_ec_point_t y)
int botan_ec_point_destroy (botan_ec_point_t ec_point)
int botan_ec_point_equal (botan_ec_point_t x, botan_ec_point_t y)
int botan_ec_point_from_bytes (botan_ec_point_t *ec_point, botan_ec_group_t ec_group, const uint8_t *bytes, size_t bytes_len)
int botan_ec_point_from_xy (botan_ec_point_t *ec_point, botan_ec_group_t ec_group, botan_mp_t x, botan_mp_t y)
int botan_ec_point_generator (botan_ec_point_t *ec_point, botan_ec_group_t ec_group)
int botan_ec_point_identity (botan_ec_point_t *ec_point, botan_ec_group_t ec_group)
int botan_ec_point_is_identity (botan_ec_point_t ec_point)
int botan_ec_point_mul (botan_ec_point_t *result, botan_ec_point_t ec_point, botan_ec_scalar_t ec_scalar, botan_rng_t rng)
int botan_ec_point_negate (botan_ec_point_t *result, botan_ec_point_t ec_point)
int botan_ec_point_view_compressed (botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_point_view_uncompressed (botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_point_view_x_bytes (botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_point_view_xy_bytes (botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_point_view_y_bytes (botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_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)
int botan_ec_privkey_get_group (botan_privkey_t key, botan_ec_group_t *ec_group)
int botan_ec_privkey_get_private_key (botan_privkey_t key, botan_ec_scalar_t *value)
int botan_ec_pubkey_get_group (botan_pubkey_t key, botan_ec_group_t *ec_group)
int botan_ec_scalar_destroy (botan_ec_scalar_t ec_scalar)
int botan_ec_scalar_from_mp (botan_ec_scalar_t *ec_scalar, botan_ec_group_t ec_group, botan_mp_t mp)
int botan_ec_scalar_random (botan_ec_scalar_t *ec_scalar, botan_ec_group_t ec_group, botan_rng_t rng)
int botan_ec_scalar_to_mp (botan_ec_scalar_t ec_scalar, botan_mp_t *mp)
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_security_level (botan_hash_t hash, size_t *security_level)
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_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_generate_with_input (botan_rng_t rng, uint8_t *out, size_t out_len, const uint8_t *addl_input, size_t addl_len)
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_init_drbg (botan_rng_t *rng_out, const char *drbg_name, const uint8_t *seed, size_t seed_len)
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_spake2p_derive_secret (botan_spake2p_params_t params, const char *password, const uint8_t prover_id[], size_t prover_id_len, const uint8_t verifier_id[], size_t verifier_id_len, const uint8_t salt[], size_t salt_len, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_spake2p_params_confirmation_size (botan_spake2p_params_t params, size_t *confirmation_size)
int botan_spake2p_params_destroy (botan_spake2p_params_t params)
int botan_spake2p_params_init (botan_spake2p_params_t *params, const char *ciphersuite)
int botan_spake2p_params_init_custom (botan_spake2p_params_t *params, botan_ec_group_t group, const uint8_t seed[], size_t seed_len, const char *hash_fn)
int botan_spake2p_params_share_size (botan_spake2p_params_t params, size_t *share_size)
int botan_spake2p_prover_destroy (botan_spake2p_prover_t prover)
int botan_spake2p_prover_generate_message (botan_spake2p_prover_t prover, botan_rng_t rng, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_spake2p_prover_init (botan_spake2p_prover_t *prover, botan_spake2p_params_t params, const uint8_t secret[], size_t secret_len, const uint8_t prover_id[], size_t prover_id_len, const uint8_t verifier_id[], size_t verifier_id_len, const uint8_t context[], size_t context_len)
int botan_spake2p_prover_process_message (botan_spake2p_prover_t prover, botan_rng_t rng, const uint8_t peer_message[], size_t peer_message_len, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_spake2p_prover_shared_secret (botan_spake2p_prover_t prover, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_spake2p_registration_record (botan_spake2p_params_t params, botan_rng_t rng, const uint8_t secret[], size_t secret_len, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_spake2p_verifier_destroy (botan_spake2p_verifier_t verifier)
int botan_spake2p_verifier_init (botan_spake2p_verifier_t *verifier, botan_spake2p_params_t params, const uint8_t record[], size_t record_len, const uint8_t prover_id[], size_t prover_id_len, const uint8_t verifier_id[], size_t verifier_id_len, const uint8_t context[], size_t context_len)
int botan_spake2p_verifier_process_message (botan_spake2p_verifier_t verifier, botan_rng_t rng, const uint8_t peer_message[], size_t peer_message_len, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_spake2p_verifier_shared_secret (botan_spake2p_verifier_t verifier, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_spake2p_verifier_skip_confirmation (botan_spake2p_verifier_t verifier)
int botan_spake2p_verifier_verify_confirmation (botan_spake2p_verifier_t verifier, const uint8_t confirmation[], size_t confirmation_len)
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_ext_as_blocks_get_entry_at (botan_x509_cert_t cert, int asnum, size_t i, uint32_t *min, uint32_t *max)
int botan_x509_ext_as_blocks_get_info (botan_x509_cert_t cert, int asnum, int *present, size_t *count)
int botan_x509_ext_ip_addr_blocks_get_address (botan_x509_cert_t cert, int ipv6, size_t i, size_t entry, uint8_t min_out[], uint8_t max_out[], size_t *out_len)
int botan_x509_ext_ip_addr_blocks_get_counts (botan_x509_cert_t cert, size_t *v4_count, size_t *v6_count)
int botan_x509_ext_ip_addr_blocks_get_family (botan_x509_cert_t cert, int ipv6, size_t i, int *has_safi, uint8_t *safi, int *present, 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 1800 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 678 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_ENCRYPT

#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0

Definition at line 677 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 676 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 771 of file ffi.h.

Referenced by botan_cipher_update().

◆ BOTAN_FFI_API_VERSION

#define BOTAN_FFI_API_VERSION   20260811

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

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

Definition at line 71 of file ffi.h.

◆ BOTAN_FFI_DEPRECATED

#define BOTAN_FFI_DEPRECATED ( msg)

Definition at line 104 of file ffi.h.

◆ BOTAN_FFI_EXPORT

#define BOTAN_FFI_EXPORT ( maj,
min )

BOTAN_FFI_EXPORT indicates public FFI functions.

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

Definition at line 89 of file ffi.h.

Referenced by botan_srp6_server_session_step1().

◆ BOTAN_FFI_HEX_LOWER_CASE

#define BOTAN_FFI_HEX_LOWER_CASE   1

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

Definition at line 247 of file ffi.h.

Referenced by botan_hex_encode().

◆ BOTAN_FPE_FLAG_FE1_COMPAT_MODE

#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE   1

Definition at line 4504 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 1921 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

Opaque type of an ASN.1 object identifier

Definition at line 1415 of file ffi.h.

◆ botan_block_cipher_t

typedef struct botan_block_cipher_struct* botan_block_cipher_t

Opaque type of a raw block cipher (PRP)

Definition at line 974 of file ffi.h.

◆ botan_cipher_t

typedef struct botan_cipher_struct* botan_cipher_t

Opaque type of a cipher mode

Definition at line 674 of file ffi.h.

◆ botan_ec_group_t

typedef struct botan_ec_group_struct* botan_ec_group_t

Opaque type of a set of elliptic curve domain parameters

Definition at line 1472 of file ffi.h.

◆ botan_ec_point_t

typedef struct botan_ec_point_struct* botan_ec_point_t

Opaque type of an elliptic curve point

Definition at line 1628 of file ffi.h.

◆ botan_ec_scalar_t

typedef struct botan_ec_scalar_struct* botan_ec_scalar_t

Opaque type of a scalar, that is an integer modulo the group order

Definition at line 1623 of file ffi.h.

◆ botan_fpe_t

typedef struct botan_fpe_struct* botan_fpe_t

Format Preserving Encryption

Definition at line 4502 of file ffi.h.

◆ botan_hash_t

typedef struct botan_hash_struct* botan_hash_t

Opaque type of a hash function

Definition at line 488 of file ffi.h.

◆ botan_hotp_t

typedef struct botan_hotp_struct* botan_hotp_t

HOTP

Definition at line 4430 of file ffi.h.

◆ botan_mac_t

typedef struct botan_mac_struct* botan_mac_t

Opaque type of a message authentication code

Definition at line 578 of file ffi.h.

◆ botan_mp_t

typedef struct botan_mp_struct* botan_mp_t

Opaque type of a multiple precision integer (MPI)

Definition at line 1040 of file ffi.h.

◆ botan_pk_op_decrypt_t

typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t

Opaque type of a public key decryption operation

Definition at line 3076 of file ffi.h.

◆ botan_pk_op_encrypt_t

typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t

Opaque type of a public key encryption operation

Definition at line 3025 of file ffi.h.

◆ botan_pk_op_ka_t

typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t

Opaque type of a key agreement operation

Definition at line 3224 of file ffi.h.

◆ botan_pk_op_kem_decrypt_t

typedef struct botan_pk_op_kem_decrypt_struct* botan_pk_op_kem_decrypt_t

Opaque type of a key decapsulation (KEM decryption) operation

Definition at line 3363 of file ffi.h.

◆ botan_pk_op_kem_encrypt_t

typedef struct botan_pk_op_kem_encrypt_struct* botan_pk_op_kem_encrypt_t

Opaque type of a key encapsulation (KEM encryption) operation

Definition at line 3295 of file ffi.h.

◆ botan_pk_op_sign_t

typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t

Opaque type of a signature generation operation

Definition at line 3128 of file ffi.h.

◆ botan_pk_op_verify_t

typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t

Opaque type of a signature verification operation

Definition at line 3179 of file ffi.h.

◆ botan_privkey_t

typedef struct botan_privkey_struct* botan_privkey_t

Opaque type of a private key

Definition at line 1777 of file ffi.h.

◆ botan_pubkey_t

typedef struct botan_pubkey_struct* botan_pubkey_t

Opaque type of a public key

Definition at line 2112 of file ffi.h.

◆ botan_rng_t

typedef struct botan_rng_struct* botan_rng_t

RNG type

Definition at line 289 of file ffi.h.

◆ botan_spake2p_params_t

typedef struct botan_spake2p_params_struct* botan_spake2p_params_t

SPAKE2+ (RFC 9383) password authenticated key exchange

All operations are relative to a set of system parameters, which select the elliptic curve group, the SPAKE2+ M/N group elements, and the hash function. The parameters are created either from the name of one of the RFC 9383 ciphersuites using HMAC key confirmation ("P256-SHA256", "P256-SHA512", "P384-SHA256", "P384-SHA512", or "P521-SHA512"), or for an application specific group using botan_spake2p_params_init_custom.

The identity, salt, and context parameters may be null, if the corresponding length is zero.

Since the lengths of the outputs vary with the system parameters, all outputs are produced using view callbacks. The expected lengths of the messages received from the peer can be obtained from botan_spake2p_params_share_size and botan_spake2p_params_confirmation_size. SPAKE2+ system parameters

Definition at line 4690 of file ffi.h.

◆ botan_spake2p_prover_t

typedef struct botan_spake2p_prover_struct* botan_spake2p_prover_t

SPAKE2+ prover

Definition at line 4805 of file ffi.h.

◆ botan_spake2p_verifier_t

typedef struct botan_spake2p_verifier_struct* botan_spake2p_verifier_t

SPAKE2+ verifier

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

◆ botan_totp_t

typedef struct botan_totp_struct* botan_totp_t

TOTP

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

◆ botan_tpm2_ctx_t

typedef struct botan_tpm2_ctx_struct* botan_tpm2_ctx_t

TPM2 context

Definition at line 5050 of file ffi.h.

◆ botan_tpm2_session_t

typedef struct botan_tpm2_session_struct* botan_tpm2_session_t

TPM2 session

Definition at line 5055 of file ffi.h.

◆ botan_view_bin_fn

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

Viewer function for binary data

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

Definition at line 161 of file ffi.h.

◆ botan_view_ctx

typedef void* botan_view_ctx

The application provided context for a view function

Definition at line 152 of file ffi.h.

◆ botan_view_str_fn

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

Viewer function for string data

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

Definition at line 170 of file ffi.h.

◆ botan_x509_cert_t

typedef struct botan_x509_cert_struct* botan_x509_cert_t

Opaque type of an X.509 certificate

Definition at line 3483 of file ffi.h.

◆ botan_x509_crl_entry_t

typedef struct botan_x509_crl_entry_struct* botan_x509_crl_entry_t

Opaque type of a single entry within an X.509 certificate revocation list

Definition at line 4091 of file ffi.h.

◆ botan_x509_crl_t

typedef struct botan_x509_crl_struct* botan_x509_crl_t

Opaque type of an X.509 certificate revocation list

Definition at line 4086 of file ffi.h.

◆ botan_x509_general_name_t

typedef struct botan_x509_general_name_struct* botan_x509_general_name_t

Opaque type of an X.509 GeneralName value

Definition at line 3844 of file ffi.h.

◆ botan_xof_t

typedef struct botan_xof_struct* botan_xof_t

Opaque type of an eXtendable Output Function (XOF)

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

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

◆ botan_x509_cert_key_constraints

Key usage constraints from the key usage extension

Must match values of Key_Constraints in pkix_enums.h

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

3793 {
3794 NO_CONSTRAINTS = 0,
3795 DIGITAL_SIGNATURE = 32768,
3796 NON_REPUDIATION = 16384,
3797 KEY_ENCIPHERMENT = 8192,
3798 DATA_ENCIPHERMENT = 4096,
3799 KEY_AGREEMENT = 2048,
3800 KEY_CERT_SIGN = 1024,
3801 CRL_SIGN = 512,
3802 ENCIPHER_ONLY = 256,
3803 DECIPHER_ONLY = 128
3804};
@ KEY_ENCIPHERMENT
Definition ffi.h:3797
@ NO_CONSTRAINTS
Definition ffi.h:3794
@ CRL_SIGN
Definition ffi.h:3801
@ DIGITAL_SIGNATURE
Definition ffi.h:3795
@ KEY_AGREEMENT
Definition ffi.h:3799
@ DATA_ENCIPHERMENT
Definition ffi.h:3798
@ KEY_CERT_SIGN
Definition ffi.h:3800
@ ENCIPHER_ONLY
Definition ffi.h:3802
@ NON_REPUDIATION
Definition ffi.h:3796
@ DECIPHER_ONLY
Definition ffi.h:3803

◆ botan_x509_crl_reason_code

Revocation reason codes for CRL entries, see RFC 5280 Section 5.3.1

Must match values of CRL_Code in pkix_enums.h

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

4153 {
4164};
@ BOTAN_CRL_ENTRY_PRIVILEGE_WITHDRAWN
Definition ffi.h:4162
@ BOTAN_CRL_ENTRY_UNSPECIFIED
Definition ffi.h:4154
@ BOTAN_CRL_ENTRY_SUPERSEDED
Definition ffi.h:4158
@ BOTAN_CRL_ENTRY_CERTIFICATE_HOLD
Definition ffi.h:4160
@ BOTAN_CRL_ENTRY_CESSATION_OF_OPERATION
Definition ffi.h:4159
@ BOTAN_CRL_ENTRY_CA_COMPROMISE
Definition ffi.h:4156
@ BOTAN_CRL_ENTRY_REMOVE_FROM_CRL
Definition ffi.h:4161
@ BOTAN_CRL_ENTRY_AA_COMPROMISE
Definition ffi.h:4163
@ BOTAN_CRL_ENTRY_KEY_COMPROMISE
Definition ffi.h:4155
@ BOTAN_CRL_ENTRY_AFFILIATION_CHANGED
Definition ffi.h:4157

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

3851 {
3856 BOTAN_X509_URI = 6,
3858};
@ BOTAN_X509_DNS_NAME
Definition ffi.h:3854
@ BOTAN_X509_DIRECTORY_NAME
Definition ffi.h:3855
@ BOTAN_X509_OTHER_NAME
Definition ffi.h:3852
@ BOTAN_X509_EMAIL_ADDRESS
Definition ffi.h:3853
@ BOTAN_X509_IP_ADDRESS
Definition ffi.h:3857
@ BOTAN_X509_URI
Definition ffi.h:3856

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

3498 {
3499 BOTAN_X509_SERIAL_NUMBER = 0, /** singleton binary big-endian encoding */
3500 BOTAN_X509_SUBJECT_DN_BITS = 1, /** singleton binary DER encoding of the subject distinguished name */
3501 BOTAN_X509_ISSUER_DN_BITS = 2, /** singleton binary DER encoding of the issuer distinguished name */
3502 BOTAN_X509_SUBJECT_KEY_IDENTIFIER = 3, /** singleton binary encoding */
3503 BOTAN_X509_AUTHORITY_KEY_IDENTIFIER = 4, /** singleton binary encoding */
3504
3505 BOTAN_X509_PUBLIC_KEY_PKCS8_BITS = 200, /** singleton binary DER encoding of the PKCS#8 public key */
3506 BOTAN_X509_TBS_DATA_BITS = 201, /** singleton binary DER encoding */
3507 BOTAN_X509_SIGNATURE_SCHEME_BITS = 202, /** singleton binary DER encoding of the algorithm identifier */
3508 BOTAN_X509_SIGNATURE_BITS = 203, /** singleton binary signature bits */
3509
3510 BOTAN_X509_DER_ENCODING = 300, /** singleton binary DER encoding of the whole object */
3511 BOTAN_X509_PEM_ENCODING = 301, /** singleton string value PEM encoding of the whole object */
3512
3513 BOTAN_X509_CRL_DISTRIBUTION_URLS = 400, /** multi-value string of the CRL distribution points */
3514 BOTAN_X509_OCSP_RESPONDER_URLS = 401, /** multi-value string of the OCSP responder URLs */
3515 BOTAN_X509_CA_ISSUERS_URLS = 402, /** multi-value string of the CA issuer URLs */
botan_x509_value_type
Definition ffi.h:3498
@ BOTAN_X509_AUTHORITY_KEY_IDENTIFIER
Definition ffi.h:3503
@ BOTAN_X509_SUBJECT_KEY_IDENTIFIER
Definition ffi.h:3502
@ BOTAN_X509_TBS_DATA_BITS
Definition ffi.h:3506
@ BOTAN_X509_SIGNATURE_BITS
Definition ffi.h:3508
@ BOTAN_X509_PUBLIC_KEY_PKCS8_BITS
Definition ffi.h:3505
@ BOTAN_X509_DER_ENCODING
Definition ffi.h:3510
@ BOTAN_X509_PEM_ENCODING
Definition ffi.h:3511
@ BOTAN_X509_OCSP_RESPONDER_URLS
Definition ffi.h:3514
@ BOTAN_X509_SIGNATURE_SCHEME_BITS
Definition ffi.h:3507
@ BOTAN_X509_SUBJECT_DN_BITS
Definition ffi.h:3500
@ BOTAN_X509_CRL_DISTRIBUTION_URLS
Definition ffi.h:3513
@ BOTAN_X509_SERIAL_NUMBER
Definition ffi.h:3499
@ BOTAN_X509_ISSUER_DN_BITS
Definition ffi.h:3501
@ BOTAN_X509_CA_ISSUERS_URLS
Definition ffi.h:3515

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

379 {
380 if(any_null_pointers(out, out_len, base64_str)) {
382 }
383
384 return ffi_guard_thunk(__func__, [=]() -> int {
385 if(*out_len < Botan::base64_decode_max_output(in_len)) {
386 *out_len = Botan::base64_decode_max_output(in_len);
388 }
389
390 *out_len = Botan::base64_decode(out, std::string(base64_str, in_len));
391 return BOTAN_FFI_SUCCESS;
392 });
393}
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54
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:169
size_t base64_decode_max_output(size_t input_length)
Definition base64.cpp:201

References Botan_FFI::any_null_pointers(), Botan::base64_decode(), Botan::base64_decode_max_output(), BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NULL_POINTER, 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 369 of file ffi.cpp.

369 {
370 if(len > 0 && in == nullptr) {
372 }
373 return ffi_guard_thunk(__func__, [=]() -> int {
374 const std::string base64 = Botan::base64_encode(in, len);
375 return Botan_FFI::write_str_output(out, out_len, base64);
376 });
377}
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:271
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition base64.cpp:161

References Botan::base64_encode(), BOTAN_FFI_ERROR_NULL_POINTER, 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
Random Number Generatorsa 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 177 of file ffi_kdf.cpp.

178 {
179#if defined(BOTAN_HAS_BCRYPT)
180 return ffi_guard_thunk(__func__, [=]() -> int {
181 if(any_null_pointers(out, out_len, pass)) {
183 }
184
185 if(flags != 0) {
187 }
188
189 if(wf < 4 || wf > 18) {
191 }
192
193 if(*out_len < 61) {
194 *out_len = 61;
196 }
197
199 const std::string bcrypt = Botan::generate_bcrypt(pass, rng, static_cast<uint16_t>(wf));
200 // TODO(Botan4) change the type of out and remove this cast
201 return write_str_output(reinterpret_cast<char*>(out), out_len, bcrypt);
202 });
203#else
204 BOTAN_UNUSED(out, out_len, pass, rng_obj, wf, flags);
206#endif
207}
#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:148

References Botan_FFI::any_null_pointers(), 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
Hashesthe 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 209 of file ffi_kdf.cpp.

209 {
210 if(any_null_pointers(pass, hash)) {
212 }
213#if defined(BOTAN_HAS_BCRYPT)
214 return ffi_guard_thunk(__func__, [=]() -> int {
216 });
217#else
218 BOTAN_UNUSED(pass, hash);
220#endif
221}
bool check_bcrypt(std::string_view pass, std::string_view hash)
Definition bcrypt.cpp:163

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

◆ botan_block_cipher_block_size()

int botan_block_cipher_block_size ( botan_block_cipher_t bc)

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

Definition at line 61 of file ffi_block.cpp.

61 {
62 return BOTAN_FFI_VISIT(bc, [](const auto& b) -> int {
63 const size_t bs = b.block_size();
64 if(bs == 0) {
66 }
67
68 if(std::in_range<int>(bs)) {
69 return static_cast<int>(bs);
70 } else {
72 }
73 });
74}
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158

References BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, and BOTAN_FFI_VISIT.

◆ botan_block_cipher_clear()

int botan_block_cipher_clear ( botan_block_cipher_t bc)

Reinitializes the block cipher

Returns
0 on success, a negative value on failure

Definition at line 43 of file ffi_block.cpp.

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

References BOTAN_FFI_VISIT.

◆ botan_block_cipher_decrypt_blocks()

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

Decrypt one or more blocks with the cipher

Definition at line 83 of file ffi_block.cpp.

83 {
84 if(any_null_pointers(in, out)) {
86 }
87 return BOTAN_FFI_VISIT(bc, [=](const auto& b) { b.decrypt_n(in, out, blocks); });
88}

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

◆ botan_block_cipher_destroy()

int botan_block_cipher_destroy ( botan_block_cipher_t bc)

Destroy a block cipher object

Returns
0 if success, error if invalid object handle

Destroy a block cipher object

Definition at line 39 of file ffi_block.cpp.

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

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

76 {
77 if(any_null_pointers(in, out)) {
79 }
80 return BOTAN_FFI_VISIT(bc, [=](const auto& b) { b.encrypt_n(in, out, blocks); });
81}

References Botan_FFI::any_null_pointers(), 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 98 of file ffi_block.cpp.

101 {
102 return BOTAN_FFI_VISIT(cipher, [=](const auto& bc) {
103 if(out_minimum_keylength) {
104 *out_minimum_keylength = bc.minimum_keylength();
105 }
106 if(out_maximum_keylength) {
107 *out_maximum_keylength = bc.maximum_keylength();
108 }
109 if(out_keylength_modulo) {
110 *out_keylength_modulo = bc.key_spec().keylength_multiple();
111 }
112 });
113}

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

19 {
20 return ffi_guard_thunk(__func__, [=]() -> int {
21 if(bc == nullptr || bc_name == nullptr || *bc_name == 0) {
23 }
24
25 *bc = nullptr;
26
27 auto cipher = Botan::BlockCipher::create(bc_name);
28 if(cipher == nullptr) {
30 }
31
32 return ffi_new_object(bc, std::move(cipher));
33 });
34}
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 90 of file ffi_block.cpp.

90 {
91 if(name_len == nullptr) {
93 }
94
95 return BOTAN_FFI_VISIT(cipher, [=](const auto& bc) { return write_str_output(name, name_len, bc.name()); });
96}

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

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

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_cipher_clear()

int botan_cipher_clear ( botan_cipher_t hash)

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

Definition at line 123 of file ffi_cipher.cpp.

123 {
124 return BOTAN_FFI_VISIT(cipher, [=](auto& c) {
125 cipher->buf().clear();
126 c.clear();
127 });
128}

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

119 {
120 return BOTAN_FFI_CHECKED_DELETE(cipher);
121}

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

338 {
339 if(nl == nullptr) {
341 }
342 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *nl = c.default_nonce_length(); });
343}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 352 of file ffi_cipher.cpp.

352 {
353 if(ug == nullptr) {
355 }
356 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *ug = c.ideal_granularity(); });
357}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 156 of file ffi_cipher.cpp.

159 {
160 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) {
161 if(out_minimum_keylength) {
162 *out_minimum_keylength = c.key_spec().minimum_keylength();
163 }
164 if(out_maximum_keylength) {
165 *out_maximum_keylength = c.key_spec().maximum_keylength();
166 }
167 if(out_keylength_modulo) {
168 *out_keylength_modulo = c.key_spec().keylength_multiple();
169 }
170 });
171}

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

359 {
360 if(tl == nullptr) {
362 }
363 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *tl = c.tag_size(); });
364}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 345 of file ffi_cipher.cpp.

345 {
346 if(ug == nullptr) {
348 }
349 return BOTAN_FFI_VISIT(cipher, [=](const auto& /*c*/) { *ug = cipher->update_size(); });
350}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 {
101 if(any_null_pointers(cipher, cipher_name)) {
103 }
106
107 std::unique_ptr<Botan::Cipher_Mode> mode(Botan::Cipher_Mode::create(cipher_name, dir));
108 if(!mode) {
110 }
111
112 const size_t update_size = ffi_choose_update_size(*mode);
113 const size_t ideal_update_size = std::max(mode->ideal_granularity(), update_size);
114
115 return ffi_new_object(cipher, std::move(mode), update_size, ideal_update_size);
116 });
117}
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:677
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
Definition ffi.h:676
Flags flags(Flag flags)
Definition p11.h:1235

References Botan_FFI::any_null_pointers(), BOTAN_CIPHER_INIT_FLAG_ENCRYPT, BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 366 of file ffi_cipher.cpp.

366 {
367 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.authenticated() ? 1 : 0; });
368}

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

374 {
375 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return write_str_output(name, name_len, c.name()); });
376}

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

137 {
138 if(out_len == nullptr) {
140 }
141
142 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *out_len = c.output_length(in_len); });
143}

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

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

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

370 {
371 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.requires_entire_message() ? 1 : 0; });
372}

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

130 {
131 return BOTAN_FFI_VISIT(cipher, [=](auto& c) {
132 cipher->buf().clear();
133 c.reset();
134 });
135}

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

320 {
321 if(ad_len > 0 && ad == nullptr) {
323 }
324
325 return BOTAN_FFI_VISIT(cipher, [=](auto& c) {
326 if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(&c)) {
327 aead->set_associated_data(ad, ad_len);
328 return BOTAN_FFI_SUCCESS;
329 }
331 });
332}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NULL_POINTER, 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 173 of file ffi_cipher.cpp.

173 {
174 if(key_len > 0 && key == nullptr) {
176 }
177 return BOTAN_FFI_VISIT(cipher, [=](auto& c) { c.set_key(key, key_len); });
178}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 180 of file ffi_cipher.cpp.

180 {
181 if(nonce_len > 0 && nonce == nullptr) {
183 }
184
185 return ffi_guard_thunk(__func__, [=]() -> int {
186 Botan::Cipher_Mode& cipher = safe_get(cipher_obj);
187 cipher.start(nonce, nonce_len);
188 return BOTAN_FFI_SUCCESS;
189 });
190}
void start(std::span< const uint8_t > nonce)
Definition cipher_mode.h:98

References BOTAN_FFI_ERROR_NULL_POINTER, 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 192 of file ffi_cipher.cpp.

199 {
200 if(any_null_pointers(output_written, input_consumed)) {
202 }
203 if(input_size > 0 && input == nullptr) {
205 }
206 if(output_size > 0 && output == nullptr) {
208 }
209
210 return ffi_guard_thunk(__func__, [=]() -> int {
211 using namespace Botan;
212 Cipher_Mode& cipher = safe_get(cipher_obj);
213 secure_vector<uint8_t>& mbuf = cipher_obj->buf();
214
215 // If the cipher object's internal buffer contains residual data from
216 // a previous invocation, we can be sure that botan_cipher_update() was
217 // called with the final flag set but not enough buffer space was provided
218 // to accommodate the final output.
219 const bool was_finished_before = !mbuf.empty();
220 const bool final_input = (flags & BOTAN_CIPHER_UPDATE_FLAG_FINAL) != 0;
221
222 // Bring the output variables into a defined state.
223 *output_written = 0;
224 *input_consumed = 0;
225
226 // Once the final flag was set once, it must always be set for
227 // consecutive invocations.
228 if(was_finished_before && !final_input) {
230 }
231
232 // If the final flag was set in a previous invocation, no more input
233 // data can be processed.
234 if(was_finished_before && input_size > 0) {
236 }
237
238 // Make sure that we always clear the internal buffer before returning
239 // or aborting this invocation due to an exception.
240 auto clean_buffer = scoped_cleanup([&mbuf] { mbuf.clear(); });
241
242 if(final_input) {
243 // If the final flag is set for the first time, we need to process the
244 // remaining input data and then finalize the cipher object.
245 if(!was_finished_before) {
246 *input_consumed = input_size;
247 mbuf.resize(input_size);
248 copy_mem(mbuf, std::span(input, input_size));
249
250 try {
251 cipher.finish(mbuf);
254 }
255 }
256
257 // At this point, the cipher object is finalized (potentially in a
258 // previous invocation) and we can copy the final output to the caller.
259 *output_written = mbuf.size();
260
261 // Not enough space to copy the final output out to the caller.
262 // Inform them how much space we need for a successful operation.
263 if(output_size < mbuf.size()) {
264 // This is the only place where mbuf is not cleared before returning.
265 clean_buffer.disengage();
267 }
268
269 // Copy the final output to the caller, mbuf is cleared afterwards.
270 copy_mem(std::span(output, mbuf.size()), mbuf);
271 } else {
272 // Process data in a streamed fashion without finalizing. No data is
273 // ever retained in the cipher object's internal buffer. If we run out
274 // of either input data or output capacity, we stop and report that not
275 // all bytes were processed via *output_written and *input_consumed.
276
277 BufferSlicer in({input, input_size});
278 BufferStuffer out({output, output_size});
279
280 // Helper function to do blockwise processing of data.
281 auto blockwise_update = [&](const size_t granularity) {
282 if(granularity == 0) {
283 return;
284 }
285
286 const size_t expected_output_per_iteration = cipher.requires_entire_message() ? 0 : granularity;
287 mbuf.resize(granularity);
288
289 while(in.remaining() >= granularity && out.remaining_capacity() >= expected_output_per_iteration) {
290 copy_mem(mbuf, in.take(granularity));
291 const auto written_bytes = cipher.process(mbuf);
292 BOTAN_DEBUG_ASSERT(written_bytes == expected_output_per_iteration);
293 if(written_bytes > 0) {
294 BOTAN_ASSERT_NOMSG(written_bytes <= granularity);
295 copy_mem(out.next(written_bytes), std::span(mbuf).first(written_bytes));
296 }
297 }
298 };
299
300 // First, process as much data as possible in chunks of ideal granularity
301 blockwise_update(cipher_obj->ideal_update_size());
302
303 // Then process the remaining bytes in chunks of update_size() or, in one go
304 // if update_size() is equal to 1 --> i.e. likely a stream cipher.
305 const bool is_stream_cipher = (cipher_obj->update_size() == 1);
306 const size_t tail_granularity =
307 is_stream_cipher ? std::min(in.remaining(), out.remaining_capacity()) : cipher_obj->update_size();
308 BOTAN_DEBUG_ASSERT(tail_granularity < cipher_obj->ideal_update_size());
309 blockwise_update(tail_granularity);
310
311 // Inform the caller about the amount of data processed.
312 *output_written = output_size - out.remaining_capacity();
313 *input_consumed = input_size - in.remaining();
314 }
315
316 return BOTAN_FFI_SUCCESS;
317 });
318}
#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:771
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:128

References Botan_FFI::any_null_pointers(), 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_ERROR_NULL_POINTER, 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 334 of file ffi_cipher.cpp.

334 {
335 return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.valid_nonce_length(nl) ? 1 : 0; });
336}

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

327 {
328 if(len > 0 && any_null_pointers(x, y)) {
330 }
331 auto same = Botan::CT::is_equal(x, y, len);
332 // Return 0 if same or -1 otherwise
333 return static_cast<int>(same.select(1, 0)) - 1;
334}
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:798

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, and Botan::CT::is_equal().

Referenced by botan_same_mem().

◆ botan_ec_group_destroy()

int botan_ec_group_destroy ( botan_ec_group_t ec_group)

Frees all resources of the EC Group object

Parameters
EC Groupthe EC Group object to destroy
Returns
negative number on error, or zero on success

Definition at line 21 of file ffi_ec.cpp.

21 {
22 return BOTAN_FFI_CHECKED_DELETE(ec_group);
23}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_ec_group_equal()

int botan_ec_group_equal ( botan_ec_group_t curve1,
botan_ec_group_t curve2 )

Test if two EC Groups describe the same curve

Parameters
curve1the first group
curve2the second group
Returns
0 if curve1 != curve2
1 if curve1 == curve2
negative number on error

Definition at line 190 of file ffi_ec.cpp.

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

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

72 {
73 return ffi_guard_thunk(__func__, [=]() -> int {
74 if(Botan::any_null_pointers(ec_group, ber)) {
76 }
77
78 Botan::EC_Group group(ber, ber_len);
79
80 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
81 return ffi_new_object(ec_group, std::move(group_ptr));
82 });
83}
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54

References Botan::any_null_pointers(), 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 111 of file ffi_ec.cpp.

111 {
112 return ffi_guard_thunk(__func__, [=]() -> int {
113 if(Botan::any_null_pointers(ec_group, name)) {
115 }
116
118
119 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
120 return ffi_new_object(ec_group, std::move(group_ptr));
121 });
122}
static EC_Group from_name(std::string_view name)
Definition ec_group.cpp:478

References Botan::any_null_pointers(), 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 98 of file ffi_ec.cpp.

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

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
oidthe OID to associate with the group
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 51 of file ffi_ec.cpp.

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

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

85 {
86 return ffi_guard_thunk(__func__, [=]() -> int {
87 if(Botan::any_null_pointers(ec_group, pem)) {
89 }
90
92
93 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
94 return ffi_new_object(ec_group, std::move(group_ptr));
95 });
96}
static EC_Group from_PEM(std::string_view pem)
Definition ec_group.cpp:521

References Botan::any_null_pointers(), 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 167 of file ffi_ec.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

25 {
26 if(out == nullptr) {
28 }
30 *out = 1;
31 } else {
32 *out = 0;
33 }
34 return BOTAN_FFI_SUCCESS;
35}
static bool supports_application_specific_group()
Definition ec_group.cpp:449

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
namethe name of the group to check
outto 1 if so, 0 otherwise.
Returns
negative number on error, or zero on success

Definition at line 37 of file ffi_ec.cpp.

37 {
38 return ffi_guard_thunk(__func__, [=]() -> int {
39 if(Botan::any_null_pointers(name, out)) {
41 }
43 *out = 1;
44 } else {
45 *out = 0;
46 }
47 return BOTAN_FFI_SUCCESS;
48 });
49}
static bool supports_named_group(std::string_view name)
Definition ec_group.cpp:422

References Botan::any_null_pointers(), 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 124 of file ffi_ec.cpp.

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

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

128 {
129 return BOTAN_FFI_VISIT(ec_group,
130 [=](const auto& g) -> int { return invoke_view_callback(view, ctx, g.DER_encode()); });
131}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:190

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

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

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

◆ botan_ec_point_add()

int botan_ec_point_add ( botan_ec_point_t * result,
botan_ec_point_t x,
botan_ec_point_t y )

Add two points

Parameters
resultthe new object will be placed here
xthe first point
ythe second point
Returns
negative number on error, or zero on success

Definition at line 346 of file ffi_ec.cpp.

346 {
347 if(Botan::any_null_pointers(result)) {
349 }
350 return BOTAN_FFI_VISIT(x_w, [=](auto& x) -> int {
351 Botan::EC_AffinePoint res = x.add(safe_get(y_w));
352 return ffi_new_object(result, std::make_unique<Botan::EC_AffinePoint>(std::move(res)));
353 });
354}
EC_AffinePoint add(const EC_AffinePoint &q) const

References Botan::EC_AffinePoint::add(), Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_ec_point_destroy()

int botan_ec_point_destroy ( botan_ec_point_t ec_point)

Frees all resources of the point object

Parameters
ec_pointthe point object to destroy
Returns
negative number on error, or zero on success

Definition at line 230 of file ffi_ec.cpp.

230 {
231 return BOTAN_FFI_CHECKED_DELETE(ec_point);
232}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_ec_point_equal()

int botan_ec_point_equal ( botan_ec_point_t x,
botan_ec_point_t y )

Test if two points are equal

Parameters
xthe first point
ythe second point
Returns
1 if x == y, else 0
negative number on error

Definition at line 319 of file ffi_ec.cpp.

319 {
320 return BOTAN_FFI_VISIT(x_w, [=](const auto& x) -> int { return x == safe_get(y_w) ? 1 : 0; });
321}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_ec_point_from_bytes()

int botan_ec_point_from_bytes ( botan_ec_point_t * ec_point,
botan_ec_group_t ec_group,
const uint8_t * bytes,
size_t bytes_len )

Create a point from a SEC1 compressed or uncompressed format.

Returns
negative number on error

Definition at line 267 of file ffi_ec.cpp.

270 {
271 if(Botan::any_null_pointers(ec_point, bytes)) {
273 }
274 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
275 Botan::EC_AffinePoint pt(g, std::span{bytes, bytes_len});
276 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(std::move(pt)));
277 });
278}

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

◆ botan_ec_point_from_xy()

int botan_ec_point_from_xy ( botan_ec_point_t * ec_point,
botan_ec_group_t ec_group,
botan_mp_t x,
botan_mp_t y )

Create a point from a pair (x,y) of integers The integers must be within the field and must satisfy the curve equation

Definition at line 252 of file ffi_ec.cpp.

252 {
253 if(Botan::any_null_pointers(ec_point)) {
255 }
256 return ffi_guard_thunk(__func__, [=]() -> int {
257 std::optional<Botan::EC_AffinePoint> pt =
259 if(!pt.has_value()) {
261 }
262
263 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(pt.value()));
264 });
265}
static std::optional< EC_AffinePoint > from_bigint_xy(const EC_Group &group, const BigInt &x, const BigInt &y)
Definition ec_apoint.cpp:93

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), Botan::EC_AffinePoint::from_bigint_xy(), and Botan_FFI::safe_get().

◆ botan_ec_point_generator()

int botan_ec_point_generator ( botan_ec_point_t * ec_point,
botan_ec_group_t ec_group )

Create a point set to the standard group generator

Definition at line 243 of file ffi_ec.cpp.

243 {
244 if(Botan::any_null_pointers(ec_point)) {
246 }
247 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
248 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(Botan::EC_AffinePoint::generator(g)));
249 });
250}
static EC_AffinePoint generator(const EC_Group &group)
Return the standard group generator.
Definition ec_apoint.cpp:84

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), and Botan::EC_AffinePoint::generator().

◆ botan_ec_point_identity()

int botan_ec_point_identity ( botan_ec_point_t * ec_point,
botan_ec_group_t ec_group )

Create a point set to the identity element of the group

Definition at line 234 of file ffi_ec.cpp.

234 {
235 if(Botan::any_null_pointers(ec_point)) {
237 }
238 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
239 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(Botan::EC_AffinePoint::identity(g)));
240 });
241}
static EC_AffinePoint identity(const EC_Group &group)
Return the identity element.
Definition ec_apoint.cpp:80

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), and Botan::EC_AffinePoint::identity().

◆ botan_ec_point_is_identity()

int botan_ec_point_is_identity ( botan_ec_point_t ec_point)

Test if a point is the identity element of the group

Parameters
ec_pointthe point to test
Returns
1 if ec_point is the identity element, else 0
negative number on error

Definition at line 315 of file ffi_ec.cpp.

315 {
316 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int { return p.is_identity() ? 1 : 0; });
317}

References BOTAN_FFI_VISIT.

◆ botan_ec_point_mul()

int botan_ec_point_mul ( botan_ec_point_t * result,
botan_ec_point_t ec_point,
botan_ec_scalar_t ec_scalar,
botan_rng_t rng )

Multiply a point by a scalar

Parameters
resultthe new object will be placed here
ec_pointthe point to multiply
ec_scalarthe scalar to multiply by
Random Number Generatorsa random number generator, used for blinding
Returns
negative number on error, or zero on success

Definition at line 323 of file ffi_ec.cpp.

326 {
327 if(Botan::any_null_pointers(result)) {
329 }
330 return BOTAN_FFI_VISIT(ec_point, [=](auto& pt) -> int {
331 Botan::EC_AffinePoint res = pt.mul(safe_get(ec_scalar), safe_get(rng));
332 return ffi_new_object(result, std::make_unique<Botan::EC_AffinePoint>(std::move(res)));
333 });
334}
EC_AffinePoint mul(const EC_Scalar &scalar, RandomNumberGenerator &rng) const
Multiply a point by a scalar returning a complete point.

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), Botan::EC_AffinePoint::mul(), and Botan_FFI::safe_get().

◆ botan_ec_point_negate()

int botan_ec_point_negate ( botan_ec_point_t * result,
botan_ec_point_t ec_point )

Compute the additive inverse of a point

Parameters
resultthe new object will be placed here
ec_pointpoint to negate
Returns
negative number on error, or zero on success

Definition at line 336 of file ffi_ec.cpp.

336 {
337 if(Botan::any_null_pointers(result)) {
339 }
340 return BOTAN_FFI_VISIT(ec_point, [=](auto& pt) -> int {
341 Botan::EC_AffinePoint res = pt.negate();
342 return ffi_new_object(result, std::make_unique<Botan::EC_AffinePoint>(std::move(res)));
343 });
344}
EC_AffinePoint negate() const
Point negation.

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), and Botan::EC_AffinePoint::negate().

◆ botan_ec_point_view_compressed()

int botan_ec_point_view_compressed ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length SEC1 compressed encoding

Returns
negative number on error

Definition at line 308 of file ffi_ec.cpp.

308 {
309 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
310 auto bytes = p.serialize_compressed();
311 return invoke_view_callback(view, ctx, bytes);
312 });
313}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_point_view_uncompressed()

int botan_ec_point_view_uncompressed ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length SEC1 uncompressed encoding

Returns
negative number on error

Definition at line 301 of file ffi_ec.cpp.

301 {
302 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
303 auto bytes = p.serialize_uncompressed();
304 return invoke_view_callback(view, ctx, bytes);
305 });
306}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_point_view_x_bytes()

int botan_ec_point_view_x_bytes ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length encoding of the affine x coordinate

Returns
negative number on error

Definition at line 280 of file ffi_ec.cpp.

280 {
281 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
282 auto bytes = p.x_bytes();
283 return invoke_view_callback(view, ctx, bytes);
284 });
285}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_point_view_xy_bytes()

int botan_ec_point_view_xy_bytes ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length encoding of the affine x and y coordinates

Returns
negative number on error

Definition at line 294 of file ffi_ec.cpp.

294 {
295 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
296 auto bytes = p.xy_bytes();
297 return invoke_view_callback(view, ctx, bytes);
298 });
299}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_point_view_y_bytes()

int botan_ec_point_view_y_bytes ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length encoding of the affine y coordinate

Returns
negative number on error

Definition at line 287 of file ffi_ec.cpp.

287 {
288 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
289 auto bytes = p.y_bytes();
290 return invoke_view_callback(view, ctx, bytes);
291 });
292}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ 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
Random Number Generatorsa 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:464

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

int botan_ec_privkey_get_group ( botan_privkey_t key,
botan_ec_group_t * ec_group )

Get the group of an elliptic curve private key

Parameters
keythe EC private key
EC Groupthe new object will be placed here
Returns
0 on success, a negative value on failure

Definition at line 859 of file ffi_pkey_algs.cpp.

859 {
860 if(Botan::any_null_pointers(ec_group)) {
862 }
863
864#if defined(BOTAN_HAS_ECC_KEY)
865 return ffi_guard_thunk(__func__, [=]() -> int {
866 const Botan::EC_PrivateKey* ec_key = dynamic_cast<const Botan::EC_PrivateKey*>(&safe_get(key));
867 if(ec_key == nullptr) {
869 }
870 return ffi_new_object(ec_group, std::make_unique<Botan::EC_Group>(ec_key->domain()));
871 });
872#else
873 BOTAN_UNUSED(key, ec_group);
875#endif
876}
const EC_Group & domain() const
Definition ecc_key.cpp:76

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan::EC_PublicKey::domain(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_ec_privkey_get_private_key()

int botan_ec_privkey_get_private_key ( botan_privkey_t key,
botan_ec_scalar_t * value )

Loads Diffie Hellman 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_dh(botan_privkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t x); /** 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: EC keys Get the secret scalar of an elliptic curve private key

Parameters
keythe EC private key
valuethe new object will be placed here
Returns
0 on success, a negative value on failure

Definition at line 841 of file ffi_pkey_algs.cpp.

841 {
842 if(Botan::any_null_pointers(value)) {
844 }
845#if defined(BOTAN_HAS_ECC_KEY)
846 return ffi_guard_thunk(__func__, [=]() -> int {
847 const Botan::EC_PrivateKey* ec_key = dynamic_cast<const Botan::EC_PrivateKey*>(&safe_get(key));
848 if(ec_key == nullptr) {
850 }
851 return ffi_new_object(value, std::make_unique<Botan::EC_Scalar>(ec_key->_private_key()));
852 });
853#else
854 BOTAN_UNUSED(key, value);
856#endif
857}
const EC_Scalar & _private_key() const
Definition ecc_key.cpp:135

References Botan::EC_PrivateKey::_private_key(), Botan::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_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_ec_pubkey_get_group()

int botan_ec_pubkey_get_group ( botan_pubkey_t key,
botan_ec_group_t * ec_group )

Get the group of an elliptic curve public key

Parameters
keythe EC public key
EC Groupthe new object will be placed here
Returns
0 on success, a negative value on failure

Definition at line 878 of file ffi_pkey_algs.cpp.

878 {
879 if(Botan::any_null_pointers(ec_group)) {
881 }
882#if defined(BOTAN_HAS_ECC_KEY)
883 return ffi_guard_thunk(__func__, [=]() -> int {
884 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&safe_get(key));
885 if(ec_key == nullptr) {
887 }
888 return ffi_new_object(ec_group, std::make_unique<Botan::EC_Group>(ec_key->domain()));
889 });
890#else
891 BOTAN_UNUSED(key, ec_group);
893#endif
894}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan::EC_PublicKey::domain(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_ec_scalar_destroy()

int botan_ec_scalar_destroy ( botan_ec_scalar_t ec_scalar)

Frees all resources of the scalar object

Parameters
ec_scalarthe scalar object to destroy
Returns
negative number on error, or zero on success

Definition at line 196 of file ffi_ec.cpp.

196 {
197 return BOTAN_FFI_CHECKED_DELETE(ec_scalar);
198}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_ec_scalar_from_mp()

int botan_ec_scalar_from_mp ( botan_ec_scalar_t * ec_scalar,
botan_ec_group_t ec_group,
botan_mp_t mp )

Convert from an MPI to a scalar

Returns
a negative number if the provided MPI is negative or too large, 0 on success

Definition at line 209 of file ffi_ec.cpp.

209 {
210 if(Botan::any_null_pointers(ec_scalar)) {
212 }
213 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
214 return ffi_new_object(ec_scalar,
215 std::make_unique<Botan::EC_Scalar>(Botan::EC_Scalar::from_bigint(g, safe_get(mp))));
216 });
217}
static EC_Scalar from_bigint(const EC_Group &group, const BigInt &bn)
Definition ec_scalar.cpp:72

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), Botan::EC_Scalar::from_bigint(), and Botan_FFI::safe_get().

◆ botan_ec_scalar_random()

int botan_ec_scalar_random ( botan_ec_scalar_t * ec_scalar,
botan_ec_group_t ec_group,
botan_rng_t rng )

Create a new random scalar value

Definition at line 200 of file ffi_ec.cpp.

200 {
201 if(Botan::any_null_pointers(ec_scalar)) {
203 }
204 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
205 return ffi_new_object(ec_scalar, std::make_unique<Botan::EC_Scalar>(Botan::EC_Scalar::random(g, safe_get(rng))));
206 });
207}
static EC_Scalar random(const EC_Group &group, RandomNumberGenerator &rng)
Definition ec_scalar.cpp:64

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), Botan::EC_Scalar::random(), and Botan_FFI::safe_get().

◆ botan_ec_scalar_to_mp()

int botan_ec_scalar_to_mp ( botan_ec_scalar_t ec_scalar,
botan_mp_t * mp )

Convert from a scalar to an MPI

Returns
a negative number on failure, 0 on success

Definition at line 219 of file ffi_ec.cpp.

219 {
222 }
223 return BOTAN_FFI_VISIT(ec_scalar, [=](const auto& sc) -> int {
224 return ffi_new_object(mp, std::make_unique<Botan::BigInt>(sc.to_bigint()));
225 });
226}

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

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

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

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

142 {
143 return g_last_exception_what.c_str();
144}

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

223 {
224 return BOTAN_HAS_FFI;
225}
#define BOTAN_HAS_FFI
Definition build.h:202

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

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

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 )

Decrypt an integer, replacing it with the result

Parameters
fpethe FPE object
xthe value to decrypt, modified in place; must be less than n
tweakthe tweak, may be NULL if tweak_len is 0
tweak_lenlength of tweak in bytes
Returns
0 on success, a negative value on failure

Definition at line 82 of file ffi_fpe.cpp.

82 {
83 if(tweak_len > 0 && tweak == nullptr) {
85 }
86
87#if defined(BOTAN_HAS_FPE_FE1)
88 return ffi_guard_thunk(__func__, [=]() {
89 const Botan::BigInt r = safe_get(fpe).decrypt(safe_get(x), tweak, tweak_len);
90 safe_get(x) = r;
91 return BOTAN_FFI_SUCCESS;
92 });
93
94#else
95 BOTAN_UNUSED(fpe, x, tweak, tweak_len);
97#endif
98}

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

◆ botan_fpe_destroy()

int botan_fpe_destroy ( botan_fpe_t fpe)

Frees all resources of the FPE object

Parameters
fpethe FPE object to destroy
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 )

Encrypt an integer, replacing it with the result

Parameters
fpethe FPE object
xthe value to encrypt, modified in place; must be less than n
tweakthe tweak, may be NULL if tweak_len is 0
tweak_lenlength of tweak in bytes
Returns
0 on success, a negative value on failure

Definition at line 65 of file ffi_fpe.cpp.

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

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

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

Initialize an FE1 format preserving encryption object, which encrypts integers in the range [0, n)

Parameters
fpethe new object will be placed here
nthe modulus defining the range of the permutation
keythe key
key_lenlength of key in bytes
roundsthe number of Feistel rounds; at least 16 is recommended
flags0, or BOTAN_FPE_FLAG_FE1_COMPAT_MODE to match the encoding used by Botan versions prior to 2.5
Returns
0 on success, a negative value on failure

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(any_null_pointers(fpe, key)) {
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:4504

References Botan_FFI::any_null_pointers(), 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
Hasheshash 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
Hasheshash object
Returns
0 on success, a negative value on failure

Definition at line 62 of file ffi_hash.cpp.

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

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

86 {
87 if(dest == nullptr) {
89 }
90 return BOTAN_FFI_VISIT(source, [=](const auto& src) { return ffi_new_object(dest, src.copy_state()); });
91}

References BOTAN_FFI_ERROR_NULL_POINTER, 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
Hasheshash 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
Hasheshash object
outoutput buffer
Returns
0 on success, a negative value on failure

Definition at line 78 of file ffi_hash.cpp.

78 {
79 if(out == nullptr) {
81 }
82 return BOTAN_FFI_VISIT(hash, [=](auto& h) { h.final(out); });
83}

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
Hasheshash 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
Hashesthe object to read
nameoutput buffer
name_lenon input, the length of buffer, on success the number of bytes written

Definition at line 93 of file ffi_hash.cpp.

93 {
94 if(name_len == nullptr) {
96 }
97
98 return BOTAN_FFI_VISIT(hash, [=](const auto& h) { return write_str_output(name, name_len, h.name()); });
99}

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

int botan_hash_security_level ( botan_hash_t hash,
size_t * security_level )

Writes the estimated security level of the hash function, in bits, with respect to collision resistance, to *security_level. Returns zero for checksums and any hash where finding collisions is trivial.

Parameters
Hasheshash object
security_leveloutput variable to hold the security level
Returns
0 on success, a negative value on failure

Definition at line 55 of file ffi_hash.cpp.

55 {
56 if(out == nullptr) {
58 }
59 return BOTAN_FFI_VISIT(hash, [=](const auto& h) { *out = h.security_level(); });
60}

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
Hasheshash 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_hash.cpp.

66 {
67 if(len == 0) {
68 return 0;
69 }
70
71 if(buf == nullptr) {
73 }
74
75 return BOTAN_FFI_VISIT(hash, [=](auto& h) { h.update(buf, len); });
76}

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

359 {
360 if(any_null_pointers(hex_str, out_len)) {
362 }
363 return ffi_guard_thunk(__func__, [=]() -> int {
364 const std::vector<uint8_t> bin = Botan::hex_decode(hex_str, in_len);
365 return Botan_FFI::write_vec_output(out, out_len, bin);
366 });
367}
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:267
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition hex.cpp:75

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, 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 348 of file ffi.cpp.

348 {
349 if(len > 0 && (in == nullptr || out == nullptr)) {
351 }
352 return ffi_guard_thunk(__func__, [=]() -> int {
353 const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
354 Botan::hex_encode(out, in, len, uppercase);
355 return BOTAN_FFI_SUCCESS;
356 });
357}
#define BOTAN_FFI_HEX_LOWER_CASE
Definition ffi.h:247
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition hex.cpp:34

References BOTAN_FFI_ERROR_NULL_POINTER, 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(any_null_pointers(hotp, hotp_code)) {
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::any_null_pointers(), 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(any_null_pointers(hotp, key, hash_algo)) {
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::any_null_pointers(), 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 143 of file ffi_kdf.cpp.

151 {
152 if(kdf_algo == nullptr) {
154 }
155 if((out_len > 0 && out == nullptr) || (secret_len > 0 && secret == nullptr) || (salt_len > 0 && salt == nullptr) ||
156 (label_len > 0 && label == nullptr)) {
158 }
159 return ffi_guard_thunk(__func__, [=]() -> int {
160 auto kdf = Botan::KDF::create_or_throw(kdf_algo);
161 kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
162 return BOTAN_FFI_SUCCESS;
163 });
164}
static std::unique_ptr< KDF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition kdf.cpp:208

References BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Key unwrapping as per RFC 3394

Parameters
wrapped_keythe wrapped key to unwrap
wrapped_key_lenlength of wrapped_key in bytes
kekthe key encryption key
kek_lenlength of kek in bytes
keyoutput buffer for the unwrapped key
key_lenon input the size of key, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 104 of file ffi_keywrap.cpp.

109 {
110 const std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
111
112 return botan_nist_kw_dec(cipher_name.c_str(), 0, wrapped_key, wrapped_key_len, kek, kek_len, key, key_len);
113}
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 93 of file ffi_keywrap.cpp.

98 {
99 const std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
100
101 return botan_nist_kw_enc(cipher_name.c_str(), 0, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
102}
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
Message Authentication Codesmac object
Returns
0 on success, a negative value on failure

Definition at line 62 of file ffi_mac.cpp.

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

References BOTAN_FFI_VISIT.

◆ botan_mac_destroy()

int botan_mac_destroy ( botan_mac_t mac)

Frees all resources of the MAC object

Parameters
Message Authentication Codesmac 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
Message Authentication Codesmac object
outoutput buffer
Returns
0 on success, a negative value on failure

Definition at line 76 of file ffi_mac.cpp.

76 {
77 if(out == nullptr) {
79 }
80 return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.final(out); });
81}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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
Message Authentication Codesthe 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 87 of file ffi_mac.cpp.

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

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
Message Authentication Codesmac 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

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
Message Authentication Codesthe 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_mac.cpp.

83 {
84 return BOTAN_FFI_VISIT(mac, [=](const auto& m) { return write_str_output(name, name_len, m.name()); });
85}

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
Message Authentication Codesmac object
output_lengthoutput buffer to hold the MAC output length
Returns
0 on success, a negative value on failure

Definition at line 55 of file ffi_mac.cpp.

55 {
56 if(out == nullptr) {
58 }
59 return BOTAN_FFI_VISIT(mac, [=](const auto& m) { *out = m.output_length(); });
60}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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
Message Authentication Codesmac 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 if(key_len > 0 && key == nullptr) {
43 }
44 return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.set_key(key, key_len); });
45}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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
Message Authentication Codesmac 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 47 of file ffi_mac.cpp.

47 {
48 if(nonce_len > 0 && nonce == nullptr) {
50 }
51
52 return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.start(nonce, nonce_len); });
53}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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
Message Authentication Codesmac object
bufinput buffer
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_mac.cpp.

66 {
67 if(len == 0) {
68 return BOTAN_FFI_SUCCESS;
69 }
70 if(buf == nullptr) {
72 }
73 return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.update(buf, len); });
74}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and 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 )

Formerly decrypted a message using McEliece with an AEAD.

Always returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED

Parameters
mce_keyignored
AEAD Modesignored
ctignored
ct_lenignored
adignored
ad_lenignored
ptignored
pt_lenignored
Returns
BOTAN_FFI_ERROR_NOT_IMPLEMENTED

Definition at line 1564 of file ffi_pkey_algs.cpp.

1571 {
1572 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
1574}

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 )

Formerly encrypted a message using McEliece with an AEAD.

Always returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED

Parameters
mce_keyignored
Random Number Generatorsignored
AEAD Modesignored
ptignored
pt_lenignored
adignored
ad_lenignored
ctignored
ct_lenignored
Returns
BOTAN_FFI_ERROR_NOT_IMPLEMENTED

Definition at line 1576 of file ffi_pkey_algs.cpp.

1584 {
1585 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
1587}

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 )

Set result to x + y

Parameters
resultset to the sum
xthe first addend
ythe second addend
Returns
0 on success, a negative value on failure

Definition at line 161 of file ffi_mp.cpp.

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

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 )

Set result to x + y

Parameters
resultset to the sum
xthe first addend
ythe second addend
Returns
0 on success, a negative value on failure

Definition at line 181 of file ffi_mp.cpp.

181 {
182 return BOTAN_FFI_VISIT(result, [=](auto& res) {
183 if(result == x) {
184 res += static_cast<Botan::word>(y);
185 } else {
186 res = safe_get(x) + static_cast<Botan::word>(y);
187 }
188 });
189}
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word
The native machine word, used as the limb type for multiprecision integers.
Definition types.h:131

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

298 {
299 return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.clear_bit(bit); });
300}

References BOTAN_FFI_VISIT.

◆ botan_mp_cmp()

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

Compare two integers

Parameters
resultset to -1 if x < y, 0 if x == y, 1 if x > y
xthe first integer
ythe second integer
Returns
0 on success, a negative value on failure

Definition at line 235 of file ffi_mp.cpp.

235 {
236 if(result == nullptr) {
238 }
239 return BOTAN_FFI_VISIT(x_w, [=](auto& x) { *result = x.cmp(safe_get(y_w)); });
240}

References BOTAN_FFI_ERROR_NULL_POINTER, 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 157 of file ffi_mp.cpp.

157 {
158 return BOTAN_FFI_CHECKED_DELETE(mp);
159}

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 )

Divide x by y, producing both the quotient and the remainder

Parameters
quotientset to x / y
remainderset to x % y
xthe dividend
ythe divisor, which must not be zero
Returns
0 on success, a negative value on failure

Definition at line 211 of file ffi_mp.cpp.

211 {
212 return BOTAN_FFI_VISIT(quotient, [=](auto& q) {
215 safe_get(remainder) = r;
216 });
217}
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition divide.cpp:332

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 )

Test if two integers are equal

Parameters
xthe first integer
ythe second integer
Returns
1 if x == y, 0 if x != y, or a negative value on error

Definition at line 219 of file ffi_mp.cpp.

219 {
220 return BOTAN_FFI_VISIT(x_w, [=](const auto& x) -> int { return x == safe_get(y_w); });
221}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_flip_sign()

int botan_mp_flip_sign ( botan_mp_t mp)

Negate the MPI, ie replace it by its additive inverse

Parameters
Big Integer (Low-Level)the integer to negate, modified in place
Returns
0 on success, a negative value on failure

Definition at line 80 of file ffi_mp.cpp.

80 {
81 return BOTAN_FFI_VISIT(mp, [](auto& bn) { bn.flip_sign(); });
82}

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 )

Set an MP to the big-endian binary value

Parameters
Big Integer (Low-Level)the integer to set
vecthe big-endian encoding to decode
vec_lenlength of vec in bytes
Returns
0 on success, a negative value on failure

Definition at line 84 of file ffi_mp.cpp.

84 {
85 if(bin_len > 0 && bin == nullptr) {
87 }
88 return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn._assign_from_bytes({bin, bin_len}); });
89}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_mp_gcd()

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

Set out to the greatest common divisor of x and y

Parameters
outset to gcd(x, y)
xthe first integer
ythe second integer
Returns
0 on success, a negative value on failure

Definition at line 282 of file ffi_mp.cpp.

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

290 {
291 return BOTAN_FFI_VISIT(mp, [=](const auto& n) -> int { return n.get_bit(bit); });
292}

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)

Return 1 iff mp is even

Parameters
Big Integer (Low-Level)the integer to test
Returns
1 if even, 0 if odd, or a negative value on error

Definition at line 231 of file ffi_mp.cpp.

231 {
232 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_even(); });
233}

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

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

References BOTAN_FFI_VISIT.

◆ botan_mp_is_odd()

int botan_mp_is_odd ( botan_mp_t mp)

Return 1 iff mp is odd

Parameters
Big Integer (Low-Level)the integer to test
Returns
1 if odd, 0 if even, or a negative value on error

Definition at line 227 of file ffi_mp.cpp.

227 {
228 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_odd(); });
229}

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

76 {
77 return BOTAN_FFI_VISIT(mp, [](const auto& bn) { return bn.signum() >= 0 ? 1 : 0; });
78}

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

286 {
287 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; });
288}
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)

Return 1 iff mp is equal to zero

Parameters
Big Integer (Low-Level)the integer to test
Returns
1 if zero, 0 if not, or a negative value on error

Definition at line 223 of file ffi_mp.cpp.

223 {
224 return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_zero(); });
225}

References BOTAN_FFI_VISIT.

◆ botan_mp_lshift()

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

Set out to in shifted left by the specified number of bits

Parameters
outset to the shifted value
inthe integer to shift
shiftthe number of bits to shift by
Returns
0 on success, a negative value on failure

Definition at line 252 of file ffi_mp.cpp.

252 {
253 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) << shift; });
254}

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 )

Set out to the inverse of in modulo the specified modulus. If no inverse exists, out is set to zero.

Parameters
outset to the modular inverse
inthe value to invert
modulusthe modulus
Returns
0 on success, a negative value on failure

Definition at line 260 of file ffi_mp.cpp.

260 {
261 return BOTAN_FFI_VISIT(out, [=](auto& o) {
263 });
264}
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 )

Set result to (x * y) % mod

Parameters
resultset to the modular product
xthe first factor
ythe second factor
modthe modulus, which must be positive
Returns
0 on success, a negative value on failure

Definition at line 266 of file ffi_mp.cpp.

266 {
267 return BOTAN_FFI_VISIT(out, [=](auto& o) {
269 o = reducer.multiply(safe_get(x), safe_get(y));
270 });
271}
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 )

Set result to x * y

Parameters
resultset to the product
xthe first factor
ythe second factor
Returns
0 on success, a negative value on failure

Definition at line 201 of file ffi_mp.cpp.

201 {
202 return BOTAN_FFI_VISIT(result, [=](auto& res) {
203 if(result == x) {
204 res *= safe_get(y);
205 } else {
206 res = safe_get(x) * safe_get(y);
207 }
208 });
209}

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

302 {
303 if(bits == nullptr) {
305 }
306 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bits = n.bits(); });
307}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 309 of file ffi_mp.cpp.

309 {
310 if(bytes == nullptr) {
312 }
313 return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bytes = n.bytes(); });
314}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 )

Set out to (base^exponent) % modulus

Parameters
outset to the result of the modular exponentiation
Base Typesthe base
exponentthe exponent
modulusthe modulus, which must be positive
Returns
0 on success, a negative value on failure

Definition at line 247 of file ffi_mp.cpp.

247 {
248 return BOTAN_FFI_VISIT(
249 out, [=](auto& o) { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
250}
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 )

Set rand_out to a random integer of the specified bit length

Parameters
rand_outset to the random integer
Random Number Generatorsa random number generator
bitsthe desired bit length
Returns
0 on success, a negative value on failure

Definition at line 273 of file ffi_mp.cpp.

273 {
274 return BOTAN_FFI_VISIT(rng, [=](auto& r) { safe_get(rand_out).randomize(r, bits); });
275}

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 )

Set rand_out to a random integer within the half-open range [lower_bound, upper_bound)

Parameters
rand_outset to the random integer
Random Number Generatorsa random number generator
lower_boundthe inclusive lower bound
upper_boundthe exclusive upper bound
Returns
0 on success, a negative value on failure

Definition at line 277 of file ffi_mp.cpp.

277 {
278 return BOTAN_FFI_VISIT(
279 rng, [=](auto& r) { safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
280}
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 )

Set out to in shifted right by the specified number of bits

Parameters
outset to the shifted value
inthe integer to shift
shiftthe number of bits to shift by
Returns
0 on success, a negative value on failure

Definition at line 256 of file ffi_mp.cpp.

256 {
257 return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) >> shift; });
258}

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

294 {
295 return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.set_bit(bit); });
296}

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

68 {
69 return BOTAN_FFI_VISIT(dest, [=](auto& bn) { bn = safe_get(source); });
70}

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

51 {
52 if(str == nullptr) {
54 }
55
56 return BOTAN_FFI_VISIT(mp, [=](auto& bn) {
57 if(radix != 10 && radix != 16) {
59 }
60
61 bn = Botan::BigInt::from_radix_digits(std::string_view(str), radix);
62 return BOTAN_FFI_SUCCESS;
63 });
64}
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_ERROR_NULL_POINTER, 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 if(str == nullptr) {
46 }
47
48 return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn = Botan::BigInt(str); });
49}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_mp_sub()

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

Set result to x - y

Parameters
resultset to the difference
xthe minuend
ythe subtrahend
Returns
0 on success, a negative value on failure

Definition at line 171 of file ffi_mp.cpp.

171 {
172 return BOTAN_FFI_VISIT(result, [=](auto& res) {
173 if(result == x) {
174 res -= safe_get(y);
175 } else {
176 res = safe_get(x) - safe_get(y);
177 }
178 });
179}

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 )

Set result to x - y

Parameters
resultset to the difference
xthe minuend
ythe subtrahend
Returns
0 on success, a negative value on failure

Definition at line 191 of file ffi_mp.cpp.

191 {
192 return BOTAN_FFI_VISIT(result, [=](auto& res) {
193 if(result == x) {
194 res -= static_cast<Botan::word>(y);
195 } else {
196 res = safe_get(x) - static_cast<Botan::word>(y);
197 }
198 });
199}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_mp_swap()

int botan_mp_swap ( botan_mp_t x,
botan_mp_t y )

Swap the values of two integers

Parameters
xthe first integer
ythe second integer
Returns
0 on success, a negative value on failure

Definition at line 242 of file ffi_mp.cpp.

242 {
243 return BOTAN_FFI_VISIT(x_w, [=](auto& x) { x.swap(safe_get(y_w)); });
244}

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

Convert the MPI to a big-endian binary string. Writes botan_mp_num_bytes to vec

Note that the sign of the integer is ignored here; only the absolute value is copied

Parameters
Big Integer (Low-Level)the integer to encode
vecoutput buffer of at least botan_mp_num_bytes(mp) bytes
Returns
0 on success, a negative value on failure

Definition at line 136 of file ffi_mp.cpp.

136 {
137 if(vec == nullptr) {
139 }
140 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { bn.serialize_to(std::span{vec, bn.bytes()}); });
141}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 91 of file ffi_mp.cpp.

91 {
92 if(out == nullptr) {
94 }
95 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) {
96 const std::string hex = bn.to_hex_string();
97
98 // Check that we are about to write no more than the documented upper bound
99 const size_t upper_bound = 2 * bn.bytes() + 5;
100 BOTAN_ASSERT_NOMSG(hex.size() + 1 <= upper_bound);
101 std::memcpy(out, hex.c_str(), 1 + hex.size());
102 });
103}

References BOTAN_ASSERT_NOMSG, BOTAN_FFI_ERROR_NULL_POINTER, 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 112 of file ffi_mp.cpp.

112 {
113 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) -> int {
114 if(radix == 0 || radix == 10) {
115 return write_str_output(out, out_len, bn.to_dec_string());
116 } else if(radix == 16) {
117 return write_str_output(out, out_len, bn.to_hex_string());
118 } else {
120 }
121 });
122}

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 )

Convert the MPI to a uint32_t, if possible. Fails if MPI is negative or too large.

Parameters
Big Integer (Low-Level)the integer to convert
valset to the value of mp
Returns
0 on success, a negative value on failure

Definition at line 150 of file ffi_mp.cpp.

150 {
151 if(val == nullptr) {
153 }
154 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { *val = bn.to_u32bit(); });
155}

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 )

View the big-endian binary string encoding of this integer

Note that the sign of the integer is ignored here; only the absolute value is viewed

Parameters
Big Integer (Low-Level)the integer to encode
ctxan application context passed to the view function
viewthe view callback which receives the encoding
Returns
0 on success, a negative value on failure

Definition at line 143 of file ffi_mp.cpp.

143 {
144 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) {
145 const auto bytes = bn.serialize();
146 return invoke_view_callback(view, ctx, bytes);
147 });
148}

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

105 {
106 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) -> int {
107 const std::string hex = bn.to_hex_string();
108 return invoke_view_callback(view, ctx, hex);
109 });
110}

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

124 {
125 return BOTAN_FFI_VISIT(mp, [=](const auto& bn) -> int {
126 if(radix == 10) {
127 return invoke_view_callback(view, ctx, bn.to_dec_string());
128 } else if(radix == 16) {
129 return invoke_view_callback(view, ctx, bn.to_hex_string());
130 } else {
132 }
133 });
134}

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 )

Key unwrapping as per NIST SP 800-38F

Parameters
cipher_algothe block cipher to use, eg "AES-256"
paddedif non-zero use KWP (the padded variant), otherwise KW
wrapped_keythe wrapped key to unwrap
wrapped_key_lenlength of wrapped_key in bytes
kekthe key encryption key
kek_lenlength of kek in bytes
keyoutput buffer for the unwrapped key
key_lenon input the size of key, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 57 of file ffi_keywrap.cpp.

64 {
65 if(any_null_pointers(cipher_algo, wrapped_key, kek)) {
67 }
68#if defined(BOTAN_HAS_NIST_KEYWRAP)
69 return ffi_guard_thunk(__func__, [=]() -> int {
70 if(padded != 0 && padded != 1) {
72 }
73
74 auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
75 bc->set_key(kek, kek_len);
76
78
79 if(padded == 0) {
80 output = Botan::nist_key_unwrap(wrapped_key, wrapped_key_len, *bc);
81 } else {
82 output = Botan::nist_key_unwrap_padded(wrapped_key, wrapped_key_len, *bc);
83 }
84
85 return write_vec_output(key, key_len, output);
86 });
87#else
88 BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
90#endif
91}
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::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Key wrapping as per NIST SP 800-38F

Parameters
cipher_algothe block cipher to use, eg "AES-256"
paddedif non-zero use KWP (the padded variant), otherwise KW
keythe key to wrap
key_lenlength of key in bytes
kekthe key encryption key
kek_lenlength of kek in bytes
wrapped_keyoutput buffer for the wrapped key
wrapped_key_lenon input the size of wrapped_key, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 22 of file ffi_keywrap.cpp.

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

Frees all resources of the OID object

Parameters
oidthe OID object to destroy
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 )

Test if two OIDs are equal

Parameters
athe first OID
bthe second OID
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(any_null_pointers(oid_obj, oid_str)) {
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:80

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

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 )

Derive a key from a passphrase for a number of iterations

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
iterationsthe number of iterations to use (use 10K or more)
Returns
0 on success, a negative value on failure

Deprecated: use botan_pwdhash(pbkdf_algo, iterations, 0, 0, out, out_len, passphrase, 0, salt, salt_len);

Definition at line 23 of file ffi_kdf.cpp.

29 {
30 return botan_pwdhash(algo, iterations, 0, 0, out, out_len, pass, 0, salt, salt_len);
31}
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:54

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

40 {
41 return botan_pwdhash_timed(algo,
42 static_cast<uint32_t>(ms_to_run),
43 iterations_used,
44 nullptr,
45 nullptr,
46 out,
47 out_len,
48 password,
49 0,
50 salt,
51 salt_len);
52}
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:93

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 )

Decrypt a message with a private key

Parameters
opthe decryption operation
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
ciphertextthe message to decrypt
ciphertext_lenlength of ciphertext in bytes
Returns
0 on success, a negative value on failure

Definition at line 105 of file ffi_pk_op.cpp.

106 {
107 if(ciphertext_len > 0 && ciphertext == nullptr) {
109 }
110
111 return BOTAN_FFI_VISIT(
112 op, [=](const auto& o) { return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len)); });
113}

References BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Create a public key decryption operation

Parameters
opthe new object will be placed here
keythe private key to decrypt with
paddingthe padding/encoding method, eg "OAEP(SHA-256)"
flagsshould be 0 in current API revision
Returns
0 on success, a negative value on failure

Definition at line 74 of file ffi_pk_op.cpp.

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

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

Frees all resources of the decryption operation object

Parameters
opthe operation to destroy
Returns
0 if success, error if invalid object handle

Definition at line 94 of file ffi_pk_op.cpp.

94 {
95 return BOTAN_FFI_CHECKED_DELETE(op);
96}

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 )

Return an upper bound on the plaintext length for a given ciphertext length

Parameters
opthe decryption operation
ctext_lenthe ciphertext length in bytes
ptext_lenset to the maximum plaintext length in bytes
Returns
0 on success, a negative value on failure

Definition at line 98 of file ffi_pk_op.cpp.

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

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 )

Encrypt a message with a public key

Parameters
opthe encryption operation
Random Number Generatorsa random number generator
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
plaintextthe message to encrypt
plaintext_lenlength of plaintext in bytes
Returns
0 on success, a negative value on failure

Definition at line 56 of file ffi_pk_op.cpp.

61 {
62 if(plaintext_len > 0 && plaintext == nullptr) {
64 }
65
66 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
67 return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
68 });
69}

References BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Create a public key encryption operation

Parameters
opthe new object will be placed here
keythe public key to encrypt to
paddingthe padding/encoding method, eg "OAEP(SHA-256)"
flagsshould be 0 in current API revision
Returns
0 on success, a negative value on failure

Definition at line 28 of file ffi_pk_op.cpp.

28 {
29 if(Botan::any_null_pointers(op, padding)) {
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:3123

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

Frees all resources of the encryption operation object

Parameters
opthe operation to destroy
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 )

Return the ciphertext length for a given plaintext length

Parameters
opthe encryption operation
ptext_lenthe plaintext length in bytes
ctext_lenset to the resulting ciphertext length in bytes
Returns
0 on success, a negative value on failure

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 )

Create a key decapsulation operation

Parameters
opthe new object will be placed here
keythe private key to decapsulate with
Key Derivation Functionsthe KDF applied to the shared secret, or "Raw" for no KDF
Returns
0 on success, a negative value on failure

Definition at line 341 of file ffi_pk_op.cpp.

341 {
342 if(Botan::any_null_pointers(op, padding)) {
344 }
345
346 return ffi_guard_thunk(__func__, [=]() -> int {
347 auto pk = std::make_unique<Botan::PK_KEM_Decryptor>(safe_get(key_obj), Botan::system_rng(), padding);
348 return ffi_new_object(op, std::move(pk));
349 });
350}

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

Frees all resources of the key decapsulation operation object

Parameters
opthe operation to destroy
Returns
0 if success, error if invalid object handle

Definition at line 388 of file ffi_pk_op.cpp.

388 {
389 return BOTAN_FFI_CHECKED_DELETE(op);
390}

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 )

Recover the shared key from an encapsulated key

Parameters
opthe decapsulation operation
salta salt passed to the KDF, may be NULL if salt_len is 0
salt_lenlength of salt in bytes
encapsulated_keythe encapsulated key from the counterparty
encapsulated_key_lenlength of encapsulated_key in bytes
desired_shared_key_lenthe requested shared key length in bytes
shared_keyoutput buffer for the shared key
shared_key_lenon input the size of shared_key, on output the number of bytes written
Returns
0 on success, a negative value on failure

Definition at line 365 of file ffi_pk_op.cpp.

372 {
373 if(salt_len > 0 && salt == nullptr) {
375 }
376 if(Botan::any_null_pointers(encapsulated_key, shared_key_len)) {
378 }
379
380 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
381 const auto shared_key =
382 kem.decrypt(encapsulated_key, encapsulated_key_len, desired_shared_key_len, salt, salt_len);
383
384 return write_vec_output(shared_key_out, shared_key_len, shared_key);
385 });
386}

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

Return the length of the shared key this operation will produce

Parameters
opthe decapsulation operation
desired_shared_key_lengththe requested shared key length in bytes
output_shared_key_lengthset to the shared key length that will result
Returns
0 on success, a negative value on failure

Definition at line 352 of file ffi_pk_op.cpp.

354 {
355 if(output_shared_key_length == nullptr) {
357 }
358
359 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
360 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
361 return BOTAN_FFI_SUCCESS;
362 });
363}

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 )

Create a key encapsulation operation

Parameters
opthe new object will be placed here
keythe public key to encapsulate to
Key Derivation Functionsthe KDF applied to the shared secret, or "Raw" for no KDF
Returns
0 on success, a negative value on failure

Definition at line 275 of file ffi_pk_op.cpp.

275 {
276 if(Botan::any_null_pointers(op, padding)) {
278 }
279
280 return ffi_guard_thunk(__func__, [=]() -> int {
281 auto pk = std::make_unique<Botan::PK_KEM_Encryptor>(safe_get(key_obj), padding);
282 return ffi_new_object(op, std::move(pk));
283 });
284}

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

Generate a shared key along with the encapsulation of it for the counterparty

Parameters
opthe encapsulation operation
Random Number Generatorsa random number generator
salta salt passed to the KDF, may be NULL if salt_len is 0
salt_lenlength of salt in bytes
desired_shared_key_lenthe requested shared key length in bytes
shared_keyoutput buffer for the shared key
shared_key_lenon input the size of shared_key, on output the number of bytes written
encapsulated_keyoutput buffer for the encapsulated key
encapsulated_key_lenon input the size of encapsulated_key, on output the number of bytes written
Returns
0 on success, a negative value on failure

Definition at line 315 of file ffi_pk_op.cpp.

323 {
324 if(salt_len > 0 && salt == nullptr) {
326 }
327
328 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
329 const auto result = kem.encrypt(safe_get(rng), desired_shared_key_len, {salt, salt_len});
330
331 const int rc = write_vec_output(encapsulated_key_out, encapsulated_key_len, result.encapsulated_shared_key());
332
333 if(rc != 0) {
334 return rc;
335 }
336
337 return write_vec_output(shared_key_out, shared_key_len, result.shared_key());
338 });
339}

References BOTAN_FFI_ERROR_NULL_POINTER, 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)

Frees all resources of the key encapsulation operation object

Parameters
opthe operation to destroy
Returns
0 if success, error if invalid object handle

Definition at line 286 of file ffi_pk_op.cpp.

286 {
287 return BOTAN_FFI_CHECKED_DELETE(op);
288}

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 )

Return the length of the encapsulated key this operation produces

Parameters
opthe encapsulation operation
output_encapsulated_key_lengthset to the encapsulated key length in bytes
Returns
0 on success, a negative value on failure

Definition at line 303 of file ffi_pk_op.cpp.

304 {
305 if(output_encapsulated_key_length == nullptr) {
307 }
308
309 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
310 *output_encapsulated_key_length = kem.encapsulated_key_length();
311 return BOTAN_FFI_SUCCESS;
312 });
313}

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 )

Return the length of the shared key this operation will produce

Parameters
opthe encapsulation operation
desired_shared_key_lengththe requested shared key length in bytes
output_shared_key_lengthset to the shared key length that will result
Returns
0 on success, a negative value on failure

Definition at line 290 of file ffi_pk_op.cpp.

292 {
293 if(output_shared_key_length == nullptr) {
295 }
296
297 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
298 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
299 return BOTAN_FFI_SUCCESS;
300 });
301}

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 )

Perform key agreement with the counterparty's public value

Parameters
opthe key agreement operation
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
other_keythe counterparty's public value
other_key_lenlength of other_key in bytes
salta salt passed to the KDF, may be NULL if salt_len is 0
salt_lenlength of salt in bytes
Returns
0 on success, a negative value on failure

Definition at line 252 of file ffi_pk_op.cpp.

258 {
259 if(out_len == nullptr) {
261 }
262 if(other_key_len > 0 && other_key == nullptr) {
264 }
265 if(salt_len > 0 && salt == nullptr) {
267 }
268
269 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
270 auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
271 return write_vec_output(out, out_len, k);
272 });
273}

References BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Create a key agreement operation

Parameters
opthe new object will be placed here
keyour private key
Key Derivation Functionsthe KDF applied to the shared secret, or "Raw" for no KDF
flagsshould be 0 in current API revision
Returns
0 on success, a negative value on failure

Definition at line 208 of file ffi_pk_op.cpp.

208 {
209 if(Botan::any_null_pointers(op, kdf)) {
211 }
212
213 if(flags != 0) {
215 }
216
217 return ffi_guard_thunk(__func__, [=]() -> int {
218 *op = nullptr;
219 auto pk = std::make_unique<Botan::PK_Key_Agreement>(safe_get(key_obj), Botan::system_rng(), kdf);
220 return ffi_new_object(op, std::move(pk));
221 });
222}

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

Frees all resources of the key agreement operation object

Parameters
opthe operation to destroy
Returns
0 if success, error if invalid object handle

Definition at line 224 of file ffi_pk_op.cpp.

224 {
225 return BOTAN_FFI_CHECKED_DELETE(op);
226}

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 )

Export the public value of a key agreement private key, in the format expected by botan_pk_op_key_agreement

Parameters
keythe key agreement private key
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 228 of file ffi_pk_op.cpp.

228 {
229 return copy_view_bin(out, out_len, botan_pk_op_key_agreement_view_public, key);
230}
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:214

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 )

Return the length of the shared secret this operation produces

Parameters
opthe key agreement operation
out_lenset to the output length in bytes
Returns
0 on success, a negative value on failure

Definition at line 242 of file ffi_pk_op.cpp.

242 {
243 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
244 if(out_len == nullptr) {
246 }
247 *out_len = o.agreed_value_size();
248 return BOTAN_FFI_SUCCESS;
249 });
250}

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 )

View the public value of a key agreement private key

Parameters
keythe key agreement private key
ctxan application context passed to the view function
viewthe view callback which receives the encoding
Returns
0 on success, a negative value on failure

Definition at line 232 of file ffi_pk_op.cpp.

232 {
233 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
234 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k)) {
235 return invoke_view_callback(view, ctx, kak->public_value());
236 } else {
238 }
239 });
240}

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 )

Create a signature generation operation

Parameters
opthe new object will be placed here
keythe private key to sign with
hash_and_paddingthe signature padding and hash, eg "PSS(SHA-256)"
flags0, or BOTAN_PUBKEY_DER_FORMAT_SIGNATURE to request DER encoded signatures
Returns
0 on success, a negative value on failure

Definition at line 118 of file ffi_pk_op.cpp.

118 {
119 if(Botan::any_null_pointers(op, hash)) {
121 }
122
123 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
125 }
126
127 return ffi_guard_thunk(__func__, [=]() -> int {
128 *op = nullptr;
129
130 const bool use_der = (flags & BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) != 0;
132
133 auto pk = std::make_unique<Botan::PK_Signer>(safe_get(key_obj), Botan::system_rng(), hash, format);
134 return ffi_new_object(op, std::move(pk));
135 });
136}

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

Frees all resources of the signature generation operation object

Parameters
opthe operation to destroy
Returns
0 if success, error if invalid object handle

Definition at line 138 of file ffi_pk_op.cpp.

138 {
139 return BOTAN_FFI_CHECKED_DELETE(op);
140}

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 )

Produce a signature over the message, then reset for signing another message

Parameters
opthe signature operation
Random Number Generatorsa random number generator
sigoutput buffer
sig_lenon input the size of sig, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 158 of file ffi_pk_op.cpp.

158 {
159 return BOTAN_FFI_VISIT(op, [=](auto& o) { return write_vec_output(out, out_len, o.signature(safe_get(rng_obj))); });
160}

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 )

Return the length of the signatures this operation produces

Parameters
opthe signature operation
olenset to the signature length in bytes
Returns
0 on success, a negative value on failure

Definition at line 142 of file ffi_pk_op.cpp.

142 {
143 if(sig_len == nullptr) {
145 }
146
147 return BOTAN_FFI_VISIT(op, [=](const auto& o) { *sig_len = o.signature_length(); });
148}

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 )

Add more data to the message being signed

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

Definition at line 150 of file ffi_pk_op.cpp.

150 {
151 if(in_len > 0 && in == nullptr) {
153 }
154
155 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
156}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 )

Create a signature verification operation

Parameters
opthe new object will be placed here
keythe public key to verify with
hash_and_paddingthe signature padding and hash, eg "PSS(SHA-256)"
flags0, or BOTAN_PUBKEY_DER_FORMAT_SIGNATURE if the signature is DER encoded
Returns
0 on success, a negative value on failure

Definition at line 162 of file ffi_pk_op.cpp.

162 {
163 if(Botan::any_null_pointers(op, hash)) {
165 }
166
167 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
169 }
170
171 return ffi_guard_thunk(__func__, [=]() -> int {
172 *op = nullptr;
173 const bool use_der = (flags & BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) != 0;
175 auto pk = std::make_unique<Botan::PK_Verifier>(safe_get(key_obj), hash, format);
176 return ffi_new_object(op, std::move(pk));
177 });
178}

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

Frees all resources of the signature verification operation object

Parameters
opthe operation to destroy
Returns
0 if success, error if invalid object handle

Definition at line 180 of file ffi_pk_op.cpp.

180 {
181 return BOTAN_FFI_CHECKED_DELETE(op);
182}

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 )

Check the signature over the message, then reset for verifying another message

Parameters
opthe verification operation
sigthe signature to check
sig_lenlength of sig in bytes
Returns
0 if the signature is valid, BOTAN_FFI_INVALID_VERIFIER if it is not, or some other negative value on error

Definition at line 192 of file ffi_pk_op.cpp.

192 {
193 if(sig_len > 0 && sig == nullptr) {
195 }
196
197 return BOTAN_FFI_VISIT(op, [=](auto& o) {
198 const bool legit = o.check_signature(sig, sig_len);
199
200 if(legit) {
201 return BOTAN_FFI_SUCCESS;
202 } else {
204 }
205 });
206}

References BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Add more data to the message being verified

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

Definition at line 184 of file ffi_pk_op.cpp.

184 {
185 if(in_len > 0 && in == nullptr) {
187 }
188
189 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
190}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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 469 of file ffi_pkey.cpp.

469 {
470 if(hash_name == nullptr) {
472 }
473#if defined(BOTAN_HAS_HASH_ID)
474 return ffi_guard_thunk(__func__, [=]() -> int {
475 const std::vector<uint8_t> hash_id = Botan::pkcs_hash_id(hash_name);
476 return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
477 });
478#else
479 BOTAN_UNUSED(hash_name, pkcs_id, pkcs_id_len);
481#endif
482}
int write_output(T out[], size_t *out_len, const T buf[], size_t buf_len)
Definition ffi_util.h:252
std::vector< uint8_t > pkcs_hash_id(std::string_view name)
Definition hash_id.cpp:78

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Get the name of the algorithm this private key is for

Parameters
keythe private key to query
outoutput buffer
out_lenon input the length of out, on success the number of bytes written
Returns
0 on success, a negative value on failure

Definition at line 162 of file ffi_pkey.cpp.

162 {
163 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
164}

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 )

Test the consistency of a private key

Parameters
keythe private key to check
Random Number Generatorsa random number generator
flagseither 0 or BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Returns
0 if the key is valid, negative if invalid or some other error

Definition at line 178 of file ffi_pkey.cpp.

178 {
179 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS) != 0;
180 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
181 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
182 });
183}
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition ffi.h:1800

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.
Random Number Generatorsa 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:509

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 )

Create a new Diffie-Hellman private key

Parameters
keythe new object will be placed here
Random Number Generatorsa random number generator
paramthe name of the group, eg "modp/ietf/2048"
Returns
0 on success, a negative value on failure

Definition at line 598 of file ffi_pkey_algs.cpp.

598 {
599 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
600}
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 )

Create a new ECDH private key

Parameters
keythe new object will be placed here
Random Number Generatorsa random number generator
paramsthe name of the curve, eg "secp256r1"
Returns
0 on success, a negative value on failure

Definition at line 638 of file ffi_pkey_algs.cpp.

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

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

Create a new ECDSA private key

Parameters
keythe new object will be placed here
Random Number Generatorsa random number generator
paramsthe name of the curve, eg "secp256r1"
Returns
0 on success, a negative value on failure

Definition at line 439 of file ffi_pkey_algs.cpp.

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

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 )

Create a new McEliece private key

Parameters
keythe new object will be placed here
Random Number Generatorsa random number generator
nthe code length
tthe error correction capability
Returns
0 on success, a negative value on failure

Definition at line 1559 of file ffi_pkey_algs.cpp.

1559 {
1560 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
1561 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
1562}

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 )

Create a new RSA private key

Parameters
keythe new object will be placed here
Random Number Generatorsa random number generator
n_bitsthe bit length of the modulus
Returns
0 on success, a negative value on failure

Definition at line 228 of file ffi_pkey_algs.cpp.

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

References BOTAN_FFI_ERROR_BAD_PARAMETER, and botan_privkey_create().

◆ botan_privkey_destroy()

int botan_privkey_destroy ( botan_privkey_t key)

Frees all resources of the private key object

Parameters
keythe private key to destroy
Returns
0 if success, error if invalid object handle

Definition at line 120 of file ffi_pkey.cpp.

120 {
121 return BOTAN_FFI_CHECKED_DELETE(key);
122}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_privkey_dsa_get_x()

int botan_privkey_dsa_get_x ( botan_mp_t n,
botan_privkey_t key )

Get the secret value of a DSA private key

Parameters
nset to the value of the private key
keythe DSA private key
Returns
0 on success, a negative value on failure

Definition at line 419 of file ffi_pkey_algs.cpp.

419 {
420 return botan_privkey_get_field(x, key, "x");
421}
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] )

Get the raw encoding of an Ed25519 private key, followed by the public key

Parameters
keythe Ed25519 private key
outputset to the 64 byte concatenation of the private and public keys
Returns
0 on success, a negative value on failure

Definition at line 932 of file ffi_pkey_algs.cpp.

932 {
933 if(output == nullptr) {
935 }
936#if defined(BOTAN_HAS_ED25519)
937 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
938 if(auto ed = dynamic_cast<const Botan::Ed25519_PrivateKey*>(&k)) {
939 const auto ed_key = ed->raw_private_key_bits();
940 if(ed_key.size() != 64) {
942 }
943 Botan::copy_mem(output, ed_key.data(), ed_key.size());
944 return BOTAN_FFI_SUCCESS;
945 } else {
947 }
948 });
949#else
950 BOTAN_UNUSED(key, output);
952#endif
953}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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] )

Get the raw 57 byte encoding of an Ed448 private key

Parameters
keythe Ed448 private key
outputset to the raw private key
Returns
0 on success, a negative value on failure

Definition at line 1012 of file ffi_pkey_algs.cpp.

1012 {
1013 if(output == nullptr) {
1015 }
1016#if defined(BOTAN_HAS_ED448)
1017 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1018 if(auto ed = dynamic_cast<const Botan::Ed448_PrivateKey*>(&k)) {
1019 const auto ed_key = ed->raw_private_key_bits();
1020 Botan::copy_mem(std::span(output, 57), ed_key);
1021 return BOTAN_FFI_SUCCESS;
1022 } else {
1024 }
1025 });
1026#else
1027 BOTAN_UNUSED(key, output);
1029#endif
1030}
A private key for Ed448/Ed448ph according to RFC 8032.
Definition ed448.h:87

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Export a private key in DER, PEM or raw encoding

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.

Parameters
keythe private key to export
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
flagsone of BOTAN_PRIVKEY_EXPORT_FLAG_DER, _PEM or _RAW
Returns
0 on success, 1 if the buffer was too small, a negative value on other failures

Definition at line 212 of file ffi_pkey.cpp.

212 {
213 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
214 return copy_view_bin(out, out_len, botan_privkey_view_der, key);
215 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
216 return copy_view_str(out, out_len, botan_privkey_view_pem, key);
217 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
218 return copy_view_bin(out, out_len, botan_privkey_view_raw, key);
219 } else {
221 }
222}
#define BOTAN_PRIVKEY_EXPORT_FLAG_RAW
Definition ffi.h:1921
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:224
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:234
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1920
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1919
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:229
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:223

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 )

Export a private key encrypted with a passphrase

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

Parameters
keythe private key to export
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Random Number Generatorsa random number generator
passphrasethe passphrase to encrypt under
encryption_algothe cipher to use, or NULL for the default
flagseither BOTAN_PRIVKEY_EXPORT_FLAG_DER or BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Returns
0 on success, a negative value on failure

Definition at line 239 of file ffi_pkey.cpp.

245 {
246 return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
247}
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:326

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 encrypted with a passphrase, using the specified number of PBKDF iterations.

Parameters
keythe private key to export
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Random Number Generatorsa random number generator
passphrasethe passphrase to encrypt under
pbkdf_iterationsthe number of PBKDF iterations to run
cipher_algothe cipher to use, or NULL for the default
pbkdf_algothe password hash to use, or NULL for the default
flagseither BOTAN_PRIVKEY_EXPORT_FLAG_DER or BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Returns
0 on success, a negative value on failure

Definition at line 326 of file ffi_pkey.cpp.

334 {
335 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
336 return copy_view_bin(
337 out, out_len, botan_privkey_view_encrypted_der, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
338 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
339 return copy_view_str(
340 out, out_len, botan_privkey_view_encrypted_pem, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
341 } else {
343 }
344}
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:346
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:371

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 )

Export a private key encrypted with a passphrase, running the PBKDF for a specified amount of time

Note: starting in 3.0, the output iterations count is not provided

Parameters
keythe private key to export
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Random Number Generatorsa random number generator
passphrasethe passphrase to encrypt under
pbkdf_msec_runtimedesired PBKDF runtime in milliseconds
pbkdf_iterations_outignored since 3.0
cipher_algothe cipher to use, or NULL for the default
pbkdf_algothe password hash to use, or NULL for the default
flagseither BOTAN_PRIVKEY_EXPORT_FLAG_DER or BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Returns
0 on success, a negative value on failure

Definition at line 249 of file ffi_pkey.cpp.

258 {
259 if(pbkdf_iters_out != nullptr) {
260 *pbkdf_iters_out = 0;
261 }
262
263 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
264 return copy_view_bin(
265 out, out_len, botan_privkey_view_encrypted_der_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
266 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
267 return copy_view_str(
268 out, out_len, botan_privkey_view_encrypted_pem_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
269 } else {
271 }
272}
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:300
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:274

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 )

Extract the public key associated with a private key

Parameters
outthe new object will be placed here
inthe private key to extract the public key from
Returns
0 on success, a negative value on failure

Definition at line 152 of file ffi_pkey.cpp.

152 {
153 if(pubout == nullptr) {
155 }
156 return ffi_guard_thunk(__func__, [=]() -> int {
157 auto public_key = safe_get(key_obj).public_key();
158 return ffi_new_object(pubout, std::move(public_key));
159 });
160}

References BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Get an arbitrary named field from a private key, eg "p" or "q" for RSA

Parameters
outputset to the value of the requested field
keythe private key to query
field_namethe name of the field to retrieve
Returns
0 on success, a negative value on failure

Definition at line 216 of file ffi_pkey_algs.cpp.

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

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
Random Number Generatorsinitialized 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
Random Number Generatorsinitialized 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 if(key == nullptr) {
93 }
94
95 *key = nullptr;
96
97 if(bits == nullptr && len > 0) {
99 }
100
101 return ffi_guard_thunk(__func__, [=]() -> int {
102 Botan::DataSource_Memory src(bits, len);
103
104 std::unique_ptr<Botan::Private_Key> pkcs8;
105
106 if(password == nullptr) {
107 pkcs8 = Botan::PKCS8::load_key(src);
108 } else {
109 pkcs8 = Botan::PKCS8::load_key(src, std::string(password));
110 }
111
112 if(pkcs8) {
113 ffi_new_object(key, std::move(pkcs8));
114 return BOTAN_FFI_SUCCESS;
115 }
117 });
118}
std::unique_ptr< Private_Key > load_key(DataSource &source, const std::function< std::string()> &get_pass)
Definition pkcs8.cpp:319

References BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Load a Classic McEliece private key from its raw encoding

Parameters
keythe new object will be placed here
privkeythe raw private key
key_lenlength of privkey in bytes
cmce_modethe parameter set, eg "348864"
Returns
0 on success, a negative value on failure

Definition at line 1497 of file ffi_pkey_algs.cpp.

1500 {
1501#if defined(BOTAN_HAS_CLASSICMCELIECE)
1502 if(Botan::any_null_pointers(key, privkey, cmce_mode)) {
1504 }
1505
1506 *key = nullptr;
1507
1508 return ffi_guard_thunk(__func__, [=]() -> int {
1509 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1510 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PrivateKey>(std::span{privkey, key_len}, mode);
1511 return ffi_new_object(key, std::move(cmce_key));
1512 });
1513#else
1514 BOTAN_UNUSED(key, privkey, key_len, cmce_mode);
1516#endif
1517}
static Classic_McEliece_Parameter_Set from_string(std::string_view param_name)
Get the parameter set for a given parameter set name.

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::Classic_McEliece_Parameter_Set::from_string().

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

Load a DSA private key from its group parameters and secret value

Parameters
keythe new object will be placed here
pthe group prime
qthe order of the subgroup
gthe subgroup generator
xthe private key
Returns
0 on success, a negative value on failure

Definition at line 383 of file ffi_pkey_algs.cpp.

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

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 )

Load an ECDH private key from its secret scalar

Parameters
keythe new object will be placed here
scalarthe private scalar
curve_namethe name of the curve, eg "secp256r1"
Returns
0 on success, a negative value on failure

Definition at line 704 of file ffi_pkey_algs.cpp.

704 {
705#if defined(BOTAN_HAS_ECDH)
706 if(Botan::any_null_pointers(key, curve_name)) {
708 }
709 *key = nullptr;
710 return ffi_guard_thunk(__func__, [=]() -> int {
711 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
712 const int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
713 if(rc == BOTAN_FFI_SUCCESS) {
714 ffi_new_object(key, std::move(p_key));
715 }
716 return rc;
717 });
718#else
719 BOTAN_UNUSED(key, scalar, curve_name);
721#endif
722}

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

Load an ECDSA private key from its secret scalar

Parameters
keythe new object will be placed here
scalarthe private scalar
curve_namethe name of the curve, eg "secp256r1"
Returns
0 on success, a negative value on failure

Definition at line 514 of file ffi_pkey_algs.cpp.

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

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

Load an Ed25519 private key from its raw 32 byte encoding

Parameters
keythe new object will be placed here
privkeythe raw private key
Returns
0 on success, a negative value on failure

Definition at line 898 of file ffi_pkey_algs.cpp.

898 {
899#if defined(BOTAN_HAS_ED25519)
900 if(any_null_pointers(key, privkey)) {
902 }
903 *key = nullptr;
904 return ffi_guard_thunk(__func__, [=]() -> int {
905 auto ed25519 =
906 std::make_unique<Botan::Ed25519_PrivateKey>(Botan::Ed25519_PrivateKey::from_seed(std::span{privkey, 32}));
907 return ffi_new_object(key, std::move(ed25519));
908 });
909#else
910 BOTAN_UNUSED(key, privkey);
912#endif
913}
static Ed25519_PrivateKey from_seed(std::span< const uint8_t > seed)

References Botan_FFI::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::Ed25519_PrivateKey::from_seed().

◆ botan_privkey_load_ed448()

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

Load an Ed448 private key from its raw 57 byte encoding

Parameters
keythe new object will be placed here
privkeythe raw private key
Returns
0 on success, a negative value on failure

Definition at line 980 of file ffi_pkey_algs.cpp.

980 {
981#if defined(BOTAN_HAS_ED448)
982 if(any_null_pointers(key, privkey)) {
984 }
985 *key = nullptr;
986 return ffi_guard_thunk(__func__, [=]() -> int {
987 auto ed448 = std::make_unique<Botan::Ed448_PrivateKey>(std::span(privkey, 57));
988 return ffi_new_object(key, std::move(ed448));
989 });
990#else
991 BOTAN_UNUSED(key, privkey);
993#endif
994}

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

Load a FrodoKEM private key from its raw encoding

Parameters
keythe new object will be placed here
privkeythe raw private key
key_lenlength of privkey in bytes
frodo_modethe parameter set, eg "FrodoKEM-640-SHAKE"
Returns
0 on success, a negative value on failure

Definition at line 1455 of file ffi_pkey_algs.cpp.

1455 {
1456#if defined(BOTAN_HAS_FRODOKEM)
1457 if(Botan::any_null_pointers(key, privkey, frodo_mode)) {
1459 }
1460
1461 *key = nullptr;
1462
1463 return ffi_guard_thunk(__func__, [=]() -> int {
1464 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1465 auto frodo_key = std::make_unique<Botan::FrodoKEM_PrivateKey>(std::span{privkey, key_len}, mode);
1466 return ffi_new_object(key, std::move(frodo_key));
1467 });
1468#else
1469 BOTAN_UNUSED(key, privkey, key_len, frodo_mode);
1471#endif
1472}

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

Load a Kyber private key from its raw encoding. The parameter set is inferred from the key length.

Parameters
keythe new object will be placed here
privkeythe raw private key
key_lenlength of privkey in bytes
Returns
0 on success, a negative value on failure

Definition at line 1205 of file ffi_pkey_algs.cpp.

1205 {
1206#if defined(BOTAN_HAS_KYBER)
1207 if(Botan::any_null_pointers(key, privkey)) {
1209 }
1210 *key = nullptr;
1211
1212 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1213 if(len == 1632) {
1215 } else if(len == 2400) {
1217 } else if(len == 3168) {
1219 } else {
1220 return {};
1221 }
1222 }(key_len);
1223
1224 if(mode.has_value()) {
1225 return ffi_guard_thunk(__func__, [=]() -> int {
1226 auto kyber = std::make_unique<Botan::Kyber_PrivateKey>(std::span{privkey, key_len}, *mode);
1227 return ffi_new_object(key, std::move(kyber));
1228 });
1229 } else {
1231 }
1232#else
1233 BOTAN_UNUSED(key, key_len, privkey);
1235#endif
1236}

References Botan::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_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 )

Load an ML-DSA private key from its raw encoding

Parameters
keythe new object will be placed here
privkeythe raw private key
key_lenlength of privkey in bytes
mldsa_modethe parameter set, eg "ML-DSA-6x5"
Returns
0 on success, a negative value on failure

Definition at line 1355 of file ffi_pkey_algs.cpp.

1355 {
1356#if defined(BOTAN_HAS_ML_DSA)
1357 if(Botan::any_null_pointers(key, privkey, mldsa_mode)) {
1359 }
1360
1361 *key = nullptr;
1362
1363 return ffi_guard_thunk(__func__, [=]() -> int {
1364 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1365 if(!mode.is_ml_dsa()) {
1367 }
1368
1369 auto mldsa_key = std::make_unique<Botan::ML_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1370 return ffi_new_object(key, std::move(mldsa_key));
1371 });
1372#else
1373 BOTAN_UNUSED(key, key_len, privkey, mldsa_mode);
1375#endif
1376}
DilithiumMode ML_DSA_Mode
Definition ml_dsa.h:21

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

Load an ML-KEM private key from its raw encoding

Parameters
keythe new object will be placed here
privkeythe raw private key
key_lenlength of privkey in bytes
mlkem_modethe parameter set, eg "ML-KEM-768"
Returns
0 on success, a negative value on failure

Definition at line 1305 of file ffi_pkey_algs.cpp.

1305 {
1306#if defined(BOTAN_HAS_ML_KEM)
1307 if(Botan::any_null_pointers(key, privkey, mlkem_mode)) {
1309 }
1310
1311 *key = nullptr;
1312
1313 return ffi_guard_thunk(__func__, [=]() -> int {
1314 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1315 if(!mode.is_ml_kem()) {
1317 }
1318
1319 auto mlkem_key = std::make_unique<Botan::ML_KEM_PrivateKey>(std::span{privkey, key_len}, mode);
1320 return ffi_new_object(key, std::move(mlkem_key));
1321 });
1322#else
1323 BOTAN_UNUSED(key, key_len, privkey, mlkem_mode);
1325#endif
1326}
KyberMode ML_KEM_Mode
Definition ml_kem.h:21

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

Load an RSA private key from its factors and public exponent

Parameters
keythe new object will be placed here
pthe first prime factor
qthe second prime factor
ethe public exponent
Returns
0 on success, a negative value on failure

Definition at line 238 of file ffi_pkey_algs.cpp.

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_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 )

Load an RSA private key from a PKCS #1 RSAPrivateKey structure

Parameters
keythe new object will be placed here
bitsthe DER encoding to load
lenlength of bits in bytes
Returns
0 on success, a negative value on failure

Definition at line 255 of file ffi_pkey_algs.cpp.

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

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

Load an SLH-DSA private key from its raw encoding

Parameters
keythe new object will be placed here
privkeythe raw private key
key_lenlength of privkey in bytes
slhdsa_modethe parameter set, eg "SLH-DSA-SHA2-128s"
Returns
0 on success, a negative value on failure

Definition at line 1405 of file ffi_pkey_algs.cpp.

1405 {
1406#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1407 if(Botan::any_null_pointers(key, privkey, slhdsa_mode)) {
1409 }
1410
1411 *key = nullptr;
1412
1413 return ffi_guard_thunk(__func__, [=]() -> int {
1414 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1415 if(!mode.is_slh_dsa()) {
1417 }
1418
1419 auto slhdsa_key = std::make_unique<Botan::SLH_DSA_PrivateKey>(std::span{privkey, key_len}, mode);
1420 return ffi_new_object(key, std::move(slhdsa_key));
1421 });
1422#else
1423 BOTAN_UNUSED(key, key_len, privkey, slhdsa_mode);
1425#endif
1426}

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

Load an SM2 private key from its secret scalar

Parameters
keythe new object will be placed here
scalarthe private scalar
curve_namethe name of the curve, typically "sm2p256v1"
Returns
0 on success, a negative value on failure

Definition at line 806 of file ffi_pkey_algs.cpp.

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

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

Load an SM2 encryption private key; identical to botan_privkey_load_sm2

Parameters
keythe new object will be placed here
scalarthe private scalar
curve_namethe name of the curve, typically "sm2p256v1"
Returns
0 on success, a negative value on failure

Definition at line 835 of file ffi_pkey_algs.cpp.

835 {
836 return botan_privkey_load_sm2(key, scalar, curve_name);
837}
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] )

Load an X25519 private key from its raw 32 byte encoding

Parameters
keythe new object will be placed here
privkeythe raw private key
Returns
0 on success, a negative value on failure

Definition at line 1054 of file ffi_pkey_algs.cpp.

1054 {
1055#if defined(BOTAN_HAS_X25519)
1056 if(any_null_pointers(key, privkey)) {
1058 }
1059 *key = nullptr;
1060 return ffi_guard_thunk(__func__, [=]() -> int {
1061 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(std::span{privkey, 32});
1062 return ffi_new_object(key, std::move(x25519));
1063 });
1064#else
1065 BOTAN_UNUSED(key, privkey);
1067#endif
1068}

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

Load an X448 private key from its raw 56 byte encoding

Parameters
keythe new object will be placed here
privkeythe raw private key
Returns
0 on success, a negative value on failure

Definition at line 1130 of file ffi_pkey_algs.cpp.

1130 {
1131#if defined(BOTAN_HAS_X448)
1132 if(any_null_pointers(key, privkey)) {
1134 }
1135 *key = nullptr;
1136 return ffi_guard_thunk(__func__, [=]() -> int {
1137 auto x448 = std::make_unique<Botan::X448_PrivateKey>(std::span{privkey, 56});
1138 return ffi_new_object(key, std::move(x448));
1139 });
1140#else
1141 BOTAN_UNUSED(key, privkey);
1143#endif
1144}
Point448 x448(const ScalarX448 &k, const Point448 &u)
Multiply a scalar k with a point u.

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

Get the object identifier associated with a private key

Parameters
oidthe new object will be placed here
keythe private key to query
Returns
0 on success, a negative value on failure

Definition at line 409 of file ffi_pkey.cpp.

409 {
410 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
411 if(oid == nullptr) {
413 }
414
415 auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
416 ffi_new_object(oid, std::move(oid_ptr));
417
418 return BOTAN_FFI_SUCCESS;
419 });
420}

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
keythe private key to check
outto that value
Returns
0 on success, a negative value on failure or if the key is not stateful

Definition at line 437 of file ffi_pkey.cpp.

437 {
438 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
439 if(out == nullptr) {
441 }
442
443 if(auto remaining = k.remaining_operations()) {
444 *out = remaining.value();
445 return BOTAN_FFI_SUCCESS;
446 } else {
448 }
449 });
450}

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 )

Get the private exponent of an RSA private key

Parameters
dset to the value of the private exponent
rsa_keythe RSA private key
Returns
0 on success, a negative value on failure

Definition at line 323 of file ffi_pkey_algs.cpp.

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

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 )

Get the public exponent of an RSA private key

Parameters
eset to the value of the public exponent
rsa_keythe RSA private key
Returns
0 on success, a negative value on failure

Definition at line 319 of file ffi_pkey_algs.cpp.

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

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 )

Get the modulus of an RSA private key

Parameters
nset to the value of the modulus
rsa_keythe RSA private key
Returns
0 on success, a negative value on failure

Definition at line 315 of file ffi_pkey_algs.cpp.

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

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 )

Get the first prime factor of an RSA private key

Parameters
pset to the value of the factor
rsa_keythe RSA private key
Returns
0 on success, a negative value on failure

Definition at line 307 of file ffi_pkey_algs.cpp.

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

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 )

Export an RSA private key as a PKCS #1 RSAPrivateKey structure

Parameters
rsa_keythe RSA private key
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
flagseither BOTAN_PRIVKEY_EXPORT_FLAG_DER or BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Returns
0 on success, a negative value on failure

Definition at line 335 of file ffi_pkey_algs.cpp.

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

Get the second prime factor of an RSA private key

Parameters
qset to the value of the factor
rsa_keythe RSA private key
Returns
0 on success, a negative value on failure

Definition at line 311 of file ffi_pkey_algs.cpp.

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

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
keythe private key to check
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 422 of file ffi_pkey.cpp.

422 {
423 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
424 if(out == nullptr) {
426 }
427
428 if(k.stateful_operation()) {
429 *out = 1;
430 } else {
431 *out = 0;
432 }
433 return BOTAN_FFI_SUCCESS;
434 });
435}

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

224 {
225 return BOTAN_FFI_VISIT(key,
226 [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.private_key_info()); });
227}

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

353 {
354 if(passphrase == nullptr) {
356 }
357
358 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
360
361 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
362 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
363 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
364
365 auto pkcs8 = Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
366
367 return invoke_view_callback(view, ctx, pkcs8);
368 });
369}
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:207

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

281 {
282 if(passphrase == nullptr) {
284 }
285
286 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
287 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
289
290 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
291 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
292
293 auto pkcs8 =
294 Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
295
296 return invoke_view_callback(view, ctx, pkcs8);
297 });
298}
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:250

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

378 {
379 if(passphrase == nullptr) {
381 }
382
383 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
385
386 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
387 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
388 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
389
390 auto pkcs8 = Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
391
392 return invoke_view_callback(view, ctx, pkcs8);
393 });
394}
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:237

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

307 {
308 if(passphrase == nullptr) {
310 }
311
312 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
313 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
315
316 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
317 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
318
319 auto pkcs8 =
320 Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
321
322 return invoke_view_callback(view, ctx, pkcs8);
323 });
324}
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:284

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 )

View the raw encoding of a Kyber private key

Parameters
keythe Kyber private key
ctxan application context passed to the view function
viewthe view callback which receives the encoding
Returns
0 on success, a negative value on failure

Definition at line 1271 of file ffi_pkey_algs.cpp.

1271 {
1272#if defined(BOTAN_HAS_KYBER)
1273 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1274 if(auto kyber = dynamic_cast<const Botan::Kyber_PrivateKey*>(&k)) {
1275 return invoke_view_callback(view, ctx, kyber->raw_private_key_bits());
1276 } else {
1278 }
1279 });
1280#else
1281 BOTAN_UNUSED(key, ctx, view);
1283#endif
1284}

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

229 {
230 return BOTAN_FFI_VISIT(
231 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::PEM_encode(k)); });
232}
std::string PEM_encode(const Private_Key &key)
Definition pkcs8.cpp:122

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

234 {
235 return BOTAN_FFI_VISIT(
236 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_private_key_bits()); });
237}

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

Get the raw 32 byte encoding of an X25519 private key

Parameters
keythe X25519 private key
outputset to the raw private key
Returns
0 on success, a negative value on failure

Definition at line 1086 of file ffi_pkey_algs.cpp.

1086 {
1087 if(output == nullptr) {
1089 }
1090#if defined(BOTAN_HAS_X25519)
1091 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1092 if(auto x25519 = dynamic_cast<const Botan::X25519_PrivateKey*>(&k)) {
1093 const auto x25519_key = x25519->raw_private_key_bits();
1094 if(x25519_key.size() != 32) {
1096 }
1097 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
1098 return BOTAN_FFI_SUCCESS;
1099 } else {
1101 }
1102 });
1103#else
1104 BOTAN_UNUSED(key, output);
1106#endif
1107}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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] )

Get the raw 56 byte encoding of an X448 private key

Parameters
keythe X448 private key
outputset to the raw private key
Returns
0 on success, a negative value on failure

Definition at line 1162 of file ffi_pkey_algs.cpp.

1162 {
1163 if(output == nullptr) {
1165 }
1166#if defined(BOTAN_HAS_X448)
1167 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1168 if(auto x448 = dynamic_cast<const Botan::X448_PrivateKey*>(&k)) {
1169 const auto x448_key = x448->raw_private_key_bits();
1170 Botan::copy_mem(std::span{output, 56}, x448_key);
1171 return BOTAN_FFI_SUCCESS;
1172 } else {
1174 }
1175 });
1176#else
1177 BOTAN_UNUSED(key, output);
1179#endif
1180}
A private key for the X448 key agreement scheme according to RFC 7748.
Definition x448.h:74

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Get the name of the algorithm this public key is for

Parameters
keythe public key to query
outoutput buffer
out_lenon input the length of out, on success the number of bytes written
Returns
0 on success, a negative value on failure

Definition at line 166 of file ffi_pkey.cpp.

166 {
167 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
168}

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

170 {
171 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS) != 0;
172
173 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
174 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
175 });
176}

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)

Frees all resources of the public key object

Parameters
keythe public key to destroy
Returns
0 if success, error if invalid object handle

Definition at line 148 of file ffi_pkey.cpp.

148 {
149 return BOTAN_FFI_CHECKED_DELETE(key);
150}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pubkey_dsa_get_g()

int botan_pubkey_dsa_get_g ( botan_mp_t d,
botan_pubkey_t key )

Get the subgroup generator of a DSA public key

Parameters
dset to the value of the generator
keythe DSA public key
Returns
0 on success, a negative value on failure

Definition at line 431 of file ffi_pkey_algs.cpp.

431 {
432 return botan_pubkey_get_field(g, key, "g");
433}
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 )

Get the group prime of a DSA public key

Parameters
pset to the value of the group prime
keythe DSA public key
Returns
0 on success, a negative value on failure

Definition at line 423 of file ffi_pkey_algs.cpp.

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

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_q()

int botan_pubkey_dsa_get_q ( botan_mp_t q,
botan_pubkey_t key )

Get the subgroup order of a DSA public key

Parameters
qset to the value of the subgroup order
keythe DSA public key
Returns
0 on success, a negative value on failure

Definition at line 427 of file ffi_pkey_algs.cpp.

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

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_y()

int botan_pubkey_dsa_get_y ( botan_mp_t y,
botan_pubkey_t key )

Get the public value of a DSA public key

Parameters
yset to the value of the public key
keythe DSA public key
Returns
0 on success, a negative value on failure

Definition at line 435 of file ffi_pkey_algs.cpp.

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

References botan_pubkey_get_field().

◆ botan_pubkey_ecc_key_used_explicit_encoding()

int botan_pubkey_ecc_key_used_explicit_encoding ( botan_pubkey_t key)

Check if the group of this EC key was encoded using explicit curve parameters rather than a named curve OID

Parameters
keythe EC public key to examine
Returns
1 if explicit encoding was used, 0 if not, negative on error

Definition at line 445 of file ffi_pkey_algs.cpp.

445 {
446#if defined(BOTAN_HAS_ECC_KEY)
447 return ffi_guard_thunk(__func__, [=]() -> int {
448 const Botan::Public_Key& pub_key = safe_get(key);
449 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
450
451 if(ec_key == nullptr) {
453 }
454
455 return ec_key->domain().used_explicit_encoding() ? 1 : 0;
456 });
457#else
458 BOTAN_UNUSED(key);
460#endif
461}
bool used_explicit_encoding() const
Definition ec_group.h:305

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

Get the raw 32 byte encoding of an Ed25519 public key

Parameters
keythe Ed25519 public key
Public Key Algorithmsset to the raw public key
Returns
0 on success, a negative value on failure

Definition at line 955 of file ffi_pkey_algs.cpp.

955 {
956 if(output == nullptr) {
958 }
959#if defined(BOTAN_HAS_ED25519)
960 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
961 if(auto ed = dynamic_cast<const Botan::Ed25519_PublicKey*>(&k)) {
962 const std::vector<uint8_t>& ed_key = ed->get_public_key();
963 if(ed_key.size() != 32) {
965 }
966 Botan::copy_mem(output, ed_key.data(), ed_key.size());
967 return BOTAN_FFI_SUCCESS;
968 } else {
970 }
971 });
972#else
973 BOTAN_UNUSED(key, output);
975#endif
976}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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] )

Get the raw 57 byte encoding of an Ed448 public key

Parameters
keythe Ed448 public key
Public Key Algorithmsset to the raw public key
Returns
0 on success, a negative value on failure

Definition at line 1032 of file ffi_pkey_algs.cpp.

1032 {
1033 if(output == nullptr) {
1035 }
1036#if defined(BOTAN_HAS_ED448)
1037 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1038 if(auto ed = dynamic_cast<const Botan::Ed448_PublicKey*>(&k)) {
1039 const auto ed_key = ed->public_key_bits();
1040 Botan::copy_mem(std::span(output, 57), ed_key);
1041 return BOTAN_FFI_SUCCESS;
1042 } else {
1044 }
1045 });
1046#else
1047 BOTAN_UNUSED(key, output);
1049#endif
1050}
A public key for Ed448/Ed448ph according to RFC 8032.
Definition ed448.h:31

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Estimate the strength of this key, in bits, against the best known attack

Parameters
keythe public key to query
estimateset to the estimated strength in bits
Returns
0 on success, a negative value on failure

Definition at line 452 of file ffi_pkey.cpp.

452 {
453 if(estimate == nullptr) {
455 }
456 return BOTAN_FFI_VISIT(key, [=](const auto& k) { *estimate = k.estimated_strength(); });
457}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_pubkey_export()

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

Export a public key in DER, PEM or raw encoding

Parameters
keythe public key to export
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
flagsone of BOTAN_PRIVKEY_EXPORT_FLAG_DER, _PEM or _RAW
Returns
0 on success, a negative value on failure

Definition at line 185 of file ffi_pkey.cpp.

185 {
186 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
187 return copy_view_bin(out, out_len, botan_pubkey_view_der, key);
188 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
189 return copy_view_str(out, out_len, botan_pubkey_view_pem, key);
190 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
191 return copy_view_bin(out, out_len, botan_pubkey_view_raw, key);
192 } else {
194 }
195}
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:202
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:197
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:207

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 )

Compute a fingerprint (hash of the public key encoding)

Parameters
keythe public key to fingerprint
Hashesthe name of the hash to use, eg "SHA-256"
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 459 of file ffi_pkey.cpp.

459 {
460 if(hash_fn == nullptr) {
462 }
463 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
464 auto h = Botan::HashFunction::create_or_throw(hash_fn);
465 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
466 });
467}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:308

References BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Get an arbitrary named field from a public key, eg "n" or "e" for RSA

Parameters
outputset to the value of the requested field
keythe public key to query
field_namethe name of the field to retrieve
Returns
0 on success, a negative value on failure

Definition at line 206 of file ffi_pkey_algs.cpp.

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

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 )

Load a public key from an X.509 SubjectPublicKeyInfo structure

Parameters
keythe new object will be placed here
bitsthe DER encoding to load
lenlength of bits in bytes
Returns
0 on success, a negative value on failure

Definition at line 124 of file ffi_pkey.cpp.

124 {
125 if(key == nullptr) {
127 }
128
129 *key = nullptr;
130
131 if(bits == nullptr && bits_len > 0) {
133 }
134
135 return ffi_guard_thunk(__func__, [=]() -> int {
136 Botan::DataSource_Memory src(bits, bits_len);
137 std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src));
138
139 if(pubkey == nullptr) {
141 }
142
143 ffi_new_object(key, std::move(pubkey));
144 return BOTAN_FFI_SUCCESS;
145 });
146}
std::unique_ptr< Public_Key > load_key(DataSource &source)
Definition x509_key.cpp:28

References BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Load a Classic McEliece public key from its raw encoding

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
key_lenlength of pubkey in bytes
cmce_modethe parameter set, eg "348864"
Returns
0 on success, a negative value on failure

Definition at line 1519 of file ffi_pkey_algs.cpp.

1522 {
1523#if defined(BOTAN_HAS_CLASSICMCELIECE)
1524 if(Botan::any_null_pointers(key, pubkey, cmce_mode)) {
1526 }
1527
1528 *key = nullptr;
1529
1530 return ffi_guard_thunk(__func__, [=]() -> int {
1531 const auto mode = Botan::Classic_McEliece_Parameter_Set::from_string(cmce_mode);
1532 auto cmce_key = std::make_unique<Botan::Classic_McEliece_PublicKey>(std::span{pubkey, key_len}, mode);
1533 return ffi_new_object(key, std::move(cmce_key));
1534 });
1535#else
1536 BOTAN_UNUSED(key, pubkey, key_len, cmce_mode);
1538#endif
1539}

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

Load a DSA public key from its group parameters and public value

Parameters
keythe new object will be placed here
pthe group prime
qthe order of the subgroup
gthe subgroup generator
ythe public key
Returns
0 on success, a negative value on failure

Definition at line 401 of file ffi_pkey_algs.cpp.

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

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 )

Load an ECDH public key from the affine coordinates of the public point

Parameters
keythe new object will be placed here
public_xthe x coordinate of the public point
public_ythe y coordinate of the public point
curve_namethe name of the curve, eg "secp256r1"
Returns
0 on success, a negative value on failure

Definition at line 657 of file ffi_pkey_algs.cpp.

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

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

Load an ECDH public key from the SEC1 encoding of the public point

Parameters
keythe new object will be placed here
sec1the SEC1 compressed or uncompressed point encoding
sec1_lenlength of sec1 in bytes
curve_namethe name of the curve, eg "secp256r1"
Returns
0 on success, a negative value on failure

Definition at line 681 of file ffi_pkey_algs.cpp.

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

References Botan::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_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 )

Load an ECDSA public key from the affine coordinates of the public point

Parameters
keythe new object will be placed here
public_xthe x coordinate of the public point
public_ythe y coordinate of the public point
curve_namethe name of the curve, eg "secp256r1"
Returns
0 on success, a negative value on failure

Definition at line 465 of file ffi_pkey_algs.cpp.

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

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

Load an ECDSA public key from the SEC1 encoding of the public point

Parameters
keythe new object will be placed here
sec1the SEC1 compressed or uncompressed point encoding
sec1_lenlength of sec1 in bytes
curve_namethe name of the curve, eg "secp256r1"
Returns
0 on success, a negative value on failure

Definition at line 491 of file ffi_pkey_algs.cpp.

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

References Botan::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_FFI::ffi_new_object().

◆ botan_pubkey_load_ed25519()

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

Load an Ed25519 public key from its raw 32 byte encoding

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
Returns
0 on success, a negative value on failure

Definition at line 915 of file ffi_pkey_algs.cpp.

915 {
916#if defined(BOTAN_HAS_ED25519)
917 if(any_null_pointers(key, pubkey)) {
919 }
920 *key = nullptr;
921 return ffi_guard_thunk(__func__, [=]() -> int {
922 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
923 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
924 return ffi_new_object(key, std::move(ed25519));
925 });
926#else
927 BOTAN_UNUSED(key, pubkey);
929#endif
930}

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

Load an Ed448 public key from its raw 57 byte encoding

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
Returns
0 on success, a negative value on failure

Definition at line 996 of file ffi_pkey_algs.cpp.

996 {
997#if defined(BOTAN_HAS_ED448)
998 if(any_null_pointers(key, pubkey)) {
1000 }
1001 *key = nullptr;
1002 return ffi_guard_thunk(__func__, [=]() -> int {
1003 auto ed448 = std::make_unique<Botan::Ed448_PublicKey>(std::span(pubkey, 57));
1004 return ffi_new_object(key, std::move(ed448));
1005 });
1006#else
1007 BOTAN_UNUSED(key, pubkey);
1009#endif
1010}

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

Load a FrodoKEM public key from its raw encoding

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
key_lenlength of pubkey in bytes
frodo_modethe parameter set, eg "FrodoKEM-640-SHAKE"
Returns
0 on success, a negative value on failure

Definition at line 1474 of file ffi_pkey_algs.cpp.

1474 {
1475#if defined(BOTAN_HAS_FRODOKEM)
1476 if(Botan::any_null_pointers(key, pubkey, frodo_mode)) {
1478 }
1479
1480 *key = nullptr;
1481
1482 return ffi_guard_thunk(__func__, [=]() -> int {
1483 const auto mode = Botan::FrodoKEMMode(frodo_mode);
1484 auto frodo_key = std::make_unique<Botan::FrodoKEM_PublicKey>(std::span{pubkey, key_len}, mode);
1485 return ffi_new_object(key, std::move(frodo_key));
1486 });
1487#else
1488 BOTAN_UNUSED(key, pubkey, key_len, frodo_mode);
1490#endif
1491}

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

Load a Kyber public key from its raw encoding. The parameter set is inferred from the key length.

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
key_lenlength of pubkey in bytes
Returns
0 on success, a negative value on failure

Definition at line 1238 of file ffi_pkey_algs.cpp.

1238 {
1239#if defined(BOTAN_HAS_KYBER)
1240 if(Botan::any_null_pointers(key, pubkey)) {
1242 }
1243 *key = nullptr;
1244
1245 const auto mode = [](size_t len) -> std::optional<Botan::KyberMode> {
1246 if(len == 800) {
1248 } else if(len == 1184) {
1250 } else if(len == 1568) {
1252 } else {
1253 return {};
1254 }
1255 }(key_len);
1256
1257 if(mode.has_value()) {
1258 return ffi_guard_thunk(__func__, [=]() -> int {
1259 auto kyber = std::make_unique<Botan::Kyber_PublicKey>(std::span{pubkey, key_len}, *mode);
1260 return ffi_new_object(key, std::move(kyber));
1261 });
1262 } else {
1264 }
1265#else
1266 BOTAN_UNUSED(key, pubkey, key_len);
1268#endif
1269}

References Botan::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_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 )

Load an ML-DSA public key from its raw encoding

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
key_lenlength of pubkey in bytes
mldsa_modethe parameter set, eg "ML-DSA-6x5"
Returns
0 on success, a negative value on failure

Definition at line 1378 of file ffi_pkey_algs.cpp.

1378 {
1379#if defined(BOTAN_HAS_ML_DSA)
1380 if(Botan::any_null_pointers(key, pubkey, mldsa_mode)) {
1382 }
1383
1384 *key = nullptr;
1385
1386 return ffi_guard_thunk(__func__, [=]() -> int {
1387 auto mode = Botan::ML_DSA_Mode(mldsa_mode);
1388 if(!mode.is_ml_dsa()) {
1390 }
1391
1392 auto mldsa_key = std::make_unique<Botan::ML_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1393 return ffi_new_object(key, std::move(mldsa_key));
1394 });
1395#else
1396 BOTAN_UNUSED(key, key_len, pubkey, mldsa_mode);
1398#endif
1399}

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

Load an ML-KEM public key from its raw encoding

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
key_lenlength of pubkey in bytes
mlkem_modethe parameter set, eg "ML-KEM-768"
Returns
0 on success, a negative value on failure

Definition at line 1328 of file ffi_pkey_algs.cpp.

1328 {
1329#if defined(BOTAN_HAS_ML_KEM)
1330 if(Botan::any_null_pointers(key, pubkey, mlkem_mode)) {
1332 }
1333
1334 *key = nullptr;
1335
1336 return ffi_guard_thunk(__func__, [=]() -> int {
1337 auto mode = Botan::ML_KEM_Mode(mlkem_mode);
1338 if(!mode.is_ml_kem()) {
1340 }
1341
1342 auto mlkem_key = std::make_unique<Botan::ML_KEM_PublicKey>(std::span{pubkey, key_len}, mode.mode());
1343 return ffi_new_object(key, std::move(mlkem_key));
1344 });
1345#else
1346 BOTAN_UNUSED(key, key_len, pubkey, mlkem_mode);
1348#endif
1349}

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

Load an RSA public key from its modulus and public exponent

Parameters
keythe new object will be placed here
nthe modulus
ethe public exponent
Returns
0 on success, a negative value on failure

Definition at line 273 of file ffi_pkey_algs.cpp.

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

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 )

Load an RSA public key from a PKCS #1 RSAPublicKey structure

Parameters
keythe new object will be placed here
bitsthe DER encoding to load
lenlength of bits in bytes
Returns
0 on success, a negative value on failure

Definition at line 289 of file ffi_pkey_algs.cpp.

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

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

Load an SLH-DSA public key from its raw encoding

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
key_lenlength of pubkey in bytes
slhdsa_modethe parameter set, eg "SLH-DSA-SHA2-128s"
Returns
0 on success, a negative value on failure

Definition at line 1428 of file ffi_pkey_algs.cpp.

1428 {
1429#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
1430 if(Botan::any_null_pointers(key, pubkey, slhdsa_mode)) {
1432 }
1433
1434 *key = nullptr;
1435
1436 return ffi_guard_thunk(__func__, [=]() -> int {
1437 auto mode = Botan::SLH_DSA_Parameters::create(slhdsa_mode);
1438 if(!mode.is_slh_dsa()) {
1440 }
1441
1442 auto mldsa_key = std::make_unique<Botan::SLH_DSA_PublicKey>(std::span{pubkey, key_len}, mode);
1443 return ffi_new_object(key, std::move(mldsa_key));
1444 });
1445#else
1446 BOTAN_UNUSED(key, key_len, pubkey, slhdsa_mode);
1448#endif
1449}

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

Load an SM2 public key from the affine coordinates of the public point

Parameters
keythe new object will be placed here
public_xthe x coordinate of the public point
public_ythe y coordinate of the public point
curve_namethe name of the curve, typically "sm2p256v1"
Returns
0 on success, a negative value on failure

Definition at line 759 of file ffi_pkey_algs.cpp.

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

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

Load an SM2 encryption public key; identical to botan_pubkey_load_sm2

Parameters
keythe new object will be placed here
public_xthe x coordinate of the public point
public_ythe y coordinate of the public point
curve_namethe name of the curve, typically "sm2p256v1"
Returns
0 on success, a negative value on failure

Definition at line 828 of file ffi_pkey_algs.cpp.

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

Load an SM2 public key from the SEC1 encoding of the public point

Parameters
keythe new object will be placed here
sec1the SEC1 compressed or uncompressed point encoding
sec1_lenlength of sec1 in bytes
curve_namethe name of the curve, typically "sm2p256v1"
Returns
0 on success, a negative value on failure

Definition at line 783 of file ffi_pkey_algs.cpp.

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

References Botan::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_FFI::ffi_new_object().

◆ botan_pubkey_load_x25519()

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

Load an X25519 public key from its raw 32 byte encoding

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
Returns
0 on success, a negative value on failure

Definition at line 1070 of file ffi_pkey_algs.cpp.

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

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

Load an X448 public key from its raw 56 byte encoding

Parameters
keythe new object will be placed here
Public Key Algorithmsthe raw public key
Returns
0 on success, a negative value on failure

Definition at line 1146 of file ffi_pkey_algs.cpp.

1146 {
1147#if defined(BOTAN_HAS_X448)
1148 if(any_null_pointers(key, pubkey)) {
1150 }
1151 *key = nullptr;
1152 return ffi_guard_thunk(__func__, [=]() -> int {
1153 auto x448 = std::make_unique<Botan::X448_PublicKey>(std::span{pubkey, 56});
1154 return ffi_new_object(key, std::move(x448));
1155 });
1156#else
1157 BOTAN_UNUSED(key, pubkey);
1159#endif
1160}

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

Get the object identifier associated with a public key

Parameters
oidthe new object will be placed here
keythe public key to query
Returns
0 on success, a negative value on failure

Definition at line 396 of file ffi_pkey.cpp.

396 {
397 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
398 if(oid == nullptr) {
400 }
401
402 auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
403 ffi_new_object(oid, std::move(oid_ptr));
404
405 return BOTAN_FFI_SUCCESS;
406 });
407}

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 )

Get the public exponent of an RSA public key

Parameters
eset to the value of the public exponent
rsa_keythe RSA public key
Returns
0 on success, a negative value on failure

Definition at line 327 of file ffi_pkey_algs.cpp.

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

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 )

Get the modulus of an RSA public key

Parameters
nset to the value of the modulus
rsa_keythe RSA public key
Returns
0 on success, a negative value on failure

Definition at line 331 of file ffi_pkey_algs.cpp.

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

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 )

Compute the SM2 ZA value, the hash of the user identity and public key which is prefixed to the message before signing

Parameters
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
identthe user identifier
hash_algothe hash to use, typically "SM3"
keythe SM2 public key
Returns
0 on success, a negative value on failure

Definition at line 726 of file ffi_pkey_algs.cpp.

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

References Botan::EC_PublicKey::_public_ec_point(), Botan::Asymmetric_Key::algo_name(), Botan::any_null_pointers(), 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 197 of file ffi_pkey.cpp.

197 {
198 return BOTAN_FFI_VISIT(
199 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.subject_public_key()); });
200}

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

1541 {
1542#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1543 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1544 if(auto ecc = dynamic_cast<const Botan::EC_PublicKey*>(&k)) {
1545 auto pt = ecc->_public_ec_point().serialize_uncompressed();
1546 return invoke_view_callback(view, ctx, pt);
1547 } else {
1549 }
1550 });
1551#else
1552 BOTAN_UNUSED(key, view, ctx);
1554#endif
1555}

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 )

View the raw encoding of a Kyber public key

Parameters
keythe Kyber public key
ctxan application context passed to the view function
viewthe view callback which receives the encoding
Returns
0 on success, a negative value on failure

Definition at line 1286 of file ffi_pkey_algs.cpp.

1286 {
1287#if defined(BOTAN_HAS_KYBER)
1288 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
1289 if(auto kyber = dynamic_cast<const Botan::Kyber_PublicKey*>(&k)) {
1290 return invoke_view_callback(view, ctx, kyber->public_key_bits());
1291 } else {
1293 }
1294 });
1295#else
1296 BOTAN_UNUSED(key, ctx, view);
1298#endif
1299}

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

202 {
203 return BOTAN_FFI_VISIT(
204 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::X509::PEM_encode(k)); });
205}
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 207 of file ffi_pkey.cpp.

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

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

Get the raw 32 byte encoding of an X25519 public key

Parameters
keythe X25519 public key
Public Key Algorithmsset to the raw public key
Returns
0 on success, a negative value on failure

Definition at line 1109 of file ffi_pkey_algs.cpp.

1109 {
1110 if(output == nullptr) {
1112 }
1113#if defined(BOTAN_HAS_X25519)
1114 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1115 if(auto x25519 = dynamic_cast<const Botan::X25519_PublicKey*>(&k)) {
1116 Botan::copy_mem(std::span{output, 32}, x25519->raw_public_key_bits());
1117 return BOTAN_FFI_SUCCESS;
1118 } else {
1120 }
1121 });
1122#else
1123 BOTAN_UNUSED(key, output);
1125#endif
1126}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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] )

Get the raw 56 byte encoding of an X448 public key

Parameters
keythe X448 public key
Public Key Algorithmsset to the raw public key
Returns
0 on success, a negative value on failure

Definition at line 1182 of file ffi_pkey_algs.cpp.

1182 {
1183 if(output == nullptr) {
1185 }
1186#if defined(BOTAN_HAS_X448)
1187 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
1188 if(auto x448 = dynamic_cast<const Botan::X448_PublicKey*>(&k)) {
1189 Botan::copy_mem(std::span{output, 56}, x448->raw_public_key_bits());
1190 return BOTAN_FFI_SUCCESS;
1191 } else {
1193 }
1194 });
1195#else
1196 BOTAN_UNUSED(key, output);
1198#endif
1199}
A public key for the X448 key agreement scheme according to RFC 7748.
Definition x448.h:24

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Derive a key from a passphrase

Parameters
algoPBKDF algorithm, e.g., "PBKDF2(SHA-256)" or "Scrypt"
param1the first PBKDF algorithm parameter
param2the second PBKDF algorithm parameter (may be zero if unneeded)
param3the third PBKDF algorithm parameter (may be zero if unneeded)
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
passphrase_lenif > 0, specifies length of password. If len == 0, then strlen will be called on passphrase to compute the length.
salta randomly chosen salt
salt_lenlength of salt in bytes
Returns
0 on success, a negative value on failure

Definition at line 54 of file ffi_kdf.cpp.

63 {
64 if(any_null_pointers(algo, password)) {
66 }
67 if(out_len > 0 && out == nullptr) {
69 }
70 if(salt_len > 0 && salt == nullptr) {
72 }
73
74 if(password_len == 0) {
75 password_len = std::strlen(password);
76 }
77
78 return ffi_guard_thunk(__func__, [=]() -> int {
79 auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
80
81 if(!pwdhash_fam) {
83 }
84
85 auto pwdhash = pwdhash_fam->from_params(param1, param2, param3);
86
87 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
88
89 return BOTAN_FFI_SUCCESS;
90 });
91}
static std::unique_ptr< PasswordHashFamily > create(std::string_view algo_spec, std::string_view provider="")
Definition pwdhash.cpp:58

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

Derive a key from a passphrase, choosing parameters to hit a target runtime

Parameters
algoPBKDF algorithm, e.g., "Scrypt" or "PBKDF2(SHA-256)"
msecthe desired runtime in milliseconds
param1will be set to the first password hash parameter
param2will be set to the second password hash parameter
param3will be set to the third password hash parameter
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
passphrase_lenif > 0, specifies length of password. If len == 0, then strlen will be called on passphrase to compute the length.
salta randomly chosen salt
salt_lenlength of salt in bytes
Returns
0 on success, a negative value on failure

Definition at line 93 of file ffi_kdf.cpp.

103 {
104 if(any_null_pointers(algo, password)) {
106 }
107 if(out_len > 0 && out == nullptr) {
109 }
110 if(salt_len > 0 && salt == nullptr) {
112 }
113
114 if(password_len == 0) {
115 password_len = std::strlen(password);
116 }
117
118 return ffi_guard_thunk(__func__, [=]() -> int {
119 auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
120
121 if(!pwdhash_fam) {
123 }
124
125 auto pwdhash = pwdhash_fam->tune_params(out_len, msec);
126
127 if(param1 != nullptr) {
128 *param1 = pwdhash->iterations();
129 }
130 if(param2 != nullptr) {
131 *param2 = pwdhash->parallelism();
132 }
133 if(param3 != nullptr) {
134 *param3 = pwdhash->memory_param();
135 }
136
137 pwdhash->derive_key(out, out_len, password, password_len, salt, salt_len);
138
139 return BOTAN_FFI_SUCCESS;
140 });
141}

References Botan_FFI::any_null_pointers(), 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
Random Number Generatorsrng object
Entropy Collectionthe data to add
entropy_lenlength of entropy buffer
Returns
0 on success, a negative value on failure

Definition at line 189 of file ffi_rng.cpp.

189 {
190 if(len > 0 && input == nullptr) {
192 }
193 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.add_entropy(input, len); });
194}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_rng_destroy()

int botan_rng_destroy ( botan_rng_t rng)

Frees all resources of the random number generator object

Parameters
Random Number Generatorsrng object
Returns
0 if success, error if invalid object handle

Definition at line 164 of file ffi_rng.cpp.

164 {
165 return BOTAN_FFI_CHECKED_DELETE(rng);
166}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_rng_generate_with_input()

int botan_rng_generate_with_input ( botan_rng_t rng,
uint8_t * out,
size_t out_len,
const uint8_t * addl_input,
size_t addl_len )

Generate random bytes from an RNG with additional input.

For a DRBG, the additional input is mixed in before generating. Many other RNG types (eg RDRAND or system RNG) will ignore the input.

Parameters
Random Number Generatorsthe RNG object
outoutput buffer
out_lennumber of bytes to generate
addl_inputadditional input to mix in (may be NULL if addl_len is 0)
addl_lenlength of additional input
Returns
0 on success, negative on failure

Definition at line 230 of file ffi_rng.cpp.

231 {
232 if(out_len > 0 && out == nullptr) {
234 }
235 if(addl_len > 0 && addl_input == nullptr) {
237 }
238 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.randomize_with_input({out, out_len}, {addl_input, addl_len}); });
239}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ 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
Random Number Generatorsrng object
outoutput buffer of size out_len
out_lennumber of requested bytes
Returns
0 on success, negative on failure

Definition at line 168 of file ffi_rng.cpp.

168 {
169 if(out_len > 0 && out == nullptr) {
171 }
172 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.randomize(out, out_len); });
173}

References BOTAN_FFI_ERROR_NULL_POINTER, and 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
Random Number Generatorsrng 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 38 of file ffi_rng.cpp.

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

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

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

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

◆ botan_rng_init_drbg()

int botan_rng_init_drbg ( botan_rng_t * rng_out,
const char * drbg_name,
const uint8_t * seed,
size_t seed_len )

Create and seed a DRBG

Parameters
rng_outthe new DRBG object
drbg_namethe name of the DRBG (e.g. "HMAC_DRBG(SHA-256)")
SEEDthe seed material (entropy || nonce || personalization_string)
seed_lenlength of seed in bytes
Returns
0 on success, negative on failure

Definition at line 200 of file ffi_rng.cpp.

200 {
201 return ffi_guard_thunk(__func__, [=]() -> int {
202 if(any_null_pointers(rng_out, drbg_name)) {
204 }
205 if(seed_len > 0 && seed == nullptr) {
207 }
208
209 std::unique_ptr<Botan::Stateful_RNG> drbg;
210 const std::string name(drbg_name);
211
212#if defined(BOTAN_HAS_HMAC_DRBG)
213 if(name.starts_with("HMAC_DRBG(") && name.ends_with(")") && name.size() > 12) {
214 const std::string hash = name.substr(10, name.size() - 11);
215 drbg = std::make_unique<Botan::HMAC_DRBG>(hash);
216 }
217#endif
218
219 if(!drbg) {
221 }
222
223 drbg->initialize_with(std::span(seed, seed_len));
224 // Upcast to RandomNumberGenerator for the FFI object
225 std::unique_ptr<Botan::RandomNumberGenerator> rng(std::move(drbg));
226 return ffi_new_object(rng_out, std::move(rng));
227 });
228}

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, 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
Random Number Generatorsrng object
bitsnumber of bits to reseed with
Returns
0 on success, a negative value on failure

Definition at line 185 of file ffi_rng.cpp.

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

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
Random Number Generatorsrng 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 196 of file ffi_rng.cpp.

196 {
197 return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.reseed_from_rng(safe_get(source_rng), bits); });
198}

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

336 {
337 return botan_constant_time_compare(x, y, len);
338}
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition ffi.cpp:327

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

340 {
341 if(bytes > 0 && mem == nullptr) {
343 }
344 Botan::secure_scrub_memory(mem, bytes);
345 return BOTAN_FFI_SUCCESS;
346}
void secure_scrub_memory(void *ptr, size_t n)
Definition mem_utils.cpp:25

References BOTAN_FFI_ERROR_NULL_POINTER, 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 166 of file ffi_kdf.cpp.

173 {
174 return botan_pwdhash("Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);
175}

References botan_pwdhash().

◆ botan_spake2p_derive_secret()

int botan_spake2p_derive_secret ( botan_spake2p_params_t params,
const char * password,
const uint8_t prover_id[],
size_t prover_id_len,
const uint8_t verifier_id[],
size_t verifier_id_len,
const uint8_t salt[],
size_t salt_len,
botan_view_ctx ctx,
botan_view_bin_fn view )

Derive a SPAKE2+ prover secret (w0 and w1) from a password, using Argon2id

The view callback is invoked with the serialized prover secret, which is password equivalent and must be protected accordingly. It is used with botan_spake2p_registration_record and botan_spake2p_prover_init.

Parameters
paramsthe SPAKE2+ system parameters
passwordthe (null terminated) password
prover_idthe identity of the prover
prover_id_lenlength of prover_id in bytes
verifier_idthe identity of the verifier
verifier_id_lenlength of verifier_id in bytes
salta salt value, ideally random and stored with the registration record
salt_lenlength of salt in bytes
ctxa context pointer passed to the view callback
viewa view callback which is invoked with the serialized prover secret

Definition at line 137 of file ffi_spake2p.cpp.

146 {
147 if(any_null_pointers(params, password)) {
149 }
150
151#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
152 return ffi_guard_thunk(__func__, [=]() -> int {
154 password,
155 spake2p_opt_span(prover_id, prover_id_len),
156 spake2p_opt_span(verifier_id, verifier_id_len),
157 spake2p_opt_span(salt, salt_len));
158 return invoke_view_callback(view, ctx, sec.serialize());
159 });
160#else
161 BOTAN_UNUSED(params, password, prover_id, prover_id_len, verifier_id, verifier_id_len);
162 BOTAN_UNUSED(salt, salt_len, ctx, view);
164#endif
165}
static ProverSecret from_password(const SystemParameters &params, std::string_view password, std::span< const uint8_t > prover_id, std::span< const uint8_t > verifier_id, std::span< const uint8_t > salt)
Definition spake2p.cpp:283

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan::SPAKE2p::ProverSecret::from_password(), Botan_FFI::invoke_view_callback(), and Botan_FFI::safe_get().

◆ botan_spake2p_params_confirmation_size()

int botan_spake2p_params_confirmation_size ( botan_spake2p_params_t params,
size_t * confirmation_size )

Return the size in bytes of a SPAKE2+ key confirmation message (confirmP or confirmV)

Parameters
paramsthe SPAKE2+ system parameters
confirmation_sizeoutput parameter for the key confirmation size

Definition at line 121 of file ffi_spake2p.cpp.

121 {
122 if(any_null_pointers(params, confirmation_size)) {
124 }
125
126#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
127 return BOTAN_FFI_VISIT(params, [=](const auto& p) -> int {
128 *confirmation_size = p.confirmation_size();
129 return BOTAN_FFI_SUCCESS;
130 });
131#else
132 BOTAN_UNUSED(params, confirmation_size);
134#endif
135}

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

◆ botan_spake2p_params_destroy()

int botan_spake2p_params_destroy ( botan_spake2p_params_t params)

Frees all resources of SPAKE2+ system parameters

Definition at line 102 of file ffi_spake2p.cpp.

102 {
103 return BOTAN_FFI_CHECKED_DELETE(params);
104}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_spake2p_params_init()

int botan_spake2p_params_init ( botan_spake2p_params_t * params,
const char * ciphersuite )

Create SPAKE2+ system parameters from an RFC 9383 ciphersuite name

Objects created from the system parameters hold their own copy, so the parameters may be destroyed at any time.

Parameters
paramsoutput parameter for the created system parameters
ciphersuitethe SPAKE2+ ciphersuite name

Definition at line 68 of file ffi_spake2p.cpp.

68 {
69 if(any_null_pointers(params, ciphersuite)) {
71 }
72
73#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
74 return ffi_guard_thunk(__func__, [=]() -> int {
75 *params = nullptr;
76 auto p = std::make_unique<Botan::SPAKE2p::SystemParameters>(spake2p_params_from_name(ciphersuite));
77 return ffi_new_object(params, std::move(p));
78 });
79#else
81#endif
82}

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

◆ botan_spake2p_params_init_custom()

int botan_spake2p_params_init_custom ( botan_spake2p_params_t * params,
botan_ec_group_t group,
const uint8_t seed[],
size_t seed_len,
const char * hash_fn )

Create custom SPAKE2+ system parameters for an arbitrary group

The M/N group elements are derived from the seed using hash to curve; returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED if the group does not support hash to curve. Both peers must use the same group, seed, and hash.

If the seed includes the identities of the participants, this additionally makes the scheme "quantum annoying", in that an attacker with a discrete logarithm oracle must compute a new discrete log for each (prover, verifier) pair they wish to attack.

Parameters
paramsoutput parameter for the created system parameters
groupthe elliptic curve group to use
SEEDthe seed bytes used to derive the M/N group elements
seed_lenlength of seed in bytes
hash_fnthe hash function to use (eg "SHA-256")

Definition at line 84 of file ffi_spake2p.cpp.

85 {
86 if(any_null_pointers(params, group, hash_fn)) {
88 }
89
90#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
91 return ffi_guard_thunk(__func__, [=]() -> int {
92 auto p = std::make_unique<Botan::SPAKE2p::SystemParameters>(
93 Botan::SPAKE2p::SystemParameters::custom(safe_get(group), spake2p_opt_span(seed, seed_len), hash_fn));
94 return ffi_new_object(params, std::move(p));
95 });
96#else
97 BOTAN_UNUSED(params, group, seed, seed_len, hash_fn);
99#endif
100}
static SystemParameters custom(const EC_Group &group, std::span< const uint8_t > seed, std::string_view hash_fn)
Definition spake2p.cpp:221

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan::SPAKE2p::SystemParameters::custom(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_spake2p_params_share_size()

int botan_spake2p_params_share_size ( botan_spake2p_params_t params,
size_t * share_size )

Return the size in bytes of a SPAKE2+ key share (shareP or shareV)

Parameters
paramsthe SPAKE2+ system parameters
share_sizeoutput parameter for the key share size

Definition at line 106 of file ffi_spake2p.cpp.

106 {
107#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
108 return BOTAN_FFI_VISIT(params, [=](const auto& p) -> int {
109 if(share_size == nullptr) {
111 }
112 *share_size = p.share_size();
113 return BOTAN_FFI_SUCCESS;
114 });
115#else
116 BOTAN_UNUSED(params, share_size);
118#endif
119}

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

◆ botan_spake2p_prover_destroy()

int botan_spake2p_prover_destroy ( botan_spake2p_prover_t prover)

Frees all resources of a SPAKE2+ prover

Definition at line 221 of file ffi_spake2p.cpp.

221 {
222 return BOTAN_FFI_CHECKED_DELETE(prover);
223}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_spake2p_prover_generate_message()

int botan_spake2p_prover_generate_message ( botan_spake2p_prover_t prover,
botan_rng_t rng,
botan_view_ctx ctx,
botan_view_bin_fn view )

Generate the prover's key share (shareP), which is sent to the verifier

This can be called only once per prover object.

Parameters
proverthe prover object
Random Number Generatorsa random number generator
ctxa context pointer passed to the view callback
viewa view callback which is invoked with the key share

Definition at line 225 of file ffi_spake2p.cpp.

228 {
229#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
230 return BOTAN_FFI_VISIT(
231 prover, [=](auto& p) -> int { return invoke_view_callback(view, ctx, p.generate_message(safe_get(rng))); });
232#else
233 BOTAN_UNUSED(prover, rng, ctx, view);
235#endif
236}

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

◆ botan_spake2p_prover_init()

int botan_spake2p_prover_init ( botan_spake2p_prover_t * prover,
botan_spake2p_params_t params,
const uint8_t secret[],
size_t secret_len,
const uint8_t prover_id[],
size_t prover_id_len,
const uint8_t verifier_id[],
size_t verifier_id_len,
const uint8_t context[],
size_t context_len )

Initialize a SPAKE2+ prover

The identities and context must be agreed upon by both parties; the identities must additionally match the values used when deriving the prover secret.

Parameters
proveroutput parameter for the created prover object
paramsthe SPAKE2+ system parameters
secretthe serialized prover secret
secret_lenlength of secret in bytes
prover_idthe identity of the prover
prover_id_lenlength of prover_id in bytes
verifier_idthe identity of the verifier
verifier_id_lenlength of verifier_id in bytes
contextan application specific context string
context_lenlength of context in bytes

Definition at line 188 of file ffi_spake2p.cpp.

197 {
198#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
199 if(any_null_pointers(prover, params, secret)) {
201 }
202
203 return ffi_guard_thunk(__func__, [=]() -> int {
204 *prover = nullptr;
205 const auto& p = safe_get(params);
206 const auto sec = Botan::SPAKE2p::ProverSecret::deserialize(p, {secret, secret_len});
207 auto ctx = std::make_unique<Botan::SPAKE2p::ProverContext>(p,
208 sec,
209 spake2p_opt_span(prover_id, prover_id_len),
210 spake2p_opt_span(verifier_id, verifier_id_len),
211 spake2p_opt_span(context, context_len));
212 return ffi_new_object(prover, std::move(ctx));
213 });
214#else
215 BOTAN_UNUSED(prover, params, secret, secret_len, prover_id, prover_id_len);
216 BOTAN_UNUSED(verifier_id, verifier_id_len, context, context_len);
218#endif
219}
static ProverSecret deserialize(const SystemParameters &params, std::span< const uint8_t > secret)
Definition spake2p.cpp:296

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan::SPAKE2p::ProverSecret::deserialize(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_spake2p_prover_process_message()

int botan_spake2p_prover_process_message ( botan_spake2p_prover_t prover,
botan_rng_t rng,
const uint8_t peer_message[],
size_t peer_message_len,
botan_view_ctx ctx,
botan_view_bin_fn view )

Consume the verifier's response (shareV followed by confirmV) and produce the prover's key confirmation (confirmP), which is sent to the verifier.

Returns BOTAN_FFI_ERROR_BAD_MAC if the verifier's key confirmation is wrong, typically meaning the passwords do not match.

Parameters
proverthe prover object
Random Number Generatorsa random number generator
peer_messagethe verifier's response
peer_message_lenlength of peer_message in bytes
ctxa context pointer passed to the view callback
viewa view callback which is invoked with the prover's key confirmation

Definition at line 238 of file ffi_spake2p.cpp.

243 {
244 if(any_null_pointers(peer_message)) {
246 }
247#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
248 return BOTAN_FFI_VISIT(prover, [=](auto& p) -> int {
249 return invoke_view_callback(view, ctx, p.process_message({peer_message, peer_message_len}, safe_get(rng)));
250 });
251#else
252 BOTAN_UNUSED(prover, rng, peer_message, peer_message_len, ctx, view);
254#endif
255}

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

◆ botan_spake2p_prover_shared_secret()

int botan_spake2p_prover_shared_secret ( botan_spake2p_prover_t prover,
botan_view_ctx ctx,
botan_view_bin_fn view )

Return the prover's shared secret (K_shared)

This may be called only after botan_spake2p_prover_process_message has succeeded.

Parameters
proverthe prover object
ctxa context pointer passed to the view callback
viewa view callback which is invoked with the shared secret

Definition at line 257 of file ffi_spake2p.cpp.

257 {
258#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
259 return BOTAN_FFI_VISIT(prover, [=](auto& p) -> int { return invoke_view_callback(view, ctx, p.shared_secret()); });
260#else
261 BOTAN_UNUSED(prover, ctx, view);
263#endif
264}

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

◆ botan_spake2p_registration_record()

int botan_spake2p_registration_record ( botan_spake2p_params_t params,
botan_rng_t rng,
const uint8_t secret[],
size_t secret_len,
botan_view_ctx ctx,
botan_view_bin_fn view )

Compute a SPAKE2+ registration record (w0 and L) from a prover secret

The registration record is provided to the verifier during registration. While it does not allow directly impersonating the prover, it does allow offline password guessing attacks, so it should be protected.

Parameters
paramsthe SPAKE2+ system parameters
Random Number Generatorsa random number generator
secretthe serialized prover secret
secret_lenlength of secret in bytes
ctxa context pointer passed to the view callback
viewa view callback which is invoked with the serialized registration record

Definition at line 167 of file ffi_spake2p.cpp.

172 {
173#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
174 if(any_null_pointers(params, rng, secret)) {
176 }
177
178 return ffi_guard_thunk(__func__, [=]() -> int {
179 const auto sec = Botan::SPAKE2p::ProverSecret::deserialize(safe_get(params), {secret, secret_len});
180 return invoke_view_callback(view, ctx, sec.registration_record(safe_get(rng)).serialize());
181 });
182#else
183 BOTAN_UNUSED(params, rng, secret, secret_len, ctx, view);
185#endif
186}

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan::SPAKE2p::ProverSecret::deserialize(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::invoke_view_callback(), and Botan_FFI::safe_get().

◆ botan_spake2p_verifier_destroy()

int botan_spake2p_verifier_destroy ( botan_spake2p_verifier_t verifier)

Frees all resources of a SPAKE2+ verifier

Definition at line 299 of file ffi_spake2p.cpp.

299 {
300 return BOTAN_FFI_CHECKED_DELETE(verifier);
301}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_spake2p_verifier_init()

int botan_spake2p_verifier_init ( botan_spake2p_verifier_t * verifier,
botan_spake2p_params_t params,
const uint8_t record[],
size_t record_len,
const uint8_t prover_id[],
size_t prover_id_len,
const uint8_t verifier_id[],
size_t verifier_id_len,
const uint8_t context[],
size_t context_len )

Initialize a SPAKE2+ verifier

The identities and context must be agreed upon by both parties; the identities must additionally match the values used when deriving the prover secret.

Parameters
verifieroutput parameter for the created verifier object
paramsthe SPAKE2+ system parameters
recordthe serialized registration record
record_lenlength of record in bytes
prover_idthe identity of the prover
prover_id_lenlength of prover_id in bytes
verifier_idthe identity of the verifier
verifier_id_lenlength of verifier_id in bytes
contextan application specific context string
context_lenlength of context in bytes

Definition at line 266 of file ffi_spake2p.cpp.

275 {
276 if(any_null_pointers(verifier, record)) {
278 }
279
280#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
281 return ffi_guard_thunk(__func__, [=]() -> int {
282 *verifier = nullptr;
283 const auto& p = safe_get(params);
284 const auto rec = Botan::SPAKE2p::RegistrationRecord::deserialize(p, {record, record_len});
285 auto ctx = std::make_unique<Botan::SPAKE2p::VerifierContext>(p,
286 rec,
287 spake2p_opt_span(prover_id, prover_id_len),
288 spake2p_opt_span(verifier_id, verifier_id_len),
289 spake2p_opt_span(context, context_len));
290 return ffi_new_object(verifier, std::move(ctx));
291 });
292#else
293 BOTAN_UNUSED(verifier, params, record, record_len, prover_id, prover_id_len);
294 BOTAN_UNUSED(verifier_id, verifier_id_len, context, context_len);
296#endif
297}
static RegistrationRecord deserialize(const SystemParameters &params, std::span< const uint8_t > record)
Definition spake2p.cpp:261

References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan::SPAKE2p::RegistrationRecord::deserialize(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_spake2p_verifier_process_message()

int botan_spake2p_verifier_process_message ( botan_spake2p_verifier_t verifier,
botan_rng_t rng,
const uint8_t peer_message[],
size_t peer_message_len,
botan_view_ctx ctx,
botan_view_bin_fn view )

Consume the prover's key share (shareP) and produce the verifier's response (shareV followed by confirmV), which is sent to the prover.

This can be called only once per verifier object.

Parameters
verifierthe verifier object
Random Number Generatorsa random number generator
peer_messagethe prover's key share
peer_message_lenlength of peer_message in bytes
ctxa context pointer passed to the view callback
viewa view callback which is invoked with the verifier's response

Definition at line 303 of file ffi_spake2p.cpp.

308 {
309 if(any_null_pointers(peer_message)) {
311 }
312
313#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
314 return BOTAN_FFI_VISIT(verifier, [=](auto& v) -> int {
315 return invoke_view_callback(view, ctx, v.process_message({peer_message, peer_message_len}, safe_get(rng)));
316 });
317#else
318 BOTAN_UNUSED(verifier, rng, peer_message, peer_message_len, ctx, view);
320#endif
321}

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

◆ botan_spake2p_verifier_shared_secret()

int botan_spake2p_verifier_shared_secret ( botan_spake2p_verifier_t verifier,
botan_view_ctx ctx,
botan_view_bin_fn view )

Return the verifier's shared secret (K_shared)

This may be called only after botan_spake2p_verifier_verify_confirmation has succeeded, or after botan_spake2p_verifier_skip_confirmation.

Parameters
verifierthe verifier object
ctxa context pointer passed to the view callback
viewa view callback which is invoked with the shared secret

Definition at line 353 of file ffi_spake2p.cpp.

355 {
356#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
357 return BOTAN_FFI_VISIT(verifier, [=](auto& v) -> int { return invoke_view_callback(view, ctx, v.shared_secret()); });
358#else
359 BOTAN_UNUSED(verifier, ctx, view);
361#endif
362}

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

◆ botan_spake2p_verifier_skip_confirmation()

int botan_spake2p_verifier_skip_confirmation ( botan_spake2p_verifier_t verifier)

Skip checking the prover's key confirmation (confirmP)

This can be called after botan_spake2p_verifier_process_message, in place of botan_spake2p_verifier_verify_confirmation, to allow extracting the shared secret without having checked the prover's key confirmation.

Warning: after calling this, nothing is known about the peer; only a prover which knows the password can compute the same shared secret, but no evidence of this has been received. It is intended solely for protocols which embed SPAKE2+ and perform the prover's key confirmation themselves, for example the proposed TLS PAKE extension, where the TLS handshake takes the place of confirmP. Anywhere else, use botan_spake2p_verifier_verify_confirmation.

Parameters
verifierthe verifier object

Definition at line 341 of file ffi_spake2p.cpp.

341 {
342#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
343 return BOTAN_FFI_VISIT(verifier, [](auto& v) -> int {
344 v.skip_confirmation();
345 return BOTAN_FFI_SUCCESS;
346 });
347#else
348 BOTAN_UNUSED(verifier);
350#endif
351}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_spake2p_verifier_verify_confirmation()

int botan_spake2p_verifier_verify_confirmation ( botan_spake2p_verifier_t verifier,
const uint8_t confirmation[],
size_t confirmation_len )

Check the prover's key confirmation (confirmP)

Returns BOTAN_FFI_ERROR_BAD_MAC if the confirmation is wrong, meaning the prover does not know the password.

Parameters
verifierthe verifier object
confirmationthe prover's key confirmation
confirmation_lenlength of confirmation in bytes

Definition at line 323 of file ffi_spake2p.cpp.

325 {
326 if(confirmation == nullptr) {
328 }
329
330#if defined(BOTAN_HAS_PAKE_SPAKE2PLUS)
331 return BOTAN_FFI_VISIT(verifier, [=](auto& v) -> int {
332 v.verify_confirmation({confirmation, confirmation_len});
333 return BOTAN_FFI_SUCCESS;
334 });
335#else
336 BOTAN_UNUSED(verifier, confirmation, confirmation_len);
338#endif
339}

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

◆ 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 Function Identificationspecifies 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 153 of file ffi_srp6.cpp.

165 {
166#if defined(BOTAN_HAS_SRP6)
167 return ffi_guard_thunk(__func__, [=]() -> int {
168 if(any_null_pointers(identity, password, salt, group_id, hash_id, b, rng_obj)) {
170 }
171 try {
172 const std::vector<uint8_t> saltv(salt, salt + salt_len);
174 auto b_bn = Botan::BigInt::from_bytes({b, b_len});
175 const auto group = Botan::DL_Group::from_name(group_id);
176 const size_t a_bits = group.exponent_bits();
177 auto [A_bn, K_sk] = Botan::srp6_client_agree(identity, password, group, hash_id, saltv, b_bn, a_bits, rng);
178 auto ret_a = write_vec_output(A, A_len, A_bn.serialize(group.p_bytes()));
179 auto ret_k = write_vec_output(K, K_len, K_sk.bits_of());
180 if(ret_a != BOTAN_FFI_SUCCESS) {
181 return ret_a;
182 }
183 if(ret_k != BOTAN_FFI_SUCCESS) {
184 return ret_k;
185 }
186 return BOTAN_FFI_SUCCESS;
187 } catch(Botan::Lookup_Error&) {
189 }
190 });
191#else
192 BOTAN_UNUSED(identity, password, group_id, hash_id, rng_obj);
193 BOTAN_UNUSED(salt, salt_len, b, b_len, A, A_len, K, K_len);
195#endif
196}
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:266
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 Function Identificationspecifies 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 123 of file ffi_srp6.cpp.

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

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

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

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
SRP-6aSRP-6 server session object
Returns
0 if success, error if invalid object handle

Definition at line 45 of file ffi_srp6.cpp.

45 {
46 return BOTAN_FFI_CHECKED_DELETE(srp6);
47}

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
SRP-6aSRP-6 server session object

Definition at line 32 of file ffi_srp6.cpp.

32 {
33#if defined(BOTAN_HAS_SRP6)
34 if(srp6 == nullptr) {
36 }
37 return ffi_guard_thunk(
38 __func__, [=]() -> int { return ffi_new_object(srp6, std::make_unique<Botan::SRP6_Server_Session>()); });
39#else
40 BOTAN_UNUSED(srp6);
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_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
SRP-6aSRP-6 server session object
verifierthe verification value saved from client registration
verifier_lenSRP-6 verifier value length
group_idthe SRP group id
Hash Function Identificationthe 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(), and botan_srp6_server_session_step2().

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
SRP-6aSRP-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 102 of file ffi_srp6.cpp.

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

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

175 {
176 if(out_len > 0 && out == nullptr) {
178 }
179 return ffi_guard_thunk(__func__, [=]() -> int {
180 Botan::system_rng().randomize(out, out_len);
181 return BOTAN_FFI_SUCCESS;
182 });
183}
void randomize(std::span< uint8_t > output)
Definition rng.h:86

References BOTAN_FFI_ERROR_NULL_POINTER, 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(any_null_pointers(totp, totp_code)) {
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::any_null_pointers(), 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(any_null_pointers(totp, key, hash_algo)) {
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::any_null_pointers(), 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
Random Number Generatorsrandom 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(any_null_pointers(ctx_out, esys_ctx)) {
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::any_null_pointers(), 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
Random Number Generatorsrandom 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(any_null_pointers(cbs_out, esys_ctx)) {
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::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(), 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 323 of file ffi.cpp.

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

311 {
312 return Botan::version_major();
313}
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 315 of file ffi.cpp.

315 {
316 return Botan::version_minor();
317}
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 319 of file ffi.cpp.

319 {
320 return Botan::version_patch();
321}
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 307 of file ffi.cpp.

307 {
308 return Botan::version_cstr();
309}
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 574 of file ffi_cert.cpp.

574 {
575#if defined(BOTAN_HAS_X509_CERTIFICATES)
576 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int { return c.has_ex_constraint(safe_get(oid)) ? 1 : 0; });
577#else
578 BOTAN_UNUSED(cert, oid);
580#endif
581}

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

559 {
560#if defined(BOTAN_HAS_X509_CERTIFICATES)
561 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
562 if(Botan::any_null_pointers(oid)) {
564 }
565
566 return c.has_ex_constraint(oid) ? 1 : 0;
567 });
568#else
569 BOTAN_UNUSED(cert, oid);
571#endif
572}

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 )

Check if the certificate allows the specified key usage. If no key usage extension is found in the certificate, this always returns success.

Parameters
certthe certificate to inspect
key_usageone or more values from botan_x509_cert_key_constraints, ORed together
Returns
0 if the usage is allowed, 1 if it is not, negative on error

Definition at line 544 of file ffi_cert.cpp.

544 {
545#if defined(BOTAN_HAS_X509_CERTIFICATES)
546 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
547 const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
548 if(c.allowed_usage(k)) {
549 return BOTAN_FFI_SUCCESS;
550 }
551 return 1;
552 });
553#else
554 BOTAN_UNUSED(cert, key_usage);
556#endif
557}

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)

Frees all resources of the certificate object

Parameters
certthe certificate to destroy
Returns
0 if success, error if invalid object handle

Definition at line 583 of file ffi_cert.cpp.

583 {
584#if defined(BOTAN_HAS_X509_CERTIFICATES)
585 return BOTAN_FFI_CHECKED_DELETE(cert);
586#else
587 BOTAN_UNUSED(cert);
589#endif
590}

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 )

Create a new handle referring to the same certificate

Parameters
new_certthe new object will be placed here
certthe certificate to duplicate
Returns
0 on success, a negative value on failure

Definition at line 193 of file ffi_cert.cpp.

193 {
194 if(cert_obj == nullptr) {
196 }
197
198#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
199
200 return ffi_guard_thunk(__func__, [=]() -> int {
201 auto c = std::make_unique<Botan::X509_Certificate>(safe_get(cert));
202 return ffi_new_object(cert_obj, std::move(c));
203 });
204
205#else
206 BOTAN_UNUSED(cert);
208#endif
209}

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

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

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 )

Count the "excluded" name constraints of a given cert.

Parameters
certthe certificate to inspect
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 845 of file ffi_cert.cpp.

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

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 )

Get the key identifier from the authority key identifier extension

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 677 of file ffi_cert.cpp.

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

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 )

Compute the fingerprint of the certificate, formatted as a hex string with colons between the bytes

Parameters
certthe certificate to inspect
Hashesthe name of the hash to use, eg "SHA-256"
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

TODO(Botan4) this should use char for the out param

Definition at line 661 of file ffi_cert.cpp.

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 457 of file ffi_cert.cpp.

458 {
459 if(key == nullptr) {
461 }
462#if defined(BOTAN_HAS_X509_CERTIFICATES)
463 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
464 auto issuer_info = c.issuer_info(key);
465 if(index < issuer_info.size()) {
466 // TODO(Botan4) change the type of out and remove this cast
467 return write_str_output(reinterpret_cast<char*>(out), out_len, c.issuer_info(key).at(index));
468 } else {
469 return BOTAN_FFI_ERROR_BAD_PARAMETER; // TODO(Botan4): use BOTAN_FFI_ERROR_OUT_OF_RANGE
470 }
471 });
472#else
473 BOTAN_UNUSED(cert, key, index, out, out_len);
475#endif
476}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Count the names of the given key present in the issuer DN.

Parameters
certthe certificate to inspect
keythe DN component to count, eg "Name"
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 478 of file ffi_cert.cpp.

478 {
479#if defined(BOTAN_HAS_X509_CERTIFICATES)
480 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
481 if(Botan::any_null_pointers(key, count)) {
483 }
484
485 *count = c.issuer_info(key).size();
486 return BOTAN_FFI_SUCCESS;
487 });
488#else
489 BOTAN_UNUSED(cert, key, count);
491#endif
492}

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

419 {
420#if defined(BOTAN_HAS_X509_CERTIFICATES)
421 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
422 if(Botan::any_null_pointers(path_limit)) {
424 }
425
426 if(const auto path_len = c.path_length_constraint()) {
427 *path_limit = path_len.value();
428 return BOTAN_FFI_SUCCESS;
429 } else {
431 }
432 });
433#else
434 BOTAN_UNUSED(cert, path_limit);
436#endif
437}

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 )

Get the public key of the certificate

Parameters
certthe certificate to inspect
keythe new object will be placed here
Returns
0 on success, a negative value on failure

Definition at line 439 of file ffi_cert.cpp.

439 {
440 if(key == nullptr) {
442 }
443
444 *key = nullptr;
445
446#if defined(BOTAN_HAS_X509_CERTIFICATES)
447 return ffi_guard_thunk(__func__, [=]() -> int {
448 auto public_key = safe_get(cert).subject_public_key();
449 return ffi_new_object(key, std::move(public_key));
450 });
451#else
452 BOTAN_UNUSED(cert);
454#endif
455}

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 )

Get the DER encoded SubjectPublicKeyInfo of the certificate

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 695 of file ffi_cert.cpp.

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

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 )

Get the serial number of the certificate as a big-endian binary string

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 636 of file ffi_cert.cpp.

636 {
637#if defined(BOTAN_HAS_X509_CERTIFICATES)
638 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.serial_number()); });
639#else
640 BOTAN_UNUSED(cert, out, out_len);
642#endif
643}

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

495 {
496 if(key == nullptr) {
498 }
499#if defined(BOTAN_HAS_X509_CERTIFICATES)
500 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
501 auto subject_info = c.subject_info(key);
502 if(index < subject_info.size()) {
503 // TODO(Botan4) change the type of out and remove this cast
504 return write_str_output(reinterpret_cast<char*>(out), out_len, c.subject_info(key).at(index));
505 } else {
506 return BOTAN_FFI_ERROR_BAD_PARAMETER; // TODO(Botan4): use BOTAN_FFI_ERROR_OUT_OF_RANGE
507 }
508 });
509#else
510 BOTAN_UNUSED(cert, key, index, out, out_len);
512#endif
513}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Count the names of the given key present in the subject DN.

Parameters
certthe certificate to inspect
keythe DN component to count, eg "Name"
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 515 of file ffi_cert.cpp.

515 {
516#if defined(BOTAN_HAS_X509_CERTIFICATES)
517 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
518 if(Botan::any_null_pointers(key, count)) {
520 }
521
522 *count = c.subject_info(key).size();
523 return BOTAN_FFI_SUCCESS;
524 });
525#else
526 BOTAN_UNUSED(cert, key, count);
528#endif
529}

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 )

Get the subject key identifier extension

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 686 of file ffi_cert.cpp.

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

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 )

Get the end of the validity period as a string

Prefer botan_x509_cert_not_after

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

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

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

Get the start of the validity period as a string

Prefer botan_x509_cert_not_before

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 592 of file ffi_cert.cpp.

592 {
593#if defined(BOTAN_HAS_X509_CERTIFICATES)
594 return BOTAN_FFI_VISIT(cert,
595 [=](const auto& c) { return write_str_output(out, out_len, c.not_before().to_string()); });
596#else
597 BOTAN_UNUSED(cert, out, out_len);
599#endif
600}

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

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

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

410 {
411#if defined(BOTAN_HAS_X509_CERTIFICATES)
412 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return c.is_CA_cert() ? 1 : 0; });
413#else
414 BOTAN_UNUSED(cert);
416#endif
417}

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

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

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 )

Count the "issuer alternative names" of a given cert.

Parameters
certthe certificate to inspect
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 922 of file ffi_cert.cpp.

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

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 )

Load a certificate from a DER or PEM encoding

Parameters
cert_objthe new object will be placed here
certthe encoding to load
cert_lenlength of cert in bytes
Returns
0 on success, a negative value on failure

Definition at line 211 of file ffi_cert.cpp.

211 {
212 if(Botan::any_null_pointers(cert_obj, cert_bits)) {
214 }
215
216#if defined(BOTAN_HAS_X509_CERTIFICATES)
217 return ffi_guard_thunk(__func__, [=]() -> int {
218 Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
219 auto c = std::make_unique<Botan::X509_Certificate>(bits);
220 return ffi_new_object(cert_obj, std::move(c));
221 });
222#else
223 BOTAN_UNUSED(cert_bits_len);
225#endif
226}

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

Load a certificate from a file containing a DER or PEM encoding

Parameters
cert_objthe new object will be placed here
filenamepath of the file to read
Returns
0 on success, a negative value on failure

Definition at line 176 of file ffi_cert.cpp.

176 {
177 if(Botan::any_null_pointers(cert_obj, cert_path)) {
179 }
180
181#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
182
183 return ffi_guard_thunk(__func__, [=]() -> int {
184 auto c = std::make_unique<Botan::X509_Certificate>(cert_path);
185 return ffi_new_object(cert_obj, std::move(c));
186 });
187
188#else
190#endif
191}

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

Get the end of the validity period as seconds since the Unix epoch

Parameters
certthe certificate to inspect
time_since_epochset to the notAfter time
Returns
0 on success, a negative value on failure

Definition at line 624 of file ffi_cert.cpp.

624 {
625 if(time_since_epoch == nullptr) {
627 }
628#if defined(BOTAN_HAS_X509_CERTIFICATES)
629 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_after().time_since_epoch(); });
630#else
631 BOTAN_UNUSED(cert, time_since_epoch);
633#endif
634}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

Get the start of the validity period as seconds since the Unix epoch

Parameters
certthe certificate to inspect
time_since_epochset to the notBefore time
Returns
0 on success, a negative value on failure

Definition at line 612 of file ffi_cert.cpp.

612 {
613 if(time_since_epoch == nullptr) {
615 }
616#if defined(BOTAN_HAS_X509_CERTIFICATES)
617 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_before().time_since_epoch(); });
618#else
619 BOTAN_UNUSED(cert, time_since_epoch);
621#endif
622}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 788 of file ffi_cert.cpp.

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

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 )

Count the "permitted" name constraints of a given cert.

Parameters
certthe certificate to inspect
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 810 of file ffi_cert.cpp.

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

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 )

Get the serial number of the certificate as an integer

Parameters
certthe certificate to inspect
serial_numberthe new object will be placed here
Returns
0 on success, a negative value on failure

Definition at line 645 of file ffi_cert.cpp.

645 {
646#if defined(BOTAN_HAS_X509_CERTIFICATES)
647 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
648 if(Botan::any_null_pointers(serial_number)) {
650 }
651
652 auto serial_bn = c.serial().to_bigint();
653 return ffi_new_object(serial_number, std::make_unique<Botan::BigInt>(std::move(serial_bn)));
654 });
655#else
656 BOTAN_UNUSED(cert, serial_number);
658#endif
659}
const X509_Serial_Number & serial() const
Definition x509cert.cpp:444

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::X509_Certificate::serial(), and Botan::X509_Serial_Number::to_bigint().

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

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

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 )

Count the "subject alternative names" of a given cert.

Parameters
certthe certificate to inspect
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 883 of file ffi_cert.cpp.

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

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 )

Format the certificate as a human readable string

Parameters
certthe certificate to format
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 531 of file ffi_cert.cpp.

531 {
532 return copy_view_str(reinterpret_cast<uint8_t*>(out), out_len, botan_x509_cert_view_as_string, cert);
533}
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:535

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

1023 {
1024 if(code < 0) {
1025 return nullptr;
1026 }
1027
1028#if defined(BOTAN_HAS_X509_CERTIFICATES)
1030 return Botan::to_string(sc);
1031#else
1032 return nullptr;
1033#endif
1034}
Certificate_Status_Code
Definition pkix_enums.h:21
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 949 of file ffi_cert.cpp.

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 1433 of file ffi_cert.cpp.

1444 {
1445 if(required_strength == 0) {
1446 required_strength = 110;
1447 }
1448
1449#if defined(BOTAN_HAS_X509_CERTIFICATES)
1450 return ffi_guard_thunk(__func__, [=]() -> int {
1451 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
1453 const auto validation_time = reference_time == 0
1454 ? std::chrono::system_clock::now()
1455 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
1456
1457 if(intermediates_len > 0 && intermediates == nullptr) {
1459 }
1460 if(trusted_len > 0 && trusted == nullptr) {
1462 }
1463 if(crls_len > 0 && crls == nullptr) {
1465 }
1466
1467 std::vector<Botan::X509_Certificate> end_certs;
1468 end_certs.push_back(safe_get(cert));
1469 for(size_t i = 0; i != intermediates_len; ++i) {
1470 end_certs.push_back(safe_get(intermediates[i]));
1471 }
1472
1473 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
1474 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
1475 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_crls;
1476 std::vector<Botan::Certificate_Store*> trusted_roots;
1477
1478 if(trusted_path != nullptr && *trusted_path != 0) {
1479 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
1480 trusted_roots.push_back(trusted_from_path.get());
1481 }
1482
1483 if(trusted_len > 0) {
1484 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
1485 for(size_t i = 0; i != trusted_len; ++i) {
1486 trusted_extra->add_certificate(safe_get(trusted[i]));
1487 }
1488 trusted_roots.push_back(trusted_extra.get());
1489 }
1490
1491 if(crls_len > 0) {
1492 trusted_crls = std::make_unique<Botan::Certificate_Store_In_Memory>();
1493 for(size_t i = 0; i != crls_len; ++i) {
1494 trusted_crls->add_crl(safe_get(crls[i]));
1495 }
1496 trusted_roots.push_back(trusted_crls.get());
1497 }
1498
1499 const Botan::Path_Validation_Restrictions restrictions(false, required_strength);
1500
1501 auto validation_result =
1502 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
1503
1504 if(result_code != nullptr) {
1505 *result_code = static_cast<int>(validation_result.result());
1506 }
1507
1508 if(validation_result.successful_validation()) {
1509 return 0;
1510 } else {
1511 return 1;
1512 }
1513 });
1514#else
1515 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
1516 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time, crls, crls_len);
1518#endif
1519}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, 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 )

View the certificate formatted as a human readable string

Parameters
certthe certificate to format
ctxan application context passed to the view function
viewthe view callback which receives the string
Returns
0 on success, a negative value on failure

Definition at line 535 of file ffi_cert.cpp.

535 {
536#if defined(BOTAN_HAS_X509_CERTIFICATES)
537 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return invoke_view_callback(view, ctx, c.to_string()); });
538#else
539 BOTAN_UNUSED(cert, ctx, view);
541#endif
542}

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

289 {
290#if defined(BOTAN_HAS_X509_CERTIFICATES)
291 if(index != 0) {
292 // As of now there are no multi-value binary entries.
294 }
295
296 auto view = [=](std::span<const uint8_t> value) -> int {
297 if(value.empty()) {
299 } else {
300 return invoke_view_callback(view_fn, ctx, value);
301 }
302 };
303
304 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) -> int {
305 switch(value_type) {
307 return view(c.serial_number());
309 return view(c.raw_subject_dn());
311 return view(c.raw_issuer_dn());
313 return view(c.subject_key_id());
315 return view(c.authority_key_id());
317 return view(c.subject_public_key_info());
318
323 return botan_x509_object_view_value(c, value_type, index, ctx, view_fn);
324
330 }
331
333 });
334#else
335 BOTAN_UNUSED(cert, value_type, index, ctx, view_fn);
337#endif
338}
const std::vector< uint8_t > & serial_number() const
Definition x509cert.cpp:440
const std::vector< uint8_t > & authority_key_id() const
Definition x509cert.cpp:432
const std::vector< uint8_t > & raw_subject_dn() const
Definition x509cert.cpp:468
const std::vector< uint8_t > & subject_key_id() const
Definition x509cert.cpp:436
const std::vector< uint8_t > & raw_issuer_dn() const
Definition x509cert.cpp:464
const std::vector< uint8_t > & subject_public_key_info() const
Definition x509cert.cpp:412

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 )

Count the binary values of the given type available in an X.509 certificate.

Parameters
certthe certificate to inspect
value_typethe value type to count
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 340 of file ffi_cert.cpp.

340 {
341#if defined(BOTAN_HAS_X509_CERTIFICATES)
342 return enumerator_count_values(count, [=](size_t index) {
344 cert, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
345 });
346#else
347 BOTAN_UNUSED(cert, value_type, count);
349#endif
350}
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:285

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 )

View the DER encoded SubjectPublicKeyInfo of the certificate

Parameters
certthe certificate to inspect
ctxan application context passed to the view function
viewthe view callback which receives the encoding
Returns
0 on success, a negative value on failure

Definition at line 699 of file ffi_cert.cpp.

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

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

356 {
357#if defined(BOTAN_HAS_X509_CERTIFICATES)
358 auto enumerate_uris = [view_fn, ctx](const std::vector<Botan::URI>& values, size_t idx) -> int {
359 if(idx >= values.size()) {
361 } else {
362 return invoke_view_callback(view_fn, ctx, values[idx].original_input());
363 }
364 };
365
366 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) -> int {
367 switch(value_type) {
369 return enumerate_uris(c.crl_distribution_point_uris(), index);
371 return enumerate_uris(c.ocsp_responder_uris(), index);
373 return enumerate_uris(c.ca_issuer_uris(), index);
375 return botan_x509_object_view_value(c, value_type, index, ctx, view_fn);
376
388 }
389
391 });
392#else
393 BOTAN_UNUSED(cert, value_type, index, ctx, view_fn);
395#endif
396}
const std::vector< URI > & ocsp_responder_uris() const
Definition x509cert.cpp:641
const std::vector< URI > & crl_distribution_point_uris() const
Definition x509cert.cpp:657
const std::vector< URI > & ca_issuer_uris() const
Definition x509cert.cpp:649

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::X509_Certificate::ca_issuer_uris(), Botan::X509_Certificate::crl_distribution_point_uris(), Botan_FFI::invoke_view_callback(), and Botan::X509_Certificate::ocsp_responder_uris().

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 )

Count the string values of the given type available in an X.509 certificate.

Parameters
certthe certificate to inspect
value_typethe value type to count
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 398 of file ffi_cert.cpp.

398 {
399#if defined(BOTAN_HAS_X509_CERTIFICATES)
400 return enumerator_count_values(count, [=](size_t index) {
402 cert, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
403 });
404#else
405 BOTAN_UNUSED(cert, value_type, count);
407#endif
408}
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:352

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
Random Number Generatorsa 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 1106 of file ffi_cert.cpp.

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

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)

Frees all resources of the CRL object

Parameters
crlthe CRL to destroy
Returns
0 if success, error if invalid object handle

Definition at line 1196 of file ffi_cert.cpp.

1196 {
1197#if defined(BOTAN_HAS_X509_CERTIFICATES)
1198 return BOTAN_FFI_CHECKED_DELETE(crl);
1199#else
1200 BOTAN_UNUSED(crl);
1202#endif
1203}

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

1333 {
1334#if defined(BOTAN_HAS_X509_CERTIFICATES)
1335 return BOTAN_FFI_VISIT(crl, [=](const Botan::X509_CRL& c) -> int {
1336 const auto& entries = c.get_revoked();
1337 if(index >= entries.size()) {
1339 }
1340
1341 if(Botan::any_null_pointers(entry)) {
1343 }
1344
1345 return ffi_new_object(entry, std::make_unique<Botan::CRL_Entry>(entries[index]));
1346 });
1347#else
1348 BOTAN_UNUSED(crl, index, entry);
1350#endif
1351}
const std::vector< CRL_Entry > & get_revoked() const
Definition x509_crl.cpp:260

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 )

Count the entries of the CRL.

Parameters
crlthe CRL whose entries should be counted
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 1353 of file ffi_cert.cpp.

1353 {
1354#if defined(BOTAN_HAS_X509_CERTIFICATES)
1355 if(Botan::any_null_pointers(count)) {
1357 }
1358
1359 return BOTAN_FFI_VISIT(crl, [=](const Botan::X509_CRL& c) { *count = c.get_revoked().size(); });
1360#else
1361 BOTAN_UNUSED(crl, count);
1363#endif
1364}

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

1132 {
1133 if(Botan::any_null_pointers(entry)) {
1135 }
1136#if defined(BOTAN_HAS_X509_CERTIFICATES)
1137 return ffi_guard_thunk(__func__, [=]() -> int {
1138 return ffi_new_object(
1139 entry, std::make_unique<Botan::CRL_Entry>(safe_get(cert), static_cast<Botan::CRL_Code>(reason_code)));
1140 });
1141#else
1142 BOTAN_UNUSED(cert, reason_code);
1144#endif
1145}

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)

Frees all resources of the CRL entry object

Parameters
entrythe CRL entry to destroy
Returns
0 if success, error if invalid object handle

Definition at line 1366 of file ffi_cert.cpp.

1366 {
1367#if defined(BOTAN_HAS_X509_CERTIFICATES)
1368 return BOTAN_FFI_CHECKED_DELETE(entry);
1369#else
1370 BOTAN_UNUSED(entry);
1372#endif
1373}

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

1375 {
1376#if defined(BOTAN_HAS_X509_CERTIFICATES)
1377 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1378 if(Botan::any_null_pointers(reason_code)) {
1380 }
1381
1382 *reason_code = static_cast<int>(e.reason_code());
1383 return BOTAN_FFI_SUCCESS;
1384 });
1385#else
1386 BOTAN_UNUSED(entry, reason_code);
1388#endif
1389}
Definition x509_crl.h:32
CRL_Code reason_code() const
Definition crl_ent.cpp:149

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

1417 {
1418#if defined(BOTAN_HAS_X509_CERTIFICATES)
1419 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1420 if(Botan::any_null_pointers(time_since_epoch)) {
1422 }
1423
1424 *time_since_epoch = e.expire_time().time_since_epoch();
1425 return BOTAN_FFI_SUCCESS;
1426 });
1427#else
1428 BOTAN_UNUSED(entry, time_since_epoch);
1430#endif
1431}
uint64_t time_since_epoch() const
Return time since epoch.
const X509_Time & expire_time() const
Definition crl_ent.cpp:145

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

1391 {
1392#if defined(BOTAN_HAS_X509_CERTIFICATES)
1393 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1394 if(Botan::any_null_pointers(serial_number)) {
1396 }
1397
1398 auto serial_bn = e.serial().to_bigint();
1399 return ffi_new_object(serial_number, std::make_unique<Botan::BigInt>(std::move(serial_bn)));
1400 });
1401#else
1402 BOTAN_UNUSED(entry, serial_number);
1404#endif
1405}
const X509_Serial_Number & serial() const
Definition crl_ent.cpp:141

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::CRL_Entry::serial(), and Botan::X509_Serial_Number::to_bigint().

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

1407 {
1408#if defined(BOTAN_HAS_X509_CERTIFICATES)
1409 return BOTAN_FFI_VISIT(
1410 entry, [=](const Botan::CRL_Entry& e) { return invoke_view_callback(view, ctx, e.serial_number()); });
1411#else
1412 BOTAN_UNUSED(entry, ctx, view);
1414#endif
1415}
const std::vector< uint8_t > & serial_number() const
Definition crl_ent.cpp:137

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 )

Load a CRL from a DER or PEM encoding

Parameters
crl_objthe new object will be placed here
crl_bitsthe encoding to load
crl_bits_lenlength of crl_bits in bytes
Returns
0 on success, a negative value on failure

Definition at line 1053 of file ffi_cert.cpp.

1053 {
1054 if(Botan::any_null_pointers(crl_obj, crl_bits)) {
1056 }
1057
1058#if defined(BOTAN_HAS_X509_CERTIFICATES)
1059 return ffi_guard_thunk(__func__, [=]() -> int {
1060 Botan::DataSource_Memory bits(crl_bits, crl_bits_len);
1061 auto c = std::make_unique<Botan::X509_CRL>(bits);
1062 return ffi_new_object(crl_obj, std::move(c));
1063 });
1064#else
1065 BOTAN_UNUSED(crl_bits_len);
1067#endif
1068}

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

Load a CRL from a file containing a DER or PEM encoding

Parameters
crl_objthe new object will be placed here
crl_pathpath of the file to read
Returns
0 on success, a negative value on failure

Definition at line 1036 of file ffi_cert.cpp.

1036 {
1037 if(Botan::any_null_pointers(crl_obj, crl_path)) {
1039 }
1040
1041#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
1042
1043 return ffi_guard_thunk(__func__, [=]() -> int {
1044 auto c = std::make_unique<Botan::X509_CRL>(crl_path);
1045 return ffi_new_object(crl_obj, std::move(c));
1046 });
1047
1048#else
1050#endif
1051}

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

Get the nextUpdate field of the CRL as seconds since the Unix epoch

Parameters
crlthe CRL to inspect
time_since_epochset to the nextUpdate time
Returns
0 on success, or BOTAN_FFI_ERROR_NO_VALUE if the field is absent

Definition at line 1085 of file ffi_cert.cpp.

1085 {
1086#if defined(BOTAN_HAS_X509_CERTIFICATES)
1087 return BOTAN_FFI_VISIT(crl, [=](const auto& c) {
1088 const auto& time = c.next_update();
1089 if(!time.time_is_set()) {
1091 }
1092
1093 if(Botan::any_null_pointers(time_since_epoch)) {
1095 }
1096
1097 *time_since_epoch = c.next_update().time_since_epoch();
1098 return BOTAN_FFI_SUCCESS;
1099 });
1100#else
1101 BOTAN_UNUSED(crl, time_since_epoch);
1103#endif
1104}

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 )

Get the thisUpdate field of the CRL as seconds since the Unix epoch

Parameters
crlthe CRL to inspect
time_since_epochset to the thisUpdate time
Returns
0 on success, a negative value on failure

Definition at line 1070 of file ffi_cert.cpp.

1070 {
1071#if defined(BOTAN_HAS_X509_CERTIFICATES)
1072 return BOTAN_FFI_VISIT(crl, [=](const auto& c) {
1073 if(Botan::any_null_pointers(time_since_epoch)) {
1075 }
1076 *time_since_epoch = c.this_update().time_since_epoch();
1077 return BOTAN_FFI_SUCCESS;
1078 });
1079#else
1080 BOTAN_UNUSED(crl, time_since_epoch);
1082#endif
1083}

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
Random Number Generatorsa 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 1147 of file ffi_cert.cpp.

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

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 )

Check the signature on a CRL against the issuer's public key

Parameters
crlthe CRL to verify
keythe public key of the issuing CA
Returns
1 if the signature is valid, 0 if it is not, negative on error

Definition at line 1187 of file ffi_cert.cpp.

1187 {
1188#if defined(BOTAN_HAS_X509_CERTIFICATES)
1189 return BOTAN_FFI_VISIT(crl, [=](const auto& c) -> int { return c.check_signature(safe_get(key)) ? 1 : 0; });
1190#else
1191 BOTAN_UNUSED(crl, key);
1193#endif
1194}

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

1209 {
1210#if defined(BOTAN_HAS_X509_CERTIFICATES)
1211 if(index != 0) {
1212 // As of now there are no multi-value binary entries.
1214 }
1215
1216 auto view = [=](std::span<const uint8_t> value) -> int {
1217 if(value.empty()) {
1219 } else {
1220 return invoke_view_callback(view_fn, ctx, value);
1221 }
1222 };
1223
1224 return BOTAN_FFI_VISIT(crl_obj, [=](const Botan::X509_CRL& crl) -> int {
1225 switch(value_type) {
1227 if(const auto& crln = crl.crl_number_bigint()) {
1228 // Previously CRL number was a fixed 4 byte value, continue this for small CRL numbers
1229 const size_t view_bytes = std::min<size_t>(crln->bytes(), 4);
1230 return view(crln->serialize<std::vector<uint8_t>>(view_bytes));
1231 } else {
1233 }
1234 }
1236 return view(Botan::ASN1::put_in_sequence(crl.issuer_dn().get_bits()));
1238 return view(crl.authority_key_id());
1239
1244 return botan_x509_object_view_value(crl, value_type, index, ctx, view_fn);
1245
1254 }
1255
1257 });
1258#else
1259 BOTAN_UNUSED(crl_obj, value_type, index, ctx, view_fn);
1261#endif
1262}
const std::vector< uint8_t > & authority_key_id() const
Definition x509_crl.cpp:282
const X509_DN & issuer_dn() const
Definition x509_crl.cpp:275
const std::optional< BigInt > & crl_number_bigint() const
Definition x509_crl.cpp:289
const std::vector< uint8_t > & get_bits() const
Definition pkix_types.h:198
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition asn1_obj.cpp:208

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_bigint(), Botan::X509_DN::get_bits(), Botan_FFI::invoke_view_callback(), Botan::X509_CRL::issuer_dn(), and Botan::ASN1::put_in_sequence().

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 )

Count the binary values of the given type available in a CRL.

Parameters
crl_objthe CRL to inspect
value_typethe value type to count
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 1264 of file ffi_cert.cpp.

1264 {
1265#if defined(BOTAN_HAS_X509_CERTIFICATES)
1266 return enumerator_count_values(count, [=](size_t index) {
1268 crl_obj, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
1269 });
1270#else
1271 BOTAN_UNUSED(crl_obj, value_type, count);
1273#endif
1274}
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 1276 of file ffi_cert.cpp.

1280 {
1281#if defined(BOTAN_HAS_X509_CERTIFICATES)
1282 return BOTAN_FFI_VISIT(crl_obj, [=](const Botan::X509_CRL& crl) -> int {
1283 switch(value_type) {
1285 return botan_x509_object_view_value(crl, value_type, index, ctx, view);
1286
1301 }
1302
1304 });
1305#else
1306 BOTAN_UNUSED(crl_obj, value_type, index, ctx, view);
1308#endif
1309}

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 )

Count the string values of the given type available in a CRL.

Parameters
crl_objthe CRL to inspect
value_typethe value type to count
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 1311 of file ffi_cert.cpp.

1311 {
1312#if defined(BOTAN_HAS_X509_CERTIFICATES)
1313 return enumerator_count_values(count, [=](size_t index) {
1315 crl_obj, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
1316 });
1317#else
1318 BOTAN_UNUSED(crl_obj, value_type, count);
1320#endif
1321}
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_ext_as_blocks_get_entry_at()

int botan_x509_ext_as_blocks_get_entry_at ( botan_x509_cert_t cert,
int asnum,
size_t i,
uint32_t * min,
uint32_t * max )

Get a specific entry in the AS Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
asnumSet to 1 to get info about AS numbers, 0 for RDIs (the type)
iThe index of the entry to get
minis set to the min value of the range
maxis set to the max value of the range
Returns
0 on success, negative number on error

If the extension is not present or an error occurs, min and max are not modified

Definition at line 222 of file ffi_cert_ext.cpp.

222 {
223 if(Botan::any_null_pointers(min, max)) {
225 }
226#if defined(BOTAN_HAS_X509_CERTIFICATES)
227 return ffi_guard_thunk(__func__, [=]() -> int {
228 if(asnum != 0 && asnum != 1) {
230 }
231
232 const auto& ext = safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::ASBlocks>();
233 if(Botan::any_null_pointers(ext)) {
235 }
236
237 const auto& asnum_or_rdi = asnum == 1 ? ext->as_identifiers().asnum() : ext->as_identifiers().rdi();
238 if(!asnum_or_rdi.has_value() || !asnum_or_rdi.value().ranges().has_value()) {
240 }
241
242 const auto& range = asnum_or_rdi.value().ranges().value();
243 if(i >= range.size()) {
245 }
246
247 *min = range.at(i).min();
248 *max = range.at(i).max();
249 return BOTAN_FFI_SUCCESS;
250 });
251#else
252 BOTAN_UNUSED(cert, asnum, i);
254#endif
255}
const std::optional< ASIdentifierChoice > & asnum() const
Definition x509_ext.h:1195
const ASIdentifiers & as_identifiers() const
Definition x509_ext.h:1257

References Botan::any_null_pointers(), Botan::Cert_Extension::ASBlocks::as_identifiers(), Botan::Cert_Extension::ASBlocks::ASIdentifiers::asnum(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_x509_ext_as_blocks_get_info()

int botan_x509_ext_as_blocks_get_info ( botan_x509_cert_t cert,
int asnum,
int * present,
size_t * count )

Get basic info about the AS Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
asnummust be set to 1 to get info about AS numbers, 0 for RDIs (the type)
presentis set to 1 if the extension contains entries for the type, 0 if it is marked as "inherit"
countis set to number of entries for this type, if it was present, otherwise count is not modified
Returns
0 on success, negative number on error

If the extension is not present or an error occurs, present and count are not modified

Definition at line 183 of file ffi_cert_ext.cpp.

183 {
184 if(Botan::any_null_pointers(present, count)) {
186 }
187#if defined(BOTAN_HAS_X509_CERTIFICATES)
188 return ffi_guard_thunk(__func__, [=]() -> int {
189 if(asnum != 0 && asnum != 1) {
191 }
192
193 const auto& ext = safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::ASBlocks>();
194 if(Botan::any_null_pointers(ext)) {
196 }
197
198 const auto& asnum_or_rdi = asnum == 1 ? ext->as_identifiers().asnum() : ext->as_identifiers().rdi();
199
200 if(!asnum_or_rdi.has_value()) {
202 }
203
204 const auto& ranges = asnum_or_rdi.value().ranges();
205
206 if(!ranges.has_value()) {
207 *present = 0;
208 return BOTAN_FFI_SUCCESS;
209 }
210
211 *present = 1;
212 *count = ranges.value().size();
213
214 return BOTAN_FFI_SUCCESS;
215 });
216#else
217 BOTAN_UNUSED(cert, asnum);
219#endif
220}

References Botan::any_null_pointers(), Botan::Cert_Extension::ASBlocks::as_identifiers(), Botan::Cert_Extension::ASBlocks::ASIdentifiers::asnum(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_x509_ext_ip_addr_blocks_get_address()

int botan_x509_ext_ip_addr_blocks_get_address ( botan_x509_cert_t cert,
int ipv6,
size_t i,
size_t entry,
uint8_t min_out[],
uint8_t max_out[],
size_t * out_len )

Get info about a specific range in the IP Address Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
ipv6must be set to 1 if the family is an IPv6 family, 0 for IPv4 families
iis the (local) index of the family, see botan_x509_ext_ip_addr_blocks_get_family
entryis the index of the range
min_outis set to the lower address of the range
max_outis set to the upper address of the range
out_lenis set to the length of the addresses (4 for IPv4, 16 for IPv6)
Returns
0 on success, negative number on error

The output parameters min_out, max_out and out_len may be modified even if the extension is not present or some other error occurs. In this event, the value of each output parameter after the call returns is undefined.

Definition at line 142 of file ffi_cert_ext.cpp.

143 {
144 if(out_len == nullptr) {
146 }
147#if defined(BOTAN_HAS_X509_CERTIFICATES)
148 return ffi_guard_thunk(__func__, [=]() -> int {
149 if(ipv6 != 0 && ipv6 != 1) {
151 }
152
153 const auto& ext =
154 safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::IPAddressBlocks>();
155 if(Botan::any_null_pointers(ext)) {
157 }
158
159 const size_t limit = ipv6 == 0 ? ext->v4_count() : ext->v6_count();
160 if(i >= limit) {
162 }
163
164 const size_t index = ipv6 == 0 ? i : ext->v4_count() + i;
165 const auto& addr_blocks = ext->addr_blocks();
166 const auto& addr_choice = addr_blocks.at(index).addr_choice();
167
168 if(ipv6 == 0) {
169 return ip_addr_blocks_get_address<Botan::Cert_Extension::IPAddressBlocks::Version::IPv4>(
170 addr_choice, entry, min_out, max_out, out_len);
171 } else {
172 return ip_addr_blocks_get_address<Botan::Cert_Extension::IPAddressBlocks::Version::IPv6>(
173 addr_choice, entry, min_out, max_out, out_len);
174 }
175 });
176#else
177 BOTAN_UNUSED(cert, ipv6, i, entry, min_out, max_out);
179#endif
180}
size_t v4_count() const
The number of IPv4 families contained in the extension.
Definition x509_ext.h:1109

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::Cert_Extension::IPAddressBlocks::v4_count().

◆ botan_x509_ext_ip_addr_blocks_get_counts()

int botan_x509_ext_ip_addr_blocks_get_counts ( botan_x509_cert_t cert,
size_t * v4_count,
size_t * v6_count )

Get info about the IP Address Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
v4_countis set to the number of v4 families contained in the extension
v6_countis set to the number of v6 families
Returns
0 on success, negative number on error

If the extension is not present or an error occurs, v4_count and v6_count are not modified

Definition at line 73 of file ffi_cert_ext.cpp.

73 {
74 if(Botan::any_null_pointers(v4_count, v6_count)) {
76 }
77#if defined(BOTAN_HAS_X509_CERTIFICATES)
78 return ffi_guard_thunk(__func__, [=]() -> int {
79 const auto& ext =
80 safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::IPAddressBlocks>();
83 }
84
85 *v4_count = ext->v4_count();
86 *v6_count = ext->v6_count();
87
88 return BOTAN_FFI_SUCCESS;
89 });
90#else
91 BOTAN_UNUSED(cert);
93#endif
94}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::Cert_Extension::IPAddressBlocks::v4_count().

◆ botan_x509_ext_ip_addr_blocks_get_family()

int botan_x509_ext_ip_addr_blocks_get_family ( botan_x509_cert_t cert,
int ipv6,
size_t i,
int * has_safi,
uint8_t * safi,
int * present,
size_t * count )

Get info about a specific family in the IP Address Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
ipv6must be set to 1 if the family is an IPv6 family, 0 for IPv4 families
iis the (local) index for this family kind (the first v4 family is at i = 0, ipv6 = 0; the first v6 family is at i = 0, ipv6 = 1)
has_safiwill be set to 1 if the family has an associated SAFI
safiwill be set to the families' SAFI, if it has one, otherwise safi is not modified
presentis set to 1 if the family contains values (ranges), 0 if it is marked as "inherit"
countis set to the number of values (ranges), if they were present, otherwise count is not modified
Returns
0 on success, negative number on error

The output parameters has_safi, safi, present and count may be modified even if the extension is not present or some other error occurs. In this event, the value of each output parameter after the call returns is undefined.

Definition at line 96 of file ffi_cert_ext.cpp.

97 {
98 if(Botan::any_null_pointers(has_safi, safi, present, count)) {
100 }
101#if defined(BOTAN_HAS_X509_CERTIFICATES)
102 return ffi_guard_thunk(__func__, [=]() -> int {
103 if(ipv6 != 0 && ipv6 != 1) {
105 }
106
107 const auto& ext =
108 safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::IPAddressBlocks>();
109 if(Botan::any_null_pointers(ext)) {
111 }
112
113 const size_t limit = ipv6 == 0 ? ext->v4_count() : ext->v6_count();
114 if(i >= limit) {
116 }
117
118 const size_t index = ipv6 == 0 ? i : ext->v4_count() + i;
119 const auto& addr_blocks = ext->addr_blocks();
120 const auto& family = addr_blocks.at(index);
121 if(family.safi().has_value()) {
122 *has_safi = 1;
123 *safi = family.safi().value();
124 } else {
125 *has_safi = 0;
126 }
127
128 if(ipv6 == 0) {
129 return ip_addr_blocks_get_family<Botan::Cert_Extension::IPAddressBlocks::Version::IPv4>(
130 family, present, count);
131 } else {
132 return ip_addr_blocks_get_family<Botan::Cert_Extension::IPAddressBlocks::Version::IPv6>(
133 family, present, count);
134 }
135 });
136#else
137 BOTAN_UNUSED(cert, ipv6, i);
139#endif
140}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::safi(), and Botan::Cert_Extension::IPAddressBlocks::v4_count().

◆ botan_x509_general_name_destroy()

int botan_x509_general_name_destroy ( botan_x509_general_name_t alt_names)

Frees all resources of the GeneralName object

Parameters
alt_namesthe GeneralName to destroy
Returns
0 if success, error if invalid object handle

Definition at line 779 of file ffi_cert.cpp.

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

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

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

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

759 {
760#if defined(BOTAN_HAS_X509_CERTIFICATES)
761 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) -> int {
762 const auto type = to_botan_x509_general_name_types(n.type_code());
763 if(!type) {
765 }
766
767 if(type != BOTAN_X509_DIRECTORY_NAME && type != BOTAN_X509_IP_ADDRESS) {
769 }
770
771 return invoke_view_callback(view, ctx, n.binary_name());
772 });
773#else
774 BOTAN_UNUSED(name, ctx, view);
776#endif
777}
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 734 of file ffi_cert.cpp.

736 {
737#if defined(BOTAN_HAS_X509_CERTIFICATES)
738 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) -> int {
739 const auto type = to_botan_x509_general_name_types(n.type_code());
740 if(!type) {
742 }
743
744 if(type != BOTAN_X509_EMAIL_ADDRESS && type != BOTAN_X509_DNS_NAME && type != BOTAN_X509_URI &&
745 type != BOTAN_X509_IP_ADDRESS) {
747 }
748
749 return invoke_view_callback(view, ctx, n.name());
750 });
751#else
752 BOTAN_UNUSED(name, ctx, view);
754#endif
755}
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 1323 of file ffi_cert.cpp.

1323 {
1324#if defined(BOTAN_HAS_X509_CERTIFICATES)
1325 return BOTAN_FFI_VISIT(crl, [=](const auto& c) { return c.is_revoked(safe_get(cert)) ? 0 : -1; });
1326#else
1327 BOTAN_UNUSED(cert);
1328 BOTAN_UNUSED(crl);
1330#endif
1331}

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
eXtendable Output Functionthe object to read
Returns
1 iff the XOF is still accepting input bytes

Definition at line 61 of file ffi_xof.cpp.

61 {
62 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { return xof.accepts_input() ? 1 : 0; });
63}

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
eXtendable Output FunctionXOF object
block_sizevariable to hold the XOF's block size
Returns
0 on success, a negative value on failure

Definition at line 46 of file ffi_xof.cpp.

46 {
49 }
50 return BOTAN_FFI_VISIT(this_xof, [=](const auto& xof) { *out = xof.block_size(); });
51}

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
eXtendable Output FunctionXOF object
Returns
0 on success, a negative value on failure

Definition at line 65 of file ffi_xof.cpp.

65 {
66 return BOTAN_FFI_VISIT(this_xof, [](auto& xof) { xof.clear(); });
67}

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 if(dest == nullptr) {
42 }
43 return BOTAN_FFI_VISIT(this_xof, [=](const auto& src) { return ffi_new_object(dest, src.copy_state()); });
44}

References BOTAN_FFI_ERROR_NULL_POINTER, 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
eXtendable Output Functionxof object
Returns
0 if success, error if invalid object handle

Definition at line 93 of file ffi_xof.cpp.

93 {
94 return BOTAN_FFI_CHECKED_DELETE(xof);
95}

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
eXtendable Output FunctionXOF 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
eXtendable Output Functionthe object to read
nameoutput buffer
name_lenon input, the length of buffer, on success the number of bytes written

Definition at line 53 of file ffi_xof.cpp.

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

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
eXtendable Output FunctionXOF 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 81 of file ffi_xof.cpp.

81 {
82 if(out_len == 0) {
83 return 0;
84 }
85
88 }
89
90 return BOTAN_FFI_VISIT(this_xof, [=](auto& xof) { xof.output({out, out_len}); });
91}

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
eXtendable Output FunctionXOF 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 69 of file ffi_xof.cpp.

69 {
70 if(in_len == 0) {
71 return 0;
72 }
73
76 }
77
78 return BOTAN_FFI_VISIT(this_xof, [=](auto& xof) { xof.update({in, in_len}); });
79}

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

36 {
37 if(Botan::any_null_pointers(indexes, inputs, outputs)) {
39 }
40#if defined(BOTAN_HAS_ZFEC)
41 return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
42 std::map<size_t, const uint8_t*> shares;
43 for(size_t k = 0; k < K; ++k) {
44 shares.insert(std::pair<size_t, const uint8_t*>(indexes[k], inputs[k]));
45 }
47 shares, shareSize, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
48 std::copy(block, block + blockSize, outputs[index]);
49 });
50 return BOTAN_FFI_SUCCESS;
51 });
52#else
53 BOTAN_UNUSED(K, N, indexes, inputs, shareSize, outputs);
55#endif
56}
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:441

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

◆ botan_zfec_encode()

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

ZFEC Encode some bytes with certain ZFEC parameters.

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

Definition at line 18 of file ffi_zfec.cpp.

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

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