aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_kdf.cpp
blob: 86b3ea5c4762d1e8a92ae6e4cc59490b63a7656f (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
#include "tests.h"

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

using namespace Botan;

namespace {

secure_vector<byte> kdf(const std::string& algo,
                        size_t outlen,
                        const secure_vector<byte>& secret,
                        const secure_vector<byte>& salt)
   {
   std::unique_ptr<KDF> kdf(get_kdf(algo));
   return kdf->derive_key(outlen, secret, salt);
   }

std::string kdf_test(const std::string& algo,
                     size_t outlen,
                     const std::string& secret,
                     const std::string& salt)
   {
   return hex_encode(kdf(algo, outlen,
                         hex_decode_locked(secret),
                         hex_decode_locked(salt)));
   }

}

size_t test_kdf()
   {
   std::ifstream vec(TEST_DATA_DIR "/kdf.vec");

   return run_tests(vec, "KDF", "Output", true,
             [](std::map<std::string, std::string> m)
             {
             return kdf_test(m["KDF"], to_u32bit(m["OutputLen"]),
                             m["Secret"], m["Salt"]);
             });
   }