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

Last change on this file since 298 was 230, checked in by katerina, 16 years ago

Fix gcc 4.4 compiler warnings. Release 2.5.5.

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