digestpp
0.01
Experimental C++11 header-only message digest library.
algorithm
mixin
blake_mixin.hpp
1
/*
2
This code is written by kerukuro and released into public domain.
3
*/
4
5
#
ifndef
DIGESTPP_MIXINS_BLAKE_HPP
6
#
define
DIGESTPP_MIXINS_BLAKE_HPP
7
8
namespace
digestpp
9
{
10
11
namespace
mixin
12
{
13
14
/**
15
* \brief Defines additional public functions for BLAKE algorithm.
16
* \sa hasher, blake
17
*/
18
template
<
typename
T>
19
class
blake_mixin
20
{
21
public
:
22
23
/**
24
* \brief Set salt from std::string
25
*
26
* Supported salt size is 16 bytes for BLAKE-224, BLAKE-256 and 32 bytes for BLAKE-384, BLAKE-512.
27
*
28
* \param[in] salt String with salt
29
* \throw std::runtime_error if salt size is not supported.
30
* \return Reference to hasher
31
*/
32
inline
hasher
<
T
,
mixin
::
blake_mixin
>&
set_salt
(
const
std
::
string
&
salt
)
33
{
34
return
set_salt
(
salt
.
c_str
(),
salt
.
size
());
35
}
36
37
/**
38
* \brief Set salt from raw buffer
39
*
40
* Supported salt size is 16 bytes for BLAKE-224, BLAKE-256 and 32 bytes for BLAKE-384, BLAKE-512.
41
*
42
* \param[in] salt Pointer to salt bytes
43
* \param[in] salt_len Salt length (in bytes)
44
* \throw std::runtime_error if salt size is not supported.
45
* \return Reference to hasher
46
*/
47
template
<
typename
C
,
typename
std
::
enable_if
<
detail
::
is_byte
<
C
>::
value
>::
type
* =
nullptr
>
48
inline
hasher
<
T
,
mixin
::
blake_mixin
>&
set_salt
(
const
C
*
salt
,
size_t
salt_len
)
49
{
50
auto
&
blake
=
static_cast
<
hasher
<
T
,
mixin
::
blake_mixin
>&>(*
this
);
51
blake
.
provider
.
set_salt
(
reinterpret_cast
<
const
unsigned
char
*>(
salt
),
salt_len
);
52
blake
.
provider
.
init
();
53
return
blake
;
54
}
55
};
56
57
}
// namespace mixin
58
59
}
// namespace digestpp
60
61
#
endif
digestpp::mixin::blake_mixin::set_salt
hasher< T, mixin::blake_mixin > & set_salt(const C *salt, size_t salt_len)
Set salt from raw buffer.
Definition:
blake_mixin.hpp:48
digestpp::shake256
hasher< detail::shake_provider< 256, 24 > > shake256
SHAKE256 function.
Definition:
shake.hpp:53
Generated by
1.8.13