summaryrefslogtreecommitdiffstats
path: root/comm/third_party/botan/src/lib/misc/rfc3394
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /comm/third_party/botan/src/lib/misc/rfc3394
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/third_party/botan/src/lib/misc/rfc3394')
-rw-r--r--comm/third_party/botan/src/lib/misc/rfc3394/info.txt8
-rw-r--r--comm/third_party/botan/src/lib/misc/rfc3394/rfc3394.cpp44
-rw-r--r--comm/third_party/botan/src/lib/misc/rfc3394/rfc3394.h39
3 files changed, 91 insertions, 0 deletions
diff --git a/comm/third_party/botan/src/lib/misc/rfc3394/info.txt b/comm/third_party/botan/src/lib/misc/rfc3394/info.txt
new file mode 100644
index 0000000000..075834219a
--- /dev/null
+++ b/comm/third_party/botan/src/lib/misc/rfc3394/info.txt
@@ -0,0 +1,8 @@
+<defines>
+RFC3394_KEYWRAP -> 20131128
+</defines>
+
+<requires>
+aes
+nist_keywrap
+</requires>
diff --git a/comm/third_party/botan/src/lib/misc/rfc3394/rfc3394.cpp b/comm/third_party/botan/src/lib/misc/rfc3394/rfc3394.cpp
new file mode 100644
index 0000000000..cb24809984
--- /dev/null
+++ b/comm/third_party/botan/src/lib/misc/rfc3394/rfc3394.cpp
@@ -0,0 +1,44 @@
+/*
+* AES Key Wrap (RFC 3394)
+* (C) 2011 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/rfc3394.h>
+#include <botan/nist_keywrap.h>
+#include <botan/block_cipher.h>
+
+namespace Botan {
+
+secure_vector<uint8_t> rfc3394_keywrap(const secure_vector<uint8_t>& key,
+ const SymmetricKey& kek)
+ {
+ BOTAN_ARG_CHECK(kek.size() == 16 || kek.size() == 24 || kek.size() == 32,
+ "Invalid KEK length for NIST key wrap");
+
+ const std::string cipher_name = "AES-" + std::to_string(8*kek.size());
+ std::unique_ptr<BlockCipher> aes(BlockCipher::create_or_throw(cipher_name));
+ aes->set_key(kek);
+
+ std::vector<uint8_t> wrapped = nist_key_wrap(key.data(), key.size(), *aes);
+ return secure_vector<uint8_t>(wrapped.begin(), wrapped.end());
+ }
+
+secure_vector<uint8_t> rfc3394_keyunwrap(const secure_vector<uint8_t>& key,
+ const SymmetricKey& kek)
+ {
+ BOTAN_ARG_CHECK(kek.size() == 16 || kek.size() == 24 || kek.size() == 32,
+ "Invalid KEK length for NIST key wrap");
+
+ BOTAN_ARG_CHECK(key.size() >= 16 && key.size() % 8 == 0,
+ "Bad input key size for NIST key unwrap");
+
+ const std::string cipher_name = "AES-" + std::to_string(8*kek.size());
+ std::unique_ptr<BlockCipher> aes(BlockCipher::create_or_throw(cipher_name));
+ aes->set_key(kek);
+
+ return nist_key_unwrap(key.data(), key.size(), *aes);
+ }
+
+}
diff --git a/comm/third_party/botan/src/lib/misc/rfc3394/rfc3394.h b/comm/third_party/botan/src/lib/misc/rfc3394/rfc3394.h
new file mode 100644
index 0000000000..9cfcfaaf6d
--- /dev/null
+++ b/comm/third_party/botan/src/lib/misc/rfc3394/rfc3394.h
@@ -0,0 +1,39 @@
+/*
+* AES Key Wrap (RFC 3394)
+* (C) 2011 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#ifndef BOTAN_RFC3394_H_
+#define BOTAN_RFC3394_H_
+
+#include <botan/symkey.h>
+
+namespace Botan {
+
+/**
+* Encrypt a key under a key encryption key using the algorithm
+* described in RFC 3394
+*
+* @param key the plaintext key to encrypt
+* @param kek the key encryption key
+* @return key encrypted under kek
+*/
+secure_vector<uint8_t> BOTAN_PUBLIC_API(2,0) rfc3394_keywrap(const secure_vector<uint8_t>& key,
+ const SymmetricKey& kek);
+
+/**
+* Decrypt a key under a key encryption key using the algorithm
+* described in RFC 3394
+*
+* @param key the encrypted key to decrypt
+* @param kek the key encryption key
+* @return key decrypted under kek
+*/
+secure_vector<uint8_t> BOTAN_PUBLIC_API(2,0) rfc3394_keyunwrap(const secure_vector<uint8_t>& key,
+ const SymmetricKey& kek);
+
+}
+
+#endif