Skip to content

Commit

Permalink
aes128cfb_0
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Jul 15, 2020
1 parent 2f0328a commit 15c15d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 8 additions & 4 deletions encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ auth_mode_t auth_mode=auth_md5;
cipher_mode_t cipher_mode=cipher_aes128cbc;
int is_hmac_used=0;

int aes128cfb_old=0;

//TODO key negotiation and forward secrecy

int my_init_keys(const char * user_passwd,int is_client)
Expand Down Expand Up @@ -361,7 +363,10 @@ int cipher_aes128cfb_encrypt(const char *data,char *output,int &len,char * key)
if(first_time==0) key=0;
else first_time=0;
}
aes_ecb_encrypt(data,buf); //encrypt the first block
if(!aes128cfb_old)
{
aes_ecb_encrypt(data,buf); //encrypt the first block
}

AES_CFB_encrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv);
return 0;
Expand Down Expand Up @@ -416,9 +421,8 @@ int cipher_aes128cfb_decrypt(const char *data,char *output,int &len,char * key)

AES_CFB_decrypt_buffer((unsigned char *)output,(unsigned char *)data,len,(unsigned char *)key,(unsigned char *)zero_iv);

char buf[16];
memcpy(buf,output,16);
aes_ecb_decrypt(buf,output); //decrypt the first block
if(!aes128cfb_old)
aes_ecb_decrypt1(output); //decrypt the first block
//if(de_padding(output,len,16)<0) return -1;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions encrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//extern char key[16];

const int aes_key_optimize=1; //if enabled,once you used a key for aes,you cant change it anymore
extern int aes128cfb_old;

int my_init_keys(const char *,int);

Expand Down
7 changes: 7 additions & 0 deletions misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,13 @@ void process_arg(int argc, char *argv[]) //process all options
}
else if(strcmp(long_options[option_index].name,"cipher-mode")==0)
{
string s=optarg;
if(s=="aes128cfb_0")
{
s="aes128cfb";
aes128cfb_old=1;
mylog(log_warn,"aes128cfb_0 is used\n");
}
for(i=0;i<cipher_end;i++)
{
if(strcmp(optarg,cipher_mode_tostring[i])==0)
Expand Down

0 comments on commit 15c15d5

Please sign in to comment.