]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/random.c
(no commit message)
[imagemagick] / MagickCore / random.c
index 33347ed89fffc444a673acc52d129d7d32266e55..f167e004b59f845ea35b1df0627cca0ff608c49a 100644 (file)
@@ -16,7 +16,7 @@
 %                              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  %
@@ -92,6 +92,9 @@ struct _RandomInfo
   double
     normalize;
 
+  unsigned long
+    secret_key;
+
   unsigned short
     protocol_major,
     protocol_minor;
@@ -124,7 +127,7 @@ static SemaphoreInfo
   *random_semaphore = (SemaphoreInfo *) NULL;
 
 static unsigned long
-  random_seed = ~0UL;
+  secret_key = ~0UL;
 
 static MagickBooleanType
   gather_true_random = MagickFalse;
@@ -185,10 +188,11 @@ MagickExport RandomInfo *AcquireRandomInfo(void)
   random_info->reservoir=AcquireStringInfo(GetSignatureDigestsize(
     random_info->signature_info));
   ResetStringInfo(random_info->reservoir);
-  random_info->normalize=1.0/(double) MagickResourceInfinity;
-  random_info->semaphore=AllocateSemaphoreInfo();
+  random_info->normalize=1.0/(~0UL);
+  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;
   /*
@@ -219,9 +223,9 @@ MagickExport RandomInfo *AcquireRandomInfo(void)
   /*
     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);
@@ -232,8 +236,8 @@ MagickExport RandomInfo *AcquireRandomInfo(void)
         *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);
@@ -492,6 +496,7 @@ static StringInfo *GenerateEntropicChaos(RandomInfo *random_info)
     */
     SetStringInfoLength(chaos,MaxEntropyExtent);
     status=NTGatherRandomData(MaxEntropyExtent,GetStringInfoDatum(chaos));
+    (void) status;
     ConcatenateStringInfo(entropy,chaos);
   }
 #else
@@ -657,6 +662,32 @@ MagickExport StringInfo *GetRandomKey(RandomInfo *random_info,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   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                                               %
 %                                                                             %
 %                                                                             %
@@ -740,34 +771,6 @@ MagickPrivate void RandomComponentTerminus(void)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   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                                                   %
 %                                                                             %
 %                                                                             %
@@ -869,6 +872,33 @@ MagickExport void SetRandomKey(RandomInfo *random_info,const size_t length,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   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                                     %
 %                                                                             %
 %                                                                             %