Botan  2.4.0
Crypto and TLS for C++11
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 
14 extern "C" {
15 
16 using namespace Botan_FFI;
17 
18 int 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(BOTAN_CURRENT_FUNCTION, [=]() -> 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 
34 int 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(BOTAN_CURRENT_FUNCTION, [=]() -> 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 }
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 ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
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
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
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