1 /*
2 This code is written by kerukuro and released into public domain.
3 */
4 
5 #ifndef DIGESTPP_ALGORITHM_BLAKE2_HPP
6 #define DIGESTPP_ALGORITHM_BLAKE2_HPP
7 
8 #include "../hasher.hpp"
9 #include "detail/blake2_provider.hpp"
10 #include "mixin/blake2_mixin.hpp"
11 
12 /// digestpp namespace
13 namespace digestpp
14 {
15 
16 /**
17  * @brief BLAKE2b hash function
18  *
19  * @hash
20  *
21  * @outputsize 8 - 512 bits
22  *
23  * @defaultsize 512 bits
24  *
25  * @throw std::runtime_error if the requested digest size is not divisible by 8 (full bytes),
26  * or is not within the supported range
27  *
28  * @mixinparams salt, personalization, key
29  *
30  * @mixin{mixin::blake2_mixin}
31  *
32  * @par Example:\n
33  * @code // Output a 256-bit BLAKE2b digest of a string
34  * digestpp::blake2b hasher(256);
35  * hasher.absorb("The quick brown fox jumps over the lazy dog");
36  * std::cout << hasher.hexdigest() << '\n';
37  * @endcode
38  *
39  * @par Example output:\n
40  * @code 01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9
41  * @endcode
42  *
43  * @sa hasher, mixin::blake2_mixin
44  */
45 typedef hasher<detail::blake2_provider<uint64_t, detail::blake2_type::hash>, mixin::blake2_mixin> blake2b;
46 
47 /**
48  * @brief BLAKE2s hash function
49  *
50  * @hash
51  *
52  * @outputsize 8 - 256 bits
53  *
54  * @defaultsize 256 bits
55  *
56  * @throw std::runtime_error if the requested digest size is not divisible by 8 (full bytes),
57  * or is not within the supported range
58  *
59  * @mixinparams salt, personalization, key
60  *
61  * @mixin{mixin::blake2_mixin}
62  *
63  * @par Example:\n
64  * @code // Output a 256-bit BLAKE2s digest of a string
65  * digestpp::blake2s hasher;
66  * hasher.absorb("The quick brown fox jumps over the lazy dog");
67  * std::cout << hasher.hexdigest() << '\n';
68  * @endcode
69  *
70  * @par Example output:\n
71  * @code 606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812
72  * @endcode
73  *
74  * @sa hasher, mixin::blake2_mixin
75  */
76 typedef hasher<detail::blake2_provider<uint32_t, detail::blake2_type::hash>, mixin::blake2_mixin> blake2s;
77 
78 /**
79  * @brief BLAKE2xb hash function
80  *
81  * Use this variant when the required hash size is known in advance. Otherwise, use \ref blake2xb_xof
82  *
83  * @hash
84  *
85  * @outputsize arbitrary
86  *
87  * @defaultsize 512 bits
88  *
89  * @throw std::runtime_error if the requested digest size is not divisible by 8 (full bytes)
90  *
91  * @mixinparams salt, personalization, key
92  *
93  * @mixin{mixin::blake2_mixin}
94  *
95  * @par Example:\n
96  * @code // Output a 256-bit BLAKE2xb digest of a string
97  * digestpp::blake2xb hasher(256);
98  * hasher.absorb("The quick brown fox jumps over the lazy dog");
99  * std::cout << hasher.hexdigest() << '\n';
100  * @endcode
101  *
102  * @par Example output:\n
103  * @code ca7a0c9c54b4b93c0bee0aa3a4d63e4f7fb87e3e0a9050522377fde76f0b6c01
104  * @endcode
105  *
106  * @sa hasher, mixin::blake2_mixin
107  */
108 typedef hasher<detail::blake2_provider<uint64_t, detail::blake2_type::x_hash>, mixin::blake2_mixin> blake2xb;
109 
110 /**
111  * @brief BLAKE2xs hash function
112  *
113  * Use this variant when the required hash size is known in advance. Otherwise, use \ref blake2xs_xof
114  *
115  * @hash
116  *
117  * @outputsize arbitrary
118  *
119  * @defaultsize 256 bits
120  *
121  * @throw std::runtime_error if the requested digest size is not divisible by 8 (full bytes)
122  *
123  * @mixinparams salt, personalization, key
124  *
125  * @mixin{mixin::blake2_mixin}
126  *
127  * @par Example:\n
128  * @code // Output a 512-bit BLAKE2xs digest of a string
129  * digestpp::blake2xs hasher(512);
130  * hasher.absorb("The quick brown fox jumps over the lazy dog");
131  * std::cout << hasher.hexdigest() << '\n';
132  * @endcode
133  *
134  * @par Example output:\n
135  * @code e709f8377d21507c166e5dd2279a1f58b290792d65dafcc5647b6e439a974227503c341341572725709b874e95f13a438677aa6f9648467fd341e0f3e5421840
136  * @endcode
137  *
138  * @sa hasher, mixin::blake2_mixin
139  */
140 typedef hasher<detail::blake2_provider<uint32_t, detail::blake2_type::x_hash>, mixin::blake2_mixin> blake2xs;
141 
142 /**
143  * @brief BLAKE2xb in XOF mode
144  *
145  * Use this variant when the required hash size is not known in advance. Otherwise, use \ref blake2xb
146  *
147  * @xof
148  *
149  * @mixinparams salt, personalization, key
150  *
151  * @mixin{mixin::blake2_mixin}
152  *
153  * @par Example:\n
154  * @code // Absorb a string and squeeze 32 bytes of output
155  * digestpp::blake2xb_xof hasher;
156  * hasher.absorb("The quick brown fox jumps over the lazy dog");
157  * std::cout << hasher.hexsqueeze(32) << '\n';
158  * @endcode
159  *
160  * @par Example output:\n
161  * @code 364e84ca4c103df292306c93ebba6f6633d5e9cc8a95e040498e9a012d5ca534
162  * @endcode
163  *
164  * @sa hasher, mixin::blake2_mixin
165  */
166 typedef hasher<detail::blake2_provider<uint64_t, detail::blake2_type::xof>, mixin::blake2_mixin> blake2xb_xof;
167 
168 /**
169  * @brief BLAKE2xs in XOF mode
170  *
171  * Use this variant when the required hash size is not known in advance. Otherwise, use \ref blake2xs
172  *
173  * @xof
174  *
175  * @mixinparams salt, personalization, key
176  *
177  * @mixin{mixin::blake2_mixin}
178  *
179  * @par Example:\n
180  * @code // Absorb a string and squeeze 32 bytes of output
181  * digestpp::blake2xs_xof hasher;
182  * hasher.absorb("The quick brown fox jumps over the lazy dog");
183  * std::cout << hasher.hexsqueeze(32) << '\n';
184  * @endcode
185  *
186  * @par Example output:\n
187  * @code 0650cde4df888a06eada0f0fecb3c17594304b4a03fdd678182f27db1238b1747e33c34ae539fe2179a7594442b5cc9a7a0f398bb15ac3095a397de6a60061d6
188  * @endcode
189  *
190  * @sa hasher, mixin::blake2_mixin
191  */
192 typedef hasher<detail::blake2_provider<uint32_t, detail::blake2_type::xof>, mixin::blake2_mixin> blake2xs_xof;
193 
194 } // namespace digestpp
195 
196 #endif // DIGESTPP_ALGORITHM_BLAKE2_HPP