Botan 3.5.0
Crypto and TLS for C&
ffi_block.cpp File Reference
#include <botan/ffi.h>
#include <botan/block_cipher.h>
#include <botan/internal/ffi_util.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 61 of file ffi_block.cpp.

61 {
62 return BOTAN_FFI_VISIT(bc, [](const auto& b) { return static_cast<int>(b.block_size()); });
63}
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:124

References BOTAN_FFI_VISIT.

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

43 {
44 return BOTAN_FFI_VISIT(bc, [](auto& b) { b.clear(); });
45}

References BOTAN_FFI_VISIT.

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

Decrypt one or more blocks with the cipher

Definition at line 72 of file ffi_block.cpp.

72 {
73 if(in == nullptr || out == nullptr) {
75 }
76 return BOTAN_FFI_VISIT(bc, [=](const auto& b) { b.decrypt_n(in, out, blocks); });
77}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:118

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_block_cipher_destroy()

int botan_block_cipher_destroy ( botan_block_cipher_t bc)

Destroy a block cipher object

Definition at line 39 of file ffi_block.cpp.

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

References 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 )

Encrypt one or more blocks with the cipher

Definition at line 65 of file ffi_block.cpp.

65 {
66 if(in == nullptr || out == nullptr) {
68 }
69 return BOTAN_FFI_VISIT(bc, [=](const auto& b) { b.encrypt_n(in, out, blocks); });
70}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

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

Get the key length limits of this block cipher

Parameters
cipherthe object to read
out_minimum_keylengthif non-NULL, will be set to minimum keylength of cipher
out_maximum_keylengthif non-NULL, will be set to maximum keylength of cipher
out_keylength_moduloif non-NULL will be set to byte multiple of valid keys

Definition at line 87 of file ffi_block.cpp.

90 {
91 return BOTAN_FFI_VISIT(cipher, [=](const auto& bc) {
92 if(out_minimum_keylength)
93 *out_minimum_keylength = bc.minimum_keylength();
94 if(out_maximum_keylength)
95 *out_maximum_keylength = bc.maximum_keylength();
96 if(out_keylength_modulo)
97 *out_keylength_modulo = bc.key_spec().keylength_multiple();
98 });
99}

References BOTAN_FFI_VISIT.

◆ 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 18 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
24 *bc = nullptr;
25
26 auto cipher = Botan::BlockCipher::create(bc_name);
27 if(cipher == nullptr) {
29 }
30
31 *bc = new botan_block_cipher_struct(std::move(cipher));
32 return BOTAN_FFI_SUCCESS;
33 });
34}
static std::unique_ptr< BlockCipher > create(std::string_view algo_spec, std::string_view provider="")
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:124
@ BOTAN_FFI_SUCCESS
Definition ffi.h:103
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition ffi.cpp:116

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::BlockCipher::create(), 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 )

Get the name of this block cipher

Parameters
cipherthe object to read
nameoutput buffer
name_lenon input, the length of buffer, on success the number of bytes written

Definition at line 79 of file ffi_block.cpp.

79 {
80 if(name_len == nullptr) {
82 }
83
84 return BOTAN_FFI_VISIT(cipher, [=](const auto& bc) { return write_str_output(name, name_len, bc.name()); });
85}
std::string name
int write_str_output(uint8_t out[], size_t *out_len, std::string_view str)
Definition ffi_util.h:205

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, name, 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.

50 {
51 if(key == nullptr) {
53 }
54 return BOTAN_FFI_VISIT(bc, [=](auto& b) { b.set_key(key, len); });
55}

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ BOTAN_FFI_DECLARE_STRUCT()

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