Botan 2.19.5 Crypto and TLS for C&

Functions
ffi_mac.cpp File Reference
`#include <botan/ffi.h>`
`#include <botan/internal/ffi_util.h>`
`#include <botan/mac.h>`

Go to the source code of this file.

## Functions
| BOTAN_FFI_DECLARE_STRUCT (botan_mac_struct, Botan::MessageAuthenticationCode, 0xA06E8FC1)
int | botan_mac_clear (botan_mac_t mac)
int | botan_mac_destroy (botan_mac_t mac)
int | botan_mac_final (botan_mac_t mac, uint8_t out[])
int | botan_mac_get_keyspec (botan_mac_t mac, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
int | botan_mac_init (botan_mac_t *mac, const char *mac_name, uint32_t flags)
int | botan_mac_name (botan_mac_t mac, char *name, size_t *name_len)
int | botan_mac_output_length (botan_mac_t mac, size_t *out)
int | botan_mac_set_key (botan_mac_t mac, const uint8_t *key, size_t key_len)
int | botan_mac_update (botan_mac_t mac, const uint8_t *buf, size_t len)

## Function Documentation

## ◆ BOTAN_FFI_DECLARE_STRUCT()

BOTAN_FFI_DECLARE_STRUCT | ( | botan_mac_struct | ,
|  | Botan::MessageAuthenticationCode | ,
|  | 0xA06E8FC1 |
| ) |  |

## ◆ botan_mac_clear()

int botan_mac_clear | ( | botan_mac_t | mac | ) |

Reinitializes the state of the MAC computation. A MAC can be computed (with update/final) immediately.

Parameters

  mac | mac object

Returns
  0 on success, a negative value on failure

Definition at line 49 of file ffi_mac.cpp.

50 {
51 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.clear(); });
52 }
Botan::MessageAuthenticationCode
Definition: mac.h:23
Botan::SymmetricAlgorithm::clear
virtual void clear()=0
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92

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

## ◆ botan_mac_destroy()

int botan_mac_destroy | ( | botan_mac_t | mac | ) |

Frees all resources of the MAC object

Parameters

  mac | mac object

Returns
  0 if success, error if invalid object handle

Definition at line 34 of file ffi_mac.cpp.

35 {
36 return BOTAN_FFI_CHECKED_DELETE(mac);
37 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

References BOTAN_FFI_CHECKED_DELETE.

## ◆ botan_mac_final()

int botan_mac_final | ( | botan_mac_t | mac,
|  | uint8_t | out[]
| ) |  |

Finalizes the MAC computation and writes the output to out[0:botan_mac_output_length()] then reinitializes for computing another MAC as if botan_mac_clear had been called.

Parameters

  mac | mac object
  out | output buffer

Returns
  0 on success, a negative value on failure

Definition at line 59 of file ffi_mac.cpp.

60 {
61 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.final(out); });
62 }
Botan::Buffered_Computation::final
void final(uint8_t out[])
Definition: buf_comp.h:83

References BOTAN_FFI_DO, and Botan::Buffered_Computation::final().

## ◆ botan_mac_get_keyspec()

int botan_mac_get_keyspec | ( | botan_mac_t | mac,
|  | size_t * | out_minimum_keylength,
|  | size_t * | out_maximum_keylength,
|  | size_t * | out_keylength_modulo
| ) |  |

Get the key length limits of this auth code

Parameters

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

Definition at line 70 of file ffi_mac.cpp.

74 {
75 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, {
76 if(out_minimum_keylength)
77 *out_minimum_keylength = m.minimum_keylength();
78 if(out_maximum_keylength)
79 *out_maximum_keylength = m.maximum_keylength();
80 if(out_keylength_modulo)
81 *out_keylength_modulo = m.key_spec().keylength_multiple();
82 });
83 }
Botan::SymmetricAlgorithm::minimum_keylength
size_t minimum_keylength() const
Definition: sym_algo.h:128

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

## ◆ botan_mac_init()

int botan_mac_init | ( | botan_mac_t * | mac,
|  | const char * | mac_name,
|  | uint32_t | flags
| ) |  |

Initialize a message authentication code object

Parameters

  mac | mac object
  mac_name | name of the hash function, e.g., "HMAC(SHA-384)"
  flags | should be 0 in current API revision, all other uses are reserved and return a negative value (error code)

Returns
  0 on success, a negative value on failure

Definition at line 17 of file ffi_mac.cpp.

18 {
19 return ffi_guard_thunk(__func__, [=]() -> int {
20 if(!mac || !mac_name || flags != 0)
21 return BOTAN_FFI_ERROR_NULL_POINTER;
22
23 std::unique_ptr<Botan::MessageAuthenticationCode> m =
24 Botan::MessageAuthenticationCode::create(mac_name);
25
26 if(m == nullptr)
27 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
28
29 *mac = new botan_mac_struct(m.release());
30 return BOTAN_FFI_SUCCESS;
31 });
32 }
Botan::MessageAuthenticationCode::create
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
Definition: mac.cpp:46
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:83
BOTAN_FFI_ERROR_NULL_POINTER
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:77
BOTAN_FFI_SUCCESS
@ BOTAN_FFI_SUCCESS
Definition: ffi.h:63
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:860
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan::MessageAuthenticationCode::create(), Botan_FFI::ffi_guard_thunk(), and Botan::PKCS11::flags().

## ◆ botan_mac_name()

int botan_mac_name | ( | botan_mac_t | mac,
|  | char * | name,
|  | size_t * | name_len
| ) |  |

Get the name of this MAC

Parameters

  mac | 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 64 of file ffi_mac.cpp.

65 {
66 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, {
67 return write_str_output(name, name_len, m.name()); });
68 }
name
std::string name
Definition: commoncrypto_hash.cpp:24
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

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

## ◆ botan_mac_output_length()

int botan_mac_output_length | ( | botan_mac_t | mac,
|  | size_t * | output_length
| ) |  |

Writes the output length of the message authentication code to *output_length

Parameters

  mac | mac object
  output_length | output buffer to hold the MAC output length

Returns
  0 on success, a negative value on failure

Definition at line 44 of file ffi_mac.cpp.

45 {
46 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { *out = m.output_length(); });
47 }
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

References BOTAN_FFI_DO, and Botan::Buffered_Computation::output_length().

## ◆ botan_mac_set_key()

int botan_mac_set_key | ( | botan_mac_t | mac,
|  | const uint8_t * | key,
|  | size_t | key_len
| ) |  |

Sets the key on the MAC

Parameters

  mac | mac object
  key | buffer holding the key
  key_len | size of the key buffer in bytes

Returns
  0 on success, a negative value on failure

Definition at line 39 of file ffi_mac.cpp.

40 {
41 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.set_key(key, key_len); });
42 }
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:147

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

## ◆ botan_mac_update()

int botan_mac_update | ( | botan_mac_t | mac,
|  | const uint8_t * | buf,
|  | size_t | len
| ) |  |

Send more input to the message authentication code

Parameters

  mac | mac object
  buf | input buffer
  len | number of bytes to read from the input buffer

Returns
  0 on success, a negative value on failure

Definition at line 54 of file ffi_mac.cpp.

55 {
56 return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.update(buf, len); });
57 }
Botan::Buffered_Computation::update
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:33

References BOTAN_FFI_DO, and Botan::Buffered_Computation::update().