hash_drbg.c File Reference

Hash_DRBG pseudorandom number generator. More...

#include "core/crypto.h"
#include "rng/hash_drbg.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t hashDrbgInit (HashDrbgContext *context, const HashAlgo *hashAlgo)
 Initialize PRNG context. More...
 
error_t hashDrbgSeed (HashDrbgContext *context, const uint8_t *seed, size_t length)
 Seed the PRNG state. More...
 
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) More...
 
error_t hashDrbgReseed (HashDrbgContext *context, const uint8_t *seed, size_t length)
 Reseed the PRNG state. More...
 
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) More...
 
error_t hashDrbgGenerate (HashDrbgContext *context, uint8_t *output, size_t length)
 Generate pseudorandom data. More...
 
error_t hashDrbgGenerateEx (HashDrbgContext *context, const uint8_t *additionalInput, size_t additionalInputLen, uint8_t *output, size_t outputLen)
 Generate pseudorandom data (with additional input) More...
 
void hashDrbgDeinit (HashDrbgContext *context)
 Release PRNG context. More...
 
void hashDf (HashDrbgContext *context, const DataChunk *input, uint_t inputLen, uint8_t *output, size_t outputLen)
 Hash derivation function. More...
 
void hashGen (HashDrbgContext *context, uint8_t *output, size_t outputLen)
 Hash generation sub function. More...
 
void hashDrbgAdd (uint8_t *a, size_t aLen, const uint8_t *b, size_t bLen)
 Add blocks. More...
 
void hashDrbgInc (uint8_t *a, size_t aLen)
 Increment block. More...
 

Variables

const PrngAlgo hashDrbgPrngAlgo
 

Detailed Description

Hash_DRBG pseudorandom number generator.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.5.4

Definition in file hash_drbg.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file hash_drbg.c.

Function Documentation

◆ hashDf()

void hashDf ( HashDrbgContext context,
const DataChunk input,
uint_t  inputLen,
uint8_t *  output,
size_t  outputLen 
)

Hash derivation function.

Parameters
[in]contextPointer to the Hash_DRBG context
[in]inputThe string to be hashed
[in]inputLenNumber of data chunks representing the input
[out]outputBuffer where to store the output value
[out]outputLenThe number of bytes to be returned

Definition at line 463 of file hash_drbg.c.

◆ hashDrbgAdd()

void hashDrbgAdd ( uint8_t *  a,
size_t  aLen,
const uint8_t *  b,
size_t  bLen 
)

Add blocks.

Parameters
[in,out]aPointer to the first block
[in]aLenLength of the first block, in bytes
[in]bPointer to the second block
[in]bLenLength of the second block, in bytes

Definition at line 565 of file hash_drbg.c.

◆ hashDrbgDeinit()

void hashDrbgDeinit ( HashDrbgContext context)

Release PRNG context.

Parameters
[in]contextPointer to the Hash_DRBG context

Definition at line 440 of file hash_drbg.c.

◆ hashDrbgGenerate()

error_t hashDrbgGenerate ( HashDrbgContext context,
uint8_t *  output,
size_t  length 
)

Generate pseudorandom data.

Parameters
[in]contextPointer to the Hash_DRBG context
[out]outputBuffer where to store the pseudorandom bytes
[in]lengthRequested number of bytes
Returns
Error code

Definition at line 327 of file hash_drbg.c.

◆ hashDrbgGenerateEx()

error_t hashDrbgGenerateEx ( HashDrbgContext context,
const uint8_t *  additionalInput,
size_t  additionalInputLen,
uint8_t *  output,
size_t  outputLen 
)

Generate pseudorandom data (with additional input)

Parameters
[in]contextPointer to the Hash_DRBG context
[in]additionalInputAdditional input string received from the consuming application
[in]additionalInputLenLength of the additional input string, in bytes
[out]outputBuffer where to store the pseudorandom bytes
[in]outputLenRequested number of bytes
Returns
Error code

Definition at line 346 of file hash_drbg.c.

◆ hashDrbgInc()

void hashDrbgInc ( uint8_t *  a,
size_t  aLen 
)

Increment block.

Parameters
[in]aPointer to the block to be incremented
[in]aLenLength of the block, in bytes

Definition at line 588 of file hash_drbg.c.

◆ hashDrbgInit()

error_t hashDrbgInit ( HashDrbgContext context,
const HashAlgo hashAlgo 
)

Initialize PRNG context.

Parameters
[in]contextPointer to the Hash_DRBG context to initialize
[in]hashAlgoApproved hash function
Returns
Error code

Definition at line 62 of file hash_drbg.c.

◆ hashDrbgReseed()

error_t hashDrbgReseed ( HashDrbgContext context,
const uint8_t *  seed,
size_t  length 
)

Reseed the PRNG state.

Parameters
[in]contextPointer to the Hash_DRBG context
[in]seedString of bits obtained from the randomness source
[in]lengthLength of the string, in bytes
Returns
Error code

Definition at line 225 of file hash_drbg.c.

◆ hashDrbgReseedEx()

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)

Parameters
[in]contextPointer to the Hash_DRBG context
[in]entropyInputString of bits obtained from the randomness source
[in]entropyInputLenLength of the string, in bytes
[in]additionalInputAdditional input string received from the consuming application
[in]additionalInputLenLength of the additional input string, in bytes
Returns
Error code

Definition at line 244 of file hash_drbg.c.

◆ hashDrbgSeed()

error_t hashDrbgSeed ( HashDrbgContext context,
const uint8_t *  seed,
size_t  length 
)

Seed the PRNG state.

Parameters
[in]contextPointer to the Hash_DRBG context
[in]seedString of bits obtained from the randomness source
[in]lengthLength of the string, in bytes
Returns
Error code

Definition at line 120 of file hash_drbg.c.

◆ hashDrbgSeedEx()

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)

Parameters
[in]contextPointer to the Hash_DRBG context
[in]entropyInputString of bits obtained from the randomness source
[in]entropyInputLenLength of the string, in bytes
[in]nonceNonce
[in]nonceLenLength of the nonce, in bytes
[in]personalizationStringPersonalization string received from the consuming application
[in]personalizationStringLenLength of the personalization string, in bytes
Returns
Error code

Definition at line 142 of file hash_drbg.c.

◆ hashGen()

void hashGen ( HashDrbgContext context,
uint8_t *  output,
size_t  outputLen 
)

Hash generation sub function.

Parameters
[in]contextPointer to the Hash_DRBG context
[out]outputBuffer where to store the output value
[out]outputLenThe number of bytes to be returned

Definition at line 517 of file hash_drbg.c.

Variable Documentation

◆ hashDrbgPrngAlgo

const PrngAlgo hashDrbgPrngAlgo
Initial value:

Definition at line 43 of file hash_drbg.c.

error_t hashDrbgSeed(HashDrbgContext *context, const uint8_t *seed, size_t length)
Seed the PRNG state.
Definition: hash_drbg.c:120
error_t(* PrngAlgoSeed)(void *context, const uint8_t *seed, size_t length)
Definition: crypto.h:1107
error_t(* PrngAlgoReseed)(void *context, const uint8_t *seed, size_t length)
Definition: crypto.h:1110
void hashDrbgDeinit(HashDrbgContext *context)
Release PRNG context.
Definition: hash_drbg.c:440
void(* PrngAlgoDeinit)(void *context)
Definition: crypto.h:1116
error_t hashDrbgGenerate(HashDrbgContext *context, uint8_t *output, size_t length)
Generate pseudorandom data.
Definition: hash_drbg.c:327
error_t(* PrngAlgoGenerate)(void *context, uint8_t *output, size_t length)
Definition: crypto.h:1113
Hash_DRBG PRNG context.
Definition: hash_drbg.h:57
error_t(* PrngAlgoInit)(void *context)
Definition: crypto.h:1105
error_t hashDrbgReseed(HashDrbgContext *context, const uint8_t *seed, size_t length)
Reseed the PRNG state.
Definition: hash_drbg.c:225