2018-01-19 03:59:58 +08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
#ifndef GCM_H
|
|
|
|
|
#define GCM_H 1
|
|
|
|
|
|
|
|
|
|
#include "blapii.h"
|
2018-02-06 11:46:26 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#ifdef NSS_X86_OR_X64
|
|
|
|
|
#include <emmintrin.h> /* __m128i */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
SEC_BEGIN_PROTOS
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_INT128_SUPPORT
|
|
|
|
|
typedef unsigned __int128 uint128_t;
|
|
|
|
|
#endif
|
2018-01-19 03:59:58 +08:00
|
|
|
|
|
|
|
|
typedef struct GCMContextStr GCMContext;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The context argument is the inner cipher context to use with cipher. The
|
|
|
|
|
* GCMContext does not own context. context needs to remain valid for as long
|
|
|
|
|
* as the GCMContext is valid.
|
|
|
|
|
*
|
|
|
|
|
* The cipher argument is a block cipher in the ECB encrypt mode.
|
|
|
|
|
*/
|
|
|
|
|
GCMContext *GCM_CreateContext(void *context, freeblCipherFunc cipher,
|
2018-02-06 11:46:26 +01:00
|
|
|
const unsigned char *params);
|
2018-01-19 03:59:58 +08:00
|
|
|
void GCM_DestroyContext(GCMContext *gcm, PRBool freeit);
|
|
|
|
|
SECStatus GCM_EncryptUpdate(GCMContext *gcm, unsigned char *outbuf,
|
|
|
|
|
unsigned int *outlen, unsigned int maxout,
|
|
|
|
|
const unsigned char *inbuf, unsigned int inlen,
|
|
|
|
|
unsigned int blocksize);
|
|
|
|
|
SECStatus GCM_DecryptUpdate(GCMContext *gcm, unsigned char *outbuf,
|
|
|
|
|
unsigned int *outlen, unsigned int maxout,
|
|
|
|
|
const unsigned char *inbuf, unsigned int inlen,
|
|
|
|
|
unsigned int blocksize);
|
|
|
|
|
|
2018-02-06 11:46:26 +01:00
|
|
|
/* These functions are here only so we can test them */
|
|
|
|
|
#define GCM_HASH_LEN_LEN 8 /* gcm hash defines lengths to be 64 bits */
|
|
|
|
|
typedef struct gcmHashContextStr gcmHashContext;
|
|
|
|
|
typedef SECStatus (*ghash_t)(gcmHashContext *, const unsigned char *,
|
|
|
|
|
unsigned int);
|
|
|
|
|
pre_align struct gcmHashContextStr {
|
|
|
|
|
#ifdef NSS_X86_OR_X64
|
|
|
|
|
__m128i x, h;
|
|
|
|
|
#endif
|
|
|
|
|
uint64_t x_low, x_high, h_high, h_low;
|
|
|
|
|
unsigned char buffer[MAX_BLOCK_SIZE];
|
|
|
|
|
unsigned int bufLen;
|
|
|
|
|
uint8_t counterBuf[16];
|
|
|
|
|
uint64_t cLen;
|
|
|
|
|
ghash_t ghash_mul;
|
|
|
|
|
PRBool hw;
|
|
|
|
|
gcmHashContext *mem;
|
|
|
|
|
} post_align;
|
|
|
|
|
|
|
|
|
|
SECStatus gcmHash_Update(gcmHashContext *ghash, const unsigned char *buf,
|
|
|
|
|
unsigned int len);
|
|
|
|
|
SECStatus gcmHash_InitContext(gcmHashContext *ghash, const unsigned char *H,
|
|
|
|
|
PRBool sw);
|
|
|
|
|
SECStatus gcmHash_Reset(gcmHashContext *ghash, const unsigned char *AAD,
|
|
|
|
|
unsigned int AADLen);
|
|
|
|
|
SECStatus gcmHash_Final(gcmHashContext *ghash, unsigned char *outbuf,
|
|
|
|
|
unsigned int *outlen, unsigned int maxout);
|
|
|
|
|
|
|
|
|
|
SEC_END_PROTOS
|
|
|
|
|
|
2018-01-19 03:59:58 +08:00
|
|
|
#endif
|