aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_keywrap.cpp
blob: f000a8be70c5a0b7e5435a4a0edb4a10f8b0b7b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include "tests.h"

#include <botan/hex.h>

#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
  #include <botan/rfc3394.h>
#endif

namespace Botan_Tests {

namespace {

#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
class RFC3394_Keywrap_Tests : public Text_Based_Test
   {
   public:
      RFC3394_Keywrap_Tests() : Text_Based_Test("rfc3394.vec",
                                                {"Key", "KEK", "Output"})
         {}

      Test::Result run_one_test(const std::string&, const VarMap& vars) override
         {
         Test::Result result("RFC3394 keywrap");

         try
            {
            const std::vector<byte> expected = get_req_bin(vars, "Output");
            const std::vector<byte> key = get_req_bin(vars, "Key");
            const std::vector<byte> kek = get_req_bin(vars, "KEK");

            const Botan::SymmetricKey kek_sym(kek);
            const Botan::secure_vector<uint8_t> key_l(key.begin(), key.end());
            const Botan::secure_vector<uint8_t> exp_l(expected.begin(), expected.end());

            result.test_eq("encryption", Botan::rfc3394_keywrap(key_l, kek_sym), expected);
            result.test_eq("decryption", Botan::rfc3394_keyunwrap(exp_l, kek_sym), key);
            }
         catch(std::exception& e)
            {
            result.test_failure("", e.what());
            }

         return result;
         }

   };

BOTAN_REGISTER_TEST("rfc3394", RFC3394_Keywrap_Tests);
#endif

}

}