digestpp  0.01
Experimental C++11 header-only message digest library.
kmac_mixin.hpp
1 /*
2 This code is written by kerukuro and released into public domain.
3 */
4 
5 #ifndef DIGESTPP_MIXINS_KMAC_HPP
6 #define DIGESTPP_MIXINS_KMAC_HPP
7 
8 namespace digestpp
9 {
10 
11 namespace mixin
12 {
13 
14 /**
15  * \brief Defines additional public functions for KMAC family of algorithms.
16  * \sa hasher, kmac128, kmac256, kmac128_xof, kmac256_xof
17  */
18 template<typename T>
20 {
21 public:
22  /**
23  * \brief Set key from std::string
24  *
25  * \param[in] key Key string
26  * \return Reference to hasher
27  */
28  inline hasher<T, mixin::kmac_mixin>& set_key(const std::string& key)
29  {
30  auto& kmac = static_cast<hasher<T, mixin::kmac_mixin>&>(*this);
32  kmac.provider.init();
33  return kmac;
34  }
35 
36  /**
37  * \brief Set key from raw buffer
38  *
39  * \param[in] key Pointer to key bytes
40  * \param[in] key_len Key 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_key(std::string(reinterpret_cast<const char*>(key), key_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& kmac = static_cast<hasher<T, mixin::kmac_mixin>&>(*this);
59  kmac.provider.init();
60  return kmac;
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_MIXINS_KMAC_HPP
hasher< detail::shake_provider< 256, 24 > > shake256
SHAKE256 function.
Definition: shake.hpp:53
hasher< T, mixin::kmac_mixin > & set_customization(const C *customization, size_t customization_len)
Set customization from raw buffer.
Definition: kmac_mixin.hpp:71