fixed segment fault

This commit is contained in:
wangyu- 2018-08-31 22:21:23 -05:00
parent 2c67c319b7
commit bd57171b48

View File

@ -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)
{
static int first_time=1;
if(aes_key_optimize)
{
if(first_time==0) key=0;
else first_time=0;
}
char buf[buf_len];
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) ;*/
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);
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)
{
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(first_time==0) key=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);
if(de_padding(output,len,16)<0) return -1;
return 0;