Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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

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.

References BOTAN_FFI_RETURNING.

63 {
64 return BOTAN_FFI_RETURNING(Botan::BlockCipher, bc, b,
65 { return static_cast<int>(b.block_size()); });
66 }
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101
Botan::BlockCipher
Definition: block_cipher.h:21

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 }
Botan::SymmetricAlgorithm::clear
virtual void clear()=0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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

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

82 {
83 if(in == nullptr || out == nullptr)
84 return BOTAN_FFI_ERROR_NULL_POINTER;
85 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.decrypt_n(in, out, blocks); });
86 }
Botan::BlockCipher::decrypt_n
virtual void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

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

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

72 {
73 if(in == nullptr || out == nullptr)
74 return BOTAN_FFI_ERROR_NULL_POINTER;
75 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.encrypt_n(in, out, blocks); });
76 }
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::BlockCipher::encrypt_n
virtual void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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

  cipher | the object to read
  out_minimum_keylength | if non-NULL, will be set to minimum keylength of cipher
  out_maximum_keylength | if non-NULL, will be set to maximum keylength of cipher
  out_keylength_modulo | if non-NULL will be set to byte multiple of valid keys

Definition at line 97 of file ffi_block.cpp.

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

101 {
102 return BOTAN_FFI_DO(Botan::BlockCipher, cipher, bc, {
103 if(out_minimum_keylength)
104 *out_minimum_keylength = bc.minimum_keylength();
105 if(out_maximum_keylength)
106 *out_maximum_keylength = bc.maximum_keylength();
107 if(out_keylength_modulo)
108 *out_keylength_modulo = bc.key_spec().keylength_multiple();
109 });
110 }
Botan::SymmetricAlgorithm::minimum_keylength
size_t minimum_keylength() const
Definition: sym_algo.h:46
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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_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(__func__, [=]() -> int {
20 if(bc == nullptr || bc_name == nullptr || *bc_name == 0)
21 return BOTAN_FFI_ERROR_NULL_POINTER;
22
23 *bc = nullptr;
24
25 std::unique_ptr<Botan::BlockCipher> cipher(Botan::BlockCipher::create(bc_name));
26 if(cipher == nullptr)
27 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
28
29 *bc = new botan_block_cipher_struct(cipher.release());
30 return BOTAN_FFI_SUCCESS;
31 });
32 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
Botan::BlockCipher::create
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
Definition: block_cipher.cpp:108
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

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

Get the name of this block cipher

Parameters

  cipher | the object to read
  name | output buffer
  name_len | on input, the length of buffer, on success the number of bytes written

Definition at line 88 of file ffi_block.cpp.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan_FFI::write_str_output().

89 {
90 if(name_len == nullptr)
91 return BOTAN_FFI_ERROR_NULL_POINTER;
92
93 return BOTAN_FFI_DO(Botan::BlockCipher, cipher, bc, {
94 return write_str_output(name, name_len, bc.name()); });
95 }
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160
name
std::string name
Definition: commoncrypto_hash.cpp:23
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::SymmetricAlgorithm::set_key().

52 {
53 if(key == nullptr)
54 return BOTAN_FFI_ERROR_NULL_POINTER;
55 return BOTAN_FFI_DO(Botan::BlockCipher, bc, b, { b.set_key(key, len); });
56 }
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:65
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan::BlockCipher
Definition: block_cipher.h:21

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