andre@0: /******************************************************************************/ andre@0: /* LICENSE: */ andre@0: /* This submission to NSS is to be made available under the terms of the */ andre@0: /* Mozilla Public License, v. 2.0. You can obtain one at http: */ andre@0: /* //mozilla.org/MPL/2.0/. */ andre@0: /******************************************************************************/ andre@0: /* Copyright(c) 2013, Intel Corp. */ andre@0: /******************************************************************************/ andre@0: /* Reference: */ andre@0: /* [1] Shay Gueron, Michael E. Kounavis: Intel® Carry-Less Multiplication */ andre@0: /* Instruction and its Usage for Computing the GCM Mode (Rev. 2.01) */ andre@0: /* http://software.intel.com/sites/default/files/article/165685/clmul-wp-r*/ andre@0: /*ev-2.01-2012-09-21.pdf */ andre@0: /* [2] S. Gueron, M. E. Kounavis: Efficient Implementation of the Galois */ andre@0: /* Counter Mode Using a Carry-less Multiplier and a Fast Reduction */ andre@0: /* Algorithm. Information Processing Letters 110: 549–553 (2010). */ andre@0: /* [3] S. Gueron: AES Performance on the 2nd Generation Intel® Core™ Processor*/ andre@0: /* Family (to be posted) (2012). */ andre@0: /* [4] S. Gueron: Fast GHASH computations for speeding up AES-GCM (to be */ andre@0: /* published) (2012). */ andre@0: andre@0: #ifndef INTEL_GCM_H andre@0: #define INTEL_GCM_H 1 andre@0: andre@0: #include "blapii.h" andre@0: andre@0: typedef struct intel_AES_GCMContextStr intel_AES_GCMContext; andre@0: andre@0: intel_AES_GCMContext *intel_AES_GCM_CreateContext(void *context, freeblCipherFunc cipher, andre@0: const unsigned char *params, unsigned int blocksize); andre@0: andre@0: void intel_AES_GCM_DestroyContext(intel_AES_GCMContext *gcm, PRBool freeit); andre@0: andre@0: SECStatus intel_AES_GCM_EncryptUpdate(intel_AES_GCMContext *gcm, unsigned char *outbuf, andre@0: unsigned int *outlen, unsigned int maxout, andre@0: const unsigned char *inbuf, unsigned int inlen, andre@0: unsigned int blocksize); andre@0: andre@0: SECStatus intel_AES_GCM_DecryptUpdate(intel_AES_GCMContext *gcm, unsigned char *outbuf, andre@0: unsigned int *outlen, unsigned int maxout, andre@0: const unsigned char *inbuf, unsigned int inlen, andre@0: unsigned int blocksize); andre@0: andre@0: /* Prorotypes of functions in the assembler file for fast AES-GCM, using andre@0: Intel AES-NI and CLMUL-NI, as described in [1] andre@0: [1] Shay Gueron, Michael E. Kounavis: Intel® Carry-Less Multiplication andre@0: Instruction and its Usage for Computing the GCM Mode */ andre@0: andre@0: /* Prepares the constants used in the aggregated reduction method */ andre@0: void intel_aes_gcmINIT(unsigned char Htbl[16*16], andre@0: unsigned char *KS, andre@0: int NR); andre@0: andre@0: /* Produces the final GHASH value */ andre@0: void intel_aes_gcmTAG(unsigned char Htbl[16*16], andre@0: unsigned char *Tp, andre@0: unsigned long Mlen, andre@0: unsigned long Alen, andre@0: unsigned char* X0, andre@0: unsigned char* TAG); andre@0: andre@0: /* Hashes the Additional Authenticated Data, should be used before enc/dec. andre@0: Operates on whole blocks only. Partial blocks should be padded externally. */ andre@0: void intel_aes_gcmAAD(unsigned char Htbl[16*16], andre@0: unsigned char *AAD, andre@0: unsigned long Alen, andre@0: unsigned char *Tp); andre@0: andre@0: /* Encrypts and hashes the Plaintext. andre@0: Operates on any length of data, however partial block should only be encrypted andre@0: at the last call, otherwise the result will be incorrect. */ andre@0: void intel_aes_gcmENC(const unsigned char* PT, andre@0: unsigned char* CT, andre@0: void *Gctx, andre@0: unsigned long len); andre@0: andre@0: /* Similar to ENC, but decrypts the Ciphertext. */ andre@0: void intel_aes_gcmDEC(const unsigned char* CT, andre@0: unsigned char* PT, andre@0: void *Gctx, andre@0: unsigned long len); andre@0: andre@0: #endif