TrustCore SDK NanoCrypto API reference  version 7.0
nist_rng.h File Reference

Implementation of the RNGs described in NIST 800-90A nist_rng.h. More...

Go to the source code of this file.

Functions

MOC_EXTERN MSTATUS NIST_CTRDRBG_deleteContext (MOC_SYM(hwAccelDescr hwAccelCtx) randomContext **ppNewContext)
 Clear and free a previously instantiated CTRDRBG context. More...
 
MOC_EXTERN MSTATUS NIST_CTRDRBG_generate (MOC_SYM(hwAccelDescr hwAccelCtx) randomContext *pContext, const ubyte *additionalInput, ubyte4 additionalInputLen, ubyte *output, ubyte4 outputLenBits)
 Generate random data with optional additional input. More...
 
MOC_EXTERN MSTATUS NIST_CTRDRBG_newContext (MOC_SYM(hwAccelDescr hwAccelCtx) randomContext **ppNewContext, const ubyte *entropyInput, ubyte4 keyLenBytes, ubyte4 outLenBytes, const ubyte *personalization, ubyte4 personalizationLen)
 Allocate and initialize a new CTRDRBG context that is not using a derivation function. More...
 
MOC_EXTERN MSTATUS NIST_CTRDRBG_newDFContext (MOC_SYM(hwAccelDescr hwAccelCtx) randomContext **ppNewContext, ubyte4 keyLenBytes, ubyte4 outLenBytes, const ubyte *entropyInput, ubyte4 entropyInputLen, const ubyte *nonce, ubyte4 nonceLen, const ubyte *personalization, ubyte4 personalizationLen)
 Allocate and initialize a new CTRDRBG context that is using a derivation function. More...
 
MOC_EXTERN MSTATUS NIST_CTRDRBG_numberGenerator (MOC_SYM(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, ubyte *pBuffer, sbyte4 bufSize)
 Generate random data. More...
 
MOC_EXTERN MSTATUS NIST_CTRDRBG_reseed (MOC_SYM(hwAccelDescr hwAccelCtx) randomContext *pContext, const ubyte *entropyInput, ubyte4 entropyInputLen, const ubyte *additionalInput, ubyte4 additionalInputLen)
 Reseed a previously instantiated CTRDRBG context. More...
 
MOC_EXTERN sbyte4 NIST_CTRDRBG_rngFun (MOC_SYM(hwAccelDescr hwAccelCtx) void *rngFunArg, ubyte4 length, ubyte *buffer)
 Callback function to generate random data. More...
 
MOC_EXTERN void resetDRBGFail (void)
 
MOC_EXTERN void triggerDRBGFail (void)
 

Detailed Description

Copyright 2019-2024 DigiCert, Inc. All Rights Reserved. Proprietary and Confidential Material.

Function Documentation

◆ NIST_CTRDRBG_deleteContext()

MOC_EXTERN MSTATUS NIST_CTRDRBG_deleteContext ( MOC_SYM(hwAccelDescr hwAccelCtx) randomContext **  ppNewContext)
Parameters
ppNewContextPointer to the context to be freed.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

◆ NIST_CTRDRBG_generate()

MOC_EXTERN MSTATUS NIST_CTRDRBG_generate ( MOC_SYM(hwAccelDescr hwAccelCtx) randomContext *  pContext,
const ubyte *  additionalInput,
ubyte4  additionalInputLen,
ubyte *  output,
ubyte4  outputLenBits 
)
Parameters
pContextContext to use to generate the random data.
additionalInputOptional additional input to use for the reseed.
additionalInputLenLength in bytes of the additional input.
outputPointer to the caller allocated output buffer.
outputLenBitsLength in bits of random data to generate.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

◆ NIST_CTRDRBG_newContext()

MOC_EXTERN MSTATUS NIST_CTRDRBG_newContext ( MOC_SYM(hwAccelDescr hwAccelCtx) randomContext **  ppNewContext,
const ubyte *  entropyInput,
ubyte4  keyLenBytes,
ubyte4  outLenBytes,
const ubyte *  personalization,
ubyte4  personalizationLen 
)

This function implements the CTR_DRBG_Instantiate_algorithm described in NIST SP 800-90A Rev1 10.2.1.3.1

Parameters
ppNewContextPointer to the address that will recieve the newly allocated context.
entropyInputEntropy to seed this DRBG with. Must be equal to the block length + key length.
keyLenBytesLength in bytes of the key material to use, sets the security strength of the DRBG. For example 16 for AES-128 and 32 for AES-256.
outLenBytesBlock length of the underlying block cipher to be used for this CTRDRBG instantiation. Must be 8 to use triple DES or 16 to use AES.
personalizationOptional personalization string.
personalizationLenLength in bytes of the personalization string.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

◆ NIST_CTRDRBG_newDFContext()

MOC_EXTERN MSTATUS NIST_CTRDRBG_newDFContext ( MOC_SYM(hwAccelDescr hwAccelCtx) randomContext **  ppNewContext,
ubyte4  keyLenBytes,
ubyte4  outLenBytes,
const ubyte *  entropyInput,
ubyte4  entropyInputLen,
const ubyte *  nonce,
ubyte4  nonceLen,
const ubyte *  personalization,
ubyte4  personalizationLen 
)

This function implements the CTR_DRBG_Instantiate_algorithm described in NIST SP 800-90A Rev1 10.2.1.3.2

Parameters
ppNewContextPointer to the address that will recieve the newly allocated context.
keyLenBytesLength in bytes of the key material to use, sets the security strength of the DRBG. For example 16 for AES-128 and 32 for AES-256.
outLenBytesBlock length of the underlying block cipher to be used for this CTRDRBG instantiation. Must be 8 to use triple DES or 16 to use AES.
entropyInputEntropy to seed this DRBG with.
entropyInputLenLength in bytes of the entropy material. Must be sufficient to support the given key length, see NIST SP 800-90A Rev1 10.2.1 Table 3 for more info.
nonceOptional nonce.
nonceLenLength in bytes of the nonce.
personalizationOptional personalization string.
personalizationLenLength in bytes of the personalization string.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

◆ NIST_CTRDRBG_numberGenerator()

MOC_EXTERN MSTATUS NIST_CTRDRBG_numberGenerator ( MOC_SYM(hwAccelDescr hwAccelCtx) randomContext *  pRandomContext,
ubyte *  pBuffer,
sbyte4  bufSize 
)
Parameters
pContextContext to use to generate the random data.
pBufferPointer to the caller allocated output buffer.
bufSizeLength in bytes of random data to generate.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

◆ NIST_CTRDRBG_reseed()

MOC_EXTERN MSTATUS NIST_CTRDRBG_reseed ( MOC_SYM(hwAccelDescr hwAccelCtx) randomContext *  pContext,
const ubyte *  entropyInput,
ubyte4  entropyInputLen,
const ubyte *  additionalInput,
ubyte4  additionalInputLen 
)
Parameters
pContextContext to be reseeded.
entropyInputEntropy input to use for this reseed.
entropyInputLenLength in bytes of the input entropy material. See NIST SP 800-90A Rev1 10.2.1 Table 3 for more info.
additionalInputOptional additional input to use for the reseed.
additionalInputLenLength in bytes of the additional input.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

◆ NIST_CTRDRBG_rngFun()

MOC_EXTERN sbyte4 NIST_CTRDRBG_rngFun ( MOC_SYM(hwAccelDescr hwAccelCtx) void *  rngFunArg,
ubyte4  length,
ubyte *  buffer 
)

There are many functions that take in a RNG callback to get random data, this function is a wrapper to fit the callback signature.

Parameters
rngFunArgArgument to the callback, in practice it is typically a CTRDRBG context.
lengthLength in bytes of random data to generate.
bufferPointer to the caller allocated output buffer.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.