AES-GCM算法简介
AES-GCM算法是带认证和加密的算法,同时可以对给定的原文,生成加密数据和认证码。参数如下:
1)带加密的原文、2)存储加密后密文、3)IV向量、4)生成的消息验证码tag、5)额外的消息认证数据aad,通信双方需要共享;
整个AES-GCM算法代码如下:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ica_api.h>
#define AES_CIPHER_BLOCK_SIZE 16
/* 本测试demo用了一个静态的key
*
* Note: AES-128 key size is 16 bytes (AES_KEY_LEN128)
*/
unsigned char aes_key[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
};
/* 带加密的数据原文.
*/
unsigned char plain_data[] = {
0x55, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6c, 0x69,
0x62, 0x69, 0x63, 0x61, 0x20, 0x69, 0x73, 0x20,
0x73, 0x6d, 0x61, 0x72, 0x74, 0x20, 0x61, 0x6e,
0x64, 0x20, 0x65, 0x61, 0x73, 0x79, 0x21, 0x00
};
/* 初始化的IV向量. The initialization vector
* size must be greater than 0 and less than 2**61. A length of
* 12 is recom