summaryrefslogtreecommitdiff
path: root/src/KM_prng.cpp
diff options
context:
space:
mode:
authorjhurst <jhurst@cinecert.com>2006-04-21 17:32:06 +0000
committerjhurst <>2006-04-21 17:32:06 +0000
commit4e83acbf365d9b87dfdc95aef5c46785b33d2269 (patch)
treeffb7c03653dae138339b79a5f52f4986061f4eb3 /src/KM_prng.cpp
parent34464c5616c053942cf7bdbb919bd8845cb0ceae (diff)
kumu merge
Diffstat (limited to 'src/KM_prng.cpp')
-rwxr-xr-xsrc/KM_prng.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/KM_prng.cpp b/src/KM_prng.cpp
index 5e3dd48..c51b2db 100755
--- a/src/KM_prng.cpp
+++ b/src/KM_prng.cpp
@@ -43,18 +43,24 @@ using namespace Kumu;
#ifdef KM_WIN32
// make up a byte by sampling the perf counter LSB
-static byte_t get_perf_byte()
+static byte_t get_perf_byte(byte_t carry)
{
LARGE_INTEGER ticks;
- byte_t retval;
-
- for ( int i = 0; i < 8; i++ )
+ byte_t sha_buf[20];
+ SHA_CTX SHA;
+ SHA1_Init(&SHA);
+ SHA1_Update(&SHA, &carry, sizeof(byte_t));
+
+ for ( int i = 0; i < 128; i++ )
{
QueryPerformanceCounter(&ticks);
- retval |= (ticks.LowPart & 0x00000001) << i;
+ SHA1_Update(&SHA, &ticks.LowPart, sizeof(ticks.LowPart));
}
- return retval;
+ SHA1_Final(sha_buf, &SHA);
+
+ fprintf(stderr, "0x%02x ", sha_buf[0]);
+ return sha_buf[0];
}
#else // KM_WIN32
@@ -92,8 +98,10 @@ public:
#ifdef KM_WIN32
for ( ui32_t i = 0; i < RNG_KEY_SIZE; i++ )
- rng_key[i] = get_perf_byte();
-
+ {
+ byte_t carry = ( i == 0 ) ? 0xa3 : rng_key[i-1];
+ rng_key[i] = get_perf_byte(carry);
+ }
#else // KM_WIN32
// on POSIX systems we simply read some seed from /dev/urandom
FileReader URandom;