Skip to content

Commit

Permalink
update cfb
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Jul 16, 2019
1 parent f68c6e2 commit 7636225
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
15 changes: 14 additions & 1 deletion encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ int cipher_aes128cfb_encrypt(const char *data,char *output,int &len,char * key)
if(first_time==0) key=0;
else first_time=0;
}

if(len>=16)
{
AES_ECB_encrypt_buffer(data,key,buf); //tmp solution, to fix a problem
}

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 +379,15 @@ 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

if(len>=16)
{
AES_ECB_decrypt_buffer(data,key,buf);//tmp solution to fix a problem
}

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
5 changes: 2 additions & 3 deletions lib/aes-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#include <stdint.h>


//not used
//void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length);
//void AES_ECB_decrypt(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);
void AES_ECB_decrypt_buffer(const uint8_t* input, const uint8_t* key, uint8_t *output);

void AES_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
Expand Down
21 changes: 7 additions & 14 deletions lib/aes_acc/aesacc.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,32 +366,25 @@ 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)
{
uint8_t rk[AES_RKSIZE];
static uint8_t rk[AES_RKSIZE];

if (key == NULL)
{
return;
}
aeshw_init();
setkey_enc(rk, key);
if(key!=NULL)
setkey_enc(rk, key);
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)
{
uint8_t rk[AES_RKSIZE];
static uint8_t rk[AES_RKSIZE];

if (key == NULL)
{
return;
}
aeshw_init();
setkey_dec(rk, key);
if(key!=NULL)
setkey_dec(rk, key);
decrypt_ecb(AES_NR, rk, input, output);
}*/
}

static void encrypt_cfb( uint8_t* rk,
uint32_t length,size_t *iv_off,
Expand Down
22 changes: 18 additions & 4 deletions lib/aes_faster_c/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@

void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length)
{
printf("AES_ECB_encrypt not implemented\n");
exit(-1);
static aes_context ctx;
if(key!=0)
{
aes_init( &ctx);
aes_setkey_enc(&ctx,key,AES_KEYSIZE);
}
int ret=aes_crypt_ecb( &ctx, AES_ENCRYPT, (const unsigned char*)input,(unsigned char*) output );
assert(ret==0);
return ;
}
void AES_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length)
{
printf("AES_ECB_encrypt not implemented\n");
exit(-1);
static aes_context ctx;
if(key!=0)
{
aes_init( &ctx);
aes_setkey_dec(&ctx,key,AES_KEYSIZE);
}
int ret=aes_crypt_ecb( &ctx, AES_DECRYPT, (const unsigned char*)input,(unsigned char*) output );
assert(ret==0);
return ;
}

void AES_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
Expand Down

0 comments on commit 7636225

Please sign in to comment.