mirror of
git://erdgeist.org/opentracker
synced 2025-04-01 02:52:57 +08:00
Use arc4random whereever we need strong entropy
This commit is contained in:
parent
ccef1d0ccd
commit
b73b3b17cc
5
Makefile
5
Makefile
@ -39,6 +39,10 @@ BINDIR?=$(PREFIX)/bin
|
|||||||
FEATURES+=-DWANT_DEV_RANDOM
|
FEATURES+=-DWANT_DEV_RANDOM
|
||||||
FEATURES+=-DWANT_FULLSCRAPE
|
FEATURES+=-DWANT_FULLSCRAPE
|
||||||
|
|
||||||
|
# Is enabled on BSD systems by default in trackerlogic.h
|
||||||
|
# on Linux systems you will need -lbds
|
||||||
|
#FEATURES+=-DWANT_ARC4RANDOM
|
||||||
|
|
||||||
#FEATURES+=-D_DEBUG_HTTPERROR
|
#FEATURES+=-D_DEBUG_HTTPERROR
|
||||||
|
|
||||||
OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage
|
OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage
|
||||||
@ -46,6 +50,7 @@ OPTS_production=-O3
|
|||||||
|
|
||||||
CFLAGS+=-I$(LIBOWFAT_HEADERS) -Wall -pipe -Wextra #-ansi -pedantic
|
CFLAGS+=-I$(LIBOWFAT_HEADERS) -Wall -pipe -Wextra #-ansi -pedantic
|
||||||
LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread -lpthread -lz
|
LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread -lpthread -lz
|
||||||
|
#LDFLAGS+=-lbsd
|
||||||
|
|
||||||
BINARY =opentracker
|
BINARY =opentracker
|
||||||
HEADERS=trackerlogic.h scan_urlencoded_query.h ot_mutex.h ot_stats.h ot_vector.h ot_clean.h ot_udp.h ot_iovec.h ot_fullscrape.h ot_accesslist.h ot_http.h ot_livesync.h ot_rijndael.h
|
HEADERS=trackerlogic.h scan_urlencoded_query.h ot_mutex.h ot_stats.h ot_vector.h ot_clean.h ot_udp.h ot_iovec.h ot_fullscrape.h ot_accesslist.h ot_http.h ot_livesync.h ot_rijndael.h
|
||||||
|
@ -256,11 +256,17 @@ static void * server_mainloop( void * args ) {
|
|||||||
#ifdef _DEBUG_HTTPERROR
|
#ifdef _DEBUG_HTTPERROR
|
||||||
ws.debugbuf= malloc( G_DEBUGBUF_SIZE );
|
ws.debugbuf= malloc( G_DEBUGBUF_SIZE );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( !ws.inbuf || !ws.outbuf )
|
if( !ws.inbuf || !ws.outbuf )
|
||||||
panic( "Initializing worker failed" );
|
panic( "Initializing worker failed" );
|
||||||
|
|
||||||
|
#ifdef WANT_ARC4RANDOM
|
||||||
|
arc4random_buf(&ws.rand48_state[0], 3 * sizeof(uint16_t));
|
||||||
|
#else
|
||||||
ws.rand48_state[0] = (uint16_t)random();
|
ws.rand48_state[0] = (uint16_t)random();
|
||||||
ws.rand48_state[1] = (uint16_t)random();
|
ws.rand48_state[1] = (uint16_t)random();
|
||||||
ws.rand48_state[2] = (uint16_t)random();
|
ws.rand48_state[2] = (uint16_t)random();
|
||||||
|
#endif
|
||||||
|
|
||||||
for( ; ; ) {
|
for( ; ; ) {
|
||||||
int64 sock;
|
int64 sock;
|
||||||
|
12
ot_udp.c
12
ot_udp.c
@ -29,13 +29,21 @@ static ot_time g_hour_of_the_key;
|
|||||||
|
|
||||||
static void udp_generate_rijndael_round_key() {
|
static void udp_generate_rijndael_round_key() {
|
||||||
uint32_t key[16];
|
uint32_t key[16];
|
||||||
|
#ifdef WANT_ARC4RANDOM
|
||||||
|
arc4random_buf(&key[0], sizeof(key));
|
||||||
|
#else
|
||||||
key[0] = random();
|
key[0] = random();
|
||||||
key[1] = random();
|
key[1] = random();
|
||||||
key[2] = random();
|
key[2] = random();
|
||||||
key[3] = random();
|
key[3] = random();
|
||||||
|
#endif
|
||||||
rijndaelKeySetupEnc128( g_rijndael_round_key, (uint8_t*)key );
|
rijndaelKeySetupEnc128( g_rijndael_round_key, (uint8_t*)key );
|
||||||
|
|
||||||
|
#ifdef WANT_ARC4RANDOM
|
||||||
|
g_key_of_the_hour[0] = arc4random();
|
||||||
|
#else
|
||||||
g_key_of_the_hour[0] = random();
|
g_key_of_the_hour[0] = random();
|
||||||
|
#endif
|
||||||
g_hour_of_the_key = g_now_minutes;
|
g_hour_of_the_key = g_now_minutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +54,11 @@ static void udp_make_connectionid( uint32_t connid[2], const ot_ip6 remoteip, in
|
|||||||
if( g_now_minutes + 60 > g_hour_of_the_key ) {
|
if( g_now_minutes + 60 > g_hour_of_the_key ) {
|
||||||
g_hour_of_the_key = g_now_minutes;
|
g_hour_of_the_key = g_now_minutes;
|
||||||
g_key_of_the_hour[1] = g_key_of_the_hour[0];
|
g_key_of_the_hour[1] = g_key_of_the_hour[0];
|
||||||
|
#ifdef WANT_ARC4RANDOM
|
||||||
|
g_key_of_the_hour[0] = arc4random();
|
||||||
|
#else
|
||||||
g_key_of_the_hour[0] = random();
|
g_key_of_the_hour[0] = random();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy( plain, remoteip, sizeof( plain ) );
|
memcpy( plain, remoteip, sizeof( plain ) );
|
||||||
|
4
proxy.c
4
proxy.c
@ -553,7 +553,11 @@ int main( int argc, char **argv ) {
|
|||||||
int scanon = 1, lbound = 0, sbound = 0;
|
int scanon = 1, lbound = 0, sbound = 0;
|
||||||
|
|
||||||
srandom( time(NULL) );
|
srandom( time(NULL) );
|
||||||
|
#ifdef WANT_ARC4RANDOM
|
||||||
|
g_tracker_id = arc4random();
|
||||||
|
#else
|
||||||
g_tracker_id = random();
|
g_tracker_id = random();
|
||||||
|
#endif
|
||||||
noipv6=1;
|
noipv6=1;
|
||||||
|
|
||||||
while( scanon ) {
|
while( scanon ) {
|
||||||
|
@ -12,6 +12,13 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#if defined(__linux__) && defined(WANT_ARC4RANDOM)
|
||||||
|
#include <bsd/stdlib.h>
|
||||||
|
#endif
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#define WANT_ARC4RANDOM
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef uint8_t ot_hash[20];
|
typedef uint8_t ot_hash[20];
|
||||||
typedef time_t ot_time;
|
typedef time_t ot_time;
|
||||||
typedef char ot_ip6[16];
|
typedef char ot_ip6[16];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user