mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
add const int aes_key_optimize
This commit is contained in:
parent
661b329930
commit
dcc722ff5e
15
encrypt.cpp
15
encrypt.cpp
@ -209,8 +209,11 @@ 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(first_time==0) key=0;
|
||||
else first_time=0;
|
||||
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
|
||||
@ -258,9 +261,11 @@ 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(first_time==0) key=0;
|
||||
else first_time=0;
|
||||
|
||||
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);
|
||||
|
@ -10,6 +10,10 @@
|
||||
|
||||
//using namespace std;
|
||||
|
||||
|
||||
const int aes_key_optimize=1; //if enabled,once you used a key for aes,you cant change it anymore
|
||||
|
||||
|
||||
int my_encrypt(const char *data,char *output,int &len,char * key);
|
||||
int my_decrypt(const char *data,char *output,int &len,char * key);
|
||||
|
||||
@ -35,7 +39,7 @@ extern unordered_map<int, const char *> cipher_mode_tostring;
|
||||
|
||||
|
||||
|
||||
int cipher_decrypt(const char *data,char *output,int &len,char * key);
|
||||
int cipher_encrypt(const char *data,char *output,int &len,char * key);
|
||||
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
|
||||
|
||||
#endif
|
||||
|
@ -37,7 +37,7 @@
|
||||
////////modification begin
|
||||
#define POLARSSL_AES_ROM_TABLES
|
||||
#define POLARSSL_CIPHER_MODE_CBC
|
||||
#define POLARSSL_SELF_TEST
|
||||
//#define POLARSSL_SELF_TEST
|
||||
#define polarssl_printf printf
|
||||
///////add end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user