@@ -10,10 +10,12 @@ namespace Shadowsocks.Obfs
1010 class xorshift128plus
1111 {
1212 protected UInt64 v0 , v1 ;
13+ protected int init_loop ;
1314
14- public xorshift128plus ( )
15+ public xorshift128plus ( int init_loop_ = 4 )
1516 {
1617 v0 = v1 = 0 ;
18+ init_loop = init_loop_ ;
1719 }
1820
1921 public UInt64 next ( )
@@ -42,7 +44,7 @@ public void init_from_bin(byte[] bytes, int datalength)
4244 BitConverter . GetBytes ( ( ushort ) datalength ) . CopyTo ( fill_bytes , 0 ) ;
4345 v0 = BitConverter . ToUInt64 ( fill_bytes , 0 ) ;
4446 v1 = BitConverter . ToUInt64 ( fill_bytes , 8 ) ;
45- for ( int i = 0 ; i < 4 ; ++ i )
47+ for ( int i = 0 ; i < init_loop ; ++ i )
4648 {
4749 next ( ) ;
4850 }
@@ -202,6 +204,11 @@ public void PackData(byte[] data, int datalength, byte[] outdata, out int outlen
202204 }
203205 }
204206
207+ public virtual void OnInitAuthData ( UInt64 unixTimestamp )
208+ {
209+
210+ }
211+
205212 public void PackAuthData ( byte [ ] data , int datalength , byte [ ] outdata , out int outlength )
206213 {
207214 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
234241 UInt64 utc_time_second = ( UInt64 ) Math . Floor ( DateTime . UtcNow . Subtract ( new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 ) ) . TotalSeconds ) ;
235242 UInt32 utc_time = ( UInt32 ) ( utc_time_second ) ;
236243 Array . Copy ( BitConverter . GetBytes ( utc_time ) , 0 , encrypt , 0 , 4 ) ;
244+ OnInitAuthData ( utc_time_second ) ;
237245
238246 encrypt [ 12 ] = ( byte ) ( Server . overhead ) ;
239247 encrypt [ 13 ] = ( byte ) ( Server . overhead >> 8 ) ;
@@ -572,7 +580,7 @@ public override Dictionary<string, int[]> GetObfs()
572580 return _obfs ;
573581 }
574582
575- protected void InitDataSizeList ( )
583+ protected virtual void InitDataSizeList ( )
576584 {
577585 xorshift128plus random = new xorshift128plus ( ) ;
578586 random . init_from_bin ( Server . key ) ;
@@ -683,7 +691,7 @@ public override Dictionary<string, int[]> GetObfs()
683691 return _obfs ;
684692 }
685693
686- protected new void InitDataSizeList ( )
694+ protected override void InitDataSizeList ( )
687695 {
688696 xorshift128plus random = new xorshift128plus ( ) ;
689697 random . init_from_bin ( Server . key ) ;
@@ -760,7 +768,7 @@ protected void CheckAndPatchDataSize(List<int> data_list, xorshift128plus random
760768 }
761769 }
762770
763- protected new void InitDataSizeList ( )
771+ protected override void InitDataSizeList ( )
764772 {
765773 xorshift128plus random = new xorshift128plus ( ) ;
766774 random . init_from_bin ( Server . key ) ;
@@ -866,7 +874,7 @@ public override Dictionary<string, int[]> GetObfs()
866874 protected UInt64 key_change_datetime_key ;
867875 protected List < byte > key_change_datetime_key_bytes = new List < byte > ( ) ;
868876
869- protected new void InitDataSizeList ( )
877+ protected override void InitDataSizeList ( )
870878 {
871879 xorshift128plus random = new xorshift128plus ( ) ;
872880 byte [ ] newKey = new byte [ Server . key . Length ] ;
@@ -908,8 +916,10 @@ public override void SetServerInfo(ServerInfo serverInfo)
908916 key_change_interval = interval ;
909917 }
910918 }
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+ {
913923 key_change_datetime_key = unixTimestamp / key_change_interval ;
914924 for ( int i = 7 ; i > - 1 ; -- i )
915925 {
0 commit comments