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