diff options
author | Jack Lloyd <[email protected]> | 2017-07-25 15:24:30 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-07-31 10:31:53 -0400 |
commit | 5703b195f5dbf0a0df45bf0a7f39aa090666f877 (patch) | |
tree | 1f686ae1362aaef9eabe1db3c1a58ac0fd166a70 /src/lib/ffi/ffi_mac.cpp | |
parent | bb30a1e1ffbe839478b4bf04624d841c6d9ecfc3 (diff) |
Split up ffi.cpp into several files
It was getting pretty big and would get worse over time, eg whenver
I get around to adding TLS support.
Diffstat (limited to 'src/lib/ffi/ffi_mac.cpp')
-rw-r--r-- | src/lib/ffi/ffi_mac.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/lib/ffi/ffi_mac.cpp b/src/lib/ffi/ffi_mac.cpp new file mode 100644 index 000000000..b3237592f --- /dev/null +++ b/src/lib/ffi/ffi_mac.cpp @@ -0,0 +1,64 @@ +/* +* (C) 2015,2017 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include <botan/ffi.h> +#include <botan/internal/ffi_util.h> +#include <botan/mac.h> + +extern "C" { + +using namespace Botan_FFI; + +BOTAN_FFI_DECLARE_STRUCT(botan_mac_struct, Botan::MessageAuthenticationCode, 0xA06E8FC1); + +int botan_mac_init(botan_mac_t* mac, const char* mac_name, uint32_t flags) + { + return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() { + if(!mac || !mac_name || flags != 0) + return BOTAN_FFI_ERROR_NULL_POINTER; + + std::unique_ptr<Botan::MessageAuthenticationCode> m = + Botan::MessageAuthenticationCode::create(mac_name); + + if(m == nullptr) + return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; + + *mac = new botan_mac_struct(m.release()); + return BOTAN_FFI_SUCCESS; + }); + } + +int botan_mac_destroy(botan_mac_t mac) + { + return BOTAN_FFI_CHECKED_DELETE(mac); + } + +int botan_mac_set_key(botan_mac_t mac, const uint8_t* key, size_t key_len) + { + return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.set_key(key, key_len); }); + } + +int botan_mac_output_length(botan_mac_t mac, size_t* out) + { + return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { *out = m.output_length(); }); + } + +int botan_mac_clear(botan_mac_t mac) + { + return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.clear(); }); + } + +int botan_mac_update(botan_mac_t mac, const uint8_t* buf, size_t len) + { + return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.update(buf, len); }); + } + +int botan_mac_final(botan_mac_t mac, uint8_t out[]) + { + return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { m.final(out); }); + } + +} |