Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
40 #if (PBKDF_SUPPORT == ENABLED)
43 const uint8_t
PBKDF2_OID[9] = {0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0C};
65 const uint8_t *
s,
size_t sLen,
uint_t c, uint8_t *dk,
size_t dkLen)
69 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
76 if(hashAlgo == NULL ||
p == NULL ||
s == NULL || dk == NULL)
87 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
91 if(hashContext == NULL)
96 hashAlgo->
init(hashContext);
97 hashAlgo->
update(hashContext,
p, pLen);
98 hashAlgo->
update(hashContext,
s, sLen);
99 hashAlgo->
final(hashContext,
t);
102 for(i = 1; i <
c; i++)
105 hashAlgo->
init(hashContext);
107 hashAlgo->
final(hashContext,
t);
113 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
142 size_t pLen,
const uint8_t *
s,
size_t sLen,
uint_t c, uint8_t *dk,
150 error =
pbkdf2Hmac(hashAlgo,
p, pLen,
s, sLen,
c, dk, dkLen);
180 const uint8_t *
s,
size_t sLen,
uint_t c, uint8_t *dk,
size_t dkLen)
182 #if (HMAC_SUPPORT == ENABLED)
189 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
196 if(hashAlgo == NULL ||
p == NULL ||
s == NULL || dk == NULL)
203 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
207 if(hmacContext == NULL)
212 for(i = 1; dkLen > 0; i++)
218 hmacInit(hmacContext, hashAlgo,
p, pLen);
227 for(j = 1; j <
c; j++)
230 hmacInit(hmacContext, hashAlgo,
p, pLen);
251 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
278 size_t sLen,
uint_t c, uint8_t *dk,
size_t dkLen)
280 #if (CMAC_SUPPORT == ENABLED && AES_SUPPORT == ENABLED)
288 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
295 if(
p == NULL ||
s == NULL || dk == NULL)
302 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
306 if(cmacContext == NULL)
331 for(i = 1; dkLen > 0; i++)
346 for(j = 1; j <
c; j++)
354 for(
n = 0;
n < 16;
n++)
370 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
Generic hash algorithm context.
error_t pbkdf2(Pbkdf2Type type, const HashAlgo *hashAlgo, const uint8_t *p, size_t pLen, const uint8_t *s, size_t sLen, uint_t c, uint8_t *dk, size_t dkLen)
PBKDF2 key derivation function.
Pbkdf2Type
PBKDF2 pseudorandom functions.
#define MAX_HASH_DIGEST_SIZE
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
error_t pbkdf2AesCmacPrf128(const uint8_t *p, size_t pLen, const uint8_t *s, size_t sLen, uint_t c, uint8_t *dk, size_t dkLen)
PBKDF2 key derivation function (with AES-CMAC-PRF-128)
error_t pbkdf2Hmac(const HashAlgo *hashAlgo, const uint8_t *p, size_t pLen, const uint8_t *s, size_t sLen, uint_t c, uint8_t *dk, size_t dkLen)
PBKDF2 key derivation function (with HMAC)
General definitions for cryptographic algorithms.
__weak_func void hmacUpdate(HmacContext *context, const void *data, size_t length)
Update the HMAC context with a portion of the message being hashed.
PBKDF (Password-Based Key Derivation Function)
__weak_func void hmacFinal(HmacContext *context, uint8_t *digest)
Finish the HMAC calculation.
error_t cmacInit(CmacContext *context, const CipherAlgo *cipher, const void *key, size_t keyLen)
Initialize CMAC calculation.
#define cryptoAllocMem(size)
void cmacUpdate(CmacContext *context, const void *data, size_t dataLen)
Update the CMAC context with a portion of the message being hashed.
Collection of MAC algorithms.
Common interface for hash algorithms.
const uint8_t PBKDF2_OID[9]
#define osMemset(p, value, length)
__weak_func error_t hmacInit(HmacContext *context, const HashAlgo *hash, const void *key, size_t keyLen)
Initialize HMAC calculation.
@ PBKDF2_TYPE_AES_CMAC_PRF_128
error_t cmacFinal(CmacContext *context, uint8_t *mac, size_t macLen)
Finish the CMAC calculation.
error_t pbkdf1(const HashAlgo *hashAlgo, const uint8_t *p, size_t pLen, const uint8_t *s, size_t sLen, uint_t c, uint8_t *dk, size_t dkLen)
PBKDF1 key derivation function.