Data Structures | Defines | Functions | Variables

# random.c File Reference

`#include "wizard/studio.h"`
`#include "wizard/entropy.h"`
`#include "wizard/exception.h"`
`#include "wizard/exception-private.h"`
`#include "wizard/file.h"`
`#include "wizard/hash.h"`
`#include "wizard/magick.h"`
`#include "wizard/memory_.h"`
`#include "wizard/random_.h"`
`#include "wizard/thread_.h"`
`#include "wizard/thread-private.h"`
`#include "wizard/semaphore.h"`

## Data Structures
struct | _RandomInfo
## Defines
#define | PseudoRandomHash SHA256Hash
#define | RandomEntropyLevel 9
#define | RandomFilename "reservoir.xdm"
#define | RandomFiletype "random"
#define | RandomProtocolMajorVersion 1
#define | RandomProtocolMinorVersion 1
#define | MaxEntropyExtent 64
## Functions
static WizardBooleanType | SaveEntropyToReservoir (RandomInfo *, ExceptionInfo *)
static StringInfo * | GenerateEntropicChaos (RandomInfo *, ExceptionInfo *)
static StringInfo ** | GetEntropyFromReservoir (RandomInfo *, ExceptionInfo *)
static size_t | WizardMin (const size_t x, const size_t y)
WizardExport RandomInfo * | AcquireRandomInfo (const HashType hash)
WizardExport RandomInfo * | DestroyRandomInfo (RandomInfo *random_info)
static ssize_t | ReadRandom (int file, unsigned char *source, size_t length)
WizardExport double | GetPseudoRandomValue (RandomInfo *random_info)
WizardExport StringInfo * | GetRandomKey (RandomInfo *random_info, const size_t length)
WizardExport double | GetRandomValue (RandomInfo *random_info)
WizardExport WizardBooleanType | RandomComponentGenesis (void)
WizardExport void | RandomComponentTerminus (void)
WizardExport void | SeedPseudoRandomGenerator (const size_t seed)
static void | IncrementRandomNonce (StringInfo *nonce)
WizardExport void | SetRandomKey (RandomInfo *random_info, const size_t length, unsigned char *key)
WizardExport void | SetRandomTrueRandom (const WizardBooleanType true_random)
## Variables
char ** | environ
static SemaphoreInfo * | random_semaphore = (SemaphoreInfo *) NULL
static size_t | random_seed = ~0UL
static WizardBooleanType | gather_true_random = WizardFalse

## Define Documentation

#define MaxEntropyExtent 64

Referenced by GenerateEntropicChaos().

#define PseudoRandomHash SHA256Hash

Referenced by AcquireRandomInfo().

#define RandomEntropyLevel 9

Referenced by GenerateEntropicChaos().

#define RandomFilename "reservoir.xdm"

Referenced by GetEntropyFromReservoir(), and SaveEntropyToReservoir().

#define RandomFiletype "random"

Referenced by GetEntropyFromReservoir(), and SaveEntropyToReservoir().

#define RandomProtocolMajorVersion 1

#define RandomProtocolMinorVersion 1

## Function Documentation

WizardExport RandomInfo* AcquireRandomInfo | ( | const HashType | hash | ) |

References AcquireExceptionInfo(), AcquireHashInfo(), AcquireHMACInfo(), AcquireStringInfo(), AcquireWizardMemory(), AllocateSemaphoreInfo(), CopyWizardMemory(), DestroyExceptionInfo(), DestroyHashInfo(), DestroyStringInfo(), FinalizeHash(), GenerateEntropicChaos(), GetHashDigest(), GetHashDigestsize(), GetHMACDigest(), GetHMACDigestsize(), GetRandomKey(), GetStringInfoDatum(), GetStringInfoLength(), HashDomain, _RandomInfo::hmac_info, InitializeHMAC(), MemoryError, _RandomInfo::nonce, _RandomInfo::normalize, _RandomInfo::protocol_major, _RandomInfo::protocol_minor, PseudoRandomHash, random_info, random_seed, RandomFatalError, _RandomInfo::reservoir, ResetStringInfo(), ResetWizardMemory(), SaveEntropyToReservoir(), _RandomInfo::seed, _RandomInfo::semaphore, SetStringInfo(), SetStringInfoDatum(), SetStringInfoLength(), _RandomInfo::signature, ThrowFatalException, ThrowWizardFatalError, _RandomInfo::timestamp, UpdateHash(), and WizardMin().

Referenced by AcquireCipherInfo(), AcquireKeyInfo(), AcquireSecretInfo(), and AcquireUniqueFileResource().

WizardExport RandomInfo* DestroyRandomInfo | ( | RandomInfo * | random_info | ) |

References CipherDomain, DestroyHMACInfo(), DestroySemaphoreInfo(), DestroyStringInfo(), GetWizardModule, _RandomInfo::hmac_info, LockSemaphoreInfo(), LogWizardEvent(), _RandomInfo::nonce, RelinquishWizardMemory(), _RandomInfo::reservoir, ResetWizardMemory(), _RandomInfo::seed, _RandomInfo::semaphore, _RandomInfo::signature, TraceEvent, UnlockSemaphoreInfo(), WizardAssert, and WizardSignature.

Referenced by AsynchronousResourceComponentTerminus(), DestroyCipherInfo(), DestroyKeyInfo(), and DestroySecretInfo().

static StringInfo * GenerateEntropicChaos | ( | RandomInfo * | random_info,
|  | ExceptionInfo * | exception |
| ) |  |  | `[static]`

References AcquireEntropyInfo(), AcquireString(), AcquireStringInfo(), close, ConcatenateStringInfo(), DestroyEntropyInfo(), DestroyString(), DestroyStringInfo(), environ, gather_true_random, GetEntropyChaos(), GetEntropyFromReservoir(), getpid, GetStringInfoCRC(), GetStringInfoDatum(), GetStringInfoLength(), gettimeofday(), GetWizardModule, GetWizardThreadId(), IncreaseEntropy(), LockSemaphoreInfo(), MaxEntropyExtent, NTElapsedTime(), NTGatherRandomData(), NTUserTime(), O_BINARY, open, RandomEntropyLevel, RandomError, RandomFatalError, ReadRandom(), _RandomInfo::semaphore, SetStringInfoDatum(), SetStringInfoLength(), StringToStringInfo(), ThrowFatalException, ThrowWizardException(), UnlockSemaphoreInfo(), WizardFalse, and ZIPEntropy.

Referenced by AcquireRandomInfo().

static StringInfo * GetEntropyFromReservoir | ( | RandomInfo * | random_info,
|  | ExceptionInfo * | exception |
| ) |  |  |

References AcquireFileInfo(), AcquireStringInfo(), CipherDomain, CloneStringInfo(), CompareStringInfo(), DestroyFileInfo(), DestroyStringInfo(), GetFilePath(), GetStringInfoCRC(), GetStringInfoDatum(), GetStringInfoLength(), GetWizardMagick(), GetWizardModule, LockSemaphoreInfo(), LogWizardEvent(), _RandomInfo::protocol_major, _RandomInfo::protocol_minor, RandomFilename, RandomFiletype, ReadFile16Bits(), ReadFile32Bits(), ReadFile64Bits(), ReadFileChunk(), ReadFileMode, _RandomInfo::semaphore, _RandomInfo::signature, ThrowWizardException(), _RandomInfo::timestamp, TraceEvent, UnlockSemaphoreInfo(), WizardAssert, WizardFalse, WizardMagick, and WizardSignature.

Referenced by GenerateEntropicChaos().

WizardExport double GetPseudoRandomValue | ( | RandomInfo * | random_info | ) |

References _RandomInfo::normalize, and _RandomInfo::seed.

WizardExport StringInfo* GetRandomKey | ( | RandomInfo * | random_info,
|  | const size_t | length |
| ) |  |  |

References AcquireStringInfo(), CipherDomain, GetStringInfoDatum(), SetRandomKey(), and WizardAssert.

Referenced by AcquireRandomInfo(), AcquireUniqueFileResource(), GenerateCipherNonce(), GenerateSecretKey(), and GenerateSessionKey().

WizardExport double GetRandomValue | ( | RandomInfo * | random_info | ) |

References SetRandomKey().

static void IncrementRandomNonce | ( | StringInfo * | nonce | ) | `[inline, static]`

References GetStringInfoDatum(), GetStringInfoLength(), RandomFatalError, and ThrowFatalException.

Referenced by SetRandomKey().

WizardExport WizardBooleanType RandomComponentGenesis | ( | void |  | ) |

References AcquireSemaphoreInfo(), random_semaphore, and WizardTrue.

Referenced by WizardsToolkitGenesis().

WizardExport void RandomComponentTerminus | ( | void |  | ) |

References AcquireSemaphoreInfo(), DestroySemaphoreInfo(), and random_semaphore.

Referenced by WizardsToolkitTerminus().

static ssize_t ReadRandom | ( | int | file,
|  | unsigned char * | source,
|  | size_t | length |
| ) |  |  | `[static]`

References read.

Referenced by GenerateEntropicChaos().

static WizardBooleanType SaveEntropyToReservoir | ( | RandomInfo * | random_info,
|  | ExceptionInfo * | exception |
| ) |  |  | `[static]`

References AcquireFileInfo(), CipherDomain, DestroyFileInfo(), DestroyStringInfo(), GetFilePath(), GetHMACDigest(), GetStringInfoCRC(), GetStringInfoDatum(), GetStringInfoLength(), GetWizardMagick(), GetWizardModule, _RandomInfo::hmac_info, LockSemaphoreInfo(), LogWizardEvent(), _RandomInfo::protocol_major, _RandomInfo::protocol_minor, RandomFilename, RandomFiletype, _RandomInfo::semaphore, _RandomInfo::signature, ThrowWizardException(), _RandomInfo::timestamp, TraceEvent, UnlockSemaphoreInfo(), WizardAssert, WizardFalse, WizardMagick, WizardSignature, WizardTrue, WriteFile16Bits(), WriteFile32Bits(), WriteFile64Bits(), WriteFileChunk(), and WriteFileMode.

Referenced by AcquireRandomInfo().

WizardExport void SeedPseudoRandomGenerator | ( | const size_t | seed | ) |

References random_seed.

WizardExport void SetRandomKey | ( | RandomInfo * | random_info,
|  | const size_t | length,
|  | unsigned char * | key |
| ) |  |  |

References CipherDomain, CopyWizardMemory(), FinalizeHMAC(), GetHMACDigest(), GetHMACDigestsize(), GetStringInfoDatum(), _RandomInfo::hmac_info, _RandomInfo::i, IncrementRandomNonce(), LockSemaphoreInfo(), _RandomInfo::nonce, _RandomInfo::reservoir, ResetHMAC(), _RandomInfo::semaphore, SetStringInfo(), UnlockSemaphoreInfo(), UpdateHMAC(), and WizardAssert.

Referenced by EncipherCBCMode(), EncipherCTRMode(), EncipherECBMode(), EncipherOFBMode(), GenerateCipherNonce(), GetRandomKey(), and GetRandomValue().

WizardExport void SetRandomTrueRandom | ( | const WizardBooleanType | true_random | ) |

References gather_true_random.

static size_t WizardMin | ( | const size_t | x,
|  | const size_t | y |
| ) |  |  | `[inline, static]`

Referenced by AcquireRandomInfo().

## Variable Documentation

char** environ

Referenced by GenerateEntropicChaos().

WizardBooleanType gather_true_random = WizardFalse`[static]`

Referenced by GenerateEntropicChaos(), and SetRandomTrueRandom().

size_t random_seed = ~0UL`[static]`

Referenced by AcquireRandomInfo(), and SeedPseudoRandomGenerator().

SemaphoreInfo* random_semaphore = (SemaphoreInfo *) NULL`[static]`

Referenced by RandomComponentGenesis(), and RandomComponentTerminus().