Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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(__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
30 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
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(__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
46 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
47 #endif
48 }
49
50 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::OctetString
Definition: symkey.h:19
botan_key_unwrap3394
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
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::write_vec_output
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:155
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
botan_key_wrap3394
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
Botan_FFI
Definition: ffi.cpp:17
Botan::rfc3394_keywrap
secure_vector< uint8_t > rfc3394_keywrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:14
Botan::rfc3394_keyunwrap
secure_vector< uint8_t > rfc3394_keyunwrap(const secure_vector< uint8_t > &key, const SymmetricKey &kek)
Definition: rfc3394.cpp:28