Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef _RIJNDAEL_H_ |
michael@0 | 6 | #define _RIJNDAEL_H_ 1 |
michael@0 | 7 | |
michael@0 | 8 | #include "blapii.h" |
michael@0 | 9 | |
michael@0 | 10 | #define RIJNDAEL_MIN_BLOCKSIZE 16 /* bytes */ |
michael@0 | 11 | #define RIJNDAEL_MAX_BLOCKSIZE 32 /* bytes */ |
michael@0 | 12 | |
michael@0 | 13 | typedef SECStatus AESBlockFunc(AESContext *cx, |
michael@0 | 14 | unsigned char *output, |
michael@0 | 15 | const unsigned char *input); |
michael@0 | 16 | |
michael@0 | 17 | /* RIJNDAEL_NUM_ROUNDS |
michael@0 | 18 | * |
michael@0 | 19 | * Number of rounds per execution |
michael@0 | 20 | * Nk - number of key bytes |
michael@0 | 21 | * Nb - blocksize (in bytes) |
michael@0 | 22 | */ |
michael@0 | 23 | #define RIJNDAEL_NUM_ROUNDS(Nk, Nb) \ |
michael@0 | 24 | (PR_MAX(Nk, Nb) + 6) |
michael@0 | 25 | |
michael@0 | 26 | /* RIJNDAEL_MAX_STATE_SIZE |
michael@0 | 27 | * |
michael@0 | 28 | * Maximum number of bytes in the state (spec includes up to 256-bit block |
michael@0 | 29 | * size) |
michael@0 | 30 | */ |
michael@0 | 31 | #define RIJNDAEL_MAX_STATE_SIZE 32 |
michael@0 | 32 | |
michael@0 | 33 | /* |
michael@0 | 34 | * This magic number is (Nb_max * (Nr_max + 1)) |
michael@0 | 35 | * where Nb_max is the maximum block size in 32-bit words, |
michael@0 | 36 | * Nr_max is the maximum number of rounds, which is Nb_max + 6 |
michael@0 | 37 | */ |
michael@0 | 38 | #define RIJNDAEL_MAX_EXP_KEY_SIZE (8 * 15) |
michael@0 | 39 | |
michael@0 | 40 | /* AESContextStr |
michael@0 | 41 | * |
michael@0 | 42 | * Values which maintain the state for Rijndael encryption/decryption. |
michael@0 | 43 | * |
michael@0 | 44 | * iv - initialization vector for CBC mode |
michael@0 | 45 | * Nb - the number of bytes in a block, specified by user |
michael@0 | 46 | * Nr - the number of rounds, specified by a table |
michael@0 | 47 | * expandedKey - the round keys in 4-byte words, the length is Nr * Nb |
michael@0 | 48 | * worker - the encryption/decryption function to use with worker_cx |
michael@0 | 49 | * destroy - if not NULL, the destroy function to use with worker_cx |
michael@0 | 50 | * worker_cx - the context for worker and destroy |
michael@0 | 51 | * isBlock - is the mode of operation a block cipher or a stream cipher? |
michael@0 | 52 | */ |
michael@0 | 53 | struct AESContextStr |
michael@0 | 54 | { |
michael@0 | 55 | unsigned int Nb; |
michael@0 | 56 | unsigned int Nr; |
michael@0 | 57 | freeblCipherFunc worker; |
michael@0 | 58 | /* NOTE: The offsets of iv and expandedKey are hardcoded in intel-aes.s. |
michael@0 | 59 | * Don't add new members before them without updating intel-aes.s. */ |
michael@0 | 60 | unsigned char iv[RIJNDAEL_MAX_BLOCKSIZE]; |
michael@0 | 61 | PRUint32 expandedKey[RIJNDAEL_MAX_EXP_KEY_SIZE]; |
michael@0 | 62 | freeblDestroyFunc destroy; |
michael@0 | 63 | void *worker_cx; |
michael@0 | 64 | PRBool isBlock; |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | #endif /* _RIJNDAEL_H_ */ |