Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
40 #if (HASH_DRBG_SUPPORT == ENABLED)
65 if(context == NULL || hashAlgo == NULL)
143 size_t entropyInputLen,
const uint8_t *
nonce,
size_t nonceLen,
144 const uint8_t *personalizationString,
size_t personalizationStringLen)
150 if(context == NULL || entropyInput == NULL)
154 if(
nonce == NULL && nonceLen != 0)
158 if(personalizationString == NULL && personalizationStringLen != 0)
169 if(entropyInputLen < context->securityStrength)
184 input[0].
buffer = entropyInput;
185 input[0].
length = entropyInputLen;
187 input[1].
length = nonceLen;
188 input[2].
buffer = personalizationString;
189 input[2].
length = personalizationStringLen;
199 input[0].
length =
sizeof(k);
245 size_t entropyInputLen,
const uint8_t *additionalInput,
246 size_t additionalInputLen)
253 if(context == NULL || entropyInput == NULL)
257 if(additionalInput == NULL && additionalInputLen != 0)
272 if(entropyInputLen < context->securityStrength)
283 input[0].
length =
sizeof(k);
286 input[2].
buffer = entropyInput;
287 input[2].
length = entropyInputLen;
288 input[3].
buffer = additionalInput;
289 input[3].
length = additionalInputLen;
301 input[0].
length =
sizeof(k);
347 const uint8_t *additionalInput,
size_t additionalInputLen, uint8_t *output,
361 if(additionalInput == NULL && additionalInputLen != 0)
388 if(additionalInputLen > 0)
394 hashAlgo->
init(hashContext);
395 hashAlgo->
update(hashContext, &k,
sizeof(k));
397 hashAlgo->
update(hashContext, additionalInput, additionalInputLen);
398 hashAlgo->
final(hashContext,
t);
405 hashGen(context, output, outputLen);
411 hashAlgo->
init(hashContext);
412 hashAlgo->
update(hashContext, &k,
sizeof(k));
414 hashAlgo->
final(hashContext,
t);
464 uint8_t *output,
size_t outputLen)
483 for(counter = 1; outputLen > 0; counter++)
489 hashAlgo->
init(hashContext);
490 hashAlgo->
update(hashContext, &counter,
sizeof(counter));
491 hashAlgo->
update(hashContext, buffer,
sizeof(buffer));
493 for(i = 0; i < inputLen; i++)
495 hashAlgo->
update(hashContext, input[i].buffer, input[i].
length);
498 hashAlgo->
final(hashContext, digest);
540 hashAlgo->
init(hashContext);
542 hashAlgo->
final(hashContext, w);
571 for(temp = 0, i = 1; i <= aLen; i++)
575 temp += (i <= bLen) ?
b[bLen - i] : 0;
576 a[aLen - i] = temp & 0xFF;
594 for(temp = 1, i = 1; i <= aLen; i++)
598 a[aLen - i] = temp & 0xFF;
Generic hash algorithm context.
error_t hashDrbgSeed(HashDrbgContext *context, const uint8_t *seed, size_t length)
Seed the PRNG state.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
HashContext hashContext
Hash context.
error_t hashDrbgReseedEx(HashDrbgContext *context, const uint8_t *entropyInput, size_t entropyInputLen, const uint8_t *additionalInput, size_t additionalInputLen)
Reseed the PRNG state (with additional input)
error_t hashDrbgGenerateEx(HashDrbgContext *context, const uint8_t *additionalInput, size_t additionalInputLen, uint8_t *output, size_t outputLen)
Generate pseudorandom data (with additional input)
uint64_t reseedCounter
Reseed counter.
error_t(* PrngAlgoSeed)(void *context, const uint8_t *seed, size_t length)
void hashDf(HashDrbgContext *context, const DataChunk *input, uint_t inputLen, uint8_t *output, size_t outputLen)
Hash derivation function.
void hashDrbgAdd(uint8_t *a, size_t aLen, const uint8_t *b, size_t bLen)
Add blocks.
error_t(* PrngAlgoReseed)(void *context, const uint8_t *seed, size_t length)
uint8_t c[HASH_DRBG_MAX_SEED_LEN]
Constant C.
OsMutex mutex
Mutex preventing simultaneous access to the PRNG state.
const PrngAlgo hashDrbgPrngAlgo
#define MAX_HASH_DIGEST_SIZE
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
Hash_DRBG pseudorandom number generator.
const HashAlgo * hashAlgo
Hash function.
General definitions for cryptographic algorithms.
#define HASH_DRBG_MAX_SEED_LEN
void hashDrbgDeinit(HashDrbgContext *context)
Release PRNG context.
size_t seedLen
Seed length.
size_t securityStrength
Security strength.
error_t hashDrbgInit(HashDrbgContext *context, const HashAlgo *hashAlgo)
Initialize PRNG context.
void hashGen(HashDrbgContext *context, uint8_t *output, size_t outputLen)
Hash generation sub function.
void(* PrngAlgoDeinit)(void *context)
error_t hashDrbgGenerate(HashDrbgContext *context, uint8_t *output, size_t length)
Generate pseudorandom data.
error_t hashDrbgSeedEx(HashDrbgContext *context, const uint8_t *entropyInput, size_t entropyInputLen, const uint8_t *nonce, size_t nonceLen, const uint8_t *personalizationString, size_t personalizationStringLen)
Seed the PRNG state (with nonce and personalization string)
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
uint8_t v[HASH_DRBG_MAX_SEED_LEN]
Value V.
#define HASH_DRBG_MAX_RESEED_INTERVAL
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
error_t(* PrngAlgoGenerate)(void *context, uint8_t *output, size_t length)
void hashDrbgInc(uint8_t *a, size_t aLen)
Increment block.
Common interface for hash algorithms.
#define osMemset(p, value, length)
error_t(* PrngAlgoInit)(void *context)
error_t hashDrbgReseed(HashDrbgContext *context, const uint8_t *seed, size_t length)
Reseed the PRNG state.