andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: /* Prototypes of the functions defined in the assembler file. */ andre@0: void intel_aes_encrypt_init_128(const unsigned char *key, PRUint32 *expanded); andre@0: void intel_aes_encrypt_init_192(const unsigned char *key, PRUint32 *expanded); andre@0: void intel_aes_encrypt_init_256(const unsigned char *key, PRUint32 *expanded); andre@0: void intel_aes_decrypt_init_128(const unsigned char *key, PRUint32 *expanded); andre@0: void intel_aes_decrypt_init_192(const unsigned char *key, PRUint32 *expanded); andre@0: void intel_aes_decrypt_init_256(const unsigned char *key, PRUint32 *expanded); andre@0: SECStatus intel_aes_encrypt_ecb_128(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_decrypt_ecb_128(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_encrypt_cbc_128(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_decrypt_cbc_128(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_encrypt_ctr_128(CTRContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_encrypt_ecb_192(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_decrypt_ecb_192(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_encrypt_cbc_192(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_decrypt_cbc_192(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_encrypt_ctr_192(CTRContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_encrypt_ecb_256(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_decrypt_ecb_256(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_encrypt_cbc_256(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_decrypt_cbc_256(AESContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: SECStatus intel_aes_encrypt_ctr_256(CTRContext *cx, unsigned char *output, andre@0: unsigned int *outputLen, andre@0: unsigned int maxOutputLen, andre@0: const unsigned char *input, andre@0: unsigned int inputLen, andre@0: unsigned int blocksize); andre@0: andre@0: andre@0: #define intel_aes_ecb_worker(encrypt, keysize) \ andre@0: ((encrypt) \ andre@0: ? ((keysize) == 16 ? intel_aes_encrypt_ecb_128 : \ andre@0: (keysize) == 24 ? intel_aes_encrypt_ecb_192 : \ andre@0: intel_aes_encrypt_ecb_256) \ andre@0: : ((keysize) == 16 ? intel_aes_decrypt_ecb_128 : \ andre@0: (keysize) == 24 ? intel_aes_decrypt_ecb_192 : \ andre@0: intel_aes_decrypt_ecb_256)) andre@0: andre@0: andre@0: #define intel_aes_cbc_worker(encrypt, keysize) \ andre@0: ((encrypt) \ andre@0: ? ((keysize) == 16 ? intel_aes_encrypt_cbc_128 : \ andre@0: (keysize) == 24 ? intel_aes_encrypt_cbc_192 : \ andre@0: intel_aes_encrypt_cbc_256) \ andre@0: : ((keysize) == 16 ? intel_aes_decrypt_cbc_128 : \ andre@0: (keysize) == 24 ? intel_aes_decrypt_cbc_192 : \ andre@0: intel_aes_decrypt_cbc_256)) andre@0: andre@0: #define intel_aes_ctr_worker(nr) \ andre@0: ((nr) == 10 ? intel_aes_encrypt_ctr_128 : \ andre@0: (nr) == 12 ? intel_aes_encrypt_ctr_192 : \ andre@0: intel_aes_encrypt_ctr_256) andre@0: andre@0: andre@0: #define intel_aes_init(encrypt, keysize) \ andre@0: do { \ andre@0: if (encrypt) { \ andre@0: if (keysize == 16) \ andre@0: intel_aes_encrypt_init_128(key, cx->expandedKey); \ andre@0: else if (keysize == 24) \ andre@0: intel_aes_encrypt_init_192(key, cx->expandedKey); \ andre@0: else \ andre@0: intel_aes_encrypt_init_256(key, cx->expandedKey); \ andre@0: } else { \ andre@0: if (keysize == 16) \ andre@0: intel_aes_decrypt_init_128(key, cx->expandedKey); \ andre@0: else if (keysize == 24) \ andre@0: intel_aes_decrypt_init_192(key, cx->expandedKey); \ andre@0: else \ andre@0: intel_aes_decrypt_init_256(key, cx->expandedKey); \ andre@0: } \ andre@0: } while (0)