Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Macros | Functions
ffi.cpp File Reference
`#include <botan/ffi.h>`
`#include <botan/system_rng.h>`
`#include <botan/exceptn.h>`
`#include <botan/auto_rng.h>`
`#include <botan/aead.h>`
`#include <botan/block_cipher.h>`
`#include <botan/hash.h>`
`#include <botan/mac.h>`
`#include <botan/pbkdf.h>`
`#include <botan/version.h>`
`#include <botan/pkcs8.h>`
`#include <botan/x509cert.h>`
`#include <botan/data_src.h>`
`#include <botan/pubkey.h>`
`#include <botan/hex.h>`
`#include <botan/mem_ops.h>`
`#include <botan/x509_key.h>`
`#include <botan/pk_algs.h>`
`#include <botan/bigint.h>`
`#include <botan/reducer.h>`
`#include <botan/numthry.h>`
`#include <botan/divide.h>`
`#include <cstring>`
`#include <memory>`

Go to the source code of this file.

## Macros
#define | BOTAN_ASSERT_ARG_NON_NULL(p) do { if(!p) throw Botan::Invalid_Argument("Argument " #p " is null"); } while(0)
#define | BOTAN_FFI_DECLARE_STRUCT(NAME, TYPE, MAGIC) struct NAME : public botan_struct<TYPE, MAGIC> { explicit NAME(TYPE* x) : botan_struct(x) {} }
#define | BOTAN_FFI_DO(T, obj, param, block) apply_fn(obj, BOTAN_CURRENT_FUNCTION, [=](T& param) -> int { do { block } while(0); return 0; })

## Functions
int | botan_bcrypt_generate (uint8_t *out, size_t *out_len, const char *pass, botan_rng_t rng_obj, size_t wf, uint32_t flags)
int | botan_bcrypt_is_valid (const char *pass, const char *hash)
int | botan_block_cipher_block_size (botan_block_cipher_t bc)
int | botan_block_cipher_clear (botan_block_cipher_t bc)
int | botan_block_cipher_decrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
int | botan_block_cipher_destroy (botan_block_cipher_t bc)
int | botan_block_cipher_encrypt_blocks (botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
int | botan_block_cipher_init (botan_block_cipher_t *bc, const char *bc_name)
int | botan_block_cipher_set_key (botan_block_cipher_t bc, const uint8_t key[], size_t len)
int | botan_cipher_clear (botan_cipher_t cipher)
int | botan_cipher_destroy (botan_cipher_t cipher)
int | botan_cipher_get_default_nonce_length (botan_cipher_t cipher, size_t *nl)
int | botan_cipher_get_tag_length (botan_cipher_t cipher, size_t *tl)
int | botan_cipher_get_update_granularity (botan_cipher_t cipher, size_t *ug)
int | botan_cipher_init (botan_cipher_t *cipher, const char *cipher_name, uint32_t flags)
int | botan_cipher_query_keylen (botan_cipher_t cipher, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
int | botan_cipher_set_associated_data (botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
int | botan_cipher_set_key (botan_cipher_t cipher, const uint8_t *key, size_t key_len)
int | botan_cipher_start (botan_cipher_t cipher_obj, const uint8_t *nonce, size_t nonce_len)
int | botan_cipher_update (botan_cipher_t cipher_obj, uint32_t flags, uint8_t output[], size_t output_size, size_t *output_written, const uint8_t input[], size_t input_size, size_t *input_consumed)
int | botan_cipher_valid_nonce_length (botan_cipher_t cipher, size_t nl)
uint32_t | botan_ffi_api_version ()
| BOTAN_FFI_DECLARE_STRUCT (botan_rng_struct, Botan::RandomNumberGenerator, 0x4901F9C1)
| BOTAN_FFI_DECLARE_STRUCT (botan_mp_struct, Botan::BigInt, 0xC828B9D2)
| BOTAN_FFI_DECLARE_STRUCT (botan_block_cipher_struct, Botan::BlockCipher, 0x64C29716)
| BOTAN_FFI_DECLARE_STRUCT (botan_hash_struct, Botan::HashFunction, 0x1F0A4F84)
| BOTAN_FFI_DECLARE_STRUCT (botan_mac_struct, Botan::MessageAuthenticationCode, 0xA06E8FC1)
| BOTAN_FFI_DECLARE_STRUCT (botan_pubkey_struct, Botan::Public_Key, 0x2C286519)
| BOTAN_FFI_DECLARE_STRUCT (botan_privkey_struct, Botan::Private_Key, 0x7F96385E)
| BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_encrypt_struct, Botan::PK_Encryptor, 0x891F3FC3)
| BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_decrypt_struct, Botan::PK_Decryptor, 0x912F3C37)
| BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_sign_struct, Botan::PK_Signer, 0x1AF0C39F)
| BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_verify_struct, Botan::PK_Verifier, 0x2B91F936)
| BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_ka_struct, Botan::PK_Key_Agreement, 0x2939CAB1)
| BOTAN_FFI_DECLARE_STRUCT (botan_x509_cert_struct, Botan::X509_Certificate, 0x8F628937)
int | botan_ffi_supports_api (uint32_t api_version)
int | botan_hash_clear (botan_hash_t hash)
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_output_length (botan_hash_t hash, size_t *out)
int | botan_hash_update (botan_hash_t hash, const uint8_t *buf, size_t len)
int | botan_hex_encode (const uint8_t *in, size_t len, char *out, uint32_t flags)
int | botan_kdf (const char *kdf_algo, uint8_t out[], size_t out_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len)
int | botan_mac_clear (botan_mac_t mac)
int | botan_mac_destroy (botan_mac_t mac)
int | botan_mac_final (botan_mac_t mac, uint8_t out[])
int | botan_mac_init (botan_mac_t *mac, const char *mac_name, uint32_t flags)
int | botan_mac_output_length (botan_mac_t mac, size_t *out)
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_obj, const char *aead, const uint8_t ct[], size_t ct_len, const uint8_t ad[], size_t ad_len, uint8_t out[], size_t *out_len)
int | botan_mceies_encrypt (botan_pubkey_t mce_key_obj, botan_rng_t rng_obj, const char *aead, const uint8_t pt[], size_t pt_len, const uint8_t ad[], size_t ad_len, uint8_t out[], size_t *out_len)
int | botan_mp_add (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_clear (botan_mp_t mp)
int | botan_mp_clear_bit (botan_mp_t mp, size_t bit)
int | botan_mp_cmp (int *result, const botan_mp_t x_w, const botan_mp_t y_w)
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_w, const botan_mp_t y_w)
int | botan_mp_flip_sign (botan_mp_t mp)
int | botan_mp_from_bin (botan_mp_t mp, const uint8_t bin[], size_t bin_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 mp, 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 mp, 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 out, const botan_mp_t x, const botan_mp_t y, const botan_mp_t modulus)
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 mp, size_t *bits)
int | botan_mp_num_bytes (const botan_mp_t mp, 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, const botan_mp_t upper)
int | botan_mp_rshift (botan_mp_t out, const botan_mp_t in, size_t shift)
int | botan_mp_set_bit (botan_mp_t mp, 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 mp, const char *str, size_t radix)
int | botan_mp_set_from_str (botan_mp_t mp, const char *str)
int | botan_mp_sub (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_swap (botan_mp_t x_w, botan_mp_t y_w)
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 digit_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 *pass, 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 *password, const uint8_t salt[], size_t salt_len, size_t ms_to_run, size_t *iterations_used)
int | botan_pk_op_decrypt (botan_pk_op_decrypt_t op, uint8_t out[], size_t *out_len, uint8_t ciphertext[], size_t ciphertext_len)
int | botan_pk_op_decrypt_create (botan_pk_op_decrypt_t *op, botan_privkey_t key_obj, const char *padding, uint32_t flags)
int | botan_pk_op_decrypt_destroy (botan_pk_op_decrypt_t op)
int | botan_pk_op_encrypt (botan_pk_op_encrypt_t op, botan_rng_t rng_obj, 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_obj, const char *padding, uint32_t flags)
int | botan_pk_op_encrypt_destroy (botan_pk_op_encrypt_t op)
int | botan_pk_op_key_agreement (botan_pk_op_ka_t op, uint8_t out[], size_t *out_len, const uint8_t other_key[], size_t other_key_len, const uint8_t salt[], size_t salt_len)
int | botan_pk_op_key_agreement_create (botan_pk_op_ka_t *op, botan_privkey_t key_obj, const char *kdf, uint32_t flags)
int | botan_pk_op_key_agreement_destroy (botan_pk_op_ka_t op)
int | botan_pk_op_key_agreement_export_public (botan_privkey_t key, uint8_t out[], size_t *out_len)
int | botan_pk_op_sign_create (botan_pk_op_sign_t *op, botan_privkey_t key_obj, const char *hash, 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_obj, uint8_t out[], size_t *out_len)
int | botan_pk_op_sign_update (botan_pk_op_sign_t op, const uint8_t in[], size_t in_len)
int | botan_pk_op_verify_create (botan_pk_op_verify_t *op, botan_pubkey_t key_obj, const char *hash, 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_privkey_check_key (botan_privkey_t key, botan_rng_t rng, uint32_t flags)
int | botan_privkey_create (botan_privkey_t *key_obj, const char *algo_name, const char *algo_params, botan_rng_t rng_obj)
int | botan_privkey_create_ecdh (botan_privkey_t *key_obj, botan_rng_t rng_obj, const char *param_str)
int | botan_privkey_create_ecdsa (botan_privkey_t *key_obj, botan_rng_t rng_obj, const char *param_str)
int | botan_privkey_create_mceliece (botan_privkey_t *key_obj, botan_rng_t rng_obj, size_t n, size_t t)
int | botan_privkey_create_rsa (botan_privkey_t *key_obj, botan_rng_t rng_obj, size_t n_bits)
int | botan_privkey_destroy (botan_privkey_t key)
int | botan_privkey_dsa_get_x (botan_mp_t x, botan_privkey_t key)
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_obj, const char *pass, const char *, 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_obj, const char *pass, size_t pbkdf_iter, const char *maybe_cipher, const char *maybe_pbkdf_hash, 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_obj, const char *pass, uint32_t pbkdf_msec, size_t *pbkdf_iters_out, const char *maybe_cipher, const char *maybe_pbkdf_hash, uint32_t flags)
int | botan_privkey_export_pubkey (botan_pubkey_t *pubout, botan_privkey_t key_obj)
int | botan_privkey_get_field (botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
int | botan_privkey_load (botan_privkey_t *key, botan_rng_t rng_obj, const uint8_t bits[], size_t len, const char *password)
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_rsa (botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t d)
int | botan_privkey_rsa_get_d (botan_mp_t d, botan_privkey_t key)
int | botan_privkey_rsa_get_e (botan_mp_t e, botan_privkey_t key)
int | botan_privkey_rsa_get_n (botan_mp_t n, botan_privkey_t key)
int | botan_privkey_rsa_get_p (botan_mp_t p, botan_privkey_t key)
int | botan_privkey_rsa_get_q (botan_mp_t q, botan_privkey_t key)
int | botan_pubkey_algo_name (botan_pubkey_t key, char out[], size_t *out_len)
int | botan_pubkey_check_key (botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
int | botan_pubkey_destroy (botan_pubkey_t key)
int | botan_pubkey_dsa_get_g (botan_mp_t g, 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_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_fn, uint8_t out[], size_t *out_len)
int | botan_pubkey_get_field (botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
int | botan_pubkey_load (botan_pubkey_t *key, const uint8_t bits[], size_t bits_len)
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_rsa (botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
int | botan_pubkey_rsa_get_e (botan_mp_t e, botan_pubkey_t key)
int | botan_pubkey_rsa_get_n (botan_mp_t n, botan_pubkey_t key)
int | botan_rng_destroy (botan_rng_t rng)
int | botan_rng_get (botan_rng_t rng, uint8_t *out, size_t out_len)
int | botan_rng_init (botan_rng_t *rng_out, const char *rng_type)
int | botan_rng_reseed (botan_rng_t rng, size_t bits)
int | botan_same_mem (const uint8_t *x, const uint8_t *y, size_t len)
uint32_t | botan_version_datestamp ()
uint32_t | botan_version_major ()
uint32_t | botan_version_minor ()
uint32_t | botan_version_patch ()
const char * | botan_version_string ()
int | botan_x509_cert_allowed_usage (botan_x509_cert_t cert, unsigned int key_usage)
int | botan_x509_cert_destroy (botan_x509_cert_t cert)
int | botan_x509_cert_get_authority_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_fingerprint (botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_issuer_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_public_key (botan_x509_cert_t cert, botan_pubkey_t *key)
int | botan_x509_cert_get_public_key_bits (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_serial_number (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_subject_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_subject_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int | botan_x509_cert_get_time_expires (botan_x509_cert_t cert, char out[], size_t *out_len)
int | botan_x509_cert_get_time_starts (botan_x509_cert_t cert, char out[], size_t *out_len)
int | botan_x509_cert_load (botan_x509_cert_t *cert_obj, const uint8_t cert_bits[], size_t cert_bits_len)
int | botan_x509_cert_load_file (botan_x509_cert_t *cert_obj, const char *cert_path)
int | botan_x509_cert_to_string (botan_x509_cert_t cert, char out[], size_t *out_len)

## Macro Definition Documentation

#define BOTAN_ASSERT_ARG_NON_NULL | ( |  | p | ) | do { if(!p) throw Botan::Invalid_Argument("Argument " #p " is null"); } while(0)

Definition at line 79 of file ffi.cpp.

Referenced by botan_bcrypt_generate(), and botan_rng_init().

#define BOTAN_FFI_DECLARE_STRUCT | ( |  | NAME,
|  |  | TYPE,
|  |  | MAGIC
| ) |  | struct NAME : public botan_struct<TYPE, MAGIC> { explicit NAME(TYPE* x) : botan_struct(x) {} }

Definition at line 210 of file ffi.cpp.

#define BOTAN_FFI_DO | ( |  | T,
|  |  | obj,
|  |  | param,
|  |  | block
| ) |  | apply_fn(obj, BOTAN_CURRENT_FUNCTION, [=](T& param) -> int { do { block } while(0); return 0; })

Definition at line 204 of file ffi.cpp.

Referenced by botan_block_cipher_block_size(), botan_block_cipher_clear(), botan_block_cipher_decrypt_blocks(), botan_block_cipher_encrypt_blocks(), botan_block_cipher_set_key(), botan_cipher_clear(), botan_cipher_get_default_nonce_length(), botan_cipher_get_tag_length(), botan_cipher_get_update_granularity(), botan_cipher_query_keylen(), botan_cipher_set_associated_data(), botan_cipher_set_key(), botan_cipher_valid_nonce_length(), botan_hash_clear(), botan_hash_final(), botan_hash_output_length(), botan_hash_update(), botan_mac_clear(), botan_mac_final(), botan_mac_output_length(), botan_mac_set_key(), botan_mac_update(), botan_mp_add(), botan_mp_clear(), botan_mp_clear_bit(), botan_mp_cmp(), botan_mp_div(), botan_mp_equal(), botan_mp_flip_sign(), botan_mp_from_bin(), botan_mp_gcd(), botan_mp_get_bit(), botan_mp_is_even(), botan_mp_is_negative(), botan_mp_is_odd(), botan_mp_is_positive(), botan_mp_is_prime(), botan_mp_is_zero(), botan_mp_lshift(), botan_mp_mod_inverse(), botan_mp_mod_mul(), botan_mp_mul(), botan_mp_num_bits(), botan_mp_num_bytes(), botan_mp_powmod(), botan_mp_rand_bits(), botan_mp_rand_range(), botan_mp_rshift(), botan_mp_set_bit(), botan_mp_set_from_int(), botan_mp_set_from_mp(), botan_mp_set_from_radix_str(), botan_mp_set_from_str(), botan_mp_sub(), botan_mp_swap(), botan_mp_to_bin(), botan_mp_to_hex(), botan_mp_to_str(), botan_mp_to_uint32(), botan_pk_op_decrypt(), botan_pk_op_encrypt(), botan_pk_op_key_agreement(), botan_pk_op_key_agreement_export_public(), botan_pk_op_sign_finish(), botan_pk_op_sign_update(), botan_pk_op_verify_finish(), botan_pk_op_verify_update(), botan_privkey_check_key(), botan_privkey_export(), botan_privkey_export_encrypted_pbkdf_iter(), botan_privkey_export_encrypted_pbkdf_msec(), botan_privkey_get_field(), botan_pubkey_algo_name(), botan_pubkey_check_key(), botan_pubkey_estimated_strength(), botan_pubkey_export(), botan_pubkey_fingerprint(), botan_pubkey_get_field(), botan_rng_get(), botan_rng_reseed(), botan_x509_cert_allowed_usage(), botan_x509_cert_get_authority_key_id(), botan_x509_cert_get_fingerprint(), botan_x509_cert_get_issuer_dn(), botan_x509_cert_get_public_key_bits(), botan_x509_cert_get_serial_number(), botan_x509_cert_get_subject_dn(), botan_x509_cert_get_subject_key_id(), botan_x509_cert_get_time_expires(), botan_x509_cert_get_time_starts(), and botan_x509_cert_to_string().

## Function Documentation

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

Create a password hash using Bcrypt

Parameters

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

Returns
  0 on success, a negative value on failure

Output is formatted bcrypt $2a$...

Definition at line 1053 of file ffi.cpp.

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

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

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

Check a previously created password hash

Parameters

  pass | the password to check against
  hash | the stored hash to check against

Returns
  0 if if this password/hash combination is valid, 1 if the combination is not valid (but otherwise well formed), negative on error

Definition at line 1090 of file ffi.cpp.

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

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

int botan_block_cipher_block_size | ( | botan_block_cipher_t | bc | ) |

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

Definition at line 652 of file ffi.cpp.

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

653 {
654 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { return b.block_size(); });
655 }
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::BlockCipher::block_size
virtual size_t block_size() const =0
Botan::BlockCipher
Definition: block_cipher.h:19

int botan_block_cipher_clear | ( | botan_block_cipher_t | bc | ) |

Reinitializes the block cipher

Returns
  0 on success, a negative value on failure

Definition at line 634 of file ffi.cpp.

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

635 {
636 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.clear(); });
637 }
Botan::SymmetricAlgorithm::clear
virtual void clear()=0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::BlockCipher
Definition: block_cipher.h:19

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

Definition at line 665 of file ffi.cpp.

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

669 {
670 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.decrypt_n(in, out, blocks); });
671 }
Botan::BlockCipher::decrypt_n
virtual void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::BlockCipher
Definition: block_cipher.h:19

int botan_block_cipher_destroy | ( | botan_block_cipher_t | bc | ) |

Destroy a block cipher object

Definition at line 628 of file ffi.cpp.

629 {
630 delete bc;
631 return 0;
632 }

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

Definition at line 657 of file ffi.cpp.

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

661 {
662 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.encrypt_n(in, out, blocks); });
663 }
Botan::BlockCipher::encrypt_n
virtual void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::BlockCipher
Definition: block_cipher.h:19

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

Initialize a block cipher object

Definition at line 598 of file ffi.cpp.

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

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

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

Set the key for a block cipher instance

Definition at line 642 of file ffi.cpp.

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

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

int botan_cipher_clear | ( | botan_cipher_t | cipher | ) |

Definition at line 814 of file ffi.cpp.

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

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

int botan_cipher_destroy | ( | botan_cipher_t | cipher | ) |

Definition at line 808 of file ffi.cpp.

809 {
810 delete cipher;
811 return 0;
812 }

int botan_cipher_get_default_nonce_length | ( | botan_cipher_t | cipher,
|  | size_t * | nl
| ) |  |

Definition at line 977 of file ffi.cpp.

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

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

int botan_cipher_get_tag_length | ( | botan_cipher_t | cipher,
|  | size_t * | tl
| ) |  |

Definition at line 987 of file ffi.cpp.

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

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

int botan_cipher_get_update_granularity | ( | botan_cipher_t | cipher,
|  | size_t * | ug
| ) |  |

Definition at line 982 of file ffi.cpp.

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

983 {
984 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { *ug = c.update_granularity(); });
985 }
Botan::Cipher_Mode::update_granularity
virtual size_t update_granularity() const =0
Botan::Cipher_Mode
Definition: cipher_mode.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 784 of file ffi.cpp.

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

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

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

Definition at line 819 of file ffi.cpp.

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

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

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

Definition at line 958 of file ffi.cpp.

References BOTAN_FFI_DO.

961 {
962 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
963 if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(&c))
964 {
965 aead->set_associated_data(ad, ad_len);
966 return 0;
967 }
968 return -1;
969 });
970 }
Botan::AEAD_Mode
Definition: aead.h:22
Botan::Cipher_Mode
Definition: cipher_mode.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 829 of file ffi.cpp.

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

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

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

Definition at line 835 of file ffi.cpp.

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

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

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

Definition at line 853 of file ffi.cpp.

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

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

int botan_cipher_valid_nonce_length | ( | botan_cipher_t | cipher,
|  | size_t | nl
| ) |  |

Definition at line 972 of file ffi.cpp.

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

973 {
974 return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, { return c.valid_nonce_length(nl) ? 1 : 0; });
975 }
Botan::Cipher_Mode
Definition: cipher_mode.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::Cipher_Mode::valid_nonce_length
virtual bool valid_nonce_length(size_t nonce_len) const =0

uint32_t botan_ffi_api_version | ( |  | ) |

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

Definition at line 242 of file ffi.cpp.

243 {
244 return BOTAN_HAS_FFI;
245 }

BOTAN_FFI_DECLARE_STRUCT | ( | botan_rng_struct | ,
|  | Botan::RandomNumberGenerator | ,
|  | 0x4901F9C1 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_mp_struct | ,
|  | Botan::BigInt | ,
|  | 0xC828B9D2 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_block_cipher_struct | ,
|  | Botan::BlockCipher | ,
|  | 0x64C29716 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_hash_struct | ,
|  | Botan::HashFunction | ,
|  | 0x1F0A4F84 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_mac_struct | ,
|  | Botan::MessageAuthenticationCode | ,
|  | 0xA06E8FC1 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_pubkey_struct | ,
|  | Botan::Public_Key | ,
|  | 0x2C286519 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_privkey_struct | ,
|  | Botan::Private_Key | ,
|  | 0x7F96385E |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_pk_op_encrypt_struct | ,
|  | Botan::PK_Encryptor | ,
|  | 0x891F3FC3 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_pk_op_decrypt_struct | ,
|  | Botan::PK_Decryptor | ,
|  | 0x912F3C37 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_pk_op_sign_struct | ,
|  | Botan::PK_Signer | ,
|  | 0x1AF0C39F |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_pk_op_verify_struct | ,
|  | Botan::PK_Verifier | ,
|  | 0x2B91F936 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_pk_op_ka_struct | ,
|  | Botan::PK_Key_Agreement | ,
|  | 0x2939CAB1 |
| ) |  |

BOTAN_FFI_DECLARE_STRUCT | ( | botan_x509_cert_struct | ,
|  | Botan::X509_Certificate | ,
|  | 0x8F628937 |
| ) |  |

int botan_ffi_supports_api | ( | uint32_t | api_version | ) |

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

Definition at line 247 of file ffi.cpp.

248 {
249 /*
250 * In the future if multiple versions are supported, this
251 * function would accept any of them.
252 */
253 if(api_version == BOTAN_HAS_FFI)
254 return 0;
255 return -1;
256 }

int botan_hash_clear | ( | botan_hash_t | hash | ) |

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

Parameters

  hash | hash object

Returns
  0 on success, a negative value on failure

Definition at line 712 of file ffi.cpp.

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

713 {
714 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.clear(); });
715 }
Botan::HashFunction
Definition: hash.h:19
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

int botan_hash_destroy | ( | botan_hash_t | hash | ) |

Frees all resources of the hash object

Parameters

  hash | hash object

Returns
  always returns 0

Definition at line 701 of file ffi.cpp.

References hash.

702 {
703 delete hash;
704 return 0;
705 }
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

int botan_hash_final | ( | botan_hash_t | hash,
|  | uint8_t | out[]
| ) |  |

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

Parameters

  hash | hash object
  out | output buffer

Returns
  0 on success, a negative value on failure

Definition at line 722 of file ffi.cpp.

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

723 {
724 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.final(out); });
725 }
Botan::HashFunction
Definition: hash.h:19
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

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

Initialize a hash function object

Parameters

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

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

Definition at line 673 of file ffi.cpp.

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

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

int botan_hash_output_length | ( | botan_hash_t | hash,
|  | size_t * | output_length
| ) |  |

Writes the output length of the hash function to *output_length

Parameters

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

Returns
  0 on success, a negative value on failure

Definition at line 707 of file ffi.cpp.

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

708 {
709 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { *out = h.output_length(); });
710 }
Botan::HashFunction
Definition: hash.h:19
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

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

Send more input to the hash function

Parameters

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

Returns
  0 on success, a negative value on failure

Definition at line 717 of file ffi.cpp.

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

718 {
719 return BOTAN_FFI_DO(Botan::HashFunction, hash, h, { h.update(buf, len); });
720 }
Botan::HashFunction
Definition: hash.h:19
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

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

Perform hex encoding

Parameters

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

Returns
  0 on success, 1 on failure

Definition at line 273 of file ffi.cpp.

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

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

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

Derive a key

Parameters

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

Returns
  0 on success, a negative value on failure

Definition at line 1033 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and Botan::get_kdf().

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

int botan_mac_clear | ( | botan_mac_t | mac | ) |

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

Parameters

  mac | mac object

Returns
  0 on success, a negative value on failure

Definition at line 769 of file ffi.cpp.

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

770 {
771 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.clear(); });
772 }
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::SymmetricAlgorithm::clear
virtual void clear()=0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

int botan_mac_destroy | ( | botan_mac_t | mac | ) |

Frees all resources of the MAC object

Parameters

  mac | mac object

Returns
  always returns 0

Definition at line 753 of file ffi.cpp.

754 {
755 delete mac;
756 return 0;
757 }

int botan_mac_final | ( | botan_mac_t | mac,
|  | uint8_t | out[]
| ) |  |

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

Parameters

  mac | mac object
  out | output buffer

Returns
  0 on success, a negative value on failure

Definition at line 779 of file ffi.cpp.

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

780 {
781 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.final(out); });
782 }
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::Buffered_Computation::final
void final(uint8_t out[])
Definition: buf_comp.h:89
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Initialize a message authentication code object

Parameters

  mac | mac object
  mac_name | name of the hash function, e.g., "HMAC(SHA-384)"
  flags | should be 0 in current API revision, all other uses are reserved and return a negative value (error code)

Returns
  0 on success, a negative value on failure

Definition at line 727 of file ffi.cpp.

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

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

int botan_mac_output_length | ( | botan_mac_t | mac,
|  | size_t * | output_length
| ) |  |

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

Parameters

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

Returns
  0 on success, a negative value on failure

Definition at line 764 of file ffi.cpp.

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

765 {
766 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { *out = m.output_length(); });
767 }
Botan::MessageAuthenticationCode
Definition: mac.h:20
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

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

Sets the key on the MAC

Parameters

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

Returns
  0 on success, a negative value on failure

Definition at line 759 of file ffi.cpp.

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

760 {
761 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.set_key(key, key_len); });
762 }
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Send more input to the message authentication code

Parameters

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

Returns
  0 on success, a negative value on failure

Definition at line 774 of file ffi.cpp.

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

775 {
776 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.update(buf, len); });
777 }
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::Buffered_Computation::update
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:34
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

int botan_mceies_decrypt | ( | botan_privkey_t | mce_key_obj,
|  | const char * | aead,
|  | const uint8_t | ct[],
|  | size_t | ct_len,
|  | const uint8_t | ad[],
|  | size_t | ad_len,
|  | uint8_t | out[],
|  | size_t * | out_len
| ) |  |

Definition at line 2208 of file ffi.cpp.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and Botan::mceies_decrypt().

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

int botan_mceies_encrypt | ( | botan_pubkey_t | mce_key_obj,
|  | botan_rng_t | rng_obj,
|  | const char * | aead,
|  | const uint8_t | pt[],
|  | size_t | pt_len,
|  | const uint8_t | ad[],
|  | size_t | ad_len,
|  | uint8_t | out[],
|  | size_t * | out_len
| ) |  |

Definition at line 2235 of file ffi.cpp.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and Botan::mceies_encrypt().

2241 {
2242 try
2243 {
2244 Botan::Public_Key& key = safe_get(mce_key_obj);
2245 Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
2246
2247 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
2248 Botan::McEliece_PublicKey* mce = dynamic_cast<Botan::McEliece_PublicKey*>(&key);
2249 if(!mce)
2250 return -2;
2251
2252 Botan::secure_vector<uint8_t> ct = mceies_encrypt(*mce, pt, pt_len, ad, ad_len, rng, aead);
2253 return write_vec_output(out, out_len, ct);
2254 #else
2255 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
2256 #endif
2257 }
2258 catch(std::exception& e)
2259 {
2260 return ffi_error_exception_thrown(e.what());
2261 }
2262 }
Botan::RandomNumberGenerator
Definition: rng.h:25
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:141
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::mceies_encrypt
secure_vector< uint8_t > mceies_encrypt(const McEliece_PublicKey &pubkey, const uint8_t pt[], size_t pt_len, const uint8_t ad[], size_t ad_len, RandomNumberGenerator &rng, const std::string &algo)
Definition: mceies.cpp:33
Botan::Public_Key
Definition: pk_keys.h:24
Botan::McEliece_PublicKey
Definition: mceliece.h:21

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

Definition at line 460 of file ffi.cpp.

References BOTAN_FFI_DO.

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

int botan_mp_clear | ( | botan_mp_t | mp | ) |

Definition at line 347 of file ffi.cpp.

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

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

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

Clear the specified bit

Definition at line 583 of file ffi.cpp.

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

584 {
585 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.clear_bit(bit); });
586 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::BigInt::clear_bit
void clear_bit(size_t n)
Definition: bigint.cpp:168

int botan_mp_cmp | ( | int * | result,
|  | const botan_mp_t | x_w,
|  | const botan_mp_t | y_w
| ) |  |

Definition at line 506 of file ffi.cpp.

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

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

int botan_mp_destroy | ( | botan_mp_t | mp | ) |

Definition at line 454 of file ffi.cpp.

455 {
456 delete mp;
457 return 0;
458 }

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

Definition at line 475 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::divide().

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

int botan_mp_equal | ( | const botan_mp_t | x_w,
|  | const botan_mp_t | y_w
| ) |  |

Definition at line 486 of file ffi.cpp.

References BOTAN_FFI_DO.

487 {
488 return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { return x == safe_get(y_w); });
489 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

int botan_mp_flip_sign | ( | botan_mp_t | mp | ) |

Definition at line 405 of file ffi.cpp.

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

406 {
407 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.flip_sign(); });
408 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::BigInt::flip_sign
void flip_sign()
Definition: bigint.cpp:226

int botan_mp_from_bin | ( | botan_mp_t | mp,
|  | const uint8_t | bin[],
|  | size_t | bin_len
| ) |  |

Definition at line 410 of file ffi.cpp.

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

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

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

Definition at line 561 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::gcd().

562 {
563 return BOTAN_FFI_DO(Botan::BigInt, out, o, {
564 o = Botan::gcd(safe_get(x), safe_get(y)); });
565 }
Botan::BigInt
Definition: bigint.h:23
Botan::gcd
BigInt gcd(const BigInt &a, const BigInt &b)
Definition: numthry.cpp:46
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

int botan_mp_get_bit | ( | const botan_mp_t | n,
|  | size_t | bit
| ) |  |

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

Definition at line 573 of file ffi.cpp.

References BOTAN_FFI_DO.

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

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

Definition at line 341 of file ffi.cpp.

342 {
343 *mp = new botan_mp_struct(new Botan::BigInt);
344 return 0;
345 }
Botan::BigInt
Definition: bigint.h:23

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

Definition at line 501 of file ffi.cpp.

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

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

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

Return true iff mp is less than 0

Definition at line 395 of file ffi.cpp.

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

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

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

Definition at line 496 of file ffi.cpp.

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

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

int botan_mp_is_positive | ( | const botan_mp_t | mp | ) |

Return true iff mp is greater than 0

Definition at line 400 of file ffi.cpp.

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

401 {
402 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_positive() ? 1 : 0; });
403 }
Botan::BigInt
Definition: bigint.h:23
Botan::BigInt::is_positive
bool is_positive() const
Definition: bigint.h:354
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

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

Definition at line 567 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::is_prime().

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

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

Definition at line 491 of file ffi.cpp.

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

492 {
493 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_zero(); });
494 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::BigInt::is_zero
bool is_zero() const
Definition: bigint.h:250

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

Definition at line 523 of file ffi.cpp.

References BOTAN_FFI_DO.

524 {
525 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) << shift; });
526 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 533 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::inverse_mod().

534 {
535 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); });
536 }
Botan::BigInt
Definition: bigint.h:23
Botan::inverse_mod
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:276
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

int botan_mp_mod_mul | ( | botan_mp_t | out,
|  | const botan_mp_t | x,
|  | const botan_mp_t | y,
|  | const botan_mp_t | modulus
| ) |  |

Definition at line 538 of file ffi.cpp.

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

539 {
540 return BOTAN_FFI_DO(Botan::BigInt, out, o, {
541 Botan::Modular_Reducer reducer(safe_get(modulus));
542 o = reducer.multiply(safe_get(x), safe_get(y));
543 });
544 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::Modular_Reducer
Definition: reducer.h:18

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

Definition at line 470 of file ffi.cpp.

References BOTAN_FFI_DO.

471 {
472 return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) * safe_get(y); });
473 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

int botan_mp_num_bits | ( | const botan_mp_t | mp,
|  | size_t * | bits
| ) |  |

Definition at line 588 of file ffi.cpp.

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

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

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

Definition at line 593 of file ffi.cpp.

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

594 {
595 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bytes = n.bytes(); });
596 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::BigInt::bytes
size_t bytes() const
Definition: bigint.cpp:176

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

Definition at line 517 of file ffi.cpp.

References BOTAN_FFI_DO, and Botan::power_mod().

518 {
519 return BOTAN_FFI_DO(Botan::BigInt, out, o,
520 { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
521 }
Botan::BigInt
Definition: bigint.h:23
Botan::power_mod
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:373
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 546 of file ffi.cpp.

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

547 {
548 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, {
549 safe_get(rand_out).randomize(r, bits); });
550 }
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::RandomNumberGenerator::randomize
virtual void randomize(uint8_t output[], size_t length)=0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

int botan_mp_rand_range | ( | botan_mp_t | rand_out,
|  | botan_rng_t | rng,
|  | const botan_mp_t | lower,
|  | const botan_mp_t | upper
| ) |  |

Definition at line 552 of file ffi.cpp.

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

556 {
557 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, {
558 safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
559 }
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::BigInt::random_integer
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
Definition: big_rand.cpp:45
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 528 of file ffi.cpp.

References BOTAN_FFI_DO.

529 {
530 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) >> shift; });
531 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Set the specified bit

Definition at line 578 of file ffi.cpp.

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

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

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

Definition at line 352 of file ffi.cpp.

References BOTAN_FFI_DO.

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

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

Definition at line 390 of file ffi.cpp.

References BOTAN_FFI_DO.

391 {
392 return BOTAN_FFI_DO(Botan::BigInt, dest, bn, { bn = safe_get(source); });
393 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 372 of file ffi.cpp.

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

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

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

Definition at line 367 of file ffi.cpp.

References BOTAN_FFI_DO.

368 {
369 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn = Botan::BigInt(str); });
370 }
Botan::BigInt
Definition: bigint.h:23
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 465 of file ffi.cpp.

References BOTAN_FFI_DO.

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

int botan_mp_swap | ( | botan_mp_t | x_w,
|  | botan_mp_t | y_w
| ) |  |

Definition at line 511 of file ffi.cpp.

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

512 {
513 return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { x.swap(safe_get(y_w)); });
514 }
Botan::BigInt
Definition: bigint.h:23
Botan::BigInt::swap
void swap(BigInt &other)
Definition: bigint.h:122
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 441 of file ffi.cpp.

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

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

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

Definition at line 415 of file ffi.cpp.

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

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

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

Definition at line 424 of file ffi.cpp.

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

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

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

Definition at line 446 of file ffi.cpp.

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

447 {
448 if(val == nullptr) {
449 return BOTAN_FFI_ERROR_NULL_POINTER;
450 }
451 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { *val = bn.to_u32bit(); });
452 }
Botan::BigInt
Definition: bigint.h:23
Botan::BigInt::to_u32bit
uint32_t to_u32bit() const
Definition: bigint.cpp:141
BOTAN_FFI_ERROR_NULL_POINTER
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:140
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 992 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and Botan::get_pbkdf().

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

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

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

Parameters

  pbkdf_algo | PBKDF algorithm, e.g., "PBKDF2"
  out | buffer to store the derived key, must be of out_len bytes
  out_len | the desired length of the key to produce
  passphrase | the password to derive the key from
  salt | a randomly chosen salt
  salt_len | length of salt in bytes
  milliseconds_to_run | if iterations is zero, then instead the PBKDF is run until milliseconds_to_run milliseconds has passed
  out_iterations_used | set to the number iterations executed

Returns
  0 on success, a negative value on failure

Definition at line 1010 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and Botan::get_pbkdf().

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

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

Definition at line 1889 of file ffi.cpp.

References BOTAN_FFI_DO.

1892 {
1893 return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, {
1894 return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len));
1895 });
1896 }
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::PK_Decryptor
Definition: pubkey.h:85

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

Definition at line 1857 of file ffi.cpp.

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

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

int botan_pk_op_decrypt_destroy | ( | botan_pk_op_decrypt_t | op | ) |

Definition at line 1883 of file ffi.cpp.

1884 {
1885 delete op;
1886 return 0;
1887 }

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

Definition at line 1844 of file ffi.cpp.

References BOTAN_FFI_DO.

1848 {
1849 return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, {
1850 return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
1851 });
1852 }
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::PK_Encryptor
Definition: pubkey.h:35

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

Definition at line 1812 of file ffi.cpp.

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

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

int botan_pk_op_encrypt_destroy | ( | botan_pk_op_encrypt_t | op | ) |

Definition at line 1838 of file ffi.cpp.

1839 {
1840 delete op;
1841 return 0;
1842 }

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

Definition at line 2034 of file ffi.cpp.

References BOTAN_FFI_DO.

2038 {
2039 return BOTAN_FFI_DO(Botan::PK_Key_Agreement, op, o, {
2040 auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
2041 return write_vec_output(out, out_len, k);
2042 });
2043 }
Botan::OctetString::bits_of
secure_vector< uint8_t > bits_of() const
Definition: symkey.h:31
Botan::PK_Key_Agreement::derive_key
SymmetricKey derive_key(size_t key_len, const uint8_t in[], size_t in_len, const uint8_t params[], size_t params_len) const
Definition: pubkey.cpp:202
Botan::PK_Key_Agreement
Definition: pubkey.h:400
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 1992 of file ffi.cpp.

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

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

int botan_pk_op_key_agreement_destroy | ( | botan_pk_op_ka_t | op | ) |

Definition at line 2018 of file ffi.cpp.

2019 {
2020 delete op;
2021 return 0;
2022 }

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

Definition at line 2024 of file ffi.cpp.

References BOTAN_FFI_DO.

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

int botan_pk_op_sign_create | ( | botan_pk_op_sign_t * | op,
|  | botan_privkey_t | key_obj,
|  | const char * | hash,
|  | uint32_t | flags
| ) |  |

Definition at line 1901 of file ffi.cpp.

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

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

int botan_pk_op_sign_destroy | ( | botan_pk_op_sign_t | op | ) |

Definition at line 1927 of file ffi.cpp.

1928 {
1929 delete op;
1930 return 0;
1931 }

int botan_pk_op_sign_finish | ( | botan_pk_op_sign_t | op,
|  | botan_rng_t | rng_obj,
|  | uint8_t | out[],
|  | size_t * | out_len
| ) |  |

Definition at line 1938 of file ffi.cpp.

References BOTAN_FFI_DO.

1939 {
1940 return BOTAN_FFI_DO(Botan::PK_Signer, op, o, {
1941 return write_vec_output(out, out_len, o.signature(safe_get(rng_obj)));
1942 });
1943 }
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::PK_Signer
Definition: pubkey.h:161

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

Definition at line 1933 of file ffi.cpp.

References BOTAN_FFI_DO.

1934 {
1935 return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { o.update(in, in_len); });
1936 }
Botan::PK_Signer::update
void update(uint8_t in)
Definition: pubkey.h:240
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
Botan::PK_Signer
Definition: pubkey.h:161

int botan_pk_op_verify_create | ( | botan_pk_op_verify_t * | op,
|  | botan_pubkey_t | key_obj,
|  | const char * | hash,
|  | uint32_t | flags
| ) |  |

Definition at line 1945 of file ffi.cpp.

References BOTAN_ASSERT_NONNULL, BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_BAD_FLAG.

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

int botan_pk_op_verify_destroy | ( | botan_pk_op_verify_t | op | ) |

Definition at line 1969 of file ffi.cpp.

1970 {
1971 delete op;
1972 return 0;
1973 }

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

Definition at line 1980 of file ffi.cpp.

References BOTAN_FFI_DO.

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

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

Definition at line 1975 of file ffi.cpp.

References BOTAN_FFI_DO.

1976 {
1977 return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, { o.update(in, in_len); });
1978 }
Botan::PK_Verifier::update
void update(uint8_t in)
Definition: pubkey.h:337
Botan::PK_Verifier
Definition: pubkey.h:288
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 1673 of file ffi.cpp.

References BOTAN_CHECK_KEY_EXPENSIVE_TESTS, and BOTAN_FFI_DO.

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

int botan_privkey_create | ( | botan_privkey_t * | key_obj,
|  | const char * | algo_name,
|  | const char * | algo_params,
|  | botan_rng_t | rng_obj
| ) |  |

Definition at line 1113 of file ffi.cpp.

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

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

int botan_privkey_create_ecdh | ( | botan_privkey_t * | key_obj,
|  | botan_rng_t | rng_obj,
|  | const char * | param_str
| ) |  |

Definition at line 1235 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_EXCEPTION_THROWN.

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

int botan_privkey_create_ecdsa | ( | botan_privkey_t * | key_obj,
|  | botan_rng_t | rng_obj,
|  | const char * | param_str
| ) |  |

Definition at line 1183 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

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

int botan_privkey_create_mceliece | ( | botan_privkey_t * | key_obj,
|  | botan_rng_t | rng_obj,
|  | size_t | n,
|  | size_t | t
| ) |  |

Definition at line 1210 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

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

int botan_privkey_create_rsa | ( | botan_privkey_t * | key_obj,
|  | botan_rng_t | rng_obj,
|  | size_t | n_bits
| ) |  |

Definition at line 1154 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

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

int botan_privkey_destroy | ( | botan_privkey_t | key | ) |

Definition at line 1630 of file ffi.cpp.

1631 {
1632 delete key;
1633 return 0;
1634 }

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

Definition at line 1607 of file ffi.cpp.

References botan_privkey_get_field().

1608 {
1609 return botan_privkey_get_field(x, key, "x");
1610 }
botan_privkey_get_field
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1558

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

Definition at line 1692 of file ffi.cpp.

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

1693 {
1694 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
1695 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER)
1696 return write_vec_output(out, out_len, Botan::PKCS8::BER_encode(k));
1697 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
1698 return write_str_output(out, out_len, Botan::PKCS8::PEM_encode(k));
1699 else
1700 return -2;
1701 });
1702 }
BOTAN_PRIVKEY_EXPORT_FLAG_PEM
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:659
Botan::Private_Key
Definition: pk_keys.h:166
Botan::PKCS8::BER_encode
secure_vector< uint8_t > BER_encode(const Private_Key &key)
Definition: pkcs8.cpp:130
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
Botan::PKCS8::PEM_encode
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:139
BOTAN_PRIVKEY_EXPORT_FLAG_DER
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:658
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 1704 of file ffi.cpp.

References botan_privkey_export_encrypted_pbkdf_iter().

1710 {
1711 return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
1712 }
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
botan_privkey_export_encrypted_pbkdf_iter
int botan_privkey_export_encrypted_pbkdf_iter(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng_obj, const char *pass, size_t pbkdf_iter, const char *maybe_cipher, const char *maybe_pbkdf_hash, uint32_t flags)
Definition: ffi.cpp:1757

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 at line 1757 of file ffi.cpp.

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

Referenced by botan_privkey_export_encrypted().

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

int botan_privkey_export_encrypted_pbkdf_msec | ( | botan_privkey_t | key,
|  | uint8_t | out[],
|  | size_t * | out_len,
|  | botan_rng_t | rng_obj,
|  | const char * | pass,
|  | uint32_t | pbkdf_msec,
|  | size_t * | pbkdf_iters_out,
|  | const char * | maybe_cipher,
|  | const char * | maybe_pbkdf_hash,
|  | uint32_t | flags
| ) |  |

Definition at line 1714 of file ffi.cpp.

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

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

int botan_privkey_export_pubkey | ( | botan_pubkey_t * | pubout,
|  | botan_privkey_t | key_obj
| ) |  |

Definition at line 1642 of file ffi.cpp.

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

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

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

Definition at line 1558 of file ffi.cpp.

References BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

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

1561 {
1562 if(field_name_cstr == nullptr)
1563 return BOTAN_FFI_ERROR_NULL_POINTER;
1564
1565 const std::string field_name(field_name_cstr);
1566
1567 return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
1568 safe_get(output) = botan_privkey_do_get_field(k, field_name);
1569 });
1570 }
Botan::Private_Key
Definition: pk_keys.h:166
BOTAN_FFI_ERROR_NULL_POINTER
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:140
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 1270 of file ffi.cpp.

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

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

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

Definition at line 1371 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

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

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

Definition at line 1326 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

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

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

Definition at line 1592 of file ffi.cpp.

References botan_privkey_get_field().

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

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

Definition at line 1587 of file ffi.cpp.

References botan_privkey_get_field().

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

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

Definition at line 1582 of file ffi.cpp.

References botan_privkey_get_field().

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

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

Definition at line 1572 of file ffi.cpp.

References botan_privkey_get_field().

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

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

Definition at line 1577 of file ffi.cpp.

References botan_privkey_get_field().

1578 {
1579 return botan_privkey_get_field(q, key, "q");
1580 }
botan_privkey_get_field
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1558

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

Definition at line 1660 of file ffi.cpp.

References BOTAN_FFI_DO.

1661 {
1662 return BOTAN_FFI_DO(Botan::Public_Key, key, k, { return write_str_output(out, out_len, k.algo_name()); });
1663 }
Botan::Public_Key
Definition: pk_keys.h:24
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

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

Definition at line 1665 of file ffi.cpp.

References BOTAN_CHECK_KEY_EXPENSIVE_TESTS, and BOTAN_FFI_DO.

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

int botan_pubkey_destroy | ( | botan_pubkey_t | key | ) |

Definition at line 1636 of file ffi.cpp.

1637 {
1638 delete key;
1639 return 0;
1640 }

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

Definition at line 1620 of file ffi.cpp.

References botan_pubkey_get_field().

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

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

Definition at line 1612 of file ffi.cpp.

References botan_pubkey_get_field().

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

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

Definition at line 1616 of file ffi.cpp.

References botan_pubkey_get_field().

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

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

Definition at line 1624 of file ffi.cpp.

References botan_pubkey_get_field().

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

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

Definition at line 1798 of file ffi.cpp.

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

1799 {
1800 return BOTAN_FFI_DO(Botan::Public_Key, key, k, { *estimate = k.estimated_strength(); });
1801 }
Botan::Public_Key
Definition: pk_keys.h:24
Botan::Public_Key::estimated_strength
virtual size_t estimated_strength() const =0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 1680 of file ffi.cpp.

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

1681 {
1682 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
1683 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER)
1684 return write_vec_output(out, out_len, Botan::X509::BER_encode(k));
1685 else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM)
1686 return write_str_output(out, out_len, Botan::X509::PEM_encode(k));
1687 else
1688 return -2;
1689 });
1690 }
Botan::X509::BER_encode
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.cpp:19
BOTAN_PRIVKEY_EXPORT_FLAG_PEM
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition: ffi.h:659
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_PRIVKEY_EXPORT_FLAG_DER
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition: ffi.h:658
Botan::X509::PEM_encode
std::string PEM_encode(const Public_Key &key)
Definition: x509_key.cpp:28
Botan::Public_Key
Definition: pk_keys.h:24
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 1803 of file ffi.cpp.

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

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

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

Definition at line 1544 of file ffi.cpp.

References BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

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

1547 {
1548 if(field_name_cstr == nullptr)
1549 return BOTAN_FFI_ERROR_NULL_POINTER;
1550
1551 const std::string field_name(field_name_cstr);
1552
1553 return BOTAN_FFI_DO(Botan::Public_Key, key, k, {
1554 safe_get(output) = botan_pubkey_do_get_field(k, field_name);
1555 });
1556 }
Botan::Public_Key
Definition: pk_keys.h:24
BOTAN_FFI_ERROR_NULL_POINTER
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:140
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 1302 of file ffi.cpp.

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

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

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

Definition at line 1398 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

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

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

Definition at line 1349 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

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

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

Definition at line 1597 of file ffi.cpp.

References botan_pubkey_get_field().

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

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

Definition at line 1602 of file ffi.cpp.

References botan_pubkey_get_field().

1603 {
1604 return botan_pubkey_get_field(n, key, "n");
1605 }
botan_pubkey_get_field
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
Definition: ffi.cpp:1544

int botan_rng_destroy | ( | botan_rng_t | rng | ) |

Frees all resources of the random number generator object

Parameters

  rng | rng object

Returns
  always returns 0

Definition at line 325 of file ffi.cpp.

326 {
327 delete rng;
328 return 0;
329 }

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

Get random bytes from a random number generator

Parameters

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

Returns
  0 on success, negative on failure

TODO: better name

Definition at line 331 of file ffi.cpp.

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

332 {
333 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.randomize(out, out_len); });
334 }
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::RandomNumberGenerator::randomize
virtual void randomize(uint8_t output[], size_t length)=0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Initialize a random number generator object

Parameters

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

TODO: replace rng_type with simple flags?

Definition at line 289 of file ffi.cpp.

References BOTAN_ASSERT_ARG_NON_NULL, and BOTAN_CURRENT_FUNCTION.

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

int botan_rng_reseed | ( | botan_rng_t | rng,
|  | size_t | bits
| ) |  |

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

Parameters

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

Returns
  0 on success, a negative value on failure

Definition at line 336 of file ffi.cpp.

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

337 {
338 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, { r.reseed_from_rng(Botan::system_rng(), bits); });
339 }
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::RandomNumberGenerator::reseed_from_rng
virtual void reseed_from_rng(RandomNumberGenerator &rng, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS)
Definition: rng.cpp:44
Botan::system_rng
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:196
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

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

Definition at line 268 of file ffi.cpp.

References Botan::same_mem().

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

uint32_t botan_version_datestamp | ( |  | ) |

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

Definition at line 266 of file ffi.cpp.

References Botan::version_datestamp().

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

uint32_t botan_version_major | ( |  | ) |

Return the major version of the library

Definition at line 263 of file ffi.cpp.

References Botan::version_major().

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

uint32_t botan_version_minor | ( |  | ) |

Return the minor version of the library

Definition at line 264 of file ffi.cpp.

References Botan::version_minor().

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

uint32_t botan_version_patch | ( |  | ) |

Return the patch version of the library

Definition at line 265 of file ffi.cpp.

References Botan::version_patch().

265 { return Botan::version_patch(); }
Botan::version_patch
uint32_t version_patch()
Definition: version.cpp:62

const char* botan_version_string | ( |  | ) |

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

Definition at line 258 of file ffi.cpp.

References Botan::version_cstr().

259 {
260 return Botan::version_cstr();
261 }
Botan::version_cstr
const char * version_cstr()
Definition: version.cpp:28

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

Definition at line 2198 of file ffi.cpp.

References BOTAN_FFI_DO.

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

int botan_x509_cert_destroy | ( | botan_x509_cert_t | cert | ) |

Definition at line 2106 of file ffi.cpp.

2107 {
2108 delete cert;
2109 return 0;
2110 }

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

Definition at line 2132 of file ffi.cpp.

References BOTAN_FFI_DO.

2133 {
2134 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.authority_key_id()); });
2135 }
Botan::X509_Certificate
Definition: x509cert.h:36
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 2127 of file ffi.cpp.

References BOTAN_FFI_DO.

2128 {
2129 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.fingerprint(hash)); });
2130 }
Botan::X509_Certificate
Definition: x509cert.h:36
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

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

Definition at line 2179 of file ffi.cpp.

References BOTAN_FFI_DO.

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

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

Definition at line 2154 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_EXCEPTION_THROWN, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

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

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

Definition at line 2142 of file ffi.cpp.

References BOTAN_FFI_DO.

2143 {
2144 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_public_key_bits()); });
2145 }
Botan::X509_Certificate
Definition: x509cert.h:36
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 2122 of file ffi.cpp.

References BOTAN_FFI_DO.

2123 {
2124 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.serial_number()); });
2125 }
Botan::X509_Certificate
Definition: x509cert.h:36
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 2186 of file ffi.cpp.

References BOTAN_FFI_DO.

2189 {
2190 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.subject_info(key).at(index)); });
2191 }
Botan::X509_Certificate
Definition: x509cert.h:36
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 2137 of file ffi.cpp.

References BOTAN_FFI_DO.

2138 {
2139 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_vec_output(out, out_len, c.subject_key_id()); });
2140 }
Botan::X509_Certificate
Definition: x509cert.h:36
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 2117 of file ffi.cpp.

References BOTAN_FFI_DO.

2118 {
2119 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.end_time()); });
2120 }
Botan::X509_Certificate
Definition: x509cert.h:36
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

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

Definition at line 2112 of file ffi.cpp.

References BOTAN_FFI_DO.

2113 {
2114 return BOTAN_FFI_DO(Botan::X509_Certificate, cert, c, { return write_str_output(out, out_len, c.start_time()); });
2115 }
Botan::X509_Certificate
Definition: x509cert.h:36
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi.cpp:204

int botan_x509_cert_load | ( | botan_x509_cert_t * | cert_obj,
|  | const uint8_t | cert_bits[],
|  | size_t | cert_bits_len
| ) |  |

Definition at line 2076 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION.

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

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

Definition at line 2045 of file ffi.cpp.

References BOTAN_CURRENT_FUNCTION, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

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

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

Definition at line 2193 of file ffi.cpp.

References BOTAN_FFI_DO.

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