Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Macros | Typedefs | Enumerations | Functions
ffi.h File Reference
`#include <botan/build.h>`
`#include <stdint.h>`
`#include <stddef.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_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

## Typedefs
typedef struct botan_block_cipher_struct * | botan_block_cipher_t
typedef struct botan_cipher_struct * | botan_cipher_t
typedef struct botan_fpe_struct * | botan_fpe_t
typedef struct botan_hash_struct * | botan_hash_t
typedef struct botan_hotp_struct * | botan_hotp_t
typedef struct botan_mac_struct * | botan_mac_t
typedef struct botan_mp_struct * | botan_mp_t
typedef struct botan_pk_op_decrypt_struct * | botan_pk_op_decrypt_t
typedef struct botan_pk_op_encrypt_struct * | botan_pk_op_encrypt_t
typedef struct botan_pk_op_ka_struct * | botan_pk_op_ka_t
typedef struct botan_pk_op_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_totp_struct * | botan_totp_t
typedef struct botan_x509_cert_struct * | botan_x509_cert_t
typedef struct botan_x509_crl_struct * | botan_x509_crl_t

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

## Functions
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_keyspec (botan_cipher_t, size_t *min_keylen, size_t *max_keylen, size_t *mod_keylen)
int | botan_cipher_get_tag_length (botan_cipher_t cipher, size_t *tag_size)
int | botan_cipher_get_update_granularity (botan_cipher_t cipher, size_t *ug)
int | botan_cipher_init (botan_cipher_t *cipher, const char *name, uint32_t flags)
int | botan_cipher_name (botan_cipher_t cipher, char *name, size_t *name_len)
int | botan_cipher_output_length (botan_cipher_t cipher, size_t in_len, size_t *out_len)
int | botan_cipher_query_keylen (botan_cipher_t, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
int | botan_cipher_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)
int | botan_cipher_valid_nonce_length (botan_cipher_t cipher, size_t nl)
int | botan_constant_time_compare (const uint8_t *x, const uint8_t *y, size_t len)
const char * | botan_error_description (int err)
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, const botan_hash_t source)
int | botan_hash_destroy (botan_hash_t hash)
int | botan_hash_final (botan_hash_t hash, uint8_t out[])
int | botan_hash_init (botan_hash_t *hash, const char *hash_name, uint32_t flags)
int | botan_hash_name (botan_hash_t hash, char *name, size_t *name_len)
int | botan_hash_output_length (botan_hash_t hash, size_t *output_length)
int | botan_hash_update (botan_hash_t hash, const uint8_t *in, size_t in_len)
int | botan_hex_decode (const char *hex_str, size_t in_len, uint8_t *out, size_t *out_len)
int | botan_hex_encode (const uint8_t *x, size_t len, char *out, uint32_t flags)
int | botan_hotp_check (botan_hotp_t hotp, uint64_t *next_hotp_counter, uint32_t hotp_code, uint64_t hotp_counter, size_t resync_range)
int | botan_hotp_destroy (botan_hotp_t hotp)
int | botan_hotp_generate (botan_hotp_t hotp, uint32_t *hotp_code, uint64_t hotp_counter)
int | botan_hotp_init (botan_hotp_t *hotp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits)
int | botan_kdf (const char *kdf_algo, uint8_t out[], size_t out_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len)
int | botan_key_unwrap3394 (const uint8_t wrapped_key[], size_t wrapped_key_len, const uint8_t kek[], size_t kek_len, uint8_t key[], size_t *key_len)
int | botan_key_wrap3394 (const uint8_t key[], size_t key_len, const uint8_t kek[], size_t kek_len, uint8_t wrapped_key[], size_t *wrapped_key_len)
int | botan_mac_clear (botan_mac_t mac)
int | botan_mac_destroy (botan_mac_t mac)
int | botan_mac_final (botan_mac_t mac, uint8_t out[])
int | botan_mac_get_keyspec (botan_mac_t mac, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
int | botan_mac_init (botan_mac_t *mac, const char *mac_name, uint32_t flags)
int | botan_mac_name (botan_mac_t mac, char *name, size_t *name_len)
int | botan_mac_output_length (botan_mac_t mac, size_t *output_length)
int | botan_mac_set_key (botan_mac_t mac, const uint8_t *key, size_t key_len)
int | botan_mac_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, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_add_u32 (botan_mp_t result, const 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, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_destroy (botan_mp_t mp)
int | botan_mp_div (botan_mp_t quotient, botan_mp_t remainder, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_equal (const botan_mp_t x, const botan_mp_t y)
int | botan_mp_flip_sign (botan_mp_t mp)
int | botan_mp_from_bin (const botan_mp_t mp, const uint8_t vec[], size_t vec_len)
int | botan_mp_gcd (botan_mp_t out, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_get_bit (const botan_mp_t n, size_t bit)
int | botan_mp_init (botan_mp_t *mp)
int | botan_mp_is_even (const botan_mp_t mp)
int | botan_mp_is_negative (const botan_mp_t mp)
int | botan_mp_is_odd (const botan_mp_t mp)
int | botan_mp_is_positive (const botan_mp_t mp)
int | botan_mp_is_prime (const botan_mp_t n, botan_rng_t rng, size_t test_prob)
int | botan_mp_is_zero (const botan_mp_t mp)
int | botan_mp_lshift (botan_mp_t out, const botan_mp_t in, size_t shift)
int | botan_mp_mod_inverse (botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus)
int | botan_mp_mod_mul (botan_mp_t result, const botan_mp_t x, const botan_mp_t y, const botan_mp_t mod)
int | botan_mp_mul (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_num_bits (const botan_mp_t n, size_t *bits)
int | botan_mp_num_bytes (const botan_mp_t n, size_t *bytes)
int | botan_mp_powmod (botan_mp_t out, const botan_mp_t base, const botan_mp_t exponent, const 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, const botan_mp_t lower_bound, const botan_mp_t upper_bound)
int | botan_mp_rshift (botan_mp_t out, const 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, const 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, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_sub_u32 (botan_mp_t result, const botan_mp_t x, uint32_t y)
int | botan_mp_swap (botan_mp_t x, botan_mp_t y)
int | botan_mp_to_bin (const botan_mp_t mp, uint8_t vec[])
int | botan_mp_to_hex (const botan_mp_t mp, char *out)
int | botan_mp_to_str (const botan_mp_t mp, uint8_t base, char *out, size_t *out_len)
int | botan_mp_to_uint32 (const botan_mp_t mp, uint32_t *val)
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_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_sign_create (botan_pk_op_sign_t *op, botan_privkey_t key, const char *hash_and_padding, uint32_t flags)
int | botan_pk_op_sign_destroy (botan_pk_op_sign_t op)
int | botan_pk_op_sign_finish (botan_pk_op_sign_t op, botan_rng_t rng, uint8_t sig[], size_t *sig_len)
int | botan_pk_op_sign_output_length (botan_pk_op_sign_t op, size_t *olen)
int | botan_pk_op_sign_update (botan_pk_op_sign_t op, const uint8_t in[], size_t in_len)
int | botan_pk_op_verify_create (botan_pk_op_verify_t *op, botan_pubkey_t key, const char *hash_and_padding, uint32_t flags)
int | botan_pk_op_verify_destroy (botan_pk_op_verify_t op)
int | botan_pk_op_verify_finish (botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len)
int | botan_pk_op_verify_update (botan_pk_op_verify_t op, const uint8_t in[], size_t in_len)
int | botan_pkcs_hash_id (const char *hash_name, uint8_t pkcs_id[], size_t *pkcs_id_len)
int | botan_privkey_algo_name (botan_privkey_t key, char out[], size_t *out_len)
int | botan_privkey_check_key (botan_privkey_t key, botan_rng_t rng, uint32_t flags)
int | botan_privkey_create (botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
int | botan_privkey_create_dh (botan_privkey_t *key, botan_rng_t rng, const char *param)
int | botan_privkey_create_dsa (botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
int | botan_privkey_create_ecdh (botan_privkey_t *key, botan_rng_t rng, const char *params)
int | botan_privkey_create_ecdsa (botan_privkey_t *key, botan_rng_t rng, const char *params)
int | botan_privkey_create_elgamal (botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
int | botan_privkey_create_mceliece (botan_privkey_t *key, botan_rng_t rng, size_t n, size_t t)
int | botan_privkey_create_rsa (botan_privkey_t *key, botan_rng_t rng, size_t n_bits)
int | botan_privkey_destroy (botan_privkey_t key)
int | botan_privkey_dsa_get_x (botan_mp_t n, botan_privkey_t key)
int | botan_privkey_ed25519_get_privkey (botan_privkey_t key, uint8_t output[64])
int | botan_privkey_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_dh (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
int | botan_privkey_load_dsa (botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t x)
int | botan_privkey_load_ecdh (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
int | botan_privkey_load_ecdsa (botan_privkey_t *key, const 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_elgamal (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
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_sm2 (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
int | botan_privkey_load_sm2_enc (botan_privkey_t *key, const 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_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_x25519_get_privkey (botan_privkey_t key, uint8_t output[32])
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_ed25519_get_pubkey (botan_pubkey_t key, uint8_t pubkey[32])
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_dh (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
int | botan_pubkey_load_dsa (botan_pubkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t y)
int | botan_pubkey_load_ecdh (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
int | botan_pubkey_load_ecdsa (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
int | botan_pubkey_load_ed25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
int | botan_pubkey_load_elgamal (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
int | botan_pubkey_load_rsa (botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
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)
int | botan_pubkey_load_sm2_enc (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
int | botan_pubkey_load_x25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
int | botan_pubkey_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, const botan_pubkey_t key)
int | botan_pubkey_x25519_get_pubkey (botan_pubkey_t key, uint8_t pubkey[32])
int | botan_pwdhash (const char *algo, size_t param1, size_t param2, size_t param3, uint8_t out[], size_t out_len, const char *passphrase, size_t passphrase_len, const uint8_t salt[], size_t salt_len)
int | botan_pwdhash_timed (const char *algo, uint32_t msec, size_t *param1, size_t *param2, size_t *param3, uint8_t out[], size_t out_len, const char *passphrase, size_t passphrase_len, const uint8_t salt[], size_t salt_len)
int | botan_rng_add_entropy (botan_rng_t rng, const uint8_t *entropy, size_t entropy_len)
int | botan_rng_destroy (botan_rng_t rng)
int | botan_rng_get (botan_rng_t rng, uint8_t *out, size_t out_len)
int | botan_rng_init (botan_rng_t *rng, const char *rng_type)
int | botan_rng_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_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)
uint32_t | botan_version_datestamp (void)
uint32_t | botan_version_major (void)
uint32_t | botan_version_minor (void)
uint32_t | botan_version_patch (void)
const char * | botan_version_string (void)
int | botan_x509_cert_allowed_usage (botan_x509_cert_t cert, unsigned int key_usage)
int | botan_x509_cert_destroy (botan_x509_cert_t cert)
int | botan_x509_cert_dup (botan_x509_cert_t *new_cert, botan_x509_cert_t cert)
int | botan_x509_cert_get_authority_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_fingerprint (botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_issuer_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_public_key (botan_x509_cert_t cert, botan_pubkey_t *key)
int | botan_x509_cert_get_public_key_bits (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_serial_number (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_subject_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_subject_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_time_expires (botan_x509_cert_t cert, char out[], size_t *out_len)
int | botan_x509_cert_get_time_starts (botan_x509_cert_t cert, char out[], size_t *out_len)
int | botan_x509_cert_hostname_match (botan_x509_cert_t cert, const char *hostname)
int | botan_x509_cert_load (botan_x509_cert_t *cert_obj, const uint8_t cert[], size_t cert_len)
int | botan_x509_cert_load_file (botan_x509_cert_t *cert_obj, const char *filename)
int | botan_x509_cert_not_after (botan_x509_cert_t cert, uint64_t *time_since_epoch)
int | botan_x509_cert_not_before (botan_x509_cert_t cert, uint64_t *time_since_epoch)
int | botan_x509_cert_to_string (botan_x509_cert_t cert, char out[], size_t *out_len)
const char * | botan_x509_cert_validation_status (int code)
int | botan_x509_cert_verify (int *validation_result, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const char *trusted_path, size_t required_strength, const char *hostname, uint64_t reference_time)
int | botan_x509_cert_verify_with_crl (int *validation_result, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const botan_x509_crl_t *crls, size_t crls_len, const char *trusted_path, size_t required_strength, const char *hostname, uint64_t reference_time)
int | botan_x509_crl_destroy (botan_x509_crl_t crl)
int | botan_x509_crl_load (botan_x509_crl_t *crl_obj, const uint8_t crl_bits[], size_t crl_bits_len)
int | botan_x509_crl_load_file (botan_x509_crl_t *crl_obj, const char *crl_path)
int | botan_x509_is_revoked (botan_x509_crl_t crl, botan_x509_cert_t cert)

## Macro Definition Documentation

#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS 1

Definition at line 966 of file ffi.h.

Referenced by botan_privkey_check_key(), and botan_pubkey_check_key().

#define BOTAN_CIPHER_INIT_FLAG_DECRYPT 1

Definition at line 426 of file ffi.h.

#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT 0

Definition at line 425 of file ffi.h.

Referenced by botan_cipher_init().

#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION 1

Definition at line 424 of file ffi.h.

Referenced by botan_cipher_init().

#define BOTAN_CIPHER_UPDATE_FLAG_FINAL (1U << 0)

Definition at line 507 of file ffi.h.

Referenced by botan_cipher_update().

#define BOTAN_FFI_HEX_LOWER_CASE 1

Definition at line 153 of file ffi.h.

Referenced by botan_hex_encode().

#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE 1

Definition at line 1737 of file ffi.h.

Referenced by botan_fpe_fe1_init().

#define BOTAN_PRIVKEY_EXPORT_FLAG_DER 0

Definition at line 1045 of file ffi.h.

Referenced by botan_privkey_export(), botan_privkey_export_encrypted_pbkdf_iter(), botan_privkey_export_encrypted_pbkdf_msec(), botan_privkey_rsa_get_privkey(), and botan_pubkey_export().

#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM 1

Definition at line 1046 of file ffi.h.

Referenced by botan_privkey_export(), botan_privkey_export_encrypted_pbkdf_iter(), botan_privkey_export_encrypted_pbkdf_msec(), botan_privkey_rsa_get_privkey(), and botan_pubkey_export().

## Typedef Documentation

typedef struct botan_block_cipher_struct* botan_block_cipher_t

Definition at line 677 of file ffi.h.

typedef struct botan_cipher_struct* botan_cipher_t

Definition at line 422 of file ffi.h.

typedef struct botan_fpe_struct* botan_fpe_t

Format Preserving Encryption

Definition at line 1735 of file ffi.h.

typedef struct botan_hash_struct* botan_hash_t

Definition at line 256 of file ffi.h.

typedef struct botan_hotp_struct* botan_hotp_t

HOTP

Definition at line 1645 of file ffi.h.

typedef struct botan_mac_struct* botan_mac_t

Definition at line 336 of file ffi.h.

typedef struct botan_mp_struct* botan_mp_t

Definition at line 750 of file ffi.h.

typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t

Definition at line 1386 of file ffi.h.

typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t

Definition at line 1360 of file ffi.h.

typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t

Definition at line 1452 of file ffi.h.

typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t

Definition at line 1409 of file ffi.h.

typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t

Definition at line 1433 of file ffi.h.

typedef struct botan_privkey_struct* botan_privkey_t

Definition at line 951 of file ffi.h.

typedef struct botan_pubkey_struct* botan_pubkey_t

Definition at line 1098 of file ffi.h.

typedef struct botan_rng_struct* botan_rng_t

RNG type

Definition at line 189 of file ffi.h.

typedef struct botan_totp_struct* botan_totp_t

TOTP

Definition at line 1686 of file ffi.h.

typedef struct botan_x509_cert_struct* botan_x509_cert_t

Definition at line 1503 of file ffi.h.

typedef struct botan_x509_crl_struct* botan_x509_crl_t

Definition at line 1597 of file ffi.h.

## Enumeration Type Documentation

enum BOTAN_FFI_ERROR

Error codes

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

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

Definition at line 61 of file ffi.h.

61 {
62 BOTAN_FFI_SUCCESS = 0,
63 BOTAN_FFI_INVALID_VERIFIER = 1,
64
65 BOTAN_FFI_ERROR_INVALID_INPUT = -1,
66 BOTAN_FFI_ERROR_BAD_MAC = -2,
67
68 BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE = -10,
69
70 BOTAN_FFI_ERROR_EXCEPTION_THROWN = -20,
71 BOTAN_FFI_ERROR_OUT_OF_MEMORY = -21,
72 BOTAN_FFI_ERROR_SYSTEM_ERROR = -22,
73 BOTAN_FFI_ERROR_INTERNAL_ERROR = -23,
74
75 BOTAN_FFI_ERROR_BAD_FLAG = -30,
76 BOTAN_FFI_ERROR_NULL_POINTER = -31,
77 BOTAN_FFI_ERROR_BAD_PARAMETER = -32,
78 BOTAN_FFI_ERROR_KEY_NOT_SET = -33,
79 BOTAN_FFI_ERROR_INVALID_KEY_LENGTH = -34,
80 BOTAN_FFI_ERROR_INVALID_OBJECT_STATE = -35,
81
82 BOTAN_FFI_ERROR_NOT_IMPLEMENTED = -40,
83 BOTAN_FFI_ERROR_INVALID_OBJECT = -50,
84
85 BOTAN_FFI_ERROR_TLS_ERROR = -75,
86 BOTAN_FFI_ERROR_HTTP_ERROR = -76,
87 BOTAN_FFI_ERROR_ROUGHTIME_ERROR = -77,
88
89 BOTAN_FFI_ERROR_UNKNOWN_ERROR = -100,
90 };
BOTAN_FFI_ERROR_OUT_OF_MEMORY
Definition: ffi.h:71
BOTAN_FFI_ERROR_INVALID_INPUT
Definition: ffi.h:65
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:70
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_ERROR_BAD_MAC
Definition: ffi.h:66
BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:68
BOTAN_FFI_ERROR_INTERNAL_ERROR
Definition: ffi.h:73
BOTAN_FFI_ERROR_INVALID_KEY_LENGTH
Definition: ffi.h:79
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
Definition: ffi.h:80
BOTAN_FFI_ERROR_SYSTEM_ERROR
Definition: ffi.h:72
BOTAN_FFI_ERROR_HTTP_ERROR
Definition: ffi.h:86
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_ERROR_ROUGHTIME_ERROR
Definition: ffi.h:87
BOTAN_FFI_ERROR_TLS_ERROR
Definition: ffi.h:85
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_ERROR_KEY_NOT_SET
Definition: ffi.h:78
BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:63
BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:89
BOTAN_FFI_ERROR_INVALID_OBJECT
Definition: ffi.h:83

enum botan_x509_cert_key_constraints

Enumerator
NO_CONSTRAINTS |
DIGITAL_SIGNATURE |
NON_REPUDIATION |
KEY_ENCIPHERMENT |
DATA_ENCIPHERMENT |
KEY_AGREEMENT |
KEY_CERT_SIGN |
CRL_SIGN |
ENCIPHER_ONLY |
DECIPHER_ONLY |

Definition at line 1546 of file ffi.h.

1546 {
1547 NO_CONSTRAINTS = 0,
1548 DIGITAL_SIGNATURE = 32768,
1549 NON_REPUDIATION = 16384,
1550 KEY_ENCIPHERMENT = 8192,
1551 DATA_ENCIPHERMENT = 4096,
1552 KEY_AGREEMENT = 2048,
1553 KEY_CERT_SIGN = 1024,
1554 CRL_SIGN = 512,
1555 ENCIPHER_ONLY = 256,
1556 DECIPHER_ONLY = 128
1557 };
KEY_AGREEMENT
Definition: ffi.h:1552
CRL_SIGN
Definition: ffi.h:1554
KEY_CERT_SIGN
Definition: ffi.h:1553
NON_REPUDIATION
Definition: ffi.h:1549
DECIPHER_ONLY
Definition: ffi.h:1556
NO_CONSTRAINTS
Definition: ffi.h:1547
DIGITAL_SIGNATURE
Definition: ffi.h:1548
DATA_ENCIPHERMENT
Definition: ffi.h:1551
ENCIPHER_ONLY
Definition: ffi.h:1555
KEY_ENCIPHERMENT
Definition: ffi.h:1550

## Function Documentation

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

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

280 {
281 return ffi_guard_thunk(__func__, [=]() -> int {
282 if(*out_len < Botan::base64_decode_max_output(in_len))
283 {
284 *out_len = Botan::base64_decode_max_output(in_len);
285 return BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE;
286 }
287
288 *out_len = Botan::base64_decode(out, std::string(base64_str, in_len));
289 return BOTAN_FFI_SUCCESS;
290 });
291 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::base64_decode_max_output
size_t base64_decode_max_output(size_t input_length)
Definition: base64.cpp:224
BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:68
Botan::base64_decode
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:181
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Perform base64 encoding

Definition at line 270 of file ffi.cpp.

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

271 {
272 return ffi_guard_thunk(__func__, [=]() -> int {
273 const std::string base64 = Botan::base64_encode(in, len);
274 return Botan_FFI::write_str_output(out, out_len, base64);
275 });
276 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
Botan::base64_encode
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition: base64.cpp:166

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

  out | buffer holding the password hash, should be of length 64 bytes
  out_len | the desired output length in bytes
  password | the password
  rng | a random number generator
  work_factor | how much work to do to slow down guessing attacks
  flags | should be 0 in current API revision, all other uses are reserved and return BOTAN_FFI_ERROR_BAD_FLAG

Returns
  0 on success, a negative value on failure

Output is formatted bcrypt $2a$...

Definition at line 153 of file ffi_kdf.cpp.

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

157 {
158 #if defined(BOTAN_HAS_BCRYPT)
159 return ffi_guard_thunk(__func__, [=]() -> int {
160 if(out == nullptr || out_len == nullptr || pass == nullptr)
161 return BOTAN_FFI_ERROR_NULL_POINTER;
162
163 if(flags != 0)
164 return BOTAN_FFI_ERROR_BAD_FLAG;
165
166 if(wf < 4 || wf > 18)
167 return BOTAN_FFI_ERROR_BAD_PARAMETER;
168
169 Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
170 const std::string bcrypt = Botan::generate_bcrypt(pass, rng, static_cast<uint16_t>(wf));
171 return write_str_output(out, out_len, bcrypt);
172 });
173 #else
174 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
175 #endif
176 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
Botan::generate_bcrypt
std::string generate_bcrypt(const std::string &pass, RandomNumberGenerator &rng, uint16_t work_factor, char version)
Definition: bcrypt.cpp:137

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

Check a previously created password hash

Parameters

  pass | the password to check against
  hash | the 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 178 of file ffi_kdf.cpp.

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

179 {
180 #if defined(BOTAN_HAS_BCRYPT)
181 return ffi_guard_thunk(__func__, [=]() -> int {
182 return Botan::check_bcrypt(pass, hash) ? BOTAN_FFI_SUCCESS : BOTAN_FFI_INVALID_VERIFIER;
183 });
184 #else
185 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
186 #endif
187 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
Botan::check_bcrypt
bool check_bcrypt(const std::string &pass, const std::string &hash)
Definition: bcrypt.cpp:155
BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:63
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

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

References BOTAN_FFI_RETURNING.

63 {
64 return BOTAN_FFI_RETURNING(Botan::BlockCipher, bc, b,
65 { return static_cast<int>(b.block_size()); });
66 }
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan::BlockCipher
Definition: block_cipher.h:21

int botan_block_cipher_clear | ( | botan_block_cipher_t | bc | ) |

Reinitializes the block cipher

Returns
  0 on success, a negative value on failure

Definition at line 42 of file ffi_block.cpp.

References BOTAN_FFI_DO, and Botan::SymmetricAlgorithm::clear().

43 {
44 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.clear(); });
45 }
Botan::SymmetricAlgorithm::clear
virtual void clear()=0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::BlockCipher::decrypt_n().

82 {
83 if(in == nullptr || out == nullptr)
84 return BOTAN_FFI_ERROR_NULL_POINTER;
85 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.decrypt_n(in, out, blocks); });
86 }
Botan::BlockCipher::decrypt_n
virtual void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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

References BOTAN_FFI_CHECKED_DELETE.

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

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

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::BlockCipher::encrypt_n().

72 {
73 if(in == nullptr || out == nullptr)
74 return BOTAN_FFI_ERROR_NULL_POINTER;
75 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.encrypt_n(in, out, blocks); });
76 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::BlockCipher::encrypt_n
virtual void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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

  cipher | the object to read
  out_minimum_keylength | if non-NULL, will be set to minimum keylength of cipher
  out_maximum_keylength | if non-NULL, will be set to maximum keylength of cipher
  out_keylength_modulo | if non-NULL will be set to byte multiple of valid keys

Definition at line 97 of file ffi_block.cpp.

References BOTAN_FFI_DO, and Botan::SymmetricAlgorithm::minimum_keylength().

101 {
102 return BOTAN_FFI_DO(Botan::BlockCipher, cipher, bc, {
103 if(out_minimum_keylength)
104 *out_minimum_keylength = bc.minimum_keylength();
105 if(out_maximum_keylength)
106 *out_maximum_keylength = bc.maximum_keylength();
107 if(out_keylength_modulo)
108 *out_keylength_modulo = bc.key_spec().keylength_multiple();
109 });
110 }
Botan::SymmetricAlgorithm::minimum_keylength
size_t minimum_keylength() const
Definition: sym_algo.h:46
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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

Initialize a block cipher object

Definition at line 17 of file ffi_block.cpp.

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

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(bc == nullptr || bc_name == nullptr || *bc_name == 0)
21 return BOTAN_FFI_ERROR_NULL_POINTER;
22
23 *bc = nullptr;
24
25 std::unique_ptr<Botan::BlockCipher> cipher(Botan::BlockCipher::create(bc_name));
26 if(cipher == nullptr)
27 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
28
29 *bc = new botan_block_cipher_struct(cipher.release());
30 return BOTAN_FFI_SUCCESS;
31 });
32 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::BlockCipher::create
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
Definition: block_cipher.cpp:108
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Get the name of this block cipher

Parameters

  cipher | the object to read
  name | output buffer
  name_len | on input, the length of buffer, on success the number of bytes written

Definition at line 88 of file ffi_block.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan_FFI::write_str_output().

89 {
90 if(name_len == nullptr)
91 return BOTAN_FFI_ERROR_NULL_POINTER;
92
93 return BOTAN_FFI_DO(Botan::BlockCipher, cipher, bc, {
94 return write_str_output(name, name_len, bc.name()); });
95 }
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
name
std::string name
Definition: commoncrypto_hash.cpp:23
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::SymmetricAlgorithm::set_key().

52 {
53 if(key == nullptr)
54 return BOTAN_FFI_ERROR_NULL_POINTER;
55 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.set_key(key, len); });
56 }
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:65
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

int botan_cipher_clear | ( | botan_cipher_t | hash | ) |

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

Definition at line 39 of file ffi_cipher.cpp.

References BOTAN_FFI_DO, and Botan::SymmetricAlgorithm::clear().

40 {
41 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { c.clear(); });
42 }
Botan::SymmetricAlgorithm::clear
virtual void clear()=0
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_cipher_destroy | ( | botan_cipher_t | cipher | ) |

Destroy the cipher object

Returns
  0 if success, error if invalid object handle

Definition at line 34 of file ffi_cipher.cpp.

References BOTAN_FFI_CHECKED_DELETE.

35 {
36 return BOTAN_FFI_CHECKED_DELETE(cipher);
37 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

References BOTAN_FFI_DO, and Botan::Cipher_Mode::default_nonce_length().

213 {
214 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *nl = c.default_nonce_length(); });
215 }
Botan::Cipher_Mode::default_nonce_length
virtual size_t default_nonce_length() const =0
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_cipher_get_keyspec | ( | botan_cipher_t | ,
|  | size_t * | min_keylen,
|  | size_t * | max_keylen,
|  | size_t * | mod_keylen
| ) |  |

Get information about the supported key lengths.

Definition at line 67 of file ffi_cipher.cpp.

References BOTAN_FFI_DO, Botan::SymmetricAlgorithm::key_spec(), and Botan::Key_Length_Specification::minimum_keylength().

71 {
72 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
73 if(out_minimum_keylength)
74 *out_minimum_keylength = c.key_spec().minimum_keylength();
75 if(out_maximum_keylength)
76 *out_maximum_keylength = c.key_spec().maximum_keylength();
77 if(out_keylength_modulo)
78 *out_keylength_modulo = c.key_spec().keylength_multiple();
79 });
80 }
Botan::Key_Length_Specification::minimum_keylength
size_t minimum_keylength() const
Definition: key_spec.h:61
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

References BOTAN_FFI_DO, and Botan::Cipher_Mode::tag_size().

223 {
224 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *tl = c.tag_size(); });
225 }
Botan::Cipher_Mode::tag_size
virtual size_t tag_size() const
Definition: cipher_mode.h:174
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

References BOTAN_FFI_DO, and Botan::Cipher_Mode::update_granularity().

218 {
219 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *ug = c.update_granularity(); });
220 }
Botan::Cipher_Mode::update_granularity
virtual size_t update_granularity() const =0
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Initialize a cipher object

Definition at line 21 of file ffi_cipher.cpp.

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

22 {
23 return ffi_guard_thunk(__func__, [=]() -> int {
24 const bool encrypt_p = ((flags & BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION) == BOTAN_CIPHER_INIT_FLAG_ENCRYPT);
25 const Botan::Cipher_Dir dir = encrypt_p ? Botan::ENCRYPTION : Botan::DECRYPTION;
26 std::unique_ptr<Botan::Cipher_Mode> mode(Botan::Cipher_Mode::create(cipher_name, dir));
27 if(!mode)
28 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
29 *cipher = new botan_cipher_struct(mode.release());
30 return BOTAN_FFI_SUCCESS;
31 });
32 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_CIPHER_INIT_FLAG_ENCRYPT
#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT
Definition: ffi.h:425
BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
Definition: ffi.h:424
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::DECRYPTION
Definition: cipher_mode.h:23
Botan::Cipher_Mode::create
static std::unique_ptr< Cipher_Mode > create(const std::string &algo, Cipher_Dir direction, const std::string &provider="")
Definition: cipher_mode.cpp:54
Botan::Cipher_Dir
Cipher_Dir
Definition: cipher_mode.h:23
Botan::ENCRYPTION
Definition: cipher_mode.h:23
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Return the name of the cipher object

Definition at line 227 of file ffi_cipher.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

228 {
229 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
230 return write_str_output(name, name_len, c.name()); });
231 }
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
name
std::string name
Definition: commoncrypto_hash.cpp:23
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::Cipher_Mode::output_length().

50 {
51 if(out_len == nullptr)
52 return BOTAN_FFI_ERROR_NULL_POINTER;
53
54 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *out_len = c.output_length(in_len); });
55 }
Botan::Cipher_Mode::output_length
virtual size_t output_length(size_t input_length) const =0
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_cipher_query_keylen | ( | botan_cipher_t | ,
|  | size_t * | out_minimum_keylength,
|  | size_t * | out_maximum_keylength
| ) |  |

Get information about the key lengths. Prefer botan_cipher_get_keyspec

Definition at line 57 of file ffi_cipher.cpp.

References BOTAN_FFI_DO, Botan::SymmetricAlgorithm::key_spec(), and Botan::Key_Length_Specification::minimum_keylength().

60 {
61 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
62 *out_minimum_keylength = c.key_spec().minimum_keylength();
63 *out_maximum_keylength = c.key_spec().maximum_keylength();
64 });
65 }
Botan::Key_Length_Specification::minimum_keylength
size_t minimum_keylength() const
Definition: key_spec.h:61
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

References BOTAN_FFI_DO, and Botan::Cipher_Mode::reset().

45 {
46 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { c.reset(); });
47 }
Botan::Cipher_Mode::reset
virtual void reset()=0
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_RETURNING, and BOTAN_FFI_SUCCESS.

194 {
195 return BOTAN_FFI_RETURNING(Botan::Cipher_Mode, cipher, c, {
196 if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(&c))
197 {
198 aead->set_associated_data(ad, ad_len);
199 return BOTAN_FFI_SUCCESS;
200 }
201 return BOTAN_FFI_ERROR_BAD_PARAMETER;
202 });
203 }
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
Botan::AEAD_Mode
Definition: aead.h:22
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

References BOTAN_FFI_DO, and Botan::SymmetricAlgorithm::set_key().

84 {
85 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { c.set_key(key, key_len); });
86 }
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:65
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

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

90 {
91 return ffi_guard_thunk(__func__, [=]() -> int {
92 Botan::Cipher_Mode& cipher = safe_get(cipher_obj);
93 cipher.start(nonce, nonce_len);
94 cipher_obj->m_buf.reserve(cipher.update_granularity());
95 return BOTAN_FFI_SUCCESS;
96 });
97 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::Cipher_Mode::update_granularity
virtual size_t update_granularity() const =0
Botan::Cipher_Mode::start
void start(const std::vector< uint8_t, Alloc > &nonce)
Definition: cipher_mode.h:69
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Encrypt some data

Definition at line 99 of file ffi_cipher.cpp.

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

107 {
108 return ffi_guard_thunk(__func__, [=]() -> int {
109
110 size_t input_size = orig_input_size;
111 size_t output_size = orig_output_size;
112 const uint8_t* input = input_ptr;
113 uint8_t* output = output_ptr;
114
115 using namespace Botan;
116 Cipher_Mode& cipher = safe_get(cipher_obj);
117 secure_vector<uint8_t>& mbuf = cipher_obj->m_buf;
118
119 const bool final_input = (flags & BOTAN_CIPHER_UPDATE_FLAG_FINAL);
120
121 if(final_input)
122 {
123 mbuf.assign(input, input + input_size);
124 *input_consumed = input_size;
125 *output_written = 0;
126
127 try
128 {
129 cipher.finish(mbuf);
130 }
131 catch(Invalid_Authentication_Tag&)
132 {
133 return BOTAN_FFI_ERROR_BAD_MAC;
134 }
135
136 *output_written = mbuf.size();
137
138 if(mbuf.size() <= output_size)
139 {
140 copy_mem(output, mbuf.data(), mbuf.size());
141 mbuf.clear();
142 return BOTAN_FFI_SUCCESS;
143 }
144
145 return -1;
146 }
147
148 if(input_size == 0)
149 {
150 // Currently must take entire buffer in this case
151 *output_written = mbuf.size();
152 if(output_size >= mbuf.size())
153 {
154 copy_mem(output, mbuf.data(), mbuf.size());
155 mbuf.clear();
156 return BOTAN_FFI_SUCCESS;
157 }
158
159 return -1;
160 }
161
162 const size_t ud = cipher.update_granularity();
163 BOTAN_ASSERT(cipher.update_granularity() > cipher.minimum_final_size(), "logic error");
164
165 mbuf.resize(ud);
166 size_t taken = 0, written = 0;
167
168 while(input_size >= ud && output_size >= ud)
169 {
170 // FIXME we can use process here and avoid the copy
171 copy_mem(mbuf.data(), input, ud);
172 cipher.update(mbuf);
173
174 input_size -= ud;
175 copy_mem(output, mbuf.data(), ud);
176 input += ud;
177 taken += ud;
178
179 output_size -= ud;
180 output += ud;
181 written += ud;
182 }
183
184 *output_written = written;
185 *input_consumed = taken;
186
187 return BOTAN_FFI_SUCCESS;
188 });
189 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::Cipher_Mode::update
void update(secure_vector< uint8_t > &buffer, size_t offset=0)
Definition: cipher_mode.h:112
Botan::Cipher_Mode::update_granularity
virtual size_t update_granularity() const =0
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
Botan::Cipher_Mode::minimum_final_size
virtual size_t minimum_final_size() const =0
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:55
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
BOTAN_CIPHER_UPDATE_FLAG_FINAL
#define BOTAN_CIPHER_UPDATE_FLAG_FINAL
Definition: ffi.h:507
BOTAN_FFI_ERROR_BAD_MAC
Definition: ffi.h:66
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:132
Botan
Definition: alg_id.cpp:13
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
Botan::Cipher_Mode
Definition: cipher_mode.h:28
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
Botan::Invalid_Authentication_Tag
Definition: exceptn.h:290
Botan::Cipher_Mode::finish
virtual void finish(secure_vector< uint8_t > &final_block, size_t offset=0)=0

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

References BOTAN_FFI_RETURNING, and Botan::Cipher_Mode::valid_nonce_length().

206 {
207 return BOTAN_FFI_RETURNING(Botan::Cipher_Mode, cipher, c, {
208 return c.valid_nonce_length(nl) ? 1 : 0;
209 });
210 }
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan::Cipher_Mode
Definition: cipher_mode.h:28
Botan::Cipher_Mode::valid_nonce_length
virtual bool valid_nonce_length(size_t nonce_len) const =0

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

References Botan::constant_time_compare().

Referenced by botan_same_mem().

238 {
239 return Botan::constant_time_compare(x, y, len) ? 0 : -1;
240 }
Botan::constant_time_compare
bool constant_time_compare(const uint8_t x[], const uint8_t y[], size_t len)
Definition: mem_ops.h:82

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

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

126 {
127 switch(err)
128 {
129 case BOTAN_FFI_SUCCESS:
130 return "OK";
131
132 case BOTAN_FFI_INVALID_VERIFIER:
133 return "Invalid verifier";
134
135 case BOTAN_FFI_ERROR_INVALID_INPUT:
136 return "Invalid input";
137
138 case BOTAN_FFI_ERROR_BAD_MAC:
139 return "Invalid authentication code";
140
141 case BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE:
142 return "Insufficient buffer space";
143
144 case BOTAN_FFI_ERROR_EXCEPTION_THROWN:
145 return "Exception thrown";
146
147 case BOTAN_FFI_ERROR_OUT_OF_MEMORY:
148 return "Out of memory";
149
150 case BOTAN_FFI_ERROR_SYSTEM_ERROR:
151 return "Error while calling system API";
152
153 case BOTAN_FFI_ERROR_INTERNAL_ERROR:
154 return "Internal error";
155
156 case BOTAN_FFI_ERROR_BAD_FLAG:
157 return "Bad flag";
158
159 case BOTAN_FFI_ERROR_NULL_POINTER:
160 return "Null pointer argument";
161
162 case BOTAN_FFI_ERROR_BAD_PARAMETER:
163 return "Bad parameter";
164
165 case BOTAN_FFI_ERROR_KEY_NOT_SET:
166 return "Key not set on object";
167
168 case BOTAN_FFI_ERROR_INVALID_KEY_LENGTH:
169 return "Invalid key length";
170
171 case BOTAN_FFI_ERROR_INVALID_OBJECT_STATE:
172 return "Invalid object state";
173
174 case BOTAN_FFI_ERROR_NOT_IMPLEMENTED:
175 return "Not implemented";
176
177 case BOTAN_FFI_ERROR_INVALID_OBJECT:
178 return "Invalid object handle";
179
180 case BOTAN_FFI_ERROR_TLS_ERROR:
181 return "TLS error";
182
183 case BOTAN_FFI_ERROR_HTTP_ERROR:
184 return "HTTP error";
185
186 case BOTAN_FFI_ERROR_UNKNOWN_ERROR:
187 return "Unknown error";
188 }
189
190 return "Unknown error";
191 }
BOTAN_FFI_ERROR_OUT_OF_MEMORY
Definition: ffi.h:71
BOTAN_FFI_ERROR_INVALID_INPUT
Definition: ffi.h:65
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:70
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_ERROR_BAD_MAC
Definition: ffi.h:66
BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:68
BOTAN_FFI_ERROR_INTERNAL_ERROR
Definition: ffi.h:73
BOTAN_FFI_ERROR_INVALID_KEY_LENGTH
Definition: ffi.h:79
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
Definition: ffi.h:80
BOTAN_FFI_ERROR_SYSTEM_ERROR
Definition: ffi.h:72
BOTAN_FFI_ERROR_HTTP_ERROR
Definition: ffi.h:86
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_ERROR_TLS_ERROR
Definition: ffi.h:85
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_ERROR_KEY_NOT_SET
Definition: ffi.h:78
BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:63
BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:89
BOTAN_FFI_ERROR_INVALID_OBJECT
Definition: ffi.h:83

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

197 {
198 return BOTAN_HAS_FFI;
199 }

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

References BOTAN_FFI_SUCCESS.

202 {
203 // This is the API introduced in 2.13
204 if(api_version == 20191214)
205 return BOTAN_FFI_SUCCESS;
206
207 // This is the API introduced in 2.8
208 if(api_version == 20180713)
209 return BOTAN_FFI_SUCCESS;
210
211 // This is the API introduced in 2.3
212 if(api_version == 20170815)
213 return BOTAN_FFI_SUCCESS;
214
215 // This is the API introduced in 2.1
216 if(api_version == 20170327)
217 return BOTAN_FFI_SUCCESS;
218
219 // This is the API introduced in 2.0
220 if(api_version == 20150515)
221 return BOTAN_FFI_SUCCESS;
222
223 // Something else:
224 return -1;
225 }
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 80 of file ffi_fpe.cpp.

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

81 {
82 #if defined(BOTAN_HAS_FPE_FE1)
83 return ffi_guard_thunk(__func__, [=]() {
84 Botan::BigInt r = safe_get(fpe).decrypt(safe_get(x), tweak, tweak_len);
85 safe_get(x) = r;
86 return BOTAN_FFI_SUCCESS;
87 });
88
89 #else
90 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
91 #endif
92 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_fpe_destroy | ( | botan_fpe_t | fpe | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 58 of file ffi_fpe.cpp.

References BOTAN_FFI_CHECKED_DELETE, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

59 {
60 #if defined(BOTAN_HAS_FPE_FE1)
61 return BOTAN_FFI_CHECKED_DELETE(fpe);
62 #else
63 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
64 #endif
65 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

Definition at line 67 of file ffi_fpe.cpp.

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

68 {
69 #if defined(BOTAN_HAS_FPE_FE1)
70 return ffi_guard_thunk(__func__, [=]() {
71 Botan::BigInt r = safe_get(fpe).encrypt(safe_get(x), tweak, tweak_len);
72 safe_get(x) = r;
73 return BOTAN_FFI_SUCCESS;
74 });
75 #else
76 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
77 #endif
78 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 26 of file ffi_fpe.cpp.

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

29 {
30 #if defined(BOTAN_HAS_FPE_FE1)
31
32 return ffi_guard_thunk(__func__, [=]() {
33
34 if(fpe == nullptr || key == nullptr)
35 return BOTAN_FFI_ERROR_NULL_POINTER;
36
37 *fpe = nullptr;
38
39 if(flags != 0 && flags != BOTAN_FPE_FLAG_FE1_COMPAT_MODE)
40 return BOTAN_FFI_ERROR_BAD_FLAG;
41
42 const bool compat_mode = (flags & BOTAN_FPE_FLAG_FE1_COMPAT_MODE);
43
44 std::unique_ptr<Botan::FPE_FE1> fpe_obj(
45 new Botan::FPE_FE1(safe_get(n), rounds, compat_mode));
46
47 fpe_obj->set_key(key, key_len);
48
49 *fpe = new botan_fpe_struct(fpe_obj.release());
50 return BOTAN_FFI_SUCCESS;
51 });
52 #else
53 *fpe = nullptr;
54 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
55 #endif
56 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::FPE_FE1
Definition: fpe_fe1.h:24
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FPE_FLAG_FE1_COMPAT_MODE
#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE
Definition: ffi.h:1737
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

  hash | hash object
  block_size | output buffer to hold the hash function output length

Returns
  0 on success, a negative value on failure

Definition at line 46 of file ffi_hash.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::HashFunction::hash_block_size().

47 {
48 if(out == nullptr)
49 return BOTAN_FFI_ERROR_NULL_POINTER;
50 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { *out = h.hash_block_size(); });
51 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::HashFunction
Definition: hash.h:20
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

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

  hash | hash object

Returns
  0 on success, a negative value on failure

Definition at line 53 of file ffi_hash.cpp.

References BOTAN_FFI_DO, and Botan::HashFunction::clear().

54 {
55 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.clear(); });
56 }
Botan::HashFunction
Definition: hash.h:20
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

int botan_hash_copy_state | ( | botan_hash_t * | dest,
|  | const botan_hash_t | source
| ) |  |

Copy the state of a hash function object

Parameters

  dest | destination hash object
  source | source hash object

Returns
  0 on success, a negative value on failure

Definition at line 76 of file ffi_hash.cpp.

References BOTAN_FFI_DO.

77 {
78 return BOTAN_FFI_DO(Botan::HashFunction, source, src, {
79 *dest = new botan_hash_struct(src.copy_state().release()); });
80 }
Botan::HashFunction
Definition: hash.h:20
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_hash_destroy | ( | botan_hash_t | hash | ) |

Frees all resources of the hash object

Parameters

  hash | hash object

Returns
  0 if success, error if invalid object handle

Definition at line 34 of file ffi_hash.cpp.

References BOTAN_FFI_CHECKED_DELETE.

35 {
36 return BOTAN_FFI_CHECKED_DELETE(hash);
37 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

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

  hash | hash object
  out | output buffer

Returns
  0 on success, a negative value on failure

Definition at line 69 of file ffi_hash.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::Buffered_Computation::final().

70 {
71 if(out == nullptr)
72 return BOTAN_FFI_ERROR_NULL_POINTER;
73 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.final(out); });
74 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::HashFunction
Definition: hash.h:20
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

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

Initialize a hash function object

Parameters

  hash | hash object
  hash_name | name of the hash function, e.g., "SHA-384"
  flags | should be 0 in current API revision, all other uses are reserved and return BOTAN_FFI_ERROR_BAD_FLAG

Definition at line 17 of file ffi_hash.cpp.

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

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(hash == nullptr || hash_name == nullptr || *hash_name == 0)
21 return BOTAN_FFI_ERROR_NULL_POINTER;
22 if(flags != 0)
23 return BOTAN_FFI_ERROR_BAD_FLAG;
24
25 std::unique_ptr<Botan::HashFunction> h = Botan::HashFunction::create(hash_name);
26 if(h == nullptr)
27 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
28
29 *hash = new botan_hash_struct(h.release());
30 return BOTAN_FFI_SUCCESS;
31 });
32 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:106
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

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

Get the name of this hash function

Parameters

  hash | the object to read
  name | output buffer
  name_len | on input, the length of buffer, on success the number of bytes written

Definition at line 82 of file ffi_hash.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan_FFI::write_str_output().

83 {
84 if(name_len == nullptr)
85 return BOTAN_FFI_ERROR_NULL_POINTER;
86
87 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, {
88 return write_str_output(name, name_len, h.name()); });
89 }
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
name
std::string name
Definition: commoncrypto_hash.cpp:23
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::HashFunction
Definition: hash.h:20
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

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

  hash | hash object
  output_length | output buffer to hold the hash function output length

Returns
  0 on success, a negative value on failure

Definition at line 39 of file ffi_hash.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::Buffered_Computation::output_length().

40 {
41 if(out == nullptr)
42 return BOTAN_FFI_ERROR_NULL_POINTER;
43 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { *out = h.output_length(); });
44 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::HashFunction
Definition: hash.h:20
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

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

Send more input to the hash function

Parameters

  hash | hash object
  in | input buffer
  in_len | number of bytes to read from the input buffer

Returns
  0 on success, a negative value on failure

Definition at line 58 of file ffi_hash.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::Buffered_Computation::update().

59 {
60 if(len == 0)
61 return 0;
62
63 if(buf == nullptr)
64 return BOTAN_FFI_ERROR_NULL_POINTER;
65
66 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.update(buf, len); });
67 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::HashFunction
Definition: hash.h:20
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

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

Perform hex decoding

Parameters

  hex_str | a string of hex chars (whitespace is ignored)
  in_len | the length of hex_str
  out | the output buffer should be at least strlen(hex_str)/2 bytes
  out_len | the size of out

Definition at line 262 of file ffi.cpp.

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

263 {
264 return ffi_guard_thunk(__func__, [=]() -> int {
265 const std::vector<uint8_t> bin = Botan::hex_decode(hex_str, in_len);
266 return Botan_FFI::write_vec_output(out, out_len, bin);
267 });
268 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::hex_decode
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition: hex.cpp:49

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

Perform hex encoding

Parameters

  x | is some binary data
  len | length of x in bytes
  out | an array of at least x*2 bytes
  flags | flags out be upper or lower case?

Returns
  0 on success, 1 on failure

Definition at line 253 of file ffi.cpp.

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

254 {
255 return ffi_guard_thunk(__func__, [=]() -> int {
256 const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
257 Botan::hex_encode(out, in, len, uppercase);
258 return BOTAN_FFI_SUCCESS;
259 });
260 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::hex_encode
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_HEX_LOWER_CASE
#define BOTAN_FFI_HEX_LOWER_CASE
Definition: ffi.h:153
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_RETURNING, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan::HOTP::verify_hotp().

81 {
82 #if defined(BOTAN_HAS_HOTP)
83 return BOTAN_FFI_RETURNING(Botan::HOTP, hotp, h, {
84
85 auto resp = h.verify_hotp(hotp_code, hotp_counter, resync_range);
86
87 if(next_hotp_counter)
88 *next_hotp_counter = resp.second;
89
90 return (resp.first == true) ? BOTAN_FFI_SUCCESS : BOTAN_FFI_INVALID_VERIFIER;
91 });
92
93 #else
94 BOTAN_UNUSED(hotp, next_hotp_counter, hotp_code, hotp_counter, resync_range);
95 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
96 #endif
97 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan::HOTP
Definition: hotp.h:18
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::HOTP::verify_hotp
std::pair< bool, uint64_t > verify_hotp(uint32_t otp, uint64_t starting_counter, size_t resync_range=0)
Definition: hotp.cpp:52
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:63

int botan_hotp_destroy | ( | botan_hotp_t | hotp | ) |

Destroy a HOTP instance

Returns
  0 if success, error if invalid object handle

Definition at line 48 of file ffi_hotp.cpp.

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

49 {
50 #if defined(BOTAN_HAS_HOTP)
51 return BOTAN_FFI_CHECKED_DELETE(hotp);
52 #else
53 BOTAN_UNUSED(hotp);
54 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
55 #endif
56 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142

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

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, and Botan::HOTP::generate_hotp().

61 {
62 #if defined(BOTAN_HAS_HOTP)
63 if(hotp == nullptr || hotp_code == nullptr)
64 return BOTAN_FFI_ERROR_NULL_POINTER;
65
66 return BOTAN_FFI_DO(Botan::HOTP, hotp, h, {
67 *hotp_code = h.generate_hotp(hotp_counter);
68 });
69
70 #else
71 BOTAN_UNUSED(hotp, hotp_code, hotp_counter);
72 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
73 #endif
74 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::HOTP
Definition: hotp.h:18
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::HOTP::generate_hotp
uint32_t generate_hotp(uint64_t counter)
Definition: hotp.cpp:42

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

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

28 {
29 if(hotp == nullptr || key == nullptr || hash_algo == nullptr)
30 return BOTAN_FFI_ERROR_NULL_POINTER;
31
32 *hotp = nullptr;
33
34 #if defined(BOTAN_HAS_HOTP)
35 return ffi_guard_thunk(__func__, [=]() -> int {
36
37 *hotp = new botan_hotp_struct(
38 new Botan::HOTP(key, key_len, hash_algo, digits));
39
40 return BOTAN_FFI_SUCCESS;
41 });
42 #else
43 BOTAN_UNUSED(hotp, key, key_len, hash_algo, digits);
44 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
45 #endif
46 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::HOTP
Definition: hotp.h:18
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
hash_algo
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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_algo | KDF algorithm, e.g., "SP800-56C"
  out | buffer holding the derived key, must be of length out_len
  out_len | the desired output length in bytes
  secret | the secret input
  secret_len | size of secret in bytes
  salt | a diversifier
  salt_len | size of salt in bytes
  label | purpose for the derived keying material
  label_len | size of label in bytes

Returns
  0 on success, a negative value on failure

Definition at line 129 of file ffi_kdf.cpp.

References BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan::get_kdf().

134 {
135 return ffi_guard_thunk(__func__, [=]() -> int {
136 std::unique_ptr<Botan::KDF> kdf(Botan::get_kdf(kdf_algo));
137 kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
138 return BOTAN_FFI_SUCCESS;
139 });
140 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::get_kdf
KDF * get_kdf(const std::string &algo_spec)
Definition: kdf.cpp:241
salt_len
size_t salt_len
Definition: x509_obj.cpp:25
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 34 of file ffi_keywrap.cpp.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, Botan_FFI::ffi_guard_thunk(), Botan::rfc3394_keyunwrap(), and Botan_FFI::write_vec_output().

37 {
38 #if defined(BOTAN_HAS_RFC3394_KEYWRAP)
39 return ffi_guard_thunk(__func__, [=]() -> int {
40 const Botan::SymmetricKey kek_sym(kek, kek_len);
41 const Botan::secure_vector<uint8_t> key_ct(wrapped_key, wrapped_key + wrapped_key_len);
42 const Botan::secure_vector<uint8_t> key_pt = Botan::rfc3394_keyunwrap(key_ct, kek_sym);
43 return write_vec_output(key, key_len, key_pt);
44 });
45 #else
46 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
47 #endif
48 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::OctetString
Definition: symkey.h:19
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::rfc3394_keyunwrap
secure_vector< uint8_t > rfc3394_keyunwrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:28

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, Botan_FFI::ffi_guard_thunk(), Botan::rfc3394_keywrap(), and Botan_FFI::write_vec_output().

21 {
22 #if defined(BOTAN_HAS_RFC3394_KEYWRAP)
23 return ffi_guard_thunk(__func__, [=]() -> int {
24 const Botan::SymmetricKey kek_sym(kek, kek_len);
25 const Botan::secure_vector<uint8_t> key_pt(key, key + key_len);
26 const Botan::secure_vector<uint8_t> key_ct = Botan::rfc3394_keywrap(key_pt, kek_sym);
27 return write_vec_output(wrapped_key, wrapped_key_len, key_ct);
28 });
29 #else
30 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
31 #endif
32 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::OctetString
Definition: symkey.h:19
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::rfc3394_keywrap
secure_vector< uint8_t > rfc3394_keywrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:14

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

  mac | mac object

Returns
  0 on success, a negative value on failure

Definition at line 49 of file ffi_mac.cpp.

References BOTAN_FFI_DO, and Botan::SymmetricAlgorithm::clear().

50 {
51 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.clear(); });
52 }
Botan::MessageAuthenticationCode
Definition: mac.h:21
Botan::SymmetricAlgorithm::clear
virtual void clear()=0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mac_destroy | ( | botan_mac_t | mac | ) |

Frees all resources of the MAC object

Parameters

  mac | mac object

Returns
  0 if success, error if invalid object handle

Definition at line 34 of file ffi_mac.cpp.

References BOTAN_FFI_CHECKED_DELETE.

35 {
36 return BOTAN_FFI_CHECKED_DELETE(mac);
37 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

  mac | mac object
  out | output buffer

Returns
  0 on success, a negative value on failure

Definition at line 59 of file ffi_mac.cpp.

References BOTAN_FFI_DO, and Botan::Buffered_Computation::final().

60 {
61 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.final(out); });
62 }
Botan::MessageAuthenticationCode
Definition: mac.h:21
Botan::Buffered_Computation::final
void final(uint8_t out[])
Definition: buf_comp.h:83
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

  mac | the object to read
  out_minimum_keylength | if non-NULL, will be set to minimum keylength of MAC
  out_maximum_keylength | if non-NULL, will be set to maximum keylength of MAC
  out_keylength_modulo | if non-NULL will be set to byte multiple of valid keys

Definition at line 70 of file ffi_mac.cpp.

References BOTAN_FFI_DO, and Botan::SymmetricAlgorithm::minimum_keylength().

74 {
75 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, {
76 if(out_minimum_keylength)
77 *out_minimum_keylength = m.minimum_keylength();
78 if(out_maximum_keylength)
79 *out_maximum_keylength = m.maximum_keylength();
80 if(out_keylength_modulo)
81 *out_keylength_modulo = m.key_spec().keylength_multiple();
82 });
83 }
Botan::MessageAuthenticationCode
Definition: mac.h:21
Botan::SymmetricAlgorithm::minimum_keylength
size_t minimum_keylength() const
Definition: sym_algo.h:46
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Initialize a message authentication code object

Parameters

  mac | mac object
  mac_name | name of the hash function, e.g., "HMAC(SHA-384)"
  flags | should 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 17 of file ffi_mac.cpp.

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

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(!mac || !mac_name || flags != 0)
21 return BOTAN_FFI_ERROR_NULL_POINTER;
22
23 std::unique_ptr<Botan::MessageAuthenticationCode> m =
24 Botan::MessageAuthenticationCode::create(mac_name);
25
26 if(m == nullptr)
27 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
28
29 *mac = new botan_mac_struct(m.release());
30 return BOTAN_FFI_SUCCESS;
31 });
32 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::MessageAuthenticationCode::create
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
Definition: mac.cpp:46
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Get the name of this MAC

Parameters

  mac | the object to read
  name | output buffer
  name_len | on input, the length of buffer, on success the number of bytes written

Definition at line 64 of file ffi_mac.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

65 {
66 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, {
67 return write_str_output(name, name_len, m.name()); });
68 }
Botan::MessageAuthenticationCode
Definition: mac.h:21
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
name
std::string name
Definition: commoncrypto_hash.cpp:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

  mac | mac object
  output_length | output buffer to hold the MAC output length

Returns
  0 on success, a negative value on failure

Definition at line 44 of file ffi_mac.cpp.

References BOTAN_FFI_DO, and Botan::Buffered_Computation::output_length().

45 {
46 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { *out = m.output_length(); });
47 }
Botan::MessageAuthenticationCode
Definition: mac.h:21
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

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

Sets the key on the MAC

Parameters

  mac | mac object
  key | buffer holding the key
  key_len | size of the key buffer in bytes

Returns
  0 on success, a negative value on failure

Definition at line 39 of file ffi_mac.cpp.

References BOTAN_FFI_DO, and Botan::SymmetricAlgorithm::set_key().

40 {
41 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.set_key(key, key_len); });
42 }
Botan::MessageAuthenticationCode
Definition: mac.h:21
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:65
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Send more input to the message authentication code

Parameters

  mac | mac object
  buf | input buffer
  len | number of bytes to read from the input buffer

Returns
  0 on success, a negative value on failure

Definition at line 54 of file ffi_mac.cpp.

References BOTAN_FFI_DO, and Botan::Buffered_Computation::update().

55 {
56 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.update(buf, len); });
57 }
Botan::MessageAuthenticationCode
Definition: mac.h:21
Botan::Buffered_Computation::update
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:33
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 934 of file ffi_pkey_algs.cpp.

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, Botan_FFI::ffi_guard_thunk(), Botan::mceies_decrypt(), Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

939 {
940 return ffi_guard_thunk(__func__, [=]() -> int {
941 Botan::Private_Key& key = safe_get(mce_key_obj);
942
943 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
944 Botan::McEliece_PrivateKey* mce = dynamic_cast<Botan::McEliece_PrivateKey*>(&key);
945 if(!mce)
946 return BOTAN_FFI_ERROR_BAD_PARAMETER;
947
948 const Botan::secure_vector<uint8_t> pt = mceies_decrypt(*mce, ct, ct_len, ad, ad_len, aead);
949 return write_vec_output(out, out_len, pt);
950 #else
951 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
952 #endif
953 });
954 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::McEliece_PrivateKey
Definition: mceliece.h:70
Botan::mceies_decrypt
secure_vector< uint8_t > mceies_decrypt(const McEliece_PrivateKey &privkey, const uint8_t ct[], size_t ct_len, const uint8_t ad[], size_t ad_len, const std::string &algo)
Definition: mceies.cpp:70
Botan::Private_Key
Definition: pk_keys.h:181
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61

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

Definition at line 956 of file ffi_pkey_algs.cpp.

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, Botan_FFI::ffi_guard_thunk(), Botan::mceies_encrypt(), Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

962 {
963 return ffi_guard_thunk(__func__, [=]() -> int {
964 Botan::Public_Key& key = safe_get(mce_key_obj);
965 Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
966
967 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
968 Botan::McEliece_PublicKey* mce = dynamic_cast<Botan::McEliece_PublicKey*>(&key);
969 if(!mce)
970 return BOTAN_FFI_ERROR_BAD_PARAMETER;
971
972 Botan::secure_vector<uint8_t> ct = mceies_encrypt(*mce, pt, pt_len, ad, ad_len, rng, aead);
973 return write_vec_output(out, out_len, ct);
974 #else
975 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
976 #endif
977 });
978 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::RandomNumberGenerator
Definition: rng.h:24
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::mceies_encrypt
secure_vector< uint8_t > mceies_encrypt(const McEliece_PublicKey &pubkey, const uint8_t pt[], size_t pt_len, const uint8_t ad[], size_t ad_len, RandomNumberGenerator &rng, const std::string &algo)
Definition: mceies.cpp:35
Botan::Public_Key
Definition: pk_keys.h:29
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
Botan::McEliece_PublicKey
Definition: mceliece.h:21

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

Definition at line 139 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

140 {
141 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
142 if(result == x)
143 res += safe_get(y);
144 else
145 res = safe_get(x) + safe_get(y);
146 });
147 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 159 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

160 {
161 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
162 if(result == x)
163 res += static_cast<Botan::word>(y);
164 else
165 res = safe_get(x) + static_cast<Botan::word>(y);
166 });
167 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_clear | ( | botan_mp_t | mp | ) |

Set the MPI to zero

Definition at line 31 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan::BigInt::clear().

32 {
33 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.clear(); });
34 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::clear
void clear()
Definition: bigint.h:364
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_clear_bit | ( | botan_mp_t | n,
|  | size_t | bit
| ) |  |

Clear the specified bit

Definition at line 297 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan::BigInt::clear_bit().

298 {
299 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.clear_bit(bit); });
300 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::clear_bit
void clear_bit(size_t n)
Definition: bigint.cpp:262
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 220 of file ffi_mp.cpp.

References BOTAN_FFI_DO, Botan::BigInt::cmp(), and Botan_FFI::safe_get().

221 {
222 return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { *result = x.cmp(safe_get(y_w)); });
223 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::cmp
int32_t cmp(const BigInt &n, bool check_signs=true) const
Definition: bigint.cpp:131
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_destroy | ( | botan_mp_t | mp | ) |

Destroy (deallocate) an MPI

Returns
  0 if success, error if invalid object handle

Definition at line 134 of file ffi_mp.cpp.

References BOTAN_FFI_CHECKED_DELETE.

135 {
136 return BOTAN_FFI_CHECKED_DELETE(mp);
137 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

Definition at line 189 of file ffi_mp.cpp.

References BOTAN_FFI_DO, Botan::divide(), and Botan_FFI::safe_get().

192 {
193 return BOTAN_FFI_DO(Botan::BigInt, quotient, q, {
194 Botan::BigInt r;
195 Botan::divide(safe_get(x), safe_get(y), q, r);
196 safe_get(remainder) = r;
197 });
198 }
Botan::BigInt
Definition: bigint.h:24
Botan::divide
void divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition: divide.cpp:159
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_equal | ( | const botan_mp_t | x,
|  | const botan_mp_t | y
| ) |  |

Definition at line 200 of file ffi_mp.cpp.

References BOTAN_FFI_RETURNING, and Botan_FFI::safe_get().

201 {
202 return BOTAN_FFI_RETURNING(Botan::BigInt, x_w, x, { return x == safe_get(y_w); });
203 }
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61

int botan_mp_flip_sign | ( | botan_mp_t | mp | ) |

Definition at line 89 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan::BigInt::flip_sign().

90 {
91 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.flip_sign(); });
92 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::flip_sign
void flip_sign()
Definition: bigint.h:552
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 94 of file ffi_mp.cpp.

References Botan::BigInt::binary_decode(), and BOTAN_FFI_DO.

95 {
96 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_decode(bin, bin_len); });
97 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::binary_decode
void binary_decode(const uint8_t buf[], size_t length)
Definition: bigint.cpp:424
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 275 of file ffi_mp.cpp.

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

276 {
277 return BOTAN_FFI_DO(Botan::BigInt, out, o, {
278 o = Botan::gcd(safe_get(x), safe_get(y)); });
279 }
Botan::BigInt
Definition: bigint.h:24
Botan::gcd
BigInt gcd(const BigInt &a, const BigInt &b)
Definition: numthry.cpp:66
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_get_bit | ( | const 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 287 of file ffi_mp.cpp.

References BOTAN_FFI_RETURNING.

288 {
289 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, n, { return (n.get_bit(bit)); });
290 }
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101

int botan_mp_init | ( | botan_mp_t * | mp | ) |

Initialize an MPI

Definition at line 20 of file ffi_mp.cpp.

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

21 {
22 return ffi_guard_thunk(__func__, [=]() -> int {
23 if(mp_out == nullptr)
24 return BOTAN_FFI_ERROR_NULL_POINTER;
25
26 *mp_out = new botan_mp_struct(new Botan::BigInt);
27 return BOTAN_FFI_SUCCESS;
28 });
29 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_mp_is_even | ( | const botan_mp_t | mp | ) |

Definition at line 215 of file ffi_mp.cpp.

References BOTAN_FFI_RETURNING, and Botan::BigInt::is_even().

216 {
217 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_even(); });
218 }
Botan::BigInt::is_even
bool is_even() const
Definition: bigint.h:401
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101

int botan_mp_is_negative | ( | const botan_mp_t | mp | ) |

Return 1 iff mp is less than 0

Definition at line 79 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan::BigInt::is_negative().

80 {
81 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_negative() ? 1 : 0; });
82 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::is_negative
bool is_negative() const
Definition: bigint.h:525
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_is_odd | ( | const botan_mp_t | mp | ) |

Definition at line 210 of file ffi_mp.cpp.

References BOTAN_FFI_RETURNING, and Botan::BigInt::is_odd().

211 {
212 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_odd(); });
213 }
Botan::BigInt::is_odd
bool is_odd() const
Definition: bigint.h:407
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101

int botan_mp_is_positive | ( | const 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 84 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan::BigInt::is_positive().

85 {
86 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_positive() ? 1 : 0; });
87 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::is_positive
bool is_positive() const
Definition: bigint.h:531
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_is_prime | ( | const 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 281 of file ffi_mp.cpp.

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

282 {
283 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, n,
284 { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; });
285 }
Botan::BigInt
Definition: bigint.h:24
Botan::is_prime
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition: numthry.cpp:528
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61

int botan_mp_is_zero | ( | const botan_mp_t | mp | ) |

Definition at line 205 of file ffi_mp.cpp.

References BOTAN_FFI_RETURNING, and Botan::BigInt::is_zero().

206 {
207 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_zero(); });
208 }
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan::BigInt::is_zero
bool is_zero() const
Definition: bigint.h:419

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

Definition at line 237 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

238 {
239 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) << shift; });
240 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 247 of file ffi_mp.cpp.

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

248 {
249 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); });
250 }
Botan::BigInt
Definition: bigint.h:24
Botan::inverse_mod
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:325
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 252 of file ffi_mp.cpp.

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

253 {
254 return BOTAN_FFI_DO(Botan::BigInt, out, o, {
255 Botan::Modular_Reducer reducer(safe_get(modulus));
256 o = reducer.multiply(safe_get(x), safe_get(y));
257 });
258 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::Modular_Reducer
Definition: reducer.h:18

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

Definition at line 179 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

180 {
181 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
182 if(result == x)
183 res *= safe_get(y);
184 else
185 res = safe_get(x) * safe_get(y);
186 });
187 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_num_bits | ( | const 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.

References Botan::BigInt::bits(), and BOTAN_FFI_DO.

303 {
304 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bits = n.bits(); });
305 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::bits
size_t bits() const
Definition: bigint.cpp:288
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_num_bytes | ( | const botan_mp_t | n,
|  | size_t * | bytes
| ) |  |

Return the number of significant bytes in the MPI

Definition at line 307 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan::BigInt::bytes().

308 {
309 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bytes = n.bytes(); });
310 }
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BigInt::bytes
size_t bytes() const
Definition: bigint.cpp:273

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

Definition at line 231 of file ffi_mp.cpp.

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

232 {
233 return BOTAN_FFI_DO(Botan::BigInt, out, o,
234 { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
235 }
Botan::BigInt
Definition: bigint.h:24
Botan::power_mod
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:451
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 260 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

261 {
262 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, {
263 safe_get(rand_out).randomize(r, bits); });
264 }
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_rand_range | ( | botan_mp_t | rand_out,
|  | botan_rng_t | rng,
|  | const botan_mp_t | lower_bound,
|  | const botan_mp_t | upper_bound
| ) |  |

Definition at line 266 of file ffi_mp.cpp.

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

270 {
271 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, {
272 safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
273 }
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::BigInt::random_integer
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
Definition: big_rand.cpp:45
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 242 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

243 {
244 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) >> shift; });
245 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_set_bit | ( | botan_mp_t | n,
|  | size_t | bit
| ) |  |

Set the specified bit

Definition at line 292 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan::BigInt::set_bit().

293 {
294 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.set_bit(bit); });
295 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::set_bit
void set_bit(size_t n)
Definition: bigint.h:428
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_set_from_int | ( | botan_mp_t | mp,
|  | int | initial_value
| ) |  |

Set the MPI value from an int

Definition at line 36 of file ffi_mp.cpp.

References BOTAN_FFI_DO.

37 {
38 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
39 if(initial_value >= 0)
40 {
41 bn = Botan::BigInt(static_cast<uint64_t>(initial_value));
42 }
43 else
44 {
45 bn = Botan::BigInt(static_cast<uint64_t>(-initial_value));
46 bn.flip_sign();
47 }
48 });
49 }
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_set_from_mp | ( | botan_mp_t | dest,
|  | const botan_mp_t | source
| ) |  |

Set the MPI value from another MP object

Definition at line 74 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

75 {
76 return BOTAN_FFI_DO(Botan::BigInt, dest, bn, { bn = safe_get(source); });
77 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

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

57 {
58 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
59 Botan::BigInt::Base base;
60 if(radix == 10)
61 base = Botan::BigInt::Decimal;
62 else if(radix == 16)
63 base = Botan::BigInt::Hexadecimal;
64 else
65 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
66
67 const uint8_t* bytes = Botan::cast_char_ptr_to_uint8(str);
68 const size_t len = strlen(str);
69
70 bn = Botan::BigInt(bytes, len, base);
71 });
72 }
Botan::BigInt::Hexadecimal
Definition: bigint.h:30
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::Decimal
Definition: bigint.h:30
Botan::cast_char_ptr_to_uint8
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:189
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::BigInt::Base
Base
Definition: bigint.h:30
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Set the MPI value from a string

Definition at line 51 of file ffi_mp.cpp.

References BOTAN_FFI_DO.

52 {
53 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn = Botan::BigInt(str); });
54 }
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 149 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

150 {
151 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
152 if(result == x)
153 res -= safe_get(y);
154 else
155 res = safe_get(x) - safe_get(y);
156 });
157 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 169 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

170 {
171 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
172 if(result == x)
173 res -= static_cast<Botan::word>(y);
174 else
175 res = safe_get(x) - static_cast<Botan::word>(y);
176 });
177 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_swap | ( | botan_mp_t | x,
|  | botan_mp_t | y
| ) |  |

Definition at line 225 of file ffi_mp.cpp.

References BOTAN_FFI_DO, Botan_FFI::safe_get(), and Botan::BigInt::swap().

226 {
227 return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { x.swap(safe_get(y_w)); });
228 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::swap
void swap(BigInt &other)
Definition: bigint.h:159
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_to_bin | ( | const botan_mp_t | mp,
|  | uint8_t | vec[]
| ) |  |

Definition at line 120 of file ffi_mp.cpp.

References Botan::BigInt::binary_encode(), and BOTAN_FFI_DO.

121 {
122 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_encode(vec); });
123 }
Botan::BigInt::binary_encode
void binary_encode(uint8_t buf[]) const
Definition: bigint.cpp:391
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_mp_to_hex | ( | const botan_mp_t | mp,
|  | char * | out
| ) |  |

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

Definition at line 99 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan::BigInt::to_hex_string().

100 {
101 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
102 const std::string hex = bn.to_hex_string();
103 std::memcpy(out, hex.c_str(), 1 + hex.size());
104 });
105 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::to_hex_string
std::string to_hex_string() const
Definition: big_code.cpp:42
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

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

Definition at line 107 of file ffi_mp.cpp.

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

108 {
109 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, {
110
111 if(digit_base == 0 || digit_base == 10)
112 return write_str_output(out, out_len, bn.to_dec_string());
113 else if(digit_base == 16)
114 return write_str_output(out, out_len, bn.to_hex_string());
115 else
116 return BOTAN_FFI_ERROR_BAD_PARAMETER;
117 });
118 }
Botan::BigInt
Definition: bigint.h:24
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77

int botan_mp_to_uint32 | ( | const botan_mp_t | mp,
|  | uint32_t * | val
| ) |  |

Definition at line 125 of file ffi_mp.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::BigInt::to_u32bit().

126 {
127 if(val == nullptr)
128 {
129 return BOTAN_FFI_ERROR_NULL_POINTER;
130 }
131 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { *val = bn.to_u32bit(); });
132 }
Botan::BigInt
Definition: bigint.h:24
Botan::BigInt::to_u32bit
uint32_t to_u32bit() const
Definition: bigint.cpp:236
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 22 of file ffi_kdf.cpp.

References botan_pwdhash().

25 {
26 return botan_pwdhash(algo,
27 iterations,
28 0,
29 0,
30 out, out_len,
31 pass, 0,
32 salt, salt_len);
33 }
salt_len
size_t salt_len
Definition: x509_obj.cpp:25
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 *password, size_t password_len, const uint8_t salt[], size_t salt_len)
Definition: ffi_kdf.cpp:52

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_algo | PBKDF algorithm, e.g., "PBKDF2(SHA-256)"
  out | buffer to store the derived key, must be of out_len bytes
  out_len | the desired length of the key to produce
  passphrase | the password to derive the key from
  salt | a randomly chosen salt
  salt_len | length of salt in bytes
  milliseconds_to_run | if iterations is zero, then instead the PBKDF is run until milliseconds_to_run milliseconds has passed
  out_iterations_used | set 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 35 of file ffi_kdf.cpp.

References botan_pwdhash_timed().

41 {
42 return botan_pwdhash_timed(algo,
43 static_cast<uint32_t>(ms_to_run),
44 iterations_used,
45 nullptr,
46 nullptr,
47 out, out_len,
48 password, 0,
49 salt, salt_len);
50 }
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 *password, size_t password_len, const uint8_t salt[], size_t salt_len)
Definition: ffi_kdf.cpp:86
salt_len
size_t salt_len
Definition: x509_obj.cpp:25

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

Definition at line 100 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

103 {
104 return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, {
105 return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len));
106 });
107 }
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::PK_Decryptor
Definition: pubkey.h:84

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

Definition at line 68 of file ffi_pk_op.cpp.

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

72 {
73 if(op == nullptr)
74 return BOTAN_FFI_ERROR_NULL_POINTER;
75
76 if(flags != 0)
77 return BOTAN_FFI_ERROR_BAD_FLAG;
78
79 return ffi_guard_thunk(__func__, [=]() -> int {
80 *op = nullptr;
81
82 std::unique_ptr<Botan::PK_Decryptor> pk(new Botan::PK_Decryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
83 *op = new botan_pk_op_decrypt_struct(pk.release());
84 return BOTAN_FFI_SUCCESS;
85 });
86 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::system_rng
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:279
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
Botan::PK_Decryptor_EME
Definition: pubkey.h:579
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_pk_op_decrypt_destroy | ( | botan_pk_op_decrypt_t | op | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 88 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

89 {
90 return BOTAN_FFI_CHECKED_DELETE(op);
91 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

Definition at line 93 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::PK_Decryptor::plaintext_length().

94 {
95 if(ptext_len == nullptr)
96 return BOTAN_FFI_ERROR_NULL_POINTER;
97 return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, { *ptext_len = o.plaintext_length(ctext_len); });
98 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::PK_Decryptor::plaintext_length
virtual size_t plaintext_length(size_t ctext_len) const =0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::PK_Decryptor
Definition: pubkey.h:84

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

Definition at line 55 of file ffi_pk_op.cpp.

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

59 {
60 return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, {
61 return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
62 });
63 }
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::PK_Encryptor
Definition: pubkey.h:29

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

Definition at line 23 of file ffi_pk_op.cpp.

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

27 {
28 if(op == nullptr)
29 return BOTAN_FFI_ERROR_NULL_POINTER;
30
31 if(flags != 0)
32 return BOTAN_FFI_ERROR_BAD_FLAG;
33
34 return ffi_guard_thunk(__func__, [=]() -> int {
35 *op = nullptr;
36
37 std::unique_ptr<Botan::PK_Encryptor> pk(new Botan::PK_Encryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
38 *op = new botan_pk_op_encrypt_struct(pk.release());
39 return BOTAN_FFI_SUCCESS;
40 });
41 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::system_rng
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:279
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::PK_Encryptor_EME
Definition: pubkey.h:529
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_pk_op_encrypt_destroy | ( | botan_pk_op_encrypt_t | op | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 43 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

44 {
45 return BOTAN_FFI_CHECKED_DELETE(op);
46 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

Definition at line 48 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::PK_Encryptor::ciphertext_length().

49 {
50 if(ctext_len == nullptr)
51 return BOTAN_FFI_ERROR_NULL_POINTER;
52 return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, { *ctext_len = o.ciphertext_length(ptext_len); });
53 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::PK_Encryptor::ciphertext_length
virtual size_t ciphertext_length(size_t ctext_len) const =0
Botan::PK_Encryptor
Definition: pubkey.h:29

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

Definition at line 241 of file ffi_pk_op.cpp.

References Botan::OctetString::bits_of(), BOTAN_FFI_DO, Botan::PK_Key_Agreement::derive_key(), and Botan_FFI::write_vec_output().

245 {
246 return BOTAN_FFI_DO(Botan::PK_Key_Agreement, op, o, {
247 auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
248 return write_vec_output(out, out_len, k);
249 });
250 }
Botan::OctetString::bits_of
secure_vector< uint8_t > bits_of() const
Definition: symkey.h:31
Botan::PK_Key_Agreement::derive_key
SymmetricKey derive_key(size_t key_len, const uint8_t in[], size_t in_len, const uint8_t params[], size_t params_len) const
Definition: pubkey.cpp:218
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
salt_len
size_t salt_len
Definition: x509_obj.cpp:25
Botan::PK_Key_Agreement
Definition: pubkey.h:413
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 198 of file ffi_pk_op.cpp.

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

202 {
203 if(op == nullptr)
204 return BOTAN_FFI_ERROR_NULL_POINTER;
205
206 if(flags != 0)
207 return BOTAN_FFI_ERROR_BAD_FLAG;
208
209 return ffi_guard_thunk(__func__, [=]() -> int {
210 *op = nullptr;
211 std::unique_ptr<Botan::PK_Key_Agreement> pk(new Botan::PK_Key_Agreement(safe_get(key_obj), Botan::system_rng(), kdf));
212 *op = new botan_pk_op_ka_struct(pk.release());
213 return BOTAN_FFI_SUCCESS;
214 });
215 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::system_rng
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:279
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::PK_Key_Agreement
Definition: pubkey.h:413
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_pk_op_key_agreement_destroy | ( | botan_pk_op_ka_t | op | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 217 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

218 {
219 return BOTAN_FFI_CHECKED_DELETE(op);
220 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

Definition at line 222 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_FLAG, and Botan_FFI::write_vec_output().

224 {
225 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
226 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
227 return write_vec_output(out, out_len, kak->public_value());
228 return BOTAN_FFI_ERROR_BAD_FLAG;
229 });
230 }
Botan::Private_Key
Definition: pk_keys.h:181
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_pk_op_key_agreement_size | ( | botan_pk_op_ka_t | op,
|  | size_t * | out_len
| ) |  |

Definition at line 232 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

233 {
234 return BOTAN_FFI_DO(Botan::PK_Key_Agreement, op, o, {
235 if(out_len == nullptr)
236 return BOTAN_FFI_ERROR_NULL_POINTER;
237 *out_len = o.agreed_value_size();
238 });
239 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::PK_Key_Agreement
Definition: pubkey.h:413
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 112 of file ffi_pk_op.cpp.

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

116 {
117 if(op == nullptr)
118 return BOTAN_FFI_ERROR_NULL_POINTER;
119
120 if(flags != 0)
121 return BOTAN_FFI_ERROR_BAD_FLAG;
122
123 return ffi_guard_thunk(__func__, [=]() -> int {
124 *op = nullptr;
125
126 std::unique_ptr<Botan::PK_Signer> pk(new Botan::PK_Signer(safe_get(key_obj), Botan::system_rng(), hash));
127 *op = new botan_pk_op_sign_struct(pk.release());
128 return BOTAN_FFI_SUCCESS;
129 });
130 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::system_rng
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:279
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
Botan::PK_Signer
Definition: pubkey.h:166
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

int botan_pk_op_sign_destroy | ( | botan_pk_op_sign_t | op | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 132 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

133 {
134 return BOTAN_FFI_CHECKED_DELETE(op);
135 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

Definition at line 150 of file ffi_pk_op.cpp.

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

151 {
152 return BOTAN_FFI_DO(Botan::PK_Signer, op, o, {
153 return write_vec_output(out, out_len, o.signature(safe_get(rng_obj)));
154 });
155 }
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
Botan::PK_Signer
Definition: pubkey.h:166
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_pk_op_sign_output_length | ( | botan_pk_op_sign_t | op,
|  | size_t * | olen
| ) |  |

Definition at line 137 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::PK_Signer::signature_length().

138 {
139 if(sig_len == nullptr)
140 return BOTAN_FFI_ERROR_NULL_POINTER;
141
142 return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { *sig_len = o.signature_length(); });
143 }
Botan::PK_Signer::signature_length
size_t signature_length() const
Definition: pubkey.cpp:270
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::PK_Signer
Definition: pubkey.h:166
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 145 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, and Botan::PK_Signer::update().

146 {
147 return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { o.update(in, in_len); });
148 }
Botan::PK_Signer::update
void update(uint8_t in)
Definition: pubkey.h:238
Botan::PK_Signer
Definition: pubkey.h:166
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 157 of file ffi_pk_op.cpp.

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

161 {
162 if(op == nullptr)
163 return BOTAN_FFI_ERROR_NULL_POINTER;
164
165 if(flags != 0)
166 return BOTAN_FFI_ERROR_BAD_FLAG;
167
168 return ffi_guard_thunk(__func__, [=]() -> int {
169 *op = nullptr;
170 std::unique_ptr<Botan::PK_Verifier> pk(new Botan::PK_Verifier(safe_get(key_obj), hash));
171 *op = new botan_pk_op_verify_struct(pk.release());
172 return BOTAN_FFI_SUCCESS;
173 });
174 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::PK_Verifier
Definition: pubkey.h:298
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

int botan_pk_op_verify_destroy | ( | botan_pk_op_verify_t | op | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 176 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

177 {
178 return BOTAN_FFI_CHECKED_DELETE(op);
179 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

Definition at line 186 of file ffi_pk_op.cpp.

References BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_RETURNING, BOTAN_FFI_SUCCESS, and Botan::PK_Verifier::check_signature().

187 {
188 return BOTAN_FFI_RETURNING(Botan::PK_Verifier, op, o, {
189 const bool legit = o.check_signature(sig, sig_len);
190
191 if(legit)
192 return BOTAN_FFI_SUCCESS;
193 else
194 return BOTAN_FFI_INVALID_VERIFIER;
195 });
196 }
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan::PK_Verifier
Definition: pubkey.h:298
Botan::PK_Verifier::check_signature
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:336
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:63

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

Definition at line 181 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, and Botan::PK_Verifier::update().

182 {
183 return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, { o.update(in, in_len); });
184 }
Botan::PK_Verifier::update
void update(uint8_t in)
Definition: pubkey.h:347
Botan::PK_Verifier
Definition: pubkey.h:298
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 267 of file ffi_pkey.cpp.

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

268 {
269 #if defined(BOTAN_HAS_HASH_ID)
270 return ffi_guard_thunk(__func__, [=]() -> int {
271 const std::vector<uint8_t> hash_id = Botan::pkcs_hash_id(hash_name);
272 return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
273 });
274 #else
275 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
276 #endif
277 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_output
int write_output(uint8_t out[], size_t *out_len, const uint8_t buf[], size_t buf_len)
Definition: ffi_util.h:131
Botan::pkcs_hash_id
std::vector< uint8_t > pkcs_hash_id(const std::string &name)
Definition: hash_id.cpp:77

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

Definition at line 126 of file ffi_pkey.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

127 {
128 return BOTAN_FFI_DO(Botan::Private_Key, key, k, { return write_str_output(out, out_len, k.algo_name()); });
129 }
Botan::Private_Key
Definition: pk_keys.h:181
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 145 of file ffi_pkey.cpp.

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

146 {
147 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
148 return BOTAN_FFI_RETURNING(Botan::Private_Key, key, k, {
149 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
150 });
151 }
Botan::Private_Key
Definition: pk_keys.h:181
BOTAN_FFI_ERROR_INVALID_INPUT
Definition: ffi.h:65
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_CHECK_KEY_EXPENSIVE_TESTS
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition: ffi.h:966
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61

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

  key | the new object will be placed here
  algo_name | something like "RSA" or "ECDSA"
  algo_params | is specific to the algorithm. For RSA, specifies the modulus bit length. For ECC is the name of the curve.
  rng | a random number generator

Definition at line 26 of file ffi_pkey.cpp.

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

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

30 {
31 return ffi_guard_thunk(__func__, [=]() -> int {
32 if(key_obj == nullptr)
33 return BOTAN_FFI_ERROR_NULL_POINTER;
34
35 *key_obj = nullptr;
36 if(rng_obj == nullptr)
37 return BOTAN_FFI_ERROR_NULL_POINTER;
38
39 Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
40 std::unique_ptr<Botan::Private_Key> key(
41 Botan::create_private_key(algo_name ? algo_name : "RSA",
42 rng,
43 algo_params ? algo_params : ""));
44
45 if(key)
46 {
47 *key_obj = new botan_privkey_struct(key.release());
48 return BOTAN_FFI_SUCCESS;
49 }
50 else
51 {
52 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
53 }
54 });
55 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::create_private_key
std::unique_ptr< Private_Key > create_private_key(const std::string &alg_name, RandomNumberGenerator &rng, const std::string &params, const std::string &provider)
Definition: pk_algs.cpp:264
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 580 of file ffi_pkey_algs.cpp.

References botan_privkey_create().

581 {
582 return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
583 }
botan_privkey_create
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition: ffi_pkey.cpp:26

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

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

Parameters

  key | handler to the resulting key
  rng | initialized PRNG
  pbits | length of the key in bits. Must be between in range (1024, 3072) and multiple of 64. Bit size of the prime 'p'
  qbits | order of the subgroup. Must be in range (160, 256) and multiple of 8

Returns
  BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
  BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
  BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or `qbits'
  BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

Definition at line 383 of file ffi_pkey_algs.cpp.

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

384 {
385 #if defined(BOTAN_HAS_DSA)
386
387 if ((rng_obj == nullptr) || (key == nullptr))
388 return BOTAN_FFI_ERROR_NULL_POINTER;
389
390 if ((pbits % 64) || (qbits % 8) ||
391 (pbits < 1024) || (pbits > 3072) ||
392 (qbits < 160) || (qbits > 256)) {
393 return BOTAN_FFI_ERROR_BAD_PARAMETER;
394 }
395
396 return ffi_guard_thunk(__func__, [=]() -> int {
397 Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
398 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
399 *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(rng, group));
400 return BOTAN_FFI_SUCCESS;
401 });
402 #else
403 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
404 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
405 #endif
406 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::DL_Group::Prime_Subgroup
Definition: dl_group.h:29
Botan::RandomNumberGenerator
Definition: rng.h:24
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::DL_Group
Definition: dl_group.h:23
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::DSA_PrivateKey
Definition: dsa.h:55
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 620 of file ffi_pkey_algs.cpp.

References BOTAN_FFI_ERROR_NULL_POINTER, and botan_privkey_create().

621 {
622 if(param_str == nullptr)
623 return BOTAN_FFI_ERROR_NULL_POINTER;
624
625 const std::string params(param_str);
626
627 if(params == "curve25519")
628 return botan_privkey_create(key_obj, "Curve25519", "", rng_obj);
629
630 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
631 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
botan_privkey_create
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition: ffi_pkey.cpp:26

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

Definition at line 468 of file ffi_pkey_algs.cpp.

References botan_privkey_create().

469 {
470 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
471 }
botan_privkey_create
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition: ffi_pkey.cpp:26

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

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

- if pbits-1 == qbits then safe primes are used for key generation
- otherwise generation uses group of prime order

Parameters

  key | handler to the resulting key
  rng | initialized PRNG
  pbits | length of the key in bits. Must be at least 1024
  qbits | order of the subgroup. Must be at least 160

Returns
  BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
  BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
  BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or `qbits'
  BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

Definition at line 515 of file ffi_pkey_algs.cpp.

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

519 {
520 #if defined(BOTAN_HAS_ELGAMAL)
521
522 if ((rng_obj == nullptr) || (key == nullptr))
523 return BOTAN_FFI_ERROR_NULL_POINTER;
524
525 if ((pbits < 1024) || (qbits<160)) {
526 return BOTAN_FFI_ERROR_BAD_PARAMETER;
527 }
528
529 Botan::DL_Group::PrimeType prime_type = ((pbits-1) == qbits)
530 ? Botan::DL_Group::Strong
531 : Botan::DL_Group::Prime_Subgroup;
532
533 return ffi_guard_thunk(__func__, [=]() -> int {
534 Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
535 Botan::DL_Group group(rng, prime_type, pbits, qbits);
536 *key = new botan_privkey_struct(new Botan::ElGamal_PrivateKey(rng, group));
537 return BOTAN_FFI_SUCCESS;
538 });
539 #else
540 BOTAN_UNUSED(key, rng_obj, pbits);
541 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
542 #endif
543 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::DL_Group::Prime_Subgroup
Definition: dl_group.h:29
Botan::RandomNumberGenerator
Definition: rng.h:24
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::DL_Group::Strong
Definition: dl_group.h:29
Botan::ElGamal_PrivateKey
Definition: elgamal.h:53
Botan::DL_Group
Definition: dl_group.h:23
Botan::DL_Group::PrimeType
PrimeType
Definition: dl_group.h:29
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 928 of file ffi_pkey_algs.cpp.

References botan_privkey_create(), and Botan::ASN1::to_string().

929 {
930 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
931 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
932 }
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
botan_privkey_create
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition: ffi_pkey.cpp:26

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

Definition at line 258 of file ffi_pkey_algs.cpp.

References BOTAN_FFI_ERROR_BAD_PARAMETER, botan_privkey_create(), and Botan::ASN1::to_string().

259 {
260 if(n_bits < 1024 || n_bits > 16*1024)
261 return BOTAN_FFI_ERROR_BAD_PARAMETER;
262
263 std::string n_str = std::to_string(n_bits);
264
265 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
266 }
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
botan_privkey_create
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition: ffi_pkey.cpp:26

int botan_privkey_destroy | ( | botan_privkey_t | key | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 88 of file ffi_pkey.cpp.

References BOTAN_FFI_CHECKED_DELETE.

89 {
90 return BOTAN_FFI_CHECKED_DELETE(key);
91 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

int botan_privkey_dsa_get_x | ( | botan_mp_t | n,
|  | botan_privkey_t | key
| ) |  |

Definition at line 443 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

444 {
445 return botan_privkey_get_field(x, key, "x");
446 }
botan_privkey_get_field
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:242

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

Definition at line 798 of file ffi_pkey_algs.cpp.

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

800 {
801 #if defined(BOTAN_HAS_ED25519)
802 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
803 if(Botan::Ed25519_PrivateKey* ed = dynamic_cast<Botan::Ed25519_PrivateKey*>(&k))
804 {
805 const Botan::secure_vector<uint8_t>& ed_key = ed->get_private_key();
806 if(ed_key.size() != 64)
807 return BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE;
808 Botan::copy_mem(output, ed_key.data(), ed_key.size());
809 return BOTAN_FFI_SUCCESS;
810 }
811 else
812 {
813 return BOTAN_FFI_ERROR_BAD_PARAMETER;
814 }
815 });
816 #else
817 BOTAN_UNUSED(key, output);
818 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
819 #endif
820 }
Botan::Private_Key
Definition: pk_keys.h:181
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:68
Botan::Ed25519_PrivateKey
Definition: ed25519.h:58
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:132
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

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

Definition at line 165 of file ffi_pkey.cpp.

References Botan::PKCS8::BER_encode(), BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, Botan::PKCS8::PEM_encode(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

166 {
167 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
168 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER)
169 return write_vec_output(out, out_len, Botan::PKCS8::BER_encode(k));
170 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
171 return write_str_output(out, out_len, Botan::PKCS8::PEM_encode(k));
172 else
173 return BOTAN_FFI_ERROR_BAD_FLAG;
174 });
175 }
BOTAN_PRIVKEY_EXPORT_FLAG_PEM
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:1046
Botan::Private_Key
Definition: pk_keys.h:181
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
BOTAN_PRIVKEY_EXPORT_FLAG_DER
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:1045
Botan::PKCS8::PEM_encode
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:148
Botan::PKCS8::BER_encode
secure_vector< uint8_t > BER_encode(const Private_Key &key)
Definition: pkcs8.cpp:139
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

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

Definition at line 177 of file ffi_pkey.cpp.

References botan_privkey_export_encrypted_pbkdf_iter().

183 {
184 return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
185 }
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
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_obj, const char *pass, size_t pbkdf_iter, const char *maybe_cipher, const char *maybe_pbkdf_hash, uint32_t flags)
Definition: ffi_pkey.cpp:221

int botan_privkey_export_encrypted_pbkdf_iter | ( | botan_privkey_t | key,
|  | uint8_t | out[],
|  | size_t * | out_len,
|  | botan_rng_t | rng,
|  | const char * | passphrase,
|  | size_t | pbkdf_iterations,
|  | const char * | cipher_algo,
|  | const char * | pbkdf_algo,
|  | uint32_t | flags
| ) |  |

Export a private key using the specified number of iterations.

Definition at line 221 of file ffi_pkey.cpp.

References Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(), BOTAN_FFI_DO, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(), Botan_FFI::safe_get(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

Referenced by botan_privkey_export_encrypted().

229 {
230 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
231 Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
232
233 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
234 const std::string pbkdf_hash = (maybe_pbkdf_hash ? maybe_pbkdf_hash : "");
235
236 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER)
237 {
238 return write_vec_output(out, out_len,
239 Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
240 }
241 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
242 {
243 return write_str_output(out, out_len,
244 Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
245 }
246 else
247 {
248 return -2;
249 }
250 });
251 }
BOTAN_PRIVKEY_EXPORT_FLAG_PEM
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:1046
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::Private_Key
Definition: pk_keys.h:181
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
Botan::PKCS8::BER_encode_encrypted_pbkdf_iter
std::vector< uint8_t > BER_encode_encrypted_pbkdf_iter(const Private_Key &key, RandomNumberGenerator &rng, const std::string &pass, size_t pbkdf_iterations, const std::string &cipher, const std::string &pbkdf_hash)
Definition: pkcs8.cpp:246
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
BOTAN_PRIVKEY_EXPORT_FLAG_DER
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:1045
Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter
std::string PEM_encode_encrypted_pbkdf_iter(const Private_Key &key, RandomNumberGenerator &rng, const std::string &pass, size_t pbkdf_iterations, const std::string &cipher, const std::string &pbkdf_hash)
Definition: pkcs8.cpp:279
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_privkey_export_encrypted_pbkdf_msec | ( | botan_privkey_t | key,
|  | uint8_t | out[],
|  | size_t * | out_len,
|  | botan_rng_t | rng,
|  | const char * | passphrase,
|  | uint32_t | pbkdf_msec_runtime,
|  | size_t * | pbkdf_iterations_out,
|  | const char * | cipher_algo,
|  | const char * | pbkdf_algo,
|  | uint32_t | flags
| ) |  |

Definition at line 187 of file ffi_pkey.cpp.

References Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(), BOTAN_FFI_DO, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(), Botan_FFI::safe_get(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

196 {
197 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
198 const std::chrono::milliseconds pbkdf_time(pbkdf_msec);
199 Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
200
201 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
202 const std::string pbkdf_hash = (maybe_pbkdf_hash ? maybe_pbkdf_hash : "");
203
204 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER)
205 {
206 return write_vec_output(out, out_len,
207 Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
208 }
209 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
210 {
211 return write_str_output(out, out_len,
212 Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
213 }
214 else
215 {
216 return -2;
217 }
218 });
219 }
BOTAN_PRIVKEY_EXPORT_FLAG_PEM
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:1046
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::Private_Key
Definition: pk_keys.h:181
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::PKCS8::BER_encode_encrypted_pbkdf_msec
std::vector< uint8_t > BER_encode_encrypted_pbkdf_msec(const Private_Key &key, RandomNumberGenerator &rng, const std::string &pass, std::chrono::milliseconds pbkdf_msec, size_t *pbkdf_iterations, const std::string &cipher, const std::string &pbkdf_hash)
Definition: pkcs8.cpp:294
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
BOTAN_PRIVKEY_EXPORT_FLAG_DER
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:1045
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec
std::string PEM_encode_encrypted_pbkdf_msec(const Private_Key &key, RandomNumberGenerator &rng, const std::string &pass, std::chrono::milliseconds pbkdf_msec, size_t *pbkdf_iterations, const std::string &cipher, const std::string &pbkdf_hash)
Definition: pkcs8.cpp:327

int botan_privkey_export_pubkey | ( | botan_pubkey_t * | out,
|  | botan_privkey_t | in
| ) |  |

Definition at line 115 of file ffi_pkey.cpp.

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

116 {
117 return ffi_guard_thunk(__func__, [=]() -> int {
118 std::unique_ptr<Botan::Public_Key>
119 pubkey(Botan::X509::load_key(Botan::X509::BER_encode(safe_get(key_obj))));
120
121 *pubout = new botan_pubkey_struct(pubkey.release());
122 return BOTAN_FFI_SUCCESS;
123 });
124 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::X509::BER_encode
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.cpp:19
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
Botan::X509::load_key
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:37

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

Definition at line 242 of file ffi_pkey_algs.cpp.

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

245 {
246 if(field_name_cstr == nullptr)
247 return BOTAN_FFI_ERROR_NULL_POINTER;
248
249 const std::string field_name(field_name_cstr);
250
251 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
252 safe_get(output) = privkey_get_field(k, field_name);
253 });
254 }
Botan::Private_Key
Definition: pk_keys.h:181
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

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

Definition at line 57 of file ffi_pkey.cpp.

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

60 {
61 BOTAN_UNUSED(rng_obj);
62
63 *key = nullptr;
64
65 return ffi_guard_thunk(__func__, [=]() -> int {
66 Botan::DataSource_Memory src(bits, len);
67
68 std::unique_ptr<Botan::Private_Key> pkcs8;
69
70 if(password == nullptr)
71 {
72 pkcs8 = Botan::PKCS8::load_key(src);
73 }
74 else
75 {
76 pkcs8 = Botan::PKCS8::load_key(src, std::string(password));
77 }
78
79 if(pkcs8)
80 {
81 *key = new botan_privkey_struct(pkcs8.release());
82 return BOTAN_FFI_SUCCESS;
83 }
84 return BOTAN_FFI_ERROR_UNKNOWN_ERROR;
85 });
86 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::DataSource_Memory
Definition: data_src.h:98
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
Botan::PKCS8::load_key
std::unique_ptr< Private_Key > load_key(DataSource &source, std::function< std::string()> get_pass)
Definition: pkcs8.cpp:366
BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:89

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

Definition at line 585 of file ffi_pkey_algs.cpp.

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

587 {
588 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
589 *key = nullptr;
590 return ffi_guard_thunk(__func__, [=]() -> int {
591 Botan::Null_RNG null_rng;
592 Botan::DL_Group group(safe_get(p), safe_get(g));
593 *key = new botan_privkey_struct(new Botan::DH_PrivateKey(null_rng, group, safe_get(x)));
594 return BOTAN_FFI_SUCCESS;
595 });
596 #else
597 BOTAN_UNUSED(key, p, g, x);
598 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
599 #endif
600 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::DL_Group
Definition: dl_group.h:23
Botan::Null_RNG
Definition: rng.h:204
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
Botan::DH_PrivateKey
Definition: dh.h:49

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

Definition at line 408 of file ffi_pkey_algs.cpp.

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

410 {
411 #if defined(BOTAN_HAS_DSA)
412 *key = nullptr;
413
414 return ffi_guard_thunk(__func__, [=]() -> int {
415 Botan::Null_RNG null_rng;
416 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
417 *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(null_rng, group, safe_get(x)));
418 return BOTAN_FFI_SUCCESS;
419 });
420 #else
421 BOTAN_UNUSED(key, p, q, g, x);
422 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
423 #endif
424 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::DL_Group
Definition: dl_group.h:23
Botan::DSA_PrivateKey
Definition: dsa.h:55
Botan::Null_RNG
Definition: rng.h:204
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 653 of file ffi_pkey_algs.cpp.

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

656 {
657 #if defined(BOTAN_HAS_ECDH)
658 return ffi_guard_thunk(__func__, [=]() -> int {
659 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
660 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
661 if(rc == BOTAN_FFI_SUCCESS)
662 *key = new botan_privkey_struct(p_key.release());
663 return rc;
664 });
665 #else
666 BOTAN_UNUSED(key, scalar, curve_name);
667 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
668 #endif
669 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 496 of file ffi_pkey_algs.cpp.

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

499 {
500 #if defined(BOTAN_HAS_ECDSA)
501 return ffi_guard_thunk(__func__, [=]() -> int {
502 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
503 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
504 if(rc == BOTAN_FFI_SUCCESS)
505 *key = new botan_privkey_struct(p_key.release());
506 return rc;
507 });
508 #else
509 BOTAN_UNUSED(key, scalar, curve_name);
510 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
511 #endif
512 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 766 of file ffi_pkey_algs.cpp.

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

768 {
769 #if defined(BOTAN_HAS_ED25519)
770 *key = nullptr;
771 return ffi_guard_thunk(__func__, [=]() -> int {
772 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
773 *key = new botan_privkey_struct(new Botan::Ed25519_PrivateKey(privkey_vec));
774 return BOTAN_FFI_SUCCESS;
775 });
776 #else
777 BOTAN_UNUSED(key, privkey);
778 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
779 #endif
780 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::Ed25519_PrivateKey
Definition: ed25519.h:58
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Loads ElGamal private key

Parameters

  key | variable populated with key material
  p | prime order of a Z_p group
  g | group generator
  x | private key

Precondition
  key is NULL on input

Postcondition
  function allocates memory and assigns to `key'

Returns
  0 on success, a negative value on failure

Definition at line 561 of file ffi_pkey_algs.cpp.

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

563 {
564 #if defined(BOTAN_HAS_ELGAMAL)
565 *key = nullptr;
566 return ffi_guard_thunk(__func__, [=]() -> int {
567 Botan::Null_RNG null_rng;
568 Botan::DL_Group group(safe_get(p), safe_get(g));
569 *key = new botan_privkey_struct(new Botan::ElGamal_PrivateKey(null_rng, group, safe_get(x)));
570 return BOTAN_FFI_SUCCESS;
571 });
572 #else
573 BOTAN_UNUSED(key, p, g, x);
574 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
575 #endif
576 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::ElGamal_PrivateKey
Definition: elgamal.h:53
Botan::DL_Group
Definition: dl_group.h:23
Botan::Null_RNG
Definition: rng.h:204
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 268 of file ffi_pkey_algs.cpp.

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

270 {
271 #if defined(BOTAN_HAS_RSA)
272 *key = nullptr;
273
274 return ffi_guard_thunk(__func__, [=]() -> int {
275 *key = new botan_privkey_struct(new Botan::RSA_PrivateKey(safe_get(rsa_p),
276 safe_get(rsa_q),
277 safe_get(rsa_e)));
278 return BOTAN_FFI_SUCCESS;
279 });
280 #else
281 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
282 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
283 #endif
284 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::RSA_PrivateKey
Definition: rsa.h:92
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 286 of file ffi_pkey_algs.cpp.

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

289 {
290 #if defined(BOTAN_HAS_RSA)
291 *key = nullptr;
292
293 Botan::secure_vector<uint8_t> src(bits, bits + len);
294 return ffi_guard_thunk(__func__, [=]() -> int {
295 Botan::AlgorithmIdentifier alg_id("RSA", Botan::AlgorithmIdentifier::USE_NULL_PARAM);
296 *key = new botan_privkey_struct(new Botan::RSA_PrivateKey(alg_id, src));
297 return BOTAN_FFI_SUCCESS;
298 });
299 #else
300 BOTAN_UNUSED(key, bits, len);
301 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
302 #endif
303 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::RSA_PrivateKey
Definition: rsa.h:92
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::AlgorithmIdentifier
Definition: alg_id.h:21
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
Botan::AlgorithmIdentifier::USE_NULL_PARAM
Definition: alg_id.h:24

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

Definition at line 730 of file ffi_pkey_algs.cpp.

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

Referenced by botan_privkey_load_sm2_enc().

733 {
734 #if defined(BOTAN_HAS_SM2)
735 return ffi_guard_thunk(__func__, [=]() -> int {
736 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
737 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
738
739 if(rc == BOTAN_FFI_SUCCESS)
740 *key = new botan_privkey_struct(p_key.release());
741 return rc;
742 });
743 #else
744 BOTAN_UNUSED(key, scalar, curve_name);
745 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
746 #endif
747 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 757 of file ffi_pkey_algs.cpp.

References botan_privkey_load_sm2().

760 {
761 return botan_privkey_load_sm2(key, scalar, curve_name);
762 }
botan_privkey_load_sm2
int botan_privkey_load_sm2(botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
Definition: ffi_pkey_algs.cpp:730

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

Definition at line 848 of file ffi_pkey_algs.cpp.

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

850 {
851 #if defined(BOTAN_HAS_X25519)
852 *key = nullptr;
853 return ffi_guard_thunk(__func__, [=]() -> int {
854 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
855 *key = new botan_privkey_struct(new Botan::X25519_PrivateKey(privkey_vec));
856 return BOTAN_FFI_SUCCESS;
857 });
858 #else
859 BOTAN_UNUSED(key, privkey);
860 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
861 #endif
862 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::Curve25519_PrivateKey
Definition: curve25519.h:58
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_privkey_rsa_get_d | ( | botan_mp_t | d,
|  | botan_privkey_t | rsa_key
| ) |  |

Definition at line 340 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

341 {
342 return botan_privkey_get_field(d, key, "d");
343 }
botan_privkey_get_field
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:242

int botan_privkey_rsa_get_e | ( | botan_mp_t | e,
|  | botan_privkey_t | rsa_key
| ) |  |

Definition at line 335 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

336 {
337 return botan_privkey_get_field(e, key, "e");
338 }
botan_privkey_get_field
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:242

int botan_privkey_rsa_get_n | ( | botan_mp_t | n,
|  | botan_privkey_t | rsa_key
| ) |  |

Definition at line 330 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

331 {
332 return botan_privkey_get_field(n, key, "n");
333 }
botan_privkey_get_field
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:242

int botan_privkey_rsa_get_p | ( | botan_mp_t | p,
|  | botan_privkey_t | rsa_key
| ) |  |

Definition at line 320 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

321 {
322 return botan_privkey_get_field(p, key, "p");
323 }
botan_privkey_get_field
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:242

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

Definition at line 355 of file ffi_pkey_algs.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, 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().

358 {
359 #if defined(BOTAN_HAS_RSA)
360 return BOTAN_FFI_DO(Botan::Private_Key, rsa_key, k, {
361 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k))
362 {
363 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER)
364 return write_vec_output(out, out_len, rsa->private_key_bits());
365 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
366 return write_str_output(out, out_len, Botan::PEM_Code::encode(rsa->private_key_bits(),
367 "RSA PRIVATE KEY"));
368 else
369 return BOTAN_FFI_ERROR_BAD_FLAG;
370 }
371 else
372 {
373 return BOTAN_FFI_ERROR_BAD_PARAMETER;
374 }
375 });
376 #else
377 BOTAN_UNUSED(rsa_key, out, out_len);
378 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
379 #endif
380 }
BOTAN_PRIVKEY_EXPORT_FLAG_PEM
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:1046
Botan::Private_Key
Definition: pk_keys.h:181
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
Botan::PEM_Code::encode
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43
BOTAN_PRIVKEY_EXPORT_FLAG_DER
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:1045
Botan::RSA_PrivateKey
Definition: rsa.h:92
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_privkey_rsa_get_q | ( | botan_mp_t | q,
|  | botan_privkey_t | rsa_key
| ) |  |

Definition at line 325 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

326 {
327 return botan_privkey_get_field(q, key, "q");
328 }
botan_privkey_get_field
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:242

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

Definition at line 880 of file ffi_pkey_algs.cpp.

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

882 {
883 #if defined(BOTAN_HAS_X25519)
884 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
885 if(Botan::X25519_PrivateKey* x25519 = dynamic_cast<Botan::X25519_PrivateKey*>(&k))
886 {
887 const Botan::secure_vector<uint8_t>& x25519_key = x25519->get_x();
888 if(x25519_key.size() != 32)
889 return BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE;
890 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
891 return BOTAN_FFI_SUCCESS;
892 }
893 else
894 {
895 return BOTAN_FFI_ERROR_BAD_PARAMETER;
896 }
897 });
898 #else
899 BOTAN_UNUSED(key, output);
900 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
901 #endif
902 }
Botan::Private_Key
Definition: pk_keys.h:181
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:68
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:132
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
Botan::Curve25519_PrivateKey
Definition: curve25519.h:58
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 131 of file ffi_pkey.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

132 {
133 return BOTAN_FFI_DO(Botan::Public_Key, key, k, { return write_str_output(out, out_len, k.algo_name()); });
134 }
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
Botan::Public_Key
Definition: pk_keys.h:29
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

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

137 {
138 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
139
140 return BOTAN_FFI_RETURNING(Botan::Public_Key, key, k, {
141 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
142 });
143 }
BOTAN_FFI_ERROR_INVALID_INPUT
Definition: ffi.h:65
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_CHECK_KEY_EXPENSIVE_TESTS
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition: ffi.h:966
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan::Public_Key
Definition: pk_keys.h:29
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61

int botan_pubkey_destroy | ( | botan_pubkey_t | key | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 110 of file ffi_pkey.cpp.

References BOTAN_FFI_CHECKED_DELETE.

111 {
112 return BOTAN_FFI_CHECKED_DELETE(key);
113 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

int botan_pubkey_dsa_get_g | ( | botan_mp_t | d,
|  | botan_pubkey_t | key
| ) |  |

Definition at line 458 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

459 {
460 return botan_pubkey_get_field(g, key, "g");
461 }
botan_pubkey_get_field
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:228

int botan_pubkey_dsa_get_p | ( | botan_mp_t | p,
|  | botan_pubkey_t | key
| ) |  |

Definition at line 448 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

449 {
450 return botan_pubkey_get_field(p, key, "p");
451 }
botan_pubkey_get_field
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:228

int botan_pubkey_dsa_get_q | ( | botan_mp_t | q,
|  | botan_pubkey_t | key
| ) |  |

Definition at line 453 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

454 {
455 return botan_pubkey_get_field(q, key, "q");
456 }
botan_pubkey_get_field
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:228

int botan_pubkey_dsa_get_y | ( | botan_mp_t | y,
|  | botan_pubkey_t | key
| ) |  |

Definition at line 463 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

464 {
465 return botan_pubkey_get_field(y, key, "y");
466 }
botan_pubkey_get_field
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:228

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

Definition at line 822 of file ffi_pkey_algs.cpp.

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

824 {
825 #if defined(BOTAN_HAS_ED25519)
826 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
827 if(Botan::Ed25519_PublicKey* ed = dynamic_cast<Botan::Ed25519_PublicKey*>(&k))
828 {
829 const std::vector<uint8_t>& ed_key = ed->get_public_key();
830 if(ed_key.size() != 32)
831 return BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE;
832 Botan::copy_mem(output, ed_key.data(), ed_key.size());
833 return BOTAN_FFI_SUCCESS;
834 }
835 else
836 {
837 return BOTAN_FFI_ERROR_BAD_PARAMETER;
838 }
839 });
840 #else
841 BOTAN_UNUSED(key, output);
842 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
843 #endif
844 }
Botan::Ed25519_PublicKey
Definition: ed25519.h:18
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:68
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:132
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::Public_Key
Definition: pk_keys.h:29
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_pubkey_estimated_strength | ( | botan_pubkey_t | key,
|  | size_t * | estimate
| ) |  |

Definition at line 253 of file ffi_pkey.cpp.

References BOTAN_FFI_DO, and Botan::Public_Key::estimated_strength().

254 {
255 return BOTAN_FFI_DO(Botan::Public_Key, key, k, { *estimate = k.estimated_strength(); });
256 }
Botan::Public_Key
Definition: pk_keys.h:29
Botan::Public_Key::estimated_strength
virtual size_t estimated_strength() const =0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 153 of file ffi_pkey.cpp.

References Botan::X509::BER_encode(), BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, Botan::X509::PEM_encode(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

154 {
155 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
156 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER)
157 return write_vec_output(out, out_len, Botan::X509::BER_encode(k));
158 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
159 return write_str_output(out, out_len, Botan::X509::PEM_encode(k));
160 else
161 return BOTAN_FFI_ERROR_BAD_FLAG;
162 });
163 }
BOTAN_PRIVKEY_EXPORT_FLAG_PEM
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:1046
Botan::X509::PEM_encode
std::string PEM_encode(const Public_Key &key)
Definition: x509_key.cpp:28
Botan::X509::BER_encode
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.cpp:19
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
BOTAN_PRIVKEY_EXPORT_FLAG_DER
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:1045
Botan::Public_Key
Definition: pk_keys.h:29
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 258 of file ffi_pkey.cpp.

References BOTAN_FFI_DO, Botan::HashFunction::create(), and Botan_FFI::write_vec_output().

260 {
261 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
262 std::unique_ptr<Botan::HashFunction> h(Botan::HashFunction::create(hash_fn));
263 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
264 });
265 }
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:106
Botan::Public_Key
Definition: pk_keys.h:29
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 228 of file ffi_pkey_algs.cpp.

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

231 {
232 if(field_name_cstr == nullptr)
233 return BOTAN_FFI_ERROR_NULL_POINTER;
234
235 const std::string field_name(field_name_cstr);
236
237 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
238 safe_get(output) = pubkey_get_field(k, field_name);
239 });
240 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::Public_Key
Definition: pk_keys.h:29
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 93 of file ffi_pkey.cpp.

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

95 {
96 *key = nullptr;
97
98 return ffi_guard_thunk(__func__, [=]() -> int {
99 Botan::DataSource_Memory src(bits, bits_len);
100 std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src));
101
102 if(pubkey == nullptr)
103 return BOTAN_FFI_ERROR_UNKNOWN_ERROR;
104
105 *key = new botan_pubkey_struct(pubkey.release());
106 return BOTAN_FFI_SUCCESS;
107 });
108 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::DataSource_Memory
Definition: data_src.h:98
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:89
Botan::X509::load_key
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:37

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

Loads Diffie Hellman public key

Parameters

  key | variable populated with key material
  p | prime order of a Z_p group
  g | group generator
  y | public key

Precondition
  key is NULL on input

Postcondition
  function allocates memory and assigns to `key'

Returns
  0 on success, a negative value on failure

Definition at line 602 of file ffi_pkey_algs.cpp.

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

604 {
605 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
606 *key = nullptr;
607 return ffi_guard_thunk(__func__, [=]() -> int {
608 Botan::DL_Group group(safe_get(p), safe_get(g));
609 *key = new botan_pubkey_struct(new Botan::DH_PublicKey(group, safe_get(y)));
610 return BOTAN_FFI_SUCCESS;
611 });
612 #else
613 BOTAN_UNUSED(key, p, g, y);
614 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
615 #endif
616 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::DL_Group
Definition: dl_group.h:23
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::DH_PublicKey
Definition: dh.h:18
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_pubkey_load_dsa | ( | botan_pubkey_t * | key,
|  | botan_mp_t | p,
|  | botan_mp_t | q,
|  | botan_mp_t | g,
|  | botan_mp_t | y
| ) |  |

Definition at line 426 of file ffi_pkey_algs.cpp.

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

428 {
429 #if defined(BOTAN_HAS_DSA)
430 *key = nullptr;
431
432 return ffi_guard_thunk(__func__, [=]() -> int {
433 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
434 *key = new botan_pubkey_struct(new Botan::DSA_PublicKey(group, safe_get(y)));
435 return BOTAN_FFI_SUCCESS;
436 });
437 #else
438 BOTAN_UNUSED(key, p, q, g, y);
439 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
440 #endif
441 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::DL_Group
Definition: dl_group.h:23
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::DSA_PublicKey
Definition: dsa.h:18
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 633 of file ffi_pkey_algs.cpp.

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

637 {
638 #if defined(BOTAN_HAS_ECDH)
639 return ffi_guard_thunk(__func__, [=]() -> int {
640 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
641 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
642
643 if(rc == BOTAN_FFI_SUCCESS)
644 *key = new botan_pubkey_struct(p_key.release());
645 return rc;
646 });
647 #else
648 BOTAN_UNUSED(key, public_x, public_y, curve_name);
649 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
650 #endif
651 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 475 of file ffi_pkey_algs.cpp.

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

479 {
480 #if defined(BOTAN_HAS_ECDSA)
481 return ffi_guard_thunk(__func__, [=]() -> int {
482 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
483
484 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
485 if(rc == BOTAN_FFI_SUCCESS)
486 *key = new botan_pubkey_struct(p_key.release());
487
488 return rc;
489 });
490 #else
491 BOTAN_UNUSED(key, public_x, public_y, curve_name);
492 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
493 #endif
494 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 782 of file ffi_pkey_algs.cpp.

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

784 {
785 #if defined(BOTAN_HAS_ED25519)
786 *key = nullptr;
787 return ffi_guard_thunk(__func__, [=]() -> int {
788 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
789 *key = new botan_pubkey_struct(new Botan::Ed25519_PublicKey(pubkey_vec));
790 return BOTAN_FFI_SUCCESS;
791 });
792 #else
793 BOTAN_UNUSED(key, pubkey);
794 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
795 #endif
796 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::Ed25519_PublicKey
Definition: ed25519.h:18
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Loads ElGamal public key

Parameters

  key | variable populated with key material
  p | prime order of a Z_p group
  g | group generator
  y | public key

Precondition
  key is NULL on input

Postcondition
  function allocates memory and assigns to `key'

Returns
  0 on success, a negative value on failure

Definition at line 545 of file ffi_pkey_algs.cpp.

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

547 {
548 #if defined(BOTAN_HAS_ELGAMAL)
549 *key = nullptr;
550 return ffi_guard_thunk(__func__, [=]() -> int {
551 Botan::DL_Group group(safe_get(p), safe_get(g));
552 *key = new botan_pubkey_struct(new Botan::ElGamal_PublicKey(group, safe_get(y)));
553 return BOTAN_FFI_SUCCESS;
554 });
555 #else
556 BOTAN_UNUSED(key, p, g, y);
557 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
558 #endif
559 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::ElGamal_PublicKey
Definition: elgamal.h:18
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::DL_Group
Definition: dl_group.h:23
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 305 of file ffi_pkey_algs.cpp.

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

307 {
308 #if defined(BOTAN_HAS_RSA)
309 *key = nullptr;
310 return ffi_guard_thunk(__func__, [=]() -> int {
311 *key = new botan_pubkey_struct(new Botan::RSA_PublicKey(safe_get(n), safe_get(e)));
312 return BOTAN_FFI_SUCCESS;
313 });
314 #else
315 BOTAN_UNUSED(key, n, e);
316 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
317 #endif
318 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
Botan::RSA_PublicKey
Definition: rsa.h:25

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

Definition at line 709 of file ffi_pkey_algs.cpp.

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

Referenced by botan_pubkey_load_sm2_enc().

713 {
714 #if defined(BOTAN_HAS_SM2)
715 return ffi_guard_thunk(__func__, [=]() -> int {
716 std::unique_ptr<Botan::SM2_PublicKey> p_key;
717 if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
718 {
719 *key = new botan_pubkey_struct(p_key.release());
720 return BOTAN_FFI_SUCCESS;
721 }
722 return BOTAN_FFI_ERROR_UNKNOWN_ERROR;
723 });
724 #else
725 BOTAN_UNUSED(key, public_x, public_y, curve_name);
726 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
727 #endif
728 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:89

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

Definition at line 749 of file ffi_pkey_algs.cpp.

References botan_pubkey_load_sm2().

753 {
754 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
755 }
botan_pubkey_load_sm2
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)
Definition: ffi_pkey_algs.cpp:709

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

Definition at line 864 of file ffi_pkey_algs.cpp.

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

866 {
867 #if defined(BOTAN_HAS_X25519)
868 *key = nullptr;
869 return ffi_guard_thunk(__func__, [=]() -> int {
870 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
871 *key = new botan_pubkey_struct(new Botan::X25519_PublicKey(pubkey_vec));
872 return BOTAN_FFI_SUCCESS;
873 });
874 #else
875 BOTAN_UNUSED(key, pubkey);
876 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
877 #endif
878 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::Curve25519_PublicKey
Definition: curve25519.h:15
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_pubkey_rsa_get_e | ( | botan_mp_t | e,
|  | botan_pubkey_t | rsa_key
| ) |  |

Definition at line 345 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

346 {
347 return botan_pubkey_get_field(e, key, "e");
348 }
botan_pubkey_get_field
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:228

int botan_pubkey_rsa_get_n | ( | botan_mp_t | n,
|  | botan_pubkey_t | rsa_key
| ) |  |

Definition at line 350 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

351 {
352 return botan_pubkey_get_field(n, key, "n");
353 }
botan_pubkey_get_field
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi_pkey_algs.cpp:228

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

Definition at line 673 of file ffi_pkey_algs.cpp.

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

678 {
679 if(out == nullptr || out_len == nullptr)
680 return BOTAN_FFI_ERROR_NULL_POINTER;
681 if(ident == nullptr || hash_algo == nullptr || key == nullptr)
682 return BOTAN_FFI_ERROR_NULL_POINTER;
683
684 #if defined(BOTAN_HAS_SM2)
685 return ffi_guard_thunk(__func__, [=]() -> int {
686 const Botan::Public_Key& pub_key = safe_get(key);
687 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
688
689 if(ec_key == nullptr)
690 return BOTAN_FFI_ERROR_BAD_PARAMETER;
691
692 if(ec_key->algo_name() != "SM2")
693 return BOTAN_FFI_ERROR_BAD_PARAMETER;
694
695 const std::string ident_str(ident);
696 std::unique_ptr<Botan::HashFunction> hash =
697 Botan::HashFunction::create_or_throw(hash_algo);
698
699 const std::vector<uint8_t> za =
700 Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->public_point());
701
702 return write_vec_output(out, out_len, za);
703 });
704 #else
705 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
706 #endif
707 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::HashFunction::create_or_throw
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:344
Botan::EC_PublicKey::domain
const EC_Group & domain() const
Definition: ecc_key.h:72
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0
Botan::sm2_compute_za
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, const std::string &user_id, const EC_Group &domain, const PointGFp &pubkey)
Definition: sm2.cpp:52
Botan::EC_PublicKey
Definition: ecc_key.h:28
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::EC_PublicKey::public_point
const PointGFp & public_point() const
Definition: ecc_key.h:57
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
hash_algo
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22
Botan::Public_Key
Definition: pk_keys.h:29
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

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

Definition at line 904 of file ffi_pkey_algs.cpp.

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

906 {
907 #if defined(BOTAN_HAS_X25519)
908 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
909 if(Botan::X25519_PublicKey* x25519 = dynamic_cast<Botan::X25519_PublicKey*>(&k))
910 {
911 const std::vector<uint8_t>& x25519_key = x25519->public_value();
912 if(x25519_key.size() != 32)
913 return BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE;
914 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
915 return BOTAN_FFI_SUCCESS;
916 }
917 else
918 {
919 return BOTAN_FFI_ERROR_BAD_PARAMETER;
920 }
921 });
922 #else
923 BOTAN_UNUSED(key, output);
924 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
925 #endif
926 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::Curve25519_PublicKey
Definition: curve25519.h:15
BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:68
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:132
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::Public_Key
Definition: pk_keys.h:29
BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:77
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_pwdhash | ( | const char * | algo,
|  | size_t | param1,
|  | size_t | param2,
|  | size_t | param3,
|  | uint8_t | out[],
|  | size_t | out_len,
|  | const char * | passphrase,
|  | size_t | passphrase_len,
|  | const uint8_t | salt[],
|  | size_t | salt_len
| ) |  |

Definition at line 52 of file ffi_kdf.cpp.

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

Referenced by botan_pbkdf(), and botan_scrypt().

63 {
64 if(algo == nullptr || password == nullptr)
65 return BOTAN_FFI_ERROR_NULL_POINTER;
66
67 if(password_len == 0)
68 password_len = std::strlen(password);
69
70 return ffi_guard_thunk(__func__, [=]() -> int {
71 auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
72
73 if(!pwdhash_fam)
74 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
75
76 auto pwdhash = pwdhash_fam->from_params(param1, param2, param3);
77
78 pwdhash->derive_key(out, out_len,
79 password, password_len,
80 salt, salt_len);
81
82 return BOTAN_FFI_SUCCESS;
83 });
84 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
salt_len
size_t salt_len
Definition: x509_obj.cpp:25
Botan::PasswordHashFamily::create
static std::unique_ptr< PasswordHashFamily > create(const std::string &algo_spec, const std::string &provider="")
Definition: pwdhash.cpp:33
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_pwdhash_timed | ( | const char * | algo,
|  | uint32_t | msec,
|  | size_t * | param1,
|  | size_t * | param2,
|  | size_t * | param3,
|  | uint8_t | out[],
|  | size_t | out_len,
|  | const char * | passphrase,
|  | size_t | passphrase_len,
|  | const uint8_t | salt[],
|  | size_t | salt_len
| ) |  |

Definition at line 86 of file ffi_kdf.cpp.

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

Referenced by botan_pbkdf_timed().

98 {
99 if(algo == nullptr || password == nullptr)
100 return BOTAN_FFI_ERROR_NULL_POINTER;
101
102 if(password_len == 0)
103 password_len = std::strlen(password);
104
105 return ffi_guard_thunk(__func__, [=]() -> int {
106
107 auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
108
109 if(!pwdhash_fam)
110 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
111
112 auto pwdhash = pwdhash_fam->tune(out_len, std::chrono::milliseconds(msec));
113
114 if(param1)
115 *param1 = pwdhash->iterations();
116 if(param2)
117 *param2 = pwdhash->parallelism();
118 if(param3)
119 *param3 = pwdhash->memory_param();
120
121 pwdhash->derive_key(out, out_len,
122 password, password_len,
123 salt, salt_len);
124
125 return BOTAN_FFI_SUCCESS;
126 });
127 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
salt_len
size_t salt_len
Definition: x509_obj.cpp:25
Botan::PasswordHashFamily::create
static std::unique_ptr< PasswordHashFamily > create(const std::string &algo_spec, const std::string &provider="")
Definition: pwdhash.cpp:33
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

  rng | rng object
  entropy | the data to add
  entropy_len | length of entropy buffer

Returns
  0 on success, a negative value on failure

Definition at line 81 of file ffi_rng.cpp.

References Botan::RandomNumberGenerator::add_entropy(), and BOTAN_FFI_DO.

82 {
83 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.add_entropy(input, len); });
84 }
Botan::RandomNumberGenerator::add_entropy
virtual void add_entropy(const uint8_t input[], size_t length)=0
Botan::RandomNumberGenerator
Definition: rng.h:24
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_rng_destroy | ( | botan_rng_t | rng | ) |

Frees all resources of the random number generator object

Parameters

  rng | rng object

Returns
  0 if success, error if invalid object handle

Definition at line 66 of file ffi_rng.cpp.

References BOTAN_FFI_CHECKED_DELETE.

67 {
68 return BOTAN_FFI_CHECKED_DELETE(rng);
69 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

Get random bytes from a random number generator

Parameters

  rng | rng object
  out | output buffer of size out_len
  out_len | number of requested bytes

Returns
  0 on success, negative on failure

Definition at line 71 of file ffi_rng.cpp.

References BOTAN_FFI_DO, and Botan::RandomNumberGenerator::randomize().

72 {
73 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.randomize(out, out_len); });
74 }
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::RandomNumberGenerator::randomize
virtual void randomize(uint8_t output[], size_t length)=0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Initialize a random number generator object

Parameters

  rng | rng object
  rng_type | type of the rng, possible values: "system": system RNG "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 21 of file ffi_rng.cpp.

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

22 {
23 return ffi_guard_thunk(__func__, [=]() -> int {
24 if(rng_out == nullptr)
25 return BOTAN_FFI_ERROR_NULL_POINTER;
26
27 const std::string rng_type_s(rng_type ? rng_type : "system");
28
29 std::unique_ptr<Botan::RandomNumberGenerator> rng;
30
31 if(rng_type_s == "system")
32 {
33 rng.reset(new Botan::System_RNG);
34 }
35 else if(rng_type_s == "user")
36 {
37 rng.reset(new Botan::AutoSeeded_RNG);
38 }
39 else if(rng_type_s == "null")
40 {
41 rng.reset(new Botan::Null_RNG);
42 }
43 #if defined(BOTAN_HAS_RDRAND_RNG)
44 else if(rng_type_s == "rdrand" && Botan::RDRAND_RNG::available())
45 {
46 rng.reset(new Botan::RDRAND_RNG);
47 }
48 #endif
49 #if defined(BOTAN_TARGET_OS_HAS_THREADS)
50 else if(rng_type_s == "user-threadsafe")
51 {
52 rng.reset(new Botan::Serialized_RNG(new Botan::AutoSeeded_RNG));
53 }
54 #endif
55
56 if(!rng)
57 {
58 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
59 }
60
61 *rng_out = new botan_rng_struct(rng.release());
62 return BOTAN_FFI_SUCCESS;
63 });
64 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::RDRAND_RNG::available
static bool available()
Definition: rdrand_rng.cpp:85
Botan::RDRAND_RNG
Definition: rdrand_rng.h:15
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::AutoSeeded_RNG
Definition: auto_rng.h:20
Botan::System_RNG
Definition: system_rng.h:25
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::Null_RNG
Definition: rng.h:204
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

  rng | rng object
  bits | number of bits to to reseed with

Returns
  0 on success, a negative value on failure

Definition at line 76 of file ffi_rng.cpp.

References BOTAN_FFI_DO, Botan::RandomNumberGenerator::reseed_from_rng(), and Botan::system_rng().

77 {
78 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.reseed_from_rng(Botan::system_rng(), bits); });
79 }
Botan::system_rng
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:279
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::RandomNumberGenerator::reseed_from_rng
virtual void reseed_from_rng(RandomNumberGenerator &rng, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS)
Definition: rng.cpp:59
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Reseed a random number generator

Parameters

  rng | rng object
  source_rng | the rng that will be read from
  bits | number of bits to to reseed with

Returns
  0 on success, a negative value on failure

Definition at line 86 of file ffi_rng.cpp.

References BOTAN_FFI_DO, Botan::RandomNumberGenerator::reseed_from_rng(), and Botan_FFI::safe_get().

87 {
88 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.reseed_from_rng(safe_get(source_rng), bits); });
89 }
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
Botan::RandomNumberGenerator::reseed_from_rng
virtual void reseed_from_rng(RandomNumberGenerator &rng, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS)
Definition: rng.cpp:59
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

References botan_constant_time_compare().

243 {
244 return botan_constant_time_compare(x, y, len);
245 }
botan_constant_time_compare
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition: ffi.cpp:237

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

References BOTAN_FFI_SUCCESS, and Botan::secure_scrub_memory().

248 {
249 Botan::secure_scrub_memory(mem, bytes);
250 return BOTAN_FFI_SUCCESS;
251 }
Botan::secure_scrub_memory
void secure_scrub_memory(void *ptr, size_t n)
Definition: os_utils.cpp:66
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

References botan_pwdhash().

146 {
147 return botan_pwdhash("Scrypt", N, r, p,
148 out, out_len,
149 password, 0,
150 salt, salt_len);
151 }
salt_len
size_t salt_len
Definition: x509_obj.cpp:25
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 *password, size_t password_len, const uint8_t salt[], size_t salt_len)
Definition: ffi_kdf.cpp:52

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

  totp | the TOTP object
  totp_code | the presented OTP
  timestamp | the current local timestamp
  acceptable_clock_drift | specifies the acceptable amount of clock drift (in terms of time steps) between the two hosts.

Definition at line 77 of file ffi_totp.cpp.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_RETURNING, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and Botan::TOTP::verify_totp().

81 {
82 #if defined(BOTAN_HAS_TOTP)
83 return BOTAN_FFI_RETURNING(Botan::TOTP, totp, t, {
84 const bool ok = t.verify_totp(totp_code, timestamp, acceptable_clock_drift);
85 return (ok ? BOTAN_FFI_SUCCESS : BOTAN_FFI_INVALID_VERIFIER);
86 });
87
88 #else
89 BOTAN_UNUSED(totp, totp_code, timestamp, acceptable_clock_drift);
90 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
91 #endif
92 }
Botan::TOTP::verify_totp
bool verify_totp(uint32_t otp, std::chrono::system_clock::time_point time, size_t clock_drift_accepted=0)
Definition: totp.cpp:39
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::TOTP
Definition: totp.h:18
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:63

int botan_totp_destroy | ( | botan_totp_t | totp | ) |

Destroy a TOTP instance

Returns
  0 if success, error if invalid object handle

Definition at line 49 of file ffi_totp.cpp.

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

50 {
51 #if defined(BOTAN_HAS_TOTP)
52 return BOTAN_FFI_CHECKED_DELETE(totp);
53 #else
54 BOTAN_UNUSED(totp);
55 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
56 #endif
57 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142

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

Generate a TOTP code for the provided timestamp

Parameters

  totp | the TOTP object
  totp_code | the OTP code will be written here
  timestamp | the current local timestamp

Definition at line 59 of file ffi_totp.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, and Botan::TOTP::generate_totp().

62 {
63 #if defined(BOTAN_HAS_TOTP)
64 if(totp == nullptr || totp_code == nullptr)
65 return BOTAN_FFI_ERROR_NULL_POINTER;
66
67 return BOTAN_FFI_DO(Botan::TOTP, totp, t, {
68 *totp_code = t.generate_totp(timestamp);
69 });
70
71 #else
72 BOTAN_UNUSED(totp, totp_code, timestamp);
73 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
74 #endif
75 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::TOTP
Definition: totp.h:18
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::TOTP::generate_totp
uint32_t generate_totp(std::chrono::system_clock::time_point time_point)
Definition: totp.cpp:27
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

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

29 {
30 if(totp == nullptr || key == nullptr || hash_algo == nullptr)
31 return BOTAN_FFI_ERROR_NULL_POINTER;
32
33 *totp = nullptr;
34
35 #if defined(BOTAN_HAS_TOTP)
36 return ffi_guard_thunk(__func__, [=]() -> int {
37
38 *totp = new botan_totp_struct(
39 new Botan::TOTP(key, key_len, hash_algo, digits, time_step));
40
41 return BOTAN_FFI_SUCCESS;
42 });
43 #else
44 BOTAN_UNUSED(totp, key, key_len, hash_algo, digits, time_step);
45 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
46 #endif
47 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::TOTP
Definition: totp.h:18
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
hash_algo
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

uint32_t botan_version_datestamp | ( | void |  | ) |

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

Definition at line 235 of file ffi.cpp.

References Botan::version_datestamp().

235 { return Botan::version_datestamp(); }
Botan::version_datestamp
uint32_t version_datestamp()
Definition: version.cpp:67

uint32_t botan_version_major | ( | void |  | ) |

Return the major version of the library

Definition at line 232 of file ffi.cpp.

References Botan::version_major().

232 { return Botan::version_major(); }
Botan::version_major
uint32_t version_major()
Definition: version.cpp:72

uint32_t botan_version_minor | ( | void |  | ) |

Return the minor version of the library

Definition at line 233 of file ffi.cpp.

References Botan::version_minor().

233 { return Botan::version_minor(); }
Botan::version_minor
uint32_t version_minor()
Definition: version.cpp:73

uint32_t botan_version_patch | ( | void |  | ) |

Return the patch version of the library

Definition at line 234 of file ffi.cpp.

References Botan::version_patch().

234 { return Botan::version_patch(); }
Botan::version_patch
uint32_t version_patch()
Definition: version.cpp:74

const char* botan_version_string | ( | void |  | ) |

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

Definition at line 227 of file ffi.cpp.

References Botan::version_cstr().

228 {
229 return Botan::version_cstr();
230 }
Botan::version_cstr
const char * version_cstr()
Definition: version.cpp:29

int botan_x509_cert_allowed_usage | ( | botan_x509_cert_t | cert,
|  | unsigned int | key_usage
| ) |  |

Definition at line 136 of file ffi_cert.cpp.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_RETURNING, BOTAN_FFI_SUCCESS, and BOTAN_UNUSED.

137 {
138 #if defined(BOTAN_HAS_X509_CERTIFICATES)
139 return BOTAN_FFI_RETURNING(Botan::X509_Certificate, cert, c, {
140 const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
141 if(c.allowed_usage(k))
142 return BOTAN_FFI_SUCCESS;
143 return 1;
144 });
145 #else
146 BOTAN_UNUSED(cert, key_usage);
147 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
148 #endif
149 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_SUCCESS
Definition: ffi.h:62
Botan::Key_Constraints
Key_Constraints
Definition: key_constraint.h:21

int botan_x509_cert_destroy | ( | botan_x509_cert_t | cert | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 151 of file ffi_cert.cpp.

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

152 {
153 #if defined(BOTAN_HAS_X509_CERTIFICATES)
154 return BOTAN_FFI_CHECKED_DELETE(cert);
155 #else
156 BOTAN_UNUSED(cert);
157 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
158 #endif
159 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142

int botan_x509_cert_dup | ( | botan_x509_cert_t * | new_cert,
|  | botan_x509_cert_t | cert
| ) |  |

Definition at line 46 of file ffi_cert.cpp.

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

47 {
48 if(!cert_obj)
49 return BOTAN_FFI_ERROR_NULL_POINTER;
50
51 #if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
52
53 return ffi_guard_thunk(__func__, [=]() -> int {
54 std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(safe_get(cert)));
55 *cert_obj = new botan_x509_cert_struct(c.release());
56 return BOTAN_FFI_SUCCESS;
57 });
58
59 #else
60 BOTAN_UNUSED(cert);
61 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
62 #endif
63 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 225 of file ffi_cert.cpp.

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

226 {
227 #if defined(BOTAN_HAS_X509_CERTIFICATES)
228 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.authority_key_id()); });
229 #else
230 BOTAN_UNUSED(cert, out, out_len);
231 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
232 #endif
233 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 215 of file ffi_cert.cpp.

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

216 {
217 #if defined(BOTAN_HAS_X509_CERTIFICATES)
218 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.fingerprint(hash)); });
219 #else
220 BOTAN_UNUSED(cert, hash, out, out_len);
221 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
222 #endif
223 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

int botan_x509_cert_get_issuer_dn | ( | botan_x509_cert_t | cert,
|  | const char * | key,
|  | size_t | index,
|  | uint8_t | out[],
|  | size_t * | out_len
| ) |  |

Definition at line 102 of file ffi_cert.cpp.

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

105 {
106 #if defined(BOTAN_HAS_X509_CERTIFICATES)
107 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.issuer_info(key).at(index)); });
108 #else
109 BOTAN_UNUSED(cert, key, index, out, out_len);
110 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
111 #endif
112 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_x509_cert_get_public_key | ( | botan_x509_cert_t | cert,
|  | botan_pubkey_t * | key
| ) |  |

Definition at line 83 of file ffi_cert.cpp.

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

84 {
85 if(key == nullptr)
86 return BOTAN_FFI_ERROR_NULL_POINTER;
87
88 *key = nullptr;
89
90 #if defined(BOTAN_HAS_X509_CERTIFICATES)
91 return ffi_guard_thunk(__func__, [=]() -> int {
92 std::unique_ptr<Botan::Public_Key> publicKey = safe_get(cert).load_subject_public_key();
93 *key = new botan_pubkey_struct(publicKey.release());
94 return BOTAN_FFI_SUCCESS;
95 });
96 #else
97 BOTAN_UNUSED(cert);
98 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
99 #endif
100 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 245 of file ffi_cert.cpp.

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

246 {
247 #if defined(BOTAN_HAS_X509_CERTIFICATES)
248 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_public_key_bits()); });
249 #else
250 BOTAN_UNUSED(cert, out, out_len);
251 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
252 #endif
253 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 205 of file ffi_cert.cpp.

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

206 {
207 #if defined(BOTAN_HAS_X509_CERTIFICATES)
208 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.serial_number()); });
209 #else
210 BOTAN_UNUSED(cert, out, out_len);
211 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
212 #endif
213 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_x509_cert_get_subject_dn | ( | botan_x509_cert_t | cert,
|  | const char * | key,
|  | size_t | index,
|  | uint8_t | out[],
|  | size_t * | out_len
| ) |  |

Definition at line 114 of file ffi_cert.cpp.

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

117 {
118 #if defined(BOTAN_HAS_X509_CERTIFICATES)
119 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.subject_info(key).at(index)); });
120 #else
121 BOTAN_UNUSED(cert, key, index, out, out_len);
122 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
123 #endif
124 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 235 of file ffi_cert.cpp.

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

236 {
237 #if defined(BOTAN_HAS_X509_CERTIFICATES)
238 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_key_id()); });
239 #else
240 BOTAN_UNUSED(cert, out, out_len);
241 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
242 #endif
243 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 171 of file ffi_cert.cpp.

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

172 {
173 #if defined(BOTAN_HAS_X509_CERTIFICATES)
174 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.not_after().to_string()); });
175 #else
176 BOTAN_UNUSED(cert, out, out_len);
177 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
178 #endif
179 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 161 of file ffi_cert.cpp.

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

162 {
163 #if defined(BOTAN_HAS_X509_CERTIFICATES)
164 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.not_before().to_string()); });
165 #else
166 BOTAN_UNUSED(cert, out, out_len);
167 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
168 #endif
169 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, and Botan::X509_Certificate::matches_dns_name().

256 {
257 if(hostname == nullptr)
258 return BOTAN_FFI_ERROR_NULL_POINTER;
259
260 #if defined(BOTAN_HAS_X509_CERTIFICATES)
261 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c,
262 { return c.matches_dns_name(hostname) ? 0 : -1; });
263 #else
264 BOTAN_UNUSED(cert);
265 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
266 #endif
267 }
Botan::X509_Certificate::matches_dns_name
bool matches_dns_name(const std::string &name) const
Definition: x509cert.cpp:729
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 65 of file ffi_cert.cpp.

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

66 {
67 if(!cert_obj || !cert_bits)
68 return BOTAN_FFI_ERROR_NULL_POINTER;
69
70 #if defined(BOTAN_HAS_X509_CERTIFICATES)
71 return ffi_guard_thunk(__func__, [=]() -> int {
72 Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
73 std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(bits));
74 *cert_obj = new botan_x509_cert_struct(c.release());
75 return BOTAN_FFI_SUCCESS;
76 });
77 #else
78 BOTAN_UNUSED(cert_bits_len);
79 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
80 #endif
81 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::DataSource_Memory
Definition: data_src.h:98
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 28 of file ffi_cert.cpp.

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

29 {
30 if(!cert_obj || !cert_path)
31 return BOTAN_FFI_ERROR_NULL_POINTER;
32
33 #if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
34
35 return ffi_guard_thunk(__func__, [=]() -> int {
36 std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(cert_path));
37 *cert_obj = new botan_x509_cert_struct(c.release());
38 return BOTAN_FFI_SUCCESS;
39 });
40
41 #else
42 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
43 #endif
44 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_x509_cert_not_after | ( | botan_x509_cert_t | cert,
|  | uint64_t * | time_since_epoch
| ) |  |

Definition at line 193 of file ffi_cert.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, Botan::X509_Certificate::not_after(), and Botan::X509_Time::time_since_epoch().

194 {
195 #if defined(BOTAN_HAS_X509_CERTIFICATES)
196 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, {
197 *time_since_epoch = c.not_after().time_since_epoch();
198 });
199 #else
200 BOTAN_UNUSED(cert, time_since_epoch);
201 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
202 #endif
203 }
Botan::X509_Time::time_since_epoch
uint64_t time_since_epoch() const
Return time since epoch.
Definition: asn1_time.cpp:266
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::X509_Certificate
Definition: x509cert.h:40
Botan::X509_Certificate::not_after
const X509_Time & not_after() const
Definition: x509cert.cpp:369
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

int botan_x509_cert_not_before | ( | botan_x509_cert_t | cert,
|  | uint64_t * | time_since_epoch
| ) |  |

Definition at line 181 of file ffi_cert.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, Botan::X509_Certificate::not_before(), and Botan::X509_Time::time_since_epoch().

182 {
183 #if defined(BOTAN_HAS_X509_CERTIFICATES)
184 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, {
185 *time_since_epoch = c.not_before().time_since_epoch();
186 });
187 #else
188 BOTAN_UNUSED(cert, time_since_epoch);
189 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
190 #endif
191 }
Botan::X509_Time::time_since_epoch
uint64_t time_since_epoch() const
Return time since epoch.
Definition: asn1_time.cpp:266
Botan::X509_Certificate::not_before
const X509_Time & not_before() const
Definition: x509cert.cpp:364
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

Definition at line 126 of file ffi_cert.cpp.

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

127 {
128 #if defined(BOTAN_HAS_X509_CERTIFICATES)
129 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.to_string()); });
130 #else
131 BOTAN_UNUSED(cert, out, out_len);
132 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
133 #endif
134 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
Botan::X509_Certificate
Definition: x509cert.h:40
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

References Botan::to_string().

341 {
342 if(code < 0)
343 return nullptr;
344
345 #if defined(BOTAN_HAS_X509_CERTIFICATES)
346 Botan::Certificate_Status_Code sc = static_cast<Botan::Certificate_Status_Code>(code);
347 return Botan::to_string(sc);
348 #else
349 return nullptr;
350 #endif
351 }
Botan::to_string
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition: exceptn.cpp:11
Botan::Certificate_Status_Code
Certificate_Status_Code
Definition: cert_status.h:19

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

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

279 {
280 if(required_strength == 0)
281 required_strength = 110;
282
283 #if defined(BOTAN_HAS_X509_CERTIFICATES)
284 return ffi_guard_thunk(__func__, [=]() -> int {
285 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
286 const Botan::Usage_Type usage = Botan::Usage_Type::UNSPECIFIED;
287 const auto validation_time = reference_time == 0 ?
288 std::chrono::system_clock::now() :
289 std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
290
291 std::vector<Botan::X509_Certificate> end_certs;
292 end_certs.push_back(safe_get(cert));
293 for(size_t i = 0; i != intermediates_len; ++i)
294 end_certs.push_back(safe_get(intermediates[i]));
295
296 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
297 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
298 std::vector<Botan::Certificate_Store*> trusted_roots;
299
300 if(trusted_path && *trusted_path)
301 {
302 trusted_from_path.reset(new Botan::Certificate_Store_In_Memory(trusted_path));
303 trusted_roots.push_back(trusted_from_path.get());
304 }
305
306 if(trusted_len > 0)
307 {
308 trusted_extra.reset(new Botan::Certificate_Store_In_Memory);
309 for(size_t i = 0; i != trusted_len; ++i)
310 {
311 trusted_extra->add_certificate(safe_get(trusted[i]));
312 }
313 trusted_roots.push_back(trusted_extra.get());
314 }
315
316 Botan::Path_Validation_Restrictions restrictions(false, required_strength);
317
318 auto validation_result = Botan::x509_path_validate(end_certs,
319 restrictions,
320 trusted_roots,
321 hostname,
322 usage,
323 validation_time);
324
325 if(result_code)
326 *result_code = static_cast<int>(validation_result.result());
327
328 if(validation_result.successful_validation())
329 return 0;
330 else
331 return 1;
332 });
333 #else
334 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
335 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time);
336 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
337 #endif
338 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::Path_Validation_Restrictions
Definition: x509path.h:34
std
Definition: bigint.h:1135
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::x509_path_validate
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, const std::string &hostname, Usage_Type usage, std::chrono::system_clock::time_point ref_time, std::chrono::milliseconds ocsp_timeout, const std::vector< std::shared_ptr< const OCSP::Response >> &ocsp_resp)
Definition: x509path.cpp:836
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
Botan::Usage_Type::UNSPECIFIED
Botan::Certificate_Store_In_Memory
Definition: certstor.h:82
Botan::Usage_Type
Usage_Type
Definition: x509cert.h:25

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

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

431 {
432 if(required_strength == 0)
433 required_strength = 110;
434
435 #if defined(BOTAN_HAS_X509_CERTIFICATES)
436 return ffi_guard_thunk(__func__, [=]() -> int {
437 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
438 const Botan::Usage_Type usage = Botan::Usage_Type::UNSPECIFIED;
439 const auto validation_time = reference_time == 0 ?
440 std::chrono::system_clock::now() :
441 std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
442
443 std::vector<Botan::X509_Certificate> end_certs;
444 end_certs.push_back(safe_get(cert));
445 for(size_t i = 0; i != intermediates_len; ++i)
446 end_certs.push_back(safe_get(intermediates[i]));
447
448 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
449 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
450 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_crls;
451 std::vector<Botan::Certificate_Store*> trusted_roots;
452
453 if(trusted_path && *trusted_path)
454 {
455 trusted_from_path.reset(new Botan::Certificate_Store_In_Memory(trusted_path));
456 trusted_roots.push_back(trusted_from_path.get());
457 }
458
459 if(trusted_len > 0)
460 {
461 trusted_extra.reset(new Botan::Certificate_Store_In_Memory);
462 for(size_t i = 0; i != trusted_len; ++i)
463 {
464 trusted_extra->add_certificate(safe_get(trusted[i]));
465 }
466 trusted_roots.push_back(trusted_extra.get());
467 }
468
469 if(crls_len > 0)
470 {
471 trusted_crls.reset(new Botan::Certificate_Store_In_Memory);
472 for(size_t i = 0; i != crls_len; ++i)
473 {
474 trusted_crls->add_crl(safe_get(crls[i]));
475 }
476 trusted_roots.push_back(trusted_crls.get());
477 }
478
479 Botan::Path_Validation_Restrictions restrictions(false, required_strength);
480
481 auto validation_result = Botan::x509_path_validate(end_certs,
482 restrictions,
483 trusted_roots,
484 hostname,
485 usage,
486 validation_time);
487
488 if(result_code)
489 *result_code = static_cast<int>(validation_result.result());
490
491 if(validation_result.successful_validation())
492 return 0;
493 else
494 return 1;
495 });
496 #else
497 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
498 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time, crls, crls_len);
499 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
500 #endif
501 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::Path_Validation_Restrictions
Definition: x509path.h:34
std
Definition: bigint.h:1135
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::x509_path_validate
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, const std::string &hostname, Usage_Type usage, std::chrono::system_clock::time_point ref_time, std::chrono::milliseconds ocsp_timeout, const std::vector< std::shared_ptr< const OCSP::Response >> &ocsp_resp)
Definition: x509path.cpp:836
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
Botan::Usage_Type::UNSPECIFIED
Botan::Certificate_Store_In_Memory
Definition: certstor.h:82
Botan::Usage_Type
Usage_Type
Definition: x509cert.h:25

int botan_x509_crl_destroy | ( | botan_x509_crl_t | crl | ) |

Definition at line 395 of file ffi_cert.cpp.

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

396 {
397 #if defined(BOTAN_HAS_X509_CERTIFICATES)
398 return BOTAN_FFI_CHECKED_DELETE(crl);
399 #else
400 BOTAN_UNUSED(crl);
401 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
402 #endif
403 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142

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

Definition at line 377 of file ffi_cert.cpp.

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

378 {
379 if(!crl_obj || !crl_bits)
380 return BOTAN_FFI_ERROR_NULL_POINTER;
381
382 #if defined(BOTAN_HAS_X509_CERTIFICATES)
383 return ffi_guard_thunk(__func__, [=]() -> int {
384 Botan::DataSource_Memory bits(crl_bits, crl_bits_len);
385 std::unique_ptr<Botan::X509_CRL> c(new Botan::X509_CRL(bits));
386 *crl_obj = new botan_x509_crl_struct(c.release());
387 return BOTAN_FFI_SUCCESS;
388 });
389 #else
390 BOTAN_UNUSED(crl_bits_len);
391 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
392 #endif
393 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::DataSource_Memory
Definition: data_src.h:98
Botan::X509_CRL
Definition: x509_crl.h:26
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Definition at line 359 of file ffi_cert.cpp.

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

360 {
361 if(!crl_obj || !crl_path)
362 return BOTAN_FFI_ERROR_NULL_POINTER;
363
364 #if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
365
366 return ffi_guard_thunk(__func__, [=]() -> int {
367 std::unique_ptr<Botan::X509_CRL> c(new Botan::X509_CRL(crl_path));
368 *crl_obj = new botan_x509_crl_struct(c.release());
369 return BOTAN_FFI_SUCCESS;
370 });
371
372 #else
373 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
374 #endif
375 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::X509_CRL
Definition: x509_crl.h:26
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_RETURNING, BOTAN_UNUSED, Botan::X509_CRL::is_revoked(), and Botan_FFI::safe_get().

406 {
407 #if defined(BOTAN_HAS_X509_CERTIFICATES)
408 return BOTAN_FFI_RETURNING(Botan::X509_CRL, crl, c, {
409 return c.is_revoked(safe_get(cert)) ? 0 : -1;
410 });
411 #else
412 BOTAN_UNUSED(cert);
413 BOTAN_UNUSED(crl);
414 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
415 #endif
416 }
Botan::X509_CRL::is_revoked
bool is_revoked(const X509_Certificate &cert) const
Definition: x509_crl.cpp:76
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
Botan::X509_CRL
Definition: x509_crl.h:26