Botan  2.1.0
Crypto and TLS for C++11
xmss_wots_verification_operation.cpp
Go to the documentation of this file.
1 /**
2  * XMSS WOTS Verification Operation
3  * Provides signature verification capabilities for Winternitz One Time
4  * Signatures used in Extended Hash-Based Signatures (XMSS).
5  *
6  * This operation is not intended for stand-alone use and thus not registered
7  * in the Botan algorithm registry.
8  *
9  * (C) 2016 Matthias Gierlings
10  *
11  * Botan is released under the Simplified BSD License (see license.txt)
12  **/
13 
14 #include <botan/internal/xmss_wots_verification_operation.h>
15 
16 namespace Botan {
17 
19  const XMSS_WOTS_Addressed_PublicKey& public_key)
20  : XMSS_WOTS_Common_Ops(public_key.public_key().wots_parameters().oid()),
21  m_pub_key(public_key),
22  m_msg_buf(0)
23  {
24  m_msg_buf.reserve(m_pub_key.public_key().wots_parameters().
25  element_size());
26  }
27 
28 void
29 XMSS_WOTS_Verification_Operation::update(const uint8_t msg[], size_t msg_len)
30  {
31  BOTAN_ASSERT(msg_len == m_pub_key.public_key().wots_parameters().
32  element_size() &&
33  m_msg_buf.size() == 0,
34  "XMSS WOTS only supports one message part of size n.");
35 
36  for(size_t i = 0; i < msg_len; i++)
37  {
38  m_msg_buf.push_back(msg[i]);
39  }
40  }
41 
43  size_t sig_len)
44  {
45  const XMSS_WOTS_Parameters& w = m_pub_key.public_key().wots_parameters();
46 
47  BOTAN_ASSERT(sig_len == w.element_size() * w.len(),
48  "Invalid signature size.");
49 
50  wots_keysig_t signature(0);
51  signature.reserve(sig_len);
52 
53  size_t begin = 0;
54  size_t end = 0;
55  while(signature.size() < w.len())
56  {
57  begin = end;
58  end = begin + w.element_size();
59  signature.push_back(secure_vector<uint8_t>(sig + begin, sig + end));
60  }
61 
62  XMSS_WOTS_PublicKey pubkey_msg(w.oid(),
63  m_msg_buf,
64  signature,
65  m_pub_key.address(),
66  m_pub_key.public_key().public_seed());
67 
68  return pubkey_msg.key_data() == m_pub_key.public_key().key_data();
69  }
70 
71 }
72 
const XMSS_WOTS_PublicKey & public_key() const
XMSS_WOTS_Verification_Operation(const XMSS_WOTS_Addressed_PublicKey &public_key)
virtual bool is_valid_signature(const uint8_t sig[], size_t sig_len) override
const secure_vector< uint8_t > & public_seed() const
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Definition: alg_id.cpp:13
std::vector< secure_vector< uint8_t > > wots_keysig_t
const XMSS_WOTS_Parameters & wots_parameters() const
ots_algorithm_t oid() const
const wots_keysig_t & key_data() const
void update(const uint8_t msg[], size_t msg_len) override