EFM32例程——AES

硬件: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){
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值