mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-30 15:39:00 +08:00
67 lines
2.7 KiB
C
67 lines
2.7 KiB
C
/******************************************************************************
|
|
*
|
|
* THIS SOURCE CODE IS HEREBY PLACED INTO THE PUBLIC DOMAIN FOR THE GOOD OF ALL
|
|
*
|
|
* 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.
|
|
*
|
|
* This implementation of AES-GCM was created by Steven M. Gibson of GRC.com.
|
|
*
|
|
* 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.
|
|
*
|
|
* 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
|
|
*
|
|
* 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.
|
|
*
|
|
*******************************************************************************/
|
|
#ifndef TLS_AES128_H
|
|
#define TLS_AES128_H
|
|
|
|
/******************************************************************************
|
|
* 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
|
|
******************************************************************************/
|
|
int mg_gcm_initialize(void);
|
|
|
|
//
|
|
// aes-gcm.h
|
|
// MKo
|
|
//
|
|
// Created by Markus Kosmal on 20/11/14.
|
|
//
|
|
//
|
|
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 */
|
|
|
|
// End of aes128 PD
|