aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_kdf.cpp
blob: 30541d4598e4cf5b68af3cfb719e0f08c066de5f (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
/*
* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include "tests.h"

#if defined(BOTAN_HAS_KDF_BASE)

#include <botan/kdf.h>
#include <botan/hex.h>
#include <iostream>
#include <fstream>

using namespace Botan;

size_t test_kdf()
   {
   auto test = [](const std::string& input)
      {
      return run_tests(input, "KDF", "Output", true,
             [](std::map<std::string, std::string> vec)
             {
             std::unique_ptr<KDF> kdf(get_kdf(vec["KDF"]));

             const size_t outlen = to_u32bit(vec["OutputLen"]);
             const auto salt = hex_decode(vec["Salt"]);
             const auto secret = hex_decode(vec["Secret"]);

             const auto key = kdf->derive_key(outlen, secret, salt);

             return hex_encode(key);
             });
      };

   return run_tests_in_dir(TEST_DATA_DIR "/kdf", test);
   }

#else

SKIP_TEST(kdf);

#endif // BOTAN_HAS_KDF_BASE