… | |
… | |
120 | DWORD cipherSig; /* set to VALID_SIG by cipherInit() */ |
120 | DWORD cipherSig; /* set to VALID_SIG by cipherInit() */ |
121 | DWORD iv32[BLOCK_SIZE/32]; /* CBC IV bytes arranged as dwords */ |
121 | DWORD iv32[BLOCK_SIZE/32]; /* CBC IV bytes arranged as dwords */ |
122 | } cipherInstance; |
122 | } cipherInstance; |
123 | |
123 | |
124 | /* Function protoypes */ |
124 | /* Function protoypes */ |
125 | int makeKey(keyInstance *key, BYTE direction, int keyLen, char *keyMaterial); |
125 | static int makeKey(keyInstance *key, BYTE direction, int keyLen, char *keyMaterial); |
126 | |
126 | |
127 | int cipherInit(cipherInstance *cipher, BYTE mode, char *IV); |
127 | static int cipherInit(cipherInstance *cipher, BYTE mode, char *IV); |
128 | |
128 | |
129 | int blockEncrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, |
129 | static int blockEncrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, |
130 | int inputLen, BYTE *outBuffer); |
130 | int inputLen, BYTE *outBuffer); |
131 | |
131 | |
132 | int blockDecrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, |
132 | static int blockDecrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, |
133 | int inputLen, BYTE *outBuffer); |
133 | int inputLen, BYTE *outBuffer); |
134 | |
134 | |
135 | int reKey(keyInstance *key); /* do key schedule using modified key.keyDwords */ |
135 | static int reKey(keyInstance *key); /* do key schedule using modified key.keyDwords */ |
136 | |
136 | |
137 | /* API to check table usage, for use in ECB_TBL KAT */ |
137 | /* API to check table usage, for use in ECB_TBL KAT */ |
138 | #define TAB_DISABLE 0 |
138 | #define TAB_DISABLE 0 |
139 | #define TAB_ENABLE 1 |
139 | #define TAB_ENABLE 1 |
140 | #define TAB_RESET 2 |
140 | #define TAB_RESET 2 |
141 | #define TAB_QUERY 3 |
141 | #define TAB_QUERY 3 |
142 | #define TAB_MIN_QUERY 50 |
142 | #define TAB_MIN_QUERY 50 |
143 | int TableOp(int op); |
143 | static int TableOp(int op); |
144 | |
144 | |
145 | |
145 | |
146 | #define CONST /* helpful C++ syntax sugar, NOP for ANSI C */ |
146 | #define CONST /* helpful C++ syntax sugar, NOP for ANSI C */ |
147 | |
147 | |
148 | #if BLOCK_SIZE == 128 /* optimize block copies */ |
148 | #if BLOCK_SIZE == 128 /* optimize block copies */ |
… | |
… | |
192 | #include <stdlib.h> |
192 | #include <stdlib.h> |
193 | #include <time.h> |
193 | #include <time.h> |
194 | #include <string.h> |
194 | #include <string.h> |
195 | |
195 | |
196 | #define MAX_BLK_CNT 4 /* max # blocks per call in TestTwofish */ |
196 | #define MAX_BLK_CNT 4 /* max # blocks per call in TestTwofish */ |
197 | int TestTwofish(int mode,int keySize) /* keySize must be 128, 192, or 256 */ |
197 | static int TestTwofish(int mode,int keySize) /* keySize must be 128, 192, or 256 */ |
198 | { /* return 0 iff test passes */ |
198 | { /* return 0 iff test passes */ |
199 | keyInstance ki; /* key information, including tables */ |
199 | keyInstance ki; /* key information, including tables */ |
200 | cipherInstance ci; /* keeps mode (ECB, CBC) and IV */ |
200 | cipherInstance ci; /* keeps mode (ECB, CBC) and IV */ |
201 | BYTE plainText[MAX_BLK_CNT*(BLOCK_SIZE/8)]; |
201 | BYTE plainText[MAX_BLK_CNT*(BLOCK_SIZE/8)]; |
202 | BYTE cipherText[MAX_BLK_CNT*(BLOCK_SIZE/8)]; |
202 | BYTE cipherText[MAX_BLK_CNT*(BLOCK_SIZE/8)]; |