Changeset 481 for trunk/include/rijndael-api-fst.h
- Timestamp:
- Jul 18, 2015, 5:06:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/rijndael-api-fst.h
r230 r481 1 /* 2 * rijndael-api-fst.h v2.3 April '2000 1 /* $NetBSD: rijndael-api-fst.h,v 1.8 2007/01/21 23:00:08 cbiere Exp $ */ 2 3 /** 4 * rijndael-api-fst.h 3 5 * 4 * Optimised ANSI C code6 * @version 2.9 (December 2000) 5 7 * 8 * Optimised ANSI C code for the Rijndael cipher (now AES) 9 * 10 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be> 11 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be> 12 * @author Paulo Barreto <paulo.barreto@terra.com.br> 13 * 14 * This code is hereby placed in the public domain. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Acknowledgements: 29 * 30 * We are deeply indebted to the following people for their bug reports, 31 * fixes, and improvement suggestions to this implementation. Though we 32 * tried to list all contributions, we apologise in advance for any 33 * missing reference. 34 * 35 * Andrew Bales <Andrew.Bales@Honeywell.com> 36 * Markus Friedl <markus.friedl@informatik.uni-erlangen.de> 37 * John Skodon <skodonj@webquill.com> 6 38 */ 7 39 … … 9 41 #define __RIJNDAEL_API_FST_H 10 42 43 /* Blocksize: 16 * 8 = 128; 128 * 1 = 128 */ 44 #define B_SIZ 16 45 #define BNUM 1 46 47 48 #if defined(UINT32) 49 typedef unsigned char u8; 50 typedef UINT32 u32; 51 #else 52 53 typedef unsigned char u8; 54 #if defined(HAVE_INT_32) 55 typedef unsigned int u32; 56 #elif defined(HAVE_LONG_32) 57 typedef unsigned long u32; 58 #elif defined(HAVE_SHORT_32) 59 typedef unsigned short u32; 60 #else 61 #error "No 32 bit integer type found" 62 #endif 63 64 #endif 65 11 66 #include "rijndael-alg-fst.h" 12 67 13 /* Defines: 14 Add any additional defines you need 15 */ 16 17 #define BNUM 1 18 #define B_SIZ 16 19 #define STRICT_ALIGN 1 /* For safety */ 20 21 68 /* Generic Defines */ 22 69 #define DIR_ENCRYPT 0 /* Are we encrpyting? */ 23 70 #define DIR_DECRYPT 1 /* Are we decrpyting? */ … … 33 80 #define BITSPERBLOCK 128 /* Default number of bits in a cipher block */ 34 81 35 /* Error Codes - CHANGE POSSIBLE: inclusion of additional error codes */ 36 82 /* Error Codes */ 37 83 #define BAD_KEY_DIR -1 /* Key direction is invalid, e.g., unknown value */ 38 84 #define BAD_KEY_MAT -2 /* Key material not of correct length */ … … 45 91 #define BAD_OTHER -9 /* Unknown error */ 46 92 47 /* CHANGE POSSIBLE: inclusion of algorithm specific defines */48 #define MAX_KEY_SIZE 64 /* # of ASCII char's needed to represent a key */49 #define MAX_IV_SIZE 16 /* # bytes needed to represent an IV */93 /* Algorithm-specific Defines */ 94 #define RIJNDAEL_MAX_KEY_SIZE 64 /* # of ASCII char's needed to represent a key */ 95 #define RIJNDAEL_MAX_IV_SIZE 16 /* # bytes needed to represent an IV */ 50 96 51 97 #ifdef SH_ENCRYPT 52 98 53 /* Typedefs :99 /* Typedefs */ 54 100 55 Typedef'ed data storage elements. Add any algorithm specific 56 parameters at the bottom of the structs as appropriate. 57 */ 58 59 typedef unsigned char RIJ_BYTE; 101 typedef unsigned char BYTE; 60 102 61 103 /* The structure for key information */ 62 104 typedef struct { 63 RIJ_BYTE direction; /* Key used for encrypting or decrypting? */ 64 int keyLen; /* Length of the key */ 65 char keyMaterial[MAX_KEY_SIZE+1]; /* Raw key data in ASCII, e.g., user input or KAT values */ 66 /* The following parameters are algorithm dependent, replace or add as necessary */ 67 int ROUNDS; /* key-length-dependent number of rounds */ 68 int blockLen; /* block length */ 69 word8 keySched[MAXROUNDS+1][4][4]; /* key schedule */ 105 u32 rk[4*(RIJNDAEL_MAXNR + 1)]; /* key schedule */ 106 u32 ek[4*(RIJNDAEL_MAXNR + 1)]; /* CFB1 key schedule (encryption only) */ 107 BYTE direction; /* Key used for encrypting or decrypting? */ 108 int keyLen; /* Length of the key */ 109 char keyMaterial[RIJNDAEL_MAX_KEY_SIZE+1]; /* Raw key data in ASCII, e.g., user input or KAT values */ 110 int Nr; /* key-length-dependent number of rounds */ 70 111 } keyInstance; 71 112 72 113 /* The structure for cipher information */ 73 114 typedef struct { /* changed order of the components */ 74 RIJ_BYTE mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */ 75 RIJ_BYTE IV[MAX_IV_SIZE]; /* A possible Initialization Vector for ciphering */ 76 /* Add any algorithm specific parameters needed here */ 77 int blockLen; /* Sample: Handles non-128 bit block sizes (if available) */ 115 u32 IV[RIJNDAEL_MAX_IV_SIZE / sizeof(u32)]; 116 /* A possible Initialization Vector for ciphering */ 117 BYTE mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */ 78 118 } cipherInstance; 79 119 80 120 /* Function prototypes */ 81 /* CHANGED: nothing82 TODO: implement the following extensions to setup 192-bit and 256-bit block lengths:83 makeKeyEx(): parameter blockLen added84 -- this parameter is absolutely necessary if you want to85 setup the round keys in a variable block length setting86 cipherInitEx(): parameter blockLen added (for obvious reasons)87 */88 121 89 int makeKey(keyInstance *key, RIJ_BYTE direction, int keyLen, char *keyMaterial);122 int rijndael_makeKey(keyInstance *, BYTE, int, const char *); 90 123 91 int cipherInit(cipherInstance *cipher, RIJ_BYTE mode, char *IV);124 int rijndael_cipherInit(cipherInstance *, BYTE, const char *); 92 125 93 int blockEncrypt(cipherInstance *cipher, keyInstance *key, 94 RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer); 126 int rijndael_blockEncrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *); 95 127 96 int blockDecrypt(cipherInstance *cipher, keyInstance *key, 97 RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer); 98 #ifdef INTERMEDIATE_VALUE_KAT 99 int cipherUpdateRounds(cipherInstance *cipher, keyInstance *key, 100 RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer, int rounds); 101 #endif 128 int rijndael_padEncrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *); 129 130 int rijndael_blockDecrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *); 131 132 int rijndael_padDecrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *); 102 133 103 134 /* SH_ENCRYPT */ 104 135 #endif 105 106 /* __RIJNDAEL_API_FST_H */ 107 #endif 136 #endif /* __RIJNDAEL_API_FST_H */
Note:
See TracChangeset
for help on using the changeset viewer.