ctr_drbg.h File Reference

CTR_DRBG pseudorandom number generator. More...

Go to the source code of this file.

Data Structures

struct  CtrDrbgContext
 CTR_DRBG PRNG context. More...
 

Macros

#define CTR_DRBG_MAX_KEY_LEN   32
 
#define CTR_DRBG_MAX_SEED_LEN   48
 
#define CTR_DRBG_MAX_RESEED_INTERVAL   281474976710656ULL
 
#define CTR_DRBG_PRNG_ALGO   (&ctrDrbgPrngAlgo)
 

Functions

error_t ctrDrbgInit (CtrDrbgContext *context, const CipherAlgo *cipherAlgo, size_t keyLen, bool_t df)
 Initialize PRNG context. More...
 
error_t ctrDrbgSeed (CtrDrbgContext *context, const uint8_t *seed, size_t length)
 Seed the PRNG state. More...
 
error_t ctrDrbgSeedEx (CtrDrbgContext *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 ctrDrbgReseed (CtrDrbgContext *context, const uint8_t *seed, size_t length)
 Reseed the PRNG state. More...
 
error_t ctrDrbgReseedEx (CtrDrbgContext *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 ctrDrbgGenerate (CtrDrbgContext *context, uint8_t *output, size_t length)
 Generate pseudorandom data. More...
 
error_t ctrDrbgGenerateEx (CtrDrbgContext *context, const uint8_t *additionalInput, size_t additionalInputLen, uint8_t *output, size_t outputLen)
 Generate pseudorandom data (with additional input) More...
 
void ctrDrbgDeinit (CtrDrbgContext *context)
 Release PRNG context. More...
 
error_t blockCipherDf (CtrDrbgContext *context, const DataChunk *input, uint_t inputLen, uint8_t *output, size_t outputLen)
 Block cipher derivation function. More...
 
error_t ctrDrbgBcc (CtrDrbgContext *context, const uint8_t *key, const DataChunk *data, uint_t dataLen, uint8_t *output)
 BCC function. More...
 
error_t ctrDrbgUpdate (CtrDrbgContext *context, const uint8_t *providedData, size_t providedDataLen)
 Update internal state. More...
 
error_t ctrDrbgLoadKey (CtrDrbgContext *context, const uint8_t *key)
 Load encryption key. More...
 
void ctrDrbgIncBlock (uint8_t *ctr, size_t blockLen, size_t ctrLen)
 Increment counter block. More...
 
void ctrDrbgXorBlock (uint8_t *x, const uint8_t *a, const uint8_t *b, size_t n)
 XOR operation. More...
 

Variables

const PrngAlgo ctrDrbgPrngAlgo
 

Detailed Description

CTR_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 ctr_drbg.h.

Macro Definition Documentation

◆ CTR_DRBG_MAX_KEY_LEN

#define CTR_DRBG_MAX_KEY_LEN   32

Definition at line 39 of file ctr_drbg.h.

◆ CTR_DRBG_MAX_RESEED_INTERVAL

#define CTR_DRBG_MAX_RESEED_INTERVAL   281474976710656ULL

Definition at line 43 of file ctr_drbg.h.

◆ CTR_DRBG_MAX_SEED_LEN

#define CTR_DRBG_MAX_SEED_LEN   48

Definition at line 41 of file ctr_drbg.h.

◆ CTR_DRBG_PRNG_ALGO

#define CTR_DRBG_PRNG_ALGO   (&ctrDrbgPrngAlgo)

Definition at line 46 of file ctr_drbg.h.

Function Documentation

◆ blockCipherDf()

error_t blockCipherDf ( CtrDrbgContext context,
const DataChunk input,
uint_t  inputLen,
uint8_t *  output,
size_t  outputLen 
)

Block cipher derivation function.

Parameters
[in]contextPointer to the CTR_DRBG context
[in]inputThe string to be operated on
[in]inputLenNumber of data chunks representing the input
[out]outputBuffer where to store the output value
[out]outputLenThe number of bytes to be returned
Returns
Error code

Definition at line 594 of file ctr_drbg.c.

◆ ctrDrbgBcc()

error_t ctrDrbgBcc ( CtrDrbgContext context,
const uint8_t *  key,
const DataChunk data,
uint_t  dataLen,
uint8_t *  output 
)

BCC function.

Parameters
[in]contextPointer to the CTR_DRBG context
[in]keyThe key to be used for the block cipher operation
[in]dataThe data to be operated on
[in]dataLenNumber of data chunks representing the data
[out]outputThe result to be returned from the BCC operation
Returns
Error code

Definition at line 754 of file ctr_drbg.c.

◆ ctrDrbgDeinit()

void ctrDrbgDeinit ( CtrDrbgContext context)

Release PRNG context.

Parameters
[in]contextPointer to the CTR_DRBG context

Definition at line 570 of file ctr_drbg.c.

◆ ctrDrbgGenerate()

error_t ctrDrbgGenerate ( CtrDrbgContext context,
uint8_t *  output,
size_t  length 
)

Generate pseudorandom data.

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

Definition at line 404 of file ctr_drbg.c.

◆ ctrDrbgGenerateEx()

error_t ctrDrbgGenerateEx ( CtrDrbgContext 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 CTR_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 423 of file ctr_drbg.c.

◆ ctrDrbgIncBlock()

void ctrDrbgIncBlock ( uint8_t *  ctr,
size_t  blockLen,
size_t  ctrLen 
)

Increment counter block.

Parameters
[in,out]ctrPointer to the counter block
[in]blockLenLength of the block, in bytes
[in]ctrLenSize of the specific part of the block to be incremented

Definition at line 946 of file ctr_drbg.c.

◆ ctrDrbgInit()

error_t ctrDrbgInit ( CtrDrbgContext context,
const CipherAlgo cipherAlgo,
size_t  keyLen,
bool_t  df 
)

Initialize PRNG context.

Parameters
[in]contextPointer to the CTR_DRBG context to initialize
[in]cipherAlgoApproved block cipher algorithm
[in]keyLenKey length, in bits
[in]dfUse key derivation function
Returns
Error code

Definition at line 67 of file ctr_drbg.c.

◆ ctrDrbgLoadKey()

error_t ctrDrbgLoadKey ( CtrDrbgContext context,
const uint8_t *  key 
)

Load encryption key.

Parameters
[in]contextPointer to the CTR_DRBG context
[in]keyPointer to the Encryption key to load
Returns
Error code

Definition at line 905 of file ctr_drbg.c.

◆ ctrDrbgReseed()

error_t ctrDrbgReseed ( CtrDrbgContext context,
const uint8_t *  seed,
size_t  length 
)

Reseed the PRNG state.

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

Definition at line 279 of file ctr_drbg.c.

◆ ctrDrbgReseedEx()

error_t ctrDrbgReseedEx ( CtrDrbgContext 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 CTR_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 298 of file ctr_drbg.c.

◆ ctrDrbgSeed()

error_t ctrDrbgSeed ( CtrDrbgContext context,
const uint8_t *  seed,
size_t  length 
)

Seed the PRNG state.

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

Definition at line 138 of file ctr_drbg.c.

◆ ctrDrbgSeedEx()

error_t ctrDrbgSeedEx ( CtrDrbgContext 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 CTR_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 160 of file ctr_drbg.c.

◆ ctrDrbgUpdate()

error_t ctrDrbgUpdate ( CtrDrbgContext context,
const uint8_t *  providedData,
size_t  providedDataLen 
)

Update internal state.

Parameters
[in]contextPointer to the CTR_DRBG context
[in]providedDataThe data to be used
[in]providedDataLenLength of the data, in bytes
Returns
Error code

Definition at line 839 of file ctr_drbg.c.

◆ ctrDrbgXorBlock()

void ctrDrbgXorBlock ( uint8_t *  x,
const uint8_t *  a,
const uint8_t *  b,
size_t  n 
)

XOR operation.

Parameters
[out]xBlock resulting from the XOR operation
[in]aFirst input block
[in]bSecond input block
[in]nLength of the block, in bytes

Definition at line 971 of file ctr_drbg.c.

Variable Documentation

◆ ctrDrbgPrngAlgo

const PrngAlgo ctrDrbgPrngAlgo
extern

Definition at line 46 of file ctr_drbg.c.