mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 15:18:20 +00:00
Add utility function to access first random seed.
This commit is contained in:
parent
a6d7b7856e
commit
d2d8aff814
2 changed files with 18 additions and 0 deletions
13
src/util.cc
13
src/util.cc
|
@ -716,6 +716,8 @@ static bool write_random_seeds(const char* write_file, uint32 seed,
|
||||||
|
|
||||||
static bool bro_rand_determistic = false;
|
static bool bro_rand_determistic = false;
|
||||||
static unsigned int bro_rand_state = 0;
|
static unsigned int bro_rand_state = 0;
|
||||||
|
static bool first_seed_saved = false;
|
||||||
|
static unsigned int first_seed = 0;
|
||||||
|
|
||||||
static void bro_srandom(unsigned int seed, bool deterministic)
|
static void bro_srandom(unsigned int seed, bool deterministic)
|
||||||
{
|
{
|
||||||
|
@ -800,6 +802,12 @@ void init_random_seed(uint32 seed, const char* read_file, const char* write_file
|
||||||
|
|
||||||
bro_srandom(seed, seeds_done);
|
bro_srandom(seed, seeds_done);
|
||||||
|
|
||||||
|
if ( ! first_seed_saved )
|
||||||
|
{
|
||||||
|
first_seed = seed;
|
||||||
|
first_seed_saved = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! hmac_key_set )
|
if ( ! hmac_key_set )
|
||||||
{
|
{
|
||||||
MD5((const u_char*) buf, sizeof(buf), shared_hmac_md5_key);
|
MD5((const u_char*) buf, sizeof(buf), shared_hmac_md5_key);
|
||||||
|
@ -811,6 +819,11 @@ void init_random_seed(uint32 seed, const char* read_file, const char* write_file
|
||||||
write_file);
|
write_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int initial_seed()
|
||||||
|
{
|
||||||
|
return first_seed;
|
||||||
|
}
|
||||||
|
|
||||||
bool have_random_seed()
|
bool have_random_seed()
|
||||||
{
|
{
|
||||||
return bro_rand_determistic;
|
return bro_rand_determistic;
|
||||||
|
|
|
@ -165,6 +165,11 @@ extern void hmac_md5(size_t size, const unsigned char* bytes,
|
||||||
extern void init_random_seed(uint32 seed, const char* load_file,
|
extern void init_random_seed(uint32 seed, const char* load_file,
|
||||||
const char* write_file);
|
const char* write_file);
|
||||||
|
|
||||||
|
// Retrieves the initial seed computed after the very first call to
|
||||||
|
// init_random_seed(). Repeated calls to init_random_seed() will not affect the
|
||||||
|
// return value of this function.
|
||||||
|
unsigned int initial_seed();
|
||||||
|
|
||||||
// Returns true if the user explicitly set a seed via init_random_seed();
|
// Returns true if the user explicitly set a seed via init_random_seed();
|
||||||
extern bool have_random_seed();
|
extern bool have_random_seed();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue