新建ASF程序,找到ASF模块打开快速指导。
按快速指导提示建立程序。
这个程序是两个加密一个是密钥的加密,再一个是数据的加密,数据加密及密钥加密都给出运算值存到变量里
以下是形成的程序:
#include <asf.h>
t_key encryption_key = {
0x30, 0x70, 0x97, 0x1A, 0xB7, 0xCE, 0x45, 0x06,
0x3F, 0xD2, 0x57, 0x3F, 0x49, 0xF5, 0x42, 0x0D
};
t_data encryption_data = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
};
t_data encrypted_data;
t_data decrypted_data;
void encrypt_decrypt() {
aes_software_reset();
aes_configure(AES_ENCRYPT, AES_MANUAL, AES_XOR_OFF);
aes_set_key(encryption_key);
aes_write_inputdata(encryption_data);
aes_start();
do {
// Wait until AES is finished or an error occurs.
} while (aes_is_busy());
aes_read_outputdata(encrypted_data);
aes_configure(AES_DECRYPT, AES_MANUAL, AES_XOR_OFF);
aes_write_inputdata(encrypted_data);
aes_start();
do {
// Wait until AES is finished or an error occurs.
} while (aes_is_busy());
aes_read_outputdata(decrypted_data);
}
int main (void)
{
/* Insert system clock initialization code here (sysclk_init()). */
sysclk_init();
board_init();
sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_AES);
encrypt_decrypt();
/* Insert application code here, after the board has been initialized. */
}
以下是快速指导截图:
这个是运行打的断点,经运行可以观察到中密的值 :
|