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:
@@ -46,9 +46,9 @@ TransportSender<MyState>::TransportSender( Connection *s_connection, MyState &in
|
|||||||
ack_num( 0 ),
|
ack_num( 0 ),
|
||||||
pending_data_ack( false ),
|
pending_data_ack( false ),
|
||||||
SEND_MINDELAY( 15 ),
|
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 */
|
/* 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>
|
template <class MyState>
|
||||||
const string TransportSender<MyState>::make_chaff( void )
|
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 ];
|
char chaff[ CHAFF_MAX ];
|
||||||
for ( int i = 0; i < CHAFF_MAX; i++ ) {
|
prng.fill( chaff, chaff_len );
|
||||||
chaff[ i ] = rand() % 256;
|
|
||||||
}
|
|
||||||
int chaff_len = rand() % (CHAFF_MAX + 1);
|
|
||||||
return string( chaff, chaff_len );
|
return string( chaff, chaff_len );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "transportinstruction.pb.h"
|
#include "transportinstruction.pb.h"
|
||||||
#include "transportstate.h"
|
#include "transportstate.h"
|
||||||
#include "transportfragment.h"
|
#include "transportfragment.h"
|
||||||
|
#include "prng.h"
|
||||||
|
|
||||||
using std::list;
|
using std::list;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
@@ -86,7 +87,9 @@ namespace Network {
|
|||||||
|
|
||||||
uint64_t last_heard; /* last time received new state */
|
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:
|
public:
|
||||||
/* constructor */
|
/* constructor */
|
||||||
|
|||||||
Reference in New Issue
Block a user