~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/tests/test_rfc6979.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* (C) 2014,2015 Jack Lloyd
 
3
*
 
4
* Botan is released under the Simplified BSD License (see license.txt)
 
5
*/
 
6
 
 
7
#include "tests.h"
 
8
 
 
9
#if defined(BOTAN_HAS_RFC6979_GENERATOR)
 
10
   #include <botan/rfc6979.h>
 
11
#endif
 
12
 
 
13
#include <botan/hash.h>
 
14
 
 
15
namespace Botan_Tests {
 
16
 
 
17
namespace {
 
18
 
 
19
#if defined(BOTAN_HAS_RFC6979_GENERATOR)
 
20
 
 
21
class RFC6979_KAT_Tests final : public Text_Based_Test
 
22
   {
 
23
   public:
 
24
      RFC6979_KAT_Tests() : Text_Based_Test("rfc6979.vec", "Q,X,H,K") {}
 
25
 
 
26
      Test::Result run_one_test(const std::string& hash, const VarMap& vars) override
 
27
         {
 
28
         const BigInt Q = get_req_bn(vars, "Q");
 
29
         const BigInt X = get_req_bn(vars, "X");
 
30
         const BigInt H = get_req_bn(vars, "H");
 
31
         const BigInt K = get_req_bn(vars, "K");
 
32
 
 
33
         Test::Result result("RFC 6979 nonce generation");
 
34
 
 
35
         auto hash_func = Botan::HashFunction::create(hash);
 
36
 
 
37
         if(!hash_func)
 
38
            {
 
39
            result.test_note("Skipping due to missing: " + hash);
 
40
            return result;
 
41
            }
 
42
 
 
43
         result.test_eq("vector matches", Botan::generate_rfc6979_nonce(X, Q, H, hash), K);
 
44
 
 
45
         Botan::RFC6979_Nonce_Generator gen(hash, Q, X);
 
46
 
 
47
         result.test_eq("vector matches", gen.nonce_for(H), K);
 
48
         result.test_ne("different output for H+1", gen.nonce_for(H + 1), K);
 
49
         result.test_eq("vector matches when run again", gen.nonce_for(H), K);
 
50
 
 
51
         return result;
 
52
         }
 
53
   };
 
54
 
 
55
BOTAN_REGISTER_TEST("rfc6979", RFC6979_KAT_Tests);
 
56
 
 
57
#endif
 
58
 
 
59
}
 
60
 
 
61
}