mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
update cfb
This commit is contained in:
parent
f68c6e211d
commit
7636225414
15
encrypt.cpp
15
encrypt.cpp
@ -326,6 +326,11 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
AES_CFB_encrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv);
|
||||||
return 0;
|
return 0;
|
||||||
@ -374,7 +379,15 @@ 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
|
||||||
|
|
||||||
|
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;
|
//if(de_padding(output,len,16)<0) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
//not used
|
void AES_ECB_encrypt_buffer(const uint8_t* input, const uint8_t* key, uint8_t *output);
|
||||||
//void AES_ECB_encrypt(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);
|
||||||
//void AES_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length);
|
|
||||||
|
|
||||||
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_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);
|
void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
|
||||||
|
@ -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);
|
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(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();
|
aeshw_init();
|
||||||
setkey_enc(rk, key);
|
if(key!=NULL)
|
||||||
|
setkey_enc(rk, key);
|
||||||
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(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();
|
aeshw_init();
|
||||||
setkey_dec(rk, key);
|
if(key!=NULL)
|
||||||
|
setkey_dec(rk, key);
|
||||||
decrypt_ecb(AES_NR, rk, input, output);
|
decrypt_ecb(AES_NR, rk, input, output);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
static void encrypt_cfb( uint8_t* rk,
|
static void encrypt_cfb( uint8_t* rk,
|
||||||
uint32_t length,size_t *iv_off,
|
uint32_t length,size_t *iv_off,
|
||||||
|
@ -14,13 +14,27 @@
|
|||||||
|
|
||||||
void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length)
|
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");
|
static aes_context ctx;
|
||||||
exit(-1);
|
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)
|
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");
|
static aes_context ctx;
|
||||||
exit(-1);
|
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)
|
void AES_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user