8#include <botan/internal/ffi_util.h>
15struct botan_cipher_struct
final :
public botan_struct<Botan::Cipher_Mode, 0xB4A2BF9C>
29 *cipher =
new botan_cipher_struct(mode.release());
51 if(out_len ==
nullptr)
58 size_t* out_minimum_keylength,
59 size_t* out_maximum_keylength)
62 *out_minimum_keylength = c.
key_spec().minimum_keylength();
63 *out_maximum_keylength = c.key_spec().maximum_keylength();
68 size_t* out_minimum_keylength,
69 size_t* out_maximum_keylength,
70 size_t* out_keylength_modulo)
73 if(out_minimum_keylength)
75 if(out_maximum_keylength)
76 *out_maximum_keylength = c.key_spec().maximum_keylength();
77 if(out_keylength_modulo)
78 *out_keylength_modulo = c.key_spec().keylength_multiple();
83 const uint8_t* key,
size_t key_len)
89 const uint8_t* nonce,
size_t nonce_len)
93 cipher.
start(nonce, nonce_len);
101 uint8_t output_ptr[],
102 size_t orig_output_size,
103 size_t* output_written,
104 const uint8_t input_ptr[],
105 size_t orig_input_size,
106 size_t* input_consumed)
110 size_t input_size = orig_input_size;
111 size_t output_size = orig_output_size;
112 const uint8_t* input = input_ptr;
113 uint8_t* output = output_ptr;
115 using namespace Botan;
123 mbuf.assign(input, input + input_size);
124 *input_consumed = input_size;
136 *output_written = mbuf.size();
138 if(mbuf.size() <= output_size)
140 copy_mem(output, mbuf.data(), mbuf.size());
151 *output_written = mbuf.size();
152 if(output_size >= mbuf.size())
154 copy_mem(output, mbuf.data(), mbuf.size());
166 size_t taken = 0, written = 0;
168 while(input_size >= ud && output_size >= ud)
184 *output_written = written;
185 *input_consumed = taken;
198 aead->set_associated_data(ad, ad_len);
#define BOTAN_ASSERT(expr, assertion_made)
static std::unique_ptr< Cipher_Mode > create(const std::string &algo, Cipher_Dir direction, const std::string &provider="")
virtual size_t default_nonce_length() const =0
void start(const std::vector< uint8_t, Alloc > &nonce)
virtual size_t output_length(size_t input_length) const =0
virtual void finish(secure_vector< uint8_t > &final_block, size_t offset=0)=0
virtual size_t tag_size() const
void update(secure_vector< uint8_t > &buffer, size_t offset=0)
virtual size_t minimum_final_size() const =0
virtual size_t update_granularity() const =0
virtual bool valid_nonce_length(size_t nonce_len) const =0
size_t minimum_keylength() const
void set_key(const SymmetricKey &key)
virtual Key_Length_Specification key_spec() const =0
int(* final)(unsigned char *, CTX *)
#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT
#define BOTAN_CIPHER_UPDATE_FLAG_FINAL
#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
@ BOTAN_FFI_ERROR_NULL_POINTER
@ BOTAN_FFI_ERROR_BAD_MAC
@ BOTAN_FFI_ERROR_BAD_PARAMETER
struct botan_cipher_struct * botan_cipher_t
int botan_cipher_update(botan_cipher_t cipher_obj, uint32_t flags, uint8_t output_ptr[], size_t orig_output_size, size_t *output_written, const uint8_t input_ptr[], size_t orig_input_size, size_t *input_consumed)
int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl)
int botan_cipher_output_length(botan_cipher_t cipher, size_t in_len, size_t *out_len)
int botan_cipher_reset(botan_cipher_t cipher)
int botan_cipher_destroy(botan_cipher_t cipher)
int botan_cipher_name(botan_cipher_t cipher, char *name, size_t *name_len)
int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
int botan_cipher_start(botan_cipher_t cipher_obj, const uint8_t *nonce, size_t nonce_len)
int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t *tl)
int botan_cipher_get_keyspec(botan_cipher_t cipher, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
int botan_cipher_set_key(botan_cipher_t cipher, const uint8_t *key, size_t key_len)
int botan_cipher_clear(botan_cipher_t cipher)
int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t *nl)
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_get_update_granularity(botan_cipher_t cipher, size_t *ug)
#define BOTAN_FFI_DO(T, obj, param, block)
#define BOTAN_FFI_CHECKED_DELETE(o)
#define BOTAN_FFI_RETURNING(T, obj, param, block)
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
T & safe_get(botan_struct< T, M > *p)
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
void copy_mem(T *out, const T *in, size_t n)
std::vector< T, secure_allocator< T > > secure_vector