Skip to content

Commit

Permalink
sync ca4a5d3
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Jul 14, 2020
1 parent 5cc304a commit e95ee70
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
30 changes: 29 additions & 1 deletion encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,28 @@ int de_padding(const char *data ,int &data_len,int padding_num)
}
return 0;
}
void aes_ecb_encrypt(const char *data,char *output)
{
static int first_time=1;
char *key=(char*)cipher_key_encrypt;
if(aes_key_optimize)
{
if(first_time==0) key=0;
else first_time=0;
}
AES_ECB_encrypt_buffer((uint8_t*)data,(uint8_t*)key,(uint8_t*)output);
}
void aes_ecb_decrypt(const char *data,char *output)
{
static int first_time=1;
char *key=(char*)cipher_key_decrypt;
if(aes_key_optimize)
{
if(first_time==0) key=0;
else first_time=0;
}
AES_ECB_decrypt_buffer((uint8_t*)data,(uint8_t*)key,(uint8_t*)output);
}
int cipher_aes128cbc_encrypt(const char *data,char *output,int &len,char * key)
{
static int first_time=1;
Expand Down Expand Up @@ -326,6 +348,7 @@ 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

AES_CFB_encrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv);
return 0;
Expand Down Expand Up @@ -374,7 +397,12 @@ int cipher_aes128cfb_decrypt(const char *data,char *output,int &len,char * key)
if(first_time==0) key=0;
else first_time=0;
}
AES_CFB_decrypt_buffer((unsigned char *)output,(unsigned char *)data,len,(unsigned char *)key,(unsigned char *)zero_iv);
char buf[buf_len];
memcpy(buf,data,len);//TODO inefficient code

aes_ecb_decrypt(data,buf); //decrypt the first block

AES_CFB_decrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv);
//if(de_padding(output,len,16)<0) return -1;
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions encrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ extern char gro_xor[256+100];
int cipher_decrypt(const char *data,char *output,int &len,char * key);//internal interface ,exposed for test only
int cipher_encrypt(const char *data,char *output,int &len,char * key);//internal interface ,exposed for test only

void aes_ecb_encrypt(const char *data,char *output);
void aes_ecb_decrypt(const char *data,char *output);
#endif
4 changes: 2 additions & 2 deletions lib/aes_acc/aesacc.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, co
decrypt_cbc(rk, length, iv_tmp, input, output);
}

void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t* output, const uint32_t length)
void AES_ECB_encrypt_buffer(const uint8_t* input, const uint8_t* key, uint8_t* output)
{
static uint8_t rk[AES_RKSIZE];

Expand All @@ -376,7 +376,7 @@ void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t* output,
encrypt_ecb(AES_NR, rk, input, output);
}

void AES_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length)
void AES_ECB_decrypt_buffer(const uint8_t* input, const uint8_t* key, uint8_t *output)
{
static uint8_t rk[AES_RKSIZE];

Expand Down
4 changes: 2 additions & 2 deletions lib/aes_faster_c/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#endif


void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length)
void AES_ECB_encrypt_buffer(const uint8_t* input, const uint8_t* key, uint8_t *output)
{
static aes_context ctx;
if(key!=0)
Expand All @@ -24,7 +24,7 @@ void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output,
assert(ret==0);
return ;
}
void AES_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length)
void AES_ECB_decrypt_buffer(const uint8_t* input, const uint8_t* key, uint8_t *output)
{
static aes_context ctx;
if(key!=0)
Expand Down

0 comments on commit e95ee70

Please sign in to comment.