GCM算法实现,其依赖AES算法请点击Linux C AES算法
#include "aes.h"
#define GCM_BLOCK_SIZE AES_BLOCK_SIZE
#define GCM_DEFAULT_IV_LEN (12)
#define GCM_FIELD_CONST (0xe100000000000000)
typedef enum {
O_FAIL = -1,
O_SUC = 0,
} op_result;
typedef int (*block_key_schedule_p)(const uint8_t *key, uint8_t *roundkeys);
typedef int (*block_encrypt_p)(const uint8_t *roundkeys, const uint8_t *input, uint8_t *output);
typedef int (*block_decrypt_p)(const uint8_t *roundkeys, const uint8_t *input, uint8_t *output);
typedef struct {
uint8_t *rk;
block_encrypt_p block_encrypt;
uint8_t H[GCM_BLOCK_SIZE];
uint8_t buff[GCM_BLOCK_SIZE];
uint8_t T[GCM_BLOCK_SIZE][256][GCM_BLOCK_SIZE];
} gcm_ctx;
void *gcm_init(void);
op_result gcm_setkey(void *ctx,const unsigned char *key, unsigned int keybits);
void gcm_free( void *ctx