michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _RIJNDAEL_H_ michael@0: #define _RIJNDAEL_H_ 1 michael@0: michael@0: #include "blapii.h" michael@0: michael@0: #define RIJNDAEL_MIN_BLOCKSIZE 16 /* bytes */ michael@0: #define RIJNDAEL_MAX_BLOCKSIZE 32 /* bytes */ michael@0: michael@0: typedef SECStatus AESBlockFunc(AESContext *cx, michael@0: unsigned char *output, michael@0: const unsigned char *input); michael@0: michael@0: /* RIJNDAEL_NUM_ROUNDS michael@0: * michael@0: * Number of rounds per execution michael@0: * Nk - number of key bytes michael@0: * Nb - blocksize (in bytes) michael@0: */ michael@0: #define RIJNDAEL_NUM_ROUNDS(Nk, Nb) \ michael@0: (PR_MAX(Nk, Nb) + 6) michael@0: michael@0: /* RIJNDAEL_MAX_STATE_SIZE michael@0: * michael@0: * Maximum number of bytes in the state (spec includes up to 256-bit block michael@0: * size) michael@0: */ michael@0: #define RIJNDAEL_MAX_STATE_SIZE 32 michael@0: michael@0: /* michael@0: * This magic number is (Nb_max * (Nr_max + 1)) michael@0: * where Nb_max is the maximum block size in 32-bit words, michael@0: * Nr_max is the maximum number of rounds, which is Nb_max + 6 michael@0: */ michael@0: #define RIJNDAEL_MAX_EXP_KEY_SIZE (8 * 15) michael@0: michael@0: /* AESContextStr michael@0: * michael@0: * Values which maintain the state for Rijndael encryption/decryption. michael@0: * michael@0: * iv - initialization vector for CBC mode michael@0: * Nb - the number of bytes in a block, specified by user michael@0: * Nr - the number of rounds, specified by a table michael@0: * expandedKey - the round keys in 4-byte words, the length is Nr * Nb michael@0: * worker - the encryption/decryption function to use with worker_cx michael@0: * destroy - if not NULL, the destroy function to use with worker_cx michael@0: * worker_cx - the context for worker and destroy michael@0: * isBlock - is the mode of operation a block cipher or a stream cipher? michael@0: */ michael@0: struct AESContextStr michael@0: { michael@0: unsigned int Nb; michael@0: unsigned int Nr; michael@0: freeblCipherFunc worker; michael@0: /* NOTE: The offsets of iv and expandedKey are hardcoded in intel-aes.s. michael@0: * Don't add new members before them without updating intel-aes.s. */ michael@0: unsigned char iv[RIJNDAEL_MAX_BLOCKSIZE]; michael@0: PRUint32 expandedKey[RIJNDAEL_MAX_EXP_KEY_SIZE]; michael@0: freeblDestroyFunc destroy; michael@0: void *worker_cx; michael@0: PRBool isBlock; michael@0: }; michael@0: michael@0: #endif /* _RIJNDAEL_H_ */