Browse Source

change gro scheme

wangyu 5 years ago
parent
commit
779ebdd37a
3 changed files with 35 additions and 5 deletions
  1. 18 4
      connection.cpp
  2. 13 1
      encrypt.cpp
  3. 4 0
      encrypt.h

+ 18 - 4
connection.cpp

@@ -497,9 +497,16 @@ int send_safer(conn_info_t &conn_info,char type,const char* data,int len)  //saf
             return -1;
         }
         write_u16(send_data_buf2,new_len);
-        send_data_buf2[0]^=gro_xor[0];
-        send_data_buf2[1]^=gro_xor[1];
         new_len+=2;
+	if(cipher_mode==cipher_xor)
+	{
+	    send_data_buf2[0]^=gro_xor[0];
+	    send_data_buf2[1]^=gro_xor[1];
+	}
+	else if(cipher_mode==cipher_aes128cbc||cipher_mode==cipher_aes128cbc)
+	{
+	    aes_ecb_encrypt1(send_data_buf2);
+	}
     }
 
 
@@ -662,8 +669,15 @@ int recv_safer_multi(conn_info_t &conn_info,vector<char> &type_arr,vector<string
             int single_len_no_xor;
             single_len_no_xor=read_u16(recv_data);
             int single_len;
-            recv_data[0]^=gro_xor[0];
-            recv_data[1]^=gro_xor[1];
+	    if(cipher_mode==cipher_xor)
+	    {
+		recv_data[0]^=gro_xor[0];
+		recv_data[1]^=gro_xor[1];
+	    }
+	    else if(cipher_mode==cipher_aes128cbc||cipher_mode==cipher_aes128cbc)
+	    {
+		aes_ecb_decrypt1(recv_data);
+	    }
             single_len=read_u16(recv_data);
             recv_len-=2;
             recv_data+=2;

+ 13 - 1
encrypt.cpp

@@ -53,7 +53,7 @@ int my_init_keys(const char * user_passwd,int is_client)
 
 	if(auth_mode==auth_hmac_sha1)
 		is_hmac_used=1;
-	if(is_hmac_used||g_fix_gro)
+	if(is_hmac_used||g_fix_gro||1)
 	{
 		unsigned char salt[400]="";
 		char salt_text[400]="udp2raw_salt1";
@@ -308,6 +308,12 @@ void aes_ecb_encrypt(const char *data,char *output)
 	}	
 	AES_ECB_encrypt_buffer((uint8_t*)data,(uint8_t*)key,(uint8_t*)output);
 }
+void aes_ecb_encrypt1(char *data)
+{
+    char buf[16];
+    memcpy(buf,data,16);
+    aes_ecb_encrypt(buf,data);
+}
 void aes_ecb_decrypt(const char *data,char *output)
 {
 	static int first_time=1;
@@ -319,6 +325,12 @@ void aes_ecb_decrypt(const char *data,char *output)
 	}	
 	AES_ECB_decrypt_buffer((uint8_t*)data,(uint8_t*)key,(uint8_t*)output);
 }
+void aes_ecb_decrypt1(char *data)
+{
+    char buf[16];
+    memcpy(buf,data,16);
+    aes_ecb_decrypt(buf,data);
+}
 int cipher_aes128cbc_encrypt(const char *data,char *output,int &len,char * key)
 {
 	static int first_time=1;

+ 4 - 0
encrypt.h

@@ -41,4 +41,8 @@ int cipher_encrypt(const char *data,char *output,int &len,char * key);//internal
 
 void aes_ecb_encrypt(const char *data,char *output);
 void aes_ecb_decrypt(const char *data,char *output);
+
+void aes_ecb_encrypt1(char *data);
+void aes_ecb_decrypt1(char *data);
+
 #endif