Use the PRNG class for chaff

In particular, srand( time( NULL ) ) is very predictable.

[keithw@mit.edu -- modified to use byte PRNG from /dev/urandom]
This commit is contained in:
Keegan McAllister
2012-03-19 01:22:54 -04:00
parent 40d69da5e6
commit 4eb3cace0b
2 changed files with 9 additions and 8 deletions
+5 -7
View File
@@ -46,9 +46,9 @@ TransportSender<MyState>::TransportSender( Connection *s_connection, MyState &in
ack_num( 0 ),
pending_data_ack( false ),
SEND_MINDELAY( 15 ),
last_heard( 0 )
last_heard( 0 ),
prng()
{
srand( time( NULL ) ); /* for chaff */
}
/* Try to send roughly two frames per RTT, bounded by limits on frame rate */
@@ -263,13 +263,11 @@ void TransportSender<MyState>::rationalize_states( void )
template <class MyState>
const string TransportSender<MyState>::make_chaff( void )
{
const int CHAFF_MAX = 16;
const size_t CHAFF_MAX = 16;
const size_t chaff_len = prng.uint8() % (CHAFF_MAX + 1);
char chaff[ CHAFF_MAX ];
for ( int i = 0; i < CHAFF_MAX; i++ ) {
chaff[ i ] = rand() % 256;
}
int chaff_len = rand() % (CHAFF_MAX + 1);
prng.fill( chaff, chaff_len );
return string( chaff, chaff_len );
}
+4 -1
View File
@@ -27,6 +27,7 @@
#include "transportinstruction.pb.h"
#include "transportstate.h"
#include "transportfragment.h"
#include "prng.h"
using std::list;
using std::pair;
@@ -86,7 +87,9 @@ namespace Network {
uint64_t last_heard; /* last time received new state */
static const string make_chaff( void );
/* chaff to disguise instruction length */
PRNG prng;
const string make_chaff( void );
public:
/* constructor */