Botan  2.1.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_EXCEPTION_THROWN   (-20)
 
#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE   (-10)
 
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED   (-40)
 
#define BOTAN_FFI_ERROR_NULL_POINTER   (-31)
 
#define BOTAN_FFI_HEX_LOWER_CASE   1
 
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER   0
 
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM   1
 

Typedefs

typedef struct botan_block_cipher_struct * botan_block_cipher_t
 
typedef struct botan_cipher_struct * botan_cipher_t
 
typedef struct botan_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

BOTAN_DLL 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)
 
BOTAN_DLL int botan_bcrypt_is_valid (const char *pass, const char *hash)
 
BOTAN_DLL int botan_block_cipher_block_size (botan_block_cipher_t bc)
 
BOTAN_DLL int botan_block_cipher_clear (botan_block_cipher_t bc)
 
BOTAN_DLL int botan_block_cipher_decrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
 
BOTAN_DLL int botan_block_cipher_destroy (botan_block_cipher_t bc)
 
BOTAN_DLL int botan_block_cipher_encrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
 
BOTAN_DLL int botan_block_cipher_init (botan_block_cipher_t *bc, const char *cipher_name)
 
BOTAN_DLL int botan_block_cipher_set_key (botan_block_cipher_t bc, const uint8_t key[], size_t len)
 
BOTAN_DLL int botan_cipher_clear (botan_cipher_t hash)
 
BOTAN_DLL int botan_cipher_destroy (botan_cipher_t cipher)
 
BOTAN_DLL int botan_cipher_get_default_nonce_length (botan_cipher_t cipher, size_t *nl)
 
BOTAN_DLL int botan_cipher_get_tag_length (botan_cipher_t cipher, size_t *tag_size)
 
BOTAN_DLL int botan_cipher_get_update_granularity (botan_cipher_t cipher, size_t *ug)
 
BOTAN_DLL int botan_cipher_init (botan_cipher_t *cipher, const char *name, uint32_t flags)
 
BOTAN_DLL int botan_cipher_query_keylen (botan_cipher_t, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
 
BOTAN_DLL int botan_cipher_set_associated_data (botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
 
BOTAN_DLL int botan_cipher_set_key (botan_cipher_t cipher, const uint8_t *key, size_t key_len)
 
BOTAN_DLL int botan_cipher_start (botan_cipher_t cipher, const uint8_t *nonce, size_t nonce_len)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_cipher_valid_nonce_length (botan_cipher_t cipher, size_t nl)
 
BOTAN_DLL uint32_t botan_ffi_api_version ()
 
BOTAN_DLL int botan_ffi_supports_api (uint32_t api_version)
 
BOTAN_DLL int botan_hash_clear (botan_hash_t hash)
 
BOTAN_DLL int botan_hash_destroy (botan_hash_t hash)
 
BOTAN_DLL int botan_hash_final (botan_hash_t hash, uint8_t out[])
 
BOTAN_DLL int botan_hash_init (botan_hash_t *hash, const char *hash_name, uint32_t flags)
 
BOTAN_DLL int botan_hash_name (botan_hash_t hash, char *name, size_t name_len)
 
BOTAN_DLL int botan_hash_output_length (botan_hash_t hash, size_t *output_length)
 
BOTAN_DLL int botan_hash_update (botan_hash_t hash, const uint8_t *in, size_t in_len)
 
BOTAN_DLL int botan_hex_encode (const uint8_t *x, size_t len, char *out, uint32_t flags)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_mac_clear (botan_mac_t mac)
 
BOTAN_DLL int botan_mac_destroy (botan_mac_t mac)
 
BOTAN_DLL int botan_mac_final (botan_mac_t mac, uint8_t out[])
 
BOTAN_DLL int botan_mac_init (botan_mac_t *mac, const char *mac_name, uint32_t flags)
 
BOTAN_DLL int botan_mac_output_length (botan_mac_t mac, size_t *output_length)
 
BOTAN_DLL int botan_mac_set_key (botan_mac_t mac, const uint8_t *key, size_t key_len)
 
BOTAN_DLL int botan_mac_update (botan_mac_t mac, const uint8_t *buf, size_t len)
 
BOTAN_DLL 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)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_mp_add (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
 
BOTAN_DLL int botan_mp_clear (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_clear_bit (botan_mp_t n, size_t bit)
 
BOTAN_DLL int botan_mp_cmp (int *result, const botan_mp_t x, const botan_mp_t y)
 
BOTAN_DLL int botan_mp_destroy (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_div (botan_mp_t quotient, botan_mp_t remainder, const botan_mp_t x, const botan_mp_t y)
 
BOTAN_DLL int botan_mp_equal (const botan_mp_t x, const botan_mp_t y)
 
BOTAN_DLL int botan_mp_flip_sign (botan_mp_t mp)
 
BOTAN_DLL int botan_mp_from_bin (const botan_mp_t mp, const uint8_t vec[], size_t vec_len)
 
BOTAN_DLL int botan_mp_gcd (botan_mp_t out, const botan_mp_t x, const botan_mp_t y)
 
BOTAN_DLL int botan_mp_get_bit (const botan_mp_t n, size_t bit)
 
BOTAN_DLL int botan_mp_init (botan_mp_t *mp)
 
BOTAN_DLL int botan_mp_is_even (const botan_mp_t mp)
 
BOTAN_DLL int botan_mp_is_negative (const botan_mp_t mp)
 
BOTAN_DLL int botan_mp_is_odd (const botan_mp_t mp)
 
BOTAN_DLL int botan_mp_is_positive (const botan_mp_t mp)
 
BOTAN_DLL int botan_mp_is_prime (const botan_mp_t n, botan_rng_t rng, size_t test_prob)
 
BOTAN_DLL int botan_mp_is_zero (const botan_mp_t mp)
 
BOTAN_DLL int botan_mp_lshift (botan_mp_t out, const botan_mp_t in, size_t shift)
 
BOTAN_DLL int botan_mp_mod_inverse (botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus)
 
BOTAN_DLL int botan_mp_mod_mul (botan_mp_t result, const botan_mp_t x, const botan_mp_t y, const botan_mp_t mod)
 
BOTAN_DLL int botan_mp_mul (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
 
BOTAN_DLL int botan_mp_num_bits (const botan_mp_t n, size_t *bits)
 
BOTAN_DLL int botan_mp_num_bytes (const botan_mp_t n, size_t *bytes)
 
BOTAN_DLL int botan_mp_powmod (botan_mp_t out, const botan_mp_t base, const botan_mp_t exponent, const botan_mp_t modulus)
 
BOTAN_DLL int botan_mp_rand_bits (botan_mp_t rand_out, botan_rng_t rng, size_t bits)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_mp_rshift (botan_mp_t out, const botan_mp_t in, size_t shift)
 
BOTAN_DLL int botan_mp_set_bit (botan_mp_t n, size_t bit)
 
BOTAN_DLL int botan_mp_set_from_int (botan_mp_t mp, int initial_value)
 
BOTAN_DLL int botan_mp_set_from_mp (botan_mp_t dest, const botan_mp_t source)
 
BOTAN_DLL int botan_mp_set_from_radix_str (botan_mp_t dest, const char *str, size_t radix)
 
BOTAN_DLL int botan_mp_set_from_str (botan_mp_t dest, const char *str)
 
BOTAN_DLL int botan_mp_sub (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
 
BOTAN_DLL int botan_mp_swap (botan_mp_t x, botan_mp_t y)
 
BOTAN_DLL int botan_mp_to_bin (const botan_mp_t mp, uint8_t vec[])
 
BOTAN_DLL int botan_mp_to_hex (const botan_mp_t mp, char *out)
 
BOTAN_DLL int botan_mp_to_str (const botan_mp_t mp, uint8_t base, char *out, size_t *out_len)
 
BOTAN_DLL int botan_mp_to_uint32 (const botan_mp_t mp, uint32_t *val)
 
BOTAN_DLL 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)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_pk_op_decrypt (botan_pk_op_decrypt_t op, uint8_t out[], size_t *out_len, uint8_t ciphertext[], size_t ciphertext_len)
 
BOTAN_DLL int botan_pk_op_decrypt_create (botan_pk_op_decrypt_t *op, botan_privkey_t key, const char *padding, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_decrypt_destroy (botan_pk_op_decrypt_t op)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_pk_op_encrypt_create (botan_pk_op_encrypt_t *op, botan_pubkey_t key, const char *padding, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_encrypt_destroy (botan_pk_op_encrypt_t op)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_pk_op_key_agreement_create (botan_pk_op_ka_t *op, botan_privkey_t key, const char *kdf, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_key_agreement_destroy (botan_pk_op_ka_t op)
 
BOTAN_DLL int botan_pk_op_key_agreement_export_public (botan_privkey_t key, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_pk_op_sign_create (botan_pk_op_sign_t *op, botan_privkey_t key, const char *hash_and_padding, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_sign_destroy (botan_pk_op_sign_t op)
 
BOTAN_DLL int botan_pk_op_sign_finish (botan_pk_op_sign_t op, botan_rng_t rng, uint8_t sig[], size_t *sig_len)
 
BOTAN_DLL int botan_pk_op_sign_update (botan_pk_op_sign_t op, const uint8_t in[], size_t in_len)
 
BOTAN_DLL int botan_pk_op_verify_create (botan_pk_op_verify_t *op, botan_pubkey_t key, const char *hash_and_padding, uint32_t flags)
 
BOTAN_DLL int botan_pk_op_verify_destroy (botan_pk_op_verify_t op)
 
BOTAN_DLL int botan_pk_op_verify_finish (botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len)
 
BOTAN_DLL int botan_pk_op_verify_update (botan_pk_op_verify_t op, const uint8_t in[], size_t in_len)
 
BOTAN_DLL int botan_privkey_check_key (botan_privkey_t key, botan_rng_t rng, uint32_t flags)
 
BOTAN_DLL int botan_privkey_create (botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
 
BOTAN_DLL int botan_privkey_create_ecdh (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
BOTAN_DLL int botan_privkey_create_ecdsa (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
BOTAN_DLL int botan_privkey_create_mceliece (botan_privkey_t *key, botan_rng_t rng, size_t n, size_t t)
 
BOTAN_DLL int botan_privkey_create_rsa (botan_privkey_t *key, botan_rng_t rng, size_t n_bits)
 
BOTAN_DLL int botan_privkey_destroy (botan_privkey_t key)
 
BOTAN_DLL int botan_privkey_dsa_get_x (botan_mp_t n, botan_privkey_t key)
 
BOTAN_DLL int botan_privkey_export (botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
BOTAN_DLL 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)
 
BOTAN_DLL 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)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_privkey_export_pubkey (botan_pubkey_t *out, botan_privkey_t in)
 
BOTAN_DLL int botan_privkey_get_field (botan_mp_t output, botan_privkey_t key, const char *field_name)
 
BOTAN_DLL int botan_privkey_load (botan_privkey_t *key, botan_rng_t rng, const uint8_t bits[], size_t len, const char *password)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_privkey_load_rsa (botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t d)
 
BOTAN_DLL int botan_privkey_rsa_get_d (botan_mp_t d, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_privkey_rsa_get_e (botan_mp_t e, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_privkey_rsa_get_n (botan_mp_t n, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_privkey_rsa_get_p (botan_mp_t p, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_privkey_rsa_get_q (botan_mp_t q, botan_privkey_t rsa_key)
 
BOTAN_DLL int botan_pubkey_algo_name (botan_pubkey_t key, char out[], size_t *out_len)
 
BOTAN_DLL int botan_pubkey_check_key (botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
 
BOTAN_DLL int botan_pubkey_destroy (botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_dsa_get_g (botan_mp_t d, botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_dsa_get_p (botan_mp_t p, botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_dsa_get_q (botan_mp_t q, botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_dsa_get_y (botan_mp_t y, botan_pubkey_t key)
 
BOTAN_DLL int botan_pubkey_estimated_strength (botan_pubkey_t key, size_t *estimate)
 
BOTAN_DLL int botan_pubkey_export (botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
BOTAN_DLL int botan_pubkey_fingerprint (botan_pubkey_t key, const char *hash, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_pubkey_get_field (botan_mp_t output, botan_pubkey_t key, const char *field_name)
 
BOTAN_DLL int botan_pubkey_load (botan_pubkey_t *key, const uint8_t bits[], size_t len)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_pubkey_load_rsa (botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
 
BOTAN_DLL int botan_pubkey_rsa_get_e (botan_mp_t e, botan_pubkey_t rsa_key)
 
BOTAN_DLL int botan_pubkey_rsa_get_n (botan_mp_t n, botan_pubkey_t rsa_key)
 
BOTAN_DLL int botan_rng_destroy (botan_rng_t rng)
 
BOTAN_DLL int botan_rng_get (botan_rng_t rng, uint8_t *out, size_t out_len)
 
BOTAN_DLL int botan_rng_init (botan_rng_t *rng, const char *rng_type)
 
BOTAN_DLL int botan_rng_reseed (botan_rng_t rng, size_t bits)
 
BOTAN_DLL int botan_same_mem (const uint8_t *x, const uint8_t *y, size_t len)
 
BOTAN_DLL uint32_t botan_version_datestamp ()
 
BOTAN_DLL uint32_t botan_version_major ()
 
BOTAN_DLL uint32_t botan_version_minor ()
 
BOTAN_DLL uint32_t botan_version_patch ()
 
BOTAN_DLL const char * botan_version_string ()
 
BOTAN_DLL int botan_x509_cert_allowed_usage (botan_x509_cert_t cert, unsigned int key_usage)
 
BOTAN_DLL int botan_x509_cert_destroy (botan_x509_cert_t cert)
 
BOTAN_DLL 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_DLL int botan_x509_cert_get_authority_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_fingerprint (botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_x509_cert_get_public_key (botan_x509_cert_t cert, botan_pubkey_t *key)
 
BOTAN_DLL int botan_x509_cert_get_public_key_bits (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_serial_number (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
BOTAN_DLL 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)
 
BOTAN_DLL int botan_x509_cert_get_subject_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_time_expires (botan_x509_cert_t cert, char out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_get_time_starts (botan_x509_cert_t cert, char out[], size_t *out_len)
 
BOTAN_DLL int botan_x509_cert_load (botan_x509_cert_t *cert_obj, const uint8_t cert[], size_t cert_len)
 
BOTAN_DLL int botan_x509_cert_load_file (botan_x509_cert_t *cert_obj, const char *filename)
 
BOTAN_DLL int botan_x509_cert_path_verify (botan_x509_cert_t cert, const char *ca_dir)
 
BOTAN_DLL int botan_x509_cert_to_string (botan_x509_cert_t cert, char out[], size_t *out_len)
 

Macro Definition Documentation

#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS   1

Definition at line 639 of file ffi.h.

Referenced by botan_privkey_check_key(), and botan_pubkey_check_key().

#define BOTAN_CIPHER_INIT_FLAG_DECRYPT   1

Definition at line 347 of file ffi.h.

#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0

Definition at line 346 of file ffi.h.

Referenced by botan_cipher_init().

#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION   1

Definition at line 345 of file ffi.h.

Referenced by botan_cipher_init().

#define BOTAN_CIPHER_UPDATE_FLAG_FINAL   (1U << 0)

Definition at line 369 of file ffi.h.

Referenced by botan_cipher_update().

#define BOTAN_FFI_ERROR_BAD_FLAG   (-30)
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN   (-20)
#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE   (-10)

Definition at line 137 of file ffi.h.

#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED   (-40)
#define BOTAN_FFI_ERROR_NULL_POINTER   (-31)
#define BOTAN_FFI_HEX_LOWER_CASE   1

Definition at line 150 of file ffi.h.

Referenced by botan_hex_encode().

#define BOTAN_PRIVKEY_EXPORT_FLAG_DER   0
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM   1

Typedef Documentation

typedef struct botan_block_cipher_struct* botan_block_cipher_t

Definition at line 461 of file ffi.h.

typedef struct botan_cipher_struct* botan_cipher_t

Definition at line 343 of file ffi.h.

typedef struct botan_hash_struct* botan_hash_t

Definition at line 213 of file ffi.h.

typedef struct botan_mac_struct* botan_mac_t

Definition at line 277 of file ffi.h.

typedef struct botan_mp_struct* botan_mp_t

Definition at line 506 of file ffi.h.

typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t

Definition at line 805 of file ffi.h.

typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t

Definition at line 788 of file ffi.h.

typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t

Definition at line 849 of file ffi.h.

typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t

Definition at line 820 of file ffi.h.

typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t

Definition at line 835 of file ffi.h.

typedef struct botan_privkey_struct* botan_privkey_t

Definition at line 632 of file ffi.h.

typedef struct botan_pubkey_struct* botan_pubkey_t

Definition at line 709 of file ffi.h.

typedef struct botan_rng_struct* botan_rng_t

RNG type

Definition at line 169 of file ffi.h.

typedef struct botan_x509_cert_struct* botan_x509_cert_t

Definition at line 886 of file ffi.h.

Enumeration Type Documentation

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

926  {
927  NO_CONSTRAINTS = 0,
928  DIGITAL_SIGNATURE = 32768,
929  NON_REPUDIATION = 16384,
930  KEY_ENCIPHERMENT = 8192,
931  DATA_ENCIPHERMENT = 4096,
932  KEY_AGREEMENT = 2048,
933  KEY_CERT_SIGN = 1024,
934  CRL_SIGN = 512,
935  ENCIPHER_ONLY = 256,
936  DECIPHER_ONLY = 128
937 };
Definition: ffi.h:934

Function Documentation

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

References BOTAN_ASSERT_ARG_NON_NULL, BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_EXCEPTION_THROWN, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, Botan::generate_bcrypt(), and Botan::ASN1::to_string().

1057  {
1058  try
1059  {
1061  BOTAN_ASSERT_ARG_NON_NULL(out_len);
1063 
1064  if(flags != 0)
1065  return BOTAN_FFI_ERROR_BAD_FLAG;
1066 
1067  if(wf < 2 || wf > 30)
1068  throw FFI_Error("Bad bcrypt work factor " + std::to_string(wf));
1069 
1070 #if defined(BOTAN_HAS_BCRYPT)
1071  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1072  const std::string bcrypt = Botan::generate_bcrypt(pass, rng, wf);
1073  return write_str_output(out, out_len, bcrypt);
1074 #else
1076 #endif
1077  }
1078  catch(std::exception& e)
1079  {
1080  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1081  }
1082  catch(...)
1083  {
1084  log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
1085  }
1086 
1088  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:139
std::string generate_bcrypt(const std::string &pass, RandomNumberGenerator &rng, uint16_t work_factor)
Definition: bcrypt.cpp:125
Flags flags(Flag flags)
Definition: p11.h:858
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
#define BOTAN_ASSERT_ARG_NON_NULL(p)
Definition: ffi.cpp:79
BOTAN_DLL 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 1090 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and Botan::check_bcrypt().

1091  {
1092  try
1093  {
1094 #if defined(BOTAN_HAS_BCRYPT)
1095  if(Botan::check_bcrypt(pass, hash))
1096  return 0; // success
1097 #else
1099 #endif
1100  }
1101  catch(std::exception& e)
1102  {
1103  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1104  }
1105  catch(...)
1106  {
1107  log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
1108  }
1109 
1111  }
bool check_bcrypt(const std::string &pass, const std::string &hash)
Definition: bcrypt.cpp:132
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
MechanismType hash
BOTAN_DLL 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 652 of file ffi.cpp.

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

653  {
654  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { return b.block_size(); });
655  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
virtual size_t block_size() const =0
BOTAN_DLL 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 634 of file ffi.cpp.

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

635  {
636  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.clear(); });
637  }
virtual void clear()=0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_block_cipher_decrypt_blocks ( botan_block_cipher_t  bc,
const uint8_t  in[],
uint8_t  out[],
size_t  blocks 
)

Definition at line 665 of file ffi.cpp.

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

669  {
670  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.decrypt_n(in, out, blocks); });
671  }
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.cpp:204
BOTAN_DLL int botan_block_cipher_destroy ( botan_block_cipher_t  bc)

Destroy a block cipher object

Definition at line 628 of file ffi.cpp.

629  {
630  delete bc;
631  return 0;
632  }
BOTAN_DLL int botan_block_cipher_encrypt_blocks ( botan_block_cipher_t  bc,
const uint8_t  in[],
uint8_t  out[],
size_t  blocks 
)

Definition at line 657 of file ffi.cpp.

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

661  {
662  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.encrypt_n(in, out, blocks); });
663  }
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.cpp:204
BOTAN_DLL int botan_block_cipher_init ( botan_block_cipher_t bc,
const char *  cipher_name 
)

Initialize a block cipher object

Definition at line 598 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::BlockCipher::create().

599  {
600  try
601  {
602  if(bc == nullptr || bc_name == nullptr || *bc_name == 0)
604 
605  std::unique_ptr<Botan::BlockCipher> cipher(Botan::BlockCipher::create(bc_name));
606  if(cipher)
607  {
608  *bc = new botan_block_cipher_struct(cipher.release());
609  return 0;
610  }
611  }
612  catch(std::exception& e)
613  {
614  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
615  }
616  catch(...)
617  {
618  log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
619  }
620 
622 
623  }
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:140
BOTAN_DLL 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 642 of file ffi.cpp.

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

644  {
645  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.set_key(key, len); });
646  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_cipher_clear ( botan_cipher_t  hash)

Definition at line 814 of file ffi.cpp.

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

815  {
816  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { c.clear(); });
817  }
virtual void clear()=0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_cipher_destroy ( botan_cipher_t  cipher)

Definition at line 808 of file ffi.cpp.

809  {
810  delete cipher;
811  return 0;
812  }
BOTAN_DLL int botan_cipher_get_default_nonce_length ( botan_cipher_t  cipher,
size_t *  nl 
)

Definition at line 977 of file ffi.cpp.

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

978  {
979  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *nl = c.default_nonce_length(); });
980  }
virtual size_t default_nonce_length() const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_cipher_get_tag_length ( botan_cipher_t  cipher,
size_t *  tag_size 
)

Definition at line 987 of file ffi.cpp.

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

988  {
989  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *tl = c.tag_size(); });
990  }
virtual size_t tag_size() const
Definition: cipher_mode.h:150
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_cipher_get_update_granularity ( botan_cipher_t  cipher,
size_t *  ug 
)

Definition at line 982 of file ffi.cpp.

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

983  {
984  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *ug = c.update_granularity(); });
985  }
virtual size_t update_granularity() const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_cipher_init ( botan_cipher_t cipher,
const char *  name,
uint32_t  flags 
)

Definition at line 784 of file ffi.cpp.

References BOTAN_CIPHER_INIT_FLAG_ENCRYPT, BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION, BOTAN_CURRENT_FUNCTION, Botan::DECRYPTION, Botan::ENCRYPTION, and Botan::get_cipher_mode().

785  {
786  try
787  {
789  const Botan::Cipher_Dir dir = encrypt_p ? Botan::ENCRYPTION : Botan::DECRYPTION;
790  std::unique_ptr<Botan::Cipher_Mode> mode(Botan::get_cipher_mode(cipher_name, dir));
791  if(!mode)
792  return -1;
793  *cipher = new botan_cipher_struct(mode.release());
794  return 0;
795  }
796  catch(std::exception& e)
797  {
798  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
799  }
800  catch(...)
801  {
802  log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
803  }
804 
805  return -1;
806  }
#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT
Definition: ffi.h:346
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
Definition: ffi.h:345
Cipher_Mode * get_cipher_mode(const std::string &algo, Cipher_Dir direction)
Definition: cipher_mode.cpp:39
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_cipher_query_keylen ( botan_cipher_t  ,
size_t *  out_minimum_keylength,
size_t *  out_maximum_keylength 
)

Definition at line 819 of file ffi.cpp.

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

822  {
823  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
824  *out_minimum_keylength = c.key_spec().minimum_keylength();
825  *out_maximum_keylength = c.key_spec().maximum_keylength();
826  });
827  }
size_t minimum_keylength() const
Definition: key_spec.h:61
virtual Key_Length_Specification key_spec() const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_cipher_set_associated_data ( botan_cipher_t  cipher,
const uint8_t *  ad,
size_t  ad_len 
)

Definition at line 958 of file ffi.cpp.

References BOTAN_FFI_DO.

961  {
962  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
963  if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(&c))
964  {
965  aead->set_associated_data(ad, ad_len);
966  return 0;
967  }
968  return -1;
969  });
970  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_cipher_set_key ( botan_cipher_t  cipher,
const uint8_t *  key,
size_t  key_len 
)

Definition at line 829 of file ffi.cpp.

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

831  {
832  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { c.set_key(key, key_len); });
833  }
void set_key(const std::vector< uint8_t, Alloc > &key)
Definition: cipher_mode.h:172
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_cipher_start ( botan_cipher_t  cipher,
const uint8_t *  nonce,
size_t  nonce_len 
)

Definition at line 835 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, Botan::Cipher_Mode::start(), and Botan::Cipher_Mode::update_granularity().

837  {
838  try
839  {
840  Botan::Cipher_Mode& cipher = safe_get(cipher_obj);
841  cipher.start(nonce, nonce_len);
842  cipher_obj->m_buf.reserve(cipher.update_granularity());
843  return 0;
844  }
845  catch(std::exception& e)
846  {
847  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
848  }
849 
850  return -1;
851  }
virtual size_t update_granularity() const =0
void start(const std::vector< uint8_t, Alloc > &nonce)
Definition: cipher_mode.h:38
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL 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 853 of file ffi.cpp.

References BOTAN_ASSERT, BOTAN_CIPHER_UPDATE_FLAG_FINAL, BOTAN_CURRENT_FUNCTION, Botan::copy_mem(), Botan::Cipher_Mode::finish(), Botan::Cipher_Mode::minimum_final_size(), Botan::round_down(), Botan::Cipher_Mode::update(), Botan::Cipher_Mode::update_granularity(), and Botan::Exception::what().

861  {
862  using namespace Botan;
863 
864  try
865  {
866  Cipher_Mode& cipher = safe_get(cipher_obj);
867  secure_vector<uint8_t>& mbuf = cipher_obj->m_buf;
868 
869  const bool final_input = (flags & BOTAN_CIPHER_UPDATE_FLAG_FINAL);
870 
871  if(final_input)
872  {
873  mbuf.assign(input, input + input_size);
874  *input_consumed = input_size;
875  *output_written = 0;
876 
877  try
878  {
879  cipher.finish(mbuf);
880  }
881  catch(Integrity_Failure& e)
882  {
883  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
884  return -2;
885  }
886 
887  *output_written = mbuf.size();
888 
889  if(mbuf.size() <= output_size)
890  {
891  copy_mem(output, mbuf.data(), mbuf.size());
892  mbuf.clear();
893  return 0;
894  }
895 
896  return -1;
897  }
898 
899  if(input_size == 0)
900  {
901  // Currently must take entire buffer in this case
902  *output_written = mbuf.size();
903  if(output_size >= mbuf.size())
904  {
905  copy_mem(output, mbuf.data(), mbuf.size());
906  mbuf.clear();
907  return 0;
908  }
909 
910  return -1;
911  }
912 
913  const size_t ud = cipher.update_granularity();
914  BOTAN_ASSERT(cipher.update_granularity() > cipher.minimum_final_size(), "logic error");
915 
916 #if 0
917  // Avoiding double copy:
918  if(Online_Cipher_Mode* ocm = dynamic_cast<Online_Cipher_Mode*>(&cipher))
919  {
920  const size_t taken = round_down(input_size, ud);
921  *input_consumed = taken;
922  *output_size = taken;
923  copy_mem(output, input, taken);
924  ocm->update_in_place(output, taken);
925  return 0;
926  }
927 #endif
928 
929  mbuf.resize(ud);
930  size_t taken = 0, written = 0;
931 
932  while(input_size >= ud && output_size >= ud)
933  {
934  copy_mem(mbuf.data(), input, ud);
935  cipher.update(mbuf);
936 
937  input_size -= ud;
938  input += ud;
939  taken += ud;
940 
941  output_size -= ud;
942  output += ud;
943  written += ud;
944  }
945 
946  *output_written = written;
947  *input_consumed = taken;
948 
949  }
950  catch(std::exception& e)
951  {
952  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
953  }
954 
955  return -1;
956  }
T round_down(T n, T align_to)
Definition: rounding.h:38
void update(secure_vector< uint8_t > &buffer, size_t offset=0)
Definition: cipher_mode.h:81
virtual size_t update_granularity() const =0
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:27
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
#define BOTAN_CIPHER_UPDATE_FLAG_FINAL
Definition: ffi.h:369
const char * what() const BOTAN_NOEXCEPT override
Definition: exceptn.h:26
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:68
Definition: alg_id.cpp:13
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
virtual void finish(secure_vector< uint8_t > &final_block, size_t offset=0)=0
BOTAN_DLL int botan_cipher_valid_nonce_length ( botan_cipher_t  cipher,
size_t  nl 
)

Definition at line 972 of file ffi.cpp.

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

973  {
974  return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { return c.valid_nonce_length(nl) ? 1 : 0; });
975  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
virtual bool valid_nonce_length(size_t nonce_len) const =0
BOTAN_DLL 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 242 of file ffi.cpp.

243  {
244  return BOTAN_HAS_FFI;
245  }
BOTAN_DLL 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 247 of file ffi.cpp.

248  {
249  /*
250  * In the future if multiple versions are supported, this
251  * function would accept any of them.
252  */
253  if(api_version == BOTAN_HAS_FFI)
254  return 0;
255  return -1;
256  }
BOTAN_DLL 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 712 of file ffi.cpp.

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

713  {
714  return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.clear(); });
715  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
MechanismType hash
BOTAN_DLL 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 701 of file ffi.cpp.

References hash.

702  {
703  delete hash;
704  return 0;
705  }
MechanismType hash
BOTAN_DLL 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 722 of file ffi.cpp.

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

723  {
724  return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.final(out); });
725  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
MechanismType hash
BOTAN_DLL 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 673 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_EXCEPTION_THROWN, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::HashFunction::create().

674  {
675  try
676  {
677  if(hash == nullptr || hash_name == nullptr || *hash_name == 0)
679  if(flags != 0)
681 
682  auto h = Botan::HashFunction::create(hash_name);
683  if(h)
684  {
685  *hash = new botan_hash_struct(h.release());
686  return 0;
687  }
688  }
689  catch(std::exception& e)
690  {
691  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
692  }
693  catch(...)
694  {
695  log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
696  }
697 
699  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:139
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:140
MechanismType hash
BOTAN_DLL int botan_hash_name ( botan_hash_t  hash,
char *  name,
size_t  name_len 
)

TODO has no implementation

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

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

708  {
709  return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { *out = h.output_length(); });
710  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
MechanismType hash
BOTAN_DLL 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 717 of file ffi.cpp.

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

718  {
719  return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.update(buf, len); });
720  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
MechanismType hash
BOTAN_DLL 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 273 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_HEX_LOWER_CASE, and Botan::hex_encode().

274  {
275  try
276  {
277  const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
278  Botan::hex_encode(out, in, len, uppercase);
279  return 0;
280  }
281  catch(std::exception& e)
282  {
283  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
284  }
285 
286  return 1;
287  }
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_FFI_HEX_LOWER_CASE
Definition: ffi.h:150
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14
BOTAN_DLL 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 1033 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and Botan::get_kdf().

1038  {
1039  try
1040  {
1041  std::unique_ptr<Botan::KDF> kdf(Botan::get_kdf(kdf_algo));
1042  kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
1043  return 0;
1044  }
1045  catch(std::exception& e)
1046  {
1047  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1048  }
1049 
1050  return -1;
1051  }
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
KDF * get_kdf(const std::string &algo_spec)
Definition: kdf.cpp:226
BOTAN_DLL 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 769 of file ffi.cpp.

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

770  {
771  return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.clear(); });
772  }
virtual void clear()=0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 753 of file ffi.cpp.

754  {
755  delete mac;
756  return 0;
757  }
BOTAN_DLL 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 779 of file ffi.cpp.

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

780  {
781  return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.final(out); });
782  }
void final(uint8_t out[])
Definition: buf_comp.h:89
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 727 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and Botan::MessageAuthenticationCode::create().

728  {
729  try
730  {
731  if(!mac || !mac_name || flags != 0)
732  return -1;
733 
734  auto m = Botan::MessageAuthenticationCode::create(mac_name);
735  if(m)
736  {
737  *mac = new botan_mac_struct(m.release());
738  return 0;
739  }
740  }
741  catch(std::exception& e)
742  {
743  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
744  }
745  catch(...)
746  {
747  log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
748  }
749 
750  return -2;
751  }
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
Definition: mac.cpp:43
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL 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 764 of file ffi.cpp.

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

765  {
766  return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { *out = m.output_length(); });
767  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
virtual size_t output_length() const =0
BOTAN_DLL 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 759 of file ffi.cpp.

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

760  {
761  return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.set_key(key, key_len); });
762  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 774 of file ffi.cpp.

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

775  {
776  return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.update(buf, len); });
777  }
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:34
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 2208 of file ffi.cpp.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and Botan::mceies_decrypt().

2213  {
2214  try
2215  {
2216  Botan::Private_Key& key = safe_get(mce_key_obj);
2217 
2218 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
2219  Botan::McEliece_PrivateKey* mce = dynamic_cast<Botan::McEliece_PrivateKey*>(&key);
2220  if(!mce)
2221  return -2;
2222 
2223  const Botan::secure_vector<uint8_t> pt = mceies_decrypt(*mce, ct, ct_len, ad, ad_len, aead);
2224  return write_vec_output(out, out_len, pt);
2225 #else
2227 #endif
2228  }
2229  catch(std::exception& e)
2230  {
2231  return ffi_error_exception_thrown(e.what());
2232  }
2233  }
secure_vector< uint8_t > mceies_decrypt(const McEliece_PrivateKey &privkey, const uint8_t ct[], size_t ct_len, const uint8_t ad[], size_t ad_len, const std::string &algo)
Definition: mceies.cpp:70
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
BOTAN_DLL 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 2235 of file ffi.cpp.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and Botan::mceies_encrypt().

2241  {
2242  try
2243  {
2244  Botan::Public_Key& key = safe_get(mce_key_obj);
2245  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
2246 
2247 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
2248  Botan::McEliece_PublicKey* mce = dynamic_cast<Botan::McEliece_PublicKey*>(&key);
2249  if(!mce)
2250  return -2;
2251 
2252  Botan::secure_vector<uint8_t> ct = mceies_encrypt(*mce, pt, pt_len, ad, ad_len, rng, aead);
2253  return write_vec_output(out, out_len, ct);
2254 #else
2256 #endif
2257  }
2258  catch(std::exception& e)
2259  {
2260  return ffi_error_exception_thrown(e.what());
2261  }
2262  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
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:33
BOTAN_DLL int botan_mp_add ( botan_mp_t  result,
const botan_mp_t  x,
const botan_mp_t  y 
)

Definition at line 460 of file ffi.cpp.

References BOTAN_FFI_DO.

461  {
462  return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) + safe_get(y); });
463  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_clear ( botan_mp_t  mp)

Definition at line 347 of file ffi.cpp.

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

348  {
349  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.clear(); });
350  }
void clear()
Definition: bigint.h:217
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_clear_bit ( botan_mp_t  n,
size_t  bit 
)

Clear the specified bit

Definition at line 583 of file ffi.cpp.

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

584  {
585  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.clear_bit(bit); });
586  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
void clear_bit(size_t n)
Definition: bigint.cpp:168
BOTAN_DLL int botan_mp_cmp ( int *  result,
const botan_mp_t  x,
const botan_mp_t  y 
)

Definition at line 506 of file ffi.cpp.

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

507  {
508  return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { *result = x.cmp(safe_get(y_w)); });
509  }
int32_t cmp(const BigInt &n, bool check_signs=true) const
Definition: bigint.cpp:98
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_destroy ( botan_mp_t  mp)

Definition at line 454 of file ffi.cpp.

455  {
456  delete mp;
457  return 0;
458  }
BOTAN_DLL 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 475 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::divide().

478  {
479  return BOTAN_FFI_DO(Botan::BigInt, quotient, q, {
480  Botan::BigInt r;
481  Botan::divide(safe_get(x), safe_get(y), q, r);
482  safe_get(remainder) = r;
483  });
484  }
void divide(const BigInt &x, const BigInt &y_arg, BigInt &q, BigInt &r)
Definition: divide.cpp:58
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_equal ( const botan_mp_t  x,
const botan_mp_t  y 
)

Definition at line 486 of file ffi.cpp.

References BOTAN_FFI_DO.

487  {
488  return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { return x == safe_get(y_w); });
489  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_flip_sign ( botan_mp_t  mp)

Definition at line 405 of file ffi.cpp.

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

406  {
407  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.flip_sign(); });
408  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
void flip_sign()
Definition: bigint.cpp:226
BOTAN_DLL int botan_mp_from_bin ( const botan_mp_t  mp,
const uint8_t  vec[],
size_t  vec_len 
)

Definition at line 410 of file ffi.cpp.

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

411  {
412  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_decode(bin, bin_len); });
413  }
void binary_decode(const uint8_t buf[], size_t length)
Definition: bigint.cpp:280
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_gcd ( botan_mp_t  out,
const botan_mp_t  x,
const botan_mp_t  y 
)

Definition at line 561 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::gcd().

562  {
563  return BOTAN_FFI_DO(Botan::BigInt, out, o, {
564  o = Botan::gcd(safe_get(x), safe_get(y)); });
565  }
BigInt gcd(const BigInt &a, const BigInt &b)
Definition: numthry.cpp:46
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 573 of file ffi.cpp.

References BOTAN_FFI_DO.

574  {
575  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { return (n.get_bit(bit)); });
576  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_init ( botan_mp_t mp)

Definition at line 341 of file ffi.cpp.

342  {
343  *mp = new botan_mp_struct(new Botan::BigInt);
344  return 0;
345  }
BOTAN_DLL int botan_mp_is_even ( const botan_mp_t  mp)

Definition at line 501 of file ffi.cpp.

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

502  {
503  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_even(); });
504  }
bool is_even() const
Definition: bigint.h:232
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_is_negative ( const botan_mp_t  mp)

Return true iff mp is less than 0

Definition at line 395 of file ffi.cpp.

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

396  {
397  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_negative() ? 1 : 0; });
398  }
bool is_negative() const
Definition: bigint.h:348
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_is_odd ( const botan_mp_t  mp)

Definition at line 496 of file ffi.cpp.

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

497  {
498  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_odd(); });
499  }
bool is_odd() const
Definition: bigint.h:238
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_is_positive ( const botan_mp_t  mp)

Return true iff mp is greater than 0

Definition at line 400 of file ffi.cpp.

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

401  {
402  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_positive() ? 1 : 0; });
403  }
bool is_positive() const
Definition: bigint.h:354
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 567 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::is_prime().

568  {
569  return BOTAN_FFI_DO(Botan::BigInt, mp, n,
570  { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; });
571  }
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition: numthry.cpp:441
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_is_zero ( const botan_mp_t  mp)

Definition at line 491 of file ffi.cpp.

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

492  {
493  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_zero(); });
494  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
bool is_zero() const
Definition: bigint.h:250
BOTAN_DLL int botan_mp_lshift ( botan_mp_t  out,
const botan_mp_t  in,
size_t  shift 
)

Definition at line 523 of file ffi.cpp.

References BOTAN_FFI_DO.

524  {
525  return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) << shift; });
526  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_mod_inverse ( botan_mp_t  out,
const botan_mp_t  in,
const botan_mp_t  modulus 
)

Definition at line 533 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::inverse_mod().

534  {
535  return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); });
536  }
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:276
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 538 of file ffi.cpp.

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

539  {
540  return BOTAN_FFI_DO(Botan::BigInt, out, o, {
541  Botan::Modular_Reducer reducer(safe_get(modulus));
542  o = reducer.multiply(safe_get(x), safe_get(y));
543  });
544  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_mul ( botan_mp_t  result,
const botan_mp_t  x,
const botan_mp_t  y 
)

Definition at line 470 of file ffi.cpp.

References BOTAN_FFI_DO.

471  {
472  return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) * safe_get(y); });
473  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_num_bits ( const botan_mp_t  n,
size_t *  bits 
)

Definition at line 588 of file ffi.cpp.

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

589  {
590  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bits = n.bits(); });
591  }
size_t bits() const
Definition: bigint.cpp:184
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_num_bytes ( const botan_mp_t  n,
size_t *  bytes 
)

Definition at line 593 of file ffi.cpp.

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

594  {
595  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bytes = n.bytes(); });
596  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
size_t bytes() const
Definition: bigint.cpp:176
BOTAN_DLL 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 517 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::power_mod().

518  {
519  return BOTAN_FFI_DO(Botan::BigInt, out, o,
520  { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
521  }
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:373
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_rand_bits ( botan_mp_t  rand_out,
botan_rng_t  rng,
size_t  bits 
)

Definition at line 546 of file ffi.cpp.

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

547  {
549  safe_get(rand_out).randomize(r, bits); });
550  }
virtual void randomize(uint8_t output[], size_t length)=0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 552 of file ffi.cpp.

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

556  {
558  safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
559  }
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
Definition: big_rand.cpp:45
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_rshift ( botan_mp_t  out,
const botan_mp_t  in,
size_t  shift 
)

Definition at line 528 of file ffi.cpp.

References BOTAN_FFI_DO.

529  {
530  return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) >> shift; });
531  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_set_bit ( botan_mp_t  n,
size_t  bit 
)

Set the specified bit

Definition at line 578 of file ffi.cpp.

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

579  {
580  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.set_bit(bit); });
581  }
void set_bit(size_t n)
Definition: bigint.cpp:157
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_set_from_int ( botan_mp_t  mp,
int  initial_value 
)

Definition at line 352 of file ffi.cpp.

References BOTAN_FFI_DO.

353  {
354  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
355  if(initial_value >= 0)
356  {
357  bn = Botan::BigInt(static_cast<uint64_t>(initial_value));
358  }
359  else
360  {
361  bn = Botan::BigInt(static_cast<uint64_t>(-initial_value));
362  bn.flip_sign();
363  }
364  });
365  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_set_from_mp ( botan_mp_t  dest,
const botan_mp_t  source 
)

Definition at line 390 of file ffi.cpp.

References BOTAN_FFI_DO.

391  {
392  return BOTAN_FFI_DO(Botan::BigInt, dest, bn, { bn = safe_get(source); });
393  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_set_from_radix_str ( botan_mp_t  dest,
const char *  str,
size_t  radix 
)

Definition at line 372 of file ffi.cpp.

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

373  {
374  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
375  Botan::BigInt::Base base;
376  if(radix == 10)
377  base = Botan::BigInt::Decimal;
378  else if(radix == 16)
380  else
382 
383  const uint8_t* bytes = reinterpret_cast<const uint8_t*>(str);
384  const size_t len = strlen(str);
385 
386  bn = Botan::BigInt::decode(bytes, len, base);
387  });
388  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
static BigInt decode(const uint8_t buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:114
BOTAN_DLL int botan_mp_set_from_str ( botan_mp_t  dest,
const char *  str 
)

Definition at line 367 of file ffi.cpp.

References BOTAN_FFI_DO.

368  {
369  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn = Botan::BigInt(str); });
370  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_sub ( botan_mp_t  result,
const botan_mp_t  x,
const botan_mp_t  y 
)

Definition at line 465 of file ffi.cpp.

References BOTAN_FFI_DO.

466  {
467  return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) - safe_get(y); });
468  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_swap ( botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 511 of file ffi.cpp.

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

512  {
513  return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { x.swap(safe_get(y_w)); });
514  }
void swap(BigInt &other)
Definition: bigint.h:122
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_to_bin ( const botan_mp_t  mp,
uint8_t  vec[] 
)

Definition at line 441 of file ffi.cpp.

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

442  {
443  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_encode(vec); });
444  }
void binary_encode(uint8_t buf[]) const
Definition: bigint.cpp:270
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_mp_to_hex ( const botan_mp_t  mp,
char *  out 
)

Definition at line 415 of file ffi.cpp.

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

416  {
417  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
418  std::vector<uint8_t> hex = Botan::BigInt::encode(bn, Botan::BigInt::Hexadecimal);
419  std::memcpy(out, hex.data(), hex.size());
420  out[hex.size()] = 0; // null terminate
421  });
422  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
static std::vector< uint8_t > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:54
BOTAN_DLL int botan_mp_to_str ( const botan_mp_t  mp,
uint8_t  base,
char *  out,
size_t *  out_len 
)

Definition at line 424 of file ffi.cpp.

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

425  {
426  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
427  Botan::BigInt::Base base;
428  if(digit_base == 0 || digit_base == 10)
429  base = Botan::BigInt::Decimal;
430  else if(digit_base == 16)
432  else
433  throw FFI_Error("botan_mp_to_str invalid digit base");
434 
435  std::vector<uint8_t> hex = Botan::BigInt::encode(bn, base);
436  hex.push_back(0); // null terminator
437  write_str_output(out, out_len, hex);
438  });
439  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
static std::vector< uint8_t > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:54
BOTAN_DLL int botan_mp_to_uint32 ( const botan_mp_t  mp,
uint32_t *  val 
)

Definition at line 446 of file ffi.cpp.

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

447  {
448  if(val == nullptr) {
450  }
451  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { *val = bn.to_u32bit(); });
452  }
uint32_t to_u32bit() const
Definition: bigint.cpp:141
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:140
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 992 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and Botan::get_pbkdf().

995  {
996  try
997  {
998  std::unique_ptr<Botan::PBKDF> pbkdf(Botan::get_pbkdf(pbkdf_algo));
999  pbkdf->pbkdf_iterations(out, out_len, pass, salt, salt_len, iterations);
1000  return 0;
1001  }
1002  catch(std::exception& e)
1003  {
1004  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1005  }
1006 
1007  return -1;
1008  }
PBKDF * get_pbkdf(const std::string &algo_spec, const std::string &provider="")
Definition: pbkdf.h:216
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL 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 1010 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and Botan::get_pbkdf().

1016  {
1017  try
1018  {
1019  std::unique_ptr<Botan::PBKDF> pbkdf(Botan::get_pbkdf(pbkdf_algo));
1020  pbkdf->pbkdf_timed(out, out_len, password, salt, salt_len,
1021  std::chrono::milliseconds(ms_to_run),
1022  *iterations_used);
1023  return 0;
1024  }
1025  catch(std::exception& e)
1026  {
1027  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1028  }
1029 
1030  return -1;
1031  }
PBKDF * get_pbkdf(const std::string &algo_spec, const std::string &provider="")
Definition: pbkdf.h:216
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_pk_op_decrypt ( botan_pk_op_decrypt_t  op,
uint8_t  out[],
size_t *  out_len,
uint8_t  ciphertext[],
size_t  ciphertext_len 
)

Definition at line 1889 of file ffi.cpp.

References BOTAN_FFI_DO.

1892  {
1893  return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, {
1894  return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len));
1895  });
1896  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 1857 of file ffi.cpp.

References BOTAN_ASSERT_NONNULL, BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, and Botan::system_rng().

1861  {
1862  try
1863  {
1865 
1866  *op = nullptr;
1867 
1868  if(flags != 0)
1869  return BOTAN_FFI_ERROR_BAD_FLAG;
1870 
1871  std::unique_ptr<Botan::PK_Decryptor> pk(new Botan::PK_Decryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
1872  *op = new botan_pk_op_decrypt_struct(pk.release());
1873  return 0;
1874  }
1875  catch(std::exception& e)
1876  {
1877  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1878  }
1879 
1880  return -1;
1881  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:139
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:79
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:196
BOTAN_DLL int botan_pk_op_decrypt_destroy ( botan_pk_op_decrypt_t  op)

Definition at line 1883 of file ffi.cpp.

1884  {
1885  delete op;
1886  return 0;
1887  }
BOTAN_DLL 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 1844 of file ffi.cpp.

References BOTAN_FFI_DO.

1848  {
1849  return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, {
1850  return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
1851  });
1852  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 1812 of file ffi.cpp.

References BOTAN_ASSERT_NONNULL, BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, and Botan::system_rng().

1816  {
1817  try
1818  {
1820 
1821  *op = nullptr;
1822 
1823  if(flags != 0)
1824  return BOTAN_FFI_ERROR_BAD_FLAG;
1825 
1826  std::unique_ptr<Botan::PK_Encryptor> pk(new Botan::PK_Encryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
1827  *op = new botan_pk_op_encrypt_struct(pk.release());
1828  return 0;
1829  }
1830  catch(std::exception& e)
1831  {
1832  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1833  }
1834 
1835  return -1;
1836  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:139
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:79
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:196
BOTAN_DLL int botan_pk_op_encrypt_destroy ( botan_pk_op_encrypt_t  op)

Definition at line 1838 of file ffi.cpp.

1839  {
1840  delete op;
1841  return 0;
1842  }
BOTAN_DLL 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 2034 of file ffi.cpp.

References BOTAN_FFI_DO.

2038  {
2039  return BOTAN_FFI_DO(Botan::PK_Key_Agreement, op, o, {
2040  auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
2041  return write_vec_output(out, out_len, k);
2042  });
2043  }
secure_vector< uint8_t > bits_of() const
Definition: symkey.h:31
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:202
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 1992 of file ffi.cpp.

References BOTAN_ASSERT_NONNULL, BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, and Botan::system_rng().

1996  {
1997  try
1998  {
2000 
2001  *op = nullptr;
2002 
2003  if(flags != 0)
2004  return BOTAN_FFI_ERROR_BAD_FLAG;
2005 
2006  std::unique_ptr<Botan::PK_Key_Agreement> pk(new Botan::PK_Key_Agreement(safe_get(key_obj), Botan::system_rng(), kdf));
2007  *op = new botan_pk_op_ka_struct(pk.release());
2008  return 0;
2009  }
2010  catch(std::exception& e)
2011  {
2012  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
2013  }
2014 
2015  return -1;
2016  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:139
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:79
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:196
BOTAN_DLL int botan_pk_op_key_agreement_destroy ( botan_pk_op_ka_t  op)

Definition at line 2018 of file ffi.cpp.

2019  {
2020  delete op;
2021  return 0;
2022  }
BOTAN_DLL int botan_pk_op_key_agreement_export_public ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 2024 of file ffi.cpp.

References BOTAN_FFI_DO.

2026  {
2027  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
2028  if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
2029  return write_vec_output(out, out_len, kak->public_value());
2030  return -2;
2031  });
2032  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 1901 of file ffi.cpp.

References BOTAN_ASSERT_NONNULL, BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and Botan::system_rng().

1905  {
1906  try
1907  {
1909 
1910  *op = nullptr;
1911 
1912  if(flags != 0)
1913  return BOTAN_FFI_ERROR_BAD_FLAG;
1914 
1915  std::unique_ptr<Botan::PK_Signer> pk(new Botan::PK_Signer(safe_get(key_obj),Botan::system_rng(), hash));
1916  *op = new botan_pk_op_sign_struct(pk.release());
1917  return 0;
1918  }
1919  catch(std::exception& e)
1920  {
1921  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1922  }
1923 
1925  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:139
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:79
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:196
MechanismType hash
BOTAN_DLL int botan_pk_op_sign_destroy ( botan_pk_op_sign_t  op)

Definition at line 1927 of file ffi.cpp.

1928  {
1929  delete op;
1930  return 0;
1931  }
BOTAN_DLL 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 1938 of file ffi.cpp.

References BOTAN_FFI_DO.

1939  {
1940  return BOTAN_FFI_DO(Botan::PK_Signer, op, o, {
1941  return write_vec_output(out, out_len, o.signature(safe_get(rng_obj)));
1942  });
1943  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_pk_op_sign_update ( botan_pk_op_sign_t  op,
const uint8_t  in[],
size_t  in_len 
)

Definition at line 1933 of file ffi.cpp.

References BOTAN_FFI_DO.

1934  {
1935  return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { o.update(in, in_len); });
1936  }
void update(uint8_t in)
Definition: pubkey.h:240
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 1945 of file ffi.cpp.

References BOTAN_ASSERT_NONNULL, BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_BAD_FLAG.

1949  {
1950  try
1951  {
1953 
1954  if(flags != 0)
1955  return BOTAN_FFI_ERROR_BAD_FLAG;
1956 
1957  std::unique_ptr<Botan::PK_Verifier> pk(new Botan::PK_Verifier(safe_get(key_obj), hash));
1958  *op = new botan_pk_op_verify_struct(pk.release());
1959  return 0;
1960  }
1961  catch(std::exception& e)
1962  {
1963  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1964  }
1965 
1966  return -1;
1967  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:139
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:79
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
MechanismType hash
BOTAN_DLL int botan_pk_op_verify_destroy ( botan_pk_op_verify_t  op)

Definition at line 1969 of file ffi.cpp.

1970  {
1971  delete op;
1972  return 0;
1973  }
BOTAN_DLL int botan_pk_op_verify_finish ( botan_pk_op_verify_t  op,
const uint8_t  sig[],
size_t  sig_len 
)

Definition at line 1980 of file ffi.cpp.

References BOTAN_FFI_DO.

1981  {
1982  return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, {
1983  const bool legit = o.check_signature(sig, sig_len);
1984 
1985  if(legit)
1986  return 0;
1987  else
1988  return 1;
1989  });
1990  }
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:292
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_pk_op_verify_update ( botan_pk_op_verify_t  op,
const uint8_t  in[],
size_t  in_len 
)

Definition at line 1975 of file ffi.cpp.

References BOTAN_FFI_DO.

1976  {
1977  return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, { o.update(in, in_len); });
1978  }
void update(uint8_t in)
Definition: pubkey.h:337
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_privkey_check_key ( botan_privkey_t  key,
botan_rng_t  rng,
uint32_t  flags 
)

Definition at line 1673 of file ffi.cpp.

References BOTAN_CHECK_KEY_EXPENSIVE_TESTS, and BOTAN_FFI_DO.

1674  {
1675  const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
1676  return BOTAN_FFI_DO(Botan::Private_Key, key, k,
1677  { return (k.check_key(safe_get(rng), strong) == true) ? 0 : -1; });
1678  }
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition: ffi.h:639
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_privkey_create ( botan_privkey_t key,
const char *  algo_name,
const char *  algo_params,
botan_rng_t  rng 
)

Definition at line 1113 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::create_private_key().

1117  {
1118  try
1119  {
1120  if(key_obj == nullptr)
1122 
1123  *key_obj = nullptr;
1124  if(rng_obj == nullptr)
1126 
1127  if(algo_name == nullptr)
1128  algo_name = "RSA";
1129  if(algo_params == nullptr)
1130  algo_params = "";
1131 
1132  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1133  std::unique_ptr<Botan::Private_Key> key(
1134  Botan::create_private_key(algo_name, rng, algo_params));
1135 
1136  if(key)
1137  {
1138  *key_obj = new botan_privkey_struct(key.release());
1139  return 0;
1140  }
1141  else
1142  {
1144  }
1145  }
1146  catch(std::exception& e)
1147  {
1148  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1149  }
1150 
1152  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:140
std::unique_ptr< Private_Key > create_private_key(const std::string &alg_name, RandomNumberGenerator &rng, const std::string &params)
Definition: pk_algs.cpp:204
BOTAN_DLL int botan_privkey_create_ecdh ( botan_privkey_t key,
botan_rng_t  rng,
const char *  params 
)

Definition at line 1235 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_EXCEPTION_THROWN.

1236  {
1237  try
1238  {
1239  if(key_obj == nullptr || rng_obj == nullptr || param_str == nullptr || *param_str == 0)
1240  return -1;
1241 
1242  *key_obj = nullptr;
1243 
1244  const std::string params(param_str);
1245 
1246 #if defined(BOTAN_HAS_CURVE_25519)
1247  if(params == "curve25519")
1248  {
1249  std::unique_ptr<Botan::Private_Key> key(new Botan::Curve25519_PrivateKey(safe_get(rng_obj)));
1250  *key_obj = new botan_privkey_struct(key.release());
1251  return 0;
1252  }
1253 #endif
1254 
1255 #if defined(BOTAN_HAS_ECDH)
1256  Botan::EC_Group grp(params);
1257  std::unique_ptr<Botan::Private_Key> key(new Botan::ECDH_PrivateKey(safe_get(rng_obj), grp));
1258  *key_obj = new botan_privkey_struct(key.release());
1259  return 0;
1260 #endif
1261  }
1262  catch(std::exception& e)
1263  {
1264  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1265  }
1266 
1268  }
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_privkey_create_ecdsa ( botan_privkey_t key,
botan_rng_t  rng,
const char *  params 
)

Definition at line 1183 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

1184  {
1185  try
1186  {
1187  if(key_obj == nullptr || rng_obj == nullptr || param_str == nullptr || *param_str == 0)
1188  return -1;
1189 
1190  *key_obj = nullptr;
1191 
1192 #if defined(BOTAN_HAS_ECDSA)
1193  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1194  Botan::EC_Group grp(param_str);
1195  std::unique_ptr<Botan::Private_Key> key(new Botan::ECDSA_PrivateKey(rng, grp));
1196  *key_obj = new botan_privkey_struct(key.release());
1197  return 0;
1198 #else
1200 #endif
1201  }
1202  catch(std::exception& e)
1203  {
1204  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1205  }
1206 
1208  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_privkey_create_mceliece ( botan_privkey_t key,
botan_rng_t  rng,
size_t  n,
size_t  t 
)

Definition at line 1210 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

1211  {
1212  try
1213  {
1214  if(key_obj == nullptr || rng_obj == nullptr || n == 0 || t == 0)
1215  return -1;
1216 
1217  *key_obj = nullptr;
1218 
1219 #if defined(BOTAN_HAS_MCELIECE)
1220  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1221  std::unique_ptr<Botan::Private_Key> key(new Botan::McEliece_PrivateKey(rng, n, t));
1222  *key_obj = new botan_privkey_struct(key.release());
1223  return 0;
1224 #else
1226 #endif
1227  }
1228  catch(std::exception& e)
1229  {
1230  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1232  }
1233  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_privkey_create_rsa ( botan_privkey_t key,
botan_rng_t  rng,
size_t  n_bits 
)

Definition at line 1154 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

1155  {
1156  try
1157  {
1158  if(key_obj == nullptr || rng_obj == nullptr)
1159  return -1;
1160  if(n_bits < 1024 || n_bits > 16*1024)
1161  return -2;
1162 
1163  *key_obj = nullptr;
1164 
1165 #if defined(BOTAN_HAS_RSA)
1166  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1167  std::unique_ptr<Botan::Private_Key> key(new Botan::RSA_PrivateKey(rng, n_bits));
1168  *key_obj = new botan_privkey_struct(key.release());
1169  return 0;
1170 #else
1172 #endif
1173  }
1174  catch(std::exception& e)
1175  {
1176  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1177  }
1178 
1180  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_privkey_destroy ( botan_privkey_t  key)

Definition at line 1630 of file ffi.cpp.

1631  {
1632  delete key;
1633  return 0;
1634  }
BOTAN_DLL int botan_privkey_dsa_get_x ( botan_mp_t  n,
botan_privkey_t  key 
)

Definition at line 1607 of file ffi.cpp.

References botan_privkey_get_field().

1608  {
1609  return botan_privkey_get_field(x, key, "x");
1610  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1558
BOTAN_DLL int botan_privkey_export ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len,
uint32_t  flags 
)

Definition at line 1692 of file ffi.cpp.

References Botan::PKCS8::BER_encode(), BOTAN_FFI_DO, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, and Botan::PKCS8::PEM_encode().

1693  {
1694  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
1696  return write_vec_output(out, out_len, Botan::PKCS8::BER_encode(k));
1698  return write_str_output(out, out_len, Botan::PKCS8::PEM_encode(k));
1699  else
1700  return -2;
1701  });
1702  }
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:659
secure_vector< uint8_t > BER_encode(const Private_Key &key)
Definition: pkcs8.cpp:130
Flags flags(Flag flags)
Definition: p11.h:858
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:139
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:658
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 1704 of file ffi.cpp.

References botan_privkey_export_encrypted_pbkdf_iter().

1710  {
1711  return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
1712  }
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.cpp:1757
BOTAN_DLL 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 1757 of file ffi.cpp.

References Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(), BOTAN_FFI_DO, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, and Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter().

Referenced by botan_privkey_export_encrypted().

1765  {
1766  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
1767  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1768 
1769  std::string cipher;
1770  if(maybe_cipher)
1771  {
1772  cipher = maybe_cipher;
1773  }
1774 
1775  std::string pbkdf_hash;
1776  if(maybe_pbkdf_hash)
1777  {
1778  pbkdf_hash = maybe_pbkdf_hash;
1779  }
1780 
1782  {
1783  return write_vec_output(out, out_len,
1784  Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
1785  }
1787  {
1788  return write_str_output(out, out_len,
1789  Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
1790  }
1791  else
1792  {
1793  return -2;
1794  }
1795  });
1796  }
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:208
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:659
Flags flags(Flag flags)
Definition: p11.h:858
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:233
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:658
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 1714 of file ffi.cpp.

References Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(), BOTAN_FFI_DO, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, and Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec().

1723  {
1724  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
1725  const std::chrono::milliseconds pbkdf_time(pbkdf_msec);
1726  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1727 
1728  std::string cipher;
1729  if(maybe_cipher)
1730  {
1731  cipher = maybe_cipher;
1732  }
1733 
1734  std::string pbkdf_hash;
1735  if(maybe_pbkdf_hash)
1736  {
1737  pbkdf_hash = maybe_pbkdf_hash;
1738  }
1739 
1741  {
1742  return write_vec_output(out, out_len,
1743  Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
1744  }
1746  {
1747  return write_str_output(out, out_len,
1748  Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
1749  }
1750  else
1751  {
1752  return -2;
1753  }
1754  });
1755  }
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:659
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:658
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:248
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
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:274
BOTAN_DLL int botan_privkey_export_pubkey ( botan_pubkey_t out,
botan_privkey_t  in 
)

Definition at line 1642 of file ffi.cpp.

References Botan::X509::BER_encode(), BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and Botan::X509::load_key().

1643  {
1644  try
1645  {
1646  std::unique_ptr<Botan::Public_Key> pubkey(
1648  Botan::X509::BER_encode(safe_get(key_obj))));
1649  *pubout = new botan_pubkey_struct(pubkey.release());
1650  return 0;
1651  }
1652  catch(std::exception& e)
1653  {
1654  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1655  }
1656 
1658  }
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.cpp:19
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:37
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_privkey_get_field ( botan_mp_t  output,
botan_privkey_t  key,
const char *  field_name 
)

Definition at line 1558 of file ffi.cpp.

References BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

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

1561  {
1562  if(field_name_cstr == nullptr)
1564 
1565  const std::string field_name(field_name_cstr);
1566 
1567  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
1568  safe_get(output) = botan_privkey_do_get_field(k, field_name);
1569  });
1570  }
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:140
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 1270 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and Botan::PKCS8::load_key().

1273  {
1274  *key = nullptr;
1275 
1276  try
1277  {
1278  Botan::DataSource_Memory src(bits, len);
1279 
1280  if(password == nullptr)
1281  password = "";
1282 
1283  Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
1284 
1285  std::unique_ptr<Botan::PKCS8_PrivateKey> pkcs8;
1286  pkcs8.reset(Botan::PKCS8::load_key(src, rng, static_cast<std::string>(password)));
1287 
1288  if(pkcs8)
1289  {
1290  *key = new botan_privkey_struct(pkcs8.release());
1291  return 0;
1292  }
1293  }
1294  catch(std::exception& e)
1295  {
1296  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1297  }
1298 
1299  return -1;
1300  }
Private_Key * load_key(DataSource &source, RandomNumberGenerator &rng, std::function< std::string()> get_pass)
Definition: pkcs8.cpp:313
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL 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 1371 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

1373  {
1374  *key = nullptr;
1375 
1376 #if defined(BOTAN_HAS_DSA)
1377  try
1378  {
1379  Botan::Null_RNG null_rng;
1380  Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
1381  *key = new botan_privkey_struct(new Botan::DSA_PrivateKey(null_rng, group, safe_get(x)));
1382  return 0;
1383  }
1384  catch(std::exception& e)
1385  {
1386  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1387  }
1388  return -1;
1389 #else
1390  BOTAN_UNUSED(p);
1391  BOTAN_UNUSED(q);
1392  BOTAN_UNUSED(g);
1393  BOTAN_UNUSED(x);
1395 #endif
1396  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_UNUSED(v)
Definition: assert.h:92
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_privkey_load_rsa ( botan_privkey_t key,
botan_mp_t  p,
botan_mp_t  q,
botan_mp_t  d 
)

Definition at line 1326 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

1328  {
1329  *key = nullptr;
1330 
1331 #if defined(BOTAN_HAS_RSA)
1332  try
1333  {
1334  *key = new botan_privkey_struct(new Botan::RSA_PrivateKey(safe_get(p),
1335  safe_get(q),
1336  safe_get(d)));
1337  return 0;
1338  }
1339  catch(std::exception& e)
1340  {
1341  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1342  }
1343  return -1;
1344 #else
1346 #endif
1347  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_privkey_rsa_get_d ( botan_mp_t  d,
botan_privkey_t  rsa_key 
)

Definition at line 1592 of file ffi.cpp.

References botan_privkey_get_field().

1593  {
1594  return botan_privkey_get_field(d, key, "d");
1595  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1558
BOTAN_DLL int botan_privkey_rsa_get_e ( botan_mp_t  e,
botan_privkey_t  rsa_key 
)

Definition at line 1587 of file ffi.cpp.

References botan_privkey_get_field().

1588  {
1589  return botan_privkey_get_field(e, key, "e");
1590  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1558
BOTAN_DLL int botan_privkey_rsa_get_n ( botan_mp_t  n,
botan_privkey_t  rsa_key 
)

Definition at line 1582 of file ffi.cpp.

References botan_privkey_get_field().

1583  {
1584  return botan_privkey_get_field(n, key, "n");
1585  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1558
BOTAN_DLL int botan_privkey_rsa_get_p ( botan_mp_t  p,
botan_privkey_t  rsa_key 
)

Definition at line 1572 of file ffi.cpp.

References botan_privkey_get_field().

1573  {
1574  return botan_privkey_get_field(p, key, "p");
1575  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1558
BOTAN_DLL int botan_privkey_rsa_get_q ( botan_mp_t  q,
botan_privkey_t  rsa_key 
)

Definition at line 1577 of file ffi.cpp.

References botan_privkey_get_field().

1578  {
1579  return botan_privkey_get_field(q, key, "q");
1580  }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1558
BOTAN_DLL int botan_pubkey_algo_name ( botan_pubkey_t  key,
char  out[],
size_t *  out_len 
)

Definition at line 1660 of file ffi.cpp.

References BOTAN_FFI_DO.

1661  {
1662  return BOTAN_FFI_DO(Botan::Public_Key, key, k, { return write_str_output(out, out_len, k.algo_name()); });
1663  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 1665 of file ffi.cpp.

References BOTAN_CHECK_KEY_EXPENSIVE_TESTS, and BOTAN_FFI_DO.

1666  {
1667  const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
1668 
1669  return BOTAN_FFI_DO(Botan::Public_Key, key, k,
1670  { return (k.check_key(safe_get(rng), strong) == true) ? 0 : -1; });
1671  }
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition: ffi.h:639
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_pubkey_destroy ( botan_pubkey_t  key)

Definition at line 1636 of file ffi.cpp.

1637  {
1638  delete key;
1639  return 0;
1640  }
BOTAN_DLL int botan_pubkey_dsa_get_g ( botan_mp_t  d,
botan_pubkey_t  key 
)

Definition at line 1620 of file ffi.cpp.

References botan_pubkey_get_field().

1621  {
1622  return botan_pubkey_get_field(g, key, "g");
1623  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1544
BOTAN_DLL int botan_pubkey_dsa_get_p ( botan_mp_t  p,
botan_pubkey_t  key 
)

Definition at line 1612 of file ffi.cpp.

References botan_pubkey_get_field().

1613  {
1614  return botan_pubkey_get_field(p, key, "p");
1615  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1544
BOTAN_DLL int botan_pubkey_dsa_get_q ( botan_mp_t  q,
botan_pubkey_t  key 
)

Definition at line 1616 of file ffi.cpp.

References botan_pubkey_get_field().

1617  {
1618  return botan_pubkey_get_field(q, key, "q");
1619  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1544
BOTAN_DLL int botan_pubkey_dsa_get_y ( botan_mp_t  y,
botan_pubkey_t  key 
)

Definition at line 1624 of file ffi.cpp.

References botan_pubkey_get_field().

1625  {
1626  return botan_pubkey_get_field(y, key, "y");
1627  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1544
BOTAN_DLL int botan_pubkey_estimated_strength ( botan_pubkey_t  key,
size_t *  estimate 
)

Definition at line 1798 of file ffi.cpp.

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

1799  {
1800  return BOTAN_FFI_DO(Botan::Public_Key, key, k, { *estimate = k.estimated_strength(); });
1801  }
virtual size_t estimated_strength() const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_pubkey_export ( botan_pubkey_t  key,
uint8_t  out[],
size_t *  out_len,
uint32_t  flags 
)

Definition at line 1680 of file ffi.cpp.

References Botan::X509::BER_encode(), BOTAN_FFI_DO, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, and Botan::X509::PEM_encode().

1681  {
1682  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
1684  return write_vec_output(out, out_len, Botan::X509::BER_encode(k));
1686  return write_str_output(out, out_len, Botan::X509::PEM_encode(k));
1687  else
1688  return -2;
1689  });
1690  }
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.cpp:19
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:659
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:658
std::string PEM_encode(const Public_Key &key)
Definition: x509_key.cpp:28
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_pubkey_fingerprint ( botan_pubkey_t  key,
const char *  hash,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 1803 of file ffi.cpp.

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

1805  {
1806  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
1807  std::unique_ptr<Botan::HashFunction> h(Botan::HashFunction::create(hash_fn));
1808  return write_vec_output(out, out_len, h->process(k.public_key_bits()));
1809  });
1810  }
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_pubkey_get_field ( botan_mp_t  output,
botan_pubkey_t  key,
const char *  field_name 
)

Definition at line 1544 of file ffi.cpp.

References BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

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

1547  {
1548  if(field_name_cstr == nullptr)
1550 
1551  const std::string field_name(field_name_cstr);
1552 
1553  return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
1554  safe_get(output) = botan_pubkey_do_get_field(k, field_name);
1555  });
1556  }
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:140
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_pubkey_load ( botan_pubkey_t key,
const uint8_t  bits[],
size_t  len 
)

Definition at line 1302 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and Botan::X509::load_key().

1304  {
1305  *key = nullptr;
1306 
1307  try
1308  {
1309  Botan::DataSource_Memory src(bits, bits_len);
1310  std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src));
1311 
1312  if(pubkey)
1313  {
1314  *key = new botan_pubkey_struct(pubkey.release());
1315  return 0;
1316  }
1317  }
1318  catch(std::exception& e)
1319  {
1320  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
1321  }
1322 
1323  return -1;
1324  }
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:37
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL 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 1398 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

1400  {
1401  *key = nullptr;
1402 
1403 #if defined(BOTAN_HAS_DSA)
1404  try
1405  {
1406  Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
1407  *key = new botan_pubkey_struct(new Botan::DSA_PublicKey(group, safe_get(y)));
1408  return 0;
1409  }
1410  catch(std::exception& exn)
1411  {
1412  log_exception(BOTAN_CURRENT_FUNCTION, exn.what());
1413  }
1414 
1415  return -1;
1416 #else
1417  BOTAN_UNUSED(p);
1418  BOTAN_UNUSED(q);
1419  BOTAN_UNUSED(g);
1420  BOTAN_UNUSED(y);
1422 #endif
1423  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_UNUSED(v)
Definition: assert.h:92
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_pubkey_load_rsa ( botan_pubkey_t key,
botan_mp_t  n,
botan_mp_t  e 
)

Definition at line 1349 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

1351  {
1352  *key = nullptr;
1353 
1354 #if defined(BOTAN_HAS_RSA)
1355  try
1356  {
1357  *key = new botan_pubkey_struct(new Botan::RSA_PublicKey(safe_get(n), safe_get(e)));
1358  return 0;
1359  }
1360  catch(std::exception& exn)
1361  {
1362  log_exception(BOTAN_CURRENT_FUNCTION, exn.what());
1363  }
1364 
1365  return -1;
1366 #else
1368 #endif
1369  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_pubkey_rsa_get_e ( botan_mp_t  e,
botan_pubkey_t  rsa_key 
)

Definition at line 1597 of file ffi.cpp.

References botan_pubkey_get_field().

1598  {
1599  return botan_pubkey_get_field(e, key, "e");
1600  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1544
BOTAN_DLL int botan_pubkey_rsa_get_n ( botan_mp_t  n,
botan_pubkey_t  rsa_key 
)

Definition at line 1602 of file ffi.cpp.

References botan_pubkey_get_field().

1603  {
1604  return botan_pubkey_get_field(n, key, "n");
1605  }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1544
BOTAN_DLL 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 325 of file ffi.cpp.

326  {
327  delete rng;
328  return 0;
329  }
BOTAN_DLL 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 331 of file ffi.cpp.

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

332  {
333  return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.randomize(out, out_len); });
334  }
virtual void randomize(uint8_t output[], size_t length)=0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 289 of file ffi.cpp.

References BOTAN_ASSERT_ARG_NON_NULL, and BOTAN_CURRENT_FUNCTION.

290  {
291  try
292  {
293  BOTAN_ASSERT_ARG_NON_NULL(rng_out);
294 
295  if(rng_type == nullptr || *rng_type == 0)
296  rng_type = "system";
297 
298  const std::string rng_type_s(rng_type);
299 
300  std::unique_ptr<Botan::RandomNumberGenerator> rng;
301 
302  if(rng_type_s == "system")
303  rng.reset(new Botan::System_RNG);
304  else if(rng_type_s == "user")
305  rng.reset(new Botan::AutoSeeded_RNG);
306 
307  if(rng)
308  {
309  *rng_out = new botan_rng_struct(rng.release());
310  return 0;
311  }
312  }
313  catch(std::exception& e)
314  {
315  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
316  }
317  catch(...)
318  {
319  log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
320  }
321 
322  return -1;
323  }
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
#define BOTAN_ASSERT_ARG_NON_NULL(p)
Definition: ffi.cpp:79
BOTAN_DLL 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 336 of file ffi.cpp.

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

337  {
339  }
virtual void reseed_from_rng(RandomNumberGenerator &rng, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS)
Definition: rng.cpp:44
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:196
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_same_mem ( 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 268 of file ffi.cpp.

References Botan::same_mem().

269  {
270  return Botan::same_mem(x, y, len) ? 0 : -1;
271  }
bool same_mem(const T *p1, const T *p2, size_t n)
Definition: mem_ops.h:98
BOTAN_DLL uint32_t botan_version_datestamp ( )

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

Definition at line 266 of file ffi.cpp.

References Botan::version_datestamp().

266 { return Botan::version_datestamp(); }
uint32_t version_datestamp()
Definition: version.cpp:55
BOTAN_DLL uint32_t botan_version_major ( )

Return the major version of the library

Definition at line 263 of file ffi.cpp.

References Botan::version_major().

263 { return Botan::version_major(); }
uint32_t version_major()
Definition: version.cpp:60
BOTAN_DLL uint32_t botan_version_minor ( )

Return the minor version of the library

Definition at line 264 of file ffi.cpp.

References Botan::version_minor().

264 { return Botan::version_minor(); }
uint32_t version_minor()
Definition: version.cpp:61
BOTAN_DLL uint32_t botan_version_patch ( )

Return the patch version of the library

Definition at line 265 of file ffi.cpp.

References Botan::version_patch().

265 { return Botan::version_patch(); }
uint32_t version_patch()
Definition: version.cpp:62
BOTAN_DLL const char* botan_version_string ( )

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

Definition at line 258 of file ffi.cpp.

References Botan::version_cstr().

259  {
260  return Botan::version_cstr();
261  }
const char * version_cstr()
Definition: version.cpp:28
BOTAN_DLL int botan_x509_cert_allowed_usage ( botan_x509_cert_t  cert,
unsigned int  key_usage 
)

Definition at line 2198 of file ffi.cpp.

References BOTAN_FFI_DO.

2199  {
2200  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, {
2201  const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
2202  if(c.allowed_usage(k))
2203  return 0;
2204  return 1;
2205  });
2206  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_x509_cert_destroy ( botan_x509_cert_t  cert)

Definition at line 2106 of file ffi.cpp.

2107  {
2108  delete cert;
2109  return 0;
2110  }
BOTAN_DLL 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_DLL int botan_x509_cert_get_authority_key_id ( botan_x509_cert_t  cert,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 2132 of file ffi.cpp.

References BOTAN_FFI_DO.

2133  {
2134  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.authority_key_id()); });
2135  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_x509_cert_get_fingerprint ( botan_x509_cert_t  cert,
const char *  hash,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 2127 of file ffi.cpp.

References BOTAN_FFI_DO.

2128  {
2129  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.fingerprint(hash)); });
2130  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
MechanismType hash
BOTAN_DLL 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 2179 of file ffi.cpp.

References BOTAN_FFI_DO.

2182  {
2183  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.issuer_info(key).at(index)); });
2184  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_x509_cert_get_public_key ( botan_x509_cert_t  cert,
botan_pubkey_t key 
)

Definition at line 2154 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

2155  {
2156  try
2157  {
2158  if(key == nullptr)
2159  return -1;
2160 
2161  *key = nullptr;
2162 
2163 #if defined(BOTAN_HAS_RSA)
2164  std::unique_ptr<Botan::Public_Key> publicKey(safe_get(cert).subject_public_key());
2165  *key = new botan_pubkey_struct(publicKey.release());
2166  return 0;
2167 #else
2169 #endif
2170  }
2171  catch(std::exception& e)
2172  {
2173  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
2174  }
2175 
2177  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:138
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_x509_cert_get_public_key_bits ( botan_x509_cert_t  cert,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 2142 of file ffi.cpp.

References BOTAN_FFI_DO.

2143  {
2144  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_public_key_bits()); });
2145  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_x509_cert_get_serial_number ( botan_x509_cert_t  cert,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 2122 of file ffi.cpp.

References BOTAN_FFI_DO.

2123  {
2124  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.serial_number()); });
2125  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL 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 2186 of file ffi.cpp.

References BOTAN_FFI_DO.

2189  {
2190  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.subject_info(key).at(index)); });
2191  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_x509_cert_get_subject_key_id ( botan_x509_cert_t  cert,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 2137 of file ffi.cpp.

References BOTAN_FFI_DO.

2138  {
2139  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_key_id()); });
2140  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_x509_cert_get_time_expires ( botan_x509_cert_t  cert,
char  out[],
size_t *  out_len 
)

Definition at line 2117 of file ffi.cpp.

References BOTAN_FFI_DO.

2118  {
2119  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.end_time()); });
2120  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_x509_cert_get_time_starts ( botan_x509_cert_t  cert,
char  out[],
size_t *  out_len 
)

Definition at line 2112 of file ffi.cpp.

References BOTAN_FFI_DO.

2113  {
2114  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.start_time()); });
2115  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
BOTAN_DLL int botan_x509_cert_load ( botan_x509_cert_t cert_obj,
const uint8_t  cert[],
size_t  cert_len 
)

Definition at line 2076 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION.

2077  {
2078  try
2079  {
2080  if(!cert_obj || !cert_bits)
2081  return -1;
2082 
2083  Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
2084 
2085  std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(bits));
2086 
2087  if(c)
2088  {
2089  *cert_obj = new botan_x509_cert_struct(c.release());
2090  return 0;
2091  }
2092  }
2093  catch(std::exception& e)
2094  {
2095  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
2096  }
2097  catch(...)
2098  {
2099  log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
2100  }
2101 
2102  return -2;
2103 
2104  }
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_x509_cert_load_file ( botan_x509_cert_t cert_obj,
const char *  filename 
)

Definition at line 2045 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

2046  {
2047  try
2048  {
2049  if(!cert_obj || !cert_path)
2050  return -1;
2051 
2052 #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
2053  std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(cert_path));
2054 
2055  if(c)
2056  {
2057  *cert_obj = new botan_x509_cert_struct(c.release());
2058  return 0;
2059  }
2060 #else
2062 #endif
2063  }
2064  catch(std::exception& e)
2065  {
2066  log_exception(BOTAN_CURRENT_FUNCTION, e.what());
2067  }
2068  catch(...)
2069  {
2070  log_exception(BOTAN_CURRENT_FUNCTION, "unknown");
2071  }
2072 
2073  return -2;
2074  }
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:105
BOTAN_DLL int botan_x509_cert_path_verify ( botan_x509_cert_t  cert,
const char *  ca_dir 
)
BOTAN_DLL int botan_x509_cert_to_string ( botan_x509_cert_t  cert,
char  out[],
size_t *  out_len 
)

Definition at line 2193 of file ffi.cpp.

References BOTAN_FFI_DO.

2194  {
2195  return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.to_string()); });
2196  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204