2023-12-19 03:08:51 +08:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* THIS SOURCE CODE IS HEREBY PLACED INTO THE PUBLIC DOMAIN FOR THE GOOD OF ALL
|
|
|
|
*
|
2024-03-25 16:34:05 +08:00
|
|
|
* This is a simple and straightforward implementation of AES-GCM authenticated
|
|
|
|
* encryption. The focus of this work was correctness & accuracy. It is written
|
|
|
|
* in straight 'C' without any particular focus upon optimization or speed. It
|
|
|
|
* should be endian (memory byte order) neutral since the few places that care
|
|
|
|
* are handled explicitly.
|
2023-12-19 03:08:51 +08:00
|
|
|
*
|
2024-03-25 16:34:05 +08:00
|
|
|
* This implementation of AES-GCM was created by Steven M. Gibson of GRC.com.
|
2023-12-19 03:08:51 +08:00
|
|
|
*
|
|
|
|
* It is intended for general purpose use, but was written in support of GRC's
|
|
|
|
* reference implementation of the SQRL (Secure Quick Reliable Login) client.
|
|
|
|
*
|
2024-03-25 16:34:05 +08:00
|
|
|
* See: http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
|
|
|
|
* http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ \
|
|
|
|
* gcm/gcm-revised-spec.pdf
|
2023-12-19 03:08:51 +08:00
|
|
|
*
|
|
|
|
* NO COPYRIGHT IS CLAIMED IN THIS WORK, HOWEVER, NEITHER IS ANY WARRANTY MADE
|
|
|
|
* REGARDING ITS FITNESS FOR ANY PARTICULAR PURPOSE. USE IT AT YOUR OWN RISK.
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
2024-03-25 16:34:05 +08:00
|
|
|
#ifndef TLS_AES128_H
|
|
|
|
#define TLS_AES128_H
|
2023-12-19 03:08:51 +08:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* AES_CONTEXT : cipher context / holds inter-call data
|
|
|
|
******************************************************************************/
|
|
|
|
typedef struct {
|
|
|
|
int mode; // 1 for Encryption, 0 for Decryption
|
|
|
|
int rounds; // keysize-based rounds count
|
|
|
|
uint32_t *rk; // pointer to current round key
|
|
|
|
uint32_t buf[68]; // key expansion buffer
|
|
|
|
} aes_context;
|
|
|
|
|
|
|
|
#include "arch.h"
|
|
|
|
#define GCM_AUTH_FAILURE 0x55555555 // authentication failure
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GCM_CONTEXT : MUST be called once before ANY use of this library
|
|
|
|
******************************************************************************/
|
2024-03-25 16:34:05 +08:00
|
|
|
int mg_gcm_initialize(void);
|
2023-12-19 03:08:51 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// aes-gcm.h
|
|
|
|
// MKo
|
|
|
|
//
|
|
|
|
// Created by Markus Kosmal on 20/11/14.
|
|
|
|
//
|
|
|
|
//
|
2024-03-25 16:34:05 +08:00
|
|
|
int mg_aes_gcm_encrypt(unsigned char *output, const unsigned char *input,
|
|
|
|
size_t input_length, const unsigned char *key,
|
|
|
|
const size_t key_len, const unsigned char *iv,
|
|
|
|
const size_t iv_len, unsigned char *aead,
|
|
|
|
size_t aead_len, unsigned char *tag,
|
|
|
|
const size_t tag_len);
|
|
|
|
|
|
|
|
int mg_aes_gcm_decrypt(unsigned char *output, const unsigned char *input,
|
|
|
|
size_t input_length, const unsigned char *key,
|
|
|
|
const size_t key_len, const unsigned char *iv,
|
|
|
|
const size_t iv_len);
|
|
|
|
|
|
|
|
#endif /* TLS_AES128_H */
|
2023-12-19 03:08:51 +08:00
|
|
|
|
2023-12-21 03:40:31 +08:00
|
|
|
// End of aes128 PD
|