@@ -10,10 +10,12 @@ namespace Shadowsocks.Obfs
10
10
class xorshift128plus
11
11
{
12
12
protected UInt64 v0 , v1 ;
13
+ protected int init_loop ;
13
14
14
- public xorshift128plus ( )
15
+ public xorshift128plus ( int init_loop_ = 4 )
15
16
{
16
17
v0 = v1 = 0 ;
18
+ init_loop = init_loop_ ;
17
19
}
18
20
19
21
public UInt64 next ( )
@@ -42,7 +44,7 @@ public void init_from_bin(byte[] bytes, int datalength)
42
44
BitConverter . GetBytes ( ( ushort ) datalength ) . CopyTo ( fill_bytes , 0 ) ;
43
45
v0 = BitConverter . ToUInt64 ( fill_bytes , 0 ) ;
44
46
v1 = BitConverter . ToUInt64 ( fill_bytes , 8 ) ;
45
- for ( int i = 0 ; i < 4 ; ++ i )
47
+ for ( int i = 0 ; i < init_loop ; ++ i )
46
48
{
47
49
next ( ) ;
48
50
}
@@ -202,6 +204,11 @@ public void PackData(byte[] data, int datalength, byte[] outdata, out int outlen
202
204
}
203
205
}
204
206
207
+ public virtual void OnInitAuthData ( UInt64 unixTimestamp )
208
+ {
209
+
210
+ }
211
+
205
212
public void PackAuthData ( byte [ ] data , int datalength , byte [ ] outdata , out int outlength )
206
213
{
207
214
const int authhead_len = 4 + 8 + 4 + 16 + 4 ;
@@ -234,6 +241,7 @@ public void PackAuthData(byte[] data, int datalength, byte[] outdata, out int ou
234
241
UInt64 utc_time_second = ( UInt64 ) Math . Floor ( DateTime . UtcNow . Subtract ( new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 ) ) . TotalSeconds ) ;
235
242
UInt32 utc_time = ( UInt32 ) ( utc_time_second ) ;
236
243
Array . Copy ( BitConverter . GetBytes ( utc_time ) , 0 , encrypt , 0 , 4 ) ;
244
+ OnInitAuthData ( utc_time_second ) ;
237
245
238
246
encrypt [ 12 ] = ( byte ) ( Server . overhead ) ;
239
247
encrypt [ 13 ] = ( byte ) ( Server . overhead >> 8 ) ;
@@ -572,7 +580,7 @@ public override Dictionary<string, int[]> GetObfs()
572
580
return _obfs ;
573
581
}
574
582
575
- protected void InitDataSizeList ( )
583
+ protected virtual void InitDataSizeList ( )
576
584
{
577
585
xorshift128plus random = new xorshift128plus ( ) ;
578
586
random . init_from_bin ( Server . key ) ;
@@ -683,7 +691,7 @@ public override Dictionary<string, int[]> GetObfs()
683
691
return _obfs ;
684
692
}
685
693
686
- protected new void InitDataSizeList ( )
694
+ protected override void InitDataSizeList ( )
687
695
{
688
696
xorshift128plus random = new xorshift128plus ( ) ;
689
697
random . init_from_bin ( Server . key ) ;
@@ -760,7 +768,7 @@ protected void CheckAndPatchDataSize(List<int> data_list, xorshift128plus random
760
768
}
761
769
}
762
770
763
- protected new void InitDataSizeList ( )
771
+ protected override void InitDataSizeList ( )
764
772
{
765
773
xorshift128plus random = new xorshift128plus ( ) ;
766
774
random . init_from_bin ( Server . key ) ;
@@ -866,7 +874,7 @@ public override Dictionary<string, int[]> GetObfs()
866
874
protected UInt64 key_change_datetime_key ;
867
875
protected List < byte > key_change_datetime_key_bytes = new List < byte > ( ) ;
868
876
869
- protected new void InitDataSizeList ( )
877
+ protected override void InitDataSizeList ( )
870
878
{
871
879
xorshift128plus random = new xorshift128plus ( ) ;
872
880
byte [ ] newKey = new byte [ Server . key . Length ] ;
@@ -908,8 +916,10 @@ public override void SetServerInfo(ServerInfo serverInfo)
908
916
key_change_interval = interval ;
909
917
}
910
918
}
911
- // https://stackoverflow.com/a/17632585/3548568
912
- UInt64 unixTimestamp = ( UInt64 ) ( DateTime . UtcNow . Subtract ( new DateTime ( 1970 , 1 , 1 ) ) . TotalSeconds ) ;
919
+ }
920
+
921
+ public override void OnInitAuthData ( UInt64 unixTimestamp )
922
+ {
913
923
key_change_datetime_key = unixTimestamp / key_change_interval ;
914
924
for ( int i = 7 ; i > - 1 ; -- i )
915
925
{
0 commit comments