1/*
2 * $Id: rijndael-api-fst.h,v 12.0 2004/11/17 03:43:17 bostic Exp $
3 */
4/**
5 * rijndael-api-fst.h
6 *
7 * @version 2.9 (December 2000)
8 *
9 * Optimised ANSI C code for the Rijndael cipher (now AES)
10 *
11 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
12 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
13 * @author Paulo Barreto <paulo.barreto@terra.com.br>
14 *
15 * This code is hereby placed in the public domain.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Acknowledgements:
30 *
31 * We are deeply indebted to the following people for their bug reports,
32 * fixes, and improvement suggestions to this implementation. Though we
33 * tried to list all contributions, we apologise in advance for any
34 * missing reference.
35 *
36 * Andrew Bales <Andrew.Bales@Honeywell.com>
37 * Markus Friedl <markus.friedl@informatik.uni-erlangen.de>
38 * John Skodon <skodonj@webquill.com>
39 */
40
41#ifndef __RIJNDAEL_API_FST_H
42#define __RIJNDAEL_API_FST_H
43
44#include "crypto/rijndael/rijndael-alg-fst.h"
45
46/*  Generic Defines  */
47#define     DIR_ENCRYPT           0 /*  Are we encrpyting?  */
48#define     DIR_DECRYPT           1 /*  Are we decrpyting?  */
49#define     MODE_ECB              1 /*  Are we ciphering in ECB mode?   */
50#define     MODE_CBC              2 /*  Are we ciphering in CBC mode?   */
51#define     MODE_CFB1             3 /*  Are we ciphering in 1-bit CFB mode? */
52#undef	    TRUE
53#define     TRUE                  1
54#undef	    FALSE
55#define     FALSE                 0
56#define     BITSPERBLOCK        128 /* Default number of bits in a cipher block */
57
58/*  Error Codes  */
59#define     BAD_KEY_DIR          -1 /*  Key direction is invalid, e.g., unknown value */
60#define     BAD_KEY_MAT          -2 /*  Key material not of correct length */
61#define     BAD_KEY_INSTANCE     -3 /*  Key passed is not valid */
62#define     BAD_CIPHER_MODE      -4 /*  Params struct passed to cipherInit invalid */
63#define     BAD_CIPHER_STATE     -5 /*  Cipher in wrong state (e.g., not initialized) */
64#define     BAD_BLOCK_LENGTH     -6
65#define     BAD_CIPHER_INSTANCE  -7
66#define     BAD_DATA             -8 /*  Data contents are invalid, e.g., invalid padding */
67#define     BAD_OTHER            -9 /*  Unknown error */
68
69/*  Algorithm-specific Defines  */
70#define     MAX_KEY_SIZE         64 /* # of ASCII char's needed to represent a key */
71#define     MAX_IV_SIZE          16 /* # bytes needed to represent an IV  */
72
73/*  Typedefs  */
74
75/*  The structure for key information */
76typedef struct {
77    u_int8_t  direction;            /* Key used for encrypting or decrypting? */
78    int   keyLen;                   /* Length of the key  */
79    char  keyMaterial[MAX_KEY_SIZE+1];  /* Raw key data in ASCII, e.g., user input or KAT values */
80	int   Nr;                       /* key-length-dependent number of rounds */
81	u32   rk[4*(MAXNR + 1)];        /* key schedule */
82	u32   ek[4*(MAXNR + 1)];        /* CFB1 key schedule (encryption only) */
83} keyInstance;
84
85/*  The structure for cipher information */
86typedef struct {                    /* changed order of the components */
87    u_int8_t  mode;                 /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
88    u_int8_t  IV[MAX_IV_SIZE];      /* A possible Initialization Vector for ciphering */
89} cipherInstance;
90
91#endif /* __RIJNDAEL_API_FST_H */
92