1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* Prototypes of the functions defined in the assembler file. */ 6 void intel_aes_encrypt_init_128(const unsigned char *key, PRUint32 *expanded); 7 void intel_aes_encrypt_init_192(const unsigned char *key, PRUint32 *expanded); 8 void intel_aes_encrypt_init_256(const unsigned char *key, PRUint32 *expanded); 9 void intel_aes_decrypt_init_128(const unsigned char *key, PRUint32 *expanded); 10 void intel_aes_decrypt_init_192(const unsigned char *key, PRUint32 *expanded); 11 void intel_aes_decrypt_init_256(const unsigned char *key, PRUint32 *expanded); 12 SECStatus intel_aes_encrypt_ecb_128(AESContext *cx, unsigned char *output, 13 unsigned int *outputLen, 14 unsigned int maxOutputLen, 15 const unsigned char *input, 16 unsigned int inputLen, 17 unsigned int blocksize); 18 SECStatus intel_aes_decrypt_ecb_128(AESContext *cx, unsigned char *output, 19 unsigned int *outputLen, 20 unsigned int maxOutputLen, 21 const unsigned char *input, 22 unsigned int inputLen, 23 unsigned int blocksize); 24 SECStatus intel_aes_encrypt_cbc_128(AESContext *cx, unsigned char *output, 25 unsigned int *outputLen, 26 unsigned int maxOutputLen, 27 const unsigned char *input, 28 unsigned int inputLen, 29 unsigned int blocksize); 30 SECStatus intel_aes_decrypt_cbc_128(AESContext *cx, unsigned char *output, 31 unsigned int *outputLen, 32 unsigned int maxOutputLen, 33 const unsigned char *input, 34 unsigned int inputLen, 35 unsigned int blocksize); 36 SECStatus intel_aes_encrypt_ctr_128(CTRContext *cx, unsigned char *output, 37 unsigned int *outputLen, 38 unsigned int maxOutputLen, 39 const unsigned char *input, 40 unsigned int inputLen, 41 unsigned int blocksize); 42 SECStatus intel_aes_encrypt_ecb_192(AESContext *cx, unsigned char *output, 43 unsigned int *outputLen, 44 unsigned int maxOutputLen, 45 const unsigned char *input, 46 unsigned int inputLen, 47 unsigned int blocksize); 48 SECStatus intel_aes_decrypt_ecb_192(AESContext *cx, unsigned char *output, 49 unsigned int *outputLen, 50 unsigned int maxOutputLen, 51 const unsigned char *input, 52 unsigned int inputLen, 53 unsigned int blocksize); 54 SECStatus intel_aes_encrypt_cbc_192(AESContext *cx, unsigned char *output, 55 unsigned int *outputLen, 56 unsigned int maxOutputLen, 57 const unsigned char *input, 58 unsigned int inputLen, 59 unsigned int blocksize); 60 SECStatus intel_aes_decrypt_cbc_192(AESContext *cx, unsigned char *output, 61 unsigned int *outputLen, 62 unsigned int maxOutputLen, 63 const unsigned char *input, 64 unsigned int inputLen, 65 unsigned int blocksize); 66 SECStatus intel_aes_encrypt_ctr_192(CTRContext *cx, unsigned char *output, 67 unsigned int *outputLen, 68 unsigned int maxOutputLen, 69 const unsigned char *input, 70 unsigned int inputLen, 71 unsigned int blocksize); 72 SECStatus intel_aes_encrypt_ecb_256(AESContext *cx, unsigned char *output, 73 unsigned int *outputLen, 74 unsigned int maxOutputLen, 75 const unsigned char *input, 76 unsigned int inputLen, 77 unsigned int blocksize); 78 SECStatus intel_aes_decrypt_ecb_256(AESContext *cx, unsigned char *output, 79 unsigned int *outputLen, 80 unsigned int maxOutputLen, 81 const unsigned char *input, 82 unsigned int inputLen, 83 unsigned int blocksize); 84 SECStatus intel_aes_encrypt_cbc_256(AESContext *cx, unsigned char *output, 85 unsigned int *outputLen, 86 unsigned int maxOutputLen, 87 const unsigned char *input, 88 unsigned int inputLen, 89 unsigned int blocksize); 90 SECStatus intel_aes_decrypt_cbc_256(AESContext *cx, unsigned char *output, 91 unsigned int *outputLen, 92 unsigned int maxOutputLen, 93 const unsigned char *input, 94 unsigned int inputLen, 95 unsigned int blocksize); 96 SECStatus intel_aes_encrypt_ctr_256(CTRContext *cx, unsigned char *output, 97 unsigned int *outputLen, 98 unsigned int maxOutputLen, 99 const unsigned char *input, 100 unsigned int inputLen, 101 unsigned int blocksize); 102 103 #define native_aes_ecb_worker(encrypt, keysize) \ 104 ((encrypt) \ 105 ? ((keysize) == 16 ? intel_aes_encrypt_ecb_128 \ 106 : (keysize) == 24 ? intel_aes_encrypt_ecb_192 \ 107 : intel_aes_encrypt_ecb_256) \ 108 : ((keysize) == 16 ? intel_aes_decrypt_ecb_128 \ 109 : (keysize) == 24 ? intel_aes_decrypt_ecb_192 \ 110 : intel_aes_decrypt_ecb_256)) 111 112 #define native_aes_cbc_worker(encrypt, keysize) \ 113 ((encrypt) \ 114 ? ((keysize) == 16 ? intel_aes_encrypt_cbc_128 \ 115 : (keysize) == 24 ? intel_aes_encrypt_cbc_192 \ 116 : intel_aes_encrypt_cbc_256) \ 117 : ((keysize) == 16 ? intel_aes_decrypt_cbc_128 \ 118 : (keysize) == 24 ? intel_aes_decrypt_cbc_192 \ 119 : intel_aes_decrypt_cbc_256)) 120 121 #define intel_aes_ctr_worker(nr) \ 122 ((nr) == 10 ? intel_aes_encrypt_ctr_128 \ 123 : (nr) == 12 ? intel_aes_encrypt_ctr_192 \ 124 : intel_aes_encrypt_ctr_256) 125 126 #define native_aes_init(encrypt, keysize) \ 127 do { \ 128 if (encrypt) { \ 129 if (keysize == 16) \ 130 intel_aes_encrypt_init_128(key, cx->k.expandedKey); \ 131 else if (keysize == 24) \ 132 intel_aes_encrypt_init_192(key, cx->k.expandedKey); \ 133 else \ 134 intel_aes_encrypt_init_256(key, cx->k.expandedKey); \ 135 } else { \ 136 if (keysize == 16) \ 137 intel_aes_decrypt_init_128(key, cx->k.expandedKey); \ 138 else if (keysize == 24) \ 139 intel_aes_decrypt_init_192(key, cx->k.expandedKey); \ 140 else \ 141 intel_aes_decrypt_init_256(key, cx->k.expandedKey); \ 142 } \ 143 } while (0) 144