% December 2001 %
% %
% %
-% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
#include "MagickCore/memory_.h"
#include "MagickCore/semaphore.h"
#include "MagickCore/random_.h"
+#include "MagickCore/random-private.h"
#include "MagickCore/resource_.h"
#include "MagickCore/signature-private.h"
#include "MagickCore/string_.h"
#include "MagickCore/thread_.h"
#include "MagickCore/thread-private.h"
#include "MagickCore/utility.h"
+#include "MagickCore/utility-private.h"
/*
Define declarations.
*/
double
normalize;
+ unsigned long
+ secret_key;
+
unsigned short
protocol_major,
protocol_minor;
*random_semaphore = (SemaphoreInfo *) NULL;
static unsigned long
- random_seed = ~0UL;
+ secret_key = ~0UL;
static MagickBooleanType
gather_true_random = MagickFalse;
random_info->signature_info));
ResetStringInfo(random_info->reservoir);
random_info->normalize=1.0/(~0UL);
- random_info->semaphore=AllocateSemaphoreInfo();
+ random_info->secret_key=secret_key;
random_info->protocol_major=RandomProtocolMajorVersion;
random_info->protocol_minor=RandomProtocolMinorVersion;
+ random_info->semaphore=AllocateSemaphoreInfo();
random_info->timestamp=(ssize_t) time(0);
random_info->signature=MagickSignature;
/*
/*
Seed pseudo random number generator.
*/
- if (random_seed == ~0UL)
+ if (random_info->secret_key == ~0UL)
{
- key=GetRandomKey(random_info,sizeof(random_seed));
+ key=GetRandomKey(random_info,sizeof(random_info->secret_key));
(void) CopyMagickMemory(random_info->seed,GetStringInfoDatum(key),
GetStringInfoLength(key));
key=DestroyStringInfo(key);
*signature_info;
signature_info=AcquireSignatureInfo();
- key=AcquireStringInfo(sizeof(random_seed));
- SetStringInfoDatum(key,(unsigned char *) &random_seed);
+ key=AcquireStringInfo(sizeof(random_info->secret_key));
+ SetStringInfoDatum(key,(unsigned char *) &random_info->secret_key);
UpdateSignature(signature_info,key);
key=DestroyStringInfo(key);
FinalizeSignature(signature_info);
#endif
if (file != -1)
(void) close(file);
- (void) remove(filename);
+ (void) remove_utf8(filename);
SetStringInfoLength(chaos,strlen(filename));
SetStringInfoDatum(chaos,(unsigned char *) filename);
ConcatenateStringInfo(entropy,chaos);
*/
SetStringInfoLength(chaos,MaxEntropyExtent);
status=NTGatherRandomData(MaxEntropyExtent,GetStringInfoDatum(chaos));
+ (void) status;
ConcatenateStringInfo(entropy,chaos);
}
#else
filename=AcquireString("/dev/urandom");
device=StringToStringInfo(filename);
device=DestroyStringInfo(device);
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
filename=DestroyString(filename);
if (file != -1)
{
filename=AcquireString("/dev/random");
device=StringToStringInfo(filename);
device=DestroyStringInfo(device);
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
filename=DestroyString(filename);
if (file == -1)
{
filename=AcquireString("/dev/srandom");
device=StringToStringInfo(filename);
device=DestroyStringInfo(device);
- file=open(filename,O_RDONLY | O_BINARY);
+ file=open_utf8(filename,O_RDONLY | O_BINARY,0);
}
if (file != -1)
{
% %
% %
% %
+% G e t R a n d o m S e c r e t K e y %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% GetRandomSecretKey() returns the random secet key.
+%
+% The format of the GetRandomSecretKey method is:
+%
+% unsigned long GetRandomSecretKey(const RandomInfo *random_info)
+%
+% A description of each parameter follows:
+%
+% o random_info: the random info.
+*/
+MagickExport unsigned long GetRandomSecretKey(const RandomInfo *random_info)
+{
+ return(random_info->secret_key);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% G e t R a n d o m V a l u e %
% %
% %
% MagickBooleanType RandomComponentGenesis(void)
%
*/
-MagickExport MagickBooleanType RandomComponentGenesis(void)
+MagickPrivate MagickBooleanType RandomComponentGenesis(void)
{
AcquireSemaphoreInfo(&random_semaphore);
return(MagickTrue);
% RandomComponentTerminus(void)
%
*/
-MagickExport void RandomComponentTerminus(void)
+MagickPrivate void RandomComponentTerminus(void)
{
if (random_semaphore == (SemaphoreInfo *) NULL)
AcquireSemaphoreInfo(&random_semaphore);
% %
% %
% %
-% S e e d P s e u d o R a n d o m G e n e r a t o r %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% SeedPseudoRandomGenerator() initializes the pseudo-random number generator
-% with a random seed.
-%
-% The format of the SeedPseudoRandomGenerator method is:
-%
-% void SeedPseudoRandomGenerator(const unsigned long seed)
-%
-% A description of each parameter follows:
-%
-% o seed: the seed.
-%
-*/
-MagickExport void SeedPseudoRandomGenerator(const unsigned long seed)
-{
- random_seed=seed;
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
% S e t R a n d o m K e y %
% %
% %
% %
% %
% %
+% S e t R a n d o m S e c r e t K e y %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetRandomSecretKey() sets the pseudo-random number generator secret key.
+%
+% The format of the SetRandomSecretKey method is:
+%
+% void SetRandomSecretKey(const unsigned long key)
+%
+% A description of each parameter follows:
+%
+% o key: the secret seed.
+%
+*/
+MagickExport void SetRandomSecretKey(const unsigned long key)
+{
+ secret_key=key;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% S e t R a n d o m T r u e R a n d o m %
% %
% %