Botan  2.7.0
Crypto and TLS for C++11
Functions
ffi_block.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_util.h>
#include <botan/block_cipher.h>

Go to the source code of this file.

Functions

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)
 
 BOTAN_FFI_DECLARE_STRUCT (botan_block_cipher_struct, Botan::BlockCipher, 0x64C29716)
 

Function Documentation

◆ botan_block_cipher_block_size()

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 60 of file ffi_block.cpp.

References BOTAN_FFI_DO.

61  {
62  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b,
63  { return static_cast<int>(b.block_size()); });
64  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_block_cipher_clear()

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 42 of file ffi_block.cpp.

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

43  {
44  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.clear(); });
45  }
virtual void clear()=0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_block_cipher_decrypt_blocks()

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

Definition at line 74 of file ffi_block.cpp.

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

78  {
79  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.decrypt_n(in, out, blocks); });
80  }
virtual void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_block_cipher_destroy()

int botan_block_cipher_destroy ( botan_block_cipher_t  bc)

Destroy a block cipher object

Definition at line 37 of file ffi_block.cpp.

References BOTAN_FFI_CHECKED_DELETE.

38  {
39  return BOTAN_FFI_CHECKED_DELETE(bc);
40  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

◆ botan_block_cipher_encrypt_blocks()

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

Definition at line 66 of file ffi_block.cpp.

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

70  {
71  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.encrypt_n(in, out, blocks); });
72  }
virtual void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_block_cipher_init()

int botan_block_cipher_init ( botan_block_cipher_t bc,
const char *  cipher_name 
)

Initialize a block cipher object

Definition at line 17 of file ffi_block.cpp.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::BlockCipher::create(), and Botan_FFI::ffi_guard_thunk().

18  {
19  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
20  if(bc == nullptr || bc_name == nullptr || *bc_name == 0)
22 
23  *bc = nullptr;
24 
25  std::unique_ptr<Botan::BlockCipher> cipher(Botan::BlockCipher::create(bc_name));
26  if(cipher == nullptr)
28 
29  *bc = new botan_block_cipher_struct(cipher.release());
30  return BOTAN_FFI_SUCCESS;
31  });
32  }
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_block_cipher_set_key()

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 50 of file ffi_block.cpp.

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

52  {
53  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.set_key(key, len); });
54  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:65
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ BOTAN_FFI_DECLARE_STRUCT()

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