Botan
3.8.1
Crypto and TLS for C&
Toggle main menu visibility
Main Page
Related Pages
Topics
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Variables
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
Enumerations
a
c
d
e
f
g
h
k
l
m
n
o
p
r
s
t
u
v
w
Enumerator
c
d
f
i
m
n
r
s
t
Concepts
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
f
h
i
m
n
o
p
r
s
t
u
v
w
Enumerations
b
c
d
e
k
m
n
o
p
s
t
x
Enumerator
_
a
b
c
d
e
f
g
h
k
l
m
n
p
q
r
s
t
u
v
w
x
Related Symbols
b
c
d
e
f
k
o
p
s
t
x
Files
File List
File Members
All
_
a
b
c
d
e
f
k
m
n
p
t
w
Functions
b
c
Typedefs
b
c
e
p
t
Enumerations
Enumerator
b
c
d
e
k
n
Macros
_
a
b
c
f
m
n
t
w
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 <algorithm>
13
#include <bit>
14
#include <iterator>
15
#include <type_traits>
16
17
namespace
Botan
{
18
19
/**
20
* Helper tools for low level byte operations required
21
* for the XMSS implementation.
22
**/
23
class
XMSS_Tools
final {
24
public
:
25
XMSS_Tools
() =
delete
;
26
XMSS_Tools
(
const
XMSS_Tools
&) =
delete
;
27
void
operator=
(
const
XMSS_Tools
&) =
delete
;
28
29
/**
30
* Concatenates the byte representation in big-endian order of any
31
* integral value to a secure_vector.
32
*
33
* @param target Vector to concatenate the byte representation of the
34
* integral value to.
35
* @param src integral value to concatenate.
36
**/
37
template <typename T, typename U = typename std::enable_if<std::is_integral<T>::value,
void
>::type>
38
static
void
concat
(
secure_vector<uint8_t>
& target,
const
T& src);
39
40
/**
41
* Concatenates the last n bytes of the byte representation in big-endian
42
* order of any integral value to a to a secure_vector.
43
*
44
* @param target Vector to concatenate the byte representation of the
45
* integral value to.
46
* @param src Integral value to concatenate.
47
* @param len number of bytes to concatenate. This value must be smaller
48
* or equal to the size of type T.
49
**/
50
template <typename T, typename U = typename std::enable_if<std::is_integral<T>::value,
void
>::type>
51
static
void
concat
(
secure_vector<uint8_t>
& target,
const
T& src,
size_t
len);
52
};
23
class
XMSS_Tools
final {
…
};
53
54
template
<
typename
T,
typename
U>
55
void
XMSS_Tools::concat
(
secure_vector<uint8_t>
& target,
const
T& src) {
56
const
uint8_t* src_bytes =
reinterpret_cast<
const
uint8_t*
>
(&src);
57
if
constexpr
(std::endian::native == std::endian::little) {
58
std::reverse_copy(src_bytes, src_bytes +
sizeof
(src), std::back_inserter(target));
59
}
else
{
60
std::copy(src_bytes, src_bytes +
sizeof
(src), std::back_inserter(target));
61
}
62
}
55
void
XMSS_Tools::concat
(
secure_vector<uint8_t>
& target,
const
T& src) {
…
}
63
64
template
<
typename
T,
typename
U>
65
void
XMSS_Tools::concat
(
secure_vector<uint8_t>
& target,
const
T& src,
size_t
len) {
66
size_t
c =
static_cast<
size_t
>
(std::min(len,
sizeof
(src)));
67
if
(len >
sizeof
(src)) {
68
target.resize(target.size() + len -
sizeof
(src), 0);
69
}
70
71
const
uint8_t* src_bytes =
reinterpret_cast<
const
uint8_t*
>
(&src);
72
if
constexpr
(std::endian::native == std::endian::little) {
73
std::reverse_copy(src_bytes, src_bytes + c, std::back_inserter(target));
74
}
else
{
75
std::copy(src_bytes +
sizeof
(src) - c, src_bytes +
sizeof
(src), std::back_inserter(target));
76
}
77
}
65
void
XMSS_Tools::concat
(
secure_vector<uint8_t>
& target,
const
T& src,
size_t
len) {
…
}
78
}
// namespace Botan
79
80
#endif
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:55
Botan
Definition
alg_id.cpp:13
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition
secmem.h:65
Generated by
1.13.2