TrustCore SDK NanoCrypto API reference  version 7.0
nist_drbg_hash.h
Go to the documentation of this file.
1 /*
2  * nist_drbg_hash.h
3  *
4  * Implementation of the RNGs described in NIST 800-90
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
10 
24 /*------------------------------------------------------------------*/
25 
26 #ifndef __NIST_DRBG_HASH_HEADER__
27 #define __NIST_DRBG_HASH_HEADER__
28 
29 #include "../common/moptions.h"
30 #include "../common/mtypes.h"
31 #include "../common/mdefs.h"
32 #include "../common/merrors.h"
33 #include "../crypto/hw_accel.h"
34 #include "../common/mrtos.h"
35 
36 /* Value from NIST SP800-90A 10.1 Table 2 */
37 #define MOCANA_HASH_DRBG_MAX_SEED_LEN_BITS 888
38 #define MOCANA_HASH_DRBG_MAX_SEED_LEN_BYTES (MOCANA_HASH_DRBG_MAX_SEED_LEN_BITS/8)
39 
40 #include "../cap/capdecl.h"
41 
42 #if defined(__ENABLE_MOCANA_CRYPTO_INTERFACE__)
43 #include "../crypto_interface/crypto_interface_nist_drbg_hash_priv.h"
44 #endif
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
68 typedef MSTATUS (*DrbgHashMethod)(ubyte *pInput, ubyte4 inputLen, ubyte *pOutput);
69 
70 typedef struct NIST_HASH_DRBG_Ctx
71 {
72  DrbgHashMethod hashMethod;
73  RTOS_MUTEX pMutex;
74  ubyte4 hashOutLen;
75  ubyte4 seedLenBytes;
76  ubyte4 securityStrengthBytes;
77  ubyte pV[MOCANA_HASH_DRBG_MAX_SEED_LEN_BYTES + 1];
78  ubyte pC[MOCANA_HASH_DRBG_MAX_SEED_LEN_BYTES + 1];
79  ubyte pReseedCtr[8];
80  MocSymCtx pMocSymCtx;
81  ubyte enabled;
82 
83 } NIST_HASH_DRBG_Ctx;
84 
85 /*------------------------------------------------------------------*/
86 
112 MOC_EXTERN MSTATUS NIST_HASHDRBG_newSeededContext(MOC_SYM(hwAccelDescr hwAccelCtx)
113  NIST_HASH_DRBG_Ctx **ppNewContext,
114  ubyte *pEntropyInput,
115  ubyte4 entropyInputLen,
116  ubyte *pNonce,
117  ubyte4 nonceLen,
118  ubyte *pPersonalization,
119  ubyte4 personalizationLen,
120  DrbgHashMethod hashMethod,
121  ubyte4 hashOutLenBytes);
122 
138 MOC_EXTERN MSTATUS NIST_HASHDRBG_deleteContext( MOC_SYM(hwAccelDescr hwAccelCtx)
139  NIST_HASH_DRBG_Ctx **ppContext);
140 
160 MOC_EXTERN MSTATUS NIST_HASHDRBG_reSeed(MOC_SYM(hwAccelDescr hwAccelCtx)
161  NIST_HASH_DRBG_Ctx *pContext,
162  ubyte *pEntropyInput,
163  ubyte4 entropyInputLen,
164  ubyte *pAdditionalInput,
165  ubyte4 additionalInputLen);
166 
189 MOC_EXTERN MSTATUS NIST_HASHDRBG_generate(MOC_SYM(hwAccelDescr hwAccelCtx)
190  NIST_HASH_DRBG_Ctx *pContext,
191  ubyte *pAdditionalInput,
192  ubyte4 additionalInputLen,
193  ubyte *pOutput,
194  ubyte4 outputLenBytes);
195 
216 MOC_EXTERN MSTATUS NIST_HASHDRBG_numberGenerator(MOC_SYM(hwAccelDescr hwAccelCtx)
217  NIST_HASH_DRBG_Ctx *pRandomContext,
218  ubyte *pBuffer,
219  sbyte4 bufferLen);
220 
240 MOC_EXTERN sbyte4 NIST_HASHDRBG_rngFun(MOC_SYM(hwAccelDescr hwAccelCtx)
241  void *pRngFunArg,
242  ubyte4 length, ubyte *pBuffer);
243 
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #endif /* __NIST_DRBG_HASH_HEADER__ */
250 
MOC_EXTERN MSTATUS NIST_HASHDRBG_deleteContext(MOC_SYM(hwAccelDescr hwAccelCtx) NIST_HASH_DRBG_Ctx **ppContext)
Deletes a hash drbg context.
MOC_EXTERN MSTATUS NIST_HASHDRBG_reSeed(MOC_SYM(hwAccelDescr hwAccelCtx) NIST_HASH_DRBG_Ctx *pContext, ubyte *pEntropyInput, ubyte4 entropyInputLen, ubyte *pAdditionalInput, ubyte4 additionalInputLen)
Reseeds a previously existing hash drbg context.
MSTATUS(* DrbgHashMethod)(ubyte *pInput, ubyte4 inputLen, ubyte *pOutput)
Function pointer type for a method that hashes input data in one shot.
Definition: nist_drbg_hash.h:68
MOC_EXTERN MSTATUS NIST_HASHDRBG_numberGenerator(MOC_SYM(hwAccelDescr hwAccelCtx) NIST_HASH_DRBG_Ctx *pRandomContext, ubyte *pBuffer, sbyte4 bufferLen)
Generates deterministic bits from a seeded drbg hash context.
MOC_EXTERN MSTATUS NIST_HASHDRBG_newSeededContext(MOC_SYM(hwAccelDescr hwAccelCtx) NIST_HASH_DRBG_Ctx **ppNewContext, ubyte *pEntropyInput, ubyte4 entropyInputLen, ubyte *pNonce, ubyte4 nonceLen, ubyte *pPersonalization, ubyte4 personalizationLen, DrbgHashMethod hashMethod, ubyte4 hashOutLenBytes)
Allocates and seeds a new hash drbg context.
MOC_EXTERN sbyte4 NIST_HASHDRBG_rngFun(MOC_SYM(hwAccelDescr hwAccelCtx) void *pRngFunArg, ubyte4 length, ubyte *pBuffer)
Generates deterministic bits in an RNGFun function pointer form.
MOC_EXTERN MSTATUS NIST_HASHDRBG_generate(MOC_SYM(hwAccelDescr hwAccelCtx) NIST_HASH_DRBG_Ctx *pContext, ubyte *pAdditionalInput, ubyte4 additionalInputLen, ubyte *pOutput, ubyte4 outputLenBytes)
Generates deterministic bits from a seeded drbg hash context with an additional data input option...