Index: trunk/include/rijndael-api-fst.h
===================================================================
--- trunk/include/rijndael-api-fst.h	(revision 230)
+++ trunk/include/rijndael-api-fst.h	(revision 481)
@@ -1,7 +1,39 @@
-/*
- * rijndael-api-fst.h   v2.3   April '2000
+/*	$NetBSD: rijndael-api-fst.h,v 1.8 2007/01/21 23:00:08 cbiere Exp $	*/
+
+/**
+ * rijndael-api-fst.h
  *
- * Optimised ANSI C code
+ * @version 2.9 (December 2000)
  *
+ * Optimised ANSI C code for the Rijndael cipher (now AES)
+ *
+ * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
+ * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
+ * @author Paulo Barreto <paulo.barreto@terra.com.br>
+ *
+ * This code is hereby placed in the public domain.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Acknowledgements:
+ *
+ * We are deeply indebted to the following people for their bug reports,
+ * fixes, and improvement suggestions to this implementation. Though we
+ * tried to list all contributions, we apologise in advance for any
+ * missing reference.
+ *
+ * Andrew Bales <Andrew.Bales@Honeywell.com>
+ * Markus Friedl <markus.friedl@informatik.uni-erlangen.de>
+ * John Skodon <skodonj@webquill.com>
  */
 
@@ -9,15 +41,30 @@
 #define __RIJNDAEL_API_FST_H
 
+/* Blocksize: 16 * 8 = 128; 128 * 1 = 128 */
+#define     B_SIZ    16
+#define     BNUM      1
+
+
+#if defined(UINT32)
+typedef unsigned char u8;
+typedef UINT32 u32;
+#else
+
+typedef unsigned char u8;
+#if defined(HAVE_INT_32)
+typedef unsigned int u32;
+#elif defined(HAVE_LONG_32)
+typedef unsigned long u32;
+#elif defined(HAVE_SHORT_32)
+typedef unsigned short u32;
+#else
+#error "No 32 bit integer type found"
+#endif
+
+#endif
+
 #include "rijndael-alg-fst.h"
 
-/*  Defines:
-    Add any additional defines you need
-*/
-
-#define     BNUM                  1
-#define     B_SIZ                 16
-#define     STRICT_ALIGN          1 /*  For safety          */
-
-
+/*  Generic Defines  */
 #define     DIR_ENCRYPT           0 /*  Are we encrpyting?  */
 #define     DIR_DECRYPT           1 /*  Are we decrpyting?  */
@@ -33,6 +80,5 @@
 #define     BITSPERBLOCK        128 /* Default number of bits in a cipher block */
 
-/*  Error Codes - CHANGE POSSIBLE: inclusion of additional error codes  */
-
+/*  Error Codes  */
 #define     BAD_KEY_DIR          -1 /*  Key direction is invalid, e.g., unknown value */
 #define     BAD_KEY_MAT          -2 /*  Key material not of correct length */
@@ -45,63 +91,46 @@
 #define     BAD_OTHER            -9 /*  Unknown error */
 
-/*  CHANGE POSSIBLE:  inclusion of algorithm specific defines  */
-#define     MAX_KEY_SIZE         64 /* # of ASCII char's needed to represent a key */
-#define     MAX_IV_SIZE          16 /* # bytes needed to represent an IV  */
+/*  Algorithm-specific Defines  */
+#define     RIJNDAEL_MAX_KEY_SIZE         64 /* # of ASCII char's needed to represent a key */
+#define     RIJNDAEL_MAX_IV_SIZE          16 /* # bytes needed to represent an IV  */
 
 #ifdef SH_ENCRYPT
 
-/*  Typedefs:
+/*  Typedefs  */
 
-	Typedef'ed data storage elements.  Add any algorithm specific 
-parameters at the bottom of the structs as appropriate.
-*/
-
-typedef unsigned char   RIJ_BYTE;
+typedef unsigned char   BYTE;
 
 /*  The structure for key information */
 typedef struct {
-    RIJ_BYTE  direction;                /* Key used for encrypting or decrypting? */
-    int   keyLen;                   /* Length of the key  */
-    char  keyMaterial[MAX_KEY_SIZE+1];  /* Raw key data in ASCII, e.g., user input or KAT values */
-        /*  The following parameters are algorithm dependent, replace or add as necessary  */
-	int   ROUNDS;                   /* key-length-dependent number of rounds */
-    int   blockLen;                 /* block length */
-    word8 keySched[MAXROUNDS+1][4][4];	/* key schedule		*/
+  u32   rk[4*(RIJNDAEL_MAXNR + 1)];        /* key schedule */
+  u32   ek[4*(RIJNDAEL_MAXNR + 1)];        /* CFB1 key schedule (encryption only) */
+  BYTE  direction;                /* Key used for encrypting or decrypting? */
+  int   keyLen;                   /* Length of the key  */
+  char  keyMaterial[RIJNDAEL_MAX_KEY_SIZE+1];  /* Raw key data in ASCII, e.g., user input or KAT values */
+  int   Nr;                       /* key-length-dependent number of rounds */
 } keyInstance;
 
 /*  The structure for cipher information */
 typedef struct {                    /* changed order of the components */
-    RIJ_BYTE  mode;                     /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
-    RIJ_BYTE  IV[MAX_IV_SIZE];          /* A possible Initialization Vector for ciphering */
-        /*  Add any algorithm specific parameters needed here  */
-    int   blockLen;                 /* Sample: Handles non-128 bit block sizes (if available) */
+    u32  IV[RIJNDAEL_MAX_IV_SIZE / sizeof(u32)];
+			/* A possible Initialization Vector for ciphering */
+    BYTE  mode;                     /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
 } cipherInstance;
 
 /*  Function prototypes  */
-/*  CHANGED: nothing
-	TODO: implement the following extensions to setup 192-bit and 256-bit block lengths:
-        makeKeyEx():    parameter blockLen added
-                        -- this parameter is absolutely necessary if you want to
-                        setup the round keys in a variable block length setting 
-	    cipherInitEx(): parameter blockLen added (for obvious reasons)		
- */
 
-int makeKey(keyInstance *key, RIJ_BYTE direction, int keyLen, char *keyMaterial);
+int rijndael_makeKey(keyInstance *, BYTE, int, const char *);
 
-int cipherInit(cipherInstance *cipher, RIJ_BYTE mode, char *IV);
+int rijndael_cipherInit(cipherInstance *, BYTE, const char *);
 
-int blockEncrypt(cipherInstance *cipher, keyInstance *key,
-		 RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer);
+int rijndael_blockEncrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
 
-int blockDecrypt(cipherInstance *cipher, keyInstance *key,
-		 RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer);
-#ifdef INTERMEDIATE_VALUE_KAT
-int cipherUpdateRounds(cipherInstance *cipher, keyInstance *key,
-		       RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer, int rounds);
-#endif
+int rijndael_padEncrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
+
+int rijndael_blockDecrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
+
+int rijndael_padDecrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
 
 /* SH_ENCRYPT */
 #endif
-
-/*  __RIJNDAEL_API_FST_H */
-#endif 
+#endif /* __RIJNDAEL_API_FST_H */
