mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-07 23:59:36 +08:00
modify scheme of cfb
This commit is contained in:
parent
1031f9d760
commit
ca4a5d3417
30
encrypt.cpp
30
encrypt.cpp
@ -297,6 +297,28 @@ int de_padding(const char *data ,int &data_len,int padding_num)
|
|||||||
}
|
}
|
||||||
return 0;
|
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)
|
int cipher_aes128cbc_encrypt(const char *data,char *output,int &len,char * key)
|
||||||
{
|
{
|
||||||
static int first_time=1;
|
static int first_time=1;
|
||||||
@ -326,6 +348,7 @@ int cipher_aes128cfb_encrypt(const char *data,char *output,int &len,char * key)
|
|||||||
if(first_time==0) key=0;
|
if(first_time==0) key=0;
|
||||||
else first_time=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);
|
AES_CFB_encrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv);
|
||||||
return 0;
|
return 0;
|
||||||
@ -374,7 +397,12 @@ int cipher_aes128cfb_decrypt(const char *data,char *output,int &len,char * key)
|
|||||||
if(first_time==0) key=0;
|
if(first_time==0) key=0;
|
||||||
else first_time=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;
|
//if(de_padding(output,len,16)<0) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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_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
|
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
|
#endif
|
||||||
|
@ -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);
|
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];
|
static uint8_t rk[AES_RKSIZE];
|
||||||
|
|
||||||
@ -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);
|
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];
|
static uint8_t rk[AES_RKSIZE];
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#endif
|
#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;
|
static aes_context ctx;
|
||||||
if(key!=0)
|
if(key!=0)
|
||||||
@ -24,7 +24,7 @@ void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output,
|
|||||||
assert(ret==0);
|
assert(ret==0);
|
||||||
return ;
|
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;
|
static aes_context ctx;
|
||||||
if(key!=0)
|
if(key!=0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user