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

#include "tests.h"

#if defined(BOTAN_HAS_RFC6979_GENERATOR)
  #include <botan/rfc6979.h>
  #include <botan/hex.h>
#endif

namespace Botan_Tests {

namespace {

#if defined(BOTAN_HAS_RFC6979_GENERATOR)

class RFC6979_KAT_Tests : public Text_Based_Test
   {
   public:
      RFC6979_KAT_Tests() : Text_Based_Test(Test::data_file("rfc6979.vec"),
                                            {"Q", "X", "H", "K"}) {}

      Test::Result run_one_test(const std::string& hash, const VarMap& vars)
         {
         const BigInt Q = get_req_bn(vars, "Q");
         const BigInt X = get_req_bn(vars, "X");
         const BigInt H = get_req_bn(vars, "H");
         const BigInt K = get_req_bn(vars, "K");

         Test::Result result("RFC 6979 nonce generation");
         result.test_eq("vector matches", Botan::generate_rfc6979_nonce(X, Q, H, hash), K);

         Botan::RFC6979_Nonce_Generator gen(hash, Q, X);

         result.test_eq("vector matches", gen.nonce_for(H), K);
         result.test_ne("vector matches", gen.nonce_for(H+1), K);
         result.test_eq("vector matches", gen.nonce_for(H), K);

         return result;
         }
   };

BOTAN_REGISTER_TEST("rfc6979", RFC6979_KAT_Tests);

#endif

}

}