1/* $KAME: rijndael-api-fst.h,v 1.1.1.1 2001/08/08 09:56:27 sakane Exp $ */ 2 3/* 4 * rijndael-api-fst.h v2.3 April '2000 5 * 6 * Optimised ANSI C code 7 * 8 * #define INTERMEDIATE_VALUE_KAT to generate the Intermediate Value Known Answer Test. 9 */ 10 11#ifndef __RIJNDAEL_API_FST_H 12#define __RIJNDAEL_API_FST_H 13 14#include <crypto/rijndael/rijndael-alg-fst.h> 15 16/* Defines: 17 Add any additional defines you need 18*/ 19 20#define DIR_ENCRYPT 0 /* Are we encrpyting? */ 21#define DIR_DECRYPT 1 /* Are we decrpyting? */ 22#define MODE_ECB 1 /* Are we ciphering in ECB mode? */ 23#define MODE_CBC 2 /* Are we ciphering in CBC mode? */ 24#define MODE_CFB1 3 /* Are we ciphering in 1-bit CFB mode? */ 25#define TRUE 1 26#define FALSE 0 27#define BITSPERBLOCK 128 /* Default number of bits in a cipher block */ 28 29/* Error Codes - CHANGE POSSIBLE: inclusion of additional error codes */ 30#define BAD_KEY_DIR -1 /* Key direction is invalid, e.g., unknown value */ 31#define BAD_KEY_MAT -2 /* Key material not of correct length */ 32#define BAD_KEY_INSTANCE -3 /* Key passed is not valid */ 33#define BAD_CIPHER_MODE -4 /* Params struct passed to cipherInit invalid */ 34#define BAD_CIPHER_STATE -5 /* Cipher in wrong state (e.g., not initialized) */ 35#define BAD_BLOCK_LENGTH -6 36#define BAD_CIPHER_INSTANCE -7 37#define BAD_DATA -8 /* Data contents are invalid, e.g., invalid padding */ 38#define BAD_OTHER -9 /* Unknown error */ 39 40/* CHANGE POSSIBLE: inclusion of algorithm specific defines */ 41#define MAX_KEY_SIZE 64 /* # of ASCII char's needed to represent a key */ 42#define MAX_IV_SIZE 16 /* # bytes needed to represent an IV */ 43 44/* Typedefs: 45 46 Typedef'ed data storage elements. Add any algorithm specific 47parameters at the bottom of the structs as appropriate. 48*/ 49 50/* The structure for key information */ 51typedef struct { 52 u_int8_t direction; /* Key used for encrypting or decrypting? */ 53 int keyLen; /* Length of the key */ 54 char keyMaterial[MAX_KEY_SIZE+1]; /* Raw key data in ASCII, e.g., user input or KAT values */ 55 /* The following parameters are algorithm dependent, replace or add as necessary */ 56 int ROUNDS; /* key-length-dependent number of rounds */ 57 int blockLen; /* block length */ 58 union { 59 u_int8_t xkS8[RIJNDAEL_MAXROUNDS+1][4][4]; /* key schedule */ 60 u_int32_t xkS32[RIJNDAEL_MAXROUNDS+1][4]; /* key schedule */ 61 } xKeySched; 62#define keySched xKeySched.xkS8 63} keyInstance; 64 65/* The structure for cipher information */ 66typedef struct { /* changed order of the components */ 67 u_int8_t mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */ 68 u_int8_t IV[MAX_IV_SIZE]; /* A possible Initialization Vector for ciphering */ 69 /* Add any algorithm specific parameters needed here */ 70 int blockLen; /* Sample: Handles non-128 bit block sizes (if available) */ 71} cipherInstance; 72 73/* Function prototypes */ 74/* CHANGED: nothing 75 TODO: implement the following extensions to setup 192-bit and 256-bit block lengths: 76 makeKeyEx(): parameter blockLen added 77 -- this parameter is absolutely necessary if you want to 78 setup the round keys in a variable block length setting 79 cipherInitEx(): parameter blockLen added (for obvious reasons) 80 */ 81 82int rijndael_makeKey(keyInstance *key, u_int8_t direction, int keyLen, char *keyMaterial); 83 84int rijndael_cipherInit(cipherInstance *cipher, u_int8_t mode, char *IV); 85 86int rijndael_blockEncrypt(cipherInstance *cipher, keyInstance *key, 87 u_int8_t *input, int inputLen, u_int8_t *outBuffer); 88 89int rijndael_padEncrypt(cipherInstance *cipher, keyInstance *key, 90 u_int8_t *input, int inputOctets, u_int8_t *outBuffer); 91 92int rijndael_blockDecrypt(cipherInstance *cipher, keyInstance *key, 93 u_int8_t *input, int inputLen, u_int8_t *outBuffer); 94 95int rijndael_padDecrypt(cipherInstance *cipher, keyInstance *key, 96 u_int8_t *input, int inputOctets, u_int8_t *outBuffer); 97 98#ifdef INTERMEDIATE_VALUE_KAT 99int rijndael_cipherUpdateRounds(cipherInstance *cipher, keyInstance *key, 100 u_int8_t *input, int inputLen, u_int8_t *outBuffer, int Rounds); 101#endif /* INTERMEDIATE_VALUE_KAT */ 102 103#endif /* __RIJNDAEL_API_FST_H */ 104