security/nss/lib/freebl/intel-aes.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/freebl/intel-aes.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,146 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/* Prototypes of the functions defined in the assembler file.  */
     1.9 +void intel_aes_encrypt_init_128(const unsigned char *key, PRUint32 *expanded);
    1.10 +void intel_aes_encrypt_init_192(const unsigned char *key, PRUint32 *expanded);
    1.11 +void intel_aes_encrypt_init_256(const unsigned char *key, PRUint32 *expanded);
    1.12 +void intel_aes_decrypt_init_128(const unsigned char *key, PRUint32 *expanded);
    1.13 +void intel_aes_decrypt_init_192(const unsigned char *key, PRUint32 *expanded);
    1.14 +void intel_aes_decrypt_init_256(const unsigned char *key, PRUint32 *expanded);
    1.15 +SECStatus intel_aes_encrypt_ecb_128(AESContext *cx, unsigned char *output,
    1.16 +				    unsigned int *outputLen,
    1.17 +				    unsigned int maxOutputLen,
    1.18 +				    const unsigned char *input,
    1.19 +				    unsigned int inputLen,
    1.20 +				    unsigned int blocksize);
    1.21 +SECStatus intel_aes_decrypt_ecb_128(AESContext *cx, unsigned char *output,
    1.22 +				    unsigned int *outputLen,
    1.23 +				    unsigned int maxOutputLen,
    1.24 +				    const unsigned char *input,
    1.25 +				    unsigned int inputLen,
    1.26 +				    unsigned int blocksize);
    1.27 +SECStatus intel_aes_encrypt_cbc_128(AESContext *cx, unsigned char *output,
    1.28 +				    unsigned int *outputLen,
    1.29 +				    unsigned int maxOutputLen,
    1.30 +				    const unsigned char *input,
    1.31 +				    unsigned int inputLen,
    1.32 +				    unsigned int blocksize);
    1.33 +SECStatus intel_aes_decrypt_cbc_128(AESContext *cx, unsigned char *output,
    1.34 +				    unsigned int *outputLen,
    1.35 +				    unsigned int maxOutputLen,
    1.36 +				    const unsigned char *input,
    1.37 +				    unsigned int inputLen,
    1.38 +				    unsigned int blocksize);
    1.39 +SECStatus intel_aes_encrypt_ctr_128(CTRContext *cx, unsigned char *output,
    1.40 +				    unsigned int *outputLen,
    1.41 +				    unsigned int maxOutputLen,
    1.42 +				    const unsigned char *input,
    1.43 +				    unsigned int inputLen,
    1.44 +				    unsigned int blocksize);
    1.45 +SECStatus intel_aes_encrypt_ecb_192(AESContext *cx, unsigned char *output,
    1.46 +				    unsigned int *outputLen,
    1.47 +				    unsigned int maxOutputLen,
    1.48 +				    const unsigned char *input,
    1.49 +				    unsigned int inputLen,
    1.50 +				    unsigned int blocksize);
    1.51 +SECStatus intel_aes_decrypt_ecb_192(AESContext *cx, unsigned char *output,
    1.52 +				    unsigned int *outputLen,
    1.53 +				    unsigned int maxOutputLen,
    1.54 +				    const unsigned char *input,
    1.55 +				    unsigned int inputLen,
    1.56 +				    unsigned int blocksize);
    1.57 +SECStatus intel_aes_encrypt_cbc_192(AESContext *cx, unsigned char *output,
    1.58 +				    unsigned int *outputLen,
    1.59 +				    unsigned int maxOutputLen,
    1.60 +				    const unsigned char *input,
    1.61 +				    unsigned int inputLen,
    1.62 +				    unsigned int blocksize);
    1.63 +SECStatus intel_aes_decrypt_cbc_192(AESContext *cx, unsigned char *output,
    1.64 +				    unsigned int *outputLen,
    1.65 +				    unsigned int maxOutputLen,
    1.66 +				    const unsigned char *input,
    1.67 +				    unsigned int inputLen,
    1.68 +				    unsigned int blocksize);
    1.69 +SECStatus intel_aes_encrypt_ctr_192(CTRContext *cx, unsigned char *output,
    1.70 +				    unsigned int *outputLen,
    1.71 +				    unsigned int maxOutputLen,
    1.72 +				    const unsigned char *input,
    1.73 +				    unsigned int inputLen,
    1.74 +				    unsigned int blocksize);
    1.75 +SECStatus intel_aes_encrypt_ecb_256(AESContext *cx, unsigned char *output,
    1.76 +				    unsigned int *outputLen,
    1.77 +				    unsigned int maxOutputLen,
    1.78 +				    const unsigned char *input,
    1.79 +				    unsigned int inputLen,
    1.80 +				    unsigned int blocksize);
    1.81 +SECStatus intel_aes_decrypt_ecb_256(AESContext *cx, unsigned char *output,
    1.82 +				    unsigned int *outputLen,
    1.83 +				    unsigned int maxOutputLen,
    1.84 +				    const unsigned char *input,
    1.85 +				    unsigned int inputLen,
    1.86 +				    unsigned int blocksize);
    1.87 +SECStatus intel_aes_encrypt_cbc_256(AESContext *cx, unsigned char *output,
    1.88 +				    unsigned int *outputLen,
    1.89 +				    unsigned int maxOutputLen,
    1.90 +				    const unsigned char *input,
    1.91 +				    unsigned int inputLen,
    1.92 +				    unsigned int blocksize);
    1.93 +SECStatus intel_aes_decrypt_cbc_256(AESContext *cx, unsigned char *output,
    1.94 +				    unsigned int *outputLen,
    1.95 +				    unsigned int maxOutputLen,
    1.96 +				    const unsigned char *input,
    1.97 +				    unsigned int inputLen,
    1.98 +				    unsigned int blocksize);
    1.99 +SECStatus intel_aes_encrypt_ctr_256(CTRContext *cx, unsigned char *output,
   1.100 +				    unsigned int *outputLen,
   1.101 +				    unsigned int maxOutputLen,
   1.102 +				    const unsigned char *input,
   1.103 +				    unsigned int inputLen,
   1.104 +				    unsigned int blocksize);
   1.105 +
   1.106 +
   1.107 +#define intel_aes_ecb_worker(encrypt, keysize) \
   1.108 +  ((encrypt)						\
   1.109 +   ? ((keysize) == 16 ? intel_aes_encrypt_ecb_128 :	\
   1.110 +      (keysize) == 24 ? intel_aes_encrypt_ecb_192 :	\
   1.111 +      intel_aes_encrypt_ecb_256)			\
   1.112 +   : ((keysize) == 16 ? intel_aes_decrypt_ecb_128 :	\
   1.113 +      (keysize) == 24 ? intel_aes_decrypt_ecb_192 :	\
   1.114 +      intel_aes_decrypt_ecb_256))
   1.115 +
   1.116 +
   1.117 +#define intel_aes_cbc_worker(encrypt, keysize) \
   1.118 +  ((encrypt)						\
   1.119 +   ? ((keysize) == 16 ? intel_aes_encrypt_cbc_128 :	\
   1.120 +      (keysize) == 24 ? intel_aes_encrypt_cbc_192 :	\
   1.121 +      intel_aes_encrypt_cbc_256)			\
   1.122 +   : ((keysize) == 16 ? intel_aes_decrypt_cbc_128 :	\
   1.123 +      (keysize) == 24 ? intel_aes_decrypt_cbc_192 :	\
   1.124 +      intel_aes_decrypt_cbc_256))
   1.125 +
   1.126 +#define intel_aes_ctr_worker(nr) \
   1.127 +   ((nr) == 10 ? intel_aes_encrypt_ctr_128 :	\
   1.128 +    (nr) == 12 ? intel_aes_encrypt_ctr_192 :	\
   1.129 +    intel_aes_encrypt_ctr_256)
   1.130 +
   1.131 +
   1.132 +#define intel_aes_init(encrypt, keysize) \
   1.133 +  do {					 			\
   1.134 +      if (encrypt) {			 			\
   1.135 +	  if (keysize == 16)					\
   1.136 +	      intel_aes_encrypt_init_128(key, cx->expandedKey);	\
   1.137 +	  else if (keysize == 24)				\
   1.138 +	      intel_aes_encrypt_init_192(key, cx->expandedKey);	\
   1.139 +	  else							\
   1.140 +	      intel_aes_encrypt_init_256(key, cx->expandedKey);	\
   1.141 +      } else {							\
   1.142 +	  if (keysize == 16)					\
   1.143 +	      intel_aes_decrypt_init_128(key, cx->expandedKey);	\
   1.144 +	  else if (keysize == 24)				\
   1.145 +	      intel_aes_decrypt_init_192(key, cx->expandedKey);	\
   1.146 +	  else							\
   1.147 +	      intel_aes_decrypt_init_256(key, cx->expandedKey);	\
   1.148 +      }								\
   1.149 +  } while (0)

mercurial