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

« back to all changes in this revision

Viewing changes to src/lib/pubkey/xmss/xmss_publickey.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 Public Key
 
3
 * An XMSS: Extended Hash-Based Siganture public key.
 
4
 * The XMSS public key does not support the X509 standard. Instead the
 
5
 * raw format described in [1] is used.
 
6
 *
 
7
 *   [1] XMSS: Extended Hash-Based Signatures,
 
8
 *       draft-itrf-cfrg-xmss-hash-based-signatures-06
 
9
 *       Release: July 2016.
 
10
 *       https://datatracker.ietf.org/doc/
 
11
 *       draft-irtf-cfrg-xmss-hash-based-signatures/?include_text=1
 
12
 *
 
13
 * (C) 2016,2017 Matthias Gierlings
 
14
 *
 
15
 * Botan is released under the Simplified BSD License (see license.txt)
 
16
 **/
 
17
 
 
18
#include <botan/internal/xmss_verification_operation.h>
 
19
#include <botan/xmss_publickey.h>
 
20
 
 
21
namespace Botan {
 
22
 
 
23
XMSS_PublicKey::XMSS_PublicKey(const std::vector<uint8_t>& raw_key)
 
24
   : m_xmss_params(XMSS_PublicKey::deserialize_xmss_oid(raw_key)),
 
25
     m_wots_params(m_xmss_params.ots_oid())
 
26
   {
 
27
   if(raw_key.size() < size())
 
28
      {
 
29
      throw Integrity_Failure("Invalid XMSS public key size detected.");
 
30
      }
 
31
 
 
32
   // extract & copy root from raw key.
 
33
   m_root.clear();
 
34
   m_root.reserve(m_xmss_params.element_size());
 
35
   auto begin = raw_key.begin() + sizeof(uint32_t);
 
36
   auto end = begin + m_xmss_params.element_size();
 
37
   std::copy(begin, end, std::back_inserter(m_root));
 
38
 
 
39
   // extract & copy public seed from raw key.
 
40
   begin = end;
 
41
   end = begin + m_xmss_params.element_size();
 
42
   m_public_seed.clear();
 
43
   m_public_seed.reserve(m_xmss_params.element_size());
 
44
   std::copy(begin, end, std::back_inserter(m_public_seed));
 
45
   }
 
46
 
 
47
XMSS_Parameters::xmss_algorithm_t
 
48
XMSS_PublicKey::deserialize_xmss_oid(const std::vector<uint8_t>& raw_key)
 
49
   {
 
50
   if(raw_key.size() < 4)
 
51
      {
 
52
      throw Integrity_Failure("XMSS signature OID missing.");
 
53
      }
 
54
 
 
55
   // extract and convert algorithm id to enum type
 
56
   uint32_t raw_id = 0;
 
57
   for(size_t i = 0; i < 4; i++)
 
58
      { raw_id = ((raw_id << 8) | raw_key[i]); }
 
59
 
 
60
   return static_cast<XMSS_Parameters::xmss_algorithm_t>(raw_id);
 
61
   }
 
62
 
 
63
std::unique_ptr<PK_Ops::Verification>
 
64
XMSS_PublicKey::create_verification_op(const std::string&,
 
65
                                       const std::string& provider) const
 
66
   {
 
67
   if(provider == "base" || provider.empty())
 
68
      {
 
69
      return std::unique_ptr<PK_Ops::Verification>(
 
70
                new XMSS_Verification_Operation(*this));
 
71
      }
 
72
   throw Provider_Not_Found(algo_name(), provider);
 
73
   }
 
74
 
 
75
std::vector<uint8_t> XMSS_PublicKey::raw_public_key() const
 
76
   {
 
77
   std::vector<uint8_t> result
 
78
      {
 
79
      static_cast<uint8_t>(m_xmss_params.oid() >> 24),
 
80
      static_cast<uint8_t>(m_xmss_params.oid() >> 16),
 
81
      static_cast<uint8_t>(m_xmss_params.oid() >>  8),
 
82
      static_cast<uint8_t>(m_xmss_params.oid())
 
83
      };
 
84
 
 
85
   std::copy(m_root.begin(), m_root.end(), std::back_inserter(result));
 
86
   std::copy(m_public_seed.begin(),
 
87
             m_public_seed.end(),
 
88
             std::back_inserter(result));
 
89
 
 
90
   return result;
 
91
   }
 
92
 
 
93
}