1414 \code
1515 Blake2b b2b;
1616 // initialize Blake2b structure with 64 byte digest
17- wc_InitBlake2b(&b2b, 64 );
17+ wc_InitBlake2b(&b2b, BLAKE2B_OUTBYTES );
1818 \endcode
1919
2020 \sa wc_Blake2bUpdate
@@ -41,13 +41,13 @@ int wc_InitBlake2b(Blake2b* b2b, word32 digestSz);
4141 int ret;
4242 Blake2b b2b;
4343 // initialize Blake2b structure with 64 byte digest
44- wc_InitBlake2b(&b2b, 64 );
44+ wc_InitBlake2b(&b2b, BLAKE2B_OUTBYTES );
4545
4646 byte plain[] = { // initialize input };
4747
4848 ret = wc_Blake2bUpdate(&b2b, plain, sizeof(plain));
4949 if( ret != 0) {
50- // error updating blake2b
50+ // error updating blake2b
5151 }
5252 \endcode
5353
@@ -78,18 +78,177 @@ int wc_Blake2bUpdate(Blake2b* b2b, const byte* data, word32 sz);
7878 \code
7979 int ret;
8080 Blake2b b2b;
81- byte hash[64 ];
81+ byte hash[BLAKE2B_OUTBYTES ];
8282 // initialize Blake2b structure with 64 byte digest
83- wc_InitBlake2b(&b2b, 64 );
83+ wc_InitBlake2b(&b2b, BLAKE2B_OUTBYTES );
8484 ... // call wc_Blake2bUpdate to add data to hash
8585
86- ret = wc_Blake2bFinal(&b2b, hash, 64 );
86+ ret = wc_Blake2bFinal(&b2b, hash, BLAKE2B_OUTBYTES );
8787 if( ret != 0) {
88- // error generating blake2b hash
88+ // error generating blake2b hash
8989 }
9090 \endcode
9191
9292 \sa wc_InitBlake2b
9393 \sa wc_Blake2bUpdate
9494*/
9595int wc_Blake2bFinal (Blake2b * b2b , byte * final , word32 requestSz );
96+
97+ /*!
98+ \ingroup BLAKE2
99+
100+ \brief This function computes the HMAC-BLAKE2b message authentication code
101+ of the given input data using the given key.
102+
103+ \return 0 Returned upon successfully computing the HMAC-BLAKE2b MAC.
104+
105+ \param in pointer to the input data
106+ \param in_len length of the input data
107+ \param key pointer to the key
108+ \param key_len length of the key
109+ \param out output buffer to store computed MAC
110+ \param out_len length of output buffer
111+
112+ _Example_
113+ \code
114+ int ret;
115+ byte mac[BLAKE2B_OUTBYTES];
116+ byte data[] = {1, 2, 3};
117+ byte key[] = {4, 5, 6};
118+ ret = wc_Blake2bHmac(data, sizeof(data), key, sizeof(key), mac, sizeof(mac));
119+ if( ret != 0) {
120+ // error generating HMAC-BLAKE2b
121+ }
122+ \endcode
123+ */
124+ int wc_Blake2bHmac (const byte * in , size_t in_len ,
125+ const byte * key , size_t key_len ,
126+ byte * out , size_t out_len );
127+
128+
129+ /*!
130+ \ingroup BLAKE2
131+
132+ \brief This function initializes a Blake2s structure for use with the
133+ Blake2 hash function.
134+
135+ \return 0 Returned upon successfully initializing the Blake2s structure and
136+ setting the digest size.
137+
138+ \param b2s pointer to the Blake2s structure to initialize
139+ \param digestSz length of the blake 2 digest to implement
140+
141+ _Example_
142+ \code
143+ Blake2s b2s;
144+ // initialize Blake2s structure with 32 byte digest
145+ wc_InitBlake2s(&b2s, BLAKE2S_OUTBYTES);
146+ \endcode
147+
148+ \sa wc_Blake2sUpdate
149+ */
150+ int wc_InitBlake2s (Blake2s * b2s , word32 digestSz );
151+
152+ /*!
153+ \ingroup BLAKE2
154+
155+ \brief This function updates the Blake2s hash with the given input data.
156+ This function should be called after wc_InitBlake2s, and repeated until
157+ one is ready for the final hash: wc_Blake2sFinal.
158+
159+ \return 0 Returned upon successfully update the Blake2s structure with
160+ the given data
161+ \return -1 Returned if there is a failure while compressing the input data
162+
163+ \param b2s pointer to the Blake2s structure to update
164+ \param data pointer to a buffer containing the data to append
165+ \param sz length of the input data to append
166+
167+ _Example_
168+ \code
169+ int ret;
170+ Blake2s b2s;
171+ // initialize Blake2s structure with 32 byte digest
172+ wc_InitBlake2s(&b2s, BLAKE2S_OUTBYTES);
173+
174+ byte plain[] = { // initialize input };
175+
176+ ret = wc_Blake2sUpdate(&b2s, plain, sizeof(plain));
177+ if( ret != 0) {
178+ // error updating blake2s
179+ }
180+ \endcode
181+
182+ \sa wc_InitBlake2s
183+ \sa wc_Blake2sFinal
184+ */
185+ int wc_Blake2sUpdate (Blake2s * b2s , const byte * data , word32 sz );
186+
187+ /*!
188+ \ingroup BLAKE2
189+
190+ \brief This function computes the Blake2s hash of the previously supplied
191+ input data. The output hash will be of length requestSz, or, if
192+ requestSz==0, the digestSz of the b2s structure. This function should be
193+ called after wc_InitBlake2s and wc_Blake2sUpdate has been processed for
194+ each piece of input data desired.
195+
196+ \return 0 Returned upon successfully computing the Blake2s hash
197+ \return -1 Returned if there is a failure while parsing the Blake2s hash
198+
199+ \param b2s pointer to the Blake2s structure to update
200+ \param final pointer to a buffer in which to store the blake2s hash.
201+ Should be of length requestSz
202+ \param requestSz length of the digest to compute. When this is zero,
203+ b2s->digestSz will be used instead
204+
205+ _Example_
206+ \code
207+ int ret;
208+ Blake2s b2s;
209+ byte hash[BLAKE2S_OUTBYTES];
210+ // initialize Blake2s structure with 32 byte digest
211+ wc_InitBlake2s(&b2s, BLAKE2S_OUTBYTES);
212+ ... // call wc_Blake2sUpdate to add data to hash
213+
214+ ret = wc_Blake2sFinal(&b2s, hash, BLAKE2S_OUTBYTES);
215+ if( ret != 0) {
216+ // error generating blake2s hash
217+ }
218+ \endcode
219+
220+ \sa wc_InitBlake2s
221+ \sa wc_Blake2sUpdate
222+ */
223+ int wc_Blake2sFinal (Blake2s * b2s , byte * final , word32 requestSz );
224+
225+ /*!
226+ \ingroup BLAKE2
227+
228+ \brief This function computes the HMAC-BLAKE2s message authentication code
229+ of the given input data using the given key.
230+
231+ \return 0 Returned upon successfully computing the HMAC-BLAKE2s MAC.
232+
233+ \param in pointer to the input data
234+ \param in_len length of the input data
235+ \param key pointer to the key
236+ \param key_len length of the key
237+ \param out output buffer to store computed MAC
238+ \param out_len length of output buffer
239+
240+ _Example_
241+ \code
242+ int ret;
243+ byte mac[BLAKE2S_OUTBYTES];
244+ byte data[] = {1, 2, 3};
245+ byte key[] = {4, 5, 6};
246+ ret = wc_Blake2sHmac(data, sizeof(data), key, sizeof(key), mac, sizeof(mac));
247+ if( ret != 0) {
248+ // error generating HMAC-BLAKE2s
249+ }
250+ \endcode
251+ */
252+ int wc_Blake2sHmac (const byte * in , size_t in_len ,
253+ const byte * key , size_t key_len ,
254+ byte * out , size_t out_len );
0 commit comments