Botan 3.0.0-alpha0
Crypto and TLS for C&
Macros | Typedefs | Enumerations | Functions
ffi.h File Reference

Public Header. More...

#include <botan/build.h>
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Macros

#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS   1
 
#define BOTAN_CIPHER_INIT_FLAG_DECRYPT   1
 
#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0
 
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION   1
 
#define BOTAN_CIPHER_UPDATE_FLAG_FINAL   (1U << 0)
 
#define BOTAN_FFI_HEX_LOWER_CASE   1
 
#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE   1
 
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER   0
 
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM   1
 
#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE   1
 

Typedefs

typedef struct botan_block_cipher_struct * botan_block_cipher_t
 
typedef struct botan_cipher_struct * botan_cipher_t
 
typedef struct botan_fpe_struct * botan_fpe_t
 
typedef struct botan_hash_struct * botan_hash_t
 
typedef struct botan_hotp_struct * botan_hotp_t
 
typedef struct botan_mac_struct * botan_mac_t
 
typedef struct botan_mp_struct * botan_mp_t
 
typedef struct botan_pk_op_decrypt_struct * botan_pk_op_decrypt_t
 
typedef struct botan_pk_op_encrypt_struct * botan_pk_op_encrypt_t
 
typedef struct botan_pk_op_ka_struct * botan_pk_op_ka_t
 
typedef struct botan_pk_op_sign_struct * botan_pk_op_sign_t
 
typedef struct botan_pk_op_verify_struct * botan_pk_op_verify_t
 
typedef struct botan_privkey_struct * botan_privkey_t
 
typedef struct botan_pubkey_struct * botan_pubkey_t
 
typedef struct botan_rng_struct * botan_rng_t
 
typedef struct botan_srp6_server_session_struct * botan_srp6_server_session_t
 
typedef struct botan_totp_struct * botan_totp_t
 
typedef struct botan_x509_cert_struct * botan_x509_cert_t
 
typedef struct botan_x509_crl_struct * botan_x509_crl_t
 

Enumerations

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

Functions

int botan_base64_decode (const char *base64_str, size_t in_len, uint8_t *out, size_t *out_len)
 
int botan_base64_encode (const uint8_t *x, size_t len, char *out, size_t *out_len)
 
int botan_bcrypt_generate (uint8_t *out, size_t *out_len, const char *password, botan_rng_t rng, size_t work_factor, uint32_t flags)
 
int botan_bcrypt_is_valid (const char *pass, const char *hash)
 
int botan_block_cipher_block_size (botan_block_cipher_t bc)
 
int botan_block_cipher_clear (botan_block_cipher_t bc)
 
int botan_block_cipher_decrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
 
int botan_block_cipher_destroy (botan_block_cipher_t bc)
 
int botan_block_cipher_encrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
 
int botan_block_cipher_get_keyspec (botan_block_cipher_t cipher, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
 
int botan_block_cipher_init (botan_block_cipher_t *bc, const char *cipher_name)
 
int botan_block_cipher_name (botan_block_cipher_t cipher, char *name, size_t *name_len)
 
int botan_block_cipher_set_key (botan_block_cipher_t bc, const uint8_t key[], size_t len)
 
int botan_cipher_clear (botan_cipher_t hash)
 
int botan_cipher_destroy (botan_cipher_t cipher)
 
int botan_cipher_get_default_nonce_length (botan_cipher_t cipher, size_t *nl)
 
int botan_cipher_get_keyspec (botan_cipher_t, size_t *min_keylen, size_t *max_keylen, size_t *mod_keylen)
 
int botan_cipher_get_tag_length (botan_cipher_t cipher, size_t *tag_size)
 
int botan_cipher_get_update_granularity (botan_cipher_t cipher, size_t *ug)
 
int botan_cipher_init (botan_cipher_t *cipher, const char *name, uint32_t flags)
 
int botan_cipher_name (botan_cipher_t cipher, char *name, size_t *name_len)
 
int botan_cipher_output_length (botan_cipher_t cipher, size_t in_len, size_t *out_len)
 
int botan_cipher_query_keylen (botan_cipher_t, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
 
int botan_cipher_reset (botan_cipher_t cipher)
 
int botan_cipher_set_associated_data (botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
 
int botan_cipher_set_key (botan_cipher_t cipher, const uint8_t *key, size_t key_len)
 
int botan_cipher_start (botan_cipher_t cipher, const uint8_t *nonce, size_t nonce_len)
 
int botan_cipher_update (botan_cipher_t cipher, uint32_t flags, uint8_t output[], size_t output_size, size_t *output_written, const uint8_t input_bytes[], size_t input_size, size_t *input_consumed)
 
int botan_cipher_valid_nonce_length (botan_cipher_t cipher, size_t nl)
 
int botan_constant_time_compare (const uint8_t *x, const uint8_t *y, size_t len)
 
const char * botan_error_description (int err)
 
const char * botan_error_last_exception_message ()
 
uint32_t botan_ffi_api_version (void)
 
int botan_ffi_supports_api (uint32_t api_version)
 
int botan_fpe_decrypt (botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
 
int botan_fpe_destroy (botan_fpe_t fpe)
 
int botan_fpe_encrypt (botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
 
int botan_fpe_fe1_init (botan_fpe_t *fpe, botan_mp_t n, const uint8_t key[], size_t key_len, size_t rounds, uint32_t flags)
 
int botan_generate_srp6_verifier (const char *identifier, const char *password, const uint8_t salt[], size_t salt_len, const char *group_id, const char *hash_id, uint8_t verifier[], size_t *verifier_len)
 
int botan_hash_block_size (botan_hash_t hash, size_t *block_size)
 
int botan_hash_clear (botan_hash_t hash)
 
int botan_hash_copy_state (botan_hash_t *dest, const botan_hash_t source)
 
int botan_hash_destroy (botan_hash_t hash)
 
int botan_hash_final (botan_hash_t hash, uint8_t out[])
 
int botan_hash_init (botan_hash_t *hash, const char *hash_name, uint32_t flags)
 
int botan_hash_name (botan_hash_t hash, char *name, size_t *name_len)
 
int botan_hash_output_length (botan_hash_t hash, size_t *output_length)
 
int botan_hash_update (botan_hash_t hash, const uint8_t *in, size_t in_len)
 
int botan_hex_decode (const char *hex_str, size_t in_len, uint8_t *out, size_t *out_len)
 
int botan_hex_encode (const uint8_t *x, size_t len, char *out, uint32_t flags)
 
int botan_hotp_check (botan_hotp_t hotp, uint64_t *next_hotp_counter, uint32_t hotp_code, uint64_t hotp_counter, size_t resync_range)
 
int botan_hotp_destroy (botan_hotp_t hotp)
 
int botan_hotp_generate (botan_hotp_t hotp, uint32_t *hotp_code, uint64_t hotp_counter)
 
int botan_hotp_init (botan_hotp_t *hotp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits)
 
int botan_kdf (const char *kdf_algo, uint8_t out[], size_t out_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len)
 
int botan_key_unwrap3394 (const uint8_t wrapped_key[], size_t wrapped_key_len, const uint8_t kek[], size_t kek_len, uint8_t key[], size_t *key_len)
 
int botan_key_wrap3394 (const uint8_t key[], size_t key_len, const uint8_t kek[], size_t kek_len, uint8_t wrapped_key[], size_t *wrapped_key_len)
 
int botan_mac_clear (botan_mac_t mac)
 
int botan_mac_destroy (botan_mac_t mac)
 
int botan_mac_final (botan_mac_t mac, uint8_t out[])
 
int botan_mac_get_keyspec (botan_mac_t mac, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
 
int botan_mac_init (botan_mac_t *mac, const char *mac_name, uint32_t flags)
 
int botan_mac_name (botan_mac_t mac, char *name, size_t *name_len)
 
int botan_mac_output_length (botan_mac_t mac, size_t *output_length)
 
int botan_mac_set_key (botan_mac_t mac, const uint8_t *key, size_t key_len)
 
int botan_mac_update (botan_mac_t mac, const uint8_t *buf, size_t len)
 
int botan_mceies_decrypt (botan_privkey_t mce_key, const char *aead, const uint8_t ct[], size_t ct_len, const uint8_t ad[], size_t ad_len, uint8_t pt[], size_t *pt_len)
 
int botan_mceies_encrypt (botan_pubkey_t mce_key, botan_rng_t rng, const char *aead, const uint8_t pt[], size_t pt_len, const uint8_t ad[], size_t ad_len, uint8_t ct[], size_t *ct_len)
 
int botan_mp_add (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
 
int botan_mp_add_u32 (botan_mp_t result, const botan_mp_t x, uint32_t y)
 
int botan_mp_clear (botan_mp_t mp)
 
int botan_mp_clear_bit (botan_mp_t n, size_t bit)
 
int botan_mp_cmp (int *result, const botan_mp_t x, const botan_mp_t y)
 
int botan_mp_destroy (botan_mp_t mp)
 
int botan_mp_div (botan_mp_t quotient, botan_mp_t remainder, const botan_mp_t x, const botan_mp_t y)
 
int botan_mp_equal (const botan_mp_t x, const botan_mp_t y)
 
int botan_mp_flip_sign (botan_mp_t mp)
 
int botan_mp_from_bin (const botan_mp_t mp, const uint8_t vec[], size_t vec_len)
 
int botan_mp_gcd (botan_mp_t out, const botan_mp_t x, const botan_mp_t y)
 
int botan_mp_get_bit (const botan_mp_t n, size_t bit)
 
int botan_mp_init (botan_mp_t *mp)
 
int botan_mp_is_even (const botan_mp_t mp)
 
int botan_mp_is_negative (const botan_mp_t mp)
 
int botan_mp_is_odd (const botan_mp_t mp)
 
int botan_mp_is_positive (const botan_mp_t mp)
 
int botan_mp_is_prime (const botan_mp_t n, botan_rng_t rng, size_t test_prob)
 
int botan_mp_is_zero (const botan_mp_t mp)
 
int botan_mp_lshift (botan_mp_t out, const botan_mp_t in, size_t shift)
 
int botan_mp_mod_inverse (botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus)
 
int botan_mp_mod_mul (botan_mp_t result, const botan_mp_t x, const botan_mp_t y, const botan_mp_t mod)
 
int botan_mp_mul (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
 
int botan_mp_num_bits (const botan_mp_t n, size_t *bits)
 
int botan_mp_num_bytes (const botan_mp_t n, size_t *bytes)
 
int botan_mp_powmod (botan_mp_t out, const botan_mp_t base, const botan_mp_t exponent, const botan_mp_t modulus)
 
int botan_mp_rand_bits (botan_mp_t rand_out, botan_rng_t rng, size_t bits)
 
int botan_mp_rand_range (botan_mp_t rand_out, botan_rng_t rng, const botan_mp_t lower_bound, const botan_mp_t upper_bound)
 
int botan_mp_rshift (botan_mp_t out, const botan_mp_t in, size_t shift)
 
int botan_mp_set_bit (botan_mp_t n, size_t bit)
 
int botan_mp_set_from_int (botan_mp_t mp, int initial_value)
 
int botan_mp_set_from_mp (botan_mp_t dest, const botan_mp_t source)
 
int botan_mp_set_from_radix_str (botan_mp_t dest, const char *str, size_t radix)
 
int botan_mp_set_from_str (botan_mp_t dest, const char *str)
 
int botan_mp_sub (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
 
int botan_mp_sub_u32 (botan_mp_t result, const botan_mp_t x, uint32_t y)
 
int botan_mp_swap (botan_mp_t x, botan_mp_t y)
 
int botan_mp_to_bin (const botan_mp_t mp, uint8_t vec[])
 
int botan_mp_to_hex (const botan_mp_t mp, char *out)
 
int botan_mp_to_str (const botan_mp_t mp, uint8_t base, char *out, size_t *out_len)
 
int botan_mp_to_uint32 (const botan_mp_t mp, uint32_t *val)
 
int botan_pbkdf (const char *pbkdf_algo, uint8_t out[], size_t out_len, const char *passphrase, const uint8_t salt[], size_t salt_len, size_t iterations)
 
int botan_pbkdf_timed (const char *pbkdf_algo, uint8_t out[], size_t out_len, const char *passphrase, const uint8_t salt[], size_t salt_len, size_t milliseconds_to_run, size_t *out_iterations_used)
 
int botan_pk_op_decrypt (botan_pk_op_decrypt_t op, uint8_t out[], size_t *out_len, const uint8_t ciphertext[], size_t ciphertext_len)
 
int botan_pk_op_decrypt_create (botan_pk_op_decrypt_t *op, botan_privkey_t key, const char *padding, uint32_t flags)
 
int botan_pk_op_decrypt_destroy (botan_pk_op_decrypt_t op)
 
int botan_pk_op_decrypt_output_length (botan_pk_op_decrypt_t op, size_t ctext_len, size_t *ptext_len)
 
int botan_pk_op_encrypt (botan_pk_op_encrypt_t op, botan_rng_t rng, uint8_t out[], size_t *out_len, const uint8_t plaintext[], size_t plaintext_len)
 
int botan_pk_op_encrypt_create (botan_pk_op_encrypt_t *op, botan_pubkey_t key, const char *padding, uint32_t flags)
 
int botan_pk_op_encrypt_destroy (botan_pk_op_encrypt_t op)
 
int botan_pk_op_encrypt_output_length (botan_pk_op_encrypt_t op, size_t ptext_len, size_t *ctext_len)
 
int botan_pk_op_key_agreement (botan_pk_op_ka_t op, uint8_t out[], size_t *out_len, const uint8_t other_key[], size_t other_key_len, const uint8_t salt[], size_t salt_len)
 
int botan_pk_op_key_agreement_create (botan_pk_op_ka_t *op, botan_privkey_t key, const char *kdf, uint32_t flags)
 
int botan_pk_op_key_agreement_destroy (botan_pk_op_ka_t op)
 
int botan_pk_op_key_agreement_export_public (botan_privkey_t key, uint8_t out[], size_t *out_len)
 
int botan_pk_op_key_agreement_size (botan_pk_op_ka_t op, size_t *out_len)
 
int botan_pk_op_sign_create (botan_pk_op_sign_t *op, botan_privkey_t key, const char *hash_and_padding, uint32_t flags)
 
int botan_pk_op_sign_destroy (botan_pk_op_sign_t op)
 
int botan_pk_op_sign_finish (botan_pk_op_sign_t op, botan_rng_t rng, uint8_t sig[], size_t *sig_len)
 
int botan_pk_op_sign_output_length (botan_pk_op_sign_t op, size_t *olen)
 
int botan_pk_op_sign_update (botan_pk_op_sign_t op, const uint8_t in[], size_t in_len)
 
int botan_pk_op_verify_create (botan_pk_op_verify_t *op, botan_pubkey_t key, const char *hash_and_padding, uint32_t flags)
 
int botan_pk_op_verify_destroy (botan_pk_op_verify_t op)
 
int botan_pk_op_verify_finish (botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len)
 
int botan_pk_op_verify_update (botan_pk_op_verify_t op, const uint8_t in[], size_t in_len)
 
int botan_pkcs_hash_id (const char *hash_name, uint8_t pkcs_id[], size_t *pkcs_id_len)
 
int botan_privkey_algo_name (botan_privkey_t key, char out[], size_t *out_len)
 
int botan_privkey_check_key (botan_privkey_t key, botan_rng_t rng, uint32_t flags)
 
int botan_privkey_create (botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
 
int botan_privkey_create_dh (botan_privkey_t *key, botan_rng_t rng, const char *param)
 
int botan_privkey_create_dsa (botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
 
int botan_privkey_create_ecdh (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
int botan_privkey_create_ecdsa (botan_privkey_t *key, botan_rng_t rng, const char *params)
 
int botan_privkey_create_elgamal (botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
 
int botan_privkey_create_mceliece (botan_privkey_t *key, botan_rng_t rng, size_t n, size_t t)
 
int botan_privkey_create_rsa (botan_privkey_t *key, botan_rng_t rng, size_t n_bits)
 
int botan_privkey_destroy (botan_privkey_t key)
 
int botan_privkey_dsa_get_x (botan_mp_t n, botan_privkey_t key)
 
int botan_privkey_ed25519_get_privkey (botan_privkey_t key, uint8_t output[64])
 
int botan_privkey_export (botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_privkey_export_encrypted (botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, const char *encryption_algo, uint32_t flags)
 
int botan_privkey_export_encrypted_pbkdf_iter (botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, size_t pbkdf_iterations, const char *cipher_algo, const char *pbkdf_algo, uint32_t flags)
 
int botan_privkey_export_encrypted_pbkdf_msec (botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, uint32_t pbkdf_msec_runtime, size_t *pbkdf_iterations_out, const char *cipher_algo, const char *pbkdf_algo, uint32_t flags)
 
int botan_privkey_export_pubkey (botan_pubkey_t *out, botan_privkey_t in)
 
int botan_privkey_get_field (botan_mp_t output, botan_privkey_t key, const char *field_name)
 
int botan_privkey_load (botan_privkey_t *key, botan_rng_t rng, const uint8_t bits[], size_t len, const char *password)
 
int botan_privkey_load_dh (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
 
int botan_privkey_load_dsa (botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t x)
 
int botan_privkey_load_ecdh (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_ecdsa (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_ed25519 (botan_privkey_t *key, const uint8_t privkey[32])
 
int botan_privkey_load_elgamal (botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
 
int botan_privkey_load_rsa (botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t e)
 
int botan_privkey_load_rsa_pkcs1 (botan_privkey_t *key, const uint8_t bits[], size_t len)
 
int botan_privkey_load_sm2 (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_sm2_enc (botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
 
int botan_privkey_load_x25519 (botan_privkey_t *key, const uint8_t privkey[32])
 
int botan_privkey_rsa_get_d (botan_mp_t d, botan_privkey_t rsa_key)
 
int botan_privkey_rsa_get_e (botan_mp_t e, botan_privkey_t rsa_key)
 
int botan_privkey_rsa_get_n (botan_mp_t n, botan_privkey_t rsa_key)
 
int botan_privkey_rsa_get_p (botan_mp_t p, botan_privkey_t rsa_key)
 
int botan_privkey_rsa_get_privkey (botan_privkey_t rsa_key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_privkey_rsa_get_q (botan_mp_t q, botan_privkey_t rsa_key)
 
int botan_privkey_x25519_get_privkey (botan_privkey_t key, uint8_t output[32])
 
int botan_pubkey_algo_name (botan_pubkey_t key, char out[], size_t *out_len)
 
int botan_pubkey_check_key (botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
 
int botan_pubkey_destroy (botan_pubkey_t key)
 
int botan_pubkey_dsa_get_g (botan_mp_t d, botan_pubkey_t key)
 
int botan_pubkey_dsa_get_p (botan_mp_t p, botan_pubkey_t key)
 
int botan_pubkey_dsa_get_q (botan_mp_t q, botan_pubkey_t key)
 
int botan_pubkey_dsa_get_y (botan_mp_t y, botan_pubkey_t key)
 
int botan_pubkey_ed25519_get_pubkey (botan_pubkey_t key, uint8_t pubkey[32])
 
int botan_pubkey_estimated_strength (botan_pubkey_t key, size_t *estimate)
 
int botan_pubkey_export (botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
 
int botan_pubkey_fingerprint (botan_pubkey_t key, const char *hash, uint8_t out[], size_t *out_len)
 
int botan_pubkey_get_field (botan_mp_t output, botan_pubkey_t key, const char *field_name)
 
int botan_pubkey_load (botan_pubkey_t *key, const uint8_t bits[], size_t len)
 
int botan_pubkey_load_dh (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
 
int botan_pubkey_load_dsa (botan_pubkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t y)
 
int botan_pubkey_load_ecdh (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_ecdsa (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_ed25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
 
int botan_pubkey_load_elgamal (botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
 
int botan_pubkey_load_rsa (botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
 
int botan_pubkey_load_sm2 (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_sm2_enc (botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
 
int botan_pubkey_load_x25519 (botan_pubkey_t *key, const uint8_t pubkey[32])
 
int botan_pubkey_rsa_get_e (botan_mp_t e, botan_pubkey_t rsa_key)
 
int botan_pubkey_rsa_get_n (botan_mp_t n, botan_pubkey_t rsa_key)
 
int botan_pubkey_sm2_compute_za (uint8_t out[], size_t *out_len, const char *ident, const char *hash_algo, const botan_pubkey_t key)
 
int botan_pubkey_x25519_get_pubkey (botan_pubkey_t key, uint8_t pubkey[32])
 
int botan_pwdhash (const char *algo, size_t param1, size_t param2, size_t param3, uint8_t out[], size_t out_len, const char *passphrase, size_t passphrase_len, const uint8_t salt[], size_t salt_len)
 
int botan_pwdhash_timed (const char *algo, uint32_t msec, size_t *param1, size_t *param2, size_t *param3, uint8_t out[], size_t out_len, const char *passphrase, size_t passphrase_len, const uint8_t salt[], size_t salt_len)
 
int botan_rng_add_entropy (botan_rng_t rng, const uint8_t *entropy, size_t entropy_len)
 
int botan_rng_destroy (botan_rng_t rng)
 
int botan_rng_get (botan_rng_t rng, uint8_t *out, size_t out_len)
 
int botan_rng_init (botan_rng_t *rng, const char *rng_type)
 
int botan_rng_init_custom (botan_rng_t *rng_out, const char *rng_name, void *context, int(*get_cb)(void *context, uint8_t *out, size_t out_len), int(*add_entropy_cb)(void *context, const uint8_t input[], size_t length), void(*destroy_cb)(void *context))
 
int botan_rng_reseed (botan_rng_t rng, size_t bits)
 
int botan_rng_reseed_from_rng (botan_rng_t rng, botan_rng_t source_rng, size_t bits)
 
int botan_same_mem (const uint8_t *x, const uint8_t *y, size_t len)
 
int botan_scrub_mem (void *mem, size_t bytes)
 
int botan_scrypt (uint8_t out[], size_t out_len, const char *passphrase, const uint8_t salt[], size_t salt_len, size_t N, size_t r, size_t p)
 
int botan_srp6_client_agree (const char *username, const char *password, const char *group_id, const char *hash_id, const uint8_t salt[], size_t salt_len, const uint8_t B[], size_t B_len, botan_rng_t rng_obj, uint8_t A[], size_t *A_len, uint8_t K[], size_t *K_len)
 
int botan_srp6_server_session_destroy (botan_srp6_server_session_t srp6)
 
int botan_srp6_server_session_init (botan_srp6_server_session_t *srp6)
 
int botan_srp6_server_session_step1 (botan_srp6_server_session_t srp6, const uint8_t verifier[], size_t verifier_len, const char *group_id, const char *hash_id, botan_rng_t rng_obj, uint8_t B_pub[], size_t *B_pub_len)
 
int botan_srp6_server_session_step2 (botan_srp6_server_session_t srp6, const uint8_t A[], size_t A_len, uint8_t key[], size_t *key_len)
 
int botan_totp_check (botan_totp_t totp, uint32_t totp_code, uint64_t timestamp, size_t acceptable_clock_drift)
 
int botan_totp_destroy (botan_totp_t totp)
 
int botan_totp_generate (botan_totp_t totp, uint32_t *totp_code, uint64_t timestamp)
 
int botan_totp_init (botan_totp_t *totp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits, size_t time_step)
 
uint32_t botan_version_datestamp (void)
 
uint32_t botan_version_major (void)
 
uint32_t botan_version_minor (void)
 
uint32_t botan_version_patch (void)
 
const char * botan_version_string (void)
 
int botan_x509_cert_allowed_usage (botan_x509_cert_t cert, unsigned int key_usage)
 
int botan_x509_cert_destroy (botan_x509_cert_t cert)
 
int botan_x509_cert_dup (botan_x509_cert_t *new_cert, botan_x509_cert_t cert)
 
int botan_x509_cert_get_authority_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_fingerprint (botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_issuer_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_public_key (botan_x509_cert_t cert, botan_pubkey_t *key)
 
int botan_x509_cert_get_public_key_bits (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_serial_number (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_subject_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_subject_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
 
int botan_x509_cert_get_time_expires (botan_x509_cert_t cert, char out[], size_t *out_len)
 
int botan_x509_cert_get_time_starts (botan_x509_cert_t cert, char out[], size_t *out_len)
 
int botan_x509_cert_hostname_match (botan_x509_cert_t cert, const char *hostname)
 
int botan_x509_cert_load (botan_x509_cert_t *cert_obj, const uint8_t cert[], size_t cert_len)
 
int botan_x509_cert_load_file (botan_x509_cert_t *cert_obj, const char *filename)
 
int botan_x509_cert_not_after (botan_x509_cert_t cert, uint64_t *time_since_epoch)
 
int botan_x509_cert_not_before (botan_x509_cert_t cert, uint64_t *time_since_epoch)
 
int botan_x509_cert_to_string (botan_x509_cert_t cert, char out[], size_t *out_len)
 
const char * botan_x509_cert_validation_status (int code)
 
int botan_x509_cert_verify (int *validation_result, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const char *trusted_path, size_t required_strength, const char *hostname, uint64_t reference_time)
 
int botan_x509_cert_verify_with_crl (int *validation_result, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const botan_x509_crl_t *crls, size_t crls_len, const char *trusted_path, size_t required_strength, const char *hostname, uint64_t reference_time)
 
int botan_x509_crl_destroy (botan_x509_crl_t crl)
 
int botan_x509_crl_load (botan_x509_crl_t *crl_obj, const uint8_t crl_bits[], size_t crl_bits_len)
 
int botan_x509_crl_load_file (botan_x509_crl_t *crl_obj, const char *crl_path)
 
int botan_x509_is_revoked (botan_x509_crl_t crl, botan_x509_cert_t cert)
 

Detailed Description

Public Header.

Definition in file ffi.h.

Macro Definition Documentation

◆ BOTAN_CHECK_KEY_EXPENSIVE_TESTS

#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS   1

Definition at line 991 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_DECRYPT

#define BOTAN_CIPHER_INIT_FLAG_DECRYPT   1

Definition at line 451 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_ENCRYPT

#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT   0

Definition at line 450 of file ffi.h.

◆ BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION

#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION   1

Definition at line 449 of file ffi.h.

◆ BOTAN_CIPHER_UPDATE_FLAG_FINAL

#define BOTAN_CIPHER_UPDATE_FLAG_FINAL   (1U << 0)

Definition at line 532 of file ffi.h.

◆ BOTAN_FFI_HEX_LOWER_CASE

#define BOTAN_FFI_HEX_LOWER_CASE   1

Definition at line 163 of file ffi.h.

◆ BOTAN_FPE_FLAG_FE1_COMPAT_MODE

#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE   1

Definition at line 1766 of file ffi.h.

◆ BOTAN_PRIVKEY_EXPORT_FLAG_DER

#define BOTAN_PRIVKEY_EXPORT_FLAG_DER   0

Definition at line 1070 of file ffi.h.

◆ BOTAN_PRIVKEY_EXPORT_FLAG_PEM

#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM   1

Definition at line 1071 of file ffi.h.

◆ BOTAN_PUBKEY_DER_FORMAT_SIGNATURE

#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE   1

Definition at line 1435 of file ffi.h.

Typedef Documentation

◆ botan_block_cipher_t

typedef struct botan_block_cipher_struct* botan_block_cipher_t

Definition at line 702 of file ffi.h.

◆ botan_cipher_t

typedef struct botan_cipher_struct* botan_cipher_t

Definition at line 447 of file ffi.h.

◆ botan_fpe_t

typedef struct botan_fpe_struct* botan_fpe_t

Format Preserving Encryption

Definition at line 1764 of file ffi.h.

◆ botan_hash_t

typedef struct botan_hash_struct* botan_hash_t

Definition at line 281 of file ffi.h.

◆ botan_hotp_t

typedef struct botan_hotp_struct* botan_hotp_t

HOTP

Definition at line 1674 of file ffi.h.

◆ botan_mac_t

typedef struct botan_mac_struct* botan_mac_t

Definition at line 361 of file ffi.h.

◆ botan_mp_t

typedef struct botan_mp_struct* botan_mp_t

Definition at line 775 of file ffi.h.

◆ botan_pk_op_decrypt_t

typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t

Definition at line 1411 of file ffi.h.

◆ botan_pk_op_encrypt_t

typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t

Definition at line 1385 of file ffi.h.

◆ botan_pk_op_ka_t

typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t

Definition at line 1480 of file ffi.h.

◆ botan_pk_op_sign_t

typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t

Definition at line 1437 of file ffi.h.

◆ botan_pk_op_verify_t

typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t

Definition at line 1461 of file ffi.h.

◆ botan_privkey_t

typedef struct botan_privkey_struct* botan_privkey_t

Definition at line 976 of file ffi.h.

◆ botan_pubkey_t

typedef struct botan_pubkey_struct* botan_pubkey_t

Definition at line 1123 of file ffi.h.

◆ botan_rng_t

typedef struct botan_rng_struct* botan_rng_t

RNG type

Definition at line 200 of file ffi.h.

◆ botan_srp6_server_session_t

typedef struct botan_srp6_server_session_struct* botan_srp6_server_session_t

SRP-6 Server Session type

Definition at line 1788 of file ffi.h.

◆ botan_totp_t

typedef struct botan_totp_struct* botan_totp_t

TOTP

Definition at line 1715 of file ffi.h.

◆ botan_x509_cert_t

typedef struct botan_x509_cert_struct* botan_x509_cert_t

Definition at line 1532 of file ffi.h.

◆ botan_x509_crl_t

typedef struct botan_x509_crl_struct* botan_x509_crl_t

Definition at line 1626 of file ffi.h.

Enumeration Type Documentation

◆ BOTAN_FFI_ERROR

Error codes

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

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

Definition at line 62 of file ffi.h.

62 {
65
68
70
75
82
85
89
91};
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:83
@ BOTAN_FFI_ERROR_INVALID_KEY_LENGTH
Definition: ffi.h:80
@ BOTAN_FFI_ERROR_KEY_NOT_SET
Definition: ffi.h:79
@ BOTAN_FFI_ERROR_TLS_ERROR
Definition: ffi.h:86
@ BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition: ffi.h:71
@ BOTAN_FFI_ERROR_OUT_OF_MEMORY
Definition: ffi.h:72
@ BOTAN_FFI_ERROR_INTERNAL_ERROR
Definition: ffi.h:74
@ BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:64
@ BOTAN_FFI_ERROR_INVALID_OBJECT
Definition: ffi.h:84
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition: ffi.h:90
@ BOTAN_FFI_ERROR_HTTP_ERROR
Definition: ffi.h:87
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:76
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition: ffi.h:66
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:77
@ BOTAN_FFI_SUCCESS
Definition: ffi.h:63
@ BOTAN_FFI_ERROR_SYSTEM_ERROR
Definition: ffi.h:73
@ BOTAN_FFI_ERROR_ROUGHTIME_ERROR
Definition: ffi.h:88
@ BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
Definition: ffi.h:81
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition: ffi.h:69
@ BOTAN_FFI_ERROR_BAD_MAC
Definition: ffi.h:67
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:78

◆ botan_x509_cert_key_constraints

Enumerator
NO_CONSTRAINTS 
DIGITAL_SIGNATURE 
NON_REPUDIATION 
KEY_ENCIPHERMENT 
DATA_ENCIPHERMENT 
KEY_AGREEMENT 
KEY_CERT_SIGN 
CRL_SIGN 
ENCIPHER_ONLY 
DECIPHER_ONLY 

Definition at line 1575 of file ffi.h.

1575 {
1576 NO_CONSTRAINTS = 0,
1577 DIGITAL_SIGNATURE = 32768,
1578 NON_REPUDIATION = 16384,
1579 KEY_ENCIPHERMENT = 8192,
1580 DATA_ENCIPHERMENT = 4096,
1581 KEY_AGREEMENT = 2048,
1582 KEY_CERT_SIGN = 1024,
1583 CRL_SIGN = 512,
1584 ENCIPHER_ONLY = 256,
1585 DECIPHER_ONLY = 128
1586};
@ KEY_ENCIPHERMENT
Definition: ffi.h:1579
@ NO_CONSTRAINTS
Definition: ffi.h:1576
@ CRL_SIGN
Definition: ffi.h:1583
@ DIGITAL_SIGNATURE
Definition: ffi.h:1577
@ KEY_AGREEMENT
Definition: ffi.h:1581
@ DATA_ENCIPHERMENT
Definition: ffi.h:1580
@ KEY_CERT_SIGN
Definition: ffi.h:1582
@ ENCIPHER_ONLY
Definition: ffi.h:1584
@ NON_REPUDIATION
Definition: ffi.h:1578
@ DECIPHER_ONLY
Definition: ffi.h:1585

Function Documentation

◆ botan_base64_decode()

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

Perform base64 decoding

Definition at line 296 of file ffi.cpp.

298 {
299 return ffi_guard_thunk(__func__, [=]() -> int {
300 if(*out_len < Botan::base64_decode_max_output(in_len))
301 {
302 *out_len = Botan::base64_decode_max_output(in_len);
304 }
305
306 *out_len = Botan::base64_decode(out, std::string(base64_str, in_len));
307 return BOTAN_FFI_SUCCESS;
308 });
309 }
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition: ffi.cpp:92
size_t base64_decode(uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
Definition: base64.cpp:200
size_t base64_decode_max_output(size_t input_length)
Definition: base64.cpp:243

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

◆ botan_base64_encode()

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

Perform base64 encoding

Definition at line 288 of file ffi.cpp.

289 {
290 return ffi_guard_thunk(__func__, [=]() -> int {
291 const std::string base64 = Botan::base64_encode(in, len);
292 return Botan_FFI::write_str_output(out, out_len, base64);
293 });
294 }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:157
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition: base64.cpp:185

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

◆ botan_bcrypt_generate()

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

Create a password hash using Bcrypt

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

Output is formatted bcrypt $2a$...

Definition at line 152 of file ffi_kdf.cpp.

156 {
157#if defined(BOTAN_HAS_BCRYPT)
158 return ffi_guard_thunk(__func__, [=]() -> int {
159 if(out == nullptr || out_len == nullptr || pass == nullptr)
161
162 if(flags != 0)
164
165 if(wf < 4 || wf > 18)
167
169 const std::string bcrypt = Botan::generate_bcrypt(pass, rng, static_cast<uint16_t>(wf));
170 return write_str_output(out, out_len, bcrypt);
171 });
172#else
174#endif
175 }
Flags flags(Flag flags)
Definition: p11.h:860
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:65
std::string generate_bcrypt(const std::string &pass, RandomNumberGenerator &rng, uint16_t work_factor, char version)
Definition: bcrypt.cpp:144

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

◆ botan_bcrypt_is_valid()

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

Check a previously created password hash

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

Definition at line 177 of file ffi_kdf.cpp.

178 {
179#if defined(BOTAN_HAS_BCRYPT)
180 return ffi_guard_thunk(__func__, [=]() -> int {
182 });
183#else
185#endif
186 }
bool check_bcrypt(const std::string &pass, const std::string &hash)
Definition: bcrypt.cpp:162
MechanismType hash

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

◆ botan_block_cipher_block_size()

int botan_block_cipher_block_size ( botan_block_cipher_t  bc)

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

Definition at line 62 of file ffi_block.cpp.

63 {
65 { return static_cast<int>(b.block_size()); });
66 }
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:105
PolynomialVector b
Definition: kyber.cpp:821

References b, and BOTAN_FFI_RETURNING.

◆ botan_block_cipher_clear()

int botan_block_cipher_clear ( botan_block_cipher_t  bc)

Reinitializes the block cipher

Returns
0 on success, a negative value on failure

Definition at line 42 of file ffi_block.cpp.

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

References b, and BOTAN_FFI_DO.

◆ botan_block_cipher_decrypt_blocks()

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

Decrypt one or more blocks with the cipher

Definition at line 78 of file ffi_block.cpp.

82 {
83 if(in == nullptr || out == nullptr)
85 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.decrypt_n(in, out, blocks); });
86 }

References b, BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

◆ botan_block_cipher_destroy()

int botan_block_cipher_destroy ( botan_block_cipher_t  bc)

Destroy a block cipher object

Returns
0 if success, error if invalid object handle

Destroy a block cipher object

Definition at line 37 of file ffi_block.cpp.

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

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_block_cipher_encrypt_blocks()

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

Encrypt one or more blocks with the cipher

Definition at line 68 of file ffi_block.cpp.

72 {
73 if(in == nullptr || out == nullptr)
75 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.encrypt_n(in, out, blocks); });
76 }

References b, BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

◆ botan_block_cipher_get_keyspec()

int botan_block_cipher_get_keyspec ( botan_block_cipher_t  cipher,
size_t *  out_minimum_keylength,
size_t *  out_maximum_keylength,
size_t *  out_keylength_modulo 
)

Get the key length limits of this block cipher

Parameters
cipherthe object to read
out_minimum_keylengthif non-NULL, will be set to minimum keylength of cipher
out_maximum_keylengthif non-NULL, will be set to maximum keylength of cipher
out_keylength_moduloif non-NULL will be set to byte multiple of valid keys

Definition at line 97 of file ffi_block.cpp.

101 {
102 return BOTAN_FFI_DO(Botan::BlockCipher, cipher, bc, {
103 if(out_minimum_keylength)
104 *out_minimum_keylength = bc.minimum_keylength();
105 if(out_maximum_keylength)
106 *out_maximum_keylength = bc.maximum_keylength();
107 if(out_keylength_modulo)
108 *out_keylength_modulo = bc.key_spec().keylength_multiple();
109 });
110 }
size_t minimum_keylength() const
Definition: sym_algo.h:128

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

◆ botan_block_cipher_init()

int botan_block_cipher_init ( botan_block_cipher_t bc,
const char *  cipher_name 
)

Initialize a block cipher object

Definition at line 17 of file ffi_block.cpp.

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(bc == nullptr || bc_name == nullptr || *bc_name == 0)
22
23 *bc = nullptr;
24
25 auto cipher = Botan::BlockCipher::create(bc_name);
26 if(cipher == nullptr)
28
29 *bc = new botan_block_cipher_struct(std::move(cipher));
30 return BOTAN_FFI_SUCCESS;
31 });
32 }
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")

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

◆ botan_block_cipher_name()

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

Get the name of this block cipher

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

Definition at line 88 of file ffi_block.cpp.

89 {
90 if(name_len == nullptr)
92
93 return BOTAN_FFI_DO(Botan::BlockCipher, cipher, bc, {
94 return write_str_output(name, name_len, bc.name()); });
95 }
std::string name

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

◆ botan_block_cipher_set_key()

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

Set the key for a block cipher instance

Definition at line 50 of file ffi_block.cpp.

52 {
53 if(key == nullptr)
55 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.set_key(key, len); });
56 }

References b, BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

◆ botan_cipher_clear()

int botan_cipher_clear ( botan_cipher_t  hash)

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

Definition at line 40 of file ffi_cipher.cpp.

41 {
42 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { c.clear(); });
43 }
virtual void clear()=0

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

◆ botan_cipher_destroy()

int botan_cipher_destroy ( botan_cipher_t  cipher)

Destroy the cipher object

Returns
0 if success, error if invalid object handle

Definition at line 35 of file ffi_cipher.cpp.

36 {
37 return BOTAN_FFI_CHECKED_DELETE(cipher);
38 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_cipher_get_default_nonce_length()

int botan_cipher_get_default_nonce_length ( botan_cipher_t  cipher,
size_t *  nl 
)

Get the default nonce length of this cipher

Definition at line 213 of file ffi_cipher.cpp.

214 {
215 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *nl = c.default_nonce_length(); });
216 }
virtual size_t default_nonce_length() const =0

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

◆ botan_cipher_get_keyspec()

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

Get information about the supported key lengths.

Definition at line 68 of file ffi_cipher.cpp.

72 {
73 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
74 if(out_minimum_keylength)
75 *out_minimum_keylength = c.key_spec().minimum_keylength();
76 if(out_maximum_keylength)
77 *out_maximum_keylength = c.key_spec().maximum_keylength();
78 if(out_keylength_modulo)
79 *out_keylength_modulo = c.key_spec().keylength_multiple();
80 });
81 }
size_t minimum_keylength() const
Definition: sym_algo.h:62
virtual Key_Length_Specification key_spec() const =0

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

◆ botan_cipher_get_tag_length()

int botan_cipher_get_tag_length ( botan_cipher_t  cipher,
size_t *  tag_size 
)

Get the tag length of the cipher (0 for non-AEAD modes)

Definition at line 223 of file ffi_cipher.cpp.

224 {
225 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *tl = c.tag_size(); });
226 }
virtual size_t tag_size() const
Definition: cipher_mode.h:174

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

◆ botan_cipher_get_update_granularity()

int botan_cipher_get_update_granularity ( botan_cipher_t  cipher,
size_t *  ug 
)

Return the update granularity of the cipher; botan_cipher_update must be called with blocks of this size, except for the final.

Definition at line 218 of file ffi_cipher.cpp.

219 {
220 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *ug = c.update_granularity(); });
221 }
virtual size_t update_granularity() const =0

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

◆ botan_cipher_init()

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

Initialize a cipher object

Definition at line 22 of file ffi_cipher.cpp.

23 {
24 return ffi_guard_thunk(__func__, [=]() -> int {
27 std::unique_ptr<Botan::Cipher_Mode> mode(Botan::Cipher_Mode::create(cipher_name, dir));
28 if(!mode)
30 *cipher = new botan_cipher_struct(std::move(mode));
31 return BOTAN_FFI_SUCCESS;
32 });
33 }
static std::unique_ptr< Cipher_Mode > create(const std::string &algo, Cipher_Dir direction, const std::string &provider="")
Definition: cipher_mode.cpp:50
#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT
Definition: ffi.h:450
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
Definition: ffi.h:449
Cipher_Dir
Definition: cipher_mode.h:23
@ DECRYPTION
Definition: cipher_mode.h:23
@ ENCRYPTION
Definition: cipher_mode.h:23

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

◆ botan_cipher_name()

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

Return the name of the cipher object

Definition at line 228 of file ffi_cipher.cpp.

229 {
230 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
231 return write_str_output(name, name_len, c.name()); });
232 }

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

◆ botan_cipher_output_length()

int botan_cipher_output_length ( botan_cipher_t  cipher,
size_t  in_len,
size_t *  out_len 
)

Return the output length of this cipher, for a particular input length.

Definition at line 50 of file ffi_cipher.cpp.

51 {
52 if(out_len == nullptr)
54
55 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *out_len = c.output_length(in_len); });
56 }
virtual size_t output_length(size_t input_length) const =0

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

◆ botan_cipher_query_keylen()

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

Get information about the key lengths. Prefer botan_cipher_get_keyspec

Definition at line 58 of file ffi_cipher.cpp.

61 {
62 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
63 *out_minimum_keylength = c.key_spec().minimum_keylength();
64 *out_maximum_keylength = c.key_spec().maximum_keylength();
65 });
66 }

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

◆ botan_cipher_reset()

int botan_cipher_reset ( botan_cipher_t  cipher)

Reset the message specific state for this cipher. Without resetting the keys, this resets the nonce, and any state associated with any message bits that have been processed so far.

It is conceptually equivalent to calling botan_cipher_clear followed by botan_cipher_set_key with the original key.

Definition at line 45 of file ffi_cipher.cpp.

46 {
47 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { c.reset(); });
48 }
virtual void reset()=0

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

◆ botan_cipher_set_associated_data()

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

Set the associated data. Will fail if cipher is not an AEAD

Definition at line 192 of file ffi_cipher.cpp.

195 {
196 return BOTAN_FFI_RETURNING(Botan::Cipher_Mode, cipher, c, {
197 if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(&c))
198 {
199 aead->set_associated_data(ad, ad_len);
200 return BOTAN_FFI_SUCCESS;
201 }
203 });
204 }

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_RETURNING, and BOTAN_FFI_SUCCESS.

◆ botan_cipher_set_key()

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

Set the key for this cipher object

Definition at line 83 of file ffi_cipher.cpp.

85 {
86 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { c.set_key(key, key_len); });
87 }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:147

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

◆ botan_cipher_start()

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

Begin processing a new message using the provided nonce

Definition at line 89 of file ffi_cipher.cpp.

91 {
92 return ffi_guard_thunk(__func__, [=]() -> int {
93 Botan::Cipher_Mode& cipher = safe_get(cipher_obj);
94 cipher.start(nonce, nonce_len);
95 cipher_obj->m_buf.reserve(cipher.update_granularity());
96 return BOTAN_FFI_SUCCESS;
97 });
98 }
void start(const std::vector< uint8_t, Alloc > &nonce)
Definition: cipher_mode.h:69

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

◆ botan_cipher_update()

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

Encrypt some data

Definition at line 100 of file ffi_cipher.cpp.

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

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

◆ botan_cipher_valid_nonce_length()

int botan_cipher_valid_nonce_length ( botan_cipher_t  cipher,
size_t  nl 
)

Return if the specified nonce length is valid for this cipher

Definition at line 206 of file ffi_cipher.cpp.

207 {
208 return BOTAN_FFI_RETURNING(Botan::Cipher_Mode, cipher, c, {
209 return c.valid_nonce_length(nl) ? 1 : 0;
210 });
211 }
virtual bool valid_nonce_length(size_t nonce_len) const =0

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

◆ botan_constant_time_compare()

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

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

Definition at line 255 of file ffi.cpp.

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

References Botan::constant_time_compare().

Referenced by botan_same_mem().

◆ botan_error_description()

const char * botan_error_description ( int  err)

Convert an error code into a string. Returns "Unknown error" if the error code is not a known one.

Definition at line 135 of file ffi.cpp.

136 {
137 switch(err)
138 {
140 return "OK";
141
143 return "Invalid verifier";
144
146 return "Invalid input";
147
149 return "Invalid authentication code";
150
152 return "Insufficient buffer space";
153
155 return "Exception thrown";
156
158 return "Out of memory";
159
161 return "Error while calling system API";
162
164 return "Internal error";
165
167 return "Bad flag";
168
170 return "Null pointer argument";
171
173 return "Bad parameter";
174
176 return "Key not set on object";
177
179 return "Invalid key length";
180
182 return "Invalid object state";
183
185 return "Not implemented";
186
188 return "Invalid object handle";
189
191 return "TLS error";
192
194 return "HTTP error";
195
197 return "Unknown error";
198 }
199
200 return "Unknown error";
201 }

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

◆ botan_error_last_exception_message()

const char * botan_error_last_exception_message ( )

Return the message of the last exception caught in this thread.

This pointer can/will be reallocated or overwritten the next time this thread calls any other Botan FFI function and must be copied to persistent storage first.

Definition at line 130 of file ffi.cpp.

131 {
132 return g_last_exception_what.c_str();
133 }
thread_local std::string g_last_exception_what
Definition: ffi.cpp:19

References Botan_FFI::g_last_exception_what.

◆ botan_ffi_api_version()

uint32_t botan_ffi_api_version ( void  )

Return the version of the currently supported FFI API. This is expressed in the form YYYYMMDD of the release date of this version of the API.

Definition at line 206 of file ffi.cpp.

207 {
208 return BOTAN_HAS_FFI;
209 }
#define BOTAN_HAS_FFI
Definition: build.h:206

References BOTAN_HAS_FFI.

◆ botan_ffi_supports_api()

int botan_ffi_supports_api ( uint32_t  api_version)

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

Definition at line 211 of file ffi.cpp.

212 {
213 // This is the API introduced in 3.0
214 if(api_version == 20210628)
215 return BOTAN_FFI_SUCCESS;
216
217 // This is the API introduced in 2.18
218 if(api_version == 20210220)
219 return BOTAN_FFI_SUCCESS;
220
221 // This is the API introduced in 2.13
222 if(api_version == 20191214)
223 return BOTAN_FFI_SUCCESS;
224
225 // This is the API introduced in 2.8
226 if(api_version == 20180713)
227 return BOTAN_FFI_SUCCESS;
228
229 // This is the API introduced in 2.3
230 if(api_version == 20170815)
231 return BOTAN_FFI_SUCCESS;
232
233 // This is the API introduced in 2.1
234 if(api_version == 20170327)
235 return BOTAN_FFI_SUCCESS;
236
237 // This is the API introduced in 2.0
238 if(api_version == 20150515)
239 return BOTAN_FFI_SUCCESS;
240
241 // Something else:
242 return -1;
243 }

References BOTAN_FFI_SUCCESS.

◆ botan_fpe_decrypt()

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

Definition at line 80 of file ffi_fpe.cpp.

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

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

◆ botan_fpe_destroy()

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

Definition at line 58 of file ffi_fpe.cpp.

59 {
60#if defined(BOTAN_HAS_FPE_FE1)
61 return BOTAN_FFI_CHECKED_DELETE(fpe);
62#else
64#endif
65 }

References BOTAN_FFI_CHECKED_DELETE, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

◆ botan_fpe_encrypt()

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

Definition at line 67 of file ffi_fpe.cpp.

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

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

◆ botan_fpe_fe1_init()

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

Definition at line 26 of file ffi_fpe.cpp.

29 {
30#if defined(BOTAN_HAS_FPE_FE1)
31
32 return ffi_guard_thunk(__func__, [=]() {
33
34 if(fpe == nullptr || key == nullptr)
36
37 *fpe = nullptr;
38
41
42 const bool compat_mode = (flags & BOTAN_FPE_FLAG_FE1_COMPAT_MODE);
43
44 std::unique_ptr<Botan::FPE_FE1> fpe_obj(
45 new Botan::FPE_FE1(safe_get(n), rounds, compat_mode));
46
47 fpe_obj->set_key(key, key_len);
48
49 *fpe = new botan_fpe_struct(std::move(fpe_obj));
50 return BOTAN_FFI_SUCCESS;
51 });
52#else
53 *fpe = nullptr;
55#endif
56 }
#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE
Definition: ffi.h:1766

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

◆ botan_generate_srp6_verifier()

int botan_generate_srp6_verifier ( const char *  identifier,
const char *  password,
const uint8_t  salt[],
size_t  salt_len,
const char *  group_id,
const char *  hash_id,
uint8_t  verifier[],
size_t *  verifier_len 
)

Generate a new SRP-6 verifier

Parameters
identifiera username or other client identifier
passwordthe secret used to authenticate user
salta randomly chosen value, at least 128 bits long
group_idspecifies the shared SRP group
hash_idspecifies a secure hash function
verifierout buffer to store the SRP-6 verifier value
verifier_lenSRP-6 verifier value length
Returns
0 on success, negative on failure

Definition at line 91 of file ffi_srp6.cpp.

95 {
96 return ffi_guard_thunk(__func__, [=]() -> int
97 {
98 if(!username || !password || !salt || !group_id || !hash_id)
99 {
101 }
102 try
103 {
104 std::vector<uint8_t> salt_vec(salt, salt + salt_len);
105 auto verifier_bn = Botan::generate_srp6_verifier(
106 username, password, salt_vec, group_id, hash_id);
107 return write_vec_output(verifier, verifier_len,
108 Botan::BigInt::encode(verifier_bn));
109 }
110 catch(Botan::Lookup_Error&)
111 {
113 }
114 });
115 }
static std::vector< uint8_t > encode(const BigInt &n)
Definition: bigint.h:765
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:152
BigInt generate_srp6_verifier(const std::string &identifier, const std::string &password, const std::vector< uint8_t > &salt, const std::string &group_id, const std::string &hash_id)
Definition: srp6.cpp:129
size_t salt_len
Definition: x509_obj.cpp:25

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NULL_POINTER, Botan::BigInt::encode(), Botan_FFI::ffi_guard_thunk(), Botan::generate_srp6_verifier(), salt_len, and Botan_FFI::write_vec_output().

◆ botan_hash_block_size()

int botan_hash_block_size ( botan_hash_t  hash,
size_t *  block_size 
)

Writes the block size of the hash function to *block_size

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

Definition at line 46 of file ffi_hash.cpp.

47 {
48 if(out == nullptr)
50 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { *out = h.hash_block_size(); });
51 }

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and hash.

◆ botan_hash_clear()

int botan_hash_clear ( botan_hash_t  hash)

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

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

Definition at line 53 of file ffi_hash.cpp.

54 {
55 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.clear(); });
56 }

References BOTAN_FFI_DO, and hash.

◆ botan_hash_copy_state()

int botan_hash_copy_state ( botan_hash_t dest,
const botan_hash_t  source 
)

Copy the state of a hash function object

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

Definition at line 76 of file ffi_hash.cpp.

77 {
78 return BOTAN_FFI_DO(Botan::HashFunction, source, src, {
79 *dest = new botan_hash_struct(src.copy_state()); });
80 }

References BOTAN_FFI_DO.

◆ botan_hash_destroy()

int botan_hash_destroy ( botan_hash_t  hash)

Frees all resources of the hash object

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

Definition at line 34 of file ffi_hash.cpp.

35 {
37 }

References BOTAN_FFI_CHECKED_DELETE, and hash.

◆ botan_hash_final()

int botan_hash_final ( botan_hash_t  hash,
uint8_t  out[] 
)

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

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

Definition at line 69 of file ffi_hash.cpp.

70 {
71 if(out == nullptr)
73 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.final(out); });
74 }

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and hash.

◆ botan_hash_init()

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

Initialize a hash function object

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

Definition at line 17 of file ffi_hash.cpp.

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(hash == nullptr || hash_name == nullptr || *hash_name == 0)
22 if(flags != 0)
24
25 auto h = Botan::HashFunction::create(hash_name);
26 if(h == nullptr)
28
29 *hash = new botan_hash_struct(std::move(h));
30 return BOTAN_FFI_SUCCESS;
31 });
32 }
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:98

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

◆ botan_hash_name()

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

Get the name of this hash function

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

Definition at line 82 of file ffi_hash.cpp.

83 {
84 if(name_len == nullptr)
86
88 return write_str_output(name, name_len, h.name()); });
89 }

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

◆ botan_hash_output_length()

int botan_hash_output_length ( botan_hash_t  hash,
size_t *  output_length 
)

Writes the output length of the hash function to *output_length

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

Definition at line 39 of file ffi_hash.cpp.

40 {
41 if(out == nullptr)
43 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { *out = h.output_length(); });
44 }

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and hash.

◆ botan_hash_update()

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

Send more input to the hash function

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

Definition at line 58 of file ffi_hash.cpp.

59 {
60 if(len == 0)
61 return 0;
62
63 if(buf == nullptr)
65
66 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.update(buf, len); });
67 }

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and hash.

◆ botan_hex_decode()

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

Perform hex decoding

Parameters
hex_stra string of hex chars (whitespace is ignored)
in_lenthe length of hex_str
outthe output buffer should be at least strlen(hex_str)/2 bytes
out_lenthe size of the output buffer on input, set to the number of bytes written
Returns
0 on success, a negative value on failure

Definition at line 280 of file ffi.cpp.

281 {
282 return ffi_guard_thunk(__func__, [=]() -> int {
283 const std::vector<uint8_t> bin = Botan::hex_decode(hex_str, in_len);
284 return Botan_FFI::write_vec_output(out, out_len, bin);
285 });
286 }
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition: hex.cpp:89

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

◆ botan_hex_encode()

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

Perform hex encoding

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

Definition at line 271 of file ffi.cpp.

272 {
273 return ffi_guard_thunk(__func__, [=]() -> int {
274 const bool uppercase = (flags & BOTAN_FFI_HEX_LOWER_CASE) == 0;
275 Botan::hex_encode(out, in, len, uppercase);
276 return BOTAN_FFI_SUCCESS;
277 });
278 }
#define BOTAN_FFI_HEX_LOWER_CASE
Definition: ffi.h:163
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:31

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

◆ botan_hotp_check()

int botan_hotp_check ( botan_hotp_t  hotp,
uint64_t *  next_hotp_counter,
uint32_t  hotp_code,
uint64_t  hotp_counter,
size_t  resync_range 
)

Verify a HOTP code

Definition at line 76 of file ffi_hotp.cpp.

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

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

◆ botan_hotp_destroy()

int botan_hotp_destroy ( botan_hotp_t  hotp)

Destroy a HOTP instance

Returns
0 if success, error if invalid object handle

Definition at line 48 of file ffi_hotp.cpp.

49 {
50#if defined(BOTAN_HAS_HOTP)
51 return BOTAN_FFI_CHECKED_DELETE(hotp);
52#else
53 BOTAN_UNUSED(hotp);
55#endif
56 }

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_hotp_generate()

int botan_hotp_generate ( botan_hotp_t  hotp,
uint32_t *  hotp_code,
uint64_t  hotp_counter 
)

Generate a HOTP code for the provided counter

Definition at line 58 of file ffi_hotp.cpp.

61 {
62#if defined(BOTAN_HAS_HOTP)
63 if(hotp == nullptr || hotp_code == nullptr)
65
66 return BOTAN_FFI_DO(Botan::HOTP, hotp, h, {
67 *hotp_code = h.generate_hotp(hotp_counter);
68 });
69
70#else
71 BOTAN_UNUSED(hotp, hotp_code, hotp_counter);
73#endif
74 }
uint32_t generate_hotp(uint64_t counter)
Definition: hotp.cpp:42

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

◆ botan_hotp_init()

int botan_hotp_init ( botan_hotp_t hotp,
const uint8_t  key[],
size_t  key_len,
const char *  hash_algo,
size_t  digits 
)

Initialize a HOTP instance

Definition at line 24 of file ffi_hotp.cpp.

28 {
29 if(hotp == nullptr || key == nullptr || hash_algo == nullptr)
31
32 *hotp = nullptr;
33
34#if defined(BOTAN_HAS_HOTP)
35 return ffi_guard_thunk(__func__, [=]() -> int {
36
37 auto otp = std::make_unique<Botan::HOTP>(key, key_len, hash_algo, digits);
38 *hotp = new botan_hotp_struct(std::move(otp));
39
40 return BOTAN_FFI_SUCCESS;
41 });
42#else
43 BOTAN_UNUSED(hotp, key, key_len, hash_algo, digits);
45#endif
46 }
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22

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

◆ botan_kdf()

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

Derive a key

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

Definition at line 128 of file ffi_kdf.cpp.

133 {
134 return ffi_guard_thunk(__func__, [=]() -> int {
135 auto kdf = Botan::KDF::create_or_throw(kdf_algo);
136 kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
137 return BOTAN_FFI_SUCCESS;
138 });
139 }
static std::unique_ptr< KDF > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: kdf.cpp:212

References BOTAN_FFI_SUCCESS, Botan::KDF::create_or_throw(), Botan_FFI::ffi_guard_thunk(), and salt_len.

◆ botan_key_unwrap3394()

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

Definition at line 34 of file ffi_keywrap.cpp.

37 {
38#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
39 return ffi_guard_thunk(__func__, [=]() -> int {
40 const Botan::SymmetricKey kek_sym(kek, kek_len);
41 const Botan::secure_vector<uint8_t> key_ct(wrapped_key, wrapped_key + wrapped_key_len);
42 const Botan::secure_vector<uint8_t> key_pt = Botan::rfc3394_keyunwrap(key_ct, kek_sym);
43 return write_vec_output(key, key_len, key_pt);
44 });
45#else
47#endif
48 }
secure_vector< uint8_t > rfc3394_keyunwrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:28

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

◆ botan_key_wrap3394()

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

Key wrapping as per RFC 3394

Definition at line 18 of file ffi_keywrap.cpp.

21 {
22#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
23 return ffi_guard_thunk(__func__, [=]() -> int {
24 const Botan::SymmetricKey kek_sym(kek, kek_len);
25 const Botan::secure_vector<uint8_t> key_pt(key, key + key_len);
26 const Botan::secure_vector<uint8_t> key_ct = Botan::rfc3394_keywrap(key_pt, kek_sym);
27 return write_vec_output(wrapped_key, wrapped_key_len, key_ct);
28 });
29#else
31#endif
32 }
secure_vector< uint8_t > rfc3394_keywrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:14

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

◆ botan_mac_clear()

int botan_mac_clear ( botan_mac_t  mac)

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

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

Definition at line 49 of file ffi_mac.cpp.

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

◆ botan_mac_destroy()

int botan_mac_destroy ( botan_mac_t  mac)

Frees all resources of the MAC object

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

Definition at line 34 of file ffi_mac.cpp.

35 {
36 return BOTAN_FFI_CHECKED_DELETE(mac);
37 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_mac_final()

int botan_mac_final ( botan_mac_t  mac,
uint8_t  out[] 
)

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

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

Definition at line 59 of file ffi_mac.cpp.

60 {
61 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.final(out); });
62 }
void final(uint8_t out[])
Definition: buf_comp.h:83

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

◆ botan_mac_get_keyspec()

int botan_mac_get_keyspec ( botan_mac_t  mac,
size_t *  out_minimum_keylength,
size_t *  out_maximum_keylength,
size_t *  out_keylength_modulo 
)

Get the key length limits of this auth code

Parameters
macthe object to read
out_minimum_keylengthif non-NULL, will be set to minimum keylength of MAC
out_maximum_keylengthif non-NULL, will be set to maximum keylength of MAC
out_keylength_moduloif non-NULL will be set to byte multiple of valid keys

Definition at line 70 of file ffi_mac.cpp.

74 {
76 if(out_minimum_keylength)
77 *out_minimum_keylength = m.minimum_keylength();
78 if(out_maximum_keylength)
79 *out_maximum_keylength = m.maximum_keylength();
80 if(out_keylength_modulo)
81 *out_keylength_modulo = m.key_spec().keylength_multiple();
82 });
83 }

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

◆ botan_mac_init()

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

Initialize a message authentication code object

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

Definition at line 17 of file ffi_mac.cpp.

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(!mac || !mac_name || flags != 0)
22
23 std::unique_ptr<Botan::MessageAuthenticationCode> m =
25
26 if(m == nullptr)
28
29 *mac = new botan_mac_struct(std::move(m));
30 return BOTAN_FFI_SUCCESS;
31 });
32 }
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
Definition: mac.cpp:46

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

◆ botan_mac_name()

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

Get the name of this MAC

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

Definition at line 64 of file ffi_mac.cpp.

65 {
67 return write_str_output(name, name_len, m.name()); });
68 }

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

◆ botan_mac_output_length()

int botan_mac_output_length ( botan_mac_t  mac,
size_t *  output_length 
)

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

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

Definition at line 44 of file ffi_mac.cpp.

45 {
46 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { *out = m.output_length(); });
47 }
virtual size_t output_length() const =0

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

◆ botan_mac_set_key()

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

Sets the key on the MAC

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

Definition at line 39 of file ffi_mac.cpp.

40 {
41 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.set_key(key, key_len); });
42 }

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

◆ botan_mac_update()

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

Send more input to the message authentication code

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

Definition at line 54 of file ffi_mac.cpp.

55 {
56 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.update(buf, len); });
57 }
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:33

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

◆ botan_mceies_decrypt()

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

Definition at line 946 of file ffi_pkey_algs.cpp.

951 {
952 BOTAN_UNUSED(mce_key_obj, aead, ct, ct_len, ad, ad_len, out, out_len);
954 }

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_mceies_encrypt()

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

Definition at line 956 of file ffi_pkey_algs.cpp.

962 {
963 BOTAN_UNUSED(mce_key_obj, rng_obj, aead, pt, pt_len, ad, ad_len, out, out_len);
965 }

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_mp_add()

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

Definition at line 132 of file ffi_mp.cpp.

133 {
134 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
135 if(result == x)
136 res += safe_get(y);
137 else
138 res = safe_get(x) + safe_get(y);
139 });
140 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

◆ botan_mp_add_u32()

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

Definition at line 152 of file ffi_mp.cpp.

153 {
154 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
155 if(result == x)
156 res += static_cast<Botan::word>(y);
157 else
158 res = safe_get(x) + static_cast<Botan::word>(y);
159 });
160 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

◆ botan_mp_clear()

int botan_mp_clear ( botan_mp_t  mp)

Set the MPI to zero

Definition at line 32 of file ffi_mp.cpp.

33 {
34 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.clear(); });
35 }
void clear()
Definition: bigint.h:375

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

◆ botan_mp_clear_bit()

int botan_mp_clear_bit ( botan_mp_t  n,
size_t  bit 
)

Clear the specified bit

Definition at line 290 of file ffi_mp.cpp.

291 {
292 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.clear_bit(bit); });
293 }
void clear_bit(size_t n)
Definition: bigint.cpp:283

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

◆ botan_mp_cmp()

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

Definition at line 213 of file ffi_mp.cpp.

214 {
215 return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { *result = x.cmp(safe_get(y_w)); });
216 }
int32_t cmp(const BigInt &n, bool check_signs=true) const
Definition: bigint.cpp:153

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

◆ botan_mp_destroy()

int botan_mp_destroy ( botan_mp_t  mp)

Destroy (deallocate) an MPI

Returns
0 if success, error if invalid object handle

Definition at line 127 of file ffi_mp.cpp.

128 {
129 return BOTAN_FFI_CHECKED_DELETE(mp);
130 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_mp_div()

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

Definition at line 182 of file ffi_mp.cpp.

185 {
186 return BOTAN_FFI_DO(Botan::BigInt, quotient, q, {
189 safe_get(remainder) = r;
190 });
191 }
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition: divide.cpp:165

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

◆ botan_mp_equal()

int botan_mp_equal ( const botan_mp_t  x,
const botan_mp_t  y 
)

Definition at line 193 of file ffi_mp.cpp.

194 {
195 return BOTAN_FFI_RETURNING(Botan::BigInt, x_w, x, { return x == safe_get(y_w); });
196 }

References BOTAN_FFI_RETURNING, and Botan_FFI::safe_get().

◆ botan_mp_flip_sign()

int botan_mp_flip_sign ( botan_mp_t  mp)

Definition at line 82 of file ffi_mp.cpp.

83 {
84 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.flip_sign(); });
85 }
void flip_sign()
Definition: bigint.h:568

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

◆ botan_mp_from_bin()

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

Definition at line 87 of file ffi_mp.cpp.

88 {
89 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_decode(bin, bin_len); });
90 }
void binary_decode(const uint8_t buf[], size_t length)
Definition: bigint.cpp:428

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

◆ botan_mp_gcd()

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

Definition at line 268 of file ffi_mp.cpp.

269 {
270 return BOTAN_FFI_DO(Botan::BigInt, out, o, {
271 o = Botan::gcd(safe_get(x), safe_get(y)); });
272 }
BigInt gcd(const BigInt &a, const BigInt &b)
Definition: numthry.cpp:220

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

◆ botan_mp_get_bit()

int botan_mp_get_bit ( const botan_mp_t  n,
size_t  bit 
)

Returns 0 if specified bit of n is not set Returns 1 if specified bit of n is set Returns negative number on error

Definition at line 280 of file ffi_mp.cpp.

281 {
282 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, n, { return (n.get_bit(bit)); });
283 }

References BOTAN_FFI_RETURNING.

◆ botan_mp_init()

int botan_mp_init ( botan_mp_t mp)

Initialize an MPI

Definition at line 20 of file ffi_mp.cpp.

21 {
22 return ffi_guard_thunk(__func__, [=]() -> int {
23 if(mp_out == nullptr)
25
26 auto mp = std::make_unique<Botan::BigInt>();
27 *mp_out = new botan_mp_struct(std::move(mp));
28 return BOTAN_FFI_SUCCESS;
29 });
30 }

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

◆ botan_mp_is_even()

int botan_mp_is_even ( const botan_mp_t  mp)

Definition at line 208 of file ffi_mp.cpp.

209 {
210 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_even(); });
211 }
bool is_even() const
Definition: bigint.h:412

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

◆ botan_mp_is_negative()

int botan_mp_is_negative ( const botan_mp_t  mp)

Return 1 iff mp is less than 0

Definition at line 72 of file ffi_mp.cpp.

73 {
74 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_negative() ? 1 : 0; });
75 }
bool is_negative() const
Definition: bigint.h:541

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

◆ botan_mp_is_odd()

int botan_mp_is_odd ( const botan_mp_t  mp)

Definition at line 203 of file ffi_mp.cpp.

204 {
205 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_odd(); });
206 }
bool is_odd() const
Definition: bigint.h:418

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

◆ botan_mp_is_positive()

int botan_mp_is_positive ( const botan_mp_t  mp)

This function should have been named mp_is_non_negative. Returns 1 iff mp is greater than or equal to zero. Use botan_mp_is_negative to detect negative numbers, botan_mp_is_zero to check for zero.

Definition at line 77 of file ffi_mp.cpp.

78 {
79 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_positive() ? 1 : 0; });
80 }
bool is_positive() const
Definition: bigint.h:547

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

◆ botan_mp_is_prime()

int botan_mp_is_prime ( const botan_mp_t  n,
botan_rng_t  rng,
size_t  test_prob 
)

Returns 0 if n is not prime Returns 1 if n is prime Returns negative number on error

Definition at line 274 of file ffi_mp.cpp.

275 {
277 { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; });
278 }
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition: numthry.cpp:370

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

◆ botan_mp_is_zero()

int botan_mp_is_zero ( const botan_mp_t  mp)

Definition at line 198 of file ffi_mp.cpp.

199 {
200 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_zero(); });
201 }
bool is_zero() const
Definition: bigint.h:430

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

◆ botan_mp_lshift()

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

Definition at line 230 of file ffi_mp.cpp.

231 {
232 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) << shift; });
233 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

◆ botan_mp_mod_inverse()

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

Definition at line 240 of file ffi_mp.cpp.

241 {
242 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); });
243 }
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: mod_inv.cpp:177

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

◆ botan_mp_mod_mul()

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

Definition at line 245 of file ffi_mp.cpp.

246 {
247 return BOTAN_FFI_DO(Botan::BigInt, out, o, {
248 Botan::Modular_Reducer reducer(safe_get(modulus));
249 o = reducer.multiply(safe_get(x), safe_get(y));
250 });
251 }

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

◆ botan_mp_mul()

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

Definition at line 172 of file ffi_mp.cpp.

173 {
174 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
175 if(result == x)
176 res *= safe_get(y);
177 else
178 res = safe_get(x) * safe_get(y);
179 });
180 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

◆ botan_mp_num_bits()

int botan_mp_num_bits ( const botan_mp_t  n,
size_t *  bits 
)

Return the number of significant bits in the MPI

Definition at line 295 of file ffi_mp.cpp.

296 {
297 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bits = n.bits(); });
298 }
size_t bits() const
Definition: bigint.cpp:309

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

◆ botan_mp_num_bytes()

int botan_mp_num_bytes ( const botan_mp_t  n,
size_t *  bytes 
)

Return the number of significant bytes in the MPI

Definition at line 300 of file ffi_mp.cpp.

301 {
302 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bytes = n.bytes(); });
303 }
size_t bytes() const
Definition: bigint.cpp:294

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

◆ botan_mp_powmod()

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

Definition at line 224 of file ffi_mp.cpp.

225 {
226 return BOTAN_FFI_DO(Botan::BigInt, out, o,
227 { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
228 }
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:296

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

◆ botan_mp_rand_bits()

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

Definition at line 253 of file ffi_mp.cpp.

254 {
256 safe_get(rand_out).randomize(r, bits); });
257 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

◆ botan_mp_rand_range()

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

Definition at line 259 of file ffi_mp.cpp.

263 {
265 safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
266 }
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
Definition: big_rand.cpp:45

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

◆ botan_mp_rshift()

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

Definition at line 235 of file ffi_mp.cpp.

236 {
237 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) >> shift; });
238 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

◆ botan_mp_set_bit()

int botan_mp_set_bit ( botan_mp_t  n,
size_t  bit 
)

Set the specified bit

Definition at line 285 of file ffi_mp.cpp.

286 {
287 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.set_bit(bit); });
288 }
void set_bit(size_t n)
Definition: bigint.h:439

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

◆ botan_mp_set_from_int()

int botan_mp_set_from_int ( botan_mp_t  mp,
int  initial_value 
)

Set the MPI value from an int

Definition at line 37 of file ffi_mp.cpp.

38 {
39 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
40 bn = Botan::BigInt::from_s32(initial_value);
41 });
42 }
static BigInt from_s32(int32_t n)
Definition: bigint.cpp:51

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

◆ botan_mp_set_from_mp()

int botan_mp_set_from_mp ( botan_mp_t  dest,
const botan_mp_t  source 
)

Set the MPI value from another MP object

Definition at line 67 of file ffi_mp.cpp.

68 {
69 return BOTAN_FFI_DO(Botan::BigInt, dest, bn, { bn = safe_get(source); });
70 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

◆ botan_mp_set_from_radix_str()

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

Set the MPI value from a string with arbitrary radix. For arbitrary being 10 or 16.

Definition at line 49 of file ffi_mp.cpp.

50 {
51 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
53 if(radix == 10)
55 else if(radix == 16)
57 else
59
60 const uint8_t* bytes = Botan::cast_char_ptr_to_uint8(str);
61 const size_t len = strlen(str);
62
63 bn = Botan::BigInt(bytes, len, base);
64 });
65 }
@ Hexadecimal
Definition: bigint.h:30
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:183

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

◆ botan_mp_set_from_str()

int botan_mp_set_from_str ( botan_mp_t  dest,
const char *  str 
)

Set the MPI value from a string

Definition at line 44 of file ffi_mp.cpp.

45 {
46 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn = Botan::BigInt(str); });
47 }

References BOTAN_FFI_DO.

◆ botan_mp_sub()

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

Definition at line 142 of file ffi_mp.cpp.

143 {
144 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
145 if(result == x)
146 res -= safe_get(y);
147 else
148 res = safe_get(x) - safe_get(y);
149 });
150 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

◆ botan_mp_sub_u32()

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

Definition at line 162 of file ffi_mp.cpp.

163 {
164 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
165 if(result == x)
166 res -= static_cast<Botan::word>(y);
167 else
168 res = safe_get(x) - static_cast<Botan::word>(y);
169 });
170 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

◆ botan_mp_swap()

int botan_mp_swap ( botan_mp_t  x,
botan_mp_t  y 
)

Definition at line 218 of file ffi_mp.cpp.

219 {
220 return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { x.swap(safe_get(y_w)); });
221 }
void swap(BigInt &other)
Definition: bigint.h:170

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

◆ botan_mp_to_bin()

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

Definition at line 113 of file ffi_mp.cpp.

114 {
115 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_encode(vec); });
116 }
void binary_encode(uint8_t buf[]) const
Definition: bigint.cpp:395

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

◆ botan_mp_to_hex()

int botan_mp_to_hex ( const botan_mp_t  mp,
char *  out 
)

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

Definition at line 92 of file ffi_mp.cpp.

93 {
94 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
95 const std::string hex = bn.to_hex_string();
96 std::memcpy(out, hex.c_str(), 1 + hex.size());
97 });
98 }
std::string to_hex_string() const
Definition: big_code.cpp:88

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

◆ botan_mp_to_str()

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

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

Definition at line 100 of file ffi_mp.cpp.

101 {
102 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, {
103
104 if(digit_base == 0 || digit_base == 10)
105 return write_str_output(out, out_len, bn.to_dec_string());
106 else if(digit_base == 16)
107 return write_str_output(out, out_len, bn.to_hex_string());
108 else
110 });
111 }

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

◆ botan_mp_to_uint32()

int botan_mp_to_uint32 ( const botan_mp_t  mp,
uint32_t *  val 
)

Definition at line 118 of file ffi_mp.cpp.

119 {
120 if(val == nullptr)
121 {
123 }
124 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { *val = bn.to_u32bit(); });
125 }
uint32_t to_u32bit() const
Definition: bigint.cpp:267

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

◆ botan_pbkdf()

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

Definition at line 21 of file ffi_kdf.cpp.

24 {
25 return botan_pwdhash(algo,
26 iterations,
27 0,
28 0,
29 out, out_len,
30 pass, 0,
31 salt, salt_len);
32 }
int botan_pwdhash(const char *algo, size_t param1, size_t param2, size_t param3, uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len)
Definition: ffi_kdf.cpp:51

References botan_pwdhash(), and salt_len.

◆ botan_pbkdf_timed()

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

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

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

Deprecated: use

botan_pwdhash_timed(pbkdf_algo, static_cast<uint32_t>(ms_to_run), iterations_used, nullptr, nullptr, out, out_len, password, 0, salt, salt_len);

Definition at line 34 of file ffi_kdf.cpp.

40 {
41 return botan_pwdhash_timed(algo,
42 static_cast<uint32_t>(ms_to_run),
43 iterations_used,
44 nullptr,
45 nullptr,
46 out, out_len,
47 password, 0,
48 salt, salt_len);
49 }
int botan_pwdhash_timed(const char *algo, uint32_t msec, size_t *param1, size_t *param2, size_t *param3, uint8_t out[], size_t out_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len)
Definition: ffi_kdf.cpp:85

References botan_pwdhash_timed(), and salt_len.

◆ botan_pk_op_decrypt()

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

Definition at line 101 of file ffi_pk_op.cpp.

104 {
105 return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, {
106 return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len));
107 });
108 }

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

◆ botan_pk_op_decrypt_create()

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

Definition at line 69 of file ffi_pk_op.cpp.

73 {
74 if(op == nullptr)
76
77 if(flags != 0)
79
80 return ffi_guard_thunk(__func__, [=]() -> int {
81 *op = nullptr;
82
83 std::unique_ptr<Botan::PK_Decryptor> pk(new Botan::PK_Decryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
84 *op = new botan_pk_op_decrypt_struct(std::move(pk));
85 return BOTAN_FFI_SUCCESS;
86 });
87 }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:363

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

◆ botan_pk_op_decrypt_destroy()

int botan_pk_op_decrypt_destroy ( botan_pk_op_decrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 89 of file ffi_pk_op.cpp.

90 {
91 return BOTAN_FFI_CHECKED_DELETE(op);
92 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_decrypt_output_length()

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

Definition at line 94 of file ffi_pk_op.cpp.

95 {
96 if(ptext_len == nullptr)
98 return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, { *ptext_len = o.plaintext_length(ctext_len); });
99 }
virtual size_t plaintext_length(size_t ctext_len) const =0

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

◆ botan_pk_op_encrypt()

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

Definition at line 56 of file ffi_pk_op.cpp.

60 {
61 return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, {
62 return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
63 });
64 }

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

◆ botan_pk_op_encrypt_create()

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

Definition at line 24 of file ffi_pk_op.cpp.

28 {
29 if(op == nullptr)
31
34
35 return ffi_guard_thunk(__func__, [=]() -> int {
36 *op = nullptr;
37
38 std::unique_ptr<Botan::PK_Encryptor> pk(new Botan::PK_Encryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
39 *op = new botan_pk_op_encrypt_struct(std::move(pk));
40 return BOTAN_FFI_SUCCESS;
41 });
42 }
#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE
Definition: ffi.h:1435

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

◆ botan_pk_op_encrypt_destroy()

int botan_pk_op_encrypt_destroy ( botan_pk_op_encrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 44 of file ffi_pk_op.cpp.

45 {
46 return BOTAN_FFI_CHECKED_DELETE(op);
47 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_encrypt_output_length()

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

Definition at line 49 of file ffi_pk_op.cpp.

50 {
51 if(ctext_len == nullptr)
53 return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, { *ctext_len = o.ciphertext_length(ptext_len); });
54 }
virtual size_t ciphertext_length(size_t ctext_len) const =0

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

◆ botan_pk_op_key_agreement()

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

Definition at line 245 of file ffi_pk_op.cpp.

249 {
251 auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
252 return write_vec_output(out, out_len, k);
253 });
254 }
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:207

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

◆ botan_pk_op_key_agreement_create()

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

Definition at line 202 of file ffi_pk_op.cpp.

206 {
207 if(op == nullptr)
209
210 if(flags != 0)
212
213 return ffi_guard_thunk(__func__, [=]() -> int {
214 *op = nullptr;
215 std::unique_ptr<Botan::PK_Key_Agreement> pk(new Botan::PK_Key_Agreement(safe_get(key_obj), Botan::system_rng(), kdf));
216 *op = new botan_pk_op_ka_struct(std::move(pk));
217 return BOTAN_FFI_SUCCESS;
218 });
219 }

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

◆ botan_pk_op_key_agreement_destroy()

int botan_pk_op_key_agreement_destroy ( botan_pk_op_ka_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 221 of file ffi_pk_op.cpp.

222 {
223 return BOTAN_FFI_CHECKED_DELETE(op);
224 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_key_agreement_export_public()

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

Definition at line 226 of file ffi_pk_op.cpp.

228 {
229 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
230 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
231 return write_vec_output(out, out_len, kak->public_value());
233 });
234 }

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

◆ botan_pk_op_key_agreement_size()

int botan_pk_op_key_agreement_size ( botan_pk_op_ka_t  op,
size_t *  out_len 
)

Definition at line 236 of file ffi_pk_op.cpp.

237 {
239 if(out_len == nullptr)
241 *out_len = o.agreed_value_size();
242 });
243 }

References BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

◆ botan_pk_op_sign_create()

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

Definition at line 113 of file ffi_pk_op.cpp.

117 {
118 if(op == nullptr)
120
123
124 return ffi_guard_thunk(__func__, [=]() -> int {
125 *op = nullptr;
126
128
129 std::unique_ptr<Botan::PK_Signer> pk(new Botan::PK_Signer(safe_get(key_obj), Botan::system_rng(), hash, format));
130 *op = new botan_pk_op_sign_struct(std::move(pk));
131 return BOTAN_FFI_SUCCESS;
132 });
133 }
@ DER_SEQUENCE
Definition: pk_keys.h:23
@ IEEE_1363
Definition: pk_keys.h:23

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DER_SEQUENCE, Botan_FFI::ffi_guard_thunk(), Botan::PKCS11::flags(), hash, Botan::IEEE_1363, Botan_FFI::safe_get(), and Botan::system_rng().

◆ botan_pk_op_sign_destroy()

int botan_pk_op_sign_destroy ( botan_pk_op_sign_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 135 of file ffi_pk_op.cpp.

136 {
137 return BOTAN_FFI_CHECKED_DELETE(op);
138 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_sign_finish()

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

Definition at line 153 of file ffi_pk_op.cpp.

154 {
155 return BOTAN_FFI_DO(Botan::PK_Signer, op, o, {
156 return write_vec_output(out, out_len, o.signature(safe_get(rng_obj)));
157 });
158 }

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

◆ botan_pk_op_sign_output_length()

int botan_pk_op_sign_output_length ( botan_pk_op_sign_t  op,
size_t *  olen 
)

Definition at line 140 of file ffi_pk_op.cpp.

141 {
142 if(sig_len == nullptr)
144
145 return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { *sig_len = o.signature_length(); });
146 }
size_t signature_length() const
Definition: pubkey.cpp:266

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

◆ botan_pk_op_sign_update()

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

Definition at line 148 of file ffi_pk_op.cpp.

149 {
150 return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { o.update(in, in_len); });
151 }
void update(uint8_t in)
Definition: pubkey.h:222

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

◆ botan_pk_op_verify_create()

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

Definition at line 160 of file ffi_pk_op.cpp.

164 {
165 if(op == nullptr)
167
170
171 return ffi_guard_thunk(__func__, [=]() -> int {
172 *op = nullptr;
174 std::unique_ptr<Botan::PK_Verifier> pk(new Botan::PK_Verifier(safe_get(key_obj), hash, format));
175 *op = new botan_pk_op_verify_struct(std::move(pk));
176 return BOTAN_FFI_SUCCESS;
177 });
178 }

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DER_SEQUENCE, Botan_FFI::ffi_guard_thunk(), Botan::PKCS11::flags(), hash, Botan::IEEE_1363, and Botan_FFI::safe_get().

◆ botan_pk_op_verify_destroy()

int botan_pk_op_verify_destroy ( botan_pk_op_verify_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 180 of file ffi_pk_op.cpp.

181 {
182 return BOTAN_FFI_CHECKED_DELETE(op);
183 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_verify_finish()

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

Definition at line 190 of file ffi_pk_op.cpp.

191 {
193 const bool legit = o.check_signature(sig, sig_len);
194
195 if(legit)
196 return BOTAN_FFI_SUCCESS;
197 else
199 });
200 }
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:332

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

◆ botan_pk_op_verify_update()

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

Definition at line 185 of file ffi_pk_op.cpp.

186 {
187 return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, { o.update(in, in_len); });
188 }
void update(uint8_t in)
Definition: pubkey.h:333

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

◆ botan_pkcs_hash_id()

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

Definition at line 267 of file ffi_pkey.cpp.

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

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

◆ botan_privkey_algo_name()

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

Definition at line 126 of file ffi_pkey.cpp.

127 {
128 return BOTAN_FFI_DO(Botan::Private_Key, key, k, { return write_str_output(out, out_len, k.algo_name()); });
129 }

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

◆ botan_privkey_check_key()

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

Definition at line 145 of file ffi_pkey.cpp.

146 {
147 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
149 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
150 });
151 }
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition: ffi.h:991

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

◆ botan_privkey_create()

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

Create a new private key

Parameters
keythe new object will be placed here
algo_namesomething like "RSA" or "ECDSA"
algo_paramsis specific to the algorithm. For RSA, specifies the modulus bit length. For ECC is the name of the curve.
rnga random number generator

Definition at line 26 of file ffi_pkey.cpp.

30 {
31 return ffi_guard_thunk(__func__, [=]() -> int {
32 if(key_obj == nullptr)
34
35 *key_obj = nullptr;
36 if(rng_obj == nullptr)
38
40 std::unique_ptr<Botan::Private_Key> key(
41 Botan::create_private_key(algo_name ? algo_name : "RSA",
42 rng,
43 algo_params ? algo_params : ""));
44
45 if(key)
46 {
47 *key_obj = new botan_privkey_struct(std::move(key));
48 return BOTAN_FFI_SUCCESS;
49 }
50 else
51 {
53 }
54 });
55 }
std::unique_ptr< Private_Key > create_private_key(const std::string &alg_name, RandomNumberGenerator &rng, const std::string &params, const std::string &provider)
Definition: pk_algs.cpp:299

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

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

◆ botan_privkey_create_dh()

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

Definition at line 586 of file ffi_pkey_algs.cpp.

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

References botan_privkey_create().

◆ botan_privkey_create_dsa()

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

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

Parameters
keyhandler to the resulting key
rnginitialized PRNG
pbitslength of the key in bits. Must be between in range (1024, 3072) and multiple of 64. Bit size of the prime 'p'
qbitsorder of the subgroup. Must be in range (160, 256) and multiple of 8
Returns
BOTAN_FFI_SUCCESS Success, ‘key’ initialized with DSA key
BOTAN_FFI_ERROR_NULL_POINTER either ‘key’ or ‘rng’ is NULL
BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either ‘pbits’ or ‘qbits’
BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

Definition at line 383 of file ffi_pkey_algs.cpp.

384 {
385#if defined(BOTAN_HAS_DSA)
386
387 if ((rng_obj == nullptr) || (key == nullptr))
389
390 if ((pbits % 64) || (qbits % 8) ||
391 (pbits < 1024) || (pbits > 3072) ||
392 (qbits < 160) || (qbits > 256)) {
394 }
395
396 return ffi_guard_thunk(__func__, [=]() -> int {
398 Botan::DL_Group group(rng, Botan::DL_Group::Prime_Subgroup, pbits, qbits);
399 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(rng, group);
400 *key = new botan_privkey_struct(std::move(dsa));
401 return BOTAN_FFI_SUCCESS;
402 });
403#else
404 BOTAN_UNUSED(key, rng_obj, pbits, qbits);
406#endif
407 }

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

◆ botan_privkey_create_ecdh()

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

Definition at line 628 of file ffi_pkey_algs.cpp.

629 {
630 if(param_str == nullptr)
632
633 const std::string params(param_str);
634
635 if(params == "curve25519")
636 return botan_privkey_create(key_obj, "Curve25519", "", rng_obj);
637
638 return botan_privkey_create(key_obj, "ECDH", param_str, rng_obj);
639 }

References BOTAN_FFI_ERROR_NULL_POINTER, and botan_privkey_create().

◆ botan_privkey_create_ecdsa()

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

Definition at line 471 of file ffi_pkey_algs.cpp.

472 {
473 return botan_privkey_create(key_obj, "ECDSA", param_str, rng_obj);
474 }

References botan_privkey_create().

◆ botan_privkey_create_elgamal()

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

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

  • if pbits-1 == qbits then safe primes are used for key generation
  • otherwise generation uses group of prime order
Parameters
keyhandler to the resulting key
rnginitialized PRNG
pbitslength of the key in bits. Must be at least 1024
qbitsorder of the subgroup. Must be at least 160
Returns
BOTAN_FFI_SUCCESS Success, ‘key’ initialized with DSA key
BOTAN_FFI_ERROR_NULL_POINTER either ‘key’ or ‘rng’ is NULL
BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either ‘pbits’ or ‘qbits’
BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented

Definition at line 518 of file ffi_pkey_algs.cpp.

522 {
523#if defined(BOTAN_HAS_ELGAMAL)
524
525 if ((rng_obj == nullptr) || (key == nullptr))
527
528 if ((pbits < 1024) || (qbits<160)) {
530 }
531
532 Botan::DL_Group::PrimeType prime_type = ((pbits-1) == qbits)
535
536 return ffi_guard_thunk(__func__, [=]() -> int {
538 Botan::DL_Group group(rng, prime_type, pbits, qbits);
539 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(rng, group);
540 *key = new botan_privkey_struct(std::move(elg));
541 return BOTAN_FFI_SUCCESS;
542 });
543#else
544 BOTAN_UNUSED(key, rng_obj, pbits);
546#endif
547 }

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

◆ botan_privkey_create_mceliece()

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

Definition at line 940 of file ffi_pkey_algs.cpp.

941 {
942 const std::string mce_params = std::to_string(n) + "," + std::to_string(t);
943 return botan_privkey_create(key_obj, "McEliece", mce_params.c_str(), rng_obj);
944 }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:209

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

◆ botan_privkey_create_rsa()

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

Definition at line 254 of file ffi_pkey_algs.cpp.

255 {
256 if(n_bits < 1024 || n_bits > 16*1024)
258
259 std::string n_str = std::to_string(n_bits);
260
261 return botan_privkey_create(key_obj, "RSA", n_str.c_str(), rng_obj);
262 }

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

◆ botan_privkey_destroy()

int botan_privkey_destroy ( botan_privkey_t  key)
Returns
0 if success, error if invalid object handle

Definition at line 88 of file ffi_pkey.cpp.

89 {
90 return BOTAN_FFI_CHECKED_DELETE(key);
91 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_privkey_dsa_get_x()

int botan_privkey_dsa_get_x ( botan_mp_t  n,
botan_privkey_t  key 
)

Definition at line 446 of file ffi_pkey_algs.cpp.

447 {
448 return botan_privkey_get_field(x, key, "x");
449 }
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)

References botan_privkey_get_field().

◆ botan_privkey_ed25519_get_privkey()

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

Definition at line 808 of file ffi_pkey_algs.cpp.

810 {
811#if defined(BOTAN_HAS_ED25519)
812 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
813 if(Botan::Ed25519_PrivateKey* ed = dynamic_cast<Botan::Ed25519_PrivateKey*>(&k))
814 {
815 const Botan::secure_vector<uint8_t>& ed_key = ed->get_private_key();
816 if(ed_key.size() != 64)
818 Botan::copy_mem(output, ed_key.data(), ed_key.size());
819 return BOTAN_FFI_SUCCESS;
820 }
821 else
822 {
824 }
825 });
826#else
827 BOTAN_UNUSED(key, output);
829#endif
830 }

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

◆ botan_privkey_export()

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

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

Definition at line 165 of file ffi_pkey.cpp.

166 {
167 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
169 return write_vec_output(out, out_len, Botan::PKCS8::BER_encode(k));
171 return write_str_output(out, out_len, Botan::PKCS8::PEM_encode(k));
172 else
174 });
175 }
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:1071
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:1070
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:137
std::vector< uint8_t > BER_encode(const Private_Key &key, RandomNumberGenerator &rng, const std::string &pass, std::chrono::milliseconds msec, const std::string &pbe_algo)
Definition: pkcs8.cpp:189

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

◆ botan_privkey_export_encrypted()

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

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

Definition at line 177 of file ffi_pkey.cpp.

183 {
184 return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
185 }
int botan_privkey_export_encrypted_pbkdf_iter(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng_obj, const char *pass, size_t pbkdf_iter, const char *maybe_cipher, const char *maybe_pbkdf_hash, uint32_t flags)
Definition: ffi_pkey.cpp:221

References botan_privkey_export_encrypted_pbkdf_iter(), and Botan::PKCS11::flags().

◆ botan_privkey_export_encrypted_pbkdf_iter()

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

Export a private key using the specified number of iterations.

Definition at line 221 of file ffi_pkey.cpp.

229 {
230 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
232
233 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
234 const std::string pbkdf_hash = (maybe_pbkdf_hash ? maybe_pbkdf_hash : "");
235
237 {
238 return write_vec_output(out, out_len,
239 Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
240 }
242 {
243 return write_str_output(out, out_len,
244 Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, pass, pbkdf_iter, cipher, pbkdf_hash));
245 }
246 else
247 {
248 return -2;
249 }
250 });
251 }
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:235
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:268

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

Referenced by botan_privkey_export_encrypted().

◆ botan_privkey_export_encrypted_pbkdf_msec()

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

Definition at line 187 of file ffi_pkey.cpp.

196 {
197 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
198 const std::chrono::milliseconds pbkdf_time(pbkdf_msec);
200
201 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
202 const std::string pbkdf_hash = (maybe_pbkdf_hash ? maybe_pbkdf_hash : "");
203
205 {
206 return write_vec_output(out, out_len,
207 Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
208 }
210 {
211 return write_str_output(out, out_len,
212 Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, pass, pbkdf_time, pbkdf_iters_out, cipher, pbkdf_hash));
213 }
214 else
215 {
216 return -2;
217 }
218 });
219 }
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:316
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:283

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

◆ botan_privkey_export_pubkey()

int botan_privkey_export_pubkey ( botan_pubkey_t out,
botan_privkey_t  in 
)

Definition at line 115 of file ffi_pkey.cpp.

116 {
117 return ffi_guard_thunk(__func__, [=]() -> int {
118 std::unique_ptr<Botan::Public_Key>
120
121 *pubout = new botan_pubkey_struct(std::move(pubkey));
122 return BOTAN_FFI_SUCCESS;
123 });
124 }
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.h:28
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:29

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

◆ botan_privkey_get_field()

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

Definition at line 238 of file ffi_pkey_algs.cpp.

241 {
242 if(field_name_cstr == nullptr)
244
245 const std::string field_name(field_name_cstr);
246
247 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
248 safe_get(output) = privkey_get_field(k, field_name);
249 });
250 }

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

Referenced by botan_privkey_dsa_get_x(), botan_privkey_rsa_get_d(), botan_privkey_rsa_get_e(), botan_privkey_rsa_get_n(), botan_privkey_rsa_get_p(), and botan_privkey_rsa_get_q().

◆ botan_privkey_load()

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

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

Definition at line 57 of file ffi_pkey.cpp.

60 {
61 BOTAN_UNUSED(rng_obj);
62
63 *key = nullptr;
64
65 return ffi_guard_thunk(__func__, [=]() -> int {
66 Botan::DataSource_Memory src(bits, len);
67
68 std::unique_ptr<Botan::Private_Key> pkcs8;
69
70 if(password == nullptr)
71 {
72 pkcs8 = Botan::PKCS8::load_key(src);
73 }
74 else
75 {
76 pkcs8 = Botan::PKCS8::load_key(src, std::string(password));
77 }
78
79 if(pkcs8)
80 {
81 *key = new botan_privkey_struct(std::move(pkcs8));
82 return BOTAN_FFI_SUCCESS;
83 }
85 });
86 }
std::unique_ptr< Private_Key > load_key(DataSource &source, const std::function< std::string()> &get_pass)
Definition: pkcs8.cpp:355

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

◆ botan_privkey_load_dh()

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

Definition at line 591 of file ffi_pkey_algs.cpp.

593 {
594#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
595 *key = nullptr;
596 return ffi_guard_thunk(__func__, [=]() -> int {
597 Botan::Null_RNG null_rng;
598 Botan::DL_Group group(safe_get(p), safe_get(g));
599 auto dh = std::make_unique<Botan::DH_PrivateKey>(null_rng, group, safe_get(x));
600 *key = new botan_privkey_struct(std::move(dh));
601 return BOTAN_FFI_SUCCESS;
602 });
603#else
604 BOTAN_UNUSED(key, p, g, x);
606#endif
607 }

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

◆ botan_privkey_load_dsa()

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

Definition at line 409 of file ffi_pkey_algs.cpp.

411 {
412#if defined(BOTAN_HAS_DSA)
413 *key = nullptr;
414
415 return ffi_guard_thunk(__func__, [=]() -> int {
416 Botan::Null_RNG null_rng;
417 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
418 auto dsa = std::make_unique<Botan::DSA_PrivateKey>(null_rng, group, safe_get(x));
419 *key = new botan_privkey_struct(std::move(dsa));
420 return BOTAN_FFI_SUCCESS;
421 });
422#else
423 BOTAN_UNUSED(key, p, q, g, x);
425#endif
426 }

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

◆ botan_privkey_load_ecdh()

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

Definition at line 661 of file ffi_pkey_algs.cpp.

664 {
665#if defined(BOTAN_HAS_ECDH)
666 return ffi_guard_thunk(__func__, [=]() -> int {
667 std::unique_ptr<Botan::ECDH_PrivateKey> p_key;
668 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
669 if(rc == BOTAN_FFI_SUCCESS)
670 *key = new botan_privkey_struct(std::move(p_key));
671 return rc;
672 });
673#else
674 BOTAN_UNUSED(key, scalar, curve_name);
676#endif
677 }

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

◆ botan_privkey_load_ecdsa()

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

Definition at line 499 of file ffi_pkey_algs.cpp.

502 {
503#if defined(BOTAN_HAS_ECDSA)
504 return ffi_guard_thunk(__func__, [=]() -> int {
505 std::unique_ptr<Botan::ECDSA_PrivateKey> p_key;
506 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
507 if(rc == BOTAN_FFI_SUCCESS)
508 *key = new botan_privkey_struct(std::move(p_key));
509 return rc;
510 });
511#else
512 BOTAN_UNUSED(key, scalar, curve_name);
514#endif
515 }

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

◆ botan_privkey_load_ed25519()

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

Definition at line 774 of file ffi_pkey_algs.cpp.

776 {
777#if defined(BOTAN_HAS_ED25519)
778 *key = nullptr;
779 return ffi_guard_thunk(__func__, [=]() -> int {
780 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
781 auto ed25519 = std::make_unique<Botan::Ed25519_PrivateKey>(privkey_vec);
782 *key = new botan_privkey_struct(std::move(ed25519));
783 return BOTAN_FFI_SUCCESS;
784 });
785#else
786 BOTAN_UNUSED(key, privkey);
788#endif
789 }

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

◆ botan_privkey_load_elgamal()

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

Loads ElGamal private key

Parameters
keyvariable populated with key material
pprime order of a Z_p group
ggroup generator
xprivate key
Precondition
key is NULL on input
Postcondition
function allocates memory and assigns to ‘key’
Returns
0 on success, a negative value on failure

Definition at line 566 of file ffi_pkey_algs.cpp.

568 {
569#if defined(BOTAN_HAS_ELGAMAL)
570 *key = nullptr;
571 return ffi_guard_thunk(__func__, [=]() -> int {
572 Botan::Null_RNG null_rng;
573 Botan::DL_Group group(safe_get(p), safe_get(g));
574 auto elg = std::make_unique<Botan::ElGamal_PrivateKey>(null_rng, group, safe_get(x));
575 *key = new botan_privkey_struct(std::move(elg));
576 return BOTAN_FFI_SUCCESS;
577 });
578#else
579 BOTAN_UNUSED(key, p, g, x);
581#endif
582 }

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

◆ botan_privkey_load_rsa()

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

Definition at line 264 of file ffi_pkey_algs.cpp.

266 {
267#if defined(BOTAN_HAS_RSA)
268 *key = nullptr;
269
270 return ffi_guard_thunk(__func__, [=]() -> int {
271
272 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(safe_get(rsa_p),
273 safe_get(rsa_q),
274 safe_get(rsa_e));
275 *key = new botan_privkey_struct(std::move(rsa));
276 return BOTAN_FFI_SUCCESS;
277 });
278#else
279 BOTAN_UNUSED(key, rsa_p, rsa_q, rsa_e);
281#endif
282 }

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

◆ botan_privkey_load_rsa_pkcs1()

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

Definition at line 284 of file ffi_pkey_algs.cpp.

287 {
288#if defined(BOTAN_HAS_RSA)
289 *key = nullptr;
290
291 Botan::secure_vector<uint8_t> src(bits, bits + len);
292 return ffi_guard_thunk(__func__, [=]() -> int {
294 auto rsa = std::make_unique<Botan::RSA_PrivateKey>(alg_id, src);
295 *key = new botan_privkey_struct(std::move(rsa));
296 return BOTAN_FFI_SUCCESS;
297 });
298#else
299 BOTAN_UNUSED(key, bits, len);
301#endif
302 }

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

◆ botan_privkey_load_sm2()

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

Definition at line 738 of file ffi_pkey_algs.cpp.

741 {
742#if defined(BOTAN_HAS_SM2)
743 return ffi_guard_thunk(__func__, [=]() -> int {
744 std::unique_ptr<Botan::SM2_PrivateKey> p_key;
745 int rc = privkey_load_ec(p_key, safe_get(scalar), curve_name);
746
747 if(rc == BOTAN_FFI_SUCCESS)
748 *key = new botan_privkey_struct(std::move(p_key));
749 return rc;
750 });
751#else
752 BOTAN_UNUSED(key, scalar, curve_name);
754#endif
755 }

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

Referenced by botan_privkey_load_sm2_enc().

◆ botan_privkey_load_sm2_enc()

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

Definition at line 765 of file ffi_pkey_algs.cpp.

768 {
769 return botan_privkey_load_sm2(key, scalar, curve_name);
770 }
int botan_privkey_load_sm2(botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)

References botan_privkey_load_sm2().

◆ botan_privkey_load_x25519()

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

Definition at line 858 of file ffi_pkey_algs.cpp.

860 {
861#if defined(BOTAN_HAS_X25519)
862 *key = nullptr;
863 return ffi_guard_thunk(__func__, [=]() -> int {
864 const Botan::secure_vector<uint8_t> privkey_vec(privkey, privkey + 32);
865 auto x25519 = std::make_unique<Botan::X25519_PrivateKey>(privkey_vec);
866 *key = new botan_privkey_struct(std::move(x25519));
867 return BOTAN_FFI_SUCCESS;
868 });
869#else
870 BOTAN_UNUSED(key, privkey);
872#endif
873 }

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

◆ botan_privkey_rsa_get_d()

int botan_privkey_rsa_get_d ( botan_mp_t  d,
botan_privkey_t  rsa_key 
)

Definition at line 340 of file ffi_pkey_algs.cpp.

341 {
342 return botan_privkey_get_field(d, key, "d");
343 }

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_e()

int botan_privkey_rsa_get_e ( botan_mp_t  e,
botan_privkey_t  rsa_key 
)

Definition at line 335 of file ffi_pkey_algs.cpp.

336 {
337 return botan_privkey_get_field(e, key, "e");
338 }

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_n()

int botan_privkey_rsa_get_n ( botan_mp_t  n,
botan_privkey_t  rsa_key 
)

Definition at line 330 of file ffi_pkey_algs.cpp.

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

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_p()

int botan_privkey_rsa_get_p ( botan_mp_t  p,
botan_privkey_t  rsa_key 
)

Definition at line 320 of file ffi_pkey_algs.cpp.

321 {
322 return botan_privkey_get_field(p, key, "p");
323 }

References botan_privkey_get_field().

◆ botan_privkey_rsa_get_privkey()

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

Definition at line 355 of file ffi_pkey_algs.cpp.

358 {
359#if defined(BOTAN_HAS_RSA)
360 return BOTAN_FFI_DO(Botan::Private_Key, rsa_key, k, {
361 if(const Botan::RSA_PrivateKey* rsa = dynamic_cast<const Botan::RSA_PrivateKey*>(&k))
362 {
364 return write_vec_output(out, out_len, rsa->private_key_bits());
366 return write_str_output(out, out_len, Botan::PEM_Code::encode(rsa->private_key_bits(),
367 "RSA PRIVATE KEY"));
368 else
370 }
371 else
372 {
374 }
375 });
376#else
377 BOTAN_UNUSED(rsa_key, out, out_len);
379#endif
380 }
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:41

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_PRIVKEY_EXPORT_FLAG_DER, BOTAN_PRIVKEY_EXPORT_FLAG_PEM, BOTAN_UNUSED, Botan::PEM_Code::encode(), Botan::PKCS11::flags(), Botan_FFI::write_str_output(), and Botan_FFI::write_vec_output().

◆ botan_privkey_rsa_get_q()

int botan_privkey_rsa_get_q ( botan_mp_t  q,
botan_privkey_t  rsa_key 
)

Definition at line 325 of file ffi_pkey_algs.cpp.

326 {
327 return botan_privkey_get_field(q, key, "q");
328 }

References botan_privkey_get_field().

◆ botan_privkey_x25519_get_privkey()

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

Definition at line 892 of file ffi_pkey_algs.cpp.

894 {
895#if defined(BOTAN_HAS_X25519)
896 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
897 if(Botan::X25519_PrivateKey* x25519 = dynamic_cast<Botan::X25519_PrivateKey*>(&k))
898 {
899 const Botan::secure_vector<uint8_t>& x25519_key = x25519->get_x();
900 if(x25519_key.size() != 32)
902 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
903 return BOTAN_FFI_SUCCESS;
904 }
905 else
906 {
908 }
909 });
910#else
911 BOTAN_UNUSED(key, output);
913#endif
914 }

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

◆ botan_pubkey_algo_name()

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

Definition at line 131 of file ffi_pkey.cpp.

132 {
133 return BOTAN_FFI_DO(Botan::Public_Key, key, k, { return write_str_output(out, out_len, k.algo_name()); });
134 }

References BOTAN_FFI_DO, and Botan_FFI::write_str_output().

◆ botan_pubkey_check_key()

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

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

Definition at line 136 of file ffi_pkey.cpp.

137 {
138 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
139
140 return BOTAN_FFI_RETURNING(Botan::Public_Key, key, k, {
141 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
142 });
143 }

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

◆ botan_pubkey_destroy()

int botan_pubkey_destroy ( botan_pubkey_t  key)
Returns
0 if success, error if invalid object handle

Definition at line 110 of file ffi_pkey.cpp.

111 {
112 return BOTAN_FFI_CHECKED_DELETE(key);
113 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pubkey_dsa_get_g()

int botan_pubkey_dsa_get_g ( botan_mp_t  d,
botan_pubkey_t  key 
)

Definition at line 461 of file ffi_pkey_algs.cpp.

462 {
463 return botan_pubkey_get_field(g, key, "g");
464 }
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_p()

int botan_pubkey_dsa_get_p ( botan_mp_t  p,
botan_pubkey_t  key 
)

Definition at line 451 of file ffi_pkey_algs.cpp.

452 {
453 return botan_pubkey_get_field(p, key, "p");
454 }

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_q()

int botan_pubkey_dsa_get_q ( botan_mp_t  q,
botan_pubkey_t  key 
)

Definition at line 456 of file ffi_pkey_algs.cpp.

457 {
458 return botan_pubkey_get_field(q, key, "q");
459 }

References botan_pubkey_get_field().

◆ botan_pubkey_dsa_get_y()

int botan_pubkey_dsa_get_y ( botan_mp_t  y,
botan_pubkey_t  key 
)

Definition at line 466 of file ffi_pkey_algs.cpp.

467 {
468 return botan_pubkey_get_field(y, key, "y");
469 }

References botan_pubkey_get_field().

◆ botan_pubkey_ed25519_get_pubkey()

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

Definition at line 832 of file ffi_pkey_algs.cpp.

834 {
835#if defined(BOTAN_HAS_ED25519)
836 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
837 if(Botan::Ed25519_PublicKey* ed = dynamic_cast<Botan::Ed25519_PublicKey*>(&k))
838 {
839 const std::vector<uint8_t>& ed_key = ed->get_public_key();
840 if(ed_key.size() != 32)
842 Botan::copy_mem(output, ed_key.data(), ed_key.size());
843 return BOTAN_FFI_SUCCESS;
844 }
845 else
846 {
848 }
849 });
850#else
851 BOTAN_UNUSED(key, output);
853#endif
854 }

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

◆ botan_pubkey_estimated_strength()

int botan_pubkey_estimated_strength ( botan_pubkey_t  key,
size_t *  estimate 
)

Definition at line 253 of file ffi_pkey.cpp.

254 {
255 return BOTAN_FFI_DO(Botan::Public_Key, key, k, { *estimate = k.estimated_strength(); });
256 }
virtual size_t estimated_strength() const =0

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

◆ botan_pubkey_export()

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

◆ botan_pubkey_fingerprint()

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

Definition at line 258 of file ffi_pkey.cpp.

260 {
261 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
262 std::unique_ptr<Botan::HashFunction> h(Botan::HashFunction::create(hash_fn));
263 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
264 });
265 }

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

◆ botan_pubkey_get_field()

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

Definition at line 224 of file ffi_pkey_algs.cpp.

227 {
228 if(field_name_cstr == nullptr)
230
231 const std::string field_name(field_name_cstr);
232
233 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
234 safe_get(output) = pubkey_get_field(k, field_name);
235 });
236 }

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

Referenced by botan_pubkey_dsa_get_g(), botan_pubkey_dsa_get_p(), botan_pubkey_dsa_get_q(), botan_pubkey_dsa_get_y(), botan_pubkey_rsa_get_e(), and botan_pubkey_rsa_get_n().

◆ botan_pubkey_load()

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

Definition at line 93 of file ffi_pkey.cpp.

95 {
96 *key = nullptr;
97
98 return ffi_guard_thunk(__func__, [=]() -> int {
99 Botan::DataSource_Memory src(bits, bits_len);
100 std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src));
101
102 if(pubkey == nullptr)
104
105 *key = new botan_pubkey_struct(std::move(pubkey));
106 return BOTAN_FFI_SUCCESS;
107 });
108 }

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

◆ botan_pubkey_load_dh()

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

Loads Diffie Hellman public key

Parameters
keyvariable populated with key material
pprime order of a Z_p group
ggroup generator
ypublic key
Precondition
key is NULL on input
Postcondition
function allocates memory and assigns to ‘key’
Returns
0 on success, a negative value on failure

Definition at line 609 of file ffi_pkey_algs.cpp.

611 {
612#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
613 *key = nullptr;
614 return ffi_guard_thunk(__func__, [=]() -> int {
615 Botan::DL_Group group(safe_get(p), safe_get(g));
616 auto dh = std::make_unique<Botan::DH_PublicKey>(group, safe_get(y));
617 *key = new botan_pubkey_struct(std::move(dh));
618 return BOTAN_FFI_SUCCESS;
619 });
620#else
621 BOTAN_UNUSED(key, p, g, y);
623#endif
624 }

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

◆ botan_pubkey_load_dsa()

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

Definition at line 428 of file ffi_pkey_algs.cpp.

430 {
431#if defined(BOTAN_HAS_DSA)
432 *key = nullptr;
433
434 return ffi_guard_thunk(__func__, [=]() -> int {
435 Botan::DL_Group group(safe_get(p), safe_get(q), safe_get(g));
436 auto dsa = std::make_unique<Botan::DSA_PublicKey>(group, safe_get(y));
437 *key = new botan_pubkey_struct(std::move(dsa));
438 return BOTAN_FFI_SUCCESS;
439 });
440#else
441 BOTAN_UNUSED(key, p, q, g, y);
443#endif
444 }

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

◆ botan_pubkey_load_ecdh()

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

Definition at line 641 of file ffi_pkey_algs.cpp.

645 {
646#if defined(BOTAN_HAS_ECDH)
647 return ffi_guard_thunk(__func__, [=]() -> int {
648 std::unique_ptr<Botan::ECDH_PublicKey> p_key;
649 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
650
651 if(rc == BOTAN_FFI_SUCCESS)
652 *key = new botan_pubkey_struct(std::move(p_key));
653 return rc;
654 });
655#else
656 BOTAN_UNUSED(key, public_x, public_y, curve_name);
658#endif
659 }

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

◆ botan_pubkey_load_ecdsa()

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

Definition at line 478 of file ffi_pkey_algs.cpp.

482 {
483#if defined(BOTAN_HAS_ECDSA)
484 return ffi_guard_thunk(__func__, [=]() -> int {
485 std::unique_ptr<Botan::ECDSA_PublicKey> p_key;
486
487 int rc = pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name);
488 if(rc == BOTAN_FFI_SUCCESS)
489 *key = new botan_pubkey_struct(std::move(p_key));
490
491 return rc;
492 });
493#else
494 BOTAN_UNUSED(key, public_x, public_y, curve_name);
496#endif
497 }

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

◆ botan_pubkey_load_ed25519()

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

Definition at line 791 of file ffi_pkey_algs.cpp.

793 {
794#if defined(BOTAN_HAS_ED25519)
795 *key = nullptr;
796 return ffi_guard_thunk(__func__, [=]() -> int {
797 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
798 auto ed25519 = std::make_unique<Botan::Ed25519_PublicKey>(pubkey_vec);
799 *key = new botan_pubkey_struct(std::move(ed25519));
800 return BOTAN_FFI_SUCCESS;
801 });
802#else
803 BOTAN_UNUSED(key, pubkey);
805#endif
806 }

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

◆ botan_pubkey_load_elgamal()

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

Loads ElGamal public key

Parameters
keyvariable populated with key material
pprime order of a Z_p group
ggroup generator
ypublic key
Precondition
key is NULL on input
Postcondition
function allocates memory and assigns to ‘key’
Returns
0 on success, a negative value on failure

Definition at line 549 of file ffi_pkey_algs.cpp.

551 {
552#if defined(BOTAN_HAS_ELGAMAL)
553 *key = nullptr;
554 return ffi_guard_thunk(__func__, [=]() -> int {
555 Botan::DL_Group group(safe_get(p), safe_get(g));
556 auto elg = std::make_unique<Botan::ElGamal_PublicKey>(group, safe_get(y));
557 *key = new botan_pubkey_struct(std::move(elg));
558 return BOTAN_FFI_SUCCESS;
559 });
560#else
561 BOTAN_UNUSED(key, p, g, y);
563#endif
564 }

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

◆ botan_pubkey_load_rsa()

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

Definition at line 304 of file ffi_pkey_algs.cpp.

306 {
307#if defined(BOTAN_HAS_RSA)
308 *key = nullptr;
309 return ffi_guard_thunk(__func__, [=]() -> int {
310 auto rsa = std::make_unique<Botan::RSA_PublicKey>(safe_get(n), safe_get(e));
311 *key = new botan_pubkey_struct(std::move(rsa));
312 return BOTAN_FFI_SUCCESS;
313 });
314#else
315 BOTAN_UNUSED(key, n, e);
317#endif
318 }

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

◆ botan_pubkey_load_sm2()

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

Definition at line 717 of file ffi_pkey_algs.cpp.

721 {
722#if defined(BOTAN_HAS_SM2)
723 return ffi_guard_thunk(__func__, [=]() -> int {
724 std::unique_ptr<Botan::SM2_PublicKey> p_key;
725 if(!pubkey_load_ec(p_key, safe_get(public_x), safe_get(public_y), curve_name))
726 {
727 *key = new botan_pubkey_struct(std::move(p_key));
728 return BOTAN_FFI_SUCCESS;
729 }
731 });
732#else
733 BOTAN_UNUSED(key, public_x, public_y, curve_name);
735#endif
736 }

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

Referenced by botan_pubkey_load_sm2_enc().

◆ botan_pubkey_load_sm2_enc()

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

Definition at line 757 of file ffi_pkey_algs.cpp.

761 {
762 return botan_pubkey_load_sm2(key, public_x, public_y, curve_name);
763 }
int botan_pubkey_load_sm2(botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)

References botan_pubkey_load_sm2().

◆ botan_pubkey_load_x25519()

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

Definition at line 875 of file ffi_pkey_algs.cpp.

877 {
878#if defined(BOTAN_HAS_X25519)
879 *key = nullptr;
880 return ffi_guard_thunk(__func__, [=]() -> int {
881 const std::vector<uint8_t> pubkey_vec(pubkey, pubkey + 32);
882 auto x25519 = std::make_unique<Botan::X25519_PublicKey>(pubkey_vec);
883 *key = new botan_pubkey_struct(std::move(x25519));
884 return BOTAN_FFI_SUCCESS;
885 });
886#else
887 BOTAN_UNUSED(key, pubkey);
889#endif
890 }

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

◆ botan_pubkey_rsa_get_e()

int botan_pubkey_rsa_get_e ( botan_mp_t  e,
botan_pubkey_t  rsa_key 
)

Definition at line 345 of file ffi_pkey_algs.cpp.

346 {
347 return botan_pubkey_get_field(e, key, "e");
348 }

References botan_pubkey_get_field().

◆ botan_pubkey_rsa_get_n()

int botan_pubkey_rsa_get_n ( botan_mp_t  n,
botan_pubkey_t  rsa_key 
)

Definition at line 350 of file ffi_pkey_algs.cpp.

351 {
352 return botan_pubkey_get_field(n, key, "n");
353 }

References botan_pubkey_get_field().

◆ botan_pubkey_sm2_compute_za()

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

Definition at line 681 of file ffi_pkey_algs.cpp.

686 {
687 if(out == nullptr || out_len == nullptr)
689 if(ident == nullptr || hash_algo == nullptr || key == nullptr)
691
692#if defined(BOTAN_HAS_SM2)
693 return ffi_guard_thunk(__func__, [=]() -> int {
694 const Botan::Public_Key& pub_key = safe_get(key);
695 const Botan::EC_PublicKey* ec_key = dynamic_cast<const Botan::EC_PublicKey*>(&pub_key);
696
697 if(ec_key == nullptr)
699
700 if(ec_key->algo_name() != "SM2")
702
703 const std::string ident_str(ident);
704 std::unique_ptr<Botan::HashFunction> hash =
706
707 const std::vector<uint8_t> za =
708 Botan::sm2_compute_za(*hash, ident_str, ec_key->domain(), ec_key->public_point());
709
710 return write_vec_output(out, out_len, za);
711 });
712#else
714#endif
715 }
const EC_Group & domain() const
Definition: ecc_key.h:56
const PointGFp & public_point() const
Definition: ecc_key.h:41
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:312
virtual std::string algo_name() const =0
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, const std::string &user_id, const EC_Group &domain, const PointGFp &pubkey)
Definition: sm2.cpp:57

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

◆ botan_pubkey_x25519_get_pubkey()

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

Definition at line 916 of file ffi_pkey_algs.cpp.

918 {
919#if defined(BOTAN_HAS_X25519)
920 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
921 if(Botan::X25519_PublicKey* x25519 = dynamic_cast<Botan::X25519_PublicKey*>(&k))
922 {
923 const std::vector<uint8_t>& x25519_key = x25519->public_value();
924 if(x25519_key.size() != 32)
926 Botan::copy_mem(output, x25519_key.data(), x25519_key.size());
927 return BOTAN_FFI_SUCCESS;
928 }
929 else
930 {
932 }
933 });
934#else
935 BOTAN_UNUSED(key, output);
937#endif
938 }

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

◆ botan_pwdhash()

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

Definition at line 51 of file ffi_kdf.cpp.

62 {
63 if(algo == nullptr || password == nullptr)
65
66 if(password_len == 0)
67 password_len = std::strlen(password);
68
69 return ffi_guard_thunk(__func__, [=]() -> int {
70 auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
71
72 if(!pwdhash_fam)
74
75 auto pwdhash = pwdhash_fam->from_params(param1, param2, param3);
76
77 pwdhash->derive_key(out, out_len,
78 password, password_len,
79 salt, salt_len);
80
81 return BOTAN_FFI_SUCCESS;
82 });
83 }
static std::unique_ptr< PasswordHashFamily > create(const std::string &algo_spec, const std::string &provider="")
Definition: pwdhash.cpp:49

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

Referenced by botan_pbkdf().

◆ botan_pwdhash_timed()

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

Definition at line 85 of file ffi_kdf.cpp.

97 {
98 if(algo == nullptr || password == nullptr)
100
101 if(password_len == 0)
102 password_len = std::strlen(password);
103
104 return ffi_guard_thunk(__func__, [=]() -> int {
105
106 auto pwdhash_fam = Botan::PasswordHashFamily::create(algo);
107
108 if(!pwdhash_fam)
110
111 auto pwdhash = pwdhash_fam->tune(out_len, std::chrono::milliseconds(msec));
112
113 if(param1)
114 *param1 = pwdhash->iterations();
115 if(param2)
116 *param2 = pwdhash->parallelism();
117 if(param3)
118 *param3 = pwdhash->memory_param();
119
120 pwdhash->derive_key(out, out_len,
121 password, password_len,
122 salt, salt_len);
123
124 return BOTAN_FFI_SUCCESS;
125 });
126 }

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

Referenced by botan_pbkdf_timed().

◆ botan_rng_add_entropy()

int botan_rng_add_entropy ( botan_rng_t  rng,
const uint8_t *  entropy,
size_t  entropy_len 
)

Add some seed material to a random number generator

Parameters
rngrng object
entropythe data to add
entropy_lenlength of entropy buffer
Returns
0 on success, a negative value on failure

Definition at line 178 of file ffi_rng.cpp.

179 {
180 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.add_entropy(input, len); });
181 }
virtual void add_entropy(const uint8_t input[], size_t length)=0

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

◆ botan_rng_destroy()

int botan_rng_destroy ( botan_rng_t  rng)

Frees all resources of the random number generator object

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

Definition at line 163 of file ffi_rng.cpp.

164 {
165 return BOTAN_FFI_CHECKED_DELETE(rng);
166 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_rng_get()

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

Get random bytes from a random number generator

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

Definition at line 168 of file ffi_rng.cpp.

169 {
170 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.randomize(out, out_len); });
171 }
virtual void randomize(uint8_t output[], size_t length)=0

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

◆ botan_rng_init()

int botan_rng_init ( botan_rng_t rng,
const char *  rng_type 
)

Initialize a random number generator object

Parameters
rngrng object
rng_typetype of the rng, possible values: "system": system RNG "user": userspace RNG "user-threadsafe": userspace RNG, with internal locking "rdrand": directly read RDRAND Set rng_type to null to let the library choose some default.

Definition at line 24 of file ffi_rng.cpp.

25 {
26 return ffi_guard_thunk(__func__, [=]() -> int {
27 if(rng_out == nullptr)
29
30 const std::string rng_type_s(rng_type ? rng_type : "system");
31
32 std::unique_ptr<Botan::RandomNumberGenerator> rng;
33
34 if(rng_type_s == "system")
35 {
36 rng.reset(new Botan::System_RNG);
37 }
38 else if(rng_type_s == "user" || rng_type_s == "user-threadsafe")
39 {
40 rng.reset(new Botan::AutoSeeded_RNG);
41 }
42 else if(rng_type_s == "null")
43 {
44 rng.reset(new Botan::Null_RNG);
45 }
46#if defined(BOTAN_HAS_PROCESSOR_RNG)
47 else if((rng_type_s == "rdrand" || rng_type_s == "hwrng") && Botan::Processor_RNG::available())
48 {
49 rng.reset(new Botan::Processor_RNG);
50 }
51#endif
52
53 if(!rng)
54 {
56 }
57
58 *rng_out = new botan_rng_struct(std::move(rng));
59 return BOTAN_FFI_SUCCESS;
60 });
61 }
static bool available()

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

◆ botan_rng_init_custom()

int botan_rng_init_custom ( botan_rng_t rng_out,
const char *  rng_name,
void *  context,
int(*)(void *context, uint8_t *out, size_t out_len)  get_cb,
int(*)(void *context, const uint8_t input[], size_t length)  add_entropy_cb,
void(*)(void *context)  destroy_cb 
)

Initialize a custom random number generator from a set of callback functions

Parameters
rng_outrng object to create
rng_namename of the rng
contextAn application-specific context passed to the callback functions
get_cbCallback for getting random bytes from the rng, return 0 for success
add_entropy_cbCallback for adding entropy to the rng, return 0 for success, may be NULL
destroy_cbCallback called when rng is destroyed, may be NULL

Definition at line 63 of file ffi_rng.cpp.

67 {
68 return ffi_guard_thunk(__func__,[=]() -> int {
69 if(rng_out == nullptr)
71
72 if(rng_name == nullptr)
74
75 if(get_cb == nullptr)
77
78 class Custom_RNG : public Botan::RandomNumberGenerator
79 {
80 public:
81 Custom_RNG(const std::string& name, void* context,
82 int(* get_cb)(void* context, uint8_t* out, size_t out_len),
83 int(* add_entropy_cb)(void* context, const uint8_t input[], size_t length),
84 void(* destroy_cb)(void* context)) :
85 m_name(name)
86 {
87 m_context = context;
88 m_get_cb = get_cb;
89 m_add_entropy_cb = add_entropy_cb;
90 m_destroy_cb = destroy_cb;
91 }
92
93 ~Custom_RNG() override
94 {
95 if(m_destroy_cb)
96 {
97 m_destroy_cb(m_context);
98 }
99 }
100
101 Custom_RNG(const Custom_RNG& other) = delete;
102 Custom_RNG(Custom_RNG&& other) = delete;
103 Custom_RNG& operator=(const Custom_RNG& other) = delete;
104 Custom_RNG& operator=(Custom_RNG&& other) = delete;
105
106 void randomize(uint8_t output[], size_t length) override
107 {
108 int rc = m_get_cb(m_context, output, length);
109 if(rc)
110 {
111 throw Botan::Invalid_State("Failed to get random from C callback, rc=" + std::to_string(rc));
112 }
113 }
114
115 bool accepts_input() const override
116 {
117 return m_add_entropy_cb != nullptr;
118 }
119
120 void add_entropy(const uint8_t input[], size_t length) override
121 {
122 if(m_add_entropy_cb == nullptr)
123 {
124 return;
125 }
126
127 int rc = m_add_entropy_cb(m_context, input, length);
128 if(rc)
129 {
130 throw Botan::Invalid_State("Failed to add entropy via C callback, rc=" + std::to_string(rc));
131 }
132 }
133
134 std::string name() const override
135 {
136 return m_name;
137 }
138
139 void clear() override
140 {
141 }
142
143 bool is_seeded() const override
144 {
145 return true;
146 }
147
148 private:
149 std::string m_name;
150 void* m_context;
151 std::function<int(void* context, uint8_t* out, size_t out_len)> m_get_cb;
152 std::function<int(void* context, const uint8_t input[], size_t length)> m_add_entropy_cb;
153 std::function<void(void* context)> m_destroy_cb;
154 };
155
156 std::unique_ptr<Botan::RandomNumberGenerator> rng(new Custom_RNG(rng_name, context, get_cb, add_entropy_cb, destroy_cb));
157
158 *rng_out = new botan_rng_struct(std::move(rng));
159 return BOTAN_FFI_SUCCESS;
160 });
161 }

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

◆ botan_rng_reseed()

int botan_rng_reseed ( botan_rng_t  rng,
size_t  bits 
)

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

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

Definition at line 173 of file ffi_rng.cpp.

174 {
176 }
virtual void reseed_from_rng(RandomNumberGenerator &rng, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS)
Definition: rng.cpp:59

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

◆ botan_rng_reseed_from_rng()

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

Reseed a random number generator

Parameters
rngrng object
source_rngthe rng that will be read from
bitsnumber of bits to reseed with
Returns
0 on success, a negative value on failure

Definition at line 183 of file ffi_rng.cpp.

184 {
185 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.reseed_from_rng(safe_get(source_rng), bits); });
186 }

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

◆ botan_same_mem()

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

Deprecated equivalent to botan_constant_time_compare

Definition at line 260 of file ffi.cpp.

261 {
262 return botan_constant_time_compare(x, y, len);
263 }
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition: ffi.cpp:255

References botan_constant_time_compare().

◆ botan_scrub_mem()

int botan_scrub_mem ( void *  mem,
size_t  bytes 
)

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

Definition at line 265 of file ffi.cpp.

266 {
267 Botan::secure_scrub_memory(mem, bytes);
268 return BOTAN_FFI_SUCCESS;
269 }
void secure_scrub_memory(void *ptr, size_t n)
Definition: os_utils.cpp:81

References BOTAN_FFI_SUCCESS, and Botan::secure_scrub_memory().

◆ botan_scrypt()

int botan_scrypt ( uint8_t  out[],
size_t  out_len,
const char *  passphrase,
const uint8_t  salt[],
size_t  salt_len,
size_t  N,
size_t  r,
size_t  p 
)

Derive a key using scrypt Deprecated; use botan_pwdhash("Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);

Definition at line 141 of file ffi_kdf.cpp.

145 {
146 return botan_pwdhash("Scrypt", N, r, p,
147 out, out_len,
148 password, 0,
149 salt, salt_len);
150 }

◆ botan_srp6_client_agree()

int botan_srp6_client_agree ( const char *  username,
const char *  password,
const char *  group_id,
const char *  hash_id,
const uint8_t  salt[],
size_t  salt_len,
const uint8_t  B[],
size_t  B_len,
botan_rng_t  rng_obj,
uint8_t  A[],
size_t *  A_len,
uint8_t  K[],
size_t *  K_len 
)

SRP6a Client side

Parameters
usernamethe username we are attempting login for
passwordthe password we are attempting to use
group_idspecifies the shared SRP group
hash_idspecifies a secure hash function
saltis the salt value sent by the server
Bis the server's public value
B_lenis the server's public value length
rng_objis a random number generator object
Aout buffer to store the SRP-6 A value
A_lenSRP-6 A verifier value length
Kout buffer to store the symmetric value
K_lensymmetric key length
Returns
0 on success, negative on failure

Definition at line 117 of file ffi_srp6.cpp.

123 {
124 return ffi_guard_thunk(__func__, [=]() -> int
125 {
126 if(!identity || !password || !salt || !group_id || !hash_id || !b || !rng_obj)
127 {
129 }
130 try
131 {
132 std::vector<uint8_t> saltv(salt, salt + salt_len);
134 auto b_bn = Botan::BigInt::decode(b, b_len);
135 auto [A_bn, K_sk] = Botan::srp6_client_agree(
136 identity, password, group_id, hash_id, saltv, b_bn, rng);
137 auto ret_a = write_vec_output(A, A_len, Botan::BigInt::encode(A_bn));
138 auto ret_k = write_vec_output(K, K_len, K_sk.bits_of());
139 if(ret_a != BOTAN_FFI_SUCCESS)
140 {
141 return ret_a;
142 }
143 if(ret_k != BOTAN_FFI_SUCCESS)
144 {
145 return ret_k;
146 }
147 return BOTAN_FFI_SUCCESS;
148 }
149 catch(Botan::Lookup_Error&)
150 {
152 }
153 });
154 }
static BigInt decode(const uint8_t buf[], size_t length)
Definition: bigint.h:790
std::pair< BigInt, SymmetricKey > srp6_client_agree(const std::string &identifier, const std::string &password, const std::string &group_id, const std::string &hash_id, const std::vector< uint8_t > &salt, const BigInt &B, RandomNumberGenerator &rng)
Definition: srp6.cpp:73

References b, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::BigInt::decode(), Botan::BigInt::encode(), Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), salt_len, Botan::srp6_client_agree(), and Botan_FFI::write_vec_output().

◆ botan_srp6_server_session_destroy()

int botan_srp6_server_session_destroy ( botan_srp6_server_session_t  srp6)

Frees all resources of the SRP-6 server session object

Parameters
srp6SRP-6 server session object
Returns
0 if success, error if invalid object handle

Definition at line 32 of file ffi_srp6.cpp.

33 {
34 return BOTAN_FFI_CHECKED_DELETE(srp6);
35 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_srp6_server_session_init()

int botan_srp6_server_session_init ( botan_srp6_server_session_t srp6)

Initialize an SRP-6 server session object

Parameters
srp6SRP-6 server session object

Definition at line 22 of file ffi_srp6.cpp.

23 {
24 return ffi_guard_thunk(__func__, [=]() -> int
25 {
26 *srp6 = new botan_srp6_server_session_struct(
27 std::make_unique<Botan::SRP6_Server_Session>());
28 return BOTAN_FFI_SUCCESS;
29 });
30 }

References BOTAN_FFI_SUCCESS, and Botan_FFI::ffi_guard_thunk().

◆ botan_srp6_server_session_step1()

int botan_srp6_server_session_step1 ( botan_srp6_server_session_t  srp6,
const uint8_t  verifier[],
size_t  verifier_len,
const char *  group_id,
const char *  hash_id,
botan_rng_t  rng_obj,
uint8_t  B_pub[],
size_t *  B_pub_len 
)

SRP-6 Server side step 1

Parameters
srp6SRP-6 server session object
verifierthe verification value saved from client registration
group_idthe SRP group id
hash_idthe SRP hash in use
rng_obja random number generator object
B_pubout buffer to store the SRP-6 B value
B_pub_lenSRP-6 B value length
Returns
0 on success, negative on failure

◆ botan_srp6_server_session_step2()

int botan_srp6_server_session_step2 ( botan_srp6_server_session_t  srp6,
const uint8_t  A[],
size_t  A_len,
uint8_t  key[],
size_t *  key_len 
)

SRP-6 Server side step 2

Parameters
srp6SRP-6 server session object
Athe client's value
A_lenthe client's value length
keyout buffer to store the symmetric key value
key_lensymmetric key length
Returns
0 on success, negative on failure

Definition at line 68 of file ffi_srp6.cpp.

71 {
73 {
74 if(!a)
75 {
77 }
78 try
79 {
80 Botan::BigInt a_bn = Botan::BigInt::decode(a, a_len);
81 auto key_sk = s.step2(a_bn);
82 return write_vec_output(key, key_len, key_sk.bits_of());
83 }
85 {
87 }
88 });
89 }

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NULL_POINTER, Botan::BigInt::decode(), and Botan_FFI::write_vec_output().

◆ botan_totp_check()

int botan_totp_check ( botan_totp_t  totp,
uint32_t  totp_code,
uint64_t  timestamp,
size_t  acceptable_clock_drift 
)

Verify a TOTP code

Parameters
totpthe TOTP object
totp_codethe presented OTP
timestampthe current local timestamp
acceptable_clock_driftspecifies the acceptable amount of clock drift (in terms of time steps) between the two hosts.

Definition at line 76 of file ffi_totp.cpp.

80 {
81#if defined(BOTAN_HAS_TOTP)
82 return BOTAN_FFI_RETURNING(Botan::TOTP, totp, t, {
83 const bool ok = t.verify_totp(totp_code, timestamp, acceptable_clock_drift);
85 });
86
87#else
88 BOTAN_UNUSED(totp, totp_code, timestamp, acceptable_clock_drift);
90#endif
91 }
bool verify_totp(uint32_t otp, std::chrono::system_clock::time_point time, size_t clock_drift_accepted=0)
Definition: totp.cpp:39

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

◆ botan_totp_destroy()

int botan_totp_destroy ( botan_totp_t  totp)

Destroy a TOTP instance

Returns
0 if success, error if invalid object handle

Definition at line 48 of file ffi_totp.cpp.

49 {
50#if defined(BOTAN_HAS_TOTP)
51 return BOTAN_FFI_CHECKED_DELETE(totp);
52#else
53 BOTAN_UNUSED(totp);
55#endif
56 }

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_totp_generate()

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

Generate a TOTP code for the provided timestamp

Parameters
totpthe TOTP object
totp_codethe OTP code will be written here
timestampthe current local timestamp

Definition at line 58 of file ffi_totp.cpp.

61 {
62#if defined(BOTAN_HAS_TOTP)
63 if(totp == nullptr || totp_code == nullptr)
65
66 return BOTAN_FFI_DO(Botan::TOTP, totp, t, {
67 *totp_code = t.generate_totp(timestamp);
68 });
69
70#else
71 BOTAN_UNUSED(totp, totp_code, timestamp);
73#endif
74 }
uint32_t generate_totp(std::chrono::system_clock::time_point time_point)
Definition: totp.cpp:27

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

◆ botan_totp_init()

int botan_totp_init ( botan_totp_t totp,
const uint8_t  key[],
size_t  key_len,
const char *  hash_algo,
size_t  digits,
size_t  time_step 
)

Initialize a TOTP instance

Definition at line 24 of file ffi_totp.cpp.

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

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

◆ botan_version_datestamp()

uint32_t botan_version_datestamp ( void  )

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

Definition at line 253 of file ffi.cpp.

253{ return Botan::version_datestamp(); }
uint32_t version_datestamp()
Definition: version.cpp:75

References Botan::version_datestamp().

◆ botan_version_major()

uint32_t botan_version_major ( void  )

Return the major version of the library

Definition at line 250 of file ffi.cpp.

250{ return Botan::version_major(); }
uint32_t version_major()
Definition: version.cpp:80

References Botan::version_major().

◆ botan_version_minor()

uint32_t botan_version_minor ( void  )

Return the minor version of the library

Definition at line 251 of file ffi.cpp.

251{ return Botan::version_minor(); }
uint32_t version_minor()
Definition: version.cpp:81

References Botan::version_minor().

◆ botan_version_patch()

uint32_t botan_version_patch ( void  )

Return the patch version of the library

Definition at line 252 of file ffi.cpp.

252{ return Botan::version_patch(); }
uint32_t version_patch()
Definition: version.cpp:82

References Botan::version_patch().

◆ botan_version_string()

const char * botan_version_string ( void  )

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

Definition at line 245 of file ffi.cpp.

246 {
247 return Botan::version_cstr();
248 }
const char * version_cstr()
Definition: version.cpp:33

References Botan::version_cstr().

◆ botan_x509_cert_allowed_usage()

int botan_x509_cert_allowed_usage ( botan_x509_cert_t  cert,
unsigned int  key_usage 
)

Definition at line 136 of file ffi_cert.cpp.

137 {
138#if defined(BOTAN_HAS_X509_CERTIFICATES)
140 const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
141 if(c.allowed_usage(k))
142 return BOTAN_FFI_SUCCESS;
143 return 1;
144 });
145#else
146 BOTAN_UNUSED(cert, key_usage);
148#endif
149 }
Key_Constraints
Definition: pkix_enums.h:102

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_RETURNING, BOTAN_FFI_SUCCESS, and BOTAN_UNUSED.

◆ botan_x509_cert_destroy()

int botan_x509_cert_destroy ( botan_x509_cert_t  cert)
Returns
0 if success, error if invalid object handle

Definition at line 151 of file ffi_cert.cpp.

152 {
153#if defined(BOTAN_HAS_X509_CERTIFICATES)
154 return BOTAN_FFI_CHECKED_DELETE(cert);
155#else
156 BOTAN_UNUSED(cert);
158#endif
159 }

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_cert_dup()

int botan_x509_cert_dup ( botan_x509_cert_t new_cert,
botan_x509_cert_t  cert 
)

Definition at line 46 of file ffi_cert.cpp.

47 {
48 if(!cert_obj)
50
51#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
52
53 return ffi_guard_thunk(__func__, [=]() -> int {
54 std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(safe_get(cert)));
55 *cert_obj = new botan_x509_cert_struct(std::move(c));
56 return BOTAN_FFI_SUCCESS;
57 });
58
59#else
60 BOTAN_UNUSED(cert);
62#endif
63 }

References