Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /******************************************************************************/ |
michael@0 | 2 | /* LICENSE: */ |
michael@0 | 3 | /* This submission to NSS is to be made available under the terms of the */ |
michael@0 | 4 | /* Mozilla Public License, v. 2.0. You can obtain one at http: */ |
michael@0 | 5 | /* //mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | /******************************************************************************/ |
michael@0 | 7 | /* Copyright(c) 2013, Intel Corp. */ |
michael@0 | 8 | /******************************************************************************/ |
michael@0 | 9 | /* Reference: */ |
michael@0 | 10 | /* [1] Shay Gueron, Michael E. Kounavis: Intel® Carry-Less Multiplication */ |
michael@0 | 11 | /* Instruction and its Usage for Computing the GCM Mode (Rev. 2.01) */ |
michael@0 | 12 | /* http://software.intel.com/sites/default/files/article/165685/clmul-wp-r*/ |
michael@0 | 13 | /*ev-2.01-2012-09-21.pdf */ |
michael@0 | 14 | /* [2] S. Gueron, M. E. Kounavis: Efficient Implementation of the Galois */ |
michael@0 | 15 | /* Counter Mode Using a Carry-less Multiplier and a Fast Reduction */ |
michael@0 | 16 | /* Algorithm. Information Processing Letters 110: 549–553 (2010). */ |
michael@0 | 17 | /* [3] S. Gueron: AES Performance on the 2nd Generation Intel® Core™ Processor*/ |
michael@0 | 18 | /* Family (to be posted) (2012). */ |
michael@0 | 19 | /* [4] S. Gueron: Fast GHASH computations for speeding up AES-GCM (to be */ |
michael@0 | 20 | /* published) (2012). */ |
michael@0 | 21 | |
michael@0 | 22 | #ifndef INTEL_GCM_H |
michael@0 | 23 | #define INTEL_GCM_H 1 |
michael@0 | 24 | |
michael@0 | 25 | #include "blapii.h" |
michael@0 | 26 | |
michael@0 | 27 | typedef struct intel_AES_GCMContextStr intel_AES_GCMContext; |
michael@0 | 28 | |
michael@0 | 29 | intel_AES_GCMContext *intel_AES_GCM_CreateContext(void *context, freeblCipherFunc cipher, |
michael@0 | 30 | const unsigned char *params, unsigned int blocksize); |
michael@0 | 31 | |
michael@0 | 32 | void intel_AES_GCM_DestroyContext(intel_AES_GCMContext *gcm, PRBool freeit); |
michael@0 | 33 | |
michael@0 | 34 | SECStatus intel_AES_GCM_EncryptUpdate(intel_AES_GCMContext *gcm, unsigned char *outbuf, |
michael@0 | 35 | unsigned int *outlen, unsigned int maxout, |
michael@0 | 36 | const unsigned char *inbuf, unsigned int inlen, |
michael@0 | 37 | unsigned int blocksize); |
michael@0 | 38 | |
michael@0 | 39 | SECStatus intel_AES_GCM_DecryptUpdate(intel_AES_GCMContext *gcm, unsigned char *outbuf, |
michael@0 | 40 | unsigned int *outlen, unsigned int maxout, |
michael@0 | 41 | const unsigned char *inbuf, unsigned int inlen, |
michael@0 | 42 | unsigned int blocksize); |
michael@0 | 43 | |
michael@0 | 44 | /* Prorotypes of functions in the assembler file for fast AES-GCM, using |
michael@0 | 45 | Intel AES-NI and CLMUL-NI, as described in [1] |
michael@0 | 46 | [1] Shay Gueron, Michael E. Kounavis: Intel® Carry-Less Multiplication |
michael@0 | 47 | Instruction and its Usage for Computing the GCM Mode */ |
michael@0 | 48 | |
michael@0 | 49 | /* Prepares the constants used in the aggregated reduction method */ |
michael@0 | 50 | void intel_aes_gcmINIT(unsigned char Htbl[16*16], |
michael@0 | 51 | unsigned char *KS, |
michael@0 | 52 | int NR); |
michael@0 | 53 | |
michael@0 | 54 | /* Produces the final GHASH value */ |
michael@0 | 55 | void intel_aes_gcmTAG(unsigned char Htbl[16*16], |
michael@0 | 56 | unsigned char *Tp, |
michael@0 | 57 | unsigned long Mlen, |
michael@0 | 58 | unsigned long Alen, |
michael@0 | 59 | unsigned char* X0, |
michael@0 | 60 | unsigned char* TAG); |
michael@0 | 61 | |
michael@0 | 62 | /* Hashes the Additional Authenticated Data, should be used before enc/dec. |
michael@0 | 63 | Operates on whole blocks only. Partial blocks should be padded externally. */ |
michael@0 | 64 | void intel_aes_gcmAAD(unsigned char Htbl[16*16], |
michael@0 | 65 | unsigned char *AAD, |
michael@0 | 66 | unsigned long Alen, |
michael@0 | 67 | unsigned char *Tp); |
michael@0 | 68 | |
michael@0 | 69 | /* Encrypts and hashes the Plaintext. |
michael@0 | 70 | Operates on any length of data, however partial block should only be encrypted |
michael@0 | 71 | at the last call, otherwise the result will be incorrect. */ |
michael@0 | 72 | void intel_aes_gcmENC(const unsigned char* PT, |
michael@0 | 73 | unsigned char* CT, |
michael@0 | 74 | void *Gctx, |
michael@0 | 75 | unsigned long len); |
michael@0 | 76 | |
michael@0 | 77 | /* Similar to ENC, but decrypts the Ciphertext. */ |
michael@0 | 78 | void intel_aes_gcmDEC(const unsigned char* CT, |
michael@0 | 79 | unsigned char* PT, |
michael@0 | 80 | void *Gctx, |
michael@0 | 81 | unsigned long len); |
michael@0 | 82 | |
michael@0 | 83 | #endif |