Make fips_gettime work on Win32 (lets hope the Win32 function we use
is OK with NIST. Otherwise, we have a problem). Avoid depending on 32-bit longs. Provided by Dr Stephen Henson <shenson@drh-consultancy.co.uk>
This commit is contained in:
parent
1e4ae04e79
commit
0ae9a77679
@ -1,2 +1,2 @@
|
|||||||
HMAC-SHA1(fips_rand.c)= f65f82a78988b284668d51497f06a0fd029b17f8
|
HMAC-SHA1(fips_rand.c)= 26921aa3f66397c57791f7c015c053ce84532e54
|
||||||
HMAC-SHA1(fips_rand.h)= 72cff1a7ca7f33fe9df6b9da30e6420874eeb623
|
HMAC-SHA1(fips_rand.h)= 72cff1a7ca7f33fe9df6b9da30e6420874eeb623
|
||||||
|
@ -57,13 +57,17 @@
|
|||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <openssl/fips_rand.h>
|
#include <openssl/fips_rand.h>
|
||||||
#include "e_os.h"
|
#include "e_os.h"
|
||||||
|
#ifndef OPENSSL_SYS_WIN32
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#ifndef OPENSSL_SYS_WIN32
|
||||||
# ifdef OPENSSL_UNISTD
|
# ifdef OPENSSL_UNISTD
|
||||||
# include OPENSSL_UNISTD
|
# include OPENSSL_UNISTD
|
||||||
# else
|
# else
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define SEED_SIZE 8
|
#define SEED_SIZE 8
|
||||||
@ -117,7 +121,11 @@ int FIPS_rand_seeded()
|
|||||||
|
|
||||||
static void fips_gettime(unsigned char buf[8])
|
static void fips_gettime(unsigned char buf[8])
|
||||||
{
|
{
|
||||||
|
#ifdef OPENSSL_SYS_WIN32
|
||||||
|
FILETIME ft;
|
||||||
|
#else
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
#endif
|
||||||
|
|
||||||
if(test_mode)
|
if(test_mode)
|
||||||
{
|
{
|
||||||
@ -125,10 +133,27 @@ static void fips_gettime(unsigned char buf[8])
|
|||||||
memcpy(buf,test_faketime,sizeof test_faketime);
|
memcpy(buf,test_faketime,sizeof test_faketime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#ifdef OPENSSL_SYS_WIN32
|
||||||
|
GetSystemTimeAsFileTime(&ft);
|
||||||
|
buf[0] = (unsigned char) (ft.dwHighDateTime & 0xff);
|
||||||
|
buf[1] = (unsigned char) ((ft.dwHighDateTime >> 8) & 0xff);
|
||||||
|
buf[2] = (unsigned char) ((ft.dwHighDateTime >> 16) & 0xff);
|
||||||
|
buf[3] = (unsigned char) ((ft.dwHighDateTime >> 24) & 0xff);
|
||||||
|
buf[4] = (unsigned char) (ft.dwLowDateTime & 0xff);
|
||||||
|
buf[5] = (unsigned char) ((ft.dwLowDateTime >> 8) & 0xff);
|
||||||
|
buf[6] = (unsigned char) ((ft.dwLowDateTime >> 16) & 0xff);
|
||||||
|
buf[7] = (unsigned char) ((ft.dwLowDateTime >> 24) & 0xff);
|
||||||
|
#else
|
||||||
gettimeofday(&tv,NULL);
|
gettimeofday(&tv,NULL);
|
||||||
assert(sizeof(long) == 4);
|
buf[0] = (unsigned char) (tv.tv_sec & 0xff);
|
||||||
memcpy (&buf[0],&tv.tv_sec,4);
|
buf[1] = (unsigned char) ((tv.tv_sec >> 8) & 0xff);
|
||||||
memcpy (&buf[4],&tv.tv_usec,4);
|
buf[2] = (unsigned char) ((tv.tv_sec >> 16) & 0xff);
|
||||||
|
buf[3] = (unsigned char) ((tv.tv_sec >> 24) & 0xff);
|
||||||
|
buf[4] = (unsigned char) (tv.tv_usec & 0xff);
|
||||||
|
buf[5] = (unsigned char) ((tv.tv_usec >> 8) & 0xff);
|
||||||
|
buf[6] = (unsigned char) ((tv.tv_usec >> 16) & 0xff);
|
||||||
|
buf[7] = (unsigned char) ((tv.tv_usec >> 24) & 0xff);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 0 /* This eminently sensible strategy is not acceptable to NIST. Sigh. */
|
#if 0 /* This eminently sensible strategy is not acceptable to NIST. Sigh. */
|
||||||
#ifndef GETPID_IS_MEANINGLESS
|
#ifndef GETPID_IS_MEANINGLESS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user