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

#include "tests.h"

#include <botan/kdf.h>
#include <botan/lookup.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);
   }