Botan
3.6.1
Crypto and TLS for C&
src
lib
pubkey
xmss
xmss_tools.h
Go to the documentation of this file.
1
/*
2
* XMSS Tools
3
* (C) 2016,2017 Matthias Gierlings
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
**/
7
8
#ifndef BOTAN_XMSS_TOOLS_H_
9
#define BOTAN_XMSS_TOOLS_H_
10
11
#include <botan/secmem.h>
12
#include <botan/internal/cpuid.h>
13
#include <iterator>
14
#include <type_traits>
15
16
namespace
Botan
{
17
18
/**
19
* Helper tools for low level byte operations required
20
* for the XMSS implementation.
21
**/
22
class
XMSS_Tools
final
{
23
public
:
24
XMSS_Tools
() =
delete
;
25
XMSS_Tools
(
const
XMSS_Tools
&) =
delete
;
26
void
operator=
(
const
XMSS_Tools
&) =
delete
;
27
28
/**
29
* Concatenates the byte representation in big-endian order of any
30
* integral value to a secure_vector.
31
*
32
* @param target Vector to concatenate the byte representation of the
33
* integral value to.
34
* @param src integral value to concatenate.
35
**/
36
template <typename T, typename U = typename std::enable_if<std::is_integral<T>::value,
void
>::type>
37
static
void
concat
(
secure_vector<uint8_t>
& target,
const
T
& src);
38
39
/**
40
* Concatenates the last n bytes of the byte representation in big-endian
41
* order of any integral value to a to a secure_vector.
42
*
43
* @param target Vector to concatenate the byte representation of the
44
* integral value to.
45
* @param src Integral value to concatenate.
46
* @param len number of bytes to concatenate. This value must be smaller
47
* or equal to the size of type T.
48
**/
49
template <typename T, typename U = typename std::enable_if<std::is_integral<T>::value,
void
>::type>
50
static
void
concat
(
secure_vector<uint8_t>
& target,
const
T
& src,
size_t
len);
51
};
52
53
template
<
typename
T,
typename
U>
54
void
XMSS_Tools::concat
(
secure_vector<uint8_t>
& target,
const
T
& src) {
55
const
uint8_t* src_bytes =
reinterpret_cast<
const
uint8_t*
>
(&src);
56
if
(
CPUID::is_little_endian
()) {
57
std::reverse_copy(src_bytes, src_bytes +
sizeof
(src), std::back_inserter(target));
58
}
else
{
59
std::copy(src_bytes, src_bytes +
sizeof
(src), std::back_inserter(target));
60
}
61
}
62
63
template
<
typename
T,
typename
U>
64
void
XMSS_Tools::concat
(
secure_vector<uint8_t>
& target,
const
T
& src,
size_t
len) {
65
size_t
c =
static_cast<
size_t
>
(std::min(len,
sizeof
(src)));
66
if
(len >
sizeof
(src)) {
67
target.resize(target.size() + len -
sizeof
(src), 0);
68
}
69
70
const
uint8_t* src_bytes =
reinterpret_cast<
const
uint8_t*
>
(&src);
71
if
(
CPUID::is_little_endian
()) {
72
std::reverse_copy(src_bytes, src_bytes + c, std::back_inserter(target));
73
}
else
{
74
std::copy(src_bytes +
sizeof
(src) - c, src_bytes +
sizeof
(src), std::back_inserter(target));
75
}
76
}
77
}
// namespace Botan
78
79
#endif
Botan::CPUID::is_little_endian
static bool is_little_endian()
Definition
cpuid.h:60
Botan::XMSS_Tools
Definition
xmss_tools.h:22
Botan::XMSS_Tools::XMSS_Tools
XMSS_Tools()=delete
Botan::XMSS_Tools::operator=
void operator=(const XMSS_Tools &)=delete
Botan::XMSS_Tools::XMSS_Tools
XMSS_Tools(const XMSS_Tools &)=delete
Botan::XMSS_Tools::concat
static void concat(secure_vector< uint8_t > &target, const T &src)
Definition
xmss_tools.h:54
final
int(* final)(unsigned char *, CTX *)
Definition
commoncrypto_hash.cpp:29
T
FE_25519 T
Definition
ge.cpp:34
Botan
Definition
alg_id.cpp:13
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition
secmem.h:61
Generated by
1.12.0