1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/*!
\ingroup HMAC
\brief This function initializes an Hmac object, setting its
encryption type, key and HMAC length.
\return 0 Returned on successfully initializing the Hmac object
\return BAD_FUNC_ARG Returned if the input type is invalid (see type param)
\return MEMORY_E Returned if there is an error allocating memory for the
structure to use for hashing
\return HMAC_MIN_KEYLEN_E Returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable
FIPS standard of 14 bytes
\param hmac pointer to the Hmac object to initialize
\param type type specifying which encryption method the Hmac object
should use. Valid options are: WC_MD5, WC_SHA, WC_SHA256, WC_SHA384,
WC_SHA512, WC_SHA3_224, WC_SHA3_256, WC_SHA3_384 or WC_SHA3_512
\param key pointer to a buffer containing the key with which to
initialize the Hmac object
\param length length of the key
_Example_
\code
Hmac hmac;
byte key[] = { // initialize with key to use for encryption };
if (wc_HmacSetKey(&hmac, WC_MD5, key, sizeof(key)) != 0) {
// error initializing Hmac object
}
\endcode
\sa wc_HmacUpdate
\sa wc_HmacFinal
*/
int ;
/*!
\ingroup HMAC
\brief This function updates the message to authenticate using HMAC.
It should be called after the Hmac object has been initialized with
wc_HmacSetKey. This function may be called multiple times to update
the message to hash. After calling wc_HmacUpdate as desired, one should
call wc_HmacFinal to obtain the final authenticated message tag.
\return 0 Returned on successfully updating the message to authenticate
\return MEMORY_E Returned if there is an error allocating memory for
use with a hashing algorithm
\param hmac pointer to the Hmac object for which to update the message
\param msg pointer to the buffer containing the message to append
\param length length of the message to append
_Example_
\code
Hmac hmac;
byte msg[] = { // initialize with message to authenticate };
byte msg2[] = { // initialize with second half of message };
// initialize hmac
if( wc_HmacUpdate(&hmac, msg, sizeof(msg)) != 0) {
// error updating message
}
if( wc_HmacUpdate(&hmac, msg2, sizeof(msg)) != 0) {
// error updating with second message
}
\endcode
\sa wc_HmacSetKey
\sa wc_HmacFinal
*/
int ;
/*!
\ingroup HMAC
\brief This function computes the final hash of an Hmac object's message.
\return 0 Returned on successfully computing the final hash
\return MEMORY_E Returned if there is an error allocating memory for
use with a hashing algorithm
\param hmac pointer to the Hmac object for which to calculate the
final hash
\param hash pointer to the buffer in which to store the final hash.
Should have room available as required by the hashing algorithm chosen
_Example_
\code
Hmac hmac;
byte hash[MD5_DIGEST_SIZE];
// initialize hmac with MD5 as type
// wc_HmacUpdate() with messages
if (wc_HmacFinal(&hmac, hash) != 0) {
// error computing hash
}
\endcode
\sa wc_HmacSetKey
\sa wc_HmacUpdate
*/
int ;
/*!
\ingroup HMAC
\brief This function returns the largest HMAC digest size available
based on the configured cipher suites.
\return Success Returns the largest HMAC digest size available based
on the configured cipher suites
\param none No parameters.
_Example_
\code
int maxDigestSz = wolfSSL_GetHmacMaxSize();
\endcode
\sa none
*/
int ;
/*!
\ingroup HMAC
\brief This function provides access to a HMAC Key Derivation Function
(HKDF). It utilizes HMAC to convert inKey, with an optional salt and
optional info into a derived key, which it stores in out. The hash type
defaults to MD5 if 0 or NULL is given.
The HMAC configure option is --enable-hmac (on by default) or if building
sources directly HAVE_HKDF
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param type hash type to use for the HKDF. Valid types are: WC_MD5, WC_SHA,
WC_SHA256, WC_SHA384, WC_SHA512, WC_SHA3_224, WC_SHA3_256, WC_SHA3_384 or
WC_SHA3_512
\param inKey pointer to the buffer containing the key to use for KDF
\param inKeySz length of the input key
\param salt pointer to a buffer containing an optional salt. Use NULL
instead if not using a salt
\param saltSz length of the salt. Use 0 if not using a salt
\param info pointer to a buffer containing optional additional info.
Use NULL if not appending extra info
\param infoSz length of additional info. Use 0 if not using additional info
\param out pointer to the buffer in which to store the derived key
\param outSz space available in the output buffer to store the
generated key
_Example_
\code
byte key[] = { // initialize with key };
byte salt[] = { // initialize with salt };
byte derivedKey[MAX_DIGEST_SIZE];
int ret = wc_HKDF(WC_SHA512, key, sizeof(key), salt, sizeof(salt),
NULL, 0, derivedKey, sizeof(derivedKey));
if ( ret != 0 ) {
// error generating derived key
}
\endcode
\sa wc_HmacSetKey
*/
int ;
/*!
\ingroup HMAC
\brief This function provides access to a HMAC Key Derivation Function
(HKDF). It utilizes HMAC to convert inKey, with an optional salt
into a derived key, which it stores in out. The hash type
defaults to MD5 if 0 or NULL is given.
The HMAC configure option is --enable-hmac (on by default) or if building
sources directly HAVE_HKDF
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param type hash type to use for the HKDF. Valid types are: WC_MD5, WC_SHA,
WC_SHA256, WC_SHA384, WC_SHA512, WC_SHA3_224, WC_SHA3_256, WC_SHA3_384 or
WC_SHA3_512
\param salt pointer to a buffer containing an optional salt. Use NULL
instead if not using a salt
\param saltSz length of the salt. Use 0 if not using a salt
\param inKey pointer to the buffer containing the key to use for KDF
\param inKeySz length of the input key
\param out pointer to the buffer in which to store the derived key
_Example_
\code
byte key[] = { // initialize with key };
byte salt[] = { // initialize with salt };
byte derivedKey[MAX_DIGEST_SIZE];
int ret = wc_HKDF_Extract(WC_SHA512, salt, sizeof(salt), key, sizeof(key),
derivedKey);
if ( ret != 0 ) {
// error generating derived key
}
\endcode
\sa wc_HKDF
\sa wc_HKDF_Extract_ex
\sa wc_HKDF_Expand
\sa wc_HKDF_Expand_ex
*/
int ;
/*!
\ingroup HMAC
\brief This function provides access to a HMAC Key Derivation Function
(HKDF). It utilizes HMAC to convert inKey, with an optional salt
into a derived key, which it stores in out. The hash type
defaults to MD5 if 0 or NULL is given. This is the _ex version adding
heap hint and device identifier.
The HMAC configure option is --enable-hmac (on by default) or if building
sources directly HAVE_HKDF
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param type hash type to use for the HKDF. Valid types are: WC_MD5, WC_SHA,
WC_SHA256, WC_SHA384, WC_SHA512, WC_SHA3_224, WC_SHA3_256, WC_SHA3_384 or
WC_SHA3_512
\param salt pointer to a buffer containing an optional salt. Use NULL
instead if not using a salt
\param saltSz length of the salt. Use 0 if not using a salt
\param inKey pointer to the buffer containing the key to use for KDF
\param inKeySz length of the input key
\param out pointer to the buffer in which to store the derived key
\param heap heap hint to use for memory. Can be NULL
\param devId ID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used
_Example_
\code
byte key[] = { // initialize with key };
byte salt[] = { // initialize with salt };
byte derivedKey[MAX_DIGEST_SIZE];
int ret = wc_HKDF_Extract_ex(WC_SHA512, salt, sizeof(salt), key, sizeof(key),
derivedKey, NULL, INVALID_DEVID);
if ( ret != 0 ) {
// error generating derived key
}
\endcode
\sa wc_HKDF
\sa wc_HKDF_Extract
\sa wc_HKDF_Expand
\sa wc_HKDF_Expand_ex
*/
int ;
/*!
\ingroup HMAC
\brief This function provides access to a HMAC Key Derivation Function
(HKDF). It utilizes HMAC to convert inKey, with optional info into a
derived key, which it stores in out. The hash type
defaults to MD5 if 0 or NULL is given.
The HMAC configure option is --enable-hmac (on by default) or if building
sources directly HAVE_HKDF
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param type hash type to use for the HKDF. Valid types are: WC_MD5, WC_SHA,
WC_SHA256, WC_SHA384, WC_SHA512, WC_SHA3_224, WC_SHA3_256, WC_SHA3_384 or
WC_SHA3_512
\param inKey pointer to the buffer containing the key to use for KDF
\param inKeySz length of the input key
\param info pointer to a buffer containing optional additional info.
Use NULL if not appending extra info
\param infoSz length of additional info. Use 0 if not using additional info
\param out pointer to the buffer in which to store the derived key
\param outSz space available in the output buffer to store the
generated key
_Example_
\code
byte key[] = { // initialize with key };
byte salt[] = { // initialize with salt };
byte derivedKey[MAX_DIGEST_SIZE];
int ret = wc_HKDF_Expand(WC_SHA512, key, sizeof(key), NULL, 0,
derivedKey, sizeof(derivedKey));
if ( ret != 0 ) {
// error generating derived key
}
\endcode
\sa wc_HKDF
\sa wc_HKDF_Extract
\sa wc_HKDF_Extract_ex
\sa wc_HKDF_Expand_ex
*/
int ;
/*!
\ingroup HMAC
\brief This function provides access to a HMAC Key Derivation Function
(HKDF). It utilizes HMAC to convert inKey, with optional info into a
derived key, which it stores in out. The hash type
defaults to MD5 if 0 or NULL is given. This is the _ex version adding
heap hint and device identifier.
The HMAC configure option is --enable-hmac (on by default) or if building
sources directly HAVE_HKDF
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param type hash type to use for the HKDF. Valid types are: WC_MD5, WC_SHA,
WC_SHA256, WC_SHA384, WC_SHA512, WC_SHA3_224, WC_SHA3_256, WC_SHA3_384 or
WC_SHA3_512
\param inKey pointer to the buffer containing the key to use for KDF
\param inKeySz length of the input key
\param info pointer to a buffer containing optional additional info.
Use NULL if not appending extra info
\param infoSz length of additional info. Use 0 if not using additional info
\param out pointer to the buffer in which to store the derived key
\param outSz space available in the output buffer to store the
generated key
\param heap heap hint to use for memory. Can be NULL
\param devId ID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used
_Example_
\code
byte key[] = { // initialize with key };
byte salt[] = { // initialize with salt };
byte derivedKey[MAX_DIGEST_SIZE];
int ret = wc_HKDF_Expand_ex(WC_SHA512, key, sizeof(key), NULL, 0,
derivedKey, sizeof(derivedKey), NULL, INVALID_DEVID);
if ( ret != 0 ) {
// error generating derived key
}
\endcode
\sa wc_HKDF
\sa wc_HKDF_Extract
\sa wc_HKDF_Extract_ex
\sa wc_HKDF_Expand
*/
int ;
/*!
\ingroup HMAC
\brief This function provides access to RFC 5869
HMAC-based Extract-and-Expand Key Derivation Function (HKDF) for TLS v1.3
key derivation
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param prk Generated pseudorandom key
\param salt salt.
\param saltLen length of the salt
\param ikm pointer to putput for keying material
\param ikmLen length of the input keying material buffer
\param digest hash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512
_Example_
\code
byte secret[] = { // initialize with random key };
byte salt[] = { // initialize with optional salt };
byte masterSecret[MAX_DIGEST_SIZE];
int ret = wc_Tls13_HKDF_Extract(secret, salt, sizeof(salt), 0,
masterSecret, sizeof(masterSecret), WC_SHA512);
if ( ret != 0 ) {
// error generating derived key
}
\endcode
\sa wc_HKDF
\sa wc_HKDF_Extract
\sa wc_HKDF_Extract_ex
\sa wc_HKDF_Expand
\sa wc_Tls13_HKDF_Extract_ex
*/
int ;
/*!
\ingroup HMAC
\brief This function provides access to RFC 5869
HMAC-based Extract-and-Expand Key Derivation Function (HKDF) for TLS v1.3
key derivation. This is the _ex version adding heap hint and device identifier.
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param prk Generated pseudorandom key
\param salt Salt.
\param saltLen Length of the salt
\param ikm Pointer to output for keying material
\param ikmLen Length of the input keying material buffer
\param digest Hash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512
\param heap Heap hint to use for memory. Can be NULL
\param devId ID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used
_Example_
\code
byte secret[] = { // initialize with random key };
byte salt[] = { // initialize with optional salt };
byte masterSecret[MAX_DIGEST_SIZE];
int ret = wc_Tls13_HKDF_Extract_ex(secret, salt, sizeof(salt), 0,
masterSecret, sizeof(masterSecret), WC_SHA512, NULL, INVALID_DEVID);
if ( ret != 0 ) {
// error generating derived key
}
\endcode
\sa wc_HKDF
\sa wc_HKDF_Extract
\sa wc_HKDF_Extract_ex
\sa wc_HKDF_Expand
\sa wc_Tls13_HKDF_Extract
*/
int ;
/*!
\ingroup HMAC
\brief Expand data using HMAC, salt and label and info. TLS v1.3 defines
this function for key derivation. This is the _ex version adding heap hint
and device identifier.
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param okm Generated pseudorandom key - output key material.
\param okmLen Length of generated pseudorandom key - output key material.
\param prk Salt - pseudo-random key.
\param prkLen Length of the salt - pseudo-random key.
\param protocol TLS protocol label.
\param protocolLen Length of the TLS protocol label.
\param info Information to expand.
\param infoLen Length of the information.
\param digest Hash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512
\param heap Heap hint to use for memory. Can be NULL
\param devId ID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used
\sa wc_HKDF
\sa wc_HKDF_Extract
\sa wc_HKDF_Extract_ex
\sa wc_HKDF_Expand
\sa wc_Tls13_HKDF_Expand_Label
\sa wc_Tls13_HKDF_Expand_Label_Alloc
*/
int ;
/*!
\ingroup HMAC
\brief Expand data using HMAC, salt and label and info. TLS v1.3 defines
this function for key derivation.
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param okm Generated pseudorandom key - output key material.
\param okmLen Length of generated pseudorandom key - output key material.
\param prk Salt - pseudo-random key.
\param prkLen Length of the salt - pseudo-random key.
\param protocol TLS protocol label.
\param protocolLen Length of the TLS protocol label.
\param info Information to expand.
\param infoLen Length of the information.
\param digest Hash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512
\sa wc_HKDF
\sa wc_HKDF_Extract
\sa wc_HKDF_Extract_ex
\sa wc_HKDF_Expand
\sa wc_Tls13_HKDF_Expand_Label_ex
\sa wc_Tls13_HKDF_Expand_Label_Alloc
*/
int ;
/*!
\ingroup HMAC
\brief This functions is very similar to wc_Tls13_HKDF_Expand_Label(), but it
allocates memory if the stack space usually used isn't enough. Expand data
using HMAC, salt and label and info. TLS v1.3 defines this function for
key derivation. This is the _ex version adding heap hint and device identifier.
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param okm Generated pseudorandom key - output key material.
\param okmLen Length of generated pseudorandom key - output key material.
\param prk Salt - pseudo-random key.
\param prkLen Length of the salt - pseudo-random key.
\param protocol TLS protocol label.
\param protocolLen Length of the TLS protocol label.
\param info Information to expand.
\param infoLen Length of the information.
\param digest Hash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512
\param heap Heap hint to use for memory. Can be NULL
\sa wc_HKDF
\sa wc_HKDF_Extract
\sa wc_HKDF_Extract_ex
\sa wc_HKDF_Expand
\sa wc_Tls13_HKDF_Expand_Label
\sa wc_Tls13_HKDF_Expand_Label_ex
*/
int ;