mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-31 20:29:36 +08:00
fixed segment fault
This commit is contained in:
parent
2c67c319b7
commit
bd57171b48
15
encrypt.cpp
15
encrypt.cpp
@ -199,11 +199,6 @@ int de_padding(const char *data ,int &data_len,int padding_num)
|
|||||||
int cipher_aes128cbc_encrypt(const char *data,char *output,int &len,char * key)
|
int cipher_aes128cbc_encrypt(const char *data,char *output,int &len,char * key)
|
||||||
{
|
{
|
||||||
static int first_time=1;
|
static int first_time=1;
|
||||||
if(aes_key_optimize)
|
|
||||||
{
|
|
||||||
if(first_time==0) key=0;
|
|
||||||
else first_time=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[buf_len];
|
char buf[buf_len];
|
||||||
memcpy(buf,data,len);//TODO inefficient code
|
memcpy(buf,data,len);//TODO inefficient code
|
||||||
@ -222,6 +217,12 @@ int cipher_aes128cbc_encrypt(const char *data,char *output,int &len,char * key)
|
|||||||
buf[len-1]=(unsigned char)( ((uint16_t(ori_len))<<8)>>8) ;*/
|
buf[len-1]=(unsigned char)( ((uint16_t(ori_len))<<8)>>8) ;*/
|
||||||
if(padding(buf,len,16)<0) return -1;
|
if(padding(buf,len,16)<0) return -1;
|
||||||
|
|
||||||
|
if(aes_key_optimize)
|
||||||
|
{
|
||||||
|
if(first_time==0) key=0;
|
||||||
|
else first_time=0;
|
||||||
|
}
|
||||||
|
|
||||||
AES_CBC_encrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv);
|
AES_CBC_encrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -251,13 +252,13 @@ int cipher_none_encrypt(const char *data,char *output,int &len,char * key)
|
|||||||
int cipher_aes128cbc_decrypt(const char *data,char *output,int &len,char * key)
|
int cipher_aes128cbc_decrypt(const char *data,char *output,int &len,char * key)
|
||||||
{
|
{
|
||||||
static int first_time=1;
|
static int first_time=1;
|
||||||
|
if(len%16 !=0) {mylog(log_debug,"len%%16!=0\n");return -1;}
|
||||||
|
//if(len<0) {mylog(log_debug,"len <0\n");return -1;}
|
||||||
if(aes_key_optimize)
|
if(aes_key_optimize)
|
||||||
{
|
{
|
||||||
if(first_time==0) key=0;
|
if(first_time==0) key=0;
|
||||||
else first_time=0;
|
else first_time=0;
|
||||||
}
|
}
|
||||||
if(len%16 !=0) {mylog(log_debug,"len%%16!=0\n");return -1;}
|
|
||||||
//if(len<0) {mylog(log_debug,"len <0\n");return -1;}
|
|
||||||
AES_CBC_decrypt_buffer((unsigned char *)output,(unsigned char *)data,len,(unsigned char *)key,(unsigned char *)zero_iv);
|
AES_CBC_decrypt_buffer((unsigned char *)output,(unsigned char *)data,len,(unsigned char *)key,(unsigned char *)zero_iv);
|
||||||
if(de_padding(output,len,16)<0) return -1;
|
if(de_padding(output,len,16)<0) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user