TrustCore SDK NanoCrypto API reference  version 7.0
random.h
Go to the documentation of this file.
1 /*
2  * random.h
3  *
4  * Random Number FIPS-186 Factory
5  *
6  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
7  * Proprietary and Confidential Material.
8  *
9  */
10 
27 /*------------------------------------------------------------------*/
28 
29 #ifndef __RANDOM_HEADER__
30 #define __RANDOM_HEADER__
31 
32 #include "../crypto/hw_accel.h"
33 
34 #ifdef __ENABLE_MOCANA_CRYPTO_INTERFACE_RANDOM__
35 #include "../crypto_interface/crypto_interface_random_priv.h"
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #define RANDOM_CONTEXT(X) (X)->pRandomContext
43 
44 #ifdef MOC_EXTERN_RANDOM_H
45 #undef MOC_EXTERN_RANDOM_H
46 #endif /* MOC_EXTERN_RANDOM_H */
47 
48 #ifdef __RTOS_WIN32__
49 
50 #ifdef WIN_EXPORT_RANDOM_H
51 #define MOC_EXTERN_RANDOM_H __declspec(dllexport)
52 #else
53 #define MOC_EXTERN_RANDOM_H __declspec(dllimport) extern
54 #endif /* WIN_EXPORT_RANDOM_H */
55 
56 #ifdef WIN_STATIC
57 #undef MOC_EXTERN_RANDOM_H
58 #define MOC_EXTERN_RANDOM_H extern
59 #endif /* WIN_STATIC */
60 
61 #else
62 
63 #define MOC_EXTERN_RANDOM_H MOC_EXTERN
64 
65 #endif /* RTOS_WIN32 */
66 
67 #ifdef MOC_EXTERN_P
68 #undef MOC_EXTERN_P
69 #endif /* MOC_EXTERN_P */
70 
71 #define MOC_EXTERN_P MOC_EXTERN_RANDOM_H
72 
73 /*------------------------------------------------------------------*/
74 
80 typedef void randomContext;
81 
98 typedef sbyte4 (*RNGFun)(void* rngFunArg, ubyte4 length, ubyte *buffer);
99 MOC_EXTERN_RANDOM_H randomContext* g_pRandomContext;
100 
101 typedef enum {
102  NIST_FIPS186 = 0,
103  NIST_CTR_DRBG = 2,
104  MOC_RAND = 3
105 } randomContextType;
106 
107 typedef struct MocRandCtx
108 {
109  void *pMocSymObj;
110 } MocRandCtx;
111 
112 /* The storage within the RandomCtxWrapper is the logical union of a
113  * NIST CTR DRBG context, a FIPS186 context, and a Digicert random object.
114  * The NIST CTR DRBG context is the largest of those structures with a
115  * maximum size of 900 bytes with the crypto interface and 840 bytes otherwise.
116  * If that structure is ever modified in a way that increases the size, this
117  * value will need to be modified to match.
118  * For the export version only the MocRandCtx is supported. The MocRandCtx is
119  * really just a container with a pointer to the real context, so we only need
120  * a pointers worth of bytes. Just to be safe there is a little extra space to
121  * alleviate any potential alignment issues. */
122 
123 #ifdef __ENABLE_MOCANA_CRYPTO_INTERFACE_EXPORT__
124 #define MOC_RAND_CTX_WRAPPER_STORAGE_SIZE 16
125 #else
126 #define MOC_RAND_CTX_WRAPPER_STORAGE_SIZE 900
127 #endif
128 
129 typedef struct RandomCtxWrapper
130 {
131  hwAccelDescr hwAccelCtx;
132 
133  randomContextType WrappedCtxType;
134  ubyte4 reseedBitCounter;
135  union
136  {
137  /* We need enough room for a NIST_CTR_DRBG_Ctx */
138  ubyte storage[MOC_RAND_CTX_WRAPPER_STORAGE_SIZE];
139  } WrappedCtx;
140  /* Don't add any fields here, because CTR adds bytes on the end of byteBuff */
141 
142 } RandomCtxWrapper;
143 
144 #define IS_MOC_RAND(wrap) \
145  ((wrap->WrappedCtxType == MOC_RAND))
146 
147 #define GET_MOC_RAND_CTX(wrap) \
148  ((wrap->WrappedCtxType == MOC_RAND) ? ((MocRandCtx *)(wrap->WrappedCtx.storage)):(NULL))
149 
150 /*------------------------------------------------------------------*/
151 
152 /* Default number of bytes of entropy to collect for seed material */
153 #define MOC_DEFAULT_NUM_ENTROPY_BYTES 48
154 
155 /* RNG Entropy source */
156 #define ENTROPY_SRC_INTERNAL 0 /* Internal entropy threads will be used */
157 #define ENTROPY_SRC_EXTERNAL 1 /* External entropy will be added to Random contexts */
158 
159 #if (defined(__DISABLE_MOCANA_RAND_ENTROPY_THREADS__) || defined(__ENABLE_MOCANA_FIPS_MODULE__))
160 #define ENTROPY_DEFAULT_SRC ENTROPY_SRC_EXTERNAL
161 #else
162 #define ENTROPY_DEFAULT_SRC ENTROPY_SRC_INTERNAL
163 #endif
164 
165 /* Seeding methods */
166 #define MOC_AUTOSEED MOC_INIT_FLAG_AUTOSEED /* FIPS approved entropy collection for autoseed */
167 #define MOC_NO_AUTOSEED MOC_INIT_FLAG_NO_AUTOSEED /* Simple entropy collection for autoseed */
168 #define MOC_SEED_FROM_DEV_URANDOM MOC_INIT_FLAG_SEED_FROM_DEV_URANDOM /* Seed from /dev/urandom */
169 
170 #ifdef __DISABLE_MOCANA_RAND_ENTROPY_THREADS__
171 #define MOC_SEED_DEFAULT MOC_NO_AUTOSEED
172 #else
173 #define MOC_SEED_DEFAULT MOC_AUTOSEED
174 #endif
175 
176 #define MOC_AUTOSEED_MIN_NUM_BYTES 8
177 #define MOC_AUTOSEED_MAX_NUM_BYTES 64
178 
179 /* personalization string used by some DRBG. Can be NULL (default)
180 or set up to be a function */
181 #ifndef MOCANA_RNG_GET_PERSONALIZATION_STRING
182 #define MOCANA_RNG_GET_PERSONALIZATION_STRING GetNullPersonalizationString
183 #endif
184 
185 #define NIST_CTRDRBG_DEFAULT_KEY_LEN_BYTES 32
186 #define NIST_CTRDRBG_DEFAULT_OUT_LEN_BYTES 16
187 
188 /*------------------------------------------------------------------*/
189 /* RNG Algorithm Defines algoId */
190 #define MODE_RNG_ANY 0 /* Any random number generator will do */
191 #define MODE_RNG_FIPS186 1 /* Use FIPS186 RNG */
192 #define MODE_DRBG_CTR 3 /* Use DRBG CTR Mode */
193 
194 #define RANDOM_DEFAULT_ALGO MODE_DRBG_CTR /* Must be one of the above (FIPS186 or CTR) */
195 
196 /*------------------------------------------------------------------*/
197 
220 MOC_EXTERN MSTATUS RANDOM_acquireContext(randomContext **pp_randomContext);
221 
222 MOC_EXTERN MSTATUS RANDOM_acquireContextEx(randomContext **pp_randomContext, ubyte algoId);
223 
247 MOC_EXTERN MSTATUS RANDOM_releaseContext (randomContext **pp_randomContext);
248 
249 MOC_EXTERN MSTATUS RANDOM_releaseContextEx (randomContext **pp_randomContext);
250 
251 #ifndef __DISABLE_MOCANA_ADD_ENTROPY__
252 
277 MOC_EXTERN MSTATUS RANDOM_addEntropyBit(randomContext *pRandomContext, ubyte entropyBit);
278 
279 MOC_EXTERN MSTATUS RANDOM_addEntropyBitEx(randomContext *pRandomContext, ubyte entropyBit);
280 #endif /*__DISABLE_MOCANA_ADD_ENTROPY__*/
281 
282 
311 MOC_EXTERN MSTATUS RANDOM_numberGenerator(randomContext *pRandomContext, ubyte *pBuffer, sbyte4 bufSize);
312 
355 MOC_EXTERN MSTATUS RANDOM_isMocSymContext(
356  randomContext **ppRandomContext,
357  intBoolean *pIsMocSym
358  );
359 
378 MOC_EXTERN MSTATUS RANDOM_launchAutoSeed(
379  randomContext *pCtx
380  );
381 
414 MOC_EXTERN MSTATUS RANDOM_getAutoSeedBytes(
415  ubyte *pSeedBytes,
416  ubyte4 numBytes
417  );
418 
456 MOC_EXTERN MSTATUS RANDOM_generateASCIIString(randomContext *pRandomContext, ubyte *pBuffer, ubyte4 bufferLen);
457 
487 MOC_EXTERN sbyte4 RANDOM_rngFun(void* rngFunArg, ubyte4 length, ubyte *buffer);
488 
489 
513 MOC_EXTERN MSTATUS RANDOM_setEntropySource(ubyte EntropySrc);
514 
529 MOC_EXTERN ubyte RANDOM_getEntropySource(void);
530 
531 
532 /* FIPS 186 specific functions */
533 
534 MOC_EXTERN MSTATUS RANDOM_KSrcGenerator(randomContext *pRandomContext, ubyte buffer[40]);
535 
566 MOC_EXTERN MSTATUS RANDOM_newFIPS186Context( randomContext **ppRandomContext, ubyte b, const ubyte pXKey[/*b*/], sbyte4 seedLen, const ubyte pXSeed[/*seedLen*/]);
567 
586 MOC_EXTERN MSTATUS RANDOM_deleteFIPS186Context( randomContext **ppRandomContext);
587 
616 MOC_EXTERN MSTATUS RANDOM_numberGeneratorFIPS186(randomContext *pRandomContext, ubyte *pRetRandomBytes, sbyte4 numRandomBytes);
617 
632 MOC_EXTERN MSTATUS RANDOM_seedFIPS186Context (
633  randomContext *pRandomCtx,
634  ubyte *seed,
635  ubyte4 seedLen
636  );
637 
649 MOC_EXTERN MSTATUS RANDOM_seedFromDevURandom (
650  randomContext *pCtx,
651  ubyte4 numBytes
652  );
653 
668 MOC_EXTERN MSTATUS RANDOM_seedOldRandom (
669  randomContext *pCtx,
670  ubyte *pSeedBytes,
671  ubyte4 seedLen
672  );
673 
695 MOC_EXTERN MSTATUS RANDOM_reseedContext (
696  randomContext *pCtx,
697  ubyte *pEntropy,
698  ubyte4 entropyLen,
699  ubyte *pAdditionalData,
700  ubyte4 additionalDataLen
701  );
702 
718 MOC_EXTERN MSTATUS RANDOM_numberGeneratorAdd (
719  randomContext *pRandomContext,
720  ubyte *pRetRandomBytes,
721  ubyte4 numRandomBytes,
722  ubyte *pAdditionalData,
723  ubyte4 additionalDataLen
724  );
725 
726 
734 MOC_EXTERN ubyte* GetNullPersonalizationString(ubyte4* pLen);
735 
736 #ifdef __FIPS_OPS_TEST__
737 
740 MOC_EXTERN void triggerRNGFail(void);
741 
745 MOC_EXTERN void resetRNGFail(void);
746 #endif
747 
748 /*----------------------------------------------------------------------------*/
749 /* Macro Function Definitions */
750 
751 #ifdef __ENABLE_MOCANA_DEV_URANDOM__
752 
762 #define MOC_SEED_FROM_DEV_URAND(_status, _randCtx, _numBytes) \
763  _status = RANDOM_seedFromDevURandom (_randCtx, _numBytes); \
764  if (OK != status) \
765  goto exit;
766 
767 #else
768 
769 #define MOC_SEED_FROM_DEV_URAND(_status, _randCtx, _numBytes) \
770  _status = ERR_RAND_SEED_METHOD_NOT_SUPPORTED; \
771  goto exit;
772 
773 #endif /* ifdef __ENABLE_MOCANA_DEV_URANDOM__ */
774 
775 /*----------------------------------------------------------------------------*/
776 
777 #ifdef __DISABLE_MOCANA_RAND_ENTROPY_THREADS__
778 
793 #define MOC_VERIFY_AUTOSEED_ENABLED(_status) \
794  _status = ERR_RAND_SEED_METHOD_NOT_SUPPORTED; \
795  goto exit;
796 #else
797 #define MOC_VERIFY_AUTOSEED_ENABLED(_status)
798 
799 #endif /* ifdef __DISABLE_MOCANA_RAND_ENTROPY_THREADS__ */
800 
801 /*----------------------------------------------------------------------------*/
802 
803 #if defined(__MOCANA_FORCE_ENTROPY__) || defined(__ENABLE_MOCANA_CUSTOM_ENTROPY_INJECT__)
804 #ifndef __DISABLE_MOCANA_ADD_ENTROPY__
805 
821 #define MOC_ADD_ENTROPY_PRE_INIT(_status) \
822  _status = RANDOM_setEntropySource(ENTROPY_SRC_EXTERNAL); \
823  if (OK != _status) \
824  goto exit;
825 
826 #endif /* ifndef __DISABLE_MOCANA_ADD_ENTROPY__ */
827 #endif
828 
829 #if defined(__ENABLE_MOCANA_CUSTOM_ENTROPY_INJECT__)
830 #ifndef __DISABLE_MOCANA_ADD_ENTROPY__
831 
848 #define MOC_ADD_ENTROPY_INIT(_status, _pSetupInfo) \
849  _status = MOCANA_addCustomEntropyInjection(); \
850  if (OK != _status) \
851  goto exit;
852 
853 #endif /* ifndef __DISABLE_MOCANA_ADD_ENTROPY__ */
854 #endif /* if defined(__ENABLE_MOCANA_CUSTOM_ENTROPY_INJECT__) */
855 
856 #if defined(__MOCANA_FORCE_ENTROPY__) && !defined(__ENABLE_MOCANA_CUSTOM_ENTROPY_INJECT__)
857 #ifndef __DISABLE_MOCANA_ADD_ENTROPY__
858 
875 #define MOC_ADD_ENTROPY_INIT(_status, _pSetupInfo) \
876  if (NULL != _pSetupInfo) \
877  { \
878  if (0 != (MOC_NO_AUTOSEED & _pSetupInfo->flags)) \
879  { \
880  _status = RANDOM_setEntropySource(ENTROPY_SRC_EXTERNAL); \
881  if (OK != _status) \
882  goto exit; \
883  } \
884  } \
885  _status = MOCANA_addExternalEntropy(1); \
886  if (OK != _status) \
887  goto exit;
888 
906 #define MOC_ADD_ENTROPY_UNINIT() \
907  MOCANA_cancelExternalEntropy();
908 
909 #endif /* ifndef __DISABLE_MOCANA_ADD_ENTROPY__ */
910 #endif /* ifdef __MOCANA_FORCE_ENTROPY__ */
911 
912 #ifndef MOC_ADD_ENTROPY_INIT
913 #define MOC_ADD_ENTROPY_INIT(_status, _pSetupInfo)
914 #endif
915 #ifndef MOC_ADD_ENTROPY_UNINIT
916 #define MOC_ADD_ENTROPY_UNINIT()
917 #endif
918 #ifndef MOC_ADD_ENTROPY_PRE_INIT
919 #define MOC_ADD_ENTROPY_PRE_INIT(_status)
920 #endif
921 
922 /*----------------------------------------------------------------------------*/
923 
924 #ifndef __DISABLE_MOCANA_RNG__
925 
926 #ifdef __ENABLE_MOCANA_CRYPTO_INTERFACE__
927 
938 #define MOC_GRNG_DEFAULT_INIT(_status) \
939  if (NULL == g_pRandomContext) \
940  { \
941  _status = CRYPTO_INTERFACE_RANDOM_acquireContextEx ( \
942  &g_pRandomContext, RANDOM_DEFAULT_ALGO); \
943  if (OK != _status) \
944  goto exit; \
945  }
946 
958 #define MOC_GRNG_DEFAULT_FREE(_status, _dStatus) \
959  _dStatus = CRYPTO_INTERFACE_RANDOM_releaseContextEx(&g_pRandomContext); \
960  if (OK != dStatus) \
961  _status = _dStatus;
962 
963 #else
964 
975 #define MOC_GRNG_DEFAULT_INIT(_status) \
976  if (NULL == g_pRandomContext) \
977  { \
978  _status = RANDOM_acquireContext(&g_pRandomContext); \
979  if (OK != _status) \
980  goto exit; \
981  }
982 
994 #define MOC_GRNG_DEFAULT_FREE(_status, _dStatus) \
995  _dStatus = RANDOM_releaseContext(&g_pRandomContext); \
996  if (OK != dStatus) \
997  _status = _dStatus;
998 
999 #endif /* ifdef __ENABLE_MOCANA_CRYPTO_INTERFACE__ */
1000 
1013 #define MOC_GRNG_DEPOT_INIT(_status) \
1014  _status = RNG_SEED_initDepotState(); \
1015  if (OK != _status) \
1016  goto exit;
1017 
1029 #define MOC_GRNG_DEPOT_FREE() \
1030  RNG_SEED_freeDepotState();
1031 
1032 /*----------------------------------------------------------------------------*/
1033 
1034 #ifdef __ENABLE_MOCANA_SYM__
1035 
1066 #define MOC_GRNG_FULL_INIT(_status, _pSetupInfo, _pMocCtx) \
1067  if (NULL != _pSetupInfo) \
1068  { \
1069  if (0 != (MOC_NO_AUTOSEED & _pSetupInfo->flags)) \
1070  { \
1071  _status = RANDOM_setEntropySource(ENTROPY_SRC_EXTERNAL); \
1072  if (OK != _status) \
1073  goto exit; \
1074  } \
1075  \
1076  _status = ERR_RAND_CTX_ALREADY_INITIALIZED; \
1077  if (NULL != g_pRandomContext) \
1078  goto exit; \
1079  \
1080  if (NULL != _pSetupInfo->MocSymRandOperator) \
1081  { \
1082  intBoolean support = FALSE; \
1083  MocRandCtx *pRandCtx = NULL; \
1084  RandomCtxWrapper *pWrap = NULL; \
1085  MocSymCtx pCtx = NULL; \
1086  \
1087  _status = CRYPTO_createMocSymRandom(_pSetupInfo->MocSymRandOperator, \
1088  _pSetupInfo->pOperatorInfo, \
1089  _pMocCtx, &g_pRandomContext); \
1090  if (OK != _status) \
1091  goto exit; \
1092  \
1093  pWrap = (RandomCtxWrapper *) g_pRandomContext; \
1094  \
1095  _status = ERR_NULL_POINTER; \
1096  if (NULL == pWrap) \
1097  goto exit; \
1098  \
1099  pRandCtx = (MocRandCtx *)&(pWrap->WrappedCtx.storage); \
1100  pCtx = (MocSymCtx)(pRandCtx->pMocSymObj); \
1101  if ( (NULL == pCtx) || (NULL == pCtx->SymOperator) ) \
1102  goto exit; \
1103  \
1104  _status = pCtx->SymOperator ( \
1105  pCtx, _pMocCtx, MOC_SYM_OP_RAND_GET_SEED_TYPE, NULL, \
1106  (void *)&support); \
1107  if (OK != _status) \
1108  goto exit; \
1109  \
1110  if ( (0 == (MOC_NO_AUTOSEED & _pSetupInfo->flags)) && \
1111  (MOC_SYM_RAND_SEED_TYPE_DIRECT == support) ) \
1112  { \
1113  if (0 != (MOC_SEED_FROM_DEV_URANDOM & _pSetupInfo->flags)) \
1114  { \
1115  MOC_SEED_FROM_DEV_URAND ( \
1116  _status, g_pRandomContext, MOC_DEFAULT_NUM_ENTROPY_BYTES) \
1117  } \
1118  else \
1119  { \
1120  ubyte entropy[MOC_DEFAULT_NUM_ENTROPY_BYTES] = {0}; \
1121  _status = RANDOM_getAutoSeedBytes ( \
1122  entropy, MOC_DEFAULT_NUM_ENTROPY_BYTES); \
1123  if (OK != _status) \
1124  goto exit; \
1125  \
1126  _status = CRYPTO_seedRandomContext(g_pRandomContext, \
1127  NULL, \
1128  entropy, \
1129  MOC_DEFAULT_NUM_ENTROPY_BYTES); \
1130  MOC_MEMSET(entropy, 0, MOC_DEFAULT_NUM_ENTROPY_BYTES); \
1131  } \
1132  if (OK != _status) \
1133  goto exit; \
1134  } \
1135  } \
1136  else \
1137  { \
1138  MOC_GRNG_DEFAULT_INIT(_status) \
1139  if (0 != (MOC_SEED_FROM_DEV_URANDOM & _pSetupInfo->flags)) \
1140  { \
1141  MOC_SEED_FROM_DEV_URAND ( \
1142  _status, g_pRandomContext, MOC_DEFAULT_NUM_ENTROPY_BYTES) \
1143  } \
1144  } \
1145  } \
1146  else \
1147  { \
1148  MOC_GRNG_DEFAULT_INIT(_status) \
1149  }
1150 
1173 #define MOC_GRNG_FULL_FREE(_status, _dStatus) \
1174  intBoolean isMocSymRand = FALSE; \
1175  _dStatus = RANDOM_isMocSymContext(&g_pRandomContext, &isMocSymRand); \
1176  if (OK != _dStatus) \
1177  _status = _dStatus; \
1178  if (TRUE == isMocSymRand) \
1179  { \
1180  _dStatus = CRYPTO_freeMocSymRandom(&g_pRandomContext); \
1181  if (OK != _dStatus) \
1182  _status = _dStatus; \
1183  } \
1184  else \
1185  { \
1186  MOC_GRNG_DEFAULT_FREE(_status, _dStatus) \
1187  }
1188 
1189 #else /* ifdef __ENABLE_MOCANA_SYM__ */
1190 
1191 /* If MocSym is disabled, define macros to handle default RNG only */
1192 #define MOC_GRNG_FULL_INIT(_status, _pSetupInfo, _pMocCtx) \
1193  MOC_GRNG_DEFAULT_INIT(_status)
1194 #define MOC_GRNG_FULL_FREE(_status, _dStatus) \
1195  MOC_GRNG_DEFAULT_FREE(_status, _dStatus)
1196 
1197 #endif /* ifdef __ENABLE_MOCANA_SYM__ */
1198 
1199 /*----------------------------------------------------------------------------*/
1200 
1214 #define MOC_GRNG_INIT(_status, _pSetupInfo, _pMocCtx) \
1215  MOC_ADD_ENTROPY_PRE_INIT(_status) \
1216  MOC_GRNG_DEPOT_INIT(_status) \
1217  MOC_GRNG_FULL_INIT(_status, _pSetupInfo, _pMocCtx) \
1218  MOC_ADD_ENTROPY_INIT(_status, _pSetupInfo)
1219 
1232 #define MOC_GRNG_FREE(_status, _dStatus) \
1233  MOC_GRNG_FULL_FREE(_status, _dStatus) \
1234  MOC_GRNG_DEPOT_FREE() \
1235  MOC_ADD_ENTROPY_UNINIT()
1236 
1237 #else /* ifndef __DISABLE_MOCANA_RNG__ */
1238 
1239 /* If RNG is disabled, define macros to be empty */
1240 #ifndef MOC_GRNG_INIT
1241 #define MOC_GRNG_INIT(_status, _pSetupInfo, _pMocCtx)
1242 #endif
1243 #ifndef MOC_GRNG_FREE
1244 #define MOC_GRNG_FREE(_status, _dStatus)
1245 #endif
1246 
1247 #endif /* ifndef __DISABLE_MOCANA_RNG__ */
1248 
1249 /*----------------------------------------------------------------------------*/
1250 
1251 #ifdef __cplusplus
1252 }
1253 #endif
1254 
1255 #endif /* __RANDOM_HEADER__ */
MOC_EXTERN MSTATUS RANDOM_addEntropyBit(randomContext *pRandomContext, ubyte entropyBit)
Add entropy to the RNG (random number generator) module.
MOC_EXTERN MSTATUS RANDOM_reseedContext(randomContext *pCtx, ubyte *pEntropy, ubyte4 entropyLen, ubyte *pAdditionalData, ubyte4 additionalDataLen)
Reseed a random context.
MOC_EXTERN MSTATUS RANDOM_seedFromDevURandom(randomContext *pCtx, ubyte4 numBytes)
Seed a random context with bytes from /dev/urandom.
MOC_EXTERN MSTATUS RANDOM_isMocSymContext(randomContext **ppRandomContext, intBoolean *pIsMocSym)
Determine if a randomContext refers to a MocSym random implementation.
MOC_EXTERN MSTATUS RANDOM_seedFIPS186Context(randomContext *pRandomCtx, ubyte *seed, ubyte4 seedLen)
Seed a previously allocated FIPS186 Random Context.
MOC_EXTERN MSTATUS RANDOM_numberGenerator(randomContext *pRandomContext, ubyte *pBuffer, sbyte4 bufSize)
Generate the specified number of random bits.
MOC_EXTERN MSTATUS RANDOM_acquireContext(randomContext **pp_randomContext)
Create an RNG (random number generator) context data structure.
MOC_EXTERN MSTATUS RANDOM_getAutoSeedBytes(ubyte *pSeedBytes, ubyte4 numBytes)
Collect entropy bytes for seed material.
MOC_EXTERN MSTATUS RANDOM_deleteFIPS186Context(randomContext **ppRandomContext)
Deletes a FIPS186 RNG context.
MOC_EXTERN MSTATUS RANDOM_releaseContext(randomContext **pp_randomContext)
Delete RNG (random number generator) context data structure.
MOC_EXTERN void triggerRNGFail(void)
Sets the global RNG fail flag to TRUE (1).
MOC_EXTERN MSTATUS RANDOM_launchAutoSeed(randomContext *pCtx)
Seed a random context using the built-in entropy collection.
MOC_EXTERN MSTATUS RANDOM_numberGeneratorAdd(randomContext *pRandomContext, ubyte *pRetRandomBytes, ubyte4 numRandomBytes, ubyte *pAdditionalData, ubyte4 additionalDataLen)
Generate random bytes with optional additional input.
MOC_EXTERN MSTATUS RANDOM_generateASCIIString(randomContext *pRandomContext, ubyte *pBuffer, ubyte4 bufferLen)
Function to return a random ASCII character string.
MOC_EXTERN MSTATUS RANDOM_numberGeneratorFIPS186(randomContext *pRandomContext, ubyte *pRetRandomBytes, sbyte4 numRandomBytes)
Generate the specified number of random bits via FIPS186.
sbyte4(* RNGFun)(void *rngFunArg, ubyte4 length, ubyte *buffer)
Function pointer type for a method that produces (pseudo) random bytes.
Definition: random.h:98
MOC_EXTERN MSTATUS RANDOM_newFIPS186Context(randomContext **ppRandomContext, ubyte b, const ubyte pXKey[], sbyte4 seedLen, const ubyte pXSeed[])
Generate FIPS-specific RNG context data structure using provided seed.
MOC_EXTERN void resetRNGFail(void)
Resets the global RNG fail flag back to FALSE (0).
MOC_EXTERN sbyte4 RANDOM_rngFun(void *rngFunArg, ubyte4 length, ubyte *buffer)
Generate a random number.
MOC_EXTERN MSTATUS RANDOM_setEntropySource(ubyte EntropySrc)
Sets the global entropy source flag.
MOC_EXTERN MSTATUS RANDOM_seedOldRandom(randomContext *pCtx, ubyte *pSeedBytes, ubyte4 seedLen)
Seeds randomContexts that are not MocSym Operators.
MOC_EXTERN ubyte * GetNullPersonalizationString(ubyte4 *pLen)
Returns a NULL string.
MOC_EXTERN ubyte RANDOM_getEntropySource(void)
Gets the global entropy source flag.