digestpp  0.01
Experimental C++11 header-only message digest library.
kmac.hpp
1 /*
2 This code is written by kerukuro and released into public domain.
3 */
4 
5 #ifndef DIGESTPP_ALGORITHM_KMAC_HPP
6 #define DIGESTPP_ALGORITHM_KMAC_HPP
7 
8 #include "../hasher.hpp"
9 #include "detail/kmac_provider.hpp"
10 #include "mixin/kmac_mixin.hpp"
11 
12 namespace digestpp
13 {
14 
15 /**
16  * @brief KMAC128 in hash mode
17  *
18  * Use this variant when the required hash size is known in advance. Otherwise, use \ref kmac128_xof.
19  * While primary usage of KMAC is message authentication, it can also be used without a key as a regular hash function.
20  *
21  * @hash
22  *
23  * @outputsize arbitrary
24  *
25  * @defaultsize none
26  *
27  * @throw std::runtime_error if the requested digest size is not divisible by 8 (full bytes)
28  *
29  * @mixinparams customization, key
30  *
31  * @mixin{mixin::kmac_mixin}
32  *
33  * @par Example:\n
34  * @code // Set key and output a 256-bit KMAC128 of a string
35  * digestpp::kmac128 hasher(256);
36  * hasher.set_key(R"(@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_)");
37  * hasher.absorb("The quick brown fox jumps over the lazy dog");
38  * std::cout << hasher.hexdigest() << '\n';
39  * @endcode
40  *
41  * @par Example output:\n
42  * @code bbd4ebf20aacc8e4dfd2cc91f2b6cbf33e2a45d805996b48a17b8d3e42b4b010
43  * @endcode
44  *
45  * @sa hasher, kmac128_xof, mixin::kmac_mixin
46  */
48 
49 /**
50  * @brief KMAC256 in hash mode
51  *
52  * Use this variant when the required hash size is known in advance. Otherwise, use \ref kmac256_xof.
53  * While primary usage of KMAC is message authentication, it can also be used without a key as a regular hash function.
54  *
55  * @hash
56  *
57  * @outputsize arbitrary
58  *
59  * @defaultsize none
60  *
61  * @throw std::runtime_error if the requested digest size is not divisible by 8 (full bytes)
62  *
63  * @mixinparams customization, key
64  *
65  * @mixin{mixin::kmac_mixin}
66  *
67  * @par Example:\n
68  * @code // Set key and output a 256-bit KMAC256 of a string
69  * digestpp::kmac256 hasher(256);
70  * hasher.set_key(R("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_"));
71  * hasher.absorb("The quick brown fox jumps over the lazy dog");
72  * std::cout << hasher.hexdigest() << '\n';
73  * @endcode
74  *
75  * @par Example output:\n
76  * @code bbe7d65fe0e7574254a13e0f3f79482275b96887287fc8b620a92ed5e5de3bce
77  * @endcode
78  *
79  * @sa hasher, kmac256_xof, mixin::kmac_mixin
80  */
82 
83 /**
84  * @brief KMAC128 in XOF mode (KMACXOF128)
85  *
86  * Use this variant when the required hash size is not known in advance. Otherwise, use \ref kmac128.
87  * This hasher can also be used without a key, but there are no advantages over \ref cshake128 in this case.
88  *
89  * @xof
90  *
91  * @mixinparams customization, key
92  *
93  * @mixin{mixin::kmac_mixin}
94  *
95  * @par Example:\n
96  * @code // Set key, absorb a string and squeeze 32 bytes of output
97  * digestpp::kmac128_xof hasher;
98  * hasher.set_key(R"(@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_)");
99  * hasher.absorb("The quick brown fox jumps over the lazy dog");
100  * std::cout << hasher.hexsqueeze(32) << '\n';
101  * @endcode
102  *
103  * @par Example output:\n
104  * @code a5dd2e2c92e4fe5d203ab7cc4e05df888b021390ba08a00dcb39a94ed07bd364
105  * @endcode
106  *
107  * @sa hasher, kmac128, mixin::kmac_mixin
108  */
110 
111 /**
112  * @brief KMAC256 in XOF mode (KMACXOF256)
113  *
114  * Use this variant when the required hash size is not known in advance. Otherwise, use \ref kmac256.
115  * This hasher can also be used without a key, but there are no advantages over \ref cshake256 in this case.
116  *
117  * @xof
118  *
119  * @mixinparams customization, key
120  *
121  * @mixin{mixin::kmac_mixin}
122  *
123  * @par Example:\n
124  * @code // Set key, absorb a string and squeeze 32 bytes of output
125  * digestpp::kmac256_xof hasher;
126  * hasher.set_key(R"(@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_)");
127  * hasher.absorb("The quick brown fox jumps over the lazy dog");
128  * std::cout << hasher.hexsqueeze(32) << '\n';
129  * @endcode
130  *
131  * @par Example output:\n
132  * @code 81ce507692e27fb404e4a765c3be3450ce5c090a61b8311f93eb4e35604877ad
133  * @endcode
134  *
135  * @sa hasher, kmac256, mixin::kmac_mixin
136  */
138 
139 } // namespace digestpp
140 
141 #endif // DIGESTPP_ALGORITHM_KMAC_HPP
hasher< detail::kmac_provider< 256, false >, mixin::kmac_mixin > kmac256
KMAC256 in hash mode.
Definition: kmac.hpp:81
hasher< detail::kmac_provider< 256, true >, mixin::kmac_mixin > kmac256_xof
KMAC256 in XOF mode (KMACXOF256)
Definition: kmac.hpp:137
hasher< detail::shake_provider< 256, 24 > > shake256
SHAKE256 function.
Definition: shake.hpp:53
hasher< detail::kmac_provider< 128, false >, mixin::kmac_mixin > kmac128
KMAC128 in hash mode.
Definition: kmac.hpp:47
hasher< detail::kmac_provider< 128, true >, mixin::kmac_mixin > kmac128_xof
KMAC128 in XOF mode (KMACXOF128)
Definition: kmac.hpp:109