digestpp
0.01
Experimental C++11 header-only message digest library.
algorithm
mixin
skein_mixin.hpp
1
/*
2
This code is written by kerukuro and released into public domain.
3
*/
4
5
#
ifndef
DIGESTPP_MIXINS_SKEIN_HPP
6
#
define
DIGESTPP_MIXINS_SKEIN_HPP
7
8
namespace
digestpp
9
{
10
11
namespace
mixin
12
{
13
14
/**
15
* \brief Defines additional public functions for Skein family of algorithms.
16
* \sa hasher, skein256, skein512, skein1024, skein256_xof, skein512_xof, skein1024_xof
17
*/
18
template
<
typename
T>
19
class
skein_mixin
20
{
21
public
:
22
/**
23
* \brief Set personalization from std::string
24
*
25
* \param[in] personalization Personalization string
26
* \return Reference to hasher
27
*/
28
inline
hasher
<
T
,
mixin
::
skein_mixin
>&
set_personalization
(
const
std
::
string
&
personalization
)
29
{
30
auto
&
skein
=
static_cast
<
hasher
<
T
,
mixin
::
skein_mixin
>&>(*
this
);
31
skein
.
provider
.
set_personalization
(
personalization
);
32
skein
.
provider
.
init
();
33
return
skein
;
34
}
35
36
/**
37
* \brief Set personalization from raw buffer
38
*
39
* \param[in] personalization Pointer to personalization bytes
40
* \param[in] personalization_len Personalization length (in bytes)
41
* \return Reference to hasher
42
*/
43
template
<
typename
C
,
typename
std
::
enable_if
<
detail
::
is_byte
<
C
>::
value
>::
type
* =
nullptr
>
44
inline
hasher
<
T
,
mixin
::
skein_mixin
>&
set_personalization
(
const
C
*
personalization
,
size_t
personalization_len
)
45
{
46
return
set_personalization
(
std
::
string
(
reinterpret_cast
<
const
char
*>(
personalization
),
personalization_len
));
47
}
48
49
/**
50
* \brief Set key from std::string
51
*
52
* \param[in] key Key string
53
* \return Reference to hasher
54
*/
55
inline
hasher
<
T
,
mixin
::
skein_mixin
>&
set_key
(
const
std
::
string
&
key
)
56
{
57
auto
&
skein
=
static_cast
<
hasher
<
T
,
mixin
::
skein_mixin
>&>(*
this
);
58
skein
.
provider
.
set_key
(
key
);
59
skein
.
provider
.
init
();
60
return
skein
;
61
}
62
63
/**
64
* \brief Set key from raw buffer
65
*
66
* \param[in] key Pointer to key bytes
67
* \param[in] key_len Key length (in bytes)
68
* \return Reference to hasher
69
*/
70
template
<
typename
C
,
typename
std
::
enable_if
<
detail
::
is_byte
<
C
>::
value
>::
type
* =
nullptr
>
71
inline
hasher
<
T
,
mixin
::
skein_mixin
>&
set_key
(
const
C
*
key
,
size_t
key_len
)
72
{
73
return
set_key
(
std
::
string
(
reinterpret_cast
<
const
char
*>(
key
),
key_len
));
74
}
75
76
/**
77
* \brief Set nonce from std::string
78
*
79
* \param[in] nonce Nonce string
80
* \return Reference to hasher
81
*/
82
inline
hasher
<
T
,
mixin
::
skein_mixin
>&
set_nonce
(
const
std
::
string
&
nonce
)
83
{
84
auto
&
skein
=
static_cast
<
hasher
<
T
,
mixin
::
skein_mixin
>&>(*
this
);
85
skein
.
provider
.
set_nonce
(
nonce
);
86
skein
.
provider
.
init
();
87
return
skein
;
88
}
89
90
/**
91
* \brief Set nonce from raw buffer
92
*
93
* \param[in] nonce Pointer to nonce bytes
94
* \param[in] nonce_len Nonce length (in bytes)
95
* \return Reference to hasher
96
*/
97
template
<
typename
C
,
typename
std
::
enable_if
<
detail
::
is_byte
<
C
>::
value
>::
type
* =
nullptr
>
98
inline
hasher
<
T
,
mixin
::
skein_mixin
>&
set_nonce
(
const
C
*
nonce
,
size_t
nonce_len
)
99
{
100
return
set_nonce
(
std
::
string
(
reinterpret_cast
<
const
char
*>(
nonce
),
nonce_len
));
101
}
102
};
103
104
}
// namespace mixin
105
106
}
// namespace digestpp
107
108
#
endif
digestpp::shake256
hasher< detail::shake_provider< 256, 24 > > shake256
SHAKE256 function.
Definition:
shake.hpp:53
digestpp::mixin::skein_mixin::set_nonce
hasher< T, mixin::skein_mixin > & set_nonce(const C *nonce, size_t nonce_len)
Set nonce from raw buffer.
Definition:
skein_mixin.hpp:98
Generated by
1.8.13