syn update of linux version. for aes128cfb and hmac_sha1

This commit is contained in:
U-DESKTOP-T772REH\wangyu
2018-07-24 19:04:57 +08:00
parent 626926e25c
commit ae9db0eecf
8 changed files with 193 additions and 681 deletions

View File

@@ -37,6 +37,7 @@
////////modification begin
#define POLARSSL_AES_ROM_TABLES
#define POLARSSL_CIPHER_MODE_CBC
#define POLARSSL_CIPHER_MODE_CFB
//#define POLARSSL_SELF_TEST
#define polarssl_printf printf
///////add end

View File

@@ -1,6 +1,7 @@
#include "aes.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#if defined(AES256) && (AES256 == 1)
#define AES_KEYSIZE 256
@@ -25,32 +26,64 @@ void AES_ECB_decrypt(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)
{
static aes_context ctx;
static int done=0;
if(done==0)
{
aes_init( &ctx);
done=1;
}
char tmp_iv[16];
if(key!=0) aes_setkey_enc(&ctx,key,AES_KEYSIZE);
if(key!=0)
{
aes_init( &ctx);
aes_setkey_enc(&ctx,key,AES_KEYSIZE);
}
memcpy(tmp_iv,iv,16);
aes_crypt_cbc( &ctx, AES_ENCRYPT, length, (unsigned char* )tmp_iv, (const unsigned char*)input,(unsigned char*) output );
int ret=aes_crypt_cbc( &ctx, AES_ENCRYPT, length, (unsigned char* )tmp_iv, (const unsigned char*)input,(unsigned char*) output );
assert(ret==0);
return ;
}
void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
{
static aes_context ctx;
static int done=0;
if(done==0)
{
aes_init( &ctx);
done=1;
}
char tmp_iv[16];
if(key!=0) aes_setkey_dec(&ctx,key,AES_KEYSIZE);
if(key!=0)
{
aes_init( &ctx);
aes_setkey_dec(&ctx,key,AES_KEYSIZE);
}
memcpy(tmp_iv,iv,16);
aes_crypt_cbc( &ctx,AES_DECRYPT, length, (unsigned char*)tmp_iv, (const unsigned char*)input, (unsigned char*) output );
int ret=aes_crypt_cbc( &ctx,AES_DECRYPT, length, (unsigned char*)tmp_iv, (const unsigned char*)input, (unsigned char*) output );
assert(ret==0);
}
void AES_CFB_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
{
static aes_context ctx;
char tmp_iv[16];
if(key!=0)
{
aes_init( &ctx);
aes_setkey_enc(&ctx,key,AES_KEYSIZE);
}
memcpy(tmp_iv,iv,16);
size_t offset=0;
int ret=aes_crypt_cfb128( &ctx, AES_ENCRYPT, length,&offset, (unsigned char* )tmp_iv, (const unsigned char*)input,(unsigned char*) output );
assert(ret==0);
return ;
}
void AES_CFB_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
{
static aes_context ctx;
char tmp_iv[16];
if(key!=0)
{
aes_init( &ctx);
aes_setkey_enc(&ctx,key,AES_KEYSIZE);// its aes_setkey_enc again, no typo
}
memcpy(tmp_iv,iv,16);
size_t offset=0;
int ret=aes_crypt_cfb128( &ctx,AES_DECRYPT, length,&offset, (unsigned char*)tmp_iv, (const unsigned char*)input, (unsigned char*) output );
assert(ret==0);
return;
}