changed random number generator

This commit is contained in:
Klaus K Wilting 2018-04-01 13:16:59 +02:00
parent c1c6dda221
commit 78ead0f0ce
3 changed files with 6 additions and 8 deletions

View File

@ -219,8 +219,7 @@ void wifi_sniffer_loop(void * pvParameters) {
// clear counter if not in cumulative counter mode
if (cfg.countermode != 1) {
macs.clear(); // clear macs container
srand(temperatureRead()); // use chip temperature for pseudorandom generator init
salt = rand() % 256; // get new random int between 0 and 255 for salting MAC hashes
salt = random(65536); // get new 16bit random for salting hashes
macnum = 0;
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
ESP_LOGI(TAG, "Scan cycle completed, new salt value: %i", salt);
@ -384,9 +383,8 @@ void setup() {
antenna_init();
#endif
// initialize pseudorandom generator and salt value
srand(temperatureRead()); // use chip temperature for pseudorandom generator init
salt = rand() % 256; // get new random int between 0 and 255 for salting MAC hashes
// initialize salt value using esp_random() called by random in arduino-esp32 core
salt = random(65536); // get new 16bit random for salting hashes
// initialize display
init_display(PROGNAME, PROGVERSION);

View File

@ -69,7 +69,7 @@ void set_reset(int val) {
ESP_LOGI(TAG, "Remote command: reset MAC counter");
macs.clear(); // clear macs container
macnum = 0;
salt = rand() % 256; // get new random int between 0 and 255 for salting MAC hashes
salt = random(65536); // get new 16bit random for salting hashes
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
u8x8.clearLine(5);
u8x8.setCursor(0, 5);

View File

@ -79,8 +79,8 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) {
//if (!(addr2int & WIFI_MAC_FILTER_MASK)) { // filter local and group MACs
// salt and hash MAC, and if new unique one, store hash in container and increment counter on display
addr2int <<= 8; // left shift out msb of vendor oui
addr2int += salt; // append salt value to MAC before hashing it
addr2int <<= 16; // left shift out 2 bytes of vendor oui to give space for salt
addr2int |= salt; // append salt value to MAC before hashing it
itoa(addr2int, macbuf, 10); // convert 64 bit MAC to base 10 decimal string
hashedmac = rokkit(macbuf, 5); // hash MAC for privacy, use 5 chars to fit in uint16_t container
newmac = macs.insert(hashedmac); // store hashed MAC if new unique