Mercurial > dropbear
comparison libtomcrypt/src/ciphers/skipjack.c @ 415:8b9aba1d5fa4 channel-fix
merge of '73fe066c5d9e2395354ba74756124d45c978a04d'
and 'f5014cc84558f1e8eba42dbecf9f72f94bfe6134'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 06 Feb 2007 16:00:18 +0000 |
parents | 0cbe8f6dbf9e |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
414:c53a26c430e5 | 415:8b9aba1d5fa4 |
---|---|
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | 8 * |
9 * Tom St Denis, [email protected], http://libtomcrypt.org | 9 * Tom St Denis, [email protected], http://libtomcrypt.com |
10 */ | 10 */ |
11 | 11 |
12 /** | 12 /** |
13 @file skipjack.c | 13 @file skipjack.c |
14 Skipjack Implementation by Tom St Denis | 14 Skipjack Implementation by Tom St Denis |
26 &skipjack_ecb_encrypt, | 26 &skipjack_ecb_encrypt, |
27 &skipjack_ecb_decrypt, | 27 &skipjack_ecb_decrypt, |
28 &skipjack_test, | 28 &skipjack_test, |
29 &skipjack_done, | 29 &skipjack_done, |
30 &skipjack_keysize, | 30 &skipjack_keysize, |
31 NULL, NULL, NULL, NULL, NULL, NULL, NULL | 31 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL |
32 }; | 32 }; |
33 | 33 |
34 static const unsigned char sbox[256] = { | 34 static const unsigned char sbox[256] = { |
35 0xa3,0xd7,0x09,0x83,0xf8,0x48,0xf6,0xf4,0xb3,0x21,0x15,0x78,0x99,0xb1,0xaf,0xf9, | 35 0xa3,0xd7,0x09,0x83,0xf8,0x48,0xf6,0xf4,0xb3,0x21,0x15,0x78,0x99,0xb1,0xaf,0xf9, |
36 0xe7,0x2d,0x4d,0x8a,0xce,0x4c,0xca,0x2e,0x52,0x95,0xd9,0x1e,0x4e,0x38,0x44,0x28, | 36 0xe7,0x2d,0x4d,0x8a,0xce,0x4c,0xca,0x2e,0x52,0x95,0xd9,0x1e,0x4e,0x38,0x44,0x28, |
136 /** | 136 /** |
137 Encrypts a block of text with Skipjack | 137 Encrypts a block of text with Skipjack |
138 @param pt The input plaintext (8 bytes) | 138 @param pt The input plaintext (8 bytes) |
139 @param ct The output ciphertext (8 bytes) | 139 @param ct The output ciphertext (8 bytes) |
140 @param skey The key as scheduled | 140 @param skey The key as scheduled |
141 @return CRYPT_OK if successful | |
141 */ | 142 */ |
142 #ifdef LTC_CLEAN_STACK | 143 #ifdef LTC_CLEAN_STACK |
143 static void _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) | 144 static int _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) |
144 #else | 145 #else |
145 void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) | 146 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) |
146 #endif | 147 #endif |
147 { | 148 { |
148 unsigned w1,w2,w3,w4,tmp,tmp1; | 149 unsigned w1,w2,w3,w4,tmp,tmp1; |
149 int x, kp; | 150 int x, kp; |
150 | 151 |
181 /* store block */ | 182 /* store block */ |
182 ct[0] = (w1>>8)&255; ct[1] = w1&255; | 183 ct[0] = (w1>>8)&255; ct[1] = w1&255; |
183 ct[2] = (w2>>8)&255; ct[3] = w2&255; | 184 ct[2] = (w2>>8)&255; ct[3] = w2&255; |
184 ct[4] = (w3>>8)&255; ct[5] = w3&255; | 185 ct[4] = (w3>>8)&255; ct[5] = w3&255; |
185 ct[6] = (w4>>8)&255; ct[7] = w4&255; | 186 ct[6] = (w4>>8)&255; ct[7] = w4&255; |
187 | |
188 return CRYPT_OK; | |
186 } | 189 } |
187 | 190 |
188 #ifdef LTC_CLEAN_STACK | 191 #ifdef LTC_CLEAN_STACK |
189 void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) | 192 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) |
190 { | 193 { |
191 _skipjack_ecb_encrypt(pt, ct, skey); | 194 int err = _skipjack_ecb_encrypt(pt, ct, skey); |
192 burn_stack(sizeof(unsigned) * 8 + sizeof(int) * 2); | 195 burn_stack(sizeof(unsigned) * 8 + sizeof(int) * 2); |
196 return err; | |
193 } | 197 } |
194 #endif | 198 #endif |
195 | 199 |
196 /** | 200 /** |
197 Decrypts a block of text with Skipjack | 201 Decrypts a block of text with Skipjack |
198 @param ct The input ciphertext (8 bytes) | 202 @param ct The input ciphertext (8 bytes) |
199 @param pt The output plaintext (8 bytes) | 203 @param pt The output plaintext (8 bytes) |
200 @param skey The key as scheduled | 204 @param skey The key as scheduled |
205 @return CRYPT_OK if successful | |
201 */ | 206 */ |
202 #ifdef LTC_CLEAN_STACK | 207 #ifdef LTC_CLEAN_STACK |
203 static void _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) | 208 static int _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) |
204 #else | 209 #else |
205 void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) | 210 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) |
206 #endif | 211 #endif |
207 { | 212 { |
208 unsigned w1,w2,w3,w4,tmp; | 213 unsigned w1,w2,w3,w4,tmp; |
209 int x, kp; | 214 int x, kp; |
210 | 215 |
245 /* store block */ | 250 /* store block */ |
246 pt[0] = (w1>>8)&255; pt[1] = w1&255; | 251 pt[0] = (w1>>8)&255; pt[1] = w1&255; |
247 pt[2] = (w2>>8)&255; pt[3] = w2&255; | 252 pt[2] = (w2>>8)&255; pt[3] = w2&255; |
248 pt[4] = (w3>>8)&255; pt[5] = w3&255; | 253 pt[4] = (w3>>8)&255; pt[5] = w3&255; |
249 pt[6] = (w4>>8)&255; pt[7] = w4&255; | 254 pt[6] = (w4>>8)&255; pt[7] = w4&255; |
255 | |
256 return CRYPT_OK; | |
250 } | 257 } |
251 | 258 |
252 #ifdef LTC_CLEAN_STACK | 259 #ifdef LTC_CLEAN_STACK |
253 void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) | 260 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) |
254 { | 261 { |
255 _skipjack_ecb_decrypt(ct, pt, skey); | 262 int err = _skipjack_ecb_decrypt(ct, pt, skey); |
256 burn_stack(sizeof(unsigned) * 7 + sizeof(int) * 2); | 263 burn_stack(sizeof(unsigned) * 7 + sizeof(int) * 2); |
264 return err; | |
257 } | 265 } |
258 #endif | 266 #endif |
259 | 267 |
260 /** | 268 /** |
261 Performs a self-test of the Skipjack block cipher | 269 Performs a self-test of the Skipjack block cipher |
288 /* encrypt and decrypt */ | 296 /* encrypt and decrypt */ |
289 skipjack_ecb_encrypt(tests[x].pt, buf[0], &key); | 297 skipjack_ecb_encrypt(tests[x].pt, buf[0], &key); |
290 skipjack_ecb_decrypt(buf[0], buf[1], &key); | 298 skipjack_ecb_decrypt(buf[0], buf[1], &key); |
291 | 299 |
292 /* compare */ | 300 /* compare */ |
293 if (memcmp(buf[0], tests[x].ct, 8) != 0 || memcmp(buf[1], tests[x].pt, 8) != 0) { | 301 if (XMEMCMP(buf[0], tests[x].ct, 8) != 0 || XMEMCMP(buf[1], tests[x].pt, 8) != 0) { |
294 return CRYPT_FAIL_TESTVECTOR; | 302 return CRYPT_FAIL_TESTVECTOR; |
295 } | 303 } |
296 | 304 |
297 /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ | 305 /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ |
298 for (y = 0; y < 8; y++) buf[0][y] = 0; | 306 for (y = 0; y < 8; y++) buf[0][y] = 0; |
329 } | 337 } |
330 | 338 |
331 #endif | 339 #endif |
332 | 340 |
333 /* $Source: /cvs/libtom/libtomcrypt/src/ciphers/skipjack.c,v $ */ | 341 /* $Source: /cvs/libtom/libtomcrypt/src/ciphers/skipjack.c,v $ */ |
334 /* $Revision: 1.7 $ */ | 342 /* $Revision: 1.12 $ */ |
335 /* $Date: 2005/05/05 14:35:58 $ */ | 343 /* $Date: 2006/11/08 23:01:06 $ */ |