source: trunk/include/rijndael-api-fst.h@ 557

Last change on this file since 557 was 481, checked in by katerina, 9 years ago

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File size: 4.9 KB
Line 
1/* $NetBSD: rijndael-api-fst.h,v 1.8 2007/01/21 23:00:08 cbiere Exp $ */
2
3/**
4 * rijndael-api-fst.h
5 *
6 * @version 2.9 (December 2000)
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>
38 */
39
40#ifndef __RIJNDAEL_API_FST_H
41#define __RIJNDAEL_API_FST_H
42
43/* Blocksize: 16 * 8 = 128; 128 * 1 = 128 */
44#define B_SIZ 16
45#define BNUM 1
46
47
48#if defined(UINT32)
49typedef unsigned char u8;
50typedef UINT32 u32;
51#else
52
53typedef unsigned char u8;
54#if defined(HAVE_INT_32)
55typedef unsigned int u32;
56#elif defined(HAVE_LONG_32)
57typedef unsigned long u32;
58#elif defined(HAVE_SHORT_32)
59typedef unsigned short u32;
60#else
61#error "No 32 bit integer type found"
62#endif
63
64#endif
65
66#include "rijndael-alg-fst.h"
67
68/* Generic Defines */
69#define DIR_ENCRYPT 0 /* Are we encrpyting? */
70#define DIR_DECRYPT 1 /* Are we decrpyting? */
71#define MODE_ECB 1 /* Are we ciphering in ECB mode? */
72#define MODE_CBC 2 /* Are we ciphering in CBC mode? */
73#define MODE_CFB1 3 /* Are we ciphering in 1-bit CFB mode? */
74#ifndef TRUE
75#define TRUE 1
76#endif
77#ifndef FALSE
78#define FALSE 0
79#endif
80#define BITSPERBLOCK 128 /* Default number of bits in a cipher block */
81
82/* Error Codes */
83#define BAD_KEY_DIR -1 /* Key direction is invalid, e.g., unknown value */
84#define BAD_KEY_MAT -2 /* Key material not of correct length */
85#define BAD_KEY_INSTANCE -3 /* Key passed is not valid */
86#define BAD_CIPHER_MODE -4 /* Params struct passed to cipherInit invalid */
87#define BAD_CIPHER_STATE -5 /* Cipher in wrong state (e.g., not initialized) */
88#define BAD_BLOCK_LENGTH -6
89#define BAD_CIPHER_INSTANCE -7
90#define BAD_DATA -8 /* Data contents are invalid, e.g., invalid padding */
91#define BAD_OTHER -9 /* Unknown error */
92
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 */
96
97#ifdef SH_ENCRYPT
98
99/* Typedefs */
100
101typedef unsigned char BYTE;
102
103/* The structure for key information */
104typedef struct {
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 */
111} keyInstance;
112
113/* The structure for cipher information */
114typedef struct { /* changed order of the components */
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 */
118} cipherInstance;
119
120/* Function prototypes */
121
122int rijndael_makeKey(keyInstance *, BYTE, int, const char *);
123
124int rijndael_cipherInit(cipherInstance *, BYTE, const char *);
125
126int rijndael_blockEncrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
127
128int rijndael_padEncrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
129
130int rijndael_blockDecrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
131
132int rijndael_padDecrypt(cipherInstance *, keyInstance *, const BYTE *, int, BYTE *);
133
134/* SH_ENCRYPT */
135#endif
136#endif /* __RIJNDAEL_API_FST_H */
Note: See TracBrowser for help on using the repository browser.