67 lines
2.0 KiB
C
67 lines
2.0 KiB
C
/**
|
|
****************************************************************************************
|
|
* *
|
|
* @file aes.c
|
|
*
|
|
* @brief Definition file for AES crypto module functions
|
|
*
|
|
* Copyright (C) RivieraWaves 2017-2018
|
|
*
|
|
****************************************************************************************
|
|
*/
|
|
|
|
#include "aes.h"
|
|
|
|
#if (RWIP_AES_ENCRYPT)
|
|
#define USE_AES_ENCRYPT 0
|
|
#define USE_AES_DECRYPT 1
|
|
|
|
#if USE_AES_ENCRYPT
|
|
uint8_t key[16]={0x10,0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x0d,0x0c,0x0b};
|
|
uint8_t src_val[16]={0x0a,0x0a,0x0e,0x0d,0x0c,0x0b,0x0a,0x13,0x12,0x07,0x06,0x05,0x04,0x0d,0x02,0x01};
|
|
uint8_t encrypt_val[16]={0xf7,0x3b,0x9a,0xe6,0x88,0xb0,0x06,0x3e,0x10,0xd4,0x0f,0xb6,0x80,0x4a,0x10,0xee};
|
|
#elif USE_AES_DECRYPT
|
|
uint8_t key[16]={0x10,0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x0d,0x0c,0x0b};
|
|
uint8_t src_val[16]={0xf7,0x3b,0x9a,0xe6,0x88,0xb0,0x06,0x3e,0x10,0xd4,0x0f,0xb6,0x80,0x4a,0x10,0xee};
|
|
uint8_t encrypt_val[16]={0x0a,0x0a,0x0e,0x0d,0x0c,0x0b,0x0a,0x13,0x12,0x07,0x06,0x05,0x04,0x0d,0x02,0x01};
|
|
#endif
|
|
|
|
aes_func_result_cb aes_res(uint8_t status, const uint8_t* aes_res_data, uint32_t src_info)
|
|
{
|
|
printf("src_info:0x%x\n",src_info);
|
|
printf("aes_res:");
|
|
for(int i=0;i<16;i++){
|
|
printf("%02x-",aes_res_data[i]);
|
|
}printf("\n");
|
|
|
|
if(!memcmp(aes_res_data,encrypt_val,sizeof(encrypt_val))){
|
|
printf("aes right\n");
|
|
}else{
|
|
printf("aes error\n");
|
|
}
|
|
}
|
|
|
|
void aes_test(void)
|
|
{
|
|
uint8_t copy=0;
|
|
static uint8_t cnt;
|
|
|
|
if(xc_gpio_read_pin(GPIO_1) == GPIO_PIN_SET){
|
|
if(cnt++ > 100){
|
|
cnt = 0;
|
|
#if USE_AES_ENCRYPT
|
|
printf("aes_encrypt\n");
|
|
aes_encrypt(key, src_val, 1, aes_res, 0xff);
|
|
#elif USE_AES_DECRYPT
|
|
printf("aes_decrypt\n");
|
|
aes_decrypt(key, src_val, copy, aes_res, 0xff);
|
|
#endif
|
|
}
|
|
}else{
|
|
cnt = 0;
|
|
}
|
|
|
|
|
|
}
|
|
#endif
|