Botan 2.19.2
Crypto and TLS for C&
ffi_keywrap.cpp
Go to the documentation of this file.
1/*
2* (C) 2017 Ribose Inc
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/ffi.h>
8#include <botan/internal/ffi_util.h>
9
10#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
11 #include <botan/rfc3394.h>
12#endif
13
14extern "C" {
15
16using namespace Botan_FFI;
17
18int botan_key_wrap3394(const uint8_t key[], size_t key_len,
19 const uint8_t kek[], size_t kek_len,
20 uint8_t wrapped_key[], size_t* wrapped_key_len)
21 {
22#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
23 return ffi_guard_thunk(__func__, [=]() -> int {
24 const Botan::SymmetricKey kek_sym(kek, kek_len);
25 const Botan::secure_vector<uint8_t> key_pt(key, key + key_len);
26 const Botan::secure_vector<uint8_t> key_ct = Botan::rfc3394_keywrap(key_pt, kek_sym);
27 return write_vec_output(wrapped_key, wrapped_key_len, key_ct);
28 });
29#else
31#endif
32 }
33
34int botan_key_unwrap3394(const uint8_t wrapped_key[], size_t wrapped_key_len,
35 const uint8_t kek[], size_t kek_len,
36 uint8_t key[], size_t* key_len)
37 {
38#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
39 return ffi_guard_thunk(__func__, [=]() -> int {
40 const Botan::SymmetricKey kek_sym(kek, kek_len);
41 const Botan::secure_vector<uint8_t> key_ct(wrapped_key, wrapped_key + wrapped_key_len);
42 const Botan::secure_vector<uint8_t> key_pt = Botan::rfc3394_keyunwrap(key_ct, kek_sym);
43 return write_vec_output(key, key_len, key_pt);
44 });
45#else
47#endif
48 }
49
50}
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:83
int botan_key_unwrap3394(const uint8_t wrapped_key[], size_t wrapped_key_len, const uint8_t kek[], size_t kek_len, uint8_t key[], size_t *key_len)
Definition: ffi_keywrap.cpp:34
int botan_key_wrap3394(const uint8_t key[], size_t key_len, const uint8_t kek[], size_t kek_len, uint8_t wrapped_key[], size_t *wrapped_key_len)
Definition: ffi_keywrap.cpp:18
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
secure_vector< uint8_t > rfc3394_keywrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:14
secure_vector< uint8_t > rfc3394_keyunwrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:28
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65