My Project
Functions
Algorithms - HMAC

Functions

int wc_HmacSetKey (Hmac *hmac, int type, const byte *key, word32 keySz)
 This function initializes an Hmac object, setting its encryption type, key and HMAC length. More...
 
int wc_HmacUpdate (Hmac *hmac, const byte *in, word32 sz)
 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. More...
 
int wc_HmacFinal (Hmac *hmac, byte *out)
 This function computes the final hash of an Hmac object's message. More...
 
int wolfSSL_GetHmacMaxSize (void)
 This function returns the largest HMAC digest size available based on the configured cipher suites. More...
 
int wc_HKDF (int type, const byte *inKey, word32 inKeySz, const byte *salt, word32 saltSz, const byte *info, word32 infoSz, byte *out, word32 outSz)
 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. More...
 
int wc_HKDF_Extract (int type, const byte *salt, word32 saltSz, const byte *inKey, word32 inKeySz, byte *out)
 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. More...
 
int wc_HKDF_Extract_ex (int type, const byte *salt, word32 saltSz, const byte *inKey, word32 inKeySz, byte *out, void *heap, int devId)
 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. More...
 
int wc_HKDF_Expand (int type, const byte *inKey, word32 inKeySz, const byte *info, word32 infoSz, byte *out, word32 outSz)
 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. More...
 
int wc_HKDF_Expand_ex (int type, const byte *inKey, word32 inKeySz, const byte *info, word32 infoSz, byte *out, word32 outSz, void *heap, int devId)
 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. More...
 
int wc_Tls13_HKDF_Extract (byte *prk, const byte *salt, word32 saltLen, byte *ikm, word32 ikmLen, int digest)
 This function provides access to RFC 5869 HMAC-based Extract-and-Expand Key Derivation Function (HKDF) for TLS v1.3 key derivation. More...
 
int wc_Tls13_HKDF_Extract_ex (byte *prk, const byte *salt, word32 saltLen, byte *ikm, word32 ikmLen, int digest, void *heap, int devId)
 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. More...
 
int wc_Tls13_HKDF_Expand_Label_ex (byte *okm, word32 okmLen, const byte *prk, word32 prkLen, const byte *protocol, word32 protocolLen, const byte *label, word32 labelLen, const byte *info, word32 infoLen, int digest, void *heap, int devId)
 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. More...
 
int wc_Tls13_HKDF_Expand_Label (byte *okm, word32 okmLen, const byte *prk, word32 prkLen, const byte *protocol, word32 protocolLen, const byte *label, word32 labelLen, const byte *info, word32 infoLen, int digest)
 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. More...
 
int wc_Tls13_HKDF_Expand_Label_Alloc (byte *okm, word32 okmLen, const byte *prk, word32 prkLen, const byte *protocol, word32 protocolLen, const byte *label, word32 labelLen, const byte *info, word32 infoLen, int digest, void *heap)
 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. More...
 

Detailed Description

Function Documentation

◆ wc_HKDF()

int wc_HKDF ( int  type,
const byte *  inKey,
word32  inKeySz,
const byte *  salt,
word32  saltSz,
const byte *  info,
word32  infoSz,
byte *  out,
word32  outSz 
)

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

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
typehash 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
inKeypointer to the buffer containing the key to use for KDF
inKeySzlength of the input key
saltpointer to a buffer containing an optional salt. Use NULL instead if not using a salt
saltSzlength of the salt. Use 0 if not using a salt
infopointer to a buffer containing optional additional info. Use NULL if not appending extra info
infoSzlength of additional info. Use 0 if not using additional info
outpointer to the buffer in which to store the derived key
outSzspace available in the output buffer to store the generated key

Example

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
}
int wc_HKDF(int type, const byte *inKey, word32 inKeySz, const byte *salt, word32 saltSz, const byte *info, word32 infoSz, byte *out, word32 outSz)
This function provides access to a HMAC Key Derivation Function (HKDF). It utilizes HMAC to convert i...
See also
wc_HmacSetKey

◆ wc_HKDF_Expand()

int wc_HKDF_Expand ( int  type,
const byte *  inKey,
word32  inKeySz,
const byte *  info,
word32  infoSz,
byte *  out,
word32  outSz 
)

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

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
typehash 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
inKeypointer to the buffer containing the key to use for KDF
inKeySzlength of the input key
infopointer to a buffer containing optional additional info. Use NULL if not appending extra info
infoSzlength of additional info. Use 0 if not using additional info
outpointer to the buffer in which to store the derived key
outSzspace available in the output buffer to store the generated key

Example

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
}
int wc_HKDF_Expand(int type, const byte *inKey, word32 inKeySz, const byte *info, word32 infoSz, byte *out, word32 outSz)
This function provides access to a HMAC Key Derivation Function (HKDF). It utilizes HMAC to convert i...
See also
wc_HKDF
wc_HKDF_Extract
wc_HKDF_Extract_ex
wc_HKDF_Expand_ex

◆ wc_HKDF_Expand_ex()

int wc_HKDF_Expand_ex ( int  type,
const byte *  inKey,
word32  inKeySz,
const byte *  info,
word32  infoSz,
byte *  out,
word32  outSz,
void *  heap,
int  devId 
)

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

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
typehash 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
inKeypointer to the buffer containing the key to use for KDF
inKeySzlength of the input key
infopointer to a buffer containing optional additional info. Use NULL if not appending extra info
infoSzlength of additional info. Use 0 if not using additional info
outpointer to the buffer in which to store the derived key
outSzspace available in the output buffer to store the generated key
heapheap hint to use for memory. Can be NULL
devIdID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used

Example

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
}
int wc_HKDF_Expand_ex(int type, const byte *inKey, word32 inKeySz, const byte *info, word32 infoSz, byte *out, word32 outSz, void *heap, int devId)
This function provides access to a HMAC Key Derivation Function (HKDF). It utilizes HMAC to convert i...
See also
wc_HKDF
wc_HKDF_Extract
wc_HKDF_Extract_ex
wc_HKDF_Expand

◆ wc_HKDF_Extract()

int wc_HKDF_Extract ( int  type,
const byte *  salt,
word32  saltSz,
const byte *  inKey,
word32  inKeySz,
byte *  out 
)

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

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
typehash 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
saltpointer to a buffer containing an optional salt. Use NULL instead if not using a salt
saltSzlength of the salt. Use 0 if not using a salt
inKeypointer to the buffer containing the key to use for KDF
inKeySzlength of the input key
outpointer to the buffer in which to store the derived key

Example

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
}
int wc_HKDF_Extract(int type, const byte *salt, word32 saltSz, const byte *inKey, word32 inKeySz, byte *out)
This function provides access to a HMAC Key Derivation Function (HKDF). It utilizes HMAC to convert i...
See also
wc_HKDF
wc_HKDF_Extract_ex
wc_HKDF_Expand
wc_HKDF_Expand_ex

◆ wc_HKDF_Extract_ex()

int wc_HKDF_Extract_ex ( int  type,
const byte *  salt,
word32  saltSz,
const byte *  inKey,
word32  inKeySz,
byte *  out,
void *  heap,
int  devId 
)

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

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
typehash 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
saltpointer to a buffer containing an optional salt. Use NULL instead if not using a salt
saltSzlength of the salt. Use 0 if not using a salt
inKeypointer to the buffer containing the key to use for KDF
inKeySzlength of the input key
outpointer to the buffer in which to store the derived key
heapheap hint to use for memory. Can be NULL
devIdID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used

Example

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
}
int wc_HKDF_Extract_ex(int type, const byte *salt, word32 saltSz, const byte *inKey, word32 inKeySz, byte *out, void *heap, int devId)
This function provides access to a HMAC Key Derivation Function (HKDF). It utilizes HMAC to convert i...
See also
wc_HKDF
wc_HKDF_Extract
wc_HKDF_Expand
wc_HKDF_Expand_ex

◆ wc_HmacFinal()

int wc_HmacFinal ( Hmac *  hmac,
byte *  out 
)

This function computes the final hash of an Hmac object's message.

Returns
0 Returned on successfully computing the final hash
MEMORY_E Returned if there is an error allocating memory for use with a hashing algorithm
Parameters
hmacpointer to the Hmac object for which to calculate the final hash
hashpointer to the buffer in which to store the final hash. Should have room available as required by the hashing algorithm chosen

Example

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
}
int wc_HmacFinal(Hmac *hmac, byte *out)
This function computes the final hash of an Hmac object's message.
See also
wc_HmacSetKey
wc_HmacUpdate

◆ wc_HmacSetKey()

int wc_HmacSetKey ( Hmac *  hmac,
int  type,
const byte *  key,
word32  keySz 
)

This function initializes an Hmac object, setting its encryption type, key and HMAC length.

Returns
0 Returned on successfully initializing the Hmac object
BAD_FUNC_ARG Returned if the input type is invalid (see type param)
MEMORY_E Returned if there is an error allocating memory for the structure to use for hashing
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
Parameters
hmacpointer to the Hmac object to initialize
typetype 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
keypointer to a buffer containing the key with which to initialize the Hmac object
lengthlength of the key

Example

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
}
int wc_HmacSetKey(Hmac *hmac, int type, const byte *key, word32 keySz)
This function initializes an Hmac object, setting its encryption type, key and HMAC length.
See also
wc_HmacUpdate
wc_HmacFinal

◆ wc_HmacUpdate()

int wc_HmacUpdate ( Hmac *  hmac,
const byte *  in,
word32  sz 
)

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.

Returns
0 Returned on successfully updating the message to authenticate
MEMORY_E Returned if there is an error allocating memory for use with a hashing algorithm
Parameters
hmacpointer to the Hmac object for which to update the message
msgpointer to the buffer containing the message to append
lengthlength of the message to append

Example

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
}
int wc_HmacUpdate(Hmac *hmac, const byte *in, word32 sz)
This function updates the message to authenticate using HMAC. It should be called after the Hmac obje...
See also
wc_HmacSetKey
wc_HmacFinal

◆ wc_Tls13_HKDF_Expand_Label()

int wc_Tls13_HKDF_Expand_Label ( byte *  okm,
word32  okmLen,
const byte *  prk,
word32  prkLen,
const byte *  protocol,
word32  protocolLen,
const byte *  label,
word32  labelLen,
const byte *  info,
word32  infoLen,
int  digest 
)

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.

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
okmGenerated pseudorandom key - output key material.
okmLenLength of generated pseudorandom key - output key material.
prkSalt - pseudo-random key.
prkLenLength of the salt - pseudo-random key.
protocolTLS protocol label.
protocolLenLength of the TLS protocol label.
infoInformation to expand.
infoLenLength of the information.
digestHash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512
See also
wc_HKDF
wc_HKDF_Extract
wc_HKDF_Extract_ex
wc_HKDF_Expand
wc_Tls13_HKDF_Expand_Label_ex
wc_Tls13_HKDF_Expand_Label_Alloc

◆ wc_Tls13_HKDF_Expand_Label_Alloc()

int wc_Tls13_HKDF_Expand_Label_Alloc ( byte *  okm,
word32  okmLen,
const byte *  prk,
word32  prkLen,
const byte *  protocol,
word32  protocolLen,
const byte *  label,
word32  labelLen,
const byte *  info,
word32  infoLen,
int  digest,
void *  heap 
)

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.

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
okmGenerated pseudorandom key - output key material.
okmLenLength of generated pseudorandom key - output key material.
prkSalt - pseudo-random key.
prkLenLength of the salt - pseudo-random key.
protocolTLS protocol label.
protocolLenLength of the TLS protocol label.
infoInformation to expand.
infoLenLength of the information.
digestHash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512
heapHeap hint to use for memory. Can be NULL
See also
wc_HKDF
wc_HKDF_Extract
wc_HKDF_Extract_ex
wc_HKDF_Expand
wc_Tls13_HKDF_Expand_Label
wc_Tls13_HKDF_Expand_Label_ex

◆ wc_Tls13_HKDF_Expand_Label_ex()

int wc_Tls13_HKDF_Expand_Label_ex ( byte *  okm,
word32  okmLen,
const byte *  prk,
word32  prkLen,
const byte *  protocol,
word32  protocolLen,
const byte *  label,
word32  labelLen,
const byte *  info,
word32  infoLen,
int  digest,
void *  heap,
int  devId 
)

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.

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
okmGenerated pseudorandom key - output key material.
okmLenLength of generated pseudorandom key - output key material.
prkSalt - pseudo-random key.
prkLenLength of the salt - pseudo-random key.
protocolTLS protocol label.
protocolLenLength of the TLS protocol label.
infoInformation to expand.
infoLenLength of the information.
digestHash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512
heapHeap hint to use for memory. Can be NULL
devIdID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used
See also
wc_HKDF
wc_HKDF_Extract
wc_HKDF_Extract_ex
wc_HKDF_Expand
wc_Tls13_HKDF_Expand_Label
wc_Tls13_HKDF_Expand_Label_Alloc

◆ wc_Tls13_HKDF_Extract()

int wc_Tls13_HKDF_Extract ( byte *  prk,
const byte *  salt,
word32  saltLen,
byte *  ikm,
word32  ikmLen,
int  digest 
)

This function provides access to RFC 5869 HMAC-based Extract-and-Expand Key Derivation Function (HKDF) for TLS v1.3 key derivation.

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
prkGenerated pseudorandom key
saltsalt.
saltLenlength of the salt
ikmpointer to putput for keying material
ikmLenlength of the input keying material buffer
digesthash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512

Example

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
}
int wc_Tls13_HKDF_Extract(byte *prk, const byte *salt, word32 saltLen, byte *ikm, word32 ikmLen, int digest)
This function provides access to RFC 5869 HMAC-based Extract-and-Expand Key Derivation Function (HKDF...
See also
wc_HKDF
wc_HKDF_Extract
wc_HKDF_Extract_ex
wc_HKDF_Expand
wc_Tls13_HKDF_Extract_ex

◆ wc_Tls13_HKDF_Extract_ex()

int wc_Tls13_HKDF_Extract_ex ( byte *  prk,
const byte *  salt,
word32  saltLen,
byte *  ikm,
word32  ikmLen,
int  digest,
void *  heap,
int  devId 
)

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.

Returns
0 Returned upon successfully generating a key with the given inputs
BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
MEMORY_E Returned if there is an error allocating memory
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
Parameters
prkGenerated pseudorandom key
saltSalt.
saltLenLength of the salt
ikmPointer to output for keying material
ikmLenLength of the input keying material buffer
digestHash type to use for the HKDF. Valid types are: WC_SHA256, WC_SHA384 or WC_SHA512
heapHeap hint to use for memory. Can be NULL
devIdID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used

Example

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
}
int wc_Tls13_HKDF_Extract_ex(byte *prk, const byte *salt, word32 saltLen, byte *ikm, word32 ikmLen, int digest, void *heap, int devId)
This function provides access to RFC 5869 HMAC-based Extract-and-Expand Key Derivation Function (HKDF...
See also
wc_HKDF
wc_HKDF_Extract
wc_HKDF_Extract_ex
wc_HKDF_Expand
wc_Tls13_HKDF_Extract

◆ wolfSSL_GetHmacMaxSize()

int wolfSSL_GetHmacMaxSize ( void  )

This function returns the largest HMAC digest size available based on the configured cipher suites.

Returns
Success Returns the largest HMAC digest size available based on the configured cipher suites
Parameters
noneNo parameters.

Example

int maxDigestSz = wolfSSL_GetHmacMaxSize();
int wolfSSL_GetHmacMaxSize(void)
This function returns the largest HMAC digest size available based on the configured cipher suites.
See also
none