xdrbg.c File Reference

XDRBG pseudorandom number generator. More...

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

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t xdrbgInit (XdrbgContext *context, const XofAlgo *xofAlgo)
 Initialize PRNG context. More...
 
error_t xdrbgSeed (XdrbgContext *context, const uint8_t *seed, size_t length)
 Seed the PRNG state. More...
 
error_t xdrbgSeedEx (XdrbgContext *context, const uint8_t *seed, size_t seedLen, const uint8_t *alpha, size_t alphaLen)
 Seed the PRNG state (with nonce and personalization string) More...
 
error_t xdrbgReseed (XdrbgContext *context, const uint8_t *seed, size_t length)
 Reseed the PRNG state. More...
 
error_t xdrbgReseedEx (XdrbgContext *context, const uint8_t *seed, size_t seedLen, const uint8_t *alpha, size_t alphaLen)
 Reseed the PRNG state (with additional input) More...
 
error_t xdrbgGenerate (XdrbgContext *context, uint8_t *output, size_t length)
 Generate pseudorandom data. More...
 
error_t xdrbgGenerateEx (XdrbgContext *context, const uint8_t *alpha, size_t alphaLen, uint8_t *output, size_t outputLen)
 Generate pseudorandom data (with additional input) More...
 
void xdrbgDeinit (XdrbgContext *context)
 Release PRNG context. More...
 

Variables

const PrngAlgo xdrbgPrngAlgo
 

Detailed Description

XDRBG 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 xdrbg.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file xdrbg.c.

Function Documentation

◆ xdrbgDeinit()

void xdrbgDeinit ( XdrbgContext context)

Release PRNG context.

Parameters
[in]contextPointer to the XDRBG context

Definition at line 393 of file xdrbg.c.

◆ xdrbgGenerate()

error_t xdrbgGenerate ( XdrbgContext context,
uint8_t *  output,
size_t  length 
)

Generate pseudorandom data.

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

Definition at line 299 of file xdrbg.c.

◆ xdrbgGenerateEx()

error_t xdrbgGenerateEx ( XdrbgContext context,
const uint8_t *  alpha,
size_t  alphaLen,
uint8_t *  output,
size_t  outputLen 
)

Generate pseudorandom data (with additional input)

Parameters
[in]contextPointer to the XDRBG context
[in]alphaOptional data
[in]alphaLenLength of the additional data, in bytes
[out]outputBuffer where to store the pseudorandom bytes
[in]outputLenRequested number of bytes
Returns
Error code

Definition at line 316 of file xdrbg.c.

◆ xdrbgInit()

error_t xdrbgInit ( XdrbgContext context,
const XofAlgo xofAlgo 
)

Initialize PRNG context.

Parameters
[in]contextPointer to the XDRBG context to initialize
[in]xofAlgoXOF algorithm
Returns
Error code

Definition at line 62 of file xdrbg.c.

◆ xdrbgReseed()

error_t xdrbgReseed ( XdrbgContext context,
const uint8_t *  seed,
size_t  length 
)

Reseed the PRNG state.

Parameters
[in]contextPointer to the XDRBG context
[in]seedSeed material
[in]seedLenLength of the seed material, in bytes
Returns
Error code

Definition at line 212 of file xdrbg.c.

◆ xdrbgReseedEx()

error_t xdrbgReseedEx ( XdrbgContext context,
const uint8_t *  seed,
size_t  seedLen,
const uint8_t *  alpha,
size_t  alphaLen 
)

Reseed the PRNG state (with additional input)

Parameters
[in]contextPointer to the XDRBG context
[in]seedSeed material
[in]seedLenLength of the seed material, in bytes
[in]alphaOptional data
[in]alphaLenLength of the additional data, in bytes
Returns
Error code

Definition at line 229 of file xdrbg.c.

◆ xdrbgSeed()

error_t xdrbgSeed ( XdrbgContext context,
const uint8_t *  seed,
size_t  length 
)

Seed the PRNG state.

Parameters
[in]contextPointer to the XDRBG context
[in]seedSeed material
[in]seedLenLength of the seed material, in bytes
Returns
Error code

Definition at line 130 of file xdrbg.c.

◆ xdrbgSeedEx()

error_t xdrbgSeedEx ( XdrbgContext context,
const uint8_t *  seed,
size_t  seedLen,
const uint8_t *  alpha,
size_t  alphaLen 
)

Seed the PRNG state (with nonce and personalization string)

Parameters
[in]contextPointer to the XDRBG context
[in]seedSeed material
[in]seedLenLength of the seed material, in bytes
[in]alphaOptional data
[in]alphaLenLength of the additional data, in bytes
Returns
Error code

Definition at line 147 of file xdrbg.c.

Variable Documentation

◆ xdrbgPrngAlgo

const PrngAlgo xdrbgPrngAlgo
Initial value:

Definition at line 43 of file xdrbg.c.

void xdrbgDeinit(XdrbgContext *context)
Release PRNG context.
Definition: xdrbg.c:393
error_t xdrbgSeed(XdrbgContext *context, const uint8_t *seed, size_t length)
Seed the PRNG state.
Definition: xdrbg.c:130
XDRBG PRNG context.
Definition: xdrbg.h:60
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
error_t xdrbgGenerate(XdrbgContext *context, uint8_t *output, size_t length)
Generate pseudorandom data.
Definition: xdrbg.c:299
error_t xdrbgReseed(XdrbgContext *context, const uint8_t *seed, size_t length)
Reseed the PRNG state.
Definition: xdrbg.c:212
void(* PrngAlgoDeinit)(void *context)
Definition: crypto.h:1116
error_t(* PrngAlgoGenerate)(void *context, uint8_t *output, size_t length)
Definition: crypto.h:1113
error_t(* PrngAlgoInit)(void *context)
Definition: crypto.h:1105