Coverage Report

Created: 2025-08-28 06:21

/src/Botan-3.4.0/src/lib/misc/rfc3394/rfc3394.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* AES Key Wrap (RFC 3394)
3
* (C) 2011 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#include <botan/rfc3394.h>
9
10
#include <botan/block_cipher.h>
11
#include <botan/nist_keywrap.h>
12
13
namespace Botan {
14
15
0
secure_vector<uint8_t> rfc3394_keywrap(const secure_vector<uint8_t>& key, const SymmetricKey& kek) {
16
0
   BOTAN_ARG_CHECK(kek.size() == 16 || kek.size() == 24 || kek.size() == 32, "Invalid KEK length for NIST key wrap");
17
18
0
   const std::string cipher_name = "AES-" + std::to_string(8 * kek.size());
19
0
   auto aes = BlockCipher::create_or_throw(cipher_name);
20
0
   aes->set_key(kek);
21
22
0
   std::vector<uint8_t> wrapped = nist_key_wrap(key.data(), key.size(), *aes);
23
0
   return secure_vector<uint8_t>(wrapped.begin(), wrapped.end());
24
0
}
25
26
0
secure_vector<uint8_t> rfc3394_keyunwrap(const secure_vector<uint8_t>& key, const SymmetricKey& kek) {
27
0
   BOTAN_ARG_CHECK(kek.size() == 16 || kek.size() == 24 || kek.size() == 32, "Invalid KEK length for NIST key wrap");
28
29
0
   BOTAN_ARG_CHECK(key.size() >= 16 && key.size() % 8 == 0, "Bad input key size for NIST key unwrap");
30
31
0
   const std::string cipher_name = "AES-" + std::to_string(8 * kek.size());
32
0
   auto aes = BlockCipher::create_or_throw(cipher_name);
33
0
   aes->set_key(kek);
34
35
0
   return nist_key_unwrap(key.data(), key.size(), *aes);
36
0
}
37
38
}  // namespace Botan