2
* (C) 2015,2017 Jack Lloyd
4
* Botan is released under the Simplified BSD License (see license.txt)
8
#include <botan/internal/ffi_util.h>
9
#include <botan/block_cipher.h>
13
using namespace Botan_FFI;
15
BOTAN_FFI_DECLARE_STRUCT(botan_block_cipher_struct, Botan::BlockCipher, 0x64C29716);
17
int botan_block_cipher_init(botan_block_cipher_t* bc, const char* bc_name)
19
return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
20
if(bc == nullptr || bc_name == nullptr || *bc_name == 0)
21
return BOTAN_FFI_ERROR_NULL_POINTER;
25
std::unique_ptr<Botan::BlockCipher> cipher(Botan::BlockCipher::create(bc_name));
27
return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
29
*bc = new botan_block_cipher_struct(cipher.release());
30
return BOTAN_FFI_SUCCESS;
35
* Destroy a block cipher object
37
int botan_block_cipher_destroy(botan_block_cipher_t bc)
39
return BOTAN_FFI_CHECKED_DELETE(bc);
42
int botan_block_cipher_clear(botan_block_cipher_t bc)
44
return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.clear(); });
48
* Set the key for a block cipher instance
50
int botan_block_cipher_set_key(botan_block_cipher_t bc,
51
const uint8_t key[], size_t len)
53
return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.set_key(key, len); });
57
* Return the positive block size of this block cipher, or negative to
60
int botan_block_cipher_block_size(botan_block_cipher_t bc)
62
return BOTAN_FFI_DO(Botan::BlockCipher, bc, b,
63
{ return static_cast<int>(b.block_size()); });
66
int botan_block_cipher_encrypt_blocks(botan_block_cipher_t bc,
71
return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.encrypt_n(in, out, blocks); });
74
int botan_block_cipher_decrypt_blocks(botan_block_cipher_t bc,
79
return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.decrypt_n(in, out, blocks); });