From 499ed5b566a951a3a092e88e416de322677b5ca7 Mon Sep 17 00:00:00 2001 From: Johanna Amann Date: Wed, 13 Jul 2016 16:40:47 -0700 Subject: [PATCH] Remove the -K/-J options for setting keys. The options were never really used and do not seem especially useful; initialization with a seed file still works. This also fixes a bug with the initialization of the siphash key. --- src/main.cc | 18 ++---------------- src/util.cc | 5 +++-- src/util.h | 3 +-- .../btest/Baseline/bifs.hll_large_estimate/out | 3 ++- testing/btest/bifs/hll_large_estimate.bro | 8 +++++++- testing/btest/random.seed | 8 ++++---- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/main.cc b/src/main.cc index c75bf3ee1b..fd462f4996 100644 --- a/src/main.cc +++ b/src/main.cc @@ -190,8 +190,6 @@ void usage() fprintf(stderr, " -G|--load-seeds | load seeds from given file\n"); fprintf(stderr, " -H|--save-seeds | save seeds to given file\n"); fprintf(stderr, " -I|--print-id | print out given ID\n"); - fprintf(stderr, " -J|--set-seed | set the random number seed\n"); - fprintf(stderr, " -K|--md5-hashkey | set key for MD5-keyed hashing\n"); fprintf(stderr, " -N|--print-plugins | print available plugins and exit (-NN for verbose)\n"); fprintf(stderr, " -P|--prime-dns | prime DNS\n"); fprintf(stderr, " -Q|--time | print execution time summary to stderr\n"); @@ -459,7 +457,6 @@ int main(int argc, char** argv) char* debug_streams = 0; int parse_only = false; int bare_mode = false; - int seed = 0; int dump_cfg = false; int to_xml = 0; int do_watchdog = 0; @@ -491,8 +488,6 @@ int main(int argc, char** argv) {"force-dns", no_argument, 0, 'F'}, {"load-seeds", required_argument, 0, 'G'}, {"save-seeds", required_argument, 0, 'H'}, - {"set-seed", required_argument, 0, 'J'}, - {"md5-hashkey", required_argument, 0, 'K'}, {"print-plugins", no_argument, 0, 'N'}, {"prime-dns", no_argument, 0, 'P'}, {"time", no_argument, 0, 'Q'}, @@ -546,7 +541,7 @@ int main(int argc, char** argv) opterr = 0; char opts[256]; - safe_strncpy(opts, "B:e:f:G:H:I:i:J:K:n:p:R:r:s:T:t:U:w:x:X:z:CFNPQSWabdghv", + safe_strncpy(opts, "B:e:f:G:H:I:i:n:p:R:r:s:T:t:U:w:x:X:z:CFNPQSWabdghv", sizeof(opts)); #ifdef USE_PERFTOOLS_DEBUG @@ -661,15 +656,6 @@ int main(int argc, char** argv) id_name = optarg; break; - case 'J': - seed = atoi(optarg); - break; - - case 'K': - MD5((const u_char*) optarg, strlen(optarg), shared_hmac_md5_key); - hmac_key_set = true; - break; - case 'N': ++print_plugins; break; @@ -760,7 +746,7 @@ int main(int argc, char** argv) } #endif - init_random_seed(seed, (seed_load_file && *seed_load_file ? seed_load_file : 0) , seed_save_file); + init_random_seed((seed_load_file && *seed_load_file ? seed_load_file : 0) , seed_save_file); // DEBUG_MSG("HMAC key: %s\n", md5_digest_print(shared_hmac_md5_key)); init_hash_function(); diff --git a/src/util.cc b/src/util.cc index 489b10e112..64991efb6a 100644 --- a/src/util.cc +++ b/src/util.cc @@ -791,13 +791,14 @@ void bro_srandom(unsigned int seed) srandom(seed); } -void init_random_seed(uint32 seed, const char* read_file, const char* write_file) +void init_random_seed(const char* read_file, const char* write_file) { static const int bufsiz = 20; uint32 buf[bufsiz]; memset(buf, 0, sizeof(buf)); int pos = 0; // accumulates entropy bool seeds_done = false; + uint32 seed = 0; if ( read_file ) { @@ -870,7 +871,7 @@ void init_random_seed(uint32 seed, const char* read_file, const char* write_file if ( ! siphash_key_set ) { assert(sizeof(buf)-64 == 16); - memcpy(shared_siphash_key, buf+64, 16); + memcpy(shared_siphash_key, reinterpret_cast(buf)+64, 16); siphash_key_set = true; } diff --git a/src/util.h b/src/util.h index e6ba7f348b..b894ad4c48 100644 --- a/src/util.h +++ b/src/util.h @@ -195,8 +195,7 @@ extern void hmac_md5(size_t size, const unsigned char* bytes, // over the "seed" argument. If write_file is given, the seeds are written // to that file. // -extern void init_random_seed(uint32 seed, const char* load_file, - const char* write_file); +extern void init_random_seed(const char* load_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 diff --git a/testing/btest/Baseline/bifs.hll_large_estimate/out b/testing/btest/Baseline/bifs.hll_large_estimate/out index f5581664d7..6897673f4e 100644 --- a/testing/btest/Baseline/bifs.hll_large_estimate/out +++ b/testing/btest/Baseline/bifs.hll_large_estimate/out @@ -1,2 +1,3 @@ +Ok error 171249.90868 -171249.90868 +Ok error diff --git a/testing/btest/bifs/hll_large_estimate.bro b/testing/btest/bifs/hll_large_estimate.bro index db2eee70ae..0f2df046b9 100644 --- a/testing/btest/bifs/hll_large_estimate.bro +++ b/testing/btest/bifs/hll_large_estimate.bro @@ -2,7 +2,8 @@ # Test the quality of HLL once by checking adding a large number of IP entries. # # @TEST-EXEC: bro %INPUT > out -# @TEST-EXEC: BRO_SEED_FILE="" bro %INPUT >> out +# @TEST-EXEC: BRO_SEED_FILE="" bro %INPUT > out2 +# @TEST-EXEC: head -n1 out2 >> out # @TEST-EXEC: btest-diff out event bro_init() @@ -15,5 +16,10 @@ event bro_init() hll_cardinality_add(cp, count_to_v4_addr(base+i)); } + if ( |hll_cardinality_estimate(cp) - 170000| > 10000 ) + print "Big error"; + else + print "Ok error"; + print hll_cardinality_estimate(cp); } diff --git a/testing/btest/random.seed b/testing/btest/random.seed index 560e74f4a1..6956a2c19a 100644 --- a/testing/btest/random.seed +++ b/testing/btest/random.seed @@ -15,7 +15,7 @@ 3912865238 3596260151 517973768 -3606168384 -119014752 -1013039866 -2458585167 +1462428821 +0 +2278350848 +32767