Merge commit '01d245ef4392152dbdc78a6ba4dfa0a6e8b08e6f'

* commit '01d245ef4392152dbdc78a6ba4dfa0a6e8b08e6f':
  random_seed: Rewrite the generic clock() based seed code

Conflicts:
	libavutil/random_seed.c

See: 66531c75d3
Merged-by: Michael Niedermayer <michaelni@gmx.at>
pull/53/head
Michael Niedermayer 11 years ago
commit 00f25e0a99
  1. 18
      libavutil/random_seed.c

@ -33,10 +33,10 @@
#include <string.h> #include <string.h>
#include "avassert.h" #include "avassert.h"
#include "internal.h" #include "internal.h"
#include "intreadwrite.h"
#include "timer.h" #include "timer.h"
#include "random_seed.h" #include "random_seed.h"
#include "sha.h" #include "sha.h"
#include "intreadwrite.h"
#ifndef TEST #ifndef TEST
#define TEST 0 #define TEST 0
@ -65,7 +65,7 @@ static uint32_t get_generic_seed(void)
struct AVSHA *sha = (void*)tmp; struct AVSHA *sha = (void*)tmp;
clock_t last_t = 0; clock_t last_t = 0;
static uint64_t i = 0; static uint64_t i = 0;
static uint32_t buffer[512] = {0}; static uint32_t buffer[512] = { 0 };
unsigned char digest[20]; unsigned char digest[20];
uint64_t last_i = i; uint64_t last_i = i;
@ -84,11 +84,11 @@ static uint32_t get_generic_seed(void)
for (;;) { for (;;) {
clock_t t = clock(); clock_t t = clock();
if(last_t == t){ if (last_t == t) {
buffer[i&511]++; buffer[i & 511]++;
}else{ } else {
buffer[++i&511]+= (t-last_t) % 3294638521U; buffer[++i & 511] += (t - last_t) % 3294638521U;
if(last_i && i-last_i > 4 || i-last_i > 64 || TEST && i-last_i > 8) if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
break; break;
} }
last_t = t; last_t = t;
@ -98,9 +98,9 @@ static uint32_t get_generic_seed(void)
buffer[0] = buffer[1] = 0; buffer[0] = buffer[1] = 0;
av_sha_init(sha, 160); av_sha_init(sha, 160);
av_sha_update(sha, (uint8_t*)buffer, sizeof(buffer)); av_sha_update(sha, (const uint8_t *)buffer, sizeof(buffer));
av_sha_final(sha, digest); av_sha_final(sha, digest);
return AV_RB32(digest) + AV_RB32(digest+16); return AV_RB32(digest) + AV_RB32(digest + 16);
} }
uint32_t av_get_random_seed(void) uint32_t av_get_random_seed(void)

Loading…
Cancel
Save