Coverage Report

Created: 2020-06-30 13:58

/src/botan/src/lib/pubkey/xmss/xmss_wots_privatekey.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * XMSS WOTS Private Key
3
 * A Winternitz One Time Signature private key for use with Extended Hash-Based
4
 * Signatures.
5
 *
6
 * (C) 2016,2017 Matthias Gierlings
7
 *
8
 * Botan is released under the Simplified BSD License (see license.txt)
9
 **/
10
11
#include <botan/xmss_wots_privatekey.h>
12
13
namespace Botan {
14
15
wots_keysig_t
16
XMSS_WOTS_PrivateKey::generate(const secure_vector<uint8_t>& priv_seed,
17
                               XMSS_Hash& hash)
18
0
   {
19
0
   wots_keysig_t priv_key(m_wots_params.len(),
20
0
                          secure_vector<uint8_t>(0));
21
0
22
0
   for(size_t i = 0; i < m_wots_params.len(); i++)
23
0
      {
24
0
      XMSS_Tools::concat<size_t>(priv_key[i], i, 32);
25
0
      hash.prf(priv_key[i], priv_seed, priv_key[i]);
26
0
      }
27
0
   return priv_key;
28
0
   }
29
30
31
XMSS_WOTS_PublicKey
32
XMSS_WOTS_PrivateKey::generate_public_key(XMSS_Address& adrs)
33
0
   {
34
0
   XMSS_WOTS_PublicKey pub_key(m_wots_params.oid(),
35
0
                               public_seed());
36
0
   generate_public_key(pub_key, wots_keysig_t((*this)[adrs]), adrs);
37
0
   return pub_key;
38
0
   }
39
40
void
41
XMSS_WOTS_PrivateKey::generate_public_key(XMSS_WOTS_PublicKey& pub_key,
42
                                          wots_keysig_t&& in_key_data,
43
                                          XMSS_Address& adrs,
44
                                          XMSS_Hash& hash)
45
0
   {
46
0
   BOTAN_ASSERT(wots_parameters() == pub_key.wots_parameters() &&
47
0
                public_seed() == pub_key.public_seed(),
48
0
                "Conflicting public key data.");
49
0
50
0
   pub_key.set_key_data(std::move(in_key_data));
51
0
   for(size_t i = 0; i < m_wots_params.len(); i++)
52
0
      {
53
0
      adrs.set_chain_address(static_cast<uint32_t>(i));
54
0
      chain(pub_key[i], 0, m_wots_params.wots_parameter() - 1, adrs,
55
0
            public_seed(), hash);
56
0
      }
57
0
   }
58
59
wots_keysig_t
60
XMSS_WOTS_PrivateKey::sign(const secure_vector<uint8_t>& msg,
61
                           XMSS_Address& adrs,
62
                           XMSS_Hash& hash)
63
64
0
   {
65
0
   secure_vector<uint8_t> msg_digest
66
0
      {
67
0
      m_wots_params.base_w(msg, m_wots_params.len_1())
68
0
      };
69
0
70
0
   m_wots_params.append_checksum(msg_digest);
71
0
   wots_keysig_t sig(this->at(adrs, hash));
72
0
73
0
   for(size_t i = 0; i < m_wots_params.len(); i++)
74
0
      {
75
0
      adrs.set_chain_address(static_cast<uint32_t>(i));
76
0
      chain(sig[i], 0 , msg_digest[i], adrs, m_public_seed, hash);
77
0
      }
78
0
79
0
   return sig;
80
0
   }
81
82
}