digestpp
0.01
Experimental C++11 header-only message digest library.
algorithm
mixin
cshake_mixin.hpp
1
/*
2
This code is written by kerukuro and released into public domain.
3
*/
4
5
#
ifndef
DIGESTPP_MIXIN_SHAKE_HPP
6
#
define
DIGESTPP_MIXIN_SHAKE_HPP
7
8
namespace
digestpp
9
{
10
11
namespace
mixin
12
{
13
14
/**
15
* \brief Defines additional public functions for cSHAKE128 and cSHAKE256.
16
* \sa hasher, cshake128, cshake256
17
*/
18
template
<
typename
T>
19
class
cshake_mixin
20
{
21
public
:
22
/**
23
* \brief Set NIST function name from std::string
24
*
25
* \param[in] function_name NIST function name string
26
* \return Reference to hasher
27
*/
28
inline
hasher
<
T
,
mixin
::
cshake_mixin
>&
set_function_name
(
const
std
::
string
&
function_name
)
29
{
30
auto
&
shake
=
static_cast
<
hasher
<
T
,
mixin
::
cshake_mixin
>&>(*
this
);
31
shake
.
provider
.
set_function_name
(
function_name
);
32
shake
.
provider
.
init
();
33
return
shake
;
34
}
35
36
/**
37
* \brief Set NIST function name from raw buffer
38
*
39
* \param[in] function_name Pointer to NIST function name bytes
40
* \param[in] function_name_len NIST function name 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
::
cshake_mixin
>&
set_function_name
(
const
C
*
function_name
,
size_t
function_name_len
)
45
{
46
return
set_function_name
(
std
::
string
(
reinterpret_cast
<
const
char
*>(
function_name
),
function_name_len
));
47
}
48
49
/**
50
* \brief Set customization from std::string
51
*
52
* \param[in] customization Customization string
53
* \return Reference to hasher
54
*/
55
inline
hasher
<
T
,
mixin
::
cshake_mixin
>&
set_customization
(
const
std
::
string
&
customization
)
56
{
57
auto
&
shake
=
static_cast
<
hasher
<
T
,
mixin
::
cshake_mixin
>&>(*
this
);
58
shake
.
provider
.
set_customization
(
customization
);
59
shake
.
provider
.
init
();
60
return
shake
;
61
}
62
63
/**
64
* \brief Set customization from raw buffer
65
*
66
* \param[in] customization Pointer to customization bytes
67
* \param[in] customization_len Customization 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
::
cshake_mixin
>&
set_customization
(
const
C
*
customization
,
size_t
customization_len
)
72
{
73
return
set_customization
(
std
::
string
(
reinterpret_cast
<
const
char
*>(
customization
),
customization_len
));
74
}
75
};
76
77
}
// namespace mixin
78
79
}
// namespace digestpp
80
81
#
endif
// DIGESTPP_MIXIN_SHAKE_HPP
digestpp::shake256
hasher< detail::shake_provider< 256, 24 > > shake256
SHAKE256 function.
Definition:
shake.hpp:53
digestpp::mixin::cshake_mixin::set_customization
hasher< T, mixin::cshake_mixin > & set_customization(const C *customization, size_t customization_len)
Set customization from raw buffer.
Definition:
cshake_mixin.hpp:71
Generated by
1.8.13