% December 2001 %
% %
% %
-% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2018 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 %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
#if defined(__VMS)
#include <time.h>
#endif
-#if defined(__MINGW32__) || defined(__MINGW64__)
+#if defined(__MINGW32__)
#include <sys/time.h>
#endif
#include "MagickCore/studio.h"
#include "MagickCore/exception.h"
#include "MagickCore/exception-private.h"
+#include "MagickCore/image-private.h"
#include "MagickCore/memory_.h"
+#include "MagickCore/memory-private.h"
#include "MagickCore/semaphore.h"
#include "MagickCore/random_.h"
#include "MagickCore/random-private.h"
%
*/
-static inline size_t MagickMin(const size_t x,const size_t y)
-{
- if (x < y)
- return(x);
- return(y);
-}
-
MagickExport RandomInfo *AcquireRandomInfo(void)
{
const StringInfo
*key,
*nonce;
- random_info=(RandomInfo *) AcquireMagickMemory(sizeof(*random_info));
- if (random_info == (RandomInfo *) NULL)
- ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
- (void) ResetMagickMemory(random_info,0,sizeof(*random_info));
+ random_info=(RandomInfo *) AcquireCriticalMemory(sizeof(*random_info));
+ (void) memset(random_info,0,sizeof(*random_info));
random_info->signature_info=AcquireSignatureInfo();
random_info->nonce=AcquireStringInfo(2*GetSignatureDigestsize(
random_info->signature_info));
random_info->protocol_minor=RandomProtocolMinorVersion;
random_info->semaphore=AcquireSemaphoreInfo();
random_info->timestamp=(ssize_t) time(0);
- random_info->signature=MagickSignature;
+ random_info->signature=MagickCoreSignature;
/*
Seed random nonce.
*/
{
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
assert(random_info != (RandomInfo *) NULL);
- assert(random_info->signature == MagickSignature);
+ assert(random_info->signature == MagickCoreSignature);
LockSemaphoreInfo(random_info->semaphore);
if (random_info->reservoir != (StringInfo *) NULL)
random_info->reservoir=DestroyStringInfo(random_info->reservoir);
if (random_info->signature_info != (SignatureInfo *) NULL)
random_info->signature_info=DestroySignatureInfo(
random_info->signature_info);
- (void) ResetMagickMemory(random_info->seed,0,sizeof(*random_info->seed));
- random_info->signature=(~MagickSignature);
+ (void) memset(random_info->seed,0,sizeof(*random_info->seed));
+ random_info->signature=(~MagickCoreSignature);
UnlockSemaphoreInfo(random_info->semaphore);
RelinquishSemaphoreInfo(&random_info->semaphore);
random_info=(RandomInfo *) RelinquishMagickMemory(random_info);
SetStringInfoLength(chaos,sizeof(tid));
SetStringInfoDatum(chaos,(unsigned char *) &tid);
ConcatenateStringInfo(entropy,chaos);
+#if defined(MAGICKCORE_HAVE_SYSCONF) && defined(_SC_PHYS_PAGES)
+ {
+ ssize_t
+ pages;
+
+ pages=(ssize_t) sysconf(_SC_PHYS_PAGES);
+ SetStringInfoLength(chaos,sizeof(pages));
+ SetStringInfoDatum(chaos,(unsigned char *) &pages);
+ ConcatenateStringInfo(entropy,chaos);
+ }
+#endif
#if defined(MAGICKCORE_HAVE_GETRUSAGE) && defined(RUSAGE_SELF)
{
struct rusage
#if defined(MAGICKCORE_HAVE_MKSTEMP)
{
char
- path[MaxTextExtent];
+ path[MagickPathExtent];
int
file;
- (void) GetPathTemplate(path);
+ (void) strcpy(path,"XXXXXX");
file=mkstemp(path);
+ if (file != -1)
+ {
+#if defined(MAGICKCORE_HAVE_FCHMOD)
+ (void) fchmod(file,0600);
+#endif
#if defined(__OS2__)
- setmode(file,O_BINARY);
+ setmode(file,O_BINARY);
#endif
- if (file != -1)
- (void) close(file);
+ (void) close(file);
+ }
(void) remove_utf8(path);
SetStringInfoLength(chaos,strlen(path));
SetStringInfoDatum(chaos,(unsigned char *) path);
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
{
double
- seconds;
+ datum;
LARGE_INTEGER
- nanoseconds;
-
- MagickBooleanType
- status;
+ datum1;
/*
Not crytographically strong but better than nothing.
*/
- seconds=NTElapsedTime()+NTUserTime();
- SetStringInfoLength(chaos,sizeof(seconds));
- SetStringInfoDatum(chaos,(unsigned char *) &seconds);
+ datum=NTElapsedTime()+NTUserTime();
+ SetStringInfoLength(chaos,sizeof(datum));
+ SetStringInfoDatum(chaos,(unsigned char *) &datum);
ConcatenateStringInfo(entropy,chaos);
- if (QueryPerformanceCounter(&nanoseconds) != 0)
+ if (QueryPerformanceCounter(&datum1) != 0)
{
- SetStringInfoLength(chaos,sizeof(nanoseconds));
- SetStringInfoDatum(chaos,(unsigned char *) &nanoseconds);
+ SetStringInfoLength(chaos,sizeof(datum1));
+ SetStringInfoDatum(chaos,(unsigned char *) &datum1);
ConcatenateStringInfo(entropy,chaos);
}
/*
Our best hope for true entropy.
*/
SetStringInfoLength(chaos,MaxEntropyExtent);
- status=NTGatherRandomData(MaxEntropyExtent,GetStringInfoDatum(chaos));
- (void) status;
+ (void) NTGatherRandomData(MaxEntropyExtent,GetStringInfoDatum(chaos));
ConcatenateStringInfo(entropy,chaos);
}
#else
% %
% %
% %
++ G e t R a n d o m I n f o N o r m a l i z e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% GetRandomInfoNormalize() returns the random normalize value.
+%
+% The format of the GetRandomInfoNormalize method is:
+%
+% double GetRandomInfoNormalize(const RandomInfo *random_info)
+%
+% A description of each parameter follows:
+%
+% o random_info: the random info.
+%
+*/
+MagickPrivate double GetRandomInfoNormalize(const RandomInfo *random_info)
+{
+ assert(random_info != (const RandomInfo *) NULL);
+ return(random_info->normalize);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ G e t R a n d o m I n f o S e e d %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% GetRandomInfoSeed() returns the random seed.
+%
+% The format of the GetRandomInfoSeed method is:
+%
+% unsigned long *GetRandomInfoSeed(RandomInfo *random_info)
+%
+% A description of each parameter follows:
+%
+% o random_info: the random info.
+%
+*/
+MagickPrivate unsigned long *GetRandomInfoSeed(RandomInfo *random_info)
+{
+ assert(random_info != (RandomInfo *) NULL);
+ return(random_info->seed);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% G e t R a n d o m K e y %
% %
% %
*/
MagickPrivate MagickBooleanType RandomComponentGenesis(void)
{
- random_semaphore=AcquireSemaphoreInfo();
+ if (random_semaphore == (SemaphoreInfo *) NULL)
+ random_semaphore=AcquireSemaphoreInfo();
return(MagickTrue);
}
\f
{
gather_true_random=true_random;
}
-
-MagickPrivate unsigned long *GetRandomInfoSeed(RandomInfo *random_info)
-{
- assert(random_info != (RandomInfo *) NULL);
- return random_info->seed;
-}
-
-MagickPrivate double GetRandomInfoNormalize(RandomInfo *random_info)
-{
- assert(random_info != (RandomInfo *) NULL);
- return random_info->normalize;
-}