summaryrefslogtreecommitdiffstats
path: root/sys/crypto/rijndael/rijndael-api-fst.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/crypto/rijndael/rijndael-api-fst.h')
-rw-r--r--sys/crypto/rijndael/rijndael-api-fst.h112
1 files changed, 54 insertions, 58 deletions
diff --git a/sys/crypto/rijndael/rijndael-api-fst.h b/sys/crypto/rijndael/rijndael-api-fst.h
index c78b093..f153b69 100644
--- a/sys/crypto/rijndael/rijndael-api-fst.h
+++ b/sys/crypto/rijndael/rijndael-api-fst.h
@@ -1,42 +1,12 @@
/* $FreeBSD$ */
-/* $NetBSD: rijndael-api-fst.h,v 1.5 2003/07/16 05:08:09 itojun Exp $ */
-/* $KAME: rijndael-api-fst.h,v 1.9 2003/07/16 05:09:38 itojun Exp $ */
+/* $KAME: rijndael-api-fst.h,v 1.6 2001/05/27 00:23:23 itojun Exp $ */
-/**
- * rijndael-api-fst.h
+/*
+ * rijndael-api-fst.h v2.3 April '2000
*
- * @version 2.9 (December 2000)
+ * Optimised ANSI C code
*
- * 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>
+ * #define INTERMEDIATE_VALUE_KAT to generate the Intermediate Value Known Answer Test.
*/
#ifndef __RIJNDAEL_API_FST_H
@@ -44,17 +14,18 @@
#include <crypto/rijndael/rijndael-alg-fst.h>
-/* Generic Defines */
+/* Defines:
+ Add any additional defines you need
+*/
+
#define DIR_ENCRYPT 0 /* Are we encrpyting? */
#define DIR_DECRYPT 1 /* Are we decrpyting? */
#define MODE_ECB 1 /* Are we ciphering in ECB mode? */
#define MODE_CBC 2 /* Are we ciphering in CBC mode? */
#define MODE_CFB1 3 /* Are we ciphering in 1-bit CFB mode? */
-#define TRUE 1
-#define FALSE 0
#define BITSPERBLOCK 128 /* Default number of bits in a cipher block */
-/* Error Codes */
+/* Error Codes - CHANGE POSSIBLE: inclusion of additional 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 */
#define BAD_KEY_INSTANCE -3 /* Key passed is not valid */
@@ -65,42 +36,67 @@
#define BAD_DATA -8 /* Data contents are invalid, e.g., invalid padding */
#define BAD_OTHER -9 /* Unknown error */
-/* 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 */
+/* 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 */
-/* Typedefs */
+/* Typedefs:
-typedef unsigned char BYTE;
+ Typedef'ed data storage elements. Add any algorithm specific
+parameters at the bottom of the structs as appropriate.
+*/
/* The structure for key information */
typedef struct {
- BYTE direction; /* Key used for encrypting or decrypting? */
+ u_int8_t 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 */
- u_int32_t rk[4*(RIJNDAEL_MAXNR + 1)]; /* key schedule */
- u_int32_t ek[4*(RIJNDAEL_MAXNR + 1)]; /* CFB1 key schedule (encryption only) */
+ 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 */
+ union {
+ u_int8_t xkS8[RIJNDAEL_MAXROUNDS+1][4][4]; /* key schedule */
+ u_int32_t xkS32[RIJNDAEL_MAXROUNDS+1][4]; /* key schedule */
+ } xKeySched;
+#define keySched xKeySched.xkS8
} keyInstance;
/* The structure for cipher information */
typedef struct { /* changed order of the components */
- BYTE mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
- BYTE IV[RIJNDAEL_MAX_IV_SIZE]; /* A possible Initialization Vector for ciphering */
+ u_int8_t mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
+ u_int8_t 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) */
} 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 rijndael_makeKey(keyInstance *key, u_int8_t direction, int keyLen, char *keyMaterial);
-int rijndael_makeKey(keyInstance *, BYTE, int, char *);
+int rijndael_cipherInit(cipherInstance *cipher, u_int8_t mode, char *IV);
-int rijndael_cipherInit(cipherInstance *, BYTE, char *);
+int rijndael_blockEncrypt(cipherInstance *cipher, keyInstance *key,
+ u_int8_t *input, int inputLen, u_int8_t *outBuffer);
-int rijndael_blockEncrypt(cipherInstance *, keyInstance *, BYTE *, int, BYTE *);
+int rijndael_padEncrypt(cipherInstance *cipher, keyInstance *key,
+ u_int8_t *input, int inputOctets, u_int8_t *outBuffer);
-int rijndael_padEncrypt(cipherInstance *, keyInstance *, BYTE *, int, BYTE *);
+int rijndael_blockDecrypt(cipherInstance *cipher, keyInstance *key,
+ u_int8_t *input, int inputLen, u_int8_t *outBuffer);
-int rijndael_blockDecrypt(cipherInstance *, keyInstance *, BYTE *, int, BYTE *);
+int rijndael_padDecrypt(cipherInstance *cipher, keyInstance *key,
+ u_int8_t *input, int inputOctets, u_int8_t *outBuffer);
-int rijndael_padDecrypt(cipherInstance *, keyInstance *, BYTE *, int, BYTE *);
+#ifdef INTERMEDIATE_VALUE_KAT
+int rijndael_cipherUpdateRounds(cipherInstance *cipher, keyInstance *key,
+ u_int8_t *input, int inputLen, u_int8_t *outBuffer, int Rounds);
+#endif /* INTERMEDIATE_VALUE_KAT */
-#endif /* __RIJNDAEL_API_FST_H */
+#endif /* __RIJNDAEL_API_FST_H */
OpenPOWER on IntegriCloud