8 #include <botan/system_rng.h>
9 #include <botan/exceptn.h>
10 #include <botan/auto_rng.h>
11 #include <botan/aead.h>
12 #include <botan/block_cipher.h>
13 #include <botan/hash.h>
14 #include <botan/mac.h>
15 #include <botan/pbkdf.h>
16 #include <botan/version.h>
17 #include <botan/pkcs8.h>
18 #include <botan/x509cert.h>
19 #include <botan/data_src.h>
20 #include <botan/pubkey.h>
21 #include <botan/hex.h>
22 #include <botan/mem_ops.h>
23 #include <botan/x509_key.h>
24 #include <botan/pk_algs.h>
25 #include <botan/bigint.h>
26 #include <botan/reducer.h>
27 #include <botan/numthry.h>
28 #include <botan/divide.h>
32 #if defined(BOTAN_HAS_RSA)
33 #include <botan/rsa.h>
36 #if defined(BOTAN_HAS_DSA)
37 #include <botan/dsa.h>
40 #if defined(BOTAN_HAS_ECDSA)
41 #include <botan/ecdsa.h>
44 #if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
45 #include <botan/ecc_key.h>
48 #if defined(BOTAN_HAS_DL_PUBLIC_KEY_FAMILY)
49 #include <botan/dl_algo.h>
52 #if defined(BOTAN_HAS_ECDH)
53 #include <botan/ecdh.h>
56 #if defined(BOTAN_HAS_CURVE_25519)
57 #include <botan/curve25519.h>
60 #if defined(BOTAN_HAS_MCELIECE)
61 #include <botan/mceliece.h>
64 #if defined(BOTAN_HAS_MCEIES)
65 #include <botan/mceies.h>
68 #if defined(BOTAN_HAS_BCRYPT)
69 #include <botan/bcrypt.h>
72 #if defined(BOTAN_HAS_TLS)
73 #include <botan/tls_client.h>
74 #include <botan/tls_server.h>
79 #define BOTAN_ASSERT_ARG_NON_NULL(p) \
80 do { if(!p) throw Botan::Invalid_Argument("Argument " #p " is null"); } while(0)
85 explicit FFI_Error(
const std::string& what) :
Exception(
"FFI error", what) {}
88 template<
typename T, u
int32_t MAGIC>
92 botan_struct(T* obj) : m_magic(MAGIC), m_obj(obj) {}
93 ~botan_struct() { m_magic = 0; m_obj.reset(); }
103 uint32_t m_magic = 0;
104 std::unique_ptr<T> m_obj;
107 void log_exception(
const char* func_name,
const char* what)
109 fprintf(stderr,
"%s: %s\n", func_name, what);
112 int ffi_error_exception_thrown(
const char* exn)
114 fprintf(stderr,
"exception %s\n", exn);
118 template<
typename T, u
int32_t M>
119 T& safe_get(botan_struct<T,M>* p)
122 throw FFI_Error(
"Null pointer argument");
125 throw FFI_Error(
"Invalid object pointer");
128 template<
typename T, u
int32_t M>
129 const T& safe_get(
const botan_struct<T,M>* p)
132 throw FFI_Error(
"Null pointer argument");
133 if(
const T* t = p->get())
135 throw FFI_Error(
"Invalid object pointer");
138 template<
typename T, u
int32_t M,
typename F>
139 int apply_fn(botan_struct<T, M>* o,
const char* func_name, F func)
144 throw FFI_Error(
"Null object to " + std::string(func_name));
148 catch(std::exception& e)
150 log_exception(func_name, e.what());
155 log_exception(func_name,
"unknown exception type");
162 inline int write_output(uint8_t out[],
size_t* out_len,
const uint8_t buf[],
size_t buf_len)
164 const size_t avail = *out_len;
179 template<
typename Alloc>
180 int write_vec_output(uint8_t out[],
size_t* out_len,
const std::vector<uint8_t, Alloc>& buf)
182 return write_output(out, out_len, buf.data(), buf.size());
185 inline int write_str_output(uint8_t out[],
size_t* out_len,
const std::string& str)
187 return write_output(out, out_len,
188 reinterpret_cast<const uint8_t*>(str.c_str()),
192 inline int write_str_output(
char out[],
size_t* out_len,
const std::string& str)
194 return write_str_output(reinterpret_cast<uint8_t*>(out), out_len, str);
197 inline int write_str_output(
char out[],
size_t* out_len,
const std::vector<uint8_t>& str_vec)
199 return write_output(reinterpret_cast<uint8_t*>(out), out_len,
200 reinterpret_cast<const uint8_t*>(str_vec.data()),
204 #define BOTAN_FFI_DO(T, obj, param, block) apply_fn(obj, BOTAN_CURRENT_FUNCTION, [=](T& param) -> int { do { block } while(0); return 0; })
210 #define BOTAN_FFI_DECLARE_STRUCT(NAME, TYPE, MAGIC) \
211 struct NAME : public botan_struct<TYPE, MAGIC> { explicit NAME(TYPE* x) : botan_struct(x) {} }
213 struct botan_cipher_struct :
public botan_struct<Botan::Cipher_Mode, 0xB4A2BF9C>
235 #if defined(BOTAN_HAS_TLS)
244 return BOTAN_HAS_FFI;
253 if(api_version == BOTAN_HAS_FFI)
281 catch(std::exception& e)
295 if(rng_type ==
nullptr || *rng_type == 0)
298 const std::string rng_type_s(rng_type);
300 std::unique_ptr<Botan::RandomNumberGenerator> rng;
302 if(rng_type_s ==
"system")
304 else if(rng_type_s ==
"user")
309 *rng_out =
new botan_rng_struct(rng.release());
313 catch(std::exception& e)
355 if(initial_value >= 0)
383 const uint8_t* bytes =
reinterpret_cast<const uint8_t*
>(str);
384 const size_t len = strlen(str);
419 std::memcpy(out, hex.data(), hex.size());
428 if(digit_base == 0 || digit_base == 10)
430 else if(digit_base == 16)
433 throw FFI_Error(
"botan_mp_to_str invalid digit base");
437 write_str_output(out, out_len, hex);
482 safe_get(remainder) = r;
520 { o =
Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
542 o = reducer.
multiply(safe_get(x), safe_get(y));
549 safe_get(rand_out).
randomize(r, bits); });
602 if(bc ==
nullptr || bc_name ==
nullptr || *bc_name == 0)
608 *bc =
new botan_block_cipher_struct(cipher.release());
612 catch(std::exception& e)
643 const uint8_t key[],
size_t len)
677 if(hash ==
nullptr || hash_name ==
nullptr || *hash_name == 0)
685 *hash =
new botan_hash_struct(h.release());
689 catch(std::exception& e)
731 if(!mac || !mac_name || flags != 0)
737 *mac =
new botan_mac_struct(m.release());
741 catch(std::exception& e)
793 *cipher =
new botan_cipher_struct(mode.release());
796 catch(std::exception& e)
820 size_t* out_minimum_keylength,
821 size_t* out_maximum_keylength)
825 *out_maximum_keylength = c.key_spec().maximum_keylength();
830 const uint8_t* key,
size_t key_len)
836 const uint8_t* nonce,
size_t nonce_len)
841 cipher.
start(nonce, nonce_len);
845 catch(std::exception& e)
857 size_t* output_written,
858 const uint8_t input[],
860 size_t* input_consumed)
862 using namespace Botan;
873 mbuf.assign(input, input + input_size);
874 *input_consumed = input_size;
887 *output_written = mbuf.size();
889 if(mbuf.size() <= output_size)
891 copy_mem(output, mbuf.data(), mbuf.size());
902 *output_written = mbuf.size();
903 if(output_size >= mbuf.size())
905 copy_mem(output, mbuf.data(), mbuf.size());
918 if(Online_Cipher_Mode* ocm = dynamic_cast<Online_Cipher_Mode*>(&cipher))
920 const size_t taken =
round_down(input_size, ud);
921 *input_consumed = taken;
922 *output_size = taken;
924 ocm->update_in_place(output, taken);
930 size_t taken = 0, written = 0;
932 while(input_size >= ud && output_size >= ud)
946 *output_written = written;
947 *input_consumed = taken;
950 catch(std::exception& e)
965 aead->set_associated_data(ad, ad_len);
992 int botan_pbkdf(
const char* pbkdf_algo, uint8_t out[],
size_t out_len,
993 const char* pass,
const uint8_t salt[],
size_t salt_len,
999 pbkdf->pbkdf_iterations(out, out_len, pass, salt, salt_len, iterations);
1002 catch(std::exception& e)
1011 uint8_t out[],
size_t out_len,
1012 const char* password,
1013 const uint8_t salt[],
size_t salt_len,
1015 size_t* iterations_used)
1020 pbkdf->pbkdf_timed(out, out_len, password, salt, salt_len,
1021 std::chrono::milliseconds(ms_to_run),
1025 catch(std::exception& e)
1034 uint8_t out[],
size_t out_len,
1035 const uint8_t secret[],
size_t secret_len,
1036 const uint8_t salt[],
size_t salt_len,
1037 const uint8_t label[],
size_t label_len)
1042 kdf->kdf(out, out_len, secret, secret_len, salt, salt_len, label, label_len);
1045 catch(std::exception& e)
1067 if(wf < 2 || wf > 30)
1070 #if defined(BOTAN_HAS_BCRYPT)
1073 return write_str_output(out, out_len, bcrypt);
1078 catch(std::exception& e)
1094 #if defined(BOTAN_HAS_BCRYPT)
1101 catch(std::exception& e)
1114 const char* algo_name,
1115 const char* algo_params,
1120 if(key_obj ==
nullptr)
1124 if(rng_obj ==
nullptr)
1127 if(algo_name ==
nullptr)
1129 if(algo_params ==
nullptr)
1133 std::unique_ptr<Botan::Private_Key> key(
1138 *key_obj =
new botan_privkey_struct(key.release());
1146 catch(std::exception& e)
1158 if(key_obj ==
nullptr || rng_obj ==
nullptr)
1160 if(n_bits < 1024 || n_bits > 16*1024)
1165 #if defined(BOTAN_HAS_RSA)
1168 *key_obj =
new botan_privkey_struct(key.release());
1174 catch(std::exception& e)
1187 if(key_obj ==
nullptr || rng_obj ==
nullptr || param_str ==
nullptr || *param_str == 0)
1192 #if defined(BOTAN_HAS_ECDSA)
1196 *key_obj =
new botan_privkey_struct(key.release());
1202 catch(std::exception& e)
1214 if(key_obj ==
nullptr || rng_obj ==
nullptr || n == 0 || t == 0)
1219 #if defined(BOTAN_HAS_MCELIECE)
1222 *key_obj =
new botan_privkey_struct(key.release());
1228 catch(std::exception& e)
1239 if(key_obj ==
nullptr || rng_obj ==
nullptr || param_str ==
nullptr || *param_str == 0)
1244 const std::string params(param_str);
1246 #if defined(BOTAN_HAS_CURVE_25519)
1247 if(params ==
"curve25519")
1250 *key_obj =
new botan_privkey_struct(key.release());
1255 #if defined(BOTAN_HAS_ECDH)
1258 *key_obj =
new botan_privkey_struct(key.release());
1262 catch(std::exception& e)
1271 const uint8_t bits[],
size_t len,
1272 const char* password)
1280 if(password ==
nullptr)
1285 std::unique_ptr<Botan::PKCS8_PrivateKey> pkcs8;
1290 *key =
new botan_privkey_struct(pkcs8.release());
1294 catch(std::exception& e)
1303 const uint8_t bits[],
size_t bits_len)
1314 *key =
new botan_pubkey_struct(pubkey.release());
1318 catch(std::exception& e)
1331 #if defined(BOTAN_HAS_RSA)
1339 catch(std::exception& e)
1354 #if defined(BOTAN_HAS_RSA)
1360 catch(std::exception& exn)
1376 #if defined(BOTAN_HAS_DSA)
1384 catch(std::exception& e)
1403 #if defined(BOTAN_HAS_DSA)
1410 catch(std::exception& exn)
1428 const std::string& field)
1432 #if defined(BOTAN_HAS_RSA)
1436 return rsa->get_n();
1437 else if(field ==
"e")
1438 return rsa->get_e();
1444 #if defined(BOTAN_HAS_DL_PUBLIC_KEY_FAMILY)
1449 return dl->group_p();
1450 else if(field ==
"q")
1451 return dl->group_q();
1452 else if(field ==
"g")
1453 return dl->group_g();
1454 else if(field ==
"y")
1461 #if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1464 if(field ==
"public_x")
1465 return ecc->public_point().get_affine_x();
1466 else if(field ==
"public_y")
1467 return ecc->public_point().get_affine_y();
1468 else if(field ==
"base_x")
1469 return ecc->domain().get_base_point().get_affine_x();
1470 else if(field ==
"base_y")
1471 return ecc->domain().get_base_point().get_affine_y();
1472 else if(field ==
"p")
1473 return ecc->domain().get_curve().get_p();
1474 else if(field ==
"a")
1475 return ecc->domain().get_curve().get_a();
1476 else if(field ==
"b")
1477 return ecc->domain().get_curve().get_b();
1478 else if(field ==
"cofactor")
1479 return ecc->domain().get_cofactor();
1480 else if(field ==
"order")
1481 return ecc->domain().get_order();
1488 throw Botan::Exception(
"Unsupported algorithm type for botan_pubkey_get_field");
1492 const std::string& field)
1496 #if defined(BOTAN_HAS_RSA)
1501 return rsa->get_p();
1502 else if(field ==
"q")
1503 return rsa->get_q();
1504 else if(field ==
"d")
1505 return rsa->get_d();
1506 else if(field ==
"c")
1507 return rsa->get_c();
1508 else if(field ==
"d1")
1509 return rsa->get_d1();
1510 else if(field ==
"d2")
1511 return rsa->get_d2();
1513 return botan_pubkey_do_get_field(key, field);
1517 #if defined(BOTAN_HAS_DL_PUBLIC_KEY_FAMILY)
1524 return botan_pubkey_do_get_field(key, field);
1528 #if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
1532 return ecc->private_value();
1534 return botan_pubkey_do_get_field(key, field);
1539 throw Botan::Exception(
"Unsupported algorithm type for botan_privkey_get_field");
1546 const char* field_name_cstr)
1548 if(field_name_cstr ==
nullptr)
1551 const std::string field_name(field_name_cstr);
1554 safe_get(output) = botan_pubkey_do_get_field(k, field_name);
1560 const char* field_name_cstr)
1562 if(field_name_cstr ==
nullptr)
1565 const std::string field_name(field_name_cstr);
1568 safe_get(output) = botan_privkey_do_get_field(k, field_name);
1646 std::unique_ptr<Botan::Public_Key> pubkey(
1649 *pubout =
new botan_pubkey_struct(pubkey.release());
1652 catch(std::exception& e)
1670 {
return (k.check_key(safe_get(rng), strong) ==
true) ? 0 : -1; });
1677 {
return (k.check_key(safe_get(rng), strong) ==
true) ? 0 : -1; });
1705 uint8_t out[],
size_t* out_len,
1715 uint8_t out[],
size_t* out_len,
1718 uint32_t pbkdf_msec,
1719 size_t* pbkdf_iters_out,
1720 const char* maybe_cipher,
1721 const char* maybe_pbkdf_hash,
1725 const std::chrono::milliseconds pbkdf_time(pbkdf_msec);
1731 cipher = maybe_cipher;
1734 std::string pbkdf_hash;
1735 if(maybe_pbkdf_hash)
1737 pbkdf_hash = maybe_pbkdf_hash;
1742 return write_vec_output(out, out_len,
1747 return write_str_output(out, out_len,
1758 uint8_t out[],
size_t* out_len,
1762 const char* maybe_cipher,
1763 const char* maybe_pbkdf_hash,
1772 cipher = maybe_cipher;
1775 std::string pbkdf_hash;
1776 if(maybe_pbkdf_hash)
1778 pbkdf_hash = maybe_pbkdf_hash;
1783 return write_vec_output(out, out_len,
1788 return write_str_output(out, out_len,
1804 uint8_t out[],
size_t* out_len)
1808 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
1814 const char* padding,
1827 *op =
new botan_pk_op_encrypt_struct(pk.release());
1830 catch(std::exception& e)
1846 uint8_t out[],
size_t* out_len,
1847 const uint8_t plaintext[],
size_t plaintext_len)
1850 return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
1859 const char* padding,
1872 *op =
new botan_pk_op_decrypt_struct(pk.release());
1875 catch(std::exception& e)
1890 uint8_t out[],
size_t* out_len,
1891 uint8_t ciphertext[],
size_t ciphertext_len)
1894 return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len));
1916 *op =
new botan_pk_op_sign_struct(pk.release());
1919 catch(std::exception& e)
1941 return write_vec_output(out, out_len, o.signature(safe_get(rng_obj)));
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());
1961 catch(std::exception& e)
1983 const bool legit = o.check_signature(sig, sig_len);
2007 *op =
new botan_pk_op_ka_struct(pk.release());
2010 catch(std::exception& e)
2025 uint8_t out[],
size_t* out_len)
2028 if(
auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
2029 return write_vec_output(out, out_len, kak->public_value());
2035 uint8_t out[],
size_t* out_len,
2036 const uint8_t other_key[],
size_t other_key_len,
2037 const uint8_t salt[],
size_t salt_len)
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);
2049 if(!cert_obj || !cert_path)
2052 #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
2057 *cert_obj =
new botan_x509_cert_struct(c.release());
2064 catch(std::exception& e)
2080 if(!cert_obj || !cert_bits)
2089 *cert_obj =
new botan_x509_cert_struct(c.release());
2093 catch(std::exception& e)
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());
2171 catch(std::exception& e)
2180 const char* key,
size_t index,
2181 uint8_t out[],
size_t* out_len)
2187 const char* key,
size_t index,
2188 uint8_t out[],
size_t* out_len)
2202 if(c.allowed_usage(k))
2210 const uint8_t ct[],
size_t ct_len,
2211 const uint8_t ad[],
size_t ad_len,
2212 uint8_t out[],
size_t* out_len)
2218 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
2224 return write_vec_output(out, out_len, pt);
2229 catch(std::exception& e)
2231 return ffi_error_exception_thrown(e.what());
2238 const uint8_t pt[],
size_t pt_len,
2239 const uint8_t ad[],
size_t ad_len,
2240 uint8_t out[],
size_t* out_len)
2247 #if defined(BOTAN_HAS_MCELIECE) && defined(BOTAN_HAS_MCEIES)
2253 return write_vec_output(out, out_len, ct);
2258 catch(std::exception& e)
2260 return ffi_error_exception_thrown(e.what());
int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t *tl)
#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT
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)
void binary_encode(uint8_t buf[]) const
int botan_block_cipher_encrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
int botan_x509_cert_get_authority_key_id(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
std::vector< uint8_t > BER_encode(const Public_Key &key)
int botan_hex_encode(const uint8_t *in, size_t len, char *out, uint32_t flags)
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name_cstr)
T round_down(T n, T align_to)
size_t minimum_keylength() const
int botan_rng_reseed(botan_rng_t rng, size_t bits)
int botan_mp_set_from_radix_str(botan_mp_t mp, const char *str, size_t radix)
int botan_mp_is_odd(const botan_mp_t mp)
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
int botan_mp_lshift(botan_mp_t out, const botan_mp_t in, size_t shift)
int botan_pubkey_load(botan_pubkey_t *key, const uint8_t bits[], size_t bits_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_mp_set_from_str(botan_mp_t mp, const char *str)
void divide(const BigInt &x, const BigInt &y_arg, BigInt &q, BigInt &r)
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)
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
int botan_hash_final(botan_hash_t hash, uint8_t out[])
int botan_mp_rshift(botan_mp_t out, const botan_mp_t in, size_t shift)
int botan_mac_update(botan_mac_t mac, const uint8_t *buf, size_t len)
int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
#define BOTAN_FFI_ERROR_BAD_FLAG
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
bool same_mem(const T *p1, const T *p2, size_t n)
int botan_privkey_rsa_get_n(botan_mp_t n, botan_privkey_t key)
int botan_rng_destroy(botan_rng_t rng)
int botan_mp_set_bit(botan_mp_t mp, size_t bit)
std::string generate_bcrypt(const std::string &pass, RandomNumberGenerator &rng, uint16_t work_factor)
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_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage)
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_x509_cert_destroy(botan_x509_cert_t cert)
int botan_block_cipher_destroy(botan_block_cipher_t bc)
virtual void randomize(uint8_t output[], size_t length)=0
Exception(const std::string &msg)
uint32_t to_u32bit() const
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_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)
void clear_mem(T *ptr, size_t n)
struct botan_pk_op_encrypt_struct * botan_pk_op_encrypt_t
int botan_hash_update(botan_hash_t hash, const uint8_t *buf, size_t len)
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
BigInt gcd(const BigInt &a, const BigInt &b)
int botan_mp_is_positive(const botan_mp_t mp)
int botan_pk_op_encrypt_destroy(botan_pk_op_encrypt_t op)
secure_vector< uint8_t > BER_encode(const Private_Key &key)
virtual void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
Public_Key * load_key(DataSource &source)
int botan_pubkey_destroy(botan_pubkey_t key)
int botan_privkey_create_ecdsa(botan_privkey_t *key_obj, botan_rng_t rng_obj, const char *param_str)
void update(secure_vector< uint8_t > &buffer, size_t offset=0)
int botan_pk_op_decrypt_create(botan_pk_op_decrypt_t *op, botan_privkey_t key_obj, const char *padding, uint32_t flags)
virtual size_t update_granularity() const =0
int botan_mp_mul(botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
int botan_mac_destroy(botan_mac_t mac)
int botan_mp_clear(botan_mp_t mp)
Cipher_Mode * get_cipher_mode(const std::string &algo, Cipher_Dir direction)
struct botan_pk_op_sign_struct * botan_pk_op_sign_t
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_rsa(botan_privkey_t *key_obj, botan_rng_t rng_obj, size_t n_bits)
int botan_rng_init(botan_rng_t *rng_out, const char *rng_type)
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)
int botan_privkey_rsa_get_e(botan_mp_t e, botan_privkey_t key)
bool check_bcrypt(const std::string &pass, const std::string &hash)
int botan_block_cipher_clear(botan_block_cipher_t bc)
int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
int botan_pk_op_sign_update(botan_pk_op_sign_t op, const uint8_t in[], size_t in_len)
int botan_pubkey_load_rsa(botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
std::string to_string(const BER_Object &obj)
virtual Key_Length_Specification key_spec() const =0
std::string PEM_encode(const Private_Key &key)
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
const char * version_cstr()
int botan_x509_cert_get_fingerprint(botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
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_load(botan_privkey_t *key, botan_rng_t rng_obj, const uint8_t bits[], size_t len, const char *password)
#define BOTAN_FFI_HEX_LOWER_CASE
int botan_x509_cert_get_public_key_bits(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int botan_hash_init(botan_hash_t *hash, const char *hash_name, uint32_t flags)
virtual size_t minimum_final_size() const =0
int botan_block_cipher_decrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
int botan_hash_clear(botan_hash_t hash)
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_load_dsa(botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t x)
int botan_mp_to_str(const botan_mp_t mp, uint8_t digit_base, char *out, size_t *out_len)
void start(const std::vector< uint8_t, Alloc > &nonce)
int botan_block_cipher_init(botan_block_cipher_t *bc, const char *bc_name)
virtual size_t default_nonce_length() const =0
uint32_t botan_version_patch()
int botan_block_cipher_block_size(botan_block_cipher_t bc)
Private_Key * load_key(DataSource &source, RandomNumberGenerator &rng, std::function< std::string()> get_pass)
int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits)
int botan_pk_op_sign_destroy(botan_pk_op_sign_t op)
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_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t *out_len)
#define BOTAN_ASSERT(expr, assertion_made)
int botan_cipher_query_keylen(botan_cipher_t cipher, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
int botan_mac_init(botan_mac_t *mac, const char *mac_name, uint32_t flags)
int botan_rng_get(botan_rng_t rng, uint8_t *out, size_t out_len)
int botan_mp_is_prime(const botan_mp_t mp, botan_rng_t rng, size_t test_prob)
virtual size_t tag_size() const
struct botan_mac_struct * botan_mac_t
int botan_mp_div(botan_mp_t quotient, botan_mp_t remainder, const botan_mp_t x, const botan_mp_t y)
void final(uint8_t out[])
int botan_privkey_create_ecdh(botan_privkey_t *key_obj, botan_rng_t rng_obj, const char *param_str)
int32_t cmp(const BigInt &n, bool check_signs=true) const
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
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_destroy(botan_pk_op_verify_t op)
uint32_t version_datestamp()
int botan_privkey_load_rsa(botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t d)
std::vector< T, secure_allocator< T >> secure_vector
int botan_pk_op_key_agreement_create(botan_pk_op_ka_t *op, botan_privkey_t key_obj, const char *kdf, uint32_t flags)
void set_key(const SymmetricKey &key)
int botan_pubkey_rsa_get_e(botan_mp_t e, botan_pubkey_t key)
struct botan_pk_op_decrypt_struct * botan_pk_op_decrypt_t
struct botan_mp_struct * botan_mp_t
int botan_x509_cert_get_subject_key_id(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
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_mp_mod_inverse(botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus)
int botan_privkey_rsa_get_p(botan_mp_t p, botan_privkey_t key)
#define BOTAN_ASSERT_NONNULL(ptr)
int botan_cipher_set_key(botan_cipher_t cipher, const uint8_t *key, size_t key_len)
int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
struct botan_x509_cert_struct * botan_x509_cert_t
uint32_t botan_ffi_api_version()
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)
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)
int botan_mp_flip_sign(botan_mp_t mp)
#define BOTAN_CIPHER_UPDATE_FLAG_FINAL
int botan_cipher_get_update_granularity(botan_cipher_t cipher, size_t *ug)
int botan_mp_powmod(botan_mp_t out, const botan_mp_t base, const botan_mp_t exponent, const botan_mp_t modulus)
BigInt multiply(const BigInt &x, const BigInt &y) const
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
int botan_bcrypt_is_valid(const char *pass, const char *hash)
int botan_cipher_start(botan_cipher_t cipher_obj, const uint8_t *nonce, size_t nonce_len)
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
int botan_privkey_rsa_get_q(botan_mp_t q, botan_privkey_t key)
#define BOTAN_FFI_ERROR_EXCEPTION_THROWN
struct botan_hash_struct * botan_hash_t
int botan_mp_num_bytes(const botan_mp_t mp, size_t *bytes)
int botan_mp_destroy(botan_mp_t mp)
int botan_mp_get_bit(const botan_mp_t mp, size_t bit)
uint32_t botan_version_major()
PBKDF * get_pbkdf(const std::string &algo_spec, const std::string &provider="")
int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t *out_len)
int botan_same_mem(const uint8_t *x, const uint8_t *y, size_t len)
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
int botan_mp_cmp(int *result, const botan_mp_t x_w, const botan_mp_t y_w)
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)
const char * what() const BOTAN_NOEXCEPT override
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_mp_swap(botan_mp_t x_w, botan_mp_t y_w)
int botan_mp_clear_bit(botan_mp_t mp, size_t bit)
int botan_mp_is_negative(const botan_mp_t mp)
int botan_cipher_destroy(botan_cipher_t cipher)
int botan_pk_op_verify_update(botan_pk_op_verify_t op, const uint8_t in[], size_t in_len)
int botan_pubkey_dsa_get_g(botan_mp_t g, botan_pubkey_t key)
int botan_mp_to_hex(const botan_mp_t mp, char *out)
std::string PEM_encode(const Public_Key &key)
struct botan_pk_op_verify_struct * botan_pk_op_verify_t
void copy_mem(T *out, const T *in, size_t n)
int botan_mac_clear(botan_mac_t mac)
int botan_hash_destroy(botan_hash_t hash)
int botan_mp_add(botan_mp_t result, 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_pubkey_dsa_get_y(botan_mp_t y, botan_pubkey_t key)
struct botan_privkey_struct * botan_privkey_t
virtual void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
int botan_pk_op_key_agreement_destroy(botan_pk_op_ka_t op)
int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
int botan_pk_op_encrypt_create(botan_pk_op_encrypt_t *op, botan_pubkey_t key_obj, const char *padding, uint32_t flags)
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t *estimate)
int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t *nl)
#define BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
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_privkey_create_mceliece(botan_privkey_t *key_obj, botan_rng_t rng_obj, size_t n, size_t t)
uint32_t botan_version_minor()
int botan_mp_is_even(const botan_mp_t mp)
virtual void reseed_from_rng(RandomNumberGenerator &rng, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS)
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_mp_is_zero(const botan_mp_t mp)
int botan_pubkey_rsa_get_n(botan_mp_t n, botan_pubkey_t key)
virtual size_t estimated_strength() const =0
int botan_privkey_export_pubkey(botan_pubkey_t *pubout, botan_privkey_t key_obj)
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
uint32_t botan_version_datestamp()
int botan_x509_cert_load(botan_x509_cert_t *cert_obj, const uint8_t cert_bits[], size_t cert_bits_len)
void set_key(const std::vector< uint8_t, Alloc > &key)
int botan_mac_set_key(botan_mac_t mac, const uint8_t *key, size_t key_len)
int botan_privkey_dsa_get_x(botan_mp_t x, botan_privkey_t key)
struct botan_block_cipher_struct * botan_block_cipher_t
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)
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_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name_cstr)
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_ffi_supports_api(uint32_t api_version)
#define BOTAN_CURRENT_FUNCTION
int botan_pk_op_key_agreement_export_public(botan_privkey_t key, uint8_t out[], size_t *out_len)
void update(const uint8_t in[], size_t length)
int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
RandomNumberGenerator & system_rng()
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t *out_len)
int botan_mac_final(botan_mac_t mac, uint8_t out[])
int botan_hash_output_length(botan_hash_t hash, size_t *out)
int botan_pubkey_dsa_get_q(botan_mp_t q, botan_pubkey_t key)
int botan_mp_to_uint32(const botan_mp_t mp, uint32_t *val)
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_mp_rand_range(botan_mp_t rand_out, botan_rng_t rng, const botan_mp_t lower, const botan_mp_t upper)
int botan_cipher_init(botan_cipher_t *cipher, const char *cipher_name, uint32_t flags)
int botan_x509_cert_get_public_key(botan_x509_cert_t cert, botan_pubkey_t *key)
void binary_decode(const uint8_t buf[], size_t length)
int botan_mp_num_bits(const botan_mp_t mp, size_t *bits)
int botan_mp_set_from_int(botan_mp_t mp, int initial_value)
struct botan_pk_op_ka_struct * botan_pk_op_ka_t
int botan_mp_set_from_mp(botan_mp_t dest, const botan_mp_t source)
int botan_block_cipher_set_key(botan_block_cipher_t bc, const uint8_t key[], size_t len)
int botan_mp_from_bin(botan_mp_t mp, const uint8_t bin[], size_t bin_len)
#define BOTAN_FFI_ERROR_NULL_POINTER
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)
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
#define BOTAN_FFI_DO(T, obj, param, block)
int botan_cipher_clear(botan_cipher_t cipher)
std::unique_ptr< Private_Key > create_private_key(const std::string &alg_name, RandomNumberGenerator &rng, const std::string ¶ms)
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_mp_gcd(botan_mp_t out, const botan_mp_t x, const botan_mp_t y)
int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags)
int botan_x509_cert_load_file(botan_x509_cert_t *cert_obj, const char *cert_path)
static std::vector< uint8_t > encode(const BigInt &n, Base base=Binary)
int botan_pk_op_verify_create(botan_pk_op_verify_t *op, botan_pubkey_t key_obj, const char *hash, uint32_t flags)
#define BOTAN_FFI_DECLARE_STRUCT(NAME, TYPE, MAGIC)
struct botan_pubkey_struct * botan_pubkey_t
KDF * get_kdf(const std::string &algo_spec)
int botan_mp_init(botan_mp_t *mp)
struct botan_cipher_struct * botan_cipher_t
int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl)
virtual size_t block_size() const =0
virtual size_t output_length() const =0
int botan_pubkey_dsa_get_p(botan_mp_t p, botan_pubkey_t key)
const char * botan_version_string()
int botan_mp_sub(botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
struct botan_rng_struct * botan_rng_t
static BigInt decode(const uint8_t buf[], size_t length, Base base=Binary)
int botan_privkey_rsa_get_d(botan_mp_t d, botan_privkey_t key)
virtual bool valid_nonce_length(size_t nonce_len) const =0
int botan_pubkey_fingerprint(botan_pubkey_t key, const char *hash_fn, uint8_t out[], size_t *out_len)
virtual void finish(secure_vector< uint8_t > &final_block, size_t offset=0)=0
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)
int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t *out_len)
#define BOTAN_ASSERT_ARG_NON_NULL(p)
int botan_privkey_destroy(botan_privkey_t key)
int botan_pk_op_decrypt_destroy(botan_pk_op_decrypt_t op)
int botan_mp_to_bin(const botan_mp_t mp, uint8_t vec[])
int botan_mac_output_length(botan_mac_t mac, size_t *out)