Botan  2.11.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_get_keyspec (botan_block_cipher_t cipher, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
 
int botan_block_cipher_init (botan_block_cipher_t *bc, const char *bc_name)
 
int botan_block_cipher_name (botan_block_cipher_t cipher, char *name, size_t *name_len)
 
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 62 of file ffi_block.cpp.

63  {
64  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b,
65  { return static_cast<int>(b.block_size()); });
66  }
bool const OID & b
Definition: asn1_oid.h:109
std::vector< uint8_t > size_t const BlockCipher & bc
Definition: nist_keywrap.h:25
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

References Botan::b, Botan::bc, and BOTAN_FFI_DO.

◆ botan_block_cipher_clear()

int botan_block_cipher_clear ( botan_block_cipher_t  bc)

Definition at line 42 of file ffi_block.cpp.

43  {
44  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.clear(); });
45  }
bool const OID & b
Definition: asn1_oid.h:109
std::vector< uint8_t > size_t const BlockCipher & bc
Definition: nist_keywrap.h:25
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

References Botan::b, Botan::bc, and BOTAN_FFI_DO.

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

82  {
83  if(in == nullptr || out == nullptr)
85  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.decrypt_n(in, out, blocks); });
86  }
bool const OID & b
Definition: asn1_oid.h:109
const uint8_t * in
Definition: ffi.h:297
size_t char * out
Definition: ffi.h:162
const uint8_t uint8_t size_t blocks
Definition: ffi.h:691
std::vector< uint8_t > size_t const BlockCipher & bc
Definition: nist_keywrap.h:25
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

References Botan::b, Botan::bc, blocks, BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, in, and out.

◆ 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.

38  {
40  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:120
std::vector< uint8_t > size_t const BlockCipher & bc
Definition: nist_keywrap.h:25

References Botan::bc, and BOTAN_FFI_CHECKED_DELETE.

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

72  {
73  if(in == nullptr || out == nullptr)
75  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.encrypt_n(in, out, blocks); });
76  }
bool const OID & b
Definition: asn1_oid.h:109
const uint8_t * in
Definition: ffi.h:297
size_t char * out
Definition: ffi.h:162
const uint8_t uint8_t size_t blocks
Definition: ffi.h:691
std::vector< uint8_t > size_t const BlockCipher & bc
Definition: nist_keywrap.h:25
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

References Botan::b, Botan::bc, blocks, BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, in, and out.

◆ botan_block_cipher_get_keyspec()

int botan_block_cipher_get_keyspec ( botan_block_cipher_t  cipher,
size_t *  out_minimum_keylength,
size_t *  out_maximum_keylength,
size_t *  out_keylength_modulo 
)

Definition at line 97 of file ffi_block.cpp.

101  {
102  return BOTAN_FFI_DO(Botan::BlockCipher, cipher, bc, {
104  *out_minimum_keylength = bc.minimum_keylength();
106  *out_maximum_keylength = bc.maximum_keylength();
108  *out_keylength_modulo = bc.key_spec().keylength_multiple();
109  });
110  }
size_t size_t size_t * out_keylength_modulo
Definition: ffi.h:407
size_t size_t * out_maximum_keylength
Definition: ffi.h:407
void BlockCipher * cipher
Definition: package.h:29
std::vector< uint8_t > size_t const BlockCipher & bc
Definition: nist_keywrap.h:25
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
size_t * out_minimum_keylength
Definition: ffi.h:407

References Botan::bc, BOTAN_FFI_DO, Botan::cipher, out_keylength_modulo, out_maximum_keylength, and out_minimum_keylength.

◆ botan_block_cipher_init()

int botan_block_cipher_init ( botan_block_cipher_t bc,
const char *  bc_name 
)

Definition at line 17 of file ffi_block.cpp.

18  {
19  return ffi_guard_thunk(__func__, [=]() -> 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, std::function< int()> thunk)
Definition: ffi.cpp:86
void BlockCipher * cipher
Definition: package.h:29
std::vector< uint8_t > size_t const BlockCipher & bc
Definition: nist_keywrap.h:25

References Botan::bc, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::cipher, and Botan_FFI::ffi_guard_thunk().

◆ botan_block_cipher_name()

int botan_block_cipher_name ( botan_block_cipher_t  cipher,
char *  name,
size_t *  name_len 
)

Definition at line 88 of file ffi_block.cpp.

89  {
90  if(name_len == nullptr)
92 
93  return BOTAN_FFI_DO(Botan::BlockCipher, cipher, bc, {
94  return write_str_output(name, name_len, bc.name()); });
95  }
char * name
Definition: ffi.h:330
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
void BlockCipher * cipher
Definition: package.h:29
char size_t * name_len
Definition: ffi.h:330
std::vector< uint8_t > size_t const BlockCipher & bc
Definition: nist_keywrap.h:25
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

References Botan::bc, BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, Botan::cipher, name, name_len, and Botan_FFI::write_str_output().

◆ 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.

52  {
53  if(key == nullptr)
55  return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.set_key(key, len); });
56  }
bool const OID & b
Definition: asn1_oid.h:109
const uint8_t * key
Definition: ffi.h:362
const uint8_t size_t len
Definition: ffi.h:139
std::vector< uint8_t > size_t const BlockCipher & bc
Definition: nist_keywrap.h:25
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

References Botan::b, Botan::bc, BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, key, and len.

◆ BOTAN_FFI_DECLARE_STRUCT()

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