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 | #define TRUE 1
|
---|
28 | #define FALSE 0
|
---|
29 | #define BITSPERBLOCK 128 /* Default number of bits in a cipher block */
|
---|
30 |
|
---|
31 | /* Error Codes - CHANGE POSSIBLE: inclusion of additional error codes */
|
---|
32 |
|
---|
33 | #define BAD_KEY_DIR -1 /* Key direction is invalid, e.g., unknown value */
|
---|
34 | #define BAD_KEY_MAT -2 /* Key material not of correct length */
|
---|
35 | #define BAD_KEY_INSTANCE -3 /* Key passed is not valid */
|
---|
36 | #define BAD_CIPHER_MODE -4 /* Params struct passed to cipherInit invalid */
|
---|
37 | #define BAD_CIPHER_STATE -5 /* Cipher in wrong state (e.g., not initialized) */
|
---|
38 | #define BAD_BLOCK_LENGTH -6
|
---|
39 | #define BAD_CIPHER_INSTANCE -7
|
---|
40 | #define BAD_DATA -8 /* Data contents are invalid, e.g., invalid padding */
|
---|
41 | #define BAD_OTHER -9 /* Unknown error */
|
---|
42 |
|
---|
43 | /* CHANGE POSSIBLE: inclusion of algorithm specific defines */
|
---|
44 | #define MAX_KEY_SIZE 64 /* # of ASCII char's needed to represent a key */
|
---|
45 | #define MAX_IV_SIZE 16 /* # bytes needed to represent an IV */
|
---|
46 |
|
---|
47 | #ifdef SH_ENCRYPT
|
---|
48 |
|
---|
49 | /* Typedefs:
|
---|
50 |
|
---|
51 | Typedef'ed data storage elements. Add any algorithm specific
|
---|
52 | parameters at the bottom of the structs as appropriate.
|
---|
53 | */
|
---|
54 |
|
---|
55 | typedef unsigned char RIJ_BYTE;
|
---|
56 |
|
---|
57 | /* The structure for key information */
|
---|
58 | typedef struct {
|
---|
59 | RIJ_BYTE direction; /* Key used for encrypting or decrypting? */
|
---|
60 | int keyLen; /* Length of the key */
|
---|
61 | char keyMaterial[MAX_KEY_SIZE+1]; /* Raw key data in ASCII, e.g., user input or KAT values */
|
---|
62 | /* The following parameters are algorithm dependent, replace or add as necessary */
|
---|
63 | int ROUNDS; /* key-length-dependent number of rounds */
|
---|
64 | int blockLen; /* block length */
|
---|
65 | word8 keySched[MAXROUNDS+1][4][4]; /* key schedule */
|
---|
66 | } keyInstance;
|
---|
67 |
|
---|
68 | /* The structure for cipher information */
|
---|
69 | typedef struct { /* changed order of the components */
|
---|
70 | RIJ_BYTE mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
|
---|
71 | RIJ_BYTE IV[MAX_IV_SIZE]; /* A possible Initialization Vector for ciphering */
|
---|
72 | /* Add any algorithm specific parameters needed here */
|
---|
73 | int blockLen; /* Sample: Handles non-128 bit block sizes (if available) */
|
---|
74 | } cipherInstance;
|
---|
75 |
|
---|
76 | /* Function prototypes */
|
---|
77 | /* CHANGED: nothing
|
---|
78 | TODO: implement the following extensions to setup 192-bit and 256-bit block lengths:
|
---|
79 | makeKeyEx(): parameter blockLen added
|
---|
80 | -- this parameter is absolutely necessary if you want to
|
---|
81 | setup the round keys in a variable block length setting
|
---|
82 | cipherInitEx(): parameter blockLen added (for obvious reasons)
|
---|
83 | */
|
---|
84 |
|
---|
85 | int makeKey(keyInstance *key, RIJ_BYTE direction, int keyLen, char *keyMaterial);
|
---|
86 |
|
---|
87 | int cipherInit(cipherInstance *cipher, RIJ_BYTE mode, char *IV);
|
---|
88 |
|
---|
89 | int blockEncrypt(cipherInstance *cipher, keyInstance *key,
|
---|
90 | RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer);
|
---|
91 |
|
---|
92 | int blockDecrypt(cipherInstance *cipher, keyInstance *key,
|
---|
93 | RIJ_BYTE *input, int inputLen, RIJ_BYTE *outBuffer);
|
---|
94 |
|
---|
95 | /* SH_ENCRYPT */
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | /* __RIJNDAEL_API_FST_H */
|
---|
99 | #endif
|
---|