Skip to content

Commit

Permalink
fixed segment fault
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Sep 1, 2018
1 parent 2c67c31 commit bd57171
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bd57171

Please sign in to comment.