Skip to content

Commit c725be2

Browse files
committed
add blake2-hash API documentation
1 parent d752f90 commit c725be2

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

src/hashes/blake2b.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,19 @@ static int blake2b_init_param(hash_state *md, const unsigned char *P)
199199
return CRYPT_OK;
200200
}
201201

202+
/**
203+
Initialize the hash/MAC state
204+
205+
Use this function to init for arbitrary sizes.
206+
207+
Give a key and keylen to init for MAC mode.
208+
209+
@param md The hash state you wish to initialize
210+
@param outlen The desired output-length
211+
@param key The key of the MAC
212+
@param keylen The length of the key
213+
@return CRYPT_OK if successful
214+
*/
202215
int blake2b_init(hash_state *md, unsigned long outlen, const unsigned char *key, unsigned long keylen)
203216
{
204217
unsigned char P[BLAKE2B_PARAM_SIZE];
@@ -237,12 +250,32 @@ int blake2b_init(hash_state *md, unsigned long outlen, const unsigned char *key,
237250
return CRYPT_OK;
238251
}
239252

253+
/**
254+
Initialize the hash state
255+
@param md The hash state you wish to initialize
256+
@return CRYPT_OK if successful
257+
*/
240258
int blake2b_160_init(hash_state *md) { return blake2b_init(md, 20, NULL, 0); }
241259

260+
/**
261+
Initialize the hash state
262+
@param md The hash state you wish to initialize
263+
@return CRYPT_OK if successful
264+
*/
242265
int blake2b_256_init(hash_state *md) { return blake2b_init(md, 32, NULL, 0); }
243266

267+
/**
268+
Initialize the hash state
269+
@param md The hash state you wish to initialize
270+
@return CRYPT_OK if successful
271+
*/
244272
int blake2b_384_init(hash_state *md) { return blake2b_init(md, 48, NULL, 0); }
245273

274+
/**
275+
Initialize the hash state
276+
@param md The hash state you wish to initialize
277+
@return CRYPT_OK if successful
278+
*/
246279
int blake2b_512_init(hash_state *md) { return blake2b_init(md, 64, NULL, 0); }
247280

248281
#define G(r, i, a, b, c, d) \
@@ -328,6 +361,13 @@ static int blake2b_compress(hash_state *md, const unsigned char *buf)
328361
}
329362
#endif
330363

364+
/**
365+
Process a block of memory through the hash
366+
@param md The hash state
367+
@param in The data to hash
368+
@param inlen The length of the data (octets)
369+
@return CRYPT_OK if successful
370+
*/
331371
int blake2b_process(hash_state *md, const unsigned char *in, unsigned long inlen)
332372
{
333373
LTC_ARGCHK(md != NULL);
@@ -360,6 +400,12 @@ int blake2b_process(hash_state *md, const unsigned char *in, unsigned long inlen
360400
return CRYPT_OK;
361401
}
362402

403+
/**
404+
Terminate the hash to get the digest
405+
@param md The hash state
406+
@param out [out] The destination of the hash (size depending on the length used on init)
407+
@return CRYPT_OK if successful
408+
*/
363409
int blake2b_done(hash_state *md, unsigned char *out)
364410
{
365411
unsigned char buffer[BLAKE2B_OUTBYTES] = { 0 };

src/hashes/blake2s.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ static int blake2s_init_param(hash_state *md, const unsigned char *P)
193193
return CRYPT_OK;
194194
}
195195

196+
/**
197+
Initialize the hash/MAC state
198+
199+
Use this function to init for arbitrary sizes.
200+
201+
Give a key and keylen to init for MAC mode.
202+
203+
@param md The hash state you wish to initialize
204+
@param outlen The desired output-length
205+
@param key The key of the MAC
206+
@param keylen The length of the key
207+
@return CRYPT_OK if successful
208+
*/
196209
int blake2s_init(hash_state *md, unsigned long outlen, const unsigned char *key, unsigned long keylen)
197210
{
198211
unsigned char P[BLAKE2S_PARAM_SIZE];
@@ -230,12 +243,32 @@ int blake2s_init(hash_state *md, unsigned long outlen, const unsigned char *key,
230243
return CRYPT_OK;
231244
}
232245

246+
/**
247+
Initialize the hash state
248+
@param md The hash state you wish to initialize
249+
@return CRYPT_OK if successful
250+
*/
233251
int blake2s_128_init(hash_state *md) { return blake2s_init(md, 16, NULL, 0); }
234252

253+
/**
254+
Initialize the hash state
255+
@param md The hash state you wish to initialize
256+
@return CRYPT_OK if successful
257+
*/
235258
int blake2s_160_init(hash_state *md) { return blake2s_init(md, 20, NULL, 0); }
236259

260+
/**
261+
Initialize the hash state
262+
@param md The hash state you wish to initialize
263+
@return CRYPT_OK if successful
264+
*/
237265
int blake2s_224_init(hash_state *md) { return blake2s_init(md, 28, NULL, 0); }
238266

267+
/**
268+
Initialize the hash state
269+
@param md The hash state you wish to initialize
270+
@return CRYPT_OK if successful
271+
*/
239272
int blake2s_256_init(hash_state *md) { return blake2s_init(md, 32, NULL, 0); }
240273

241274
#define G(r, i, a, b, c, d) \
@@ -316,6 +349,13 @@ static int blake2s_compress(hash_state *md, const unsigned char *buf)
316349
}
317350
#endif
318351

352+
/**
353+
Process a block of memory through the hash
354+
@param md The hash state
355+
@param in The data to hash
356+
@param inlen The length of the data (octets)
357+
@return CRYPT_OK if successful
358+
*/
319359
int blake2s_process(hash_state *md, const unsigned char *in, unsigned long inlen)
320360
{
321361
LTC_ARGCHK(md != NULL);
@@ -348,6 +388,12 @@ int blake2s_process(hash_state *md, const unsigned char *in, unsigned long inlen
348388
return CRYPT_OK;
349389
}
350390

391+
/**
392+
Terminate the hash to get the digest
393+
@param md The hash state
394+
@param out [out] The destination of the hash (size depending on the length used on init)
395+
@return CRYPT_OK if successful
396+
*/
351397
int blake2s_done(hash_state *md, unsigned char *out)
352398
{
353399
unsigned char buffer[BLAKE2S_OUTBYTES] = { 0 };

0 commit comments

Comments
 (0)