Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
41 #if (TLS_KDF_SUPPORT == ENABLED)
63 const uint8_t *seed,
size_t seedLen, uint8_t *output,
size_t outputLen)
65 #if (MD5_SUPPORT == ENABLED && SHA1_SUPPORT == ENABLED)
76 if(
secret == NULL || label == NULL || seed == NULL || output == NULL)
79 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
83 if(hmacContext == NULL)
92 sLen = (secretLen + 1) / 2;
96 s2 =
secret + secretLen - sLen;
105 for(i = 0; i < outputLen; )
117 output[i] = hmacContext->
digest[j];
133 for(i = 0; i < outputLen; )
145 output[i] ^= hmacContext->
digest[j];
154 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
188 size_t secretLen,
const char_t *label,
const uint8_t *seed,
size_t seedLen,
189 uint8_t *output,
size_t outputLen)
197 if(hashAlgo == NULL ||
secret == NULL || label == NULL || seed == NULL ||
203 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
207 if(hmacContext == NULL)
246 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
272 const uint8_t *context,
size_t contextLen, uint8_t *output,
275 #if (HKDF_SUPPORT == ENABLED)
283 if(
prefix == NULL || label == NULL)
286 if(context == NULL && contextLen != 0)
303 if(outputLen > 65535)
307 temp[0] =
MSB(outputLen);
308 temp[1] =
LSB(outputLen);
310 temp[2] = (uint8_t) (
prefixLen + labelLen);
312 temp[3] = (uint8_t) contextLen;
315 hkdfLabelFrags[0].
buffer = &temp[0];
316 hkdfLabelFrags[0].
length =
sizeof(uint16_t);
317 hkdfLabelFrags[1].
buffer = &temp[2];
318 hkdfLabelFrags[1].
length =
sizeof(uint8_t);
321 hkdfLabelFrags[3].
buffer = label;
322 hkdfLabelFrags[3].
length = labelLen;
323 hkdfLabelFrags[4].
buffer = &temp[3];
324 hkdfLabelFrags[4].
length =
sizeof(uint8_t);
325 hkdfLabelFrags[5].
buffer = context;
326 hkdfLabelFrags[5].
length = contextLen;
330 arraysize(hkdfLabelFrags), output, outputLen);
error_t tls12Prf(const HashAlgo *hashAlgo, const uint8_t *secret, size_t secretLen, const char_t *label, const uint8_t *seed, size_t seedLen, uint8_t *output, size_t outputLen)
Pseudorandom function (TLS 1.2)
error_t tlsPrf(const uint8_t *secret, size_t secretLen, const char_t *label, const uint8_t *seed, size_t seedLen, uint8_t *output, size_t outputLen)
Pseudorandom function (TLS 1.0 and 1.1)
TLS key derivation functions.
#define MAX_HASH_DIGEST_SIZE
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
Data fragment descriptor.
General definitions for cryptographic algorithms.
uint8_t secret[TLS_MASTER_SECRET_SIZE]
Master secret.
__weak_func void hmacUpdate(HmacContext *context, const void *data, size_t length)
Update the HMAC context with a portion of the message being hashed.
error_t hkdfExpandLabel(const HashAlgo *hashAlgo, const uint8_t *secret, size_t secretLen, const char_t *prefix, const char_t *label, const uint8_t *context, size_t contextLen, uint8_t *output, size_t outputLen)
HKDF-Expand-Label function (TLS 1.3)
uint8_t digest[MAX_HASH_DIGEST_SIZE]
HKDF (HMAC-based Key Derivation Function)
__weak_func void hmacFinal(HmacContext *context, uint8_t *digest)
Finish the HMAC calculation.
error_t hkdfExpandEx(const HashAlgo *hashAlgo, const uint8_t *prk, size_t prkLen, const DataFrag *infoFrags, size_t infoNumFrags, uint8_t *okm, size_t okmLen)
HKDF expand step.
#define cryptoAllocMem(size)
Common interface for hash algorithms.
__weak_func error_t hmacInit(HmacContext *context, const HashAlgo *hash, const void *key, size_t keyLen)
Initialize HMAC calculation.
HMAC (Keyed-Hashing for Message Authentication)