硬件:EFM32GG230512
工具:keil5
AES实验
AES测试,AES加解密测试
打开时钟
/*********************************************Copyright (c)***********************************************
** File name: aes.c
** Created by: Gui
** Version: V1.0.0
** Descriptions:
*********************************************************************************************************/
#include "aes.h"
void aes_init(void){
CMU_ClockEnable(cmuClock_AES, true); /* 打开AES时钟 */
}
/***************************************************
使用EFM32片内的AES加解密硬件加速器来实现对
特定字符的加密和解密。
1.使用128bit进行加解密
2.使用ECB方式进行加密
***************************************************/
void AES_ECB_128bit_Encrypt(uint8_t * encrypt_,uint8_t * buf,uint16_t len,uint8_t *key){
AES_ECB128(encrypt_,buf,16,key,true);
}
void AES_ECB_128bit_Decrypt(uint8_t * dncrypt_,uint8_t * buf,uint16_t len,uint8_t *key){
AES_DecryptKey128(key,key);
AES_ECB128(dncrypt_,buf,16,key,false);
}
main
/*********************************************Copyright (c)***********************************************
** File name: main.c
** Created by: Gui
** Version: V1.0.0
** Descriptions: AES测试,AES加解密测试
*********************************************************************************************************/
#include "system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "delay.h"
#include "aes.h"
#include "bsp_led.h"
int main(){
uint8_t AES_PlantTest1[16] = "1234567890123456";//初始明文
uint8_t AES_PlantTest2[16];//加密之后的密文
uint8_t AES_PlantTest3[16];//解密之后的明文
uint8_t g_ucKey[16] ={//密钥
0x12, 0x34, 0x56, 0x78, 0x90, 0x90, 0x87, 0x65,
0x43, 0x21, 0xab, 0xcd, 0xef, 0xf0, 0xf1, 0x00};
CMU_ClockEnable(cmuClock_HFPER, true); //前置芯片设置
CMU_ClockEnable(cmuClock_GPIO, true);
if(SysTick_Config(SystemCoreClockGet()/1000))while(1);//1ms的systick中断
led_init();//PD4 PD5
aes_init();
AES_ECB_128bit_Encrypt(AES_PlantTest2,AES_PlantTest1,16,g_ucKey);
AES_ECB_128bit_Decrypt(AES_PlantTest3,AES_PlantTest2,16,g_ucKey);
while(1){
}
}