public SaltyRandomGenerator( SaltyRandomGenerator clone ) { this.entropy = clone.entropy; this.bits_avail = clone.bits_avail; this.bits_used = clone.bits_used; this.getsalt = clone.getsalt; }
static void srg_getsalt( SaltyRandomGenerator.SaltData add_data_here ) { add_data_here = add_data_here + BitConverter.GetBytes( 0 ); //DateTime.Now.ToBinary() ); }
public static void Test() { SaltyRandomGenerator srg = new SaltyRandomGenerator(); srg.getsalt += srg_getsalt; BitCollector collector = new BitCollector( 512 ); int bits; int n; for( bits = 1; bits < 28; bits++ ) { srg.Reset(); collector.Clear(); for( n = 0; n < ( 512 - bits ); n += bits ) { int value = srg.GetEntropy( bits, false ); collector.AddBits( (uint)value, bits ); } { int final_value = srg.GetEntropy( 512 - n, false ); collector.AddBits( (uint)final_value, 512 - n ); } byte[] one = srg.entropy; byte[] two = collector.buffer; for( n = 0; n < 512 / 8; n++ ) { if( one[n] != two[n] ) Console.WriteLine( "Byte " + n + " differed " + one[n].ToString( "x" ) + " " + two[n].ToString( "x" ) ); } } for( bits = 1; bits < 28; bits++ ) { srg.Reset(); collector.Clear(); for( n = 0; n < ( 512 - bits ); n += bits ) { int value = srg.GetEntropy( bits, true ); collector.AddBits( (uint)value, bits ); //Console.WriteLine( "data is : " + value ); } { int final_value = srg.GetEntropy( 512 - n, false ); collector.AddBits( (uint)final_value, 512 - n ); } byte[] one = srg.entropy; byte[] two = collector.buffer; for( n = 0; n < 512 / 8; n++ ) { if( one[n] != two[n] ) Console.WriteLine( "Byte " + n + " differed " + one[n].ToString( "x" ) + " " + two[n].ToString( "x" ) ); } } }