digestpp  0.01
Experimental C++11 header-only message digest library.
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>
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  */
29  {
30  auto& shake = static_cast<hasher<T, mixin::cshake_mixin>&>(*this);
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>
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  */
56  {
57  auto& shake = static_cast<hasher<T, mixin::cshake_mixin>&>(*this);
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>
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
hasher< detail::shake_provider< 256, 24 > > shake256
SHAKE256 function.
Definition: shake.hpp:53
hasher< T, mixin::cshake_mixin > & set_customization(const C *customization, size_t customization_len)
Set customization from raw buffer.
Definition: cshake_mixin.hpp:71