9#include <botan/pubkey.h>
10#include <botan/system_rng.h>
11#include <botan/internal/ffi_pkey.h>
12#include <botan/internal/ffi_rng.h>
13#include <botan/internal/ffi_util.h>
41 *op =
new botan_pk_op_encrypt_struct(std::move(pk));
51 if(ctext_len ==
nullptr) {
54 return BOTAN_FFI_VISIT(op, [=](
const auto& o) { *ctext_len = o.ciphertext_length(ptext_len); });
61 const uint8_t plaintext[],
62 size_t plaintext_len) {
87 *op =
new botan_pk_op_decrypt_struct(std::move(pk));
97 if(ptext_len ==
nullptr) {
100 return BOTAN_FFI_VISIT(op, [=](
const auto& o) { *ptext_len = o.plaintext_length(ctext_len); });
104 botan_pk_op_decrypt_t op, uint8_t out[],
size_t* out_len,
const uint8_t ciphertext[],
size_t ciphertext_len) {
106 op, [=](
const auto& o) {
return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len)); });
128 *op =
new botan_pk_op_sign_struct(std::move(pk));
138 if(sig_len ==
nullptr) {
142 return BOTAN_FFI_VISIT(op, [=](
const auto& o) { *sig_len = o.signature_length(); });
166 auto pk = std::make_unique<Botan::PK_Verifier>(
safe_get(key_obj), hash, format);
167 *op =
new botan_pk_op_verify_struct(std::move(pk));
182 const bool legit = o.check_signature(sig, sig_len);
203 *op =
new botan_pk_op_ka_struct(std::move(pk));
227 if(out_len ==
nullptr)
229 *out_len = o.agreed_value_size();
237 const uint8_t other_key[],
238 size_t other_key_len,
239 const uint8_t salt[],
242 auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
248 if(op ==
nullptr || padding ==
nullptr) {
253 auto pk = std::make_unique<Botan::PK_KEM_Encryptor>(
safe_get(key_obj), padding);
254 *op =
new botan_pk_op_kem_encrypt_struct(std::move(pk));
264 size_t desired_shared_key_length,
265 size_t* output_shared_key_length) {
266 if(output_shared_key_length ==
nullptr) {
271 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
277 size_t* output_encapsulated_key_length) {
278 if(output_encapsulated_key_length ==
nullptr) {
283 *output_encapsulated_key_length = kem.encapsulated_key_length();
290 const uint8_t salt[],
292 size_t desired_shared_key_len,
293 uint8_t shared_key_out[],
294 size_t* shared_key_len,
295 uint8_t encapsulated_key_out[],
296 size_t* encapsulated_key_len) {
298 const auto result = kem.encrypt(
safe_get(rng), desired_shared_key_len, {salt, salt_len});
300 int rc =
write_vec_output(encapsulated_key_out, encapsulated_key_len, result.encapsulated_shared_key());
305 return write_vec_output(shared_key_out, shared_key_len, result.shared_key());
310 if(op ==
nullptr || padding ==
nullptr) {
316 *op =
new botan_pk_op_kem_decrypt_struct(std::move(pk));
322 size_t desired_shared_key_length,
323 size_t* output_shared_key_length) {
324 if(output_shared_key_length ==
nullptr) {
329 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
335 const uint8_t salt[],
337 const uint8_t encapsulated_key[],
338 size_t encapsulated_key_len,
339 size_t desired_shared_key_len,
340 uint8_t shared_key_out[],
341 size_t* shared_key_len) {
343 const auto shared_key =
344 kem.decrypt(encapsulated_key, encapsulated_key_len, desired_shared_key_len, salt, salt_len);
struct botan_pk_op_kem_decrypt_struct * botan_pk_op_kem_decrypt_t
struct botan_pubkey_struct * botan_pubkey_t
#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE
struct botan_pk_op_decrypt_struct * botan_pk_op_decrypt_t
struct botan_privkey_struct * botan_privkey_t
struct botan_pk_op_encrypt_struct * botan_pk_op_encrypt_t
struct botan_pk_op_kem_encrypt_struct * botan_pk_op_kem_encrypt_t
int(* botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t *data, size_t len)
struct botan_pk_op_ka_struct * botan_pk_op_ka_t
struct botan_pk_op_sign_struct * botan_pk_op_sign_t
struct botan_rng_struct * botan_rng_t
@ BOTAN_FFI_INVALID_VERIFIER
@ BOTAN_FFI_ERROR_BAD_FLAG
@ BOTAN_FFI_ERROR_INVALID_INPUT
@ BOTAN_FFI_ERROR_NULL_POINTER
struct botan_pk_op_verify_struct * botan_pk_op_verify_t
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_decrypt(botan_pk_op_decrypt_t op, uint8_t out[], size_t *out_len, const uint8_t ciphertext[], size_t ciphertext_len)
int botan_pk_op_kem_decrypt_create(botan_pk_op_kem_decrypt_t *op, botan_privkey_t key_obj, const char *padding)
int botan_pk_op_sign_output_length(botan_pk_op_sign_t op, size_t *sig_len)
int botan_pk_op_key_agreement_export_public(botan_privkey_t key, uint8_t out[], size_t *out_len)
int botan_pk_op_kem_decrypt_shared_key(botan_pk_op_kem_decrypt_t op, const uint8_t salt[], size_t salt_len, const uint8_t encapsulated_key[], size_t encapsulated_key_len, size_t desired_shared_key_len, uint8_t shared_key_out[], size_t *shared_key_len)
int botan_pk_op_kem_encrypt_shared_key_length(botan_pk_op_kem_encrypt_t op, size_t desired_shared_key_length, size_t *output_shared_key_length)
int botan_pk_op_key_agreement_size(botan_pk_op_ka_t op, 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_decrypt_destroy(botan_pk_op_decrypt_t op)
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_kem_encrypt_create_shared_key(botan_pk_op_kem_encrypt_t op, botan_rng_t rng, const uint8_t salt[], size_t salt_len, size_t desired_shared_key_len, uint8_t shared_key_out[], size_t *shared_key_len, uint8_t encapsulated_key_out[], size_t *encapsulated_key_len)
int botan_pk_op_key_agreement_destroy(botan_pk_op_ka_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_verify_update(botan_pk_op_verify_t op, const uint8_t in[], size_t in_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_verify_destroy(botan_pk_op_verify_t op)
int botan_pk_op_kem_encrypt_create(botan_pk_op_kem_encrypt_t *op, botan_pubkey_t key_obj, const char *padding)
int botan_pk_op_key_agreement_view_public(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_pk_op_kem_encrypt_encapsulated_key_length(botan_pk_op_kem_encrypt_t op, size_t *output_encapsulated_key_length)
int botan_pk_op_verify_finish(botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len)
int botan_pk_op_decrypt_output_length(botan_pk_op_decrypt_t op, size_t ctext_len, size_t *ptext_len)
int botan_pk_op_encrypt_output_length(botan_pk_op_encrypt_t op, size_t ptext_len, size_t *ctext_len)
int botan_pk_op_key_agreement(botan_pk_op_ka_t op, uint8_t out[], size_t *out_len, const uint8_t other_key[], size_t other_key_len, const uint8_t salt[], size_t salt_len)
int botan_pk_op_kem_encrypt_destroy(botan_pk_op_kem_encrypt_t op)
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_encrypt_destroy(botan_pk_op_encrypt_t op)
int botan_pk_op_kem_decrypt_shared_key_length(botan_pk_op_kem_decrypt_t op, size_t desired_shared_key_length, size_t *output_shared_key_length)
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_kem_decrypt_destroy(botan_pk_op_kem_decrypt_t op)
int botan_pk_op_sign_destroy(botan_pk_op_sign_t op)
int botan_pk_op_key_agreement_create(botan_pk_op_ka_t *op, botan_privkey_t key_obj, const char *kdf, uint32_t flags)
#define BOTAN_FFI_VISIT(obj, lambda)
#define BOTAN_FFI_CHECKED_DELETE(o)
#define BOTAN_FFI_DECLARE_STRUCT(NAME, TYPE, MAGIC)
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
T & safe_get(botan_struct< T, M > *p)
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, const std::vector< uint8_t, Alloc > &buf)
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
RandomNumberGenerator & system_rng()