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

« back to all changes in this revision

Viewing changes to src/lib/pubkey/xmss/xmss_hash.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
 * XMSS Hash
 
3
 * A collection of pseudorandom hash functions required for XMSS and WOTS
 
4
 * computations.
 
5
 * (C) 2016,2017 Matthias Gierlings
 
6
 *
 
7
 * Botan is released under the Simplified BSD License (see license.txt)
 
8
 **/
 
9
 
 
10
#include <botan/xmss_hash.h>
 
11
#include <botan/exceptn.h>
 
12
 
 
13
namespace Botan {
 
14
 
 
15
XMSS_Hash::XMSS_Hash(const XMSS_Hash& hash)
 
16
   : XMSS_Hash(hash.m_hash_func_name)
 
17
   {
 
18
   }
 
19
 
 
20
XMSS_Hash::XMSS_Hash(const std::string& h_func_name) :
 
21
   m_hash(HashFunction::create(h_func_name)),
 
22
   m_hash_func_name(h_func_name)
 
23
   {
 
24
   if(!m_hash)
 
25
      throw Lookup_Error("XMSS cannot use hash " + h_func_name +
 
26
                         " because it is unavailable");
 
27
 
 
28
   m_output_length = m_hash->output_length();
 
29
   BOTAN_ASSERT(m_output_length > 0, "Hash output length of zero is invalid.");
 
30
 
 
31
   m_zero_padding.resize(m_output_length - 1);
 
32
   m_msg_hash.reset(m_hash->clone());
 
33
   }
 
34
 
 
35
void
 
36
XMSS_Hash::h(secure_vector<uint8_t>& result,
 
37
             const secure_vector<uint8_t>& key,
 
38
             const secure_vector<uint8_t>& data)
 
39
   {
 
40
   m_hash->update(m_zero_padding);
 
41
   m_hash->update(m_id_h);
 
42
   m_hash->update(key);
 
43
   m_hash->update(data);
 
44
   m_hash->final(result);
 
45
   }
 
46
 
 
47
void XMSS_Hash::h_msg_init(const secure_vector<uint8_t>& randomness,
 
48
                           const secure_vector<uint8_t>& root,
 
49
                           const secure_vector<uint8_t>& index_bytes)
 
50
   {
 
51
   m_msg_hash->clear();
 
52
   m_msg_hash->update(m_zero_padding);
 
53
   m_msg_hash->update(m_id_hmsg);
 
54
   m_msg_hash->update(randomness);
 
55
   m_msg_hash->update(root);
 
56
   m_msg_hash->update(index_bytes);
 
57
   }
 
58
 
 
59
void XMSS_Hash::h_msg_update(const secure_vector<uint8_t>& data)
 
60
   {
 
61
   m_msg_hash->update(data);
 
62
   }
 
63
 
 
64
void XMSS_Hash::h_msg_update(const uint8_t data[], size_t size)
 
65
   {
 
66
   m_msg_hash->update(data, size);
 
67
   }
 
68
 
 
69
secure_vector<uint8_t> XMSS_Hash::h_msg_final()
 
70
   {
 
71
   return m_msg_hash->final();
 
72
   }
 
73
 
 
74
secure_vector<uint8_t>
 
75
XMSS_Hash::h_msg(const secure_vector<uint8_t>& randomness,
 
76
                 const secure_vector<uint8_t>& root,
 
77
                 const secure_vector<uint8_t>& index_bytes,
 
78
                 const secure_vector<uint8_t>& data)
 
79
   {
 
80
   h_msg_init(randomness, root, index_bytes);
 
81
   m_msg_hash->update(data);
 
82
   return m_msg_hash->final();
 
83
   }
 
84
 
 
85
}