Botan  2.4.0
Crypto and TLS for C++11
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_ERROR_BAD_FLAG   (-30)
 
#define BOTAN_FFI_ERROR_BAD_MAC   (-2)
 
#define BOTAN_FFI_ERROR_BAD_PARAMETER   (-32)
 
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN   (-20)
 
#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE   (-10)
 
#define BOTAN_FFI_ERROR_INVALID_INPUT   (-1)
 
#define BOTAN_FFI_ERROR_INVALID_OBJECT   (-50)
 
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED   (-40)
 
#define BOTAN_FFI_ERROR_NULL_POINTER   (-31)
 
#define BOTAN_FFI_ERROR_UNKNOWN_ERROR   (-100)
 
#define BOTAN_FFI_HEX_LOWER_CASE   1
 
#define BOTAN_FFI_INVALID_VERIFIER   (1)
 
#define BOTAN_FFI_SUCCESS   (0)
 
#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_hash_struct * botan_hash_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_x509_cert_struct * botan_x509_cert_t
 

Enumerations

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_init (botan_block_cipher_t *bc, const char *cipher_name)
 
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_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_query_keylen (botan_cipher_t, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
 
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)
 
uint32_t botan_ffi_api_version ()
 
int botan_ffi_supports_api (uint32_t api_version)
 
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_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_init (botan_mac_t *mac, const char *mac_name, uint32_t flags)
 
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_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_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_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_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_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_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_check_key (botan_privkey_t key, botan_rng_t rng, uint32_t flags)
 
int botan_privkey_create (botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
 
int botan_privkey_create_dh (botan_privkey_t *key, botan_rng_t rng, const char *param)
 
int botan_privkey_create_ecdh (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
int botan_privkey_create_ecdsa (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
int botan_privkey_create_mceliece (botan_privkey_t *key, botan_rng_t rng, size_t n, size_t t)
 
int botan_privkey_create_rsa (botan_privkey_t *key, botan_rng_t rng, size_t n_bits)
 
int botan_privkey_destroy (botan_privkey_t key)
 
int botan_privkey_dsa_get_x (botan_mp_t n, botan_privkey_t key)
 
int botan_privkey_ed25519_get_privkey (botan_privkey_t key, uint8_t output[64])
 
int botan_privkey_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_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_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_q (botan_mp_t q, botan_privkey_t rsa_key)
 
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_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_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_same_mem (const uint8_t *x, const uint8_t *y, size_t len)
 
int botan_scrub_mem (void *mem, size_t bytes)
 
uint32_t botan_version_datestamp ()
 
uint32_t botan_version_major ()
 
uint32_t botan_version_minor ()
 
uint32_t botan_version_patch ()
 
const char * botan_version_string ()
 
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_gen_selfsigned (botan_x509_cert_t *cert, botan_privkey_t key, botan_rng_t rng, const char *common_name, const char *org_name)
 
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_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_to_string (botan_x509_cert_t cert, char out[], size_t *out_len)
 

Macro Definition Documentation

◆ BOTAN_CHECK_KEY_EXPENSIVE_TESTS

#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS   1

Definition at line 696 of file ffi.h.

Referenced by botan_privkey_check_key(), and botan_pubkey_check_key().

◆ BOTAN_CIPHER_INIT_FLAG_DECRYPT

#define BOTAN_CIPHER_INIT_FLAG_DECRYPT   1

Definition at line 402 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_ENCRYPT

#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0

Definition at line 401 of file ffi.h.

Referenced by botan_cipher_init().

◆ BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION

#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION   1

Definition at line 400 of file ffi.h.

Referenced by botan_cipher_init().

◆ BOTAN_CIPHER_UPDATE_FLAG_FINAL

#define BOTAN_CIPHER_UPDATE_FLAG_FINAL   (1U << 0)

Definition at line 424 of file ffi.h.

Referenced by botan_cipher_update().

◆ BOTAN_FFI_ERROR_BAD_FLAG

#define BOTAN_FFI_ERROR_BAD_FLAG   (-30)

◆ BOTAN_FFI_ERROR_BAD_MAC

#define BOTAN_FFI_ERROR_BAD_MAC   (-2)

Definition at line 142 of file ffi.h.

Referenced by botan_cipher_update().

◆ BOTAN_FFI_ERROR_BAD_PARAMETER

#define BOTAN_FFI_ERROR_BAD_PARAMETER   (-32)

◆ BOTAN_FFI_ERROR_EXCEPTION_THROWN

#define BOTAN_FFI_ERROR_EXCEPTION_THROWN   (-20)

Definition at line 145 of file ffi.h.

Referenced by Botan_FFI::ffi_error_exception_thrown().

◆ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE

#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE   (-10)

◆ BOTAN_FFI_ERROR_INVALID_INPUT

#define BOTAN_FFI_ERROR_INVALID_INPUT   (-1)

Definition at line 141 of file ffi.h.

◆ BOTAN_FFI_ERROR_INVALID_OBJECT

#define BOTAN_FFI_ERROR_INVALID_OBJECT   (-50)

Definition at line 150 of file ffi.h.

Referenced by Botan_FFI::apply_fn(), and Botan_FFI::ffi_delete_object().

◆ BOTAN_FFI_ERROR_NOT_IMPLEMENTED

#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED   (-40)

◆ BOTAN_FFI_ERROR_NULL_POINTER

#define BOTAN_FFI_ERROR_NULL_POINTER   (-31)

◆ BOTAN_FFI_ERROR_UNKNOWN_ERROR

#define BOTAN_FFI_ERROR_UNKNOWN_ERROR   (-100)

◆ BOTAN_FFI_HEX_LOWER_CASE

#define BOTAN_FFI_HEX_LOWER_CASE   1

Definition at line 172 of file ffi.h.

Referenced by botan_hex_encode().

◆ BOTAN_FFI_INVALID_VERIFIER

#define BOTAN_FFI_INVALID_VERIFIER   (1)

Definition at line 139 of file ffi.h.

Referenced by botan_bcrypt_is_valid(), and botan_pk_op_verify_finish().

◆ BOTAN_FFI_SUCCESS

#define BOTAN_FFI_SUCCESS   (0)

◆ BOTAN_PRIVKEY_EXPORT_FLAG_DER

#define BOTAN_PRIVKEY_EXPORT_FLAG_DER   0

◆ BOTAN_PRIVKEY_EXPORT_FLAG_PEM

#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM   1

Typedef Documentation

◆ botan_block_cipher_t

typedef struct botan_block_cipher_struct* botan_block_cipher_t

Definition at line 516 of file ffi.h.

◆ botan_cipher_t

typedef struct botan_cipher_struct* botan_cipher_t

Definition at line 398 of file ffi.h.

◆ botan_hash_t

typedef struct botan_hash_struct* botan_hash_t

Definition at line 252 of file ffi.h.

◆ botan_mac_t

typedef struct botan_mac_struct* botan_mac_t

Definition at line 332 of file ffi.h.

◆ botan_mp_t

typedef struct botan_mp_struct* botan_mp_t

Definition at line 561 of file ffi.h.

◆ botan_pk_op_decrypt_t

typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t

Definition at line 1007 of file ffi.h.

◆ botan_pk_op_encrypt_t

typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t

Definition at line 990 of file ffi.h.

◆ botan_pk_op_ka_t

typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t

Definition at line 1057 of file ffi.h.

◆ botan_pk_op_sign_t

typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t

Definition at line 1022 of file ffi.h.

◆ botan_pk_op_verify_t

typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t

Definition at line 1041 of file ffi.h.

◆ botan_privkey_t

typedef struct botan_privkey_struct* botan_privkey_t

Definition at line 689 of file ffi.h.

◆ botan_pubkey_t

typedef struct botan_pubkey_struct* botan_pubkey_t

Definition at line 767 of file ffi.h.

◆ botan_rng_t

typedef struct botan_rng_struct* botan_rng_t

RNG type

Definition at line 208 of file ffi.h.

◆ botan_x509_cert_t

typedef struct botan_x509_cert_struct* botan_x509_cert_t

Definition at line 1099 of file ffi.h.

Enumeration Type Documentation

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

1139  {
1140  NO_CONSTRAINTS = 0,
1141  DIGITAL_SIGNATURE = 32768,
1142  NON_REPUDIATION = 16384,
1143  KEY_ENCIPHERMENT = 8192,
1144  DATA_ENCIPHERMENT = 4096,
1145  KEY_AGREEMENT = 2048,
1146  KEY_CERT_SIGN = 1024,
1147  CRL_SIGN = 512,
1148  ENCIPHER_ONLY = 256,
1149  DECIPHER_ONLY = 128
1150 };
Definition: ffi.h:1147

Function Documentation

◆ botan_base64_decode()

int botan_base64_decode ( const char *  base64_str,
size_t  in_len,
uint8_t *  out,
size_t *  out_len 
)

Perform base64 decoding

Definition at line 107 of file ffi.cpp.

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

109  {
110  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
111  if(*out_len < Botan::base64_decode_max_output(in_len))
112  {
113  *out_len = Botan::base64_decode_max_output(in_len);
115  }
116 
117  *out_len = Botan::base64_decode(out, std::string(base64_str, in_len));
118  return BOTAN_FFI_SUCCESS;
119  });
120  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
size_t base64_decode_max_output(size_t input_length)
Definition: base64.cpp:256
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
size_t base64_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
Definition: base64.cpp:100
#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:144
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_base64_encode()

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

Perform base64 encoding

Definition at line 99 of file ffi.cpp.

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

100  {
101  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
102  const std::string base64 = Botan::base64_encode(in, len);
103  return Botan_FFI::write_str_output(out, out_len, base64);
104  });
105  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition: base64.cpp:35
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_bcrypt_generate()

int botan_bcrypt_generate ( uint8_t *  out,
size_t *  out_len,
const char *  password,
botan_rng_t  rng,
size_t  work_factor,
uint32_t  flags 
)

Create a password hash using Bcrypt

Parameters
outbuffer holding the password hash, should be of length 64 bytes
out_lenthe desired output length in bytes
passwordthe password
rnga random number generator
work_factorhow much work to do to slow down guessing attacks
flagsshould be 0 in current API revision, all other uses are reserved and return BOTAN_FFI_ERROR_BAD_FLAG
Returns
0 on success, a negative value on failure

Output is formatted bcrypt $2a$...

Definition at line 61 of file ffi_kdf.cpp.

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

65  {
66 #if defined(BOTAN_HAS_BCRYPT)
67  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
68  if(out == nullptr || out_len == nullptr || pass == nullptr)
70 
71  if(flags != 0)
73 
74  if(wf < 4 || wf > 18)
75  throw FFI_Error("Bad bcrypt work factor " + std::to_string(wf));
76 
77  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
78  const std::string bcrypt = Botan::generate_bcrypt(pass, rng, static_cast<uint16_t>(wf));
79  return write_str_output(out, out_len, bcrypt);
80  });
81 #else
83 #endif
84  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
std::string generate_bcrypt(const std::string &pass, RandomNumberGenerator &rng, uint16_t work_factor)
Definition: bcrypt.cpp:126
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_bcrypt_is_valid()

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

Check a previously created password hash

Parameters
passthe password to check against
hashthe stored hash to check against
Returns
0 if if this password/hash combination is valid, 1 if the combination is not valid (but otherwise well formed), negative on error

Definition at line 86 of file ffi_kdf.cpp.

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

87  {
88 #if defined(BOTAN_HAS_BCRYPT)
89  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
91  });
92 #else
94 #endif
95  }
#define BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:139
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
bool check_bcrypt(const std::string &pass, const std::string &hash)
Definition: bcrypt.cpp:133
MechanismType hash

◆ botan_block_cipher_block_size()

int botan_block_cipher_block_size ( botan_block_cipher_t  bc)

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

Definition at line 60 of file ffi_block.cpp.

References BOTAN_FFI_DO.

61  {
62  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b,
63  { return static_cast<int>(b.block_size()); });
64  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_block_cipher_clear()

int botan_block_cipher_clear ( botan_block_cipher_t  bc)

Reinitializes the block cipher

Returns
0 on success, a negative value on failure

Definition at line 42 of file ffi_block.cpp.

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

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

◆ botan_block_cipher_decrypt_blocks()

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

Definition at line 74 of file ffi_block.cpp.

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

78  {
79  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.decrypt_n(in, out, blocks); });
80  }
virtual void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_block_cipher_destroy()

int botan_block_cipher_destroy ( botan_block_cipher_t  bc)

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  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_block_cipher_encrypt_blocks()

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

Definition at line 66 of file ffi_block.cpp.

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

70  {
71  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.encrypt_n(in, out, blocks); });
72  }
virtual void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_block_cipher_init()

int botan_block_cipher_init ( botan_block_cipher_t bc,
const char *  cipher_name 
)

Initialize a block cipher object

Definition at line 17 of file ffi_block.cpp.

References BOTAN_CURRENT_FUNCTION, 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(BOTAN_CURRENT_FUNCTION, [=]() -> int {
20  if(bc == nullptr || bc_name == nullptr || *bc_name == 0)
22 
23  *bc = nullptr;
24 
25  std::unique_ptr<Botan::BlockCipher> cipher(Botan::BlockCipher::create(bc_name));
26  if(cipher == nullptr)
28 
29  *bc = new botan_block_cipher_struct(cipher.release());
30  return BOTAN_FFI_SUCCESS;
31  });
32  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_block_cipher_set_key()

int botan_block_cipher_set_key ( botan_block_cipher_t  bc,
const uint8_t  key[],
size_t  len 
)

Set the key for a block cipher instance

Definition at line 50 of file ffi_block.cpp.

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

52  {
53  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.set_key(key, len); });
54  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_cipher_clear()

int botan_cipher_clear ( botan_cipher_t  hash)

Definition at line 39 of file ffi_cipher.cpp.

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

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

◆ botan_cipher_destroy()

int botan_cipher_destroy ( botan_cipher_t  cipher)

Definition at line 34 of file ffi_cipher.cpp.

References BOTAN_FFI_CHECKED_DELETE.

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

◆ botan_cipher_get_default_nonce_length()

int botan_cipher_get_default_nonce_length ( botan_cipher_t  cipher,
size_t *  nl 
)

Definition at line 181 of file ffi_cipher.cpp.

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

182  {
183  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *nl = c.default_nonce_length(); });
184  }
virtual size_t default_nonce_length() const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_cipher_get_tag_length()

int botan_cipher_get_tag_length ( botan_cipher_t  cipher,
size_t *  tag_size 
)

Definition at line 191 of file ffi_cipher.cpp.

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

192  {
193  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *tl = c.tag_size(); });
194  }
virtual size_t tag_size() const
Definition: cipher_mode.h:156
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_cipher_get_update_granularity()

int botan_cipher_get_update_granularity ( botan_cipher_t  cipher,
size_t *  ug 
)

Definition at line 186 of file ffi_cipher.cpp.

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

187  {
188  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *ug = c.update_granularity(); });
189  }
virtual size_t update_granularity() const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_cipher_init()

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

Definition at line 21 of file ffi_cipher.cpp.

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

22  {
23  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
25  const Botan::Cipher_Dir dir = encrypt_p ? Botan::ENCRYPTION : Botan::DECRYPTION;
26  std::unique_ptr<Botan::Cipher_Mode> mode(Botan::get_cipher_mode(cipher_name, dir));
27  if(!mode)
29  *cipher = new botan_cipher_struct(mode.release());
30  return BOTAN_FFI_SUCCESS;
31  });
32  }
#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT
Definition: ffi.h:401
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
Definition: ffi.h:400
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
Cipher_Mode * get_cipher_mode(const std::string &algo, Cipher_Dir direction, const std::string &provider)
Definition: cipher_mode.cpp:40
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_cipher_query_keylen()

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

Definition at line 44 of file ffi_cipher.cpp.

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

47  {
48  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
49  *out_minimum_keylength = c.key_spec().minimum_keylength();
50  *out_maximum_keylength = c.key_spec().maximum_keylength();
51  });
52  }
virtual Key_Length_Specification key_spec() const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
size_t minimum_keylength() const
Definition: key_spec.h:61

◆ botan_cipher_set_associated_data()

int botan_cipher_set_associated_data ( botan_cipher_t  cipher,
const uint8_t *  ad,
size_t  ad_len 
)

Definition at line 162 of file ffi_cipher.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_PARAMETER, and BOTAN_FFI_SUCCESS.

165  {
166  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
167  if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(&c))
168  {
169  aead->set_associated_data(ad, ad_len);
170  return BOTAN_FFI_SUCCESS;
171  }
173  });
174  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

◆ botan_cipher_set_key()

int botan_cipher_set_key ( botan_cipher_t  cipher,
const uint8_t *  key,
size_t  key_len 
)

Definition at line 54 of file ffi_cipher.cpp.

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

56  {
57  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { c.set_key(key, key_len); });
58  }
void set_key(const std::vector< uint8_t, Alloc > &key)
Definition: cipher_mode.h:178
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_cipher_start()

int botan_cipher_start ( botan_cipher_t  cipher,
const uint8_t *  nonce,
size_t  nonce_len 
)

Definition at line 60 of file ffi_cipher.cpp.

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

62  {
63  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
64  Botan::Cipher_Mode& cipher = safe_get(cipher_obj);
65  cipher.start(nonce, nonce_len);
66  cipher_obj->m_buf.reserve(cipher.update_granularity());
67  return BOTAN_FFI_SUCCESS;
68  });
69  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
virtual size_t update_granularity() const =0
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
void start(const std::vector< uint8_t, Alloc > &nonce)
Definition: cipher_mode.h:44
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_cipher_update()

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

Definition at line 71 of file ffi_cipher.cpp.

References BOTAN_ASSERT, BOTAN_CIPHER_UPDATE_FLAG_FINAL, BOTAN_CURRENT_FUNCTION, 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().

79  {
80  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
81 
82  size_t input_size = orig_input_size;
83  size_t output_size = orig_output_size;
84  const uint8_t* input = input_ptr;
85  uint8_t* output = output_ptr;
86 
87  using namespace Botan;
88  Cipher_Mode& cipher = safe_get(cipher_obj);
89  secure_vector<uint8_t>& mbuf = cipher_obj->m_buf;
90 
91  const bool final_input = (flags & BOTAN_CIPHER_UPDATE_FLAG_FINAL);
92 
93  if(final_input)
94  {
95  mbuf.assign(input, input + input_size);
96  *input_consumed = input_size;
97  *output_written = 0;
98 
99  try
100  {
101  cipher.finish(mbuf);
102  }
103  catch(Integrity_Failure&)
104  {
106  }
107 
108  *output_written = mbuf.size();
109 
110  if(mbuf.size() <= output_size)
111  {
112  copy_mem(output, mbuf.data(), mbuf.size());
113  mbuf.clear();
114  return BOTAN_FFI_SUCCESS;
115  }
116 
117  return -1;
118  }
119 
120  if(input_size == 0)
121  {
122  // Currently must take entire buffer in this case
123  *output_written = mbuf.size();
124  if(output_size >= mbuf.size())
125  {
126  copy_mem(output, mbuf.data(), mbuf.size());
127  mbuf.clear();
128  return BOTAN_FFI_SUCCESS;
129  }
130 
131  return -1;
132  }
133 
134  const size_t ud = cipher.update_granularity();
135  BOTAN_ASSERT(cipher.update_granularity() > cipher.minimum_final_size(), "logic error");
136 
137  mbuf.resize(ud);
138  size_t taken = 0, written = 0;
139 
140  while(input_size >= ud && output_size >= ud)
141  {
142  copy_mem(mbuf.data(), input, ud);
143  cipher.update(mbuf);
144 
145  input_size -= ud;
146  copy_mem(output, mbuf.data(), ud);
147  input += ud;
148  taken += ud;
149 
150  output_size -= ud;
151  output += ud;
152  written += ud;
153  }
154 
155  *output_written = written;
156  *input_consumed = taken;
157 
158  return BOTAN_FFI_SUCCESS;
159  });
160  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
void update(secure_vector< uint8_t > &buffer, size_t offset=0)
Definition: cipher_mode.h:87
virtual size_t update_granularity() const =0
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
virtual size_t minimum_final_size() const =0
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:29
#define BOTAN_CIPHER_UPDATE_FLAG_FINAL
Definition: ffi.h:424
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:97
Definition: alg_id.cpp:13
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
#define BOTAN_FFI_ERROR_BAD_MAC
Definition: ffi.h:142
virtual void finish(secure_vector< uint8_t > &final_block, size_t offset=0)=0

◆ botan_cipher_valid_nonce_length()

int botan_cipher_valid_nonce_length ( botan_cipher_t  cipher,
size_t  nl 
)

Definition at line 176 of file ffi_cipher.cpp.

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

177  {
178  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { return c.valid_nonce_length(nl) ? 1 : 0; });
179  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
virtual bool valid_nonce_length(size_t nonce_len) const =0

◆ botan_constant_time_compare()

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

Returns 0 if x[0..len] == y[0..len], or otherwise -1

Definition at line 66 of file ffi.cpp.

References Botan::constant_time_compare().

Referenced by botan_same_mem().

67  {
68  return Botan::constant_time_compare(x, y, len) ? 0 : -1;
69  }
bool constant_time_compare(const uint8_t x[], const uint8_t y[], size_t len)
Definition: mem_ops.cpp:44

◆ botan_ffi_api_version()

uint32_t botan_ffi_api_version ( )

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

33  {
34  return BOTAN_HAS_FFI;
35  }

◆ botan_ffi_supports_api()

int botan_ffi_supports_api ( uint32_t  api_version)

Return 0 (ok) if the version given is one this library supports. botan_ffi_supports_api(botan_ffi_api_version()) will always return 0.

Definition at line 37 of file ffi.cpp.

References BOTAN_FFI_SUCCESS.

38  {
39  // Current API version
40  if(api_version == BOTAN_HAS_FFI)
41  return BOTAN_FFI_SUCCESS;
42 
43  // Older versions that are still supported
44 
45  // This is the 2.1/2.2 API
46  if(api_version == 20170327)
47  return BOTAN_FFI_SUCCESS;
48 
49  // This is the 2.0 API
50  if(api_version == 20150515)
51  return BOTAN_FFI_SUCCESS;
52 
53  return -1;
54  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137

◆ botan_hash_block_size()

int botan_hash_block_size ( botan_hash_t  hash,
size_t *  block_size 
)

Writes the block size of the hash function to *block_size

Parameters
hashhash object
block_sizeoutput buffer to hold the hash function output length
Returns
0 on success, a negative value on failure

Definition at line 44 of file ffi_hash.cpp.

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

45  {
46  return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { *out = h.hash_block_size(); });
47  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
MechanismType hash

◆ botan_hash_clear()

int botan_hash_clear ( botan_hash_t  hash)

Reinitializes the state of the hash computation. A hash can be computed (with update/final) immediately.

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

Definition at line 49 of file ffi_hash.cpp.

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

50  {
51  return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.clear(); });
52  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
MechanismType hash

◆ botan_hash_copy_state()

int botan_hash_copy_state ( botan_hash_t dest,
const botan_hash_t  source 
)

Copy the state of a hash function object

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

Definition at line 64 of file ffi_hash.cpp.

References BOTAN_FFI_DO.

65  {
66  return BOTAN_FFI_DO(Botan::HashFunction, source, src, {
67  *dest = new botan_hash_struct(src.copy_state().release()); });
68  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_hash_destroy()

int botan_hash_destroy ( botan_hash_t  hash)

Frees all resources of the hash object

Parameters
hashhash object
Returns
always returns 0

Definition at line 34 of file ffi_hash.cpp.

References BOTAN_FFI_CHECKED_DELETE.

35  {
37  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126
MechanismType hash

◆ botan_hash_final()

int botan_hash_final ( botan_hash_t  hash,
uint8_t  out[] 
)

Finalizes the hash computation and writes the output to out[0:botan_hash_output_length()] then reinitializes for computing another digest as if botan_hash_clear had been called.

Parameters
hashhash object
outoutput buffer
Returns
0 on success, a negative value on failure

Definition at line 59 of file ffi_hash.cpp.

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

60  {
61  return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.final(out); });
62  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
MechanismType hash

◆ botan_hash_init()

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

Initialize a hash function object

Parameters
hashhash object
hash_namename of the hash function, e.g., "SHA-384"
flagsshould be 0 in current API revision, all other uses are reserved and return BOTAN_FFI_ERROR_BAD_FLAG

TODO: since output_length is effectively required to use this API, return it from init as an output parameter

Definition at line 17 of file ffi_hash.cpp.

References BOTAN_CURRENT_FUNCTION, 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(BOTAN_CURRENT_FUNCTION, [=]() -> int {
20  if(hash == nullptr || hash_name == nullptr || *hash_name == 0)
22  if(flags != 0)
24 
25  std::unique_ptr<Botan::HashFunction> h = Botan::HashFunction::create(hash_name);
26  if(h == nullptr)
28 
29  *hash = new botan_hash_struct(h.release());
30  return BOTAN_FFI_SUCCESS;
31  });
32  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:106
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147
MechanismType hash

◆ botan_hash_name()

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

TODO has no implementation

◆ botan_hash_output_length()

int botan_hash_output_length ( botan_hash_t  hash,
size_t *  output_length 
)

Writes the output length of the hash function to *output_length

Parameters
hashhash object
output_lengthoutput buffer to hold the hash function output length
Returns
0 on success, a negative value on failure

Definition at line 39 of file ffi_hash.cpp.

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

40  {
41  return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { *out = h.output_length(); });
42  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
MechanismType hash

◆ botan_hash_update()

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

Send more input to the hash function

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

Definition at line 54 of file ffi_hash.cpp.

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

55  {
56  return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.update(buf, len); });
57  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
MechanismType hash

◆ botan_hex_decode()

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

Perform hex decoding

Parameters
hex_stra string of hex chars (whitespace is ignored)
in_lenthe length of hex_str
outthe output buffer should be at least strlen(hex_str)/2 bytes
out_lenthe size of out

Definition at line 91 of file ffi.cpp.

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

92  {
93  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
94  const std::vector<uint8_t> bin = Botan::hex_decode(hex_str, in_len);
95  return Botan_FFI::write_vec_output(out, out_len, bin);
96  });
97  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
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
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_hex_encode()

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

Perform hex encoding

Parameters
xis some binary data
lenlength of x in bytes
outan array of at least x*2 bytes
flagsflags out be upper or lower case?
Returns
0 on success, 1 on failure

Definition at line 82 of file ffi.cpp.

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

83  {
84  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
85  const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
86  Botan::hex_encode(out, in, len, uppercase);
87  return BOTAN_FFI_SUCCESS;
88  });
89  }
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_FFI_HEX_LOWER_CASE
Definition: ffi.h:172
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_kdf()

int botan_kdf ( const char *  kdf_algo,
uint8_t  out[],
size_t  out_len,
const uint8_t  secret[],
size_t  secret_len,
const uint8_t  salt[],
size_t  salt_len,
const uint8_t  label[],
size_t  label_len 
)

Derive a key

Parameters
kdf_algoKDF algorithm, e.g., "SP800-56C"
outbuffer holding the derived key, must be of length out_len
out_lenthe desired output length in bytes
secretthe secret input
secret_lensize of secret in bytes
salta diversifier
salt_lensize of salt in bytes
labelpurpose for the derived keying material
label_lensize of label in bytes
Returns
0 on success, a negative value on failure

Definition at line 48 of file ffi_kdf.cpp.

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

53  {
54  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
55  std::unique_ptr<Botan::KDF> kdf(Botan::get_kdf(kdf_algo));
56  kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
57  return BOTAN_FFI_SUCCESS;
58  });
59  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
KDF * get_kdf(const std::string &algo_spec)
Definition: kdf.cpp:236
size_t salt_len
Definition: x509_obj.cpp:25
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_key_unwrap3394()

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

Definition at line 34 of file ffi_keywrap.cpp.

References BOTAN_CURRENT_FUNCTION, 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(BOTAN_CURRENT_FUNCTION, [=]() -> 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
47 #endif
48  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
secure_vector< uint8_t > rfc3394_keyunwrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:28

◆ botan_key_wrap3394()

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

Key wrapping as per RFC 3394

Definition at line 18 of file ffi_keywrap.cpp.

References BOTAN_CURRENT_FUNCTION, 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(BOTAN_CURRENT_FUNCTION, [=]() -> 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
31 #endif
32  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
secure_vector< uint8_t > rfc3394_keywrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:14

◆ botan_mac_clear()

int botan_mac_clear ( botan_mac_t  mac)

Reinitializes the state of the MAC computation. A MAC can be computed (with update/final) immediately.

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

Definition at line 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  }
virtual void clear()=0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mac_destroy()

int botan_mac_destroy ( botan_mac_t  mac)

Frees all resources of the MAC object

Parameters
macmac object
Returns
always returns 0

Definition at line 34 of file ffi_mac.cpp.

References BOTAN_FFI_CHECKED_DELETE.

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

◆ botan_mac_final()

int botan_mac_final ( botan_mac_t  mac,
uint8_t  out[] 
)

Finalizes the MAC computation and writes the output to out[0:botan_mac_output_length()] then reinitializes for computing another MAC as if botan_mac_clear had been called.

Parameters
macmac object
outoutput buffer
Returns
0 on success, a negative value on failure

Definition at line 59 of file ffi_mac.cpp.

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

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

◆ botan_mac_init()

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

Initialize a message authentication code object

Parameters
macmac object
mac_namename of the hash function, e.g., "HMAC(SHA-384)"
flagsshould be 0 in current API revision, all other uses are reserved and return a negative value (error code)
Returns
0 on success, a negative value on failure

Definition at line 17 of file ffi_mac.cpp.

References BOTAN_CURRENT_FUNCTION, 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(BOTAN_CURRENT_FUNCTION, [=]() -> int {
20  if(!mac || !mac_name || flags != 0)
22 
23  std::unique_ptr<Botan::MessageAuthenticationCode> m =
25 
26  if(m == nullptr)
28 
29  *mac = new botan_mac_struct(m.release());
30  return BOTAN_FFI_SUCCESS;
31  });
32  }
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
Definition: mac.cpp:45
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_mac_output_length()

int botan_mac_output_length ( botan_mac_t  mac,
size_t *  output_length 
)

Writes the output length of the message authentication code to *output_length

Parameters
macmac object
output_lengthoutput buffer to hold the MAC output length
Returns
0 on success, a negative value on failure

Definition at line 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  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
virtual size_t output_length() const =0

◆ botan_mac_set_key()

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

Sets the key on the MAC

Parameters
macmac object
keybuffer holding the key
key_lensize of the key buffer in bytes
Returns
0 on success, a negative value on failure

Definition at line 39 of file ffi_mac.cpp.

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  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mac_update()

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

Send more input to the message authentication code

Parameters
macmac object
bufinput buffer
lennumber of bytes to read from the input buffer
Returns
0 on success, a negative value on failure

Definition at line 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  }
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:34
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mceies_decrypt()

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

Definition at line 777 of file ffi_pkey_algs.cpp.

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

782  {
783  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
784  Botan::Private_Key& key = safe_get(mce_key_obj);
785 
786 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
787  Botan::McEliece_PrivateKey* mce = dynamic_cast<Botan::McEliece_PrivateKey*>(&key);
788  if(!mce)
790 
791  const Botan::secure_vector<uint8_t> pt = mceies_decrypt(*mce, ct, ct_len, ad, ad_len, aead);
792  return write_vec_output(out, out_len, pt);
793 #else
795 #endif
796  });
797  }
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:71
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

◆ botan_mceies_encrypt()

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

Definition at line 799 of file ffi_pkey_algs.cpp.

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

805  {
806  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
807  Botan::Public_Key& key = safe_get(mce_key_obj);
808  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
809 
810 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
811  Botan::McEliece_PublicKey* mce = dynamic_cast<Botan::McEliece_PublicKey*>(&key);
812  if(!mce)
814 
815  Botan::secure_vector<uint8_t> ct = mceies_encrypt(*mce, pt, pt_len, ad, ad_len, rng, aead);
816  return write_vec_output(out, out_len, ct);
817 #else
819 #endif
820  });
821  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
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:34
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

◆ botan_mp_add()

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

Definition at line 143 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

144  {
145  return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) + safe_get(y); });
146  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_clear()

int botan_mp_clear ( botan_mp_t  mp)

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  }
void clear()
Definition: bigint.h:222
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_clear_bit()

int botan_mp_clear_bit ( botan_mp_t  n,
size_t  bit 
)

Clear the specified bit

Definition at line 266 of file ffi_mp.cpp.

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

267  {
268  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.clear_bit(bit); });
269  }
void clear_bit(size_t n)
Definition: bigint.cpp:167
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_cmp()

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

Definition at line 189 of file ffi_mp.cpp.

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

190  {
191  return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { *result = x.cmp(safe_get(y_w)); });
192  }
int32_t cmp(const BigInt &n, bool check_signs=true) const
Definition: bigint.cpp:97
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_destroy()

int botan_mp_destroy ( botan_mp_t  mp)

Definition at line 138 of file ffi_mp.cpp.

References BOTAN_FFI_CHECKED_DELETE.

139  {
140  return BOTAN_FFI_CHECKED_DELETE(mp);
141  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_mp_div()

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

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

161  {
162  return BOTAN_FFI_DO(Botan::BigInt, quotient, q, {
163  Botan::BigInt r;
164  Botan::divide(safe_get(x), safe_get(y), q, r);
165  safe_get(remainder) = r;
166  });
167  }
void divide(const BigInt &x, const BigInt &y_arg, BigInt &q, BigInt &r)
Definition: divide.cpp:58
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_equal()

int botan_mp_equal ( const botan_mp_t  x,
const botan_mp_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, x_w, x, { return x == safe_get(y_w); });
172  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_flip_sign()

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  }
void flip_sign()
Definition: bigint.cpp:225
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_from_bin()

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  }
void binary_decode(const uint8_t buf[], size_t length)
Definition: bigint.cpp:279
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_gcd()

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

Definition at line 244 of file ffi_mp.cpp.

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

245  {
246  return BOTAN_FFI_DO(Botan::BigInt, out, o, {
247  o = Botan::gcd(safe_get(x), safe_get(y)); });
248  }
BigInt gcd(const BigInt &a, const BigInt &b)
Definition: numthry.cpp:47
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_get_bit()

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

References BOTAN_FFI_DO.

257  {
258  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { return (n.get_bit(bit)); });
259  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_init()

int botan_mp_init ( botan_mp_t mp)

Definition at line 20 of file ffi_mp.cpp.

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

21  {
22  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
23  if(mp_out == nullptr)
25 
26  *mp_out = new botan_mp_struct(new Botan::BigInt);
27  return BOTAN_FFI_SUCCESS;
28  });
29  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_mp_is_even()

int botan_mp_is_even ( const botan_mp_t  mp)

Definition at line 184 of file ffi_mp.cpp.

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

185  {
186  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_even(); });
187  }
bool is_even() const
Definition: bigint.h:237
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_is_negative()

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  }
bool is_negative() const
Definition: bigint.h:353
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_is_odd()

int botan_mp_is_odd ( const botan_mp_t  mp)

Definition at line 179 of file ffi_mp.cpp.

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

180  {
181  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_odd(); });
182  }
bool is_odd() const
Definition: bigint.h:243
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_is_positive()

int botan_mp_is_positive ( const botan_mp_t  mp)

This function is not well named. 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  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
bool is_positive() const
Definition: bigint.h:359

◆ botan_mp_is_prime()

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

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

251  {
252  return BOTAN_FFI_DO(Botan::BigInt, mp, n,
253  { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; });
254  }
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition: numthry.cpp:455
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_is_zero()

int botan_mp_is_zero ( const botan_mp_t  mp)

Definition at line 174 of file ffi_mp.cpp.

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

175  {
176  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_zero(); });
177  }
bool is_zero() const
Definition: bigint.h:255
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_lshift()

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

Definition at line 206 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

207  {
208  return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) << shift; });
209  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_mod_inverse()

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

Definition at line 216 of file ffi_mp.cpp.

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

217  {
218  return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); });
219  }
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:277
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_mod_mul()

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

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

222  {
223  return BOTAN_FFI_DO(Botan::BigInt, out, o, {
224  Botan::Modular_Reducer reducer(safe_get(modulus));
225  o = reducer.multiply(safe_get(x), safe_get(y));
226  });
227  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_mul()

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

Definition at line 153 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

154  {
155  return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) * safe_get(y); });
156  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_num_bits()

int botan_mp_num_bits ( const botan_mp_t  n,
size_t *  bits 
)

Definition at line 271 of file ffi_mp.cpp.

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

272  {
273  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bits = n.bits(); });
274  }
size_t bits() const
Definition: bigint.cpp:183
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_num_bytes()

int botan_mp_num_bytes ( const botan_mp_t  n,
size_t *  bytes 
)

Definition at line 276 of file ffi_mp.cpp.

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

277  {
278  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bytes = n.bytes(); });
279  }
size_t bytes() const
Definition: bigint.cpp:175
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_powmod()

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

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

201  {
202  return BOTAN_FFI_DO(Botan::BigInt, out, o,
203  { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
204  }
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:374
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_rand_bits()

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

Definition at line 229 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

230  {
232  safe_get(rand_out).randomize(r, bits); });
233  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_rand_range()

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

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

239  {
241  safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
242  }
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
Definition: big_rand.cpp:45
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_rshift()

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

Definition at line 211 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

212  {
213  return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) >> shift; });
214  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_set_bit()

int botan_mp_set_bit ( botan_mp_t  n,
size_t  bit 
)

Set the specified bit

Definition at line 261 of file ffi_mp.cpp.

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

262  {
263  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.set_bit(bit); });
264  }
void set_bit(size_t n)
Definition: bigint.cpp:156
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_set_from_int()

int botan_mp_set_from_int ( botan_mp_t  mp,
int  initial_value 
)

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  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_set_from_mp()

int botan_mp_set_from_mp ( botan_mp_t  dest,
const botan_mp_t  source 
)

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  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_set_from_radix_str()

int botan_mp_set_from_radix_str ( botan_mp_t  dest,
const char *  str,
size_t  radix 
)

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, Botan::BigInt::decode(), and Botan::BigInt::Hexadecimal.

57  {
58  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
60  if(radix == 10)
62  else if(radix == 16)
64  else
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::decode(bytes, len, base);
71  });
72  }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:120
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
static BigInt decode(const uint8_t buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:114

◆ botan_mp_set_from_str()

int botan_mp_set_from_str ( botan_mp_t  dest,
const char *  str 
)

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  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_sub()

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

Definition at line 148 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

149  {
150  return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) - safe_get(y); });
151  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_swap()

int botan_mp_swap ( botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 194 of file ffi_mp.cpp.

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

195  {
196  return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { x.swap(safe_get(y_w)); });
197  }
void swap(BigInt &other)
Definition: bigint.h:127
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_to_bin()

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

Definition at line 125 of file ffi_mp.cpp.

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

126  {
127  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_encode(vec); });
128  }
void binary_encode(uint8_t buf[]) const
Definition: bigint.cpp:269
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_to_hex()

int botan_mp_to_hex ( const botan_mp_t  mp,
char *  out 
)

Definition at line 99 of file ffi_mp.cpp.

References BOTAN_FFI_DO, Botan::BigInt::encode(), and Botan::BigInt::Hexadecimal.

100  {
101  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
102  std::vector<uint8_t> hex = Botan::BigInt::encode(bn, Botan::BigInt::Hexadecimal);
103  std::memcpy(out, hex.data(), hex.size());
104  out[hex.size()] = 0; // null terminate
105  });
106  }
static std::vector< uint8_t > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:54
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_to_str()

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

Definition at line 108 of file ffi_mp.cpp.

References BOTAN_FFI_DO, Botan::BigInt::Decimal, Botan::BigInt::encode(), Botan::BigInt::Hexadecimal, and Botan_FFI::write_str_output().

109  {
110  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
111  Botan::BigInt::Base base;
112  if(digit_base == 0 || digit_base == 10)
113  base = Botan::BigInt::Decimal;
114  else if(digit_base == 16)
116  else
117  throw FFI_Error("botan_mp_to_str invalid digit base");
118 
119  std::vector<uint8_t> hex = Botan::BigInt::encode(bn, base);
120  hex.push_back(0); // null terminator
121  return write_str_output(out, out_len, hex);
122  });
123  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
static std::vector< uint8_t > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:54
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_to_uint32()

int botan_mp_to_uint32 ( const botan_mp_t  mp,
uint32_t *  val 
)

Definition at line 130 of file ffi_mp.cpp.

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

131  {
132  if(val == nullptr) {
134  }
135  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { *val = bn.to_u32bit(); });
136  }
uint32_t to_u32bit() const
Definition: bigint.cpp:140
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pbkdf()

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

Definition at line 21 of file ffi_kdf.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan::get_pbkdf().

24  {
25  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
26  std::unique_ptr<Botan::PBKDF> pbkdf(Botan::get_pbkdf(pbkdf_algo));
27  pbkdf->pbkdf_iterations(out, out_len, pass, salt, salt_len, iterations);
28  return BOTAN_FFI_SUCCESS;
29  });
30  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
PBKDF * get_pbkdf(const std::string &algo_spec, const std::string &provider="")
Definition: pbkdf.h:230
size_t salt_len
Definition: x509_obj.cpp:25
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pbkdf_timed()

int botan_pbkdf_timed ( const char *  pbkdf_algo,
uint8_t  out[],
size_t  out_len,
const char *  passphrase,
const uint8_t  salt[],
size_t  salt_len,
size_t  milliseconds_to_run,
size_t *  out_iterations_used 
)

Derive a key from a passphrase, running until msec time has elapsed.

Parameters
pbkdf_algoPBKDF algorithm, e.g., "PBKDF2"
outbuffer to store the derived key, must be of out_len bytes
out_lenthe desired length of the key to produce
passphrasethe password to derive the key from
salta randomly chosen salt
salt_lenlength of salt in bytes
milliseconds_to_runif iterations is zero, then instead the PBKDF is run until milliseconds_to_run milliseconds has passed
out_iterations_usedset to the number iterations executed
Returns
0 on success, a negative value on failure

Definition at line 32 of file ffi_kdf.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan::get_pbkdf().

38  {
39  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
40  std::unique_ptr<Botan::PBKDF> pbkdf(Botan::get_pbkdf(pbkdf_algo));
41  pbkdf->pbkdf_timed(out, out_len, password, salt, salt_len,
42  std::chrono::milliseconds(ms_to_run),
43  *iterations_used);
44  return BOTAN_FFI_SUCCESS;
45  });
46  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
PBKDF * get_pbkdf(const std::string &algo_spec, const std::string &provider="")
Definition: pbkdf.h:230
size_t salt_len
Definition: x509_obj.cpp:25
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pk_op_decrypt()

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

Definition at line 84 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

87  {
88  return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, {
89  return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len));
90  });
91  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pk_op_decrypt_create()

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

Definition at line 60 of file ffi_pk_op.cpp.

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

64  {
65  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
67 
68  *op = nullptr;
69 
70  if(flags != 0)
72 
73  std::unique_ptr<Botan::PK_Decryptor> pk(new Botan::PK_Decryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
74  *op = new botan_pk_op_decrypt_struct(pk.release());
75  return BOTAN_FFI_SUCCESS;
76  });
77  }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:230
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pk_op_decrypt_destroy()

int botan_pk_op_decrypt_destroy ( botan_pk_op_decrypt_t  op)

Definition at line 79 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

80  {
81  return BOTAN_FFI_CHECKED_DELETE(op);
82  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_pk_op_encrypt()

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

Definition at line 47 of file ffi_pk_op.cpp.

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

51  {
52  return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, {
53  return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
54  });
55  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pk_op_encrypt_create()

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

Definition at line 23 of file ffi_pk_op.cpp.

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

27  {
28  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
30 
31  *op = nullptr;
32 
33  if(flags != 0)
35 
36  std::unique_ptr<Botan::PK_Encryptor> pk(new Botan::PK_Encryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
37  *op = new botan_pk_op_encrypt_struct(pk.release());
38  return BOTAN_FFI_SUCCESS;
39  });
40  }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:230
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pk_op_encrypt_destroy()

int botan_pk_op_encrypt_destroy ( botan_pk_op_encrypt_t  op)

Definition at line 42 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

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

◆ botan_pk_op_key_agreement()

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

Definition at line 205 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().

209  {
210  return BOTAN_FFI_DO(Botan::PK_Key_Agreement, op, o, {
211  auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
212  return write_vec_output(out, out_len, k);
213  });
214  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
size_t salt_len
Definition: x509_obj.cpp:25
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:203
secure_vector< uint8_t > bits_of() const
Definition: symkey.h:31
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pk_op_key_agreement_create()

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

Definition at line 171 of file ffi_pk_op.cpp.

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

175  {
176  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
178 
179  *op = nullptr;
180 
181  if(flags != 0)
183 
184  std::unique_ptr<Botan::PK_Key_Agreement> pk(new Botan::PK_Key_Agreement(safe_get(key_obj), Botan::system_rng(), kdf));
185  *op = new botan_pk_op_ka_struct(pk.release());
186  return BOTAN_FFI_SUCCESS;
187  });
188  }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:230
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pk_op_key_agreement_destroy()

int botan_pk_op_key_agreement_destroy ( botan_pk_op_ka_t  op)

Definition at line 190 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

191  {
192  return BOTAN_FFI_CHECKED_DELETE(op);
193  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_pk_op_key_agreement_export_public()

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

Definition at line 195 of file ffi_pk_op.cpp.

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

197  {
198  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
199  if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
200  return write_vec_output(out, out_len, kak->public_value());
202  });
203  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pk_op_sign_create()

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

Definition at line 96 of file ffi_pk_op.cpp.

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

100  {
101  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
103 
104  *op = nullptr;
105 
106  if(flags != 0)
108 
109  std::unique_ptr<Botan::PK_Signer> pk(new Botan::PK_Signer(safe_get(key_obj),Botan::system_rng(), hash));
110  *op = new botan_pk_op_sign_struct(pk.release());
111  return BOTAN_FFI_SUCCESS;
112  });
113  }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:230
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
MechanismType hash

◆ botan_pk_op_sign_destroy()

int botan_pk_op_sign_destroy ( botan_pk_op_sign_t  op)

Definition at line 115 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

116  {
117  return BOTAN_FFI_CHECKED_DELETE(op);
118  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_pk_op_sign_finish()

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

Definition at line 125 of file ffi_pk_op.cpp.

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

126  {
127  return BOTAN_FFI_DO(Botan::PK_Signer, op, o, {
128  return write_vec_output(out, out_len, o.signature(safe_get(rng_obj)));
129  });
130  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pk_op_sign_update()

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

Definition at line 120 of file ffi_pk_op.cpp.

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

121  {
122  return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { o.update(in, in_len); });
123  }
void update(uint8_t in)
Definition: pubkey.h:238
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pk_op_verify_create()

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

Definition at line 132 of file ffi_pk_op.cpp.

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

136  {
137  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
139 
140  if(flags != 0)
142 
143  std::unique_ptr<Botan::PK_Verifier> pk(new Botan::PK_Verifier(safe_get(key_obj), hash));
144  *op = new botan_pk_op_verify_struct(pk.release());
145  return BOTAN_FFI_SUCCESS;
146  });
147  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
MechanismType hash

◆ botan_pk_op_verify_destroy()

int botan_pk_op_verify_destroy ( botan_pk_op_verify_t  op)

Definition at line 149 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

150  {
151  return BOTAN_FFI_CHECKED_DELETE(op);
152  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_pk_op_verify_finish()

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

Definition at line 159 of file ffi_pk_op.cpp.

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

160  {
161  return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, {
162  const bool legit = o.check_signature(sig, sig_len);
163 
164  if(legit)
165  return BOTAN_FFI_SUCCESS;
166  else
168  });
169  }
#define BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:139
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:293
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pk_op_verify_update()

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

Definition at line 154 of file ffi_pk_op.cpp.

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

155  {
156  return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, { o.update(in, in_len); });
157  }
void update(uint8_t in)
Definition: pubkey.h:335
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pkcs_hash_id()

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

Definition at line 260 of file ffi_pkey.cpp.

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

261  {
262 #if defined(BOTAN_HAS_HASH_ID)
263  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
264  const std::vector<uint8_t> hash_id = Botan::pkcs_hash_id(hash_name);
265  return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
266  });
267 #else
269 #endif
270  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
int write_output(uint8_t out[], size_t *out_len, const uint8_t buf[], size_t buf_len)
Definition: ffi_util.h:128
std::vector< uint8_t > pkcs_hash_id(const std::string &name)
Definition: hash_id.cpp:77

◆ botan_privkey_check_key()

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

Definition at line 139 of file ffi_pkey.cpp.

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

140  {
141  const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
142  return BOTAN_FFI_DO(Botan::Private_Key, key, k,
143  { return (k.check_key(safe_get(rng), strong) == true) ? 0 : -1; });
144  }
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition: ffi.h:696
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_privkey_create()

int botan_privkey_create ( botan_privkey_t key,
const char *  algo_name,
const char *  algo_params,
botan_rng_t  rng 
)

Definition at line 26 of file ffi_pkey.cpp.

References BOTAN_CURRENT_FUNCTION, 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(BOTAN_CURRENT_FUNCTION, [=]() -> int {
32  if(key_obj == nullptr)
34 
35  *key_obj = nullptr;
36  if(rng_obj == nullptr)
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  {
53  }
54  });
55  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
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:273
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_privkey_create_dh()

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

Definition at line 480 of file ffi_pkey_algs.cpp.

References botan_privkey_create().

481  {
482  return botan_privkey_create(key_obj, "DH", param_str, rng_obj);
483  }
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

◆ botan_privkey_create_ecdh()

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

Definition at line 520 of file ffi_pkey_algs.cpp.

References BOTAN_FFI_ERROR_NULL_POINTER, and botan_privkey_create().

521  {
522  if(param_str == nullptr)
524 
525  const std::string params(param_str);
526 
527  if(params == "curve25519")
528  return botan_privkey_create(key_obj, "Curve25519", "", rng_obj);
529 
530  return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
531  }
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
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_privkey_create_ecdsa()

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

Definition at line 397 of file ffi_pkey_algs.cpp.

References botan_privkey_create().

398  {
399  return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
400  }
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

◆ botan_privkey_create_mceliece()

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

Definition at line 771 of file ffi_pkey_algs.cpp.

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

772  {
773  const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
774  return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
775  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108
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

◆ botan_privkey_create_rsa()

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

Definition at line 257 of file ffi_pkey_algs.cpp.

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

258  {
259  if(n_bits < 1024 || n_bits > 16*1024)
261 
262  std::string n_str = std::to_string(n_bits);
263 
264  return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
265  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108
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
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

◆ botan_privkey_destroy()

int botan_privkey_destroy ( botan_privkey_t  key)

Definition at line 88 of file ffi_pkey.cpp.

References BOTAN_FFI_CHECKED_DELETE.

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

◆ botan_privkey_dsa_get_x()

int botan_privkey_dsa_get_x ( botan_mp_t  n,
botan_privkey_t  key 
)

Definition at line 372 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

373  {
374  return botan_privkey_get_field(x, key, "x");
375  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_ed25519_get_privkey()

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

Definition at line 723 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().

725  {
726 #if defined(BOTAN_HAS_ED25519)
727  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
728  if(Botan::Ed25519_PrivateKey* ed = dynamic_cast<Botan::Ed25519_PrivateKey*>(&k))
729  {
730  const Botan::secure_vector<uint8_t>& ed_key = ed->get_private_key();
731  if(ed_key.size() != 64)
733  Botan::copy_mem(output, ed_key.data(), ed_key.size());
734  return BOTAN_FFI_SUCCESS;
735  }
736  else
737  {
739  }
740  });
741 #else
742  BOTAN_UNUSED(key, output);
744 #endif
745  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:97
#define BOTAN_UNUSED(...)
Definition: assert.h:106
#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:144
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

◆ botan_privkey_export()

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

Definition at line 158 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().

159  {
160  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
162  return write_vec_output(out, out_len, Botan::PKCS8::BER_encode(k));
164  return write_str_output(out, out_len, Botan::PKCS8::PEM_encode(k));
165  else
167  });
168  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:717
Flags flags(Flag flags)
Definition: p11.h:858
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:716
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:140
secure_vector< uint8_t > BER_encode(const Private_Key &key)
Definition: pkcs8.cpp:131
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_privkey_export_encrypted()

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

Definition at line 170 of file ffi_pkey.cpp.

References botan_privkey_export_encrypted_pbkdf_iter().

176  {
177  return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
178  }
Flags flags(Flag flags)
Definition: p11.h:858
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:214

◆ botan_privkey_export_encrypted_pbkdf_iter()

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

Definition at line 214 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().

222  {
223  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
224  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
225 
226  const std::string cipher = (maybe_cipher ? maybe_cipher : "");
227  const std::string pbkdf_hash = (maybe_pbkdf_hash ? maybe_pbkdf_hash : "");
228 
230  {
231  return write_vec_output(out, out_len,
232  Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
233  }
235  {
236  return write_str_output(out, out_len,
237  Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
238  }
239  else
240  {
241  return -2;
242  }
243  });
244  }
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:717
Flags flags(Flag flags)
Definition: p11.h:858
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:209
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:716
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:234
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_privkey_export_encrypted_pbkdf_msec()

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

Definition at line 180 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().

189  {
190  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
191  const std::chrono::milliseconds pbkdf_time(pbkdf_msec);
192  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
193 
194  const std::string cipher = (maybe_cipher ? maybe_cipher : "");
195  const std::string pbkdf_hash = (maybe_pbkdf_hash ? maybe_pbkdf_hash : "");
196 
198  {
199  return write_vec_output(out, out_len,
200  Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
201  }
203  {
204  return write_str_output(out, out_len,
205  Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
206  }
207  else
208  {
209  return -2;
210  }
211  });
212  }
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:717
Flags flags(Flag flags)
Definition: p11.h:858
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
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:249
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:716
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
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:275

◆ botan_privkey_export_pubkey()

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_CURRENT_FUNCTION, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan::X509::load_key(), and Botan_FFI::safe_get().

116  {
117  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
118  std::unique_ptr<Botan::Public_Key>
120 
121  *pubout = new botan_pubkey_struct(pubkey.release());
122  return BOTAN_FFI_SUCCESS;
123  });
124  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.cpp:19
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:37

◆ botan_privkey_get_field()

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

Definition at line 241 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().

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

◆ botan_privkey_load()

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

Definition at line 57 of file ffi_pkey.cpp.

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

60  {
61  *key = nullptr;
62 
63  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
64  Botan::DataSource_Memory src(bits, len);
65 
66  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
67 
68  std::unique_ptr<Botan::Private_Key> pkcs8;
69 
70  if(password == nullptr)
71  {
72  pkcs8.reset(Botan::PKCS8::load_key(src, rng));
73  }
74  else
75  {
76  pkcs8.reset(Botan::PKCS8::load_key(src, rng, static_cast<std::string>(password)));
77  }
78 
79  if(pkcs8)
80  {
81  *key = new botan_privkey_struct(pkcs8.release());
82  return BOTAN_FFI_SUCCESS;
83  }
85  });
86  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:152
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::unique_ptr< Private_Key > load_key(DataSource &source, std::function< std::string()> get_pass)
Definition: pkcs8.cpp:314

◆ botan_privkey_load_dh()

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

Definition at line 485 of file ffi_pkey_algs.cpp.

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

487  {
488 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
489  *key = nullptr;
490  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
491  Botan::Null_RNG null_rng;
492  Botan::DL_Group group(safe_get(p), safe_get(g));
493  *key = new botan_privkey_struct(new Botan::DH_PrivateKey(null_rng, group, safe_get(x)));
494  return BOTAN_FFI_SUCCESS;
495  });
496 #else
497  BOTAN_UNUSED(key, p, g, x);
499 #endif
500  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_load_dsa()

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

Definition at line 337 of file ffi_pkey_algs.cpp.

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

339  {
340 #if defined(BOTAN_HAS_DSA)
341  *key = nullptr;
342 
343  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
344  Botan::Null_RNG null_rng;
345  Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
346  *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(null_rng, group, safe_get(x)));
347  return BOTAN_FFI_SUCCESS;
348  });
349 #else
350  BOTAN_UNUSED(key, p, q, g, x);
352 #endif
353  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_load_ecdh()

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

Definition at line 553 of file ffi_pkey_algs.cpp.

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

556  {
557 #if defined(BOTAN_HAS_ECDH)
558  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
559  std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
560  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
561  if(rc == BOTAN_FFI_SUCCESS)
562  *key = new botan_privkey_struct(p_key.release());
563  return rc;
564  });
565 #else
566  BOTAN_UNUSED(key, scalar, curve_name);
568 #endif
569  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_load_ecdsa()

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

Definition at line 425 of file ffi_pkey_algs.cpp.

References BOTAN_CURRENT_FUNCTION, 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_ECDSA)
430  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
431  std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
432  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
433  if(rc == BOTAN_FFI_SUCCESS)
434  *key = new botan_privkey_struct(p_key.release());
435  return rc;
436  });
437 #else
438  BOTAN_UNUSED(key, scalar, curve_name);
440 #endif
441  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_load_ed25519()

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

Definition at line 691 of file ffi_pkey_algs.cpp.

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

693  {
694 #if defined(BOTAN_HAS_ED25519)
695  *key = nullptr;
696  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
697  const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
698  *key = new botan_privkey_struct(new Botan::Ed25519_PrivateKey(privkey_vec));
699  return BOTAN_FFI_SUCCESS;
700  });
701 #else
702  BOTAN_UNUSED(key, privkey);
704 #endif
705  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88

◆ botan_privkey_load_elgamal()

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

Definition at line 461 of file ffi_pkey_algs.cpp.

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

463  {
464 #if defined(BOTAN_HAS_ELGAMAL)
465  *key = nullptr;
466  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
467  Botan::Null_RNG null_rng;
468  Botan::DL_Group group(safe_get(p), safe_get(g));
469  *key = new botan_privkey_struct(new Botan::ElGamal_PrivateKey(null_rng, group, safe_get(x)));
470  return BOTAN_FFI_SUCCESS;
471  });
472 #else
473  BOTAN_UNUSED(key, p, g, x);
475 #endif
476  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_load_rsa()

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

Definition at line 267 of file ffi_pkey_algs.cpp.

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

269  {
270 #if defined(BOTAN_HAS_RSA)
271  *key = nullptr;
272 
273  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
274  *key = new botan_privkey_struct(new Botan::RSA_PrivateKey(safe_get(rsa_p),
275  safe_get(rsa_q),
276  safe_get(rsa_e)));
277  return BOTAN_FFI_SUCCESS;
278  });
279 #else
280  BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
282 #endif
283  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_load_sm2()

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

Definition at line 630 of file ffi_pkey_algs.cpp.

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

633  {
634 #if defined(BOTAN_HAS_SM2)
635  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
636  std::unique_ptr<Botan::SM2_Signature_PrivateKey> p_key;
637  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
638 
639  if(rc == BOTAN_FFI_SUCCESS)
640  *key = new botan_privkey_struct(p_key.release());
641  return rc;
642  });
643 #else
644  BOTAN_UNUSED(key, scalar, curve_name);
646 #endif
647  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_load_sm2_enc()

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

Definition at line 670 of file ffi_pkey_algs.cpp.

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

673  {
674 #if defined(BOTAN_HAS_SM2)
675  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
676  std::unique_ptr<Botan::SM2_Encryption_PrivateKey> p_key;
677  int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
678 
679  if(rc == BOTAN_FFI_SUCCESS)
680  *key = new botan_privkey_struct(p_key.release());
681  return rc;
682  });
683 #else
684  BOTAN_UNUSED(key, scalar, curve_name);
686 #endif
687  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_privkey_rsa_get_d()

int botan_privkey_rsa_get_d ( botan_mp_t  d,
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(d, key, "d");
323  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_rsa_get_e()

int botan_privkey_rsa_get_e ( botan_mp_t  e,
botan_privkey_t  rsa_key 
)

Definition at line 315 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

316  {
317  return botan_privkey_get_field(e, key, "e");
318  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_rsa_get_n()

int botan_privkey_rsa_get_n ( botan_mp_t  n,
botan_privkey_t  rsa_key 
)

Definition at line 310 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

311  {
312  return botan_privkey_get_field(n, key, "n");
313  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_rsa_get_p()

int botan_privkey_rsa_get_p ( botan_mp_t  p,
botan_privkey_t  rsa_key 
)

Definition at line 300 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

301  {
302  return botan_privkey_get_field(p, key, "p");
303  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_privkey_rsa_get_q()

int botan_privkey_rsa_get_q ( botan_mp_t  q,
botan_privkey_t  rsa_key 
)

Definition at line 305 of file ffi_pkey_algs.cpp.

References botan_privkey_get_field().

306  {
307  return botan_privkey_get_field(q, key, "q");
308  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

◆ botan_pubkey_algo_name()

int botan_pubkey_algo_name ( botan_pubkey_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::Public_Key, key, k, { return write_str_output(out, out_len, k.algo_name()); });
129  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_check_key()

int botan_pubkey_check_key ( botan_pubkey_t  key,
botan_rng_t  rng,
uint32_t  flags 
)

Returns 0 if key is valid, negative if invalid key or some other error

Definition at line 131 of file ffi_pkey.cpp.

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

132  {
133  const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
134 
135  return BOTAN_FFI_DO(Botan::Public_Key, key, k,
136  { return (k.check_key(safe_get(rng), strong) == true) ? 0 : -1; });
137  }
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition: ffi.h:696
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_destroy()

int botan_pubkey_destroy ( botan_pubkey_t  key)

Definition at line 110 of file ffi_pkey.cpp.

References BOTAN_FFI_CHECKED_DELETE.

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

◆ botan_pubkey_dsa_get_g()

int botan_pubkey_dsa_get_g ( botan_mp_t  d,
botan_pubkey_t  key 
)

Definition at line 387 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

388  {
389  return botan_pubkey_get_field(g, key, "g");
390  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_dsa_get_p()

int botan_pubkey_dsa_get_p ( botan_mp_t  p,
botan_pubkey_t  key 
)

Definition at line 377 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

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

◆ botan_pubkey_dsa_get_q()

int botan_pubkey_dsa_get_q ( botan_mp_t  q,
botan_pubkey_t  key 
)

Definition at line 382 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

383  {
384  return botan_pubkey_get_field(q, key, "q");
385  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_dsa_get_y()

int botan_pubkey_dsa_get_y ( botan_mp_t  y,
botan_pubkey_t  key 
)

Definition at line 392 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

393  {
394  return botan_pubkey_get_field(y, key, "y");
395  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_ed25519_get_pubkey()

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

Definition at line 747 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().

749  {
750 #if defined(BOTAN_HAS_ED25519)
751  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
752  if(Botan::Ed25519_PublicKey* ed = dynamic_cast<Botan::Ed25519_PublicKey*>(&k))
753  {
754  const std::vector<uint8_t>& ed_key = ed->get_public_key();
755  if(ed_key.size() != 32)
757  Botan::copy_mem(output, ed_key.data(), ed_key.size());
758  return BOTAN_FFI_SUCCESS;
759  }
760  else
761  {
763  }
764  });
765 #else
766  BOTAN_UNUSED(key, output);
768 #endif
769  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:97
#define BOTAN_UNUSED(...)
Definition: assert.h:106
#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:144
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

◆ botan_pubkey_estimated_strength()

int botan_pubkey_estimated_strength ( botan_pubkey_t  key,
size_t *  estimate 
)

Definition at line 246 of file ffi_pkey.cpp.

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

247  {
248  return BOTAN_FFI_DO(Botan::Public_Key, key, k, { *estimate = k.estimated_strength(); });
249  }
virtual size_t estimated_strength() const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_export()

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

Definition at line 146 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().

147  {
148  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
150  return write_vec_output(out, out_len, Botan::X509::BER_encode(k));
152  return write_str_output(out, out_len, Botan::X509::PEM_encode(k));
153  else
155  });
156  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:717
std::string PEM_encode(const Public_Key &key)
Definition: x509_key.cpp:28
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.cpp:19
Flags flags(Flag flags)
Definition: p11.h:858
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:716
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_fingerprint()

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

Definition at line 251 of file ffi_pkey.cpp.

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

253  {
254  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
255  std::unique_ptr<Botan::HashFunction> h(Botan::HashFunction::create(hash_fn));
256  return write_vec_output(out, out_len, h->process(k.public_key_bits()));
257  });
258  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:106
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_pubkey_get_field()

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

Definition at line 227 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().

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

◆ botan_pubkey_load()

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_CURRENT_FUNCTION, 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(BOTAN_CURRENT_FUNCTION, [=]() -> 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)
104 
105  *key = new botan_pubkey_struct(pubkey.release());
106  return BOTAN_FFI_SUCCESS;
107  });
108  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:152
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:37

◆ botan_pubkey_load_dh()

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

Definition at line 502 of file ffi_pkey_algs.cpp.

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

504  {
505 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
506  *key = nullptr;
507  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
508  Botan::DL_Group group(safe_get(p), safe_get(g));
509  *key = new botan_pubkey_struct(new Botan::DH_PublicKey(group, safe_get(y)));
510  return BOTAN_FFI_SUCCESS;
511  });
512 #else
513  BOTAN_UNUSED(key, p, g, y);
515 #endif
516  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_dsa()

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

Definition at line 355 of file ffi_pkey_algs.cpp.

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

357  {
358 #if defined(BOTAN_HAS_DSA)
359  *key = nullptr;
360 
361  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
362  Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
363  *key = new botan_pubkey_struct(new Botan::DSA_PublicKey(group, safe_get(y)));
364  return BOTAN_FFI_SUCCESS;
365  });
366 #else
367  BOTAN_UNUSED(key, p, q, g, y);
369 #endif
370  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_ecdh()

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

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

537  {
538 #if defined(BOTAN_HAS_ECDH)
539  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
540  std::unique_ptr<Botan::ECDH_PublicKey> p_key;
541  int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
542 
543  if(rc == BOTAN_FFI_SUCCESS)
544  *key = new botan_pubkey_struct(p_key.release());
545  return rc;
546  });
547 #else
548  BOTAN_UNUSED(key, public_x, public_y, curve_name);
550 #endif
551  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_ecdsa()

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

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

408  {
409 #if defined(BOTAN_HAS_ECDSA)
410  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
411  std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
412 
413  int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
414  if(rc == BOTAN_FFI_SUCCESS)
415  *key = new botan_pubkey_struct(p_key.release());
416 
417  return rc;
418  });
419 #else
420  BOTAN_UNUSED(key, public_x, public_y, curve_name);
422 #endif
423  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_ed25519()

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

Definition at line 707 of file ffi_pkey_algs.cpp.

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

709  {
710 #if defined(BOTAN_HAS_ED25519)
711  *key = nullptr;
712  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
713  const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
714  *key = new botan_pubkey_struct(new Botan::Ed25519_PublicKey(pubkey_vec));
715  return BOTAN_FFI_SUCCESS;
716  });
717 #else
718  BOTAN_UNUSED(key, pubkey);
720 #endif
721  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_elgamal()

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

Definition at line 445 of file ffi_pkey_algs.cpp.

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

447  {
448 #if defined(BOTAN_HAS_ELGAMAL)
449  *key = nullptr;
450  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
451  Botan::DL_Group group(safe_get(p), safe_get(g));
452  *key = new botan_pubkey_struct(new Botan::ElGamal_PublicKey(group, safe_get(y)));
453  return BOTAN_FFI_SUCCESS;
454  });
455 #else
456  BOTAN_UNUSED(key, p, g, y);
458 #endif
459  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_rsa()

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

Definition at line 285 of file ffi_pkey_algs.cpp.

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

287  {
288 #if defined(BOTAN_HAS_RSA)
289  *key = nullptr;
290  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
291  *key = new botan_pubkey_struct(new Botan::RSA_PublicKey(safe_get(n), safe_get(e)));
292  return BOTAN_FFI_SUCCESS;
293  });
294 #else
295  BOTAN_UNUSED(key, n, e);
297 #endif
298  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ 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 at line 609 of file ffi_pkey_algs.cpp.

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

613  {
614 #if defined(BOTAN_HAS_SM2)
615  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
616  std::unique_ptr<Botan::SM2_Signature_PublicKey> p_key;
617  if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
618  {
619  *key = new botan_pubkey_struct(p_key.release());
620  return BOTAN_FFI_SUCCESS;
621  }
623  });
624 #else
625  BOTAN_UNUSED(key, public_x, public_y, curve_name);
627 #endif
628  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:152
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_load_sm2_enc()

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

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

653  {
654 #if defined(BOTAN_HAS_SM2)
655  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
656  std::unique_ptr<Botan::SM2_Encryption_PublicKey> p_key;
657  if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
658  {
659  *key = new botan_pubkey_struct(p_key.release());
660  return BOTAN_FFI_SUCCESS;
661  }
663  });
664 #else
665  BOTAN_UNUSED(key, public_x, public_y, curve_name);
667 #endif
668  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:152
#define BOTAN_UNUSED(...)
Definition: assert.h:106
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pubkey_rsa_get_e()

int botan_pubkey_rsa_get_e ( botan_mp_t  e,
botan_pubkey_t  rsa_key 
)

Definition at line 325 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

326  {
327  return botan_pubkey_get_field(e, key, "e");
328  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_rsa_get_n()

int botan_pubkey_rsa_get_n ( botan_mp_t  n,
botan_pubkey_t  rsa_key 
)

Definition at line 330 of file ffi_pkey_algs.cpp.

References botan_pubkey_get_field().

331  {
332  return botan_pubkey_get_field(n, key, "n");
333  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

◆ botan_pubkey_sm2_compute_za()

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

Definition at line 573 of file ffi_pkey_algs.cpp.

References Botan::Public_Key::algo_name(), BOTAN_CURRENT_FUNCTION, 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().

578  {
579  if(out == nullptr || out_len == nullptr)
581  if(ident == nullptr || hash_algo == nullptr || key == nullptr)
583 
584 #if defined(BOTAN_HAS_SM2)
585  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
586  const Botan::Public_Key& pub_key = safe_get(key);
587  const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
588 
589  if(ec_key == nullptr)
591 
592  if(ec_key->algo_name() != "SM2_Sig" && ec_key->algo_name() != "SM2_Enc")
594 
595  const std::string ident_str(ident);
596  std::unique_ptr<Botan::HashFunction> hash =
598 
599  const std::vector<uint8_t> za =
600  Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->public_point());
601 
602  return write_vec_output(out, out_len, za);
603  });
604 #else
606 #endif
607  }
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:345
const PointGFp & public_point() const
Definition: ecc_key.h:57
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
virtual std::string algo_name() const =0
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, const std::string &user_id, const EC_Group &domain, const PointGFp &pubkey)
Definition: sm2.cpp:43
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
const EC_Group & domain() const
Definition: ecc_key.h:72
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147
MechanismType hash
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

◆ botan_rng_destroy()

int botan_rng_destroy ( botan_rng_t  rng)

Frees all resources of the random number generator object

Parameters
rngrng object
Returns
always returns 0

Definition at line 39 of file ffi_rng.cpp.

References BOTAN_FFI_CHECKED_DELETE.

40  {
41  return BOTAN_FFI_CHECKED_DELETE(rng);
42  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_rng_get()

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

Get random bytes from a random number generator

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

TODO: better name

Definition at line 44 of file ffi_rng.cpp.

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

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

◆ botan_rng_init()

int botan_rng_init ( botan_rng_t rng,
const char *  rng_type 
)

Initialize a random number generator object

Parameters
rngrng object
rng_typetype of the rng, possible values: "system": System_RNG, "user": AutoSeeded_RNG Set rng_type to null or empty string to let the library choose

TODO: replace rng_type with simple flags?

Definition at line 17 of file ffi_rng.cpp.

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

18  {
19  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
20  if(rng_out == nullptr)
22 
23  const std::string rng_type_s(rng_type ? rng_type : "system");
24 
25  std::unique_ptr<Botan::RandomNumberGenerator> rng;
26 
27  if(rng_type_s == "system")
28  rng.reset(new Botan::System_RNG);
29  else if(rng_type_s == "user")
30  rng.reset(new Botan::AutoSeeded_RNG);
31  else
33 
34  *rng_out = new botan_rng_struct(rng.release());
35  return BOTAN_FFI_SUCCESS;
36  });
37  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147
#define BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:148

◆ botan_rng_reseed()

int botan_rng_reseed ( botan_rng_t  rng,
size_t  bits 
)

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

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

Definition at line 49 of file ffi_rng.cpp.

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

50  {
52  }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:230
virtual void reseed_from_rng(RandomNumberGenerator &rng, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS)
Definition: rng.cpp:45
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_same_mem()

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

Deprecated equivalent to botan_constant_time_compare

Definition at line 71 of file ffi.cpp.

References botan_constant_time_compare().

72  {
73  return botan_constant_time_compare(x, y, len);
74  }
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition: ffi.cpp:66

◆ botan_scrub_mem()

int botan_scrub_mem ( void *  mem,
size_t  bytes 
)

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

Definition at line 76 of file ffi.cpp.

References BOTAN_FFI_SUCCESS, and Botan::secure_scrub_memory().

77  {
78  Botan::secure_scrub_memory(mem, bytes);
79  return BOTAN_FFI_SUCCESS;
80  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
void secure_scrub_memory(void *ptr, size_t n)
Definition: os_utils.cpp:37

◆ botan_version_datestamp()

uint32_t botan_version_datestamp ( )

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

Definition at line 64 of file ffi.cpp.

References Botan::version_datestamp().

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

◆ botan_version_major()

uint32_t botan_version_major ( )

Return the major version of the library

Definition at line 61 of file ffi.cpp.

References Botan::version_major().

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

◆ botan_version_minor()

uint32_t botan_version_minor ( )

Return the minor version of the library

Definition at line 62 of file ffi.cpp.

References Botan::version_minor().

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

◆ botan_version_patch()

uint32_t botan_version_patch ( )

Return the patch version of the library

Definition at line 63 of file ffi.cpp.

References Botan::version_patch().

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

◆ botan_version_string()

const char* botan_version_string ( )

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

Definition at line 56 of file ffi.cpp.

References Botan::version_cstr().

57  {
58  return Botan::version_cstr();
59  }
const char * version_cstr()
Definition: version.cpp:29

◆ botan_x509_cert_allowed_usage()

int botan_x509_cert_allowed_usage ( botan_x509_cert_t  cert,
unsigned int  key_usage 
)

Definition at line 86 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and BOTAN_FFI_SUCCESS.

87  {
88  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, {
89  const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
90  if(c.allowed_usage(k))
91  return BOTAN_FFI_SUCCESS;
92  return 1;
93  });
94  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_destroy()

int botan_x509_cert_destroy ( botan_x509_cert_t  cert)

Definition at line 96 of file ffi_cert.cpp.

References BOTAN_FFI_CHECKED_DELETE.

97  {
98  return BOTAN_FFI_CHECKED_DELETE(cert);
99  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_x509_cert_gen_selfsigned()

int botan_x509_cert_gen_selfsigned ( botan_x509_cert_t cert,
botan_privkey_t  key,
botan_rng_t  rng,
const char *  common_name,
const char *  org_name 
)

◆ botan_x509_cert_get_authority_key_id()

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

Definition at line 121 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

122  {
123  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.authority_key_id()); });
124  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_fingerprint()

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

Definition at line 116 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

117  {
118  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.fingerprint(hash)); });
119  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
MechanismType hash

◆ botan_x509_cert_get_issuer_dn()

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

Definition at line 67 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

70  {
71  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.issuer_info(key).at(index)); });
72  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_public_key()

int botan_x509_cert_get_public_key ( botan_x509_cert_t  cert,
botan_pubkey_t key 
)

Definition at line 49 of file ffi_cert.cpp.

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

50  {
51  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
52  if(key == nullptr)
54 
55  *key = nullptr;
56 
57 #if defined(BOTAN_HAS_RSA)
58  std::unique_ptr<Botan::Public_Key> publicKey = safe_get(cert).load_subject_public_key();
59  *key = new botan_pubkey_struct(publicKey.release());
60  return BOTAN_FFI_SUCCESS;
61 #else
63 #endif
64  });
65  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_x509_cert_get_public_key_bits()

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

Definition at line 131 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

132  {
133  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_public_key_bits()); });
134  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_serial_number()

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

Definition at line 111 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

112  {
113  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.serial_number()); });
114  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_subject_dn()

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

Definition at line 74 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

77  {
78  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.subject_info(key).at(index)); });
79  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_subject_key_id()

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

Definition at line 126 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

127  {
128  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_key_id()); });
129  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_time_expires()

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

Definition at line 106 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

107  {
108  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.not_after().to_string()); });
109  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_get_time_starts()

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

Definition at line 101 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

102  {
103  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.not_before().to_string()); });
104  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_x509_cert_load()

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

Definition at line 35 of file ffi_cert.cpp.

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

36  {
37  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
38  if(!cert_obj || !cert_bits)
40 
41  Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
42 
43  std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(bits));
44  *cert_obj = new botan_x509_cert_struct(c.release());
45  return BOTAN_FFI_SUCCESS;
46  });
47  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_x509_cert_load_file()

int botan_x509_cert_load_file ( botan_x509_cert_t cert_obj,
const char *  filename 
)

Definition at line 19 of file ffi_cert.cpp.

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

20  {
21  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
22  if(!cert_obj || !cert_path)
24 
25 #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
26  std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(cert_path));
27  *cert_obj = new botan_x509_cert_struct(c.release());
28  return BOTAN_FFI_SUCCESS;
29 #else
31 #endif
32  });
33  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_x509_cert_to_string()

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

Definition at line 81 of file ffi_cert.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

82  {
83  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.to_string()); });
84  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98