Add phnxdeco with debian patch set (version 0.33-3).
[delutions.git] / tc / python / serpent.py
blob422d21f02da44bfdc1864c0a5978cb9bd7007346
1 ## serpent.py - pure Python implementation of the Serpent algorithm.
2 ## Bjorn Edstrom <be@bjrn.se> 13 december 2007.
3 ##
4 ## Copyrights
5 ## ==========
6 ##
7 ## This code is a derived from an implementation by Dr Brian Gladman
8 ## (gladman@seven77.demon.co.uk) which is subject to the following license.
9 ## This Python implementation is not subject to any other license.
11 ##/* This is an independent implementation of the encryption algorithm:
12 ## *
13 ## * Serpent by Ross Anderson, Eli Biham and Lars Knudsen
14 ## *
15 ## * which is a candidate algorithm in the Advanced Encryption Standard
16 ## * programme of the US National Institute of Standards and Technology
17 ## *
18 ## * Copyright in this implementation is held by Dr B R Gladman but I
19 ## * hereby give permission for its free direct or derivative use subject
20 ## * to acknowledgment of its origin and compliance with any conditions
21 ## * that the originators of the algorithm place on its exploitation.
22 ## *
23 ## * Dr Brian Gladman (gladman@seven77.demon.co.uk) 14th January 1999
24 ## */
26 ## The above copyright notice must not be removed.
28 ## Information
29 ## ===========
31 ## Anyone thinking of using this code should reconsider. It's slow.
32 ## Try python-mcrypt instead. In case a faster library is not installed
33 ## on the target system, this code can be used as a portable fallback.
35 try:
36 import psyco
37 psyco.full()
38 except ImportError:
39 pass
41 block_size = 16
42 key_size = 32
44 class Serpent:
46 def __init__(self, key=None):
47 """Serpent."""
49 if key:
50 self.set_key(key)
53 def set_key(self, key):
54 """Init."""
56 key_len = len(key)
57 if key_len % 4:
58 # XXX: add padding?
59 raise KeyError, "key not a multiple of 4"
60 if key_len > 32:
61 # XXX: prune?
62 raise KeyError, "key_len > 32"
64 self.key_context = [0] * 140
66 key_word32 = [0] * 32
67 i = 0
68 while key:
69 key_word32[i] = struct.unpack("<L", key[0:4])[0]
70 key = key[4:]
71 i += 1
73 set_key(self.key_context, key_word32, key_len)
76 def decrypt(self, block):
77 """Decrypt blocks."""
79 if len(block) % 16:
80 raise ValueError, "block size must be a multiple of 16"
82 plaintext = ''
84 while block:
85 a, b, c, d = struct.unpack("<4L", block[:16])
86 temp = [a, b, c, d]
87 decrypt(self.key_context, temp)
88 plaintext += struct.pack("<4L", *temp)
89 block = block[16:]
91 return plaintext
94 def encrypt(self, block):
95 """Encrypt blocks."""
97 if len(block) % 16:
98 raise ValueError, "block size must be a multiple of 16"
100 ciphertext = ''
102 while block:
103 a, b, c, d = struct.unpack("<4L", block[0:16])
104 temp = [a, b, c, d]
105 encrypt(self.key_context, temp)
106 ciphertext += struct.pack("<4L", *temp)
107 block = block[16:]
109 return ciphertext
112 def get_name(self):
113 """Return the name of the cipher."""
115 return "Serpent"
118 def get_block_size(self):
119 """Get cipher block size in bytes."""
121 return 16
124 def get_key_size(self):
125 """Get cipher key size in bytes."""
127 return 32
131 # Private.
134 import struct
135 import sys
137 WORD_BIGENDIAN = 0
138 if sys.byteorder == 'big':
139 WORD_BIGENDIAN = 1
141 def rotr32(x, n):
142 return (x >> n) | ((x << (32 - n)) & 0xFFFFFFFF)
144 def rotl32(x, n):
145 return ((x << n) & 0xFFFFFFFF) | (x >> (32 - n))
147 def byteswap32(x):
148 return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | \
149 (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff)
151 def set_key(l_key, key, key_len):
152 key_len *= 8
153 if key_len > 256:
154 return False
156 i = 0
157 lk = (key_len + 31) / 32
158 while i < lk:
159 l_key[i] = key[i]
160 if WORD_BIGENDIAN:
161 l_key[i] = byteswap32(key[i])
162 i += 1
164 if key_len < 256:
165 while i < 8:
166 l_key[i] = 0
167 i += 1
168 i = key_len / 32
169 lk = 1 << (key_len % 32)
170 l_key[i] = (l_key[i] & (lk - 1)) | lk
171 for i in xrange(132):
172 lk = l_key[i] ^ l_key[i + 3] ^ l_key[i + 5] ^ l_key[i + 7] ^ 0x9e3779b9 ^ i
173 l_key[i + 8] = ((lk << 11) & 0xFFFFFFFF) | (lk >> 21)
175 key = l_key
176 # serpent_generate.py
177 a = key[4 * 0 + 8]
178 b = key[4 * 0 + 9]
179 c = key[4 * 0 + 10]
180 d = key[4 * 0 + 11]
181 e = 0
182 f = 0
183 g = 0
184 h = 0
185 t1 = 0
186 t2 = 0
187 t3 = 0
188 t4 = 0
189 t5 = 0
190 t6 = 0
191 t7 = 0
192 t8 = 0
193 t9 = 0
194 t10 = 0
195 t11 = 0
196 t12 = 0
197 t13 = 0
198 t14 = 0
199 t15 = 0
200 t16 = 0
201 t1 = a ^ c;
202 t2 = d ^ t1;
203 t3 = a & t2;
204 t4 = d ^ t3;
205 t5 = b & t4;
206 g = t2 ^ t5;
207 t7 = a | g;
208 t8 = b | d;
209 t11 = a | d;
210 t9 = t4 & t7;
211 f = t8 ^ t9;
212 t12 = b ^ t11;
213 t13 = g ^ t9;
214 t15 = t3 ^ t8;
215 h = t12 ^ t13;
216 t16 = c & t15;
217 e = t12 ^ t16
218 key[4 * 0 + 8] = e
219 key[4 * 0 + 9] = f
220 key[4 * 0 + 10] = g
221 key[4 * 0 + 11] = h
222 a = key[4 * 1 + 8]
223 b = key[4 * 1 + 9]
224 c = key[4 * 1 + 10]
225 d = key[4 * 1 + 11]
226 t1 = (~a) % 0x100000000;
227 t2 = b ^ d;
228 t3 = c & t1;
229 t13 = d | t1;
230 e = t2 ^ t3;
231 t5 = c ^ t1;
232 t6 = c ^ e;
233 t7 = b & t6;
234 t10 = e | t5;
235 h = t5 ^ t7;
236 t9 = d | t7;
237 t11 = t9 & t10;
238 t14 = t2 ^ h;
239 g = a ^ t11;
240 t15 = g ^ t13;
241 f = t14 ^ t15
242 key[4 * 1 + 8] = e
243 key[4 * 1 + 9] = f
244 key[4 * 1 + 10] = g
245 key[4 * 1 + 11] = h
246 a = key[4 * 2 + 8]
247 b = key[4 * 2 + 9]
248 c = key[4 * 2 + 10]
249 d = key[4 * 2 + 11]
250 t1 = (~a) % 0x100000000;
251 t2 = b ^ t1;
252 t3 = a | t2;
253 t4 = d | t2;
254 t5 = c ^ t3;
255 g = d ^ t5;
256 t7 = b ^ t4;
257 t8 = t2 ^ g;
258 t9 = t5 & t7;
259 h = t8 ^ t9;
260 t11 = t5 ^ t7;
261 f = h ^ t11;
262 t13 = t8 & t11;
263 e = t5 ^ t13
264 key[4 * 2 + 8] = e
265 key[4 * 2 + 9] = f
266 key[4 * 2 + 10] = g
267 key[4 * 2 + 11] = h
268 a = key[4 * 3 + 8]
269 b = key[4 * 3 + 9]
270 c = key[4 * 3 + 10]
271 d = key[4 * 3 + 11]
272 t1 = a ^ d;
273 t2 = a & d;
274 t3 = c ^ t1;
275 t6 = b & t1;
276 t4 = b ^ t3;
277 t10 = (~t3) % 0x100000000;
278 h = t2 ^ t4;
279 t7 = a ^ t6;
280 t14 = (~t7) % 0x100000000;
281 t8 = c | t7;
282 t11 = t3 ^ t7;
283 g = t4 ^ t8;
284 t12 = h & t11;
285 f = t10 ^ t12;
286 e = t12 ^ t14
287 key[4 * 3 + 8] = e
288 key[4 * 3 + 9] = f
289 key[4 * 3 + 10] = g
290 key[4 * 3 + 11] = h
291 a = key[4 * 4 + 8]
292 b = key[4 * 4 + 9]
293 c = key[4 * 4 + 10]
294 d = key[4 * 4 + 11]
295 t1 = (~c) % 0x100000000;
296 t2 = b ^ c;
297 t3 = b | t1;
298 t4 = d ^ t3;
299 t5 = a & t4;
300 t7 = a ^ d;
301 h = t2 ^ t5;
302 t8 = b ^ t5;
303 t9 = t2 | t8;
304 t11 = d & t3;
305 f = t7 ^ t9;
306 t12 = t5 ^ f;
307 t15 = t1 | t4;
308 t13 = h & t12;
309 g = t11 ^ t13;
310 t16 = t12 ^ g;
311 e = t15 ^ t16
312 key[4 * 4 + 8] = e
313 key[4 * 4 + 9] = f
314 key[4 * 4 + 10] = g
315 key[4 * 4 + 11] = h
316 a = key[4 * 5 + 8]
317 b = key[4 * 5 + 9]
318 c = key[4 * 5 + 10]
319 d = key[4 * 5 + 11]
320 t1 = (~a) % 0x100000000;
321 t2 = a ^ d;
322 t3 = b ^ t2;
323 t4 = t1 | t2;
324 t5 = c ^ t4;
325 f = b ^ t5;
326 t13 = (~t5) % 0x100000000;
327 t7 = t2 | f;
328 t8 = d ^ t7;
329 t9 = t5 & t8;
330 g = t3 ^ t9;
331 t11 = t5 ^ t8;
332 e = g ^ t11;
333 t14 = t3 & t11;
334 h = t13 ^ t14
335 key[4 * 5 + 8] = e
336 key[4 * 5 + 9] = f
337 key[4 * 5 + 10] = g
338 key[4 * 5 + 11] = h
339 a = key[4 * 6 + 8]
340 b = key[4 * 6 + 9]
341 c = key[4 * 6 + 10]
342 d = key[4 * 6 + 11]
343 t1 = (~a) % 0x100000000;
344 t2 = a ^ b;
345 t3 = a ^ d;
346 t4 = c ^ t1;
347 t5 = t2 | t3;
348 e = t4 ^ t5;
349 t7 = d & e;
350 t8 = t2 ^ e;
351 t10 = t1 | e;
352 f = t7 ^ t8;
353 t11 = t2 | t7;
354 t12 = t3 ^ t10;
355 t14 = b ^ t7;
356 g = t11 ^ t12;
357 t15 = f & t12;
358 h = t14 ^ t15
359 key[4 * 6 + 8] = e
360 key[4 * 6 + 9] = f
361 key[4 * 6 + 10] = g
362 key[4 * 6 + 11] = h
363 a = key[4 * 7 + 8]
364 b = key[4 * 7 + 9]
365 c = key[4 * 7 + 10]
366 d = key[4 * 7 + 11]
367 t1 = a ^ d;
368 t2 = d & t1;
369 t3 = c ^ t2;
370 t4 = b | t3;
371 h = t1 ^ t4;
372 t6 = (~b) % 0x100000000;
373 t7 = t1 | t6;
374 e = t3 ^ t7;
375 t9 = a & e;
376 t10 = t1 ^ t6;
377 t11 = t4 & t10;
378 g = t9 ^ t11;
379 t13 = a ^ t3;
380 t14 = t10 & g;
381 f = t13 ^ t14
382 key[4 * 7 + 8] = e
383 key[4 * 7 + 9] = f
384 key[4 * 7 + 10] = g
385 key[4 * 7 + 11] = h
386 a = key[4 * 8 + 8]
387 b = key[4 * 8 + 9]
388 c = key[4 * 8 + 10]
389 d = key[4 * 8 + 11]
390 t1 = a ^ c;
391 t2 = d ^ t1;
392 t3 = a & t2;
393 t4 = d ^ t3;
394 t5 = b & t4;
395 g = t2 ^ t5;
396 t7 = a | g;
397 t8 = b | d;
398 t11 = a | d;
399 t9 = t4 & t7;
400 f = t8 ^ t9;
401 t12 = b ^ t11;
402 t13 = g ^ t9;
403 t15 = t3 ^ t8;
404 h = t12 ^ t13;
405 t16 = c & t15;
406 e = t12 ^ t16
407 key[4 * 8 + 8] = e
408 key[4 * 8 + 9] = f
409 key[4 * 8 + 10] = g
410 key[4 * 8 + 11] = h
411 a = key[4 * 9 + 8]
412 b = key[4 * 9 + 9]
413 c = key[4 * 9 + 10]
414 d = key[4 * 9 + 11]
415 t1 = (~a) % 0x100000000;
416 t2 = b ^ d;
417 t3 = c & t1;
418 t13 = d | t1;
419 e = t2 ^ t3;
420 t5 = c ^ t1;
421 t6 = c ^ e;
422 t7 = b & t6;
423 t10 = e | t5;
424 h = t5 ^ t7;
425 t9 = d | t7;
426 t11 = t9 & t10;
427 t14 = t2 ^ h;
428 g = a ^ t11;
429 t15 = g ^ t13;
430 f = t14 ^ t15
431 key[4 * 9 + 8] = e
432 key[4 * 9 + 9] = f
433 key[4 * 9 + 10] = g
434 key[4 * 9 + 11] = h
435 a = key[4 * 10 + 8]
436 b = key[4 * 10 + 9]
437 c = key[4 * 10 + 10]
438 d = key[4 * 10 + 11]
439 t1 = (~a) % 0x100000000;
440 t2 = b ^ t1;
441 t3 = a | t2;
442 t4 = d | t2;
443 t5 = c ^ t3;
444 g = d ^ t5;
445 t7 = b ^ t4;
446 t8 = t2 ^ g;
447 t9 = t5 & t7;
448 h = t8 ^ t9;
449 t11 = t5 ^ t7;
450 f = h ^ t11;
451 t13 = t8 & t11;
452 e = t5 ^ t13
453 key[4 * 10 + 8] = e
454 key[4 * 10 + 9] = f
455 key[4 * 10 + 10] = g
456 key[4 * 10 + 11] = h
457 a = key[4 * 11 + 8]
458 b = key[4 * 11 + 9]
459 c = key[4 * 11 + 10]
460 d = key[4 * 11 + 11]
461 t1 = a ^ d;
462 t2 = a & d;
463 t3 = c ^ t1;
464 t6 = b & t1;
465 t4 = b ^ t3;
466 t10 = (~t3) % 0x100000000;
467 h = t2 ^ t4;
468 t7 = a ^ t6;
469 t14 = (~t7) % 0x100000000;
470 t8 = c | t7;
471 t11 = t3 ^ t7;
472 g = t4 ^ t8;
473 t12 = h & t11;
474 f = t10 ^ t12;
475 e = t12 ^ t14
476 key[4 * 11 + 8] = e
477 key[4 * 11 + 9] = f
478 key[4 * 11 + 10] = g
479 key[4 * 11 + 11] = h
480 a = key[4 * 12 + 8]
481 b = key[4 * 12 + 9]
482 c = key[4 * 12 + 10]
483 d = key[4 * 12 + 11]
484 t1 = (~c) % 0x100000000;
485 t2 = b ^ c;
486 t3 = b | t1;
487 t4 = d ^ t3;
488 t5 = a & t4;
489 t7 = a ^ d;
490 h = t2 ^ t5;
491 t8 = b ^ t5;
492 t9 = t2 | t8;
493 t11 = d & t3;
494 f = t7 ^ t9;
495 t12 = t5 ^ f;
496 t15 = t1 | t4;
497 t13 = h & t12;
498 g = t11 ^ t13;
499 t16 = t12 ^ g;
500 e = t15 ^ t16
501 key[4 * 12 + 8] = e
502 key[4 * 12 + 9] = f
503 key[4 * 12 + 10] = g
504 key[4 * 12 + 11] = h
505 a = key[4 * 13 + 8]
506 b = key[4 * 13 + 9]
507 c = key[4 * 13 + 10]
508 d = key[4 * 13 + 11]
509 t1 = (~a) % 0x100000000;
510 t2 = a ^ d;
511 t3 = b ^ t2;
512 t4 = t1 | t2;
513 t5 = c ^ t4;
514 f = b ^ t5;
515 t13 = (~t5) % 0x100000000;
516 t7 = t2 | f;
517 t8 = d ^ t7;
518 t9 = t5 & t8;
519 g = t3 ^ t9;
520 t11 = t5 ^ t8;
521 e = g ^ t11;
522 t14 = t3 & t11;
523 h = t13 ^ t14
524 key[4 * 13 + 8] = e
525 key[4 * 13 + 9] = f
526 key[4 * 13 + 10] = g
527 key[4 * 13 + 11] = h
528 a = key[4 * 14 + 8]
529 b = key[4 * 14 + 9]
530 c = key[4 * 14 + 10]
531 d = key[4 * 14 + 11]
532 t1 = (~a) % 0x100000000;
533 t2 = a ^ b;
534 t3 = a ^ d;
535 t4 = c ^ t1;
536 t5 = t2 | t3;
537 e = t4 ^ t5;
538 t7 = d & e;
539 t8 = t2 ^ e;
540 t10 = t1 | e;
541 f = t7 ^ t8;
542 t11 = t2 | t7;
543 t12 = t3 ^ t10;
544 t14 = b ^ t7;
545 g = t11 ^ t12;
546 t15 = f & t12;
547 h = t14 ^ t15
548 key[4 * 14 + 8] = e
549 key[4 * 14 + 9] = f
550 key[4 * 14 + 10] = g
551 key[4 * 14 + 11] = h
552 a = key[4 * 15 + 8]
553 b = key[4 * 15 + 9]
554 c = key[4 * 15 + 10]
555 d = key[4 * 15 + 11]
556 t1 = a ^ d;
557 t2 = d & t1;
558 t3 = c ^ t2;
559 t4 = b | t3;
560 h = t1 ^ t4;
561 t6 = (~b) % 0x100000000;
562 t7 = t1 | t6;
563 e = t3 ^ t7;
564 t9 = a & e;
565 t10 = t1 ^ t6;
566 t11 = t4 & t10;
567 g = t9 ^ t11;
568 t13 = a ^ t3;
569 t14 = t10 & g;
570 f = t13 ^ t14
571 key[4 * 15 + 8] = e
572 key[4 * 15 + 9] = f
573 key[4 * 15 + 10] = g
574 key[4 * 15 + 11] = h
575 a = key[4 * 16 + 8]
576 b = key[4 * 16 + 9]
577 c = key[4 * 16 + 10]
578 d = key[4 * 16 + 11]
579 t1 = a ^ c;
580 t2 = d ^ t1;
581 t3 = a & t2;
582 t4 = d ^ t3;
583 t5 = b & t4;
584 g = t2 ^ t5;
585 t7 = a | g;
586 t8 = b | d;
587 t11 = a | d;
588 t9 = t4 & t7;
589 f = t8 ^ t9;
590 t12 = b ^ t11;
591 t13 = g ^ t9;
592 t15 = t3 ^ t8;
593 h = t12 ^ t13;
594 t16 = c & t15;
595 e = t12 ^ t16
596 key[4 * 16 + 8] = e
597 key[4 * 16 + 9] = f
598 key[4 * 16 + 10] = g
599 key[4 * 16 + 11] = h
600 a = key[4 * 17 + 8]
601 b = key[4 * 17 + 9]
602 c = key[4 * 17 + 10]
603 d = key[4 * 17 + 11]
604 t1 = (~a) % 0x100000000;
605 t2 = b ^ d;
606 t3 = c & t1;
607 t13 = d | t1;
608 e = t2 ^ t3;
609 t5 = c ^ t1;
610 t6 = c ^ e;
611 t7 = b & t6;
612 t10 = e | t5;
613 h = t5 ^ t7;
614 t9 = d | t7;
615 t11 = t9 & t10;
616 t14 = t2 ^ h;
617 g = a ^ t11;
618 t15 = g ^ t13;
619 f = t14 ^ t15
620 key[4 * 17 + 8] = e
621 key[4 * 17 + 9] = f
622 key[4 * 17 + 10] = g
623 key[4 * 17 + 11] = h
624 a = key[4 * 18 + 8]
625 b = key[4 * 18 + 9]
626 c = key[4 * 18 + 10]
627 d = key[4 * 18 + 11]
628 t1 = (~a) % 0x100000000;
629 t2 = b ^ t1;
630 t3 = a | t2;
631 t4 = d | t2;
632 t5 = c ^ t3;
633 g = d ^ t5;
634 t7 = b ^ t4;
635 t8 = t2 ^ g;
636 t9 = t5 & t7;
637 h = t8 ^ t9;
638 t11 = t5 ^ t7;
639 f = h ^ t11;
640 t13 = t8 & t11;
641 e = t5 ^ t13
642 key[4 * 18 + 8] = e
643 key[4 * 18 + 9] = f
644 key[4 * 18 + 10] = g
645 key[4 * 18 + 11] = h
646 a = key[4 * 19 + 8]
647 b = key[4 * 19 + 9]
648 c = key[4 * 19 + 10]
649 d = key[4 * 19 + 11]
650 t1 = a ^ d;
651 t2 = a & d;
652 t3 = c ^ t1;
653 t6 = b & t1;
654 t4 = b ^ t3;
655 t10 = (~t3) % 0x100000000;
656 h = t2 ^ t4;
657 t7 = a ^ t6;
658 t14 = (~t7) % 0x100000000;
659 t8 = c | t7;
660 t11 = t3 ^ t7;
661 g = t4 ^ t8;
662 t12 = h & t11;
663 f = t10 ^ t12;
664 e = t12 ^ t14
665 key[4 * 19 + 8] = e
666 key[4 * 19 + 9] = f
667 key[4 * 19 + 10] = g
668 key[4 * 19 + 11] = h
669 a = key[4 * 20 + 8]
670 b = key[4 * 20 + 9]
671 c = key[4 * 20 + 10]
672 d = key[4 * 20 + 11]
673 t1 = (~c) % 0x100000000;
674 t2 = b ^ c;
675 t3 = b | t1;
676 t4 = d ^ t3;
677 t5 = a & t4;
678 t7 = a ^ d;
679 h = t2 ^ t5;
680 t8 = b ^ t5;
681 t9 = t2 | t8;
682 t11 = d & t3;
683 f = t7 ^ t9;
684 t12 = t5 ^ f;
685 t15 = t1 | t4;
686 t13 = h & t12;
687 g = t11 ^ t13;
688 t16 = t12 ^ g;
689 e = t15 ^ t16
690 key[4 * 20 + 8] = e
691 key[4 * 20 + 9] = f
692 key[4 * 20 + 10] = g
693 key[4 * 20 + 11] = h
694 a = key[4 * 21 + 8]
695 b = key[4 * 21 + 9]
696 c = key[4 * 21 + 10]
697 d = key[4 * 21 + 11]
698 t1 = (~a) % 0x100000000;
699 t2 = a ^ d;
700 t3 = b ^ t2;
701 t4 = t1 | t2;
702 t5 = c ^ t4;
703 f = b ^ t5;
704 t13 = (~t5) % 0x100000000;
705 t7 = t2 | f;
706 t8 = d ^ t7;
707 t9 = t5 & t8;
708 g = t3 ^ t9;
709 t11 = t5 ^ t8;
710 e = g ^ t11;
711 t14 = t3 & t11;
712 h = t13 ^ t14
713 key[4 * 21 + 8] = e
714 key[4 * 21 + 9] = f
715 key[4 * 21 + 10] = g
716 key[4 * 21 + 11] = h
717 a = key[4 * 22 + 8]
718 b = key[4 * 22 + 9]
719 c = key[4 * 22 + 10]
720 d = key[4 * 22 + 11]
721 t1 = (~a) % 0x100000000;
722 t2 = a ^ b;
723 t3 = a ^ d;
724 t4 = c ^ t1;
725 t5 = t2 | t3;
726 e = t4 ^ t5;
727 t7 = d & e;
728 t8 = t2 ^ e;
729 t10 = t1 | e;
730 f = t7 ^ t8;
731 t11 = t2 | t7;
732 t12 = t3 ^ t10;
733 t14 = b ^ t7;
734 g = t11 ^ t12;
735 t15 = f & t12;
736 h = t14 ^ t15
737 key[4 * 22 + 8] = e
738 key[4 * 22 + 9] = f
739 key[4 * 22 + 10] = g
740 key[4 * 22 + 11] = h
741 a = key[4 * 23 + 8]
742 b = key[4 * 23 + 9]
743 c = key[4 * 23 + 10]
744 d = key[4 * 23 + 11]
745 t1 = a ^ d;
746 t2 = d & t1;
747 t3 = c ^ t2;
748 t4 = b | t3;
749 h = t1 ^ t4;
750 t6 = (~b) % 0x100000000;
751 t7 = t1 | t6;
752 e = t3 ^ t7;
753 t9 = a & e;
754 t10 = t1 ^ t6;
755 t11 = t4 & t10;
756 g = t9 ^ t11;
757 t13 = a ^ t3;
758 t14 = t10 & g;
759 f = t13 ^ t14
760 key[4 * 23 + 8] = e
761 key[4 * 23 + 9] = f
762 key[4 * 23 + 10] = g
763 key[4 * 23 + 11] = h
764 a = key[4 * 24 + 8]
765 b = key[4 * 24 + 9]
766 c = key[4 * 24 + 10]
767 d = key[4 * 24 + 11]
768 t1 = a ^ c;
769 t2 = d ^ t1;
770 t3 = a & t2;
771 t4 = d ^ t3;
772 t5 = b & t4;
773 g = t2 ^ t5;
774 t7 = a | g;
775 t8 = b | d;
776 t11 = a | d;
777 t9 = t4 & t7;
778 f = t8 ^ t9;
779 t12 = b ^ t11;
780 t13 = g ^ t9;
781 t15 = t3 ^ t8;
782 h = t12 ^ t13;
783 t16 = c & t15;
784 e = t12 ^ t16
785 key[4 * 24 + 8] = e
786 key[4 * 24 + 9] = f
787 key[4 * 24 + 10] = g
788 key[4 * 24 + 11] = h
789 a = key[4 * 25 + 8]
790 b = key[4 * 25 + 9]
791 c = key[4 * 25 + 10]
792 d = key[4 * 25 + 11]
793 t1 = (~a) % 0x100000000;
794 t2 = b ^ d;
795 t3 = c & t1;
796 t13 = d | t1;
797 e = t2 ^ t3;
798 t5 = c ^ t1;
799 t6 = c ^ e;
800 t7 = b & t6;
801 t10 = e | t5;
802 h = t5 ^ t7;
803 t9 = d | t7;
804 t11 = t9 & t10;
805 t14 = t2 ^ h;
806 g = a ^ t11;
807 t15 = g ^ t13;
808 f = t14 ^ t15
809 key[4 * 25 + 8] = e
810 key[4 * 25 + 9] = f
811 key[4 * 25 + 10] = g
812 key[4 * 25 + 11] = h
813 a = key[4 * 26 + 8]
814 b = key[4 * 26 + 9]
815 c = key[4 * 26 + 10]
816 d = key[4 * 26 + 11]
817 t1 = (~a) % 0x100000000;
818 t2 = b ^ t1;
819 t3 = a | t2;
820 t4 = d | t2;
821 t5 = c ^ t3;
822 g = d ^ t5;
823 t7 = b ^ t4;
824 t8 = t2 ^ g;
825 t9 = t5 & t7;
826 h = t8 ^ t9;
827 t11 = t5 ^ t7;
828 f = h ^ t11;
829 t13 = t8 & t11;
830 e = t5 ^ t13
831 key[4 * 26 + 8] = e
832 key[4 * 26 + 9] = f
833 key[4 * 26 + 10] = g
834 key[4 * 26 + 11] = h
835 a = key[4 * 27 + 8]
836 b = key[4 * 27 + 9]
837 c = key[4 * 27 + 10]
838 d = key[4 * 27 + 11]
839 t1 = a ^ d;
840 t2 = a & d;
841 t3 = c ^ t1;
842 t6 = b & t1;
843 t4 = b ^ t3;
844 t10 = (~t3) % 0x100000000;
845 h = t2 ^ t4;
846 t7 = a ^ t6;
847 t14 = (~t7) % 0x100000000;
848 t8 = c | t7;
849 t11 = t3 ^ t7;
850 g = t4 ^ t8;
851 t12 = h & t11;
852 f = t10 ^ t12;
853 e = t12 ^ t14
854 key[4 * 27 + 8] = e
855 key[4 * 27 + 9] = f
856 key[4 * 27 + 10] = g
857 key[4 * 27 + 11] = h
858 a = key[4 * 28 + 8]
859 b = key[4 * 28 + 9]
860 c = key[4 * 28 + 10]
861 d = key[4 * 28 + 11]
862 t1 = (~c) % 0x100000000;
863 t2 = b ^ c;
864 t3 = b | t1;
865 t4 = d ^ t3;
866 t5 = a & t4;
867 t7 = a ^ d;
868 h = t2 ^ t5;
869 t8 = b ^ t5;
870 t9 = t2 | t8;
871 t11 = d & t3;
872 f = t7 ^ t9;
873 t12 = t5 ^ f;
874 t15 = t1 | t4;
875 t13 = h & t12;
876 g = t11 ^ t13;
877 t16 = t12 ^ g;
878 e = t15 ^ t16
879 key[4 * 28 + 8] = e
880 key[4 * 28 + 9] = f
881 key[4 * 28 + 10] = g
882 key[4 * 28 + 11] = h
883 a = key[4 * 29 + 8]
884 b = key[4 * 29 + 9]
885 c = key[4 * 29 + 10]
886 d = key[4 * 29 + 11]
887 t1 = (~a) % 0x100000000;
888 t2 = a ^ d;
889 t3 = b ^ t2;
890 t4 = t1 | t2;
891 t5 = c ^ t4;
892 f = b ^ t5;
893 t13 = (~t5) % 0x100000000;
894 t7 = t2 | f;
895 t8 = d ^ t7;
896 t9 = t5 & t8;
897 g = t3 ^ t9;
898 t11 = t5 ^ t8;
899 e = g ^ t11;
900 t14 = t3 & t11;
901 h = t13 ^ t14
902 key[4 * 29 + 8] = e
903 key[4 * 29 + 9] = f
904 key[4 * 29 + 10] = g
905 key[4 * 29 + 11] = h
906 a = key[4 * 30 + 8]
907 b = key[4 * 30 + 9]
908 c = key[4 * 30 + 10]
909 d = key[4 * 30 + 11]
910 t1 = (~a) % 0x100000000;
911 t2 = a ^ b;
912 t3 = a ^ d;
913 t4 = c ^ t1;
914 t5 = t2 | t3;
915 e = t4 ^ t5;
916 t7 = d & e;
917 t8 = t2 ^ e;
918 t10 = t1 | e;
919 f = t7 ^ t8;
920 t11 = t2 | t7;
921 t12 = t3 ^ t10;
922 t14 = b ^ t7;
923 g = t11 ^ t12;
924 t15 = f & t12;
925 h = t14 ^ t15
926 key[4 * 30 + 8] = e
927 key[4 * 30 + 9] = f
928 key[4 * 30 + 10] = g
929 key[4 * 30 + 11] = h
930 a = key[4 * 31 + 8]
931 b = key[4 * 31 + 9]
932 c = key[4 * 31 + 10]
933 d = key[4 * 31 + 11]
934 t1 = a ^ d;
935 t2 = d & t1;
936 t3 = c ^ t2;
937 t4 = b | t3;
938 h = t1 ^ t4;
939 t6 = (~b) % 0x100000000;
940 t7 = t1 | t6;
941 e = t3 ^ t7;
942 t9 = a & e;
943 t10 = t1 ^ t6;
944 t11 = t4 & t10;
945 g = t9 ^ t11;
946 t13 = a ^ t3;
947 t14 = t10 & g;
948 f = t13 ^ t14
949 key[4 * 31 + 8] = e
950 key[4 * 31 + 9] = f
951 key[4 * 31 + 10] = g
952 key[4 * 31 + 11] = h
953 a = key[4 * 32 + 8]
954 b = key[4 * 32 + 9]
955 c = key[4 * 32 + 10]
956 d = key[4 * 32 + 11]
957 t1 = a ^ c;
958 t2 = d ^ t1;
959 t3 = a & t2;
960 t4 = d ^ t3;
961 t5 = b & t4;
962 g = t2 ^ t5;
963 t7 = a | g;
964 t8 = b | d;
965 t11 = a | d;
966 t9 = t4 & t7;
967 f = t8 ^ t9;
968 t12 = b ^ t11;
969 t13 = g ^ t9;
970 t15 = t3 ^ t8;
971 h = t12 ^ t13;
972 t16 = c & t15;
973 e = t12 ^ t16
974 key[4 * 32 + 8] = e
975 key[4 * 32 + 9] = f
976 key[4 * 32 + 10] = g
977 key[4 * 32 + 11] = h
979 def encrypt(key, in_blk):
980 # serpent_generate.py
981 a = in_blk[0]
982 b = in_blk[1]
983 c = in_blk[2]
984 d = in_blk[3]
985 if WORD_BIGENDIAN:
986 a = byteswap32(a)
987 b = byteswap32(b)
988 c = byteswap32(c)
989 d = byteswap32(d)
990 e = 0
991 f = 0
992 g = 0
993 h = 0
994 t1 = 0
995 t2 = 0
996 t3 = 0
997 t4 = 0
998 t5 = 0
999 t6 = 0
1000 t7 = 0
1001 t8 = 0
1002 t9 = 0
1003 t10 = 0
1004 t11 = 0
1005 t12 = 0
1006 t13 = 0
1007 t14 = 0
1008 t15 = 0
1009 t16 = 0
1010 a ^= key[4 * 0 + 8]
1011 b ^= key[4 * 0 + 9]
1012 c ^= key[4 * 0 + 10]
1013 d ^= key[4 * 0 + 11]
1014 t1 = a ^ d;
1015 t2 = a & d;
1016 t3 = c ^ t1;
1017 t6 = b & t1;
1018 t4 = b ^ t3;
1019 t10 = (~t3) % 0x100000000;
1020 h = t2 ^ t4;
1021 t7 = a ^ t6;
1022 t14 = (~t7) % 0x100000000;
1023 t8 = c | t7;
1024 t11 = t3 ^ t7;
1025 g = t4 ^ t8;
1026 t12 = h & t11;
1027 f = t10 ^ t12;
1028 e = t12 ^ t14
1029 e = rotl32(e, 13)
1030 g = rotl32(g, 3)
1031 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1032 f ^= e ^ g
1033 h = rotl32(h, 7)
1034 f = rotl32(f, 1)
1035 e ^= f ^ h
1036 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1037 e = rotl32(e, 5)
1038 g = rotl32(g, 22)
1039 e ^= key[4 * 1 + 8]
1040 f ^= key[4 * 1 + 9]
1041 g ^= key[4 * 1 + 10]
1042 h ^= key[4 * 1 + 11]
1043 t1 = (~e) % 0x100000000;
1044 t2 = f ^ t1;
1045 t3 = e | t2;
1046 t4 = h | t2;
1047 t5 = g ^ t3;
1048 c = h ^ t5;
1049 t7 = f ^ t4;
1050 t8 = t2 ^ c;
1051 t9 = t5 & t7;
1052 d = t8 ^ t9;
1053 t11 = t5 ^ t7;
1054 b = d ^ t11;
1055 t13 = t8 & t11;
1056 a = t5 ^ t13
1057 a = rotl32(a, 13)
1058 c = rotl32(c, 3)
1059 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1060 b ^= a ^ c
1061 d = rotl32(d, 7)
1062 b = rotl32(b, 1)
1063 a ^= b ^ d
1064 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1065 a = rotl32(a, 5)
1066 c = rotl32(c, 22)
1067 a ^= key[4 * 2 + 8]
1068 b ^= key[4 * 2 + 9]
1069 c ^= key[4 * 2 + 10]
1070 d ^= key[4 * 2 + 11]
1071 t1 = (~a) % 0x100000000;
1072 t2 = b ^ d;
1073 t3 = c & t1;
1074 t13 = d | t1;
1075 e = t2 ^ t3;
1076 t5 = c ^ t1;
1077 t6 = c ^ e;
1078 t7 = b & t6;
1079 t10 = e | t5;
1080 h = t5 ^ t7;
1081 t9 = d | t7;
1082 t11 = t9 & t10;
1083 t14 = t2 ^ h;
1084 g = a ^ t11;
1085 t15 = g ^ t13;
1086 f = t14 ^ t15
1087 e = rotl32(e, 13)
1088 g = rotl32(g, 3)
1089 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1090 f ^= e ^ g
1091 h = rotl32(h, 7)
1092 f = rotl32(f, 1)
1093 e ^= f ^ h
1094 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1095 e = rotl32(e, 5)
1096 g = rotl32(g, 22)
1097 e ^= key[4 * 3 + 8]
1098 f ^= key[4 * 3 + 9]
1099 g ^= key[4 * 3 + 10]
1100 h ^= key[4 * 3 + 11]
1101 t1 = e ^ g;
1102 t2 = h ^ t1;
1103 t3 = e & t2;
1104 t4 = h ^ t3;
1105 t5 = f & t4;
1106 c = t2 ^ t5;
1107 t7 = e | c;
1108 t8 = f | h;
1109 t11 = e | h;
1110 t9 = t4 & t7;
1111 b = t8 ^ t9;
1112 t12 = f ^ t11;
1113 t13 = c ^ t9;
1114 t15 = t3 ^ t8;
1115 d = t12 ^ t13;
1116 t16 = g & t15;
1117 a = t12 ^ t16
1118 a = rotl32(a, 13)
1119 c = rotl32(c, 3)
1120 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1121 b ^= a ^ c
1122 d = rotl32(d, 7)
1123 b = rotl32(b, 1)
1124 a ^= b ^ d
1125 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1126 a = rotl32(a, 5)
1127 c = rotl32(c, 22)
1128 a ^= key[4 * 4 + 8]
1129 b ^= key[4 * 4 + 9]
1130 c ^= key[4 * 4 + 10]
1131 d ^= key[4 * 4 + 11]
1132 t1 = a ^ d;
1133 t2 = d & t1;
1134 t3 = c ^ t2;
1135 t4 = b | t3;
1136 h = t1 ^ t4;
1137 t6 = (~b) % 0x100000000;
1138 t7 = t1 | t6;
1139 e = t3 ^ t7;
1140 t9 = a & e;
1141 t10 = t1 ^ t6;
1142 t11 = t4 & t10;
1143 g = t9 ^ t11;
1144 t13 = a ^ t3;
1145 t14 = t10 & g;
1146 f = t13 ^ t14
1147 e = rotl32(e, 13)
1148 g = rotl32(g, 3)
1149 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1150 f ^= e ^ g
1151 h = rotl32(h, 7)
1152 f = rotl32(f, 1)
1153 e ^= f ^ h
1154 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1155 e = rotl32(e, 5)
1156 g = rotl32(g, 22)
1157 e ^= key[4 * 5 + 8]
1158 f ^= key[4 * 5 + 9]
1159 g ^= key[4 * 5 + 10]
1160 h ^= key[4 * 5 + 11]
1161 t1 = (~e) % 0x100000000;
1162 t2 = e ^ f;
1163 t3 = e ^ h;
1164 t4 = g ^ t1;
1165 t5 = t2 | t3;
1166 a = t4 ^ t5;
1167 t7 = h & a;
1168 t8 = t2 ^ a;
1169 t10 = t1 | a;
1170 b = t7 ^ t8;
1171 t11 = t2 | t7;
1172 t12 = t3 ^ t10;
1173 t14 = f ^ t7;
1174 c = t11 ^ t12;
1175 t15 = b & t12;
1176 d = t14 ^ t15
1177 a = rotl32(a, 13)
1178 c = rotl32(c, 3)
1179 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1180 b ^= a ^ c
1181 d = rotl32(d, 7)
1182 b = rotl32(b, 1)
1183 a ^= b ^ d
1184 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1185 a = rotl32(a, 5)
1186 c = rotl32(c, 22)
1187 a ^= key[4 * 6 + 8]
1188 b ^= key[4 * 6 + 9]
1189 c ^= key[4 * 6 + 10]
1190 d ^= key[4 * 6 + 11]
1191 t1 = (~a) % 0x100000000;
1192 t2 = a ^ d;
1193 t3 = b ^ t2;
1194 t4 = t1 | t2;
1195 t5 = c ^ t4;
1196 f = b ^ t5;
1197 t13 = (~t5) % 0x100000000;
1198 t7 = t2 | f;
1199 t8 = d ^ t7;
1200 t9 = t5 & t8;
1201 g = t3 ^ t9;
1202 t11 = t5 ^ t8;
1203 e = g ^ t11;
1204 t14 = t3 & t11;
1205 h = t13 ^ t14
1206 e = rotl32(e, 13)
1207 g = rotl32(g, 3)
1208 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1209 f ^= e ^ g
1210 h = rotl32(h, 7)
1211 f = rotl32(f, 1)
1212 e ^= f ^ h
1213 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1214 e = rotl32(e, 5)
1215 g = rotl32(g, 22)
1216 e ^= key[4 * 7 + 8]
1217 f ^= key[4 * 7 + 9]
1218 g ^= key[4 * 7 + 10]
1219 h ^= key[4 * 7 + 11]
1220 t1 = (~g) % 0x100000000;
1221 t2 = f ^ g;
1222 t3 = f | t1;
1223 t4 = h ^ t3;
1224 t5 = e & t4;
1225 t7 = e ^ h;
1226 d = t2 ^ t5;
1227 t8 = f ^ t5;
1228 t9 = t2 | t8;
1229 t11 = h & t3;
1230 b = t7 ^ t9;
1231 t12 = t5 ^ b;
1232 t15 = t1 | t4;
1233 t13 = d & t12;
1234 c = t11 ^ t13;
1235 t16 = t12 ^ c;
1236 a = t15 ^ t16
1237 a = rotl32(a, 13)
1238 c = rotl32(c, 3)
1239 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1240 b ^= a ^ c
1241 d = rotl32(d, 7)
1242 b = rotl32(b, 1)
1243 a ^= b ^ d
1244 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1245 a = rotl32(a, 5)
1246 c = rotl32(c, 22)
1247 a ^= key[4 * 8 + 8]
1248 b ^= key[4 * 8 + 9]
1249 c ^= key[4 * 8 + 10]
1250 d ^= key[4 * 8 + 11]
1251 t1 = a ^ d;
1252 t2 = a & d;
1253 t3 = c ^ t1;
1254 t6 = b & t1;
1255 t4 = b ^ t3;
1256 t10 = (~t3) % 0x100000000;
1257 h = t2 ^ t4;
1258 t7 = a ^ t6;
1259 t14 = (~t7) % 0x100000000;
1260 t8 = c | t7;
1261 t11 = t3 ^ t7;
1262 g = t4 ^ t8;
1263 t12 = h & t11;
1264 f = t10 ^ t12;
1265 e = t12 ^ t14
1266 e = rotl32(e, 13)
1267 g = rotl32(g, 3)
1268 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1269 f ^= e ^ g
1270 h = rotl32(h, 7)
1271 f = rotl32(f, 1)
1272 e ^= f ^ h
1273 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1274 e = rotl32(e, 5)
1275 g = rotl32(g, 22)
1276 e ^= key[4 * 9 + 8]
1277 f ^= key[4 * 9 + 9]
1278 g ^= key[4 * 9 + 10]
1279 h ^= key[4 * 9 + 11]
1280 t1 = (~e) % 0x100000000;
1281 t2 = f ^ t1;
1282 t3 = e | t2;
1283 t4 = h | t2;
1284 t5 = g ^ t3;
1285 c = h ^ t5;
1286 t7 = f ^ t4;
1287 t8 = t2 ^ c;
1288 t9 = t5 & t7;
1289 d = t8 ^ t9;
1290 t11 = t5 ^ t7;
1291 b = d ^ t11;
1292 t13 = t8 & t11;
1293 a = t5 ^ t13
1294 a = rotl32(a, 13)
1295 c = rotl32(c, 3)
1296 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1297 b ^= a ^ c
1298 d = rotl32(d, 7)
1299 b = rotl32(b, 1)
1300 a ^= b ^ d
1301 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1302 a = rotl32(a, 5)
1303 c = rotl32(c, 22)
1304 a ^= key[4 * 10 + 8]
1305 b ^= key[4 * 10 + 9]
1306 c ^= key[4 * 10 + 10]
1307 d ^= key[4 * 10 + 11]
1308 t1 = (~a) % 0x100000000;
1309 t2 = b ^ d;
1310 t3 = c & t1;
1311 t13 = d | t1;
1312 e = t2 ^ t3;
1313 t5 = c ^ t1;
1314 t6 = c ^ e;
1315 t7 = b & t6;
1316 t10 = e | t5;
1317 h = t5 ^ t7;
1318 t9 = d | t7;
1319 t11 = t9 & t10;
1320 t14 = t2 ^ h;
1321 g = a ^ t11;
1322 t15 = g ^ t13;
1323 f = t14 ^ t15
1324 e = rotl32(e, 13)
1325 g = rotl32(g, 3)
1326 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1327 f ^= e ^ g
1328 h = rotl32(h, 7)
1329 f = rotl32(f, 1)
1330 e ^= f ^ h
1331 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1332 e = rotl32(e, 5)
1333 g = rotl32(g, 22)
1334 e ^= key[4 * 11 + 8]
1335 f ^= key[4 * 11 + 9]
1336 g ^= key[4 * 11 + 10]
1337 h ^= key[4 * 11 + 11]
1338 t1 = e ^ g;
1339 t2 = h ^ t1;
1340 t3 = e & t2;
1341 t4 = h ^ t3;
1342 t5 = f & t4;
1343 c = t2 ^ t5;
1344 t7 = e | c;
1345 t8 = f | h;
1346 t11 = e | h;
1347 t9 = t4 & t7;
1348 b = t8 ^ t9;
1349 t12 = f ^ t11;
1350 t13 = c ^ t9;
1351 t15 = t3 ^ t8;
1352 d = t12 ^ t13;
1353 t16 = g & t15;
1354 a = t12 ^ t16
1355 a = rotl32(a, 13)
1356 c = rotl32(c, 3)
1357 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1358 b ^= a ^ c
1359 d = rotl32(d, 7)
1360 b = rotl32(b, 1)
1361 a ^= b ^ d
1362 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1363 a = rotl32(a, 5)
1364 c = rotl32(c, 22)
1365 a ^= key[4 * 12 + 8]
1366 b ^= key[4 * 12 + 9]
1367 c ^= key[4 * 12 + 10]
1368 d ^= key[4 * 12 + 11]
1369 t1 = a ^ d;
1370 t2 = d & t1;
1371 t3 = c ^ t2;
1372 t4 = b | t3;
1373 h = t1 ^ t4;
1374 t6 = (~b) % 0x100000000;
1375 t7 = t1 | t6;
1376 e = t3 ^ t7;
1377 t9 = a & e;
1378 t10 = t1 ^ t6;
1379 t11 = t4 & t10;
1380 g = t9 ^ t11;
1381 t13 = a ^ t3;
1382 t14 = t10 & g;
1383 f = t13 ^ t14
1384 e = rotl32(e, 13)
1385 g = rotl32(g, 3)
1386 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1387 f ^= e ^ g
1388 h = rotl32(h, 7)
1389 f = rotl32(f, 1)
1390 e ^= f ^ h
1391 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1392 e = rotl32(e, 5)
1393 g = rotl32(g, 22)
1394 e ^= key[4 * 13 + 8]
1395 f ^= key[4 * 13 + 9]
1396 g ^= key[4 * 13 + 10]
1397 h ^= key[4 * 13 + 11]
1398 t1 = (~e) % 0x100000000;
1399 t2 = e ^ f;
1400 t3 = e ^ h;
1401 t4 = g ^ t1;
1402 t5 = t2 | t3;
1403 a = t4 ^ t5;
1404 t7 = h & a;
1405 t8 = t2 ^ a;
1406 t10 = t1 | a;
1407 b = t7 ^ t8;
1408 t11 = t2 | t7;
1409 t12 = t3 ^ t10;
1410 t14 = f ^ t7;
1411 c = t11 ^ t12;
1412 t15 = b & t12;
1413 d = t14 ^ t15
1414 a = rotl32(a, 13)
1415 c = rotl32(c, 3)
1416 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1417 b ^= a ^ c
1418 d = rotl32(d, 7)
1419 b = rotl32(b, 1)
1420 a ^= b ^ d
1421 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1422 a = rotl32(a, 5)
1423 c = rotl32(c, 22)
1424 a ^= key[4 * 14 + 8]
1425 b ^= key[4 * 14 + 9]
1426 c ^= key[4 * 14 + 10]
1427 d ^= key[4 * 14 + 11]
1428 t1 = (~a) % 0x100000000;
1429 t2 = a ^ d;
1430 t3 = b ^ t2;
1431 t4 = t1 | t2;
1432 t5 = c ^ t4;
1433 f = b ^ t5;
1434 t13 = (~t5) % 0x100000000;
1435 t7 = t2 | f;
1436 t8 = d ^ t7;
1437 t9 = t5 & t8;
1438 g = t3 ^ t9;
1439 t11 = t5 ^ t8;
1440 e = g ^ t11;
1441 t14 = t3 & t11;
1442 h = t13 ^ t14
1443 e = rotl32(e, 13)
1444 g = rotl32(g, 3)
1445 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1446 f ^= e ^ g
1447 h = rotl32(h, 7)
1448 f = rotl32(f, 1)
1449 e ^= f ^ h
1450 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1451 e = rotl32(e, 5)
1452 g = rotl32(g, 22)
1453 e ^= key[4 * 15 + 8]
1454 f ^= key[4 * 15 + 9]
1455 g ^= key[4 * 15 + 10]
1456 h ^= key[4 * 15 + 11]
1457 t1 = (~g) % 0x100000000;
1458 t2 = f ^ g;
1459 t3 = f | t1;
1460 t4 = h ^ t3;
1461 t5 = e & t4;
1462 t7 = e ^ h;
1463 d = t2 ^ t5;
1464 t8 = f ^ t5;
1465 t9 = t2 | t8;
1466 t11 = h & t3;
1467 b = t7 ^ t9;
1468 t12 = t5 ^ b;
1469 t15 = t1 | t4;
1470 t13 = d & t12;
1471 c = t11 ^ t13;
1472 t16 = t12 ^ c;
1473 a = t15 ^ t16
1474 a = rotl32(a, 13)
1475 c = rotl32(c, 3)
1476 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1477 b ^= a ^ c
1478 d = rotl32(d, 7)
1479 b = rotl32(b, 1)
1480 a ^= b ^ d
1481 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1482 a = rotl32(a, 5)
1483 c = rotl32(c, 22)
1484 a ^= key[4 * 16 + 8]
1485 b ^= key[4 * 16 + 9]
1486 c ^= key[4 * 16 + 10]
1487 d ^= key[4 * 16 + 11]
1488 t1 = a ^ d;
1489 t2 = a & d;
1490 t3 = c ^ t1;
1491 t6 = b & t1;
1492 t4 = b ^ t3;
1493 t10 = (~t3) % 0x100000000;
1494 h = t2 ^ t4;
1495 t7 = a ^ t6;
1496 t14 = (~t7) % 0x100000000;
1497 t8 = c | t7;
1498 t11 = t3 ^ t7;
1499 g = t4 ^ t8;
1500 t12 = h & t11;
1501 f = t10 ^ t12;
1502 e = t12 ^ t14
1503 e = rotl32(e, 13)
1504 g = rotl32(g, 3)
1505 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1506 f ^= e ^ g
1507 h = rotl32(h, 7)
1508 f = rotl32(f, 1)
1509 e ^= f ^ h
1510 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1511 e = rotl32(e, 5)
1512 g = rotl32(g, 22)
1513 e ^= key[4 * 17 + 8]
1514 f ^= key[4 * 17 + 9]
1515 g ^= key[4 * 17 + 10]
1516 h ^= key[4 * 17 + 11]
1517 t1 = (~e) % 0x100000000;
1518 t2 = f ^ t1;
1519 t3 = e | t2;
1520 t4 = h | t2;
1521 t5 = g ^ t3;
1522 c = h ^ t5;
1523 t7 = f ^ t4;
1524 t8 = t2 ^ c;
1525 t9 = t5 & t7;
1526 d = t8 ^ t9;
1527 t11 = t5 ^ t7;
1528 b = d ^ t11;
1529 t13 = t8 & t11;
1530 a = t5 ^ t13
1531 a = rotl32(a, 13)
1532 c = rotl32(c, 3)
1533 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1534 b ^= a ^ c
1535 d = rotl32(d, 7)
1536 b = rotl32(b, 1)
1537 a ^= b ^ d
1538 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1539 a = rotl32(a, 5)
1540 c = rotl32(c, 22)
1541 a ^= key[4 * 18 + 8]
1542 b ^= key[4 * 18 + 9]
1543 c ^= key[4 * 18 + 10]
1544 d ^= key[4 * 18 + 11]
1545 t1 = (~a) % 0x100000000;
1546 t2 = b ^ d;
1547 t3 = c & t1;
1548 t13 = d | t1;
1549 e = t2 ^ t3;
1550 t5 = c ^ t1;
1551 t6 = c ^ e;
1552 t7 = b & t6;
1553 t10 = e | t5;
1554 h = t5 ^ t7;
1555 t9 = d | t7;
1556 t11 = t9 & t10;
1557 t14 = t2 ^ h;
1558 g = a ^ t11;
1559 t15 = g ^ t13;
1560 f = t14 ^ t15
1561 e = rotl32(e, 13)
1562 g = rotl32(g, 3)
1563 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1564 f ^= e ^ g
1565 h = rotl32(h, 7)
1566 f = rotl32(f, 1)
1567 e ^= f ^ h
1568 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1569 e = rotl32(e, 5)
1570 g = rotl32(g, 22)
1571 e ^= key[4 * 19 + 8]
1572 f ^= key[4 * 19 + 9]
1573 g ^= key[4 * 19 + 10]
1574 h ^= key[4 * 19 + 11]
1575 t1 = e ^ g;
1576 t2 = h ^ t1;
1577 t3 = e & t2;
1578 t4 = h ^ t3;
1579 t5 = f & t4;
1580 c = t2 ^ t5;
1581 t7 = e | c;
1582 t8 = f | h;
1583 t11 = e | h;
1584 t9 = t4 & t7;
1585 b = t8 ^ t9;
1586 t12 = f ^ t11;
1587 t13 = c ^ t9;
1588 t15 = t3 ^ t8;
1589 d = t12 ^ t13;
1590 t16 = g & t15;
1591 a = t12 ^ t16
1592 a = rotl32(a, 13)
1593 c = rotl32(c, 3)
1594 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1595 b ^= a ^ c
1596 d = rotl32(d, 7)
1597 b = rotl32(b, 1)
1598 a ^= b ^ d
1599 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1600 a = rotl32(a, 5)
1601 c = rotl32(c, 22)
1602 a ^= key[4 * 20 + 8]
1603 b ^= key[4 * 20 + 9]
1604 c ^= key[4 * 20 + 10]
1605 d ^= key[4 * 20 + 11]
1606 t1 = a ^ d;
1607 t2 = d & t1;
1608 t3 = c ^ t2;
1609 t4 = b | t3;
1610 h = t1 ^ t4;
1611 t6 = (~b) % 0x100000000;
1612 t7 = t1 | t6;
1613 e = t3 ^ t7;
1614 t9 = a & e;
1615 t10 = t1 ^ t6;
1616 t11 = t4 & t10;
1617 g = t9 ^ t11;
1618 t13 = a ^ t3;
1619 t14 = t10 & g;
1620 f = t13 ^ t14
1621 e = rotl32(e, 13)
1622 g = rotl32(g, 3)
1623 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1624 f ^= e ^ g
1625 h = rotl32(h, 7)
1626 f = rotl32(f, 1)
1627 e ^= f ^ h
1628 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1629 e = rotl32(e, 5)
1630 g = rotl32(g, 22)
1631 e ^= key[4 * 21 + 8]
1632 f ^= key[4 * 21 + 9]
1633 g ^= key[4 * 21 + 10]
1634 h ^= key[4 * 21 + 11]
1635 t1 = (~e) % 0x100000000;
1636 t2 = e ^ f;
1637 t3 = e ^ h;
1638 t4 = g ^ t1;
1639 t5 = t2 | t3;
1640 a = t4 ^ t5;
1641 t7 = h & a;
1642 t8 = t2 ^ a;
1643 t10 = t1 | a;
1644 b = t7 ^ t8;
1645 t11 = t2 | t7;
1646 t12 = t3 ^ t10;
1647 t14 = f ^ t7;
1648 c = t11 ^ t12;
1649 t15 = b & t12;
1650 d = t14 ^ t15
1651 a = rotl32(a, 13)
1652 c = rotl32(c, 3)
1653 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1654 b ^= a ^ c
1655 d = rotl32(d, 7)
1656 b = rotl32(b, 1)
1657 a ^= b ^ d
1658 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1659 a = rotl32(a, 5)
1660 c = rotl32(c, 22)
1661 a ^= key[4 * 22 + 8]
1662 b ^= key[4 * 22 + 9]
1663 c ^= key[4 * 22 + 10]
1664 d ^= key[4 * 22 + 11]
1665 t1 = (~a) % 0x100000000;
1666 t2 = a ^ d;
1667 t3 = b ^ t2;
1668 t4 = t1 | t2;
1669 t5 = c ^ t4;
1670 f = b ^ t5;
1671 t13 = (~t5) % 0x100000000;
1672 t7 = t2 | f;
1673 t8 = d ^ t7;
1674 t9 = t5 & t8;
1675 g = t3 ^ t9;
1676 t11 = t5 ^ t8;
1677 e = g ^ t11;
1678 t14 = t3 & t11;
1679 h = t13 ^ t14
1680 e = rotl32(e, 13)
1681 g = rotl32(g, 3)
1682 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1683 f ^= e ^ g
1684 h = rotl32(h, 7)
1685 f = rotl32(f, 1)
1686 e ^= f ^ h
1687 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1688 e = rotl32(e, 5)
1689 g = rotl32(g, 22)
1690 e ^= key[4 * 23 + 8]
1691 f ^= key[4 * 23 + 9]
1692 g ^= key[4 * 23 + 10]
1693 h ^= key[4 * 23 + 11]
1694 t1 = (~g) % 0x100000000;
1695 t2 = f ^ g;
1696 t3 = f | t1;
1697 t4 = h ^ t3;
1698 t5 = e & t4;
1699 t7 = e ^ h;
1700 d = t2 ^ t5;
1701 t8 = f ^ t5;
1702 t9 = t2 | t8;
1703 t11 = h & t3;
1704 b = t7 ^ t9;
1705 t12 = t5 ^ b;
1706 t15 = t1 | t4;
1707 t13 = d & t12;
1708 c = t11 ^ t13;
1709 t16 = t12 ^ c;
1710 a = t15 ^ t16
1711 a = rotl32(a, 13)
1712 c = rotl32(c, 3)
1713 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1714 b ^= a ^ c
1715 d = rotl32(d, 7)
1716 b = rotl32(b, 1)
1717 a ^= b ^ d
1718 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1719 a = rotl32(a, 5)
1720 c = rotl32(c, 22)
1721 a ^= key[4 * 24 + 8]
1722 b ^= key[4 * 24 + 9]
1723 c ^= key[4 * 24 + 10]
1724 d ^= key[4 * 24 + 11]
1725 t1 = a ^ d;
1726 t2 = a & d;
1727 t3 = c ^ t1;
1728 t6 = b & t1;
1729 t4 = b ^ t3;
1730 t10 = (~t3) % 0x100000000;
1731 h = t2 ^ t4;
1732 t7 = a ^ t6;
1733 t14 = (~t7) % 0x100000000;
1734 t8 = c | t7;
1735 t11 = t3 ^ t7;
1736 g = t4 ^ t8;
1737 t12 = h & t11;
1738 f = t10 ^ t12;
1739 e = t12 ^ t14
1740 e = rotl32(e, 13)
1741 g = rotl32(g, 3)
1742 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1743 f ^= e ^ g
1744 h = rotl32(h, 7)
1745 f = rotl32(f, 1)
1746 e ^= f ^ h
1747 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1748 e = rotl32(e, 5)
1749 g = rotl32(g, 22)
1750 e ^= key[4 * 25 + 8]
1751 f ^= key[4 * 25 + 9]
1752 g ^= key[4 * 25 + 10]
1753 h ^= key[4 * 25 + 11]
1754 t1 = (~e) % 0x100000000;
1755 t2 = f ^ t1;
1756 t3 = e | t2;
1757 t4 = h | t2;
1758 t5 = g ^ t3;
1759 c = h ^ t5;
1760 t7 = f ^ t4;
1761 t8 = t2 ^ c;
1762 t9 = t5 & t7;
1763 d = t8 ^ t9;
1764 t11 = t5 ^ t7;
1765 b = d ^ t11;
1766 t13 = t8 & t11;
1767 a = t5 ^ t13
1768 a = rotl32(a, 13)
1769 c = rotl32(c, 3)
1770 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1771 b ^= a ^ c
1772 d = rotl32(d, 7)
1773 b = rotl32(b, 1)
1774 a ^= b ^ d
1775 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1776 a = rotl32(a, 5)
1777 c = rotl32(c, 22)
1778 a ^= key[4 * 26 + 8]
1779 b ^= key[4 * 26 + 9]
1780 c ^= key[4 * 26 + 10]
1781 d ^= key[4 * 26 + 11]
1782 t1 = (~a) % 0x100000000;
1783 t2 = b ^ d;
1784 t3 = c & t1;
1785 t13 = d | t1;
1786 e = t2 ^ t3;
1787 t5 = c ^ t1;
1788 t6 = c ^ e;
1789 t7 = b & t6;
1790 t10 = e | t5;
1791 h = t5 ^ t7;
1792 t9 = d | t7;
1793 t11 = t9 & t10;
1794 t14 = t2 ^ h;
1795 g = a ^ t11;
1796 t15 = g ^ t13;
1797 f = t14 ^ t15
1798 e = rotl32(e, 13)
1799 g = rotl32(g, 3)
1800 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1801 f ^= e ^ g
1802 h = rotl32(h, 7)
1803 f = rotl32(f, 1)
1804 e ^= f ^ h
1805 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1806 e = rotl32(e, 5)
1807 g = rotl32(g, 22)
1808 e ^= key[4 * 27 + 8]
1809 f ^= key[4 * 27 + 9]
1810 g ^= key[4 * 27 + 10]
1811 h ^= key[4 * 27 + 11]
1812 t1 = e ^ g;
1813 t2 = h ^ t1;
1814 t3 = e & t2;
1815 t4 = h ^ t3;
1816 t5 = f & t4;
1817 c = t2 ^ t5;
1818 t7 = e | c;
1819 t8 = f | h;
1820 t11 = e | h;
1821 t9 = t4 & t7;
1822 b = t8 ^ t9;
1823 t12 = f ^ t11;
1824 t13 = c ^ t9;
1825 t15 = t3 ^ t8;
1826 d = t12 ^ t13;
1827 t16 = g & t15;
1828 a = t12 ^ t16
1829 a = rotl32(a, 13)
1830 c = rotl32(c, 3)
1831 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1832 b ^= a ^ c
1833 d = rotl32(d, 7)
1834 b = rotl32(b, 1)
1835 a ^= b ^ d
1836 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1837 a = rotl32(a, 5)
1838 c = rotl32(c, 22)
1839 a ^= key[4 * 28 + 8]
1840 b ^= key[4 * 28 + 9]
1841 c ^= key[4 * 28 + 10]
1842 d ^= key[4 * 28 + 11]
1843 t1 = a ^ d;
1844 t2 = d & t1;
1845 t3 = c ^ t2;
1846 t4 = b | t3;
1847 h = t1 ^ t4;
1848 t6 = (~b) % 0x100000000;
1849 t7 = t1 | t6;
1850 e = t3 ^ t7;
1851 t9 = a & e;
1852 t10 = t1 ^ t6;
1853 t11 = t4 & t10;
1854 g = t9 ^ t11;
1855 t13 = a ^ t3;
1856 t14 = t10 & g;
1857 f = t13 ^ t14
1858 e = rotl32(e, 13)
1859 g = rotl32(g, 3)
1860 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1861 f ^= e ^ g
1862 h = rotl32(h, 7)
1863 f = rotl32(f, 1)
1864 e ^= f ^ h
1865 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1866 e = rotl32(e, 5)
1867 g = rotl32(g, 22)
1868 e ^= key[4 * 29 + 8]
1869 f ^= key[4 * 29 + 9]
1870 g ^= key[4 * 29 + 10]
1871 h ^= key[4 * 29 + 11]
1872 t1 = (~e) % 0x100000000;
1873 t2 = e ^ f;
1874 t3 = e ^ h;
1875 t4 = g ^ t1;
1876 t5 = t2 | t3;
1877 a = t4 ^ t5;
1878 t7 = h & a;
1879 t8 = t2 ^ a;
1880 t10 = t1 | a;
1881 b = t7 ^ t8;
1882 t11 = t2 | t7;
1883 t12 = t3 ^ t10;
1884 t14 = f ^ t7;
1885 c = t11 ^ t12;
1886 t15 = b & t12;
1887 d = t14 ^ t15
1888 a = rotl32(a, 13)
1889 c = rotl32(c, 3)
1890 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
1891 b ^= a ^ c
1892 d = rotl32(d, 7)
1893 b = rotl32(b, 1)
1894 a ^= b ^ d
1895 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
1896 a = rotl32(a, 5)
1897 c = rotl32(c, 22)
1898 a ^= key[4 * 30 + 8]
1899 b ^= key[4 * 30 + 9]
1900 c ^= key[4 * 30 + 10]
1901 d ^= key[4 * 30 + 11]
1902 t1 = (~a) % 0x100000000;
1903 t2 = a ^ d;
1904 t3 = b ^ t2;
1905 t4 = t1 | t2;
1906 t5 = c ^ t4;
1907 f = b ^ t5;
1908 t13 = (~t5) % 0x100000000;
1909 t7 = t2 | f;
1910 t8 = d ^ t7;
1911 t9 = t5 & t8;
1912 g = t3 ^ t9;
1913 t11 = t5 ^ t8;
1914 e = g ^ t11;
1915 t14 = t3 & t11;
1916 h = t13 ^ t14
1917 e = rotl32(e, 13)
1918 g = rotl32(g, 3)
1919 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
1920 f ^= e ^ g
1921 h = rotl32(h, 7)
1922 f = rotl32(f, 1)
1923 e ^= f ^ h
1924 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
1925 e = rotl32(e, 5)
1926 g = rotl32(g, 22)
1927 e ^= key[4 * 31 + 8]
1928 f ^= key[4 * 31 + 9]
1929 g ^= key[4 * 31 + 10]
1930 h ^= key[4 * 31 + 11]
1931 t1 = (~g) % 0x100000000;
1932 t2 = f ^ g;
1933 t3 = f | t1;
1934 t4 = h ^ t3;
1935 t5 = e & t4;
1936 t7 = e ^ h;
1937 d = t2 ^ t5;
1938 t8 = f ^ t5;
1939 t9 = t2 | t8;
1940 t11 = h & t3;
1941 b = t7 ^ t9;
1942 t12 = t5 ^ b;
1943 t15 = t1 | t4;
1944 t13 = d & t12;
1945 c = t11 ^ t13;
1946 t16 = t12 ^ c;
1947 a = t15 ^ t16
1948 a ^= key[4 * 32 + 8]
1949 b ^= key[4 * 32 + 9]
1950 c ^= key[4 * 32 + 10]
1951 d ^= key[4 * 32 + 11]
1952 if WORD_BIGENDIAN:
1953 a = byteswap32(a)
1954 b = byteswap32(b)
1955 c = byteswap32(c)
1956 d = byteswap32(d)
1957 in_blk[0] = a
1958 in_blk[1] = b
1959 in_blk[2] = c
1960 in_blk[3] = d
1962 def decrypt(key, in_blk):
1963 # serpent_generate.py
1964 a = in_blk[0]
1965 b = in_blk[1]
1966 c = in_blk[2]
1967 d = in_blk[3]
1968 if WORD_BIGENDIAN:
1969 a = byteswap32(a)
1970 b = byteswap32(b)
1971 c = byteswap32(c)
1972 d = byteswap32(d)
1973 e = 0
1974 f = 0
1975 g = 0
1976 h = 0
1977 t1 = 0
1978 t2 = 0
1979 t3 = 0
1980 t4 = 0
1981 t5 = 0
1982 t6 = 0
1983 t7 = 0
1984 t8 = 0
1985 t9 = 0
1986 t10 = 0
1987 t11 = 0
1988 t12 = 0
1989 t13 = 0
1990 t14 = 0
1991 t15 = 0
1992 t16 = 0
1993 a ^= key[4 * 32 + 8]
1994 b ^= key[4 * 32 + 9]
1995 c ^= key[4 * 32 + 10]
1996 d ^= key[4 * 32 + 11]
1997 t1 = a & b;
1998 t2 = a | b;
1999 t3 = c | t1;
2000 t4 = d & t2;
2001 h = t3 ^ t4;
2002 t6 = (~d) % 0x100000000;
2003 t7 = b ^ t4;
2004 t8 = h ^ t6;
2005 t11 = c ^ t7;
2006 t9 = t7 | t8;
2007 f = a ^ t9;
2008 t12 = d | f;
2009 e = t11 ^ t12;
2010 t14 = a & h;
2011 t15 = t3 ^ f;
2012 t16 = e ^ t14;
2013 g = t15 ^ t16
2014 e ^= key[4 * 31 + 8]
2015 f ^= key[4 * 31 + 9]
2016 g ^= key[4 * 31 + 10]
2017 h ^= key[4 * 31 + 11]
2018 g = rotr32(g, 22)
2019 e = rotr32(e, 5)
2020 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2021 e ^= f ^ h
2022 h = rotr32(h, 7)
2023 f = rotr32(f, 1)
2024 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2025 f ^= e ^ g
2026 g = rotr32(g, 3)
2027 e = rotr32(e, 13)
2028 t1 = (~e) % 0x100000000;
2029 t2 = e ^ f;
2030 t3 = g ^ t2;
2031 t4 = g | t1;
2032 t5 = h ^ t4;
2033 t13 = h & t1;
2034 b = t3 ^ t5;
2035 t7 = t3 & t5;
2036 t8 = t2 ^ t7;
2037 t9 = f | t8;
2038 d = t5 ^ t9;
2039 t11 = f | d;
2040 a = t8 ^ t11;
2041 t14 = t3 ^ t11;
2042 c = t13 ^ t14
2043 a ^= key[4 * 30 + 8]
2044 b ^= key[4 * 30 + 9]
2045 c ^= key[4 * 30 + 10]
2046 d ^= key[4 * 30 + 11]
2047 c = rotr32(c, 22)
2048 a = rotr32(a, 5)
2049 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2050 a ^= b ^ d
2051 d = rotr32(d, 7)
2052 b = rotr32(b, 1)
2053 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2054 b ^= a ^ c
2055 c = rotr32(c, 3)
2056 a = rotr32(a, 13)
2057 t1 = (~c) % 0x100000000;
2058 t2 = b & t1;
2059 t3 = d ^ t2;
2060 t4 = a & t3;
2061 t5 = b ^ t1;
2062 h = t4 ^ t5;
2063 t7 = b | h;
2064 t8 = a & t7;
2065 f = t3 ^ t8;
2066 t10 = a | d;
2067 t11 = t1 ^ t7;
2068 e = t10 ^ t11;
2069 t13 = a ^ c;
2070 t14 = b & t10;
2071 t15 = t4 | t13;
2072 g = t14 ^ t15
2073 e ^= key[4 * 29 + 8]
2074 f ^= key[4 * 29 + 9]
2075 g ^= key[4 * 29 + 10]
2076 h ^= key[4 * 29 + 11]
2077 g = rotr32(g, 22)
2078 e = rotr32(e, 5)
2079 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2080 e ^= f ^ h
2081 h = rotr32(h, 7)
2082 f = rotr32(f, 1)
2083 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2084 f ^= e ^ g
2085 g = rotr32(g, 3)
2086 e = rotr32(e, 13)
2087 t1 = g ^ h;
2088 t2 = g | h;
2089 t3 = f ^ t2;
2090 t4 = e & t3;
2091 b = t1 ^ t4;
2092 t6 = e ^ h;
2093 t7 = f | h;
2094 t8 = t6 & t7;
2095 d = t3 ^ t8;
2096 t10 = (~e) % 0x100000000;
2097 t11 = g ^ d;
2098 t12 = t10 | t11;
2099 a = t3 ^ t12;
2100 t14 = g | t4;
2101 t15 = t7 ^ t14;
2102 t16 = d | t10;
2103 c = t15 ^ t16
2104 a ^= key[4 * 28 + 8]
2105 b ^= key[4 * 28 + 9]
2106 c ^= key[4 * 28 + 10]
2107 d ^= key[4 * 28 + 11]
2108 c = rotr32(c, 22)
2109 a = rotr32(a, 5)
2110 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2111 a ^= b ^ d
2112 d = rotr32(d, 7)
2113 b = rotr32(b, 1)
2114 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2115 b ^= a ^ c
2116 c = rotr32(c, 3)
2117 a = rotr32(a, 13)
2118 t1 = b ^ c;
2119 t2 = b | c;
2120 t3 = a ^ c;
2121 t7 = a ^ d;
2122 t4 = t2 ^ t3;
2123 t5 = d | t4;
2124 t9 = t2 ^ t7;
2125 e = t1 ^ t5;
2126 t8 = t1 | t5;
2127 t11 = a & t4;
2128 g = t8 ^ t9;
2129 t12 = e | t9;
2130 f = t11 ^ t12;
2131 t14 = a & g;
2132 t15 = t2 ^ t14;
2133 t16 = e & t15;
2134 h = t4 ^ t16
2135 e ^= key[4 * 27 + 8]
2136 f ^= key[4 * 27 + 9]
2137 g ^= key[4 * 27 + 10]
2138 h ^= key[4 * 27 + 11]
2139 g = rotr32(g, 22)
2140 e = rotr32(e, 5)
2141 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2142 e ^= f ^ h
2143 h = rotr32(h, 7)
2144 f = rotr32(f, 1)
2145 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2146 f ^= e ^ g
2147 g = rotr32(g, 3)
2148 e = rotr32(e, 13)
2149 t1 = f ^ h;
2150 t2 = (~t1) % 0x100000000;
2151 t3 = e ^ g;
2152 t4 = g ^ t1;
2153 t7 = e | t2;
2154 t5 = f & t4;
2155 t8 = h ^ t7;
2156 t11 = (~t4) % 0x100000000;
2157 a = t3 ^ t5;
2158 t9 = t3 | t8;
2159 t14 = h & t11;
2160 d = t1 ^ t9;
2161 t12 = a | d;
2162 b = t11 ^ t12;
2163 t15 = t3 ^ t12;
2164 c = t14 ^ t15
2165 a ^= key[4 * 26 + 8]
2166 b ^= key[4 * 26 + 9]
2167 c ^= key[4 * 26 + 10]
2168 d ^= key[4 * 26 + 11]
2169 c = rotr32(c, 22)
2170 a = rotr32(a, 5)
2171 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2172 a ^= b ^ d
2173 d = rotr32(d, 7)
2174 b = rotr32(b, 1)
2175 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2176 b ^= a ^ c
2177 c = rotr32(c, 3)
2178 a = rotr32(a, 13)
2179 t1 = a ^ d;
2180 t2 = a & b;
2181 t3 = b ^ c;
2182 t4 = a ^ t3;
2183 t5 = b | d;
2184 t7 = c | t1;
2185 h = t4 ^ t5;
2186 t8 = b ^ t7;
2187 t11 = (~t2) % 0x100000000;
2188 t9 = t4 & t8;
2189 f = t1 ^ t9;
2190 t13 = t9 ^ t11;
2191 t12 = h & f;
2192 g = t12 ^ t13;
2193 t15 = a & d;
2194 t16 = c ^ t13;
2195 e = t15 ^ t16
2196 e ^= key[4 * 25 + 8]
2197 f ^= key[4 * 25 + 9]
2198 g ^= key[4 * 25 + 10]
2199 h ^= key[4 * 25 + 11]
2200 g = rotr32(g, 22)
2201 e = rotr32(e, 5)
2202 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2203 e ^= f ^ h
2204 h = rotr32(h, 7)
2205 f = rotr32(f, 1)
2206 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2207 f ^= e ^ g
2208 g = rotr32(g, 3)
2209 e = rotr32(e, 13)
2210 t1 = (~e) % 0x100000000
2211 t2 = e ^ f
2212 t3 = t1 | t2
2213 t4 = h ^ t3
2214 t7 = h & t2
2215 t5 = g ^ t4
2216 t8 = t1 ^ t7
2217 c = t2 ^ t5
2218 t11 = e & t4
2219 t9 = c & t8
2220 t14 = t5 ^ t8
2221 b = t4 ^ t9
2222 t12 = t5 | b
2223 d = t11 ^ t12
2224 a = d ^ t14
2225 a ^= key[4 * 24 + 8]
2226 b ^= key[4 * 24 + 9]
2227 c ^= key[4 * 24 + 10]
2228 d ^= key[4 * 24 + 11]
2229 c = rotr32(c, 22)
2230 a = rotr32(a, 5)
2231 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2232 a ^= b ^ d
2233 d = rotr32(d, 7)
2234 b = rotr32(b, 1)
2235 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2236 b ^= a ^ c
2237 c = rotr32(c, 3)
2238 a = rotr32(a, 13)
2239 t1 = a & b;
2240 t2 = a | b;
2241 t3 = c | t1;
2242 t4 = d & t2;
2243 h = t3 ^ t4;
2244 t6 = (~d) % 0x100000000;
2245 t7 = b ^ t4;
2246 t8 = h ^ t6;
2247 t11 = c ^ t7;
2248 t9 = t7 | t8;
2249 f = a ^ t9;
2250 t12 = d | f;
2251 e = t11 ^ t12;
2252 t14 = a & h;
2253 t15 = t3 ^ f;
2254 t16 = e ^ t14;
2255 g = t15 ^ t16
2256 e ^= key[4 * 23 + 8]
2257 f ^= key[4 * 23 + 9]
2258 g ^= key[4 * 23 + 10]
2259 h ^= key[4 * 23 + 11]
2260 g = rotr32(g, 22)
2261 e = rotr32(e, 5)
2262 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2263 e ^= f ^ h
2264 h = rotr32(h, 7)
2265 f = rotr32(f, 1)
2266 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2267 f ^= e ^ g
2268 g = rotr32(g, 3)
2269 e = rotr32(e, 13)
2270 t1 = (~e) % 0x100000000;
2271 t2 = e ^ f;
2272 t3 = g ^ t2;
2273 t4 = g | t1;
2274 t5 = h ^ t4;
2275 t13 = h & t1;
2276 b = t3 ^ t5;
2277 t7 = t3 & t5;
2278 t8 = t2 ^ t7;
2279 t9 = f | t8;
2280 d = t5 ^ t9;
2281 t11 = f | d;
2282 a = t8 ^ t11;
2283 t14 = t3 ^ t11;
2284 c = t13 ^ t14
2285 a ^= key[4 * 22 + 8]
2286 b ^= key[4 * 22 + 9]
2287 c ^= key[4 * 22 + 10]
2288 d ^= key[4 * 22 + 11]
2289 c = rotr32(c, 22)
2290 a = rotr32(a, 5)
2291 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2292 a ^= b ^ d
2293 d = rotr32(d, 7)
2294 b = rotr32(b, 1)
2295 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2296 b ^= a ^ c
2297 c = rotr32(c, 3)
2298 a = rotr32(a, 13)
2299 t1 = (~c) % 0x100000000;
2300 t2 = b & t1;
2301 t3 = d ^ t2;
2302 t4 = a & t3;
2303 t5 = b ^ t1;
2304 h = t4 ^ t5;
2305 t7 = b | h;
2306 t8 = a & t7;
2307 f = t3 ^ t8;
2308 t10 = a | d;
2309 t11 = t1 ^ t7;
2310 e = t10 ^ t11;
2311 t13 = a ^ c;
2312 t14 = b & t10;
2313 t15 = t4 | t13;
2314 g = t14 ^ t15
2315 e ^= key[4 * 21 + 8]
2316 f ^= key[4 * 21 + 9]
2317 g ^= key[4 * 21 + 10]
2318 h ^= key[4 * 21 + 11]
2319 g = rotr32(g, 22)
2320 e = rotr32(e, 5)
2321 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2322 e ^= f ^ h
2323 h = rotr32(h, 7)
2324 f = rotr32(f, 1)
2325 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2326 f ^= e ^ g
2327 g = rotr32(g, 3)
2328 e = rotr32(e, 13)
2329 t1 = g ^ h;
2330 t2 = g | h;
2331 t3 = f ^ t2;
2332 t4 = e & t3;
2333 b = t1 ^ t4;
2334 t6 = e ^ h;
2335 t7 = f | h;
2336 t8 = t6 & t7;
2337 d = t3 ^ t8;
2338 t10 = (~e) % 0x100000000;
2339 t11 = g ^ d;
2340 t12 = t10 | t11;
2341 a = t3 ^ t12;
2342 t14 = g | t4;
2343 t15 = t7 ^ t14;
2344 t16 = d | t10;
2345 c = t15 ^ t16
2346 a ^= key[4 * 20 + 8]
2347 b ^= key[4 * 20 + 9]
2348 c ^= key[4 * 20 + 10]
2349 d ^= key[4 * 20 + 11]
2350 c = rotr32(c, 22)
2351 a = rotr32(a, 5)
2352 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2353 a ^= b ^ d
2354 d = rotr32(d, 7)
2355 b = rotr32(b, 1)
2356 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2357 b ^= a ^ c
2358 c = rotr32(c, 3)
2359 a = rotr32(a, 13)
2360 t1 = b ^ c;
2361 t2 = b | c;
2362 t3 = a ^ c;
2363 t7 = a ^ d;
2364 t4 = t2 ^ t3;
2365 t5 = d | t4;
2366 t9 = t2 ^ t7;
2367 e = t1 ^ t5;
2368 t8 = t1 | t5;
2369 t11 = a & t4;
2370 g = t8 ^ t9;
2371 t12 = e | t9;
2372 f = t11 ^ t12;
2373 t14 = a & g;
2374 t15 = t2 ^ t14;
2375 t16 = e & t15;
2376 h = t4 ^ t16
2377 e ^= key[4 * 19 + 8]
2378 f ^= key[4 * 19 + 9]
2379 g ^= key[4 * 19 + 10]
2380 h ^= key[4 * 19 + 11]
2381 g = rotr32(g, 22)
2382 e = rotr32(e, 5)
2383 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2384 e ^= f ^ h
2385 h = rotr32(h, 7)
2386 f = rotr32(f, 1)
2387 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2388 f ^= e ^ g
2389 g = rotr32(g, 3)
2390 e = rotr32(e, 13)
2391 t1 = f ^ h;
2392 t2 = (~t1) % 0x100000000;
2393 t3 = e ^ g;
2394 t4 = g ^ t1;
2395 t7 = e | t2;
2396 t5 = f & t4;
2397 t8 = h ^ t7;
2398 t11 = (~t4) % 0x100000000;
2399 a = t3 ^ t5;
2400 t9 = t3 | t8;
2401 t14 = h & t11;
2402 d = t1 ^ t9;
2403 t12 = a | d;
2404 b = t11 ^ t12;
2405 t15 = t3 ^ t12;
2406 c = t14 ^ t15
2407 a ^= key[4 * 18 + 8]
2408 b ^= key[4 * 18 + 9]
2409 c ^= key[4 * 18 + 10]
2410 d ^= key[4 * 18 + 11]
2411 c = rotr32(c, 22)
2412 a = rotr32(a, 5)
2413 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2414 a ^= b ^ d
2415 d = rotr32(d, 7)
2416 b = rotr32(b, 1)
2417 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2418 b ^= a ^ c
2419 c = rotr32(c, 3)
2420 a = rotr32(a, 13)
2421 t1 = a ^ d;
2422 t2 = a & b;
2423 t3 = b ^ c;
2424 t4 = a ^ t3;
2425 t5 = b | d;
2426 t7 = c | t1;
2427 h = t4 ^ t5;
2428 t8 = b ^ t7;
2429 t11 = (~t2) % 0x100000000;
2430 t9 = t4 & t8;
2431 f = t1 ^ t9;
2432 t13 = t9 ^ t11;
2433 t12 = h & f;
2434 g = t12 ^ t13;
2435 t15 = a & d;
2436 t16 = c ^ t13;
2437 e = t15 ^ t16
2438 e ^= key[4 * 17 + 8]
2439 f ^= key[4 * 17 + 9]
2440 g ^= key[4 * 17 + 10]
2441 h ^= key[4 * 17 + 11]
2442 g = rotr32(g, 22)
2443 e = rotr32(e, 5)
2444 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2445 e ^= f ^ h
2446 h = rotr32(h, 7)
2447 f = rotr32(f, 1)
2448 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2449 f ^= e ^ g
2450 g = rotr32(g, 3)
2451 e = rotr32(e, 13)
2452 t1 = (~e) % 0x100000000
2453 t2 = e ^ f
2454 t3 = t1 | t2
2455 t4 = h ^ t3
2456 t7 = h & t2
2457 t5 = g ^ t4
2458 t8 = t1 ^ t7
2459 c = t2 ^ t5
2460 t11 = e & t4
2461 t9 = c & t8
2462 t14 = t5 ^ t8
2463 b = t4 ^ t9
2464 t12 = t5 | b
2465 d = t11 ^ t12
2466 a = d ^ t14
2467 a ^= key[4 * 16 + 8]
2468 b ^= key[4 * 16 + 9]
2469 c ^= key[4 * 16 + 10]
2470 d ^= key[4 * 16 + 11]
2471 c = rotr32(c, 22)
2472 a = rotr32(a, 5)
2473 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2474 a ^= b ^ d
2475 d = rotr32(d, 7)
2476 b = rotr32(b, 1)
2477 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2478 b ^= a ^ c
2479 c = rotr32(c, 3)
2480 a = rotr32(a, 13)
2481 t1 = a & b;
2482 t2 = a | b;
2483 t3 = c | t1;
2484 t4 = d & t2;
2485 h = t3 ^ t4;
2486 t6 = (~d) % 0x100000000;
2487 t7 = b ^ t4;
2488 t8 = h ^ t6;
2489 t11 = c ^ t7;
2490 t9 = t7 | t8;
2491 f = a ^ t9;
2492 t12 = d | f;
2493 e = t11 ^ t12;
2494 t14 = a & h;
2495 t15 = t3 ^ f;
2496 t16 = e ^ t14;
2497 g = t15 ^ t16
2498 e ^= key[4 * 15 + 8]
2499 f ^= key[4 * 15 + 9]
2500 g ^= key[4 * 15 + 10]
2501 h ^= key[4 * 15 + 11]
2502 g = rotr32(g, 22)
2503 e = rotr32(e, 5)
2504 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2505 e ^= f ^ h
2506 h = rotr32(h, 7)
2507 f = rotr32(f, 1)
2508 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2509 f ^= e ^ g
2510 g = rotr32(g, 3)
2511 e = rotr32(e, 13)
2512 t1 = (~e) % 0x100000000;
2513 t2 = e ^ f;
2514 t3 = g ^ t2;
2515 t4 = g | t1;
2516 t5 = h ^ t4;
2517 t13 = h & t1;
2518 b = t3 ^ t5;
2519 t7 = t3 & t5;
2520 t8 = t2 ^ t7;
2521 t9 = f | t8;
2522 d = t5 ^ t9;
2523 t11 = f | d;
2524 a = t8 ^ t11;
2525 t14 = t3 ^ t11;
2526 c = t13 ^ t14
2527 a ^= key[4 * 14 + 8]
2528 b ^= key[4 * 14 + 9]
2529 c ^= key[4 * 14 + 10]
2530 d ^= key[4 * 14 + 11]
2531 c = rotr32(c, 22)
2532 a = rotr32(a, 5)
2533 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2534 a ^= b ^ d
2535 d = rotr32(d, 7)
2536 b = rotr32(b, 1)
2537 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2538 b ^= a ^ c
2539 c = rotr32(c, 3)
2540 a = rotr32(a, 13)
2541 t1 = (~c) % 0x100000000;
2542 t2 = b & t1;
2543 t3 = d ^ t2;
2544 t4 = a & t3;
2545 t5 = b ^ t1;
2546 h = t4 ^ t5;
2547 t7 = b | h;
2548 t8 = a & t7;
2549 f = t3 ^ t8;
2550 t10 = a | d;
2551 t11 = t1 ^ t7;
2552 e = t10 ^ t11;
2553 t13 = a ^ c;
2554 t14 = b & t10;
2555 t15 = t4 | t13;
2556 g = t14 ^ t15
2557 e ^= key[4 * 13 + 8]
2558 f ^= key[4 * 13 + 9]
2559 g ^= key[4 * 13 + 10]
2560 h ^= key[4 * 13 + 11]
2561 g = rotr32(g, 22)
2562 e = rotr32(e, 5)
2563 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2564 e ^= f ^ h
2565 h = rotr32(h, 7)
2566 f = rotr32(f, 1)
2567 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2568 f ^= e ^ g
2569 g = rotr32(g, 3)
2570 e = rotr32(e, 13)
2571 t1 = g ^ h;
2572 t2 = g | h;
2573 t3 = f ^ t2;
2574 t4 = e & t3;
2575 b = t1 ^ t4;
2576 t6 = e ^ h;
2577 t7 = f | h;
2578 t8 = t6 & t7;
2579 d = t3 ^ t8;
2580 t10 = (~e) % 0x100000000;
2581 t11 = g ^ d;
2582 t12 = t10 | t11;
2583 a = t3 ^ t12;
2584 t14 = g | t4;
2585 t15 = t7 ^ t14;
2586 t16 = d | t10;
2587 c = t15 ^ t16
2588 a ^= key[4 * 12 + 8]
2589 b ^= key[4 * 12 + 9]
2590 c ^= key[4 * 12 + 10]
2591 d ^= key[4 * 12 + 11]
2592 c = rotr32(c, 22)
2593 a = rotr32(a, 5)
2594 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2595 a ^= b ^ d
2596 d = rotr32(d, 7)
2597 b = rotr32(b, 1)
2598 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2599 b ^= a ^ c
2600 c = rotr32(c, 3)
2601 a = rotr32(a, 13)
2602 t1 = b ^ c;
2603 t2 = b | c;
2604 t3 = a ^ c;
2605 t7 = a ^ d;
2606 t4 = t2 ^ t3;
2607 t5 = d | t4;
2608 t9 = t2 ^ t7;
2609 e = t1 ^ t5;
2610 t8 = t1 | t5;
2611 t11 = a & t4;
2612 g = t8 ^ t9;
2613 t12 = e | t9;
2614 f = t11 ^ t12;
2615 t14 = a & g;
2616 t15 = t2 ^ t14;
2617 t16 = e & t15;
2618 h = t4 ^ t16
2619 e ^= key[4 * 11 + 8]
2620 f ^= key[4 * 11 + 9]
2621 g ^= key[4 * 11 + 10]
2622 h ^= key[4 * 11 + 11]
2623 g = rotr32(g, 22)
2624 e = rotr32(e, 5)
2625 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2626 e ^= f ^ h
2627 h = rotr32(h, 7)
2628 f = rotr32(f, 1)
2629 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2630 f ^= e ^ g
2631 g = rotr32(g, 3)
2632 e = rotr32(e, 13)
2633 t1 = f ^ h;
2634 t2 = (~t1) % 0x100000000;
2635 t3 = e ^ g;
2636 t4 = g ^ t1;
2637 t7 = e | t2;
2638 t5 = f & t4;
2639 t8 = h ^ t7;
2640 t11 = (~t4) % 0x100000000;
2641 a = t3 ^ t5;
2642 t9 = t3 | t8;
2643 t14 = h & t11;
2644 d = t1 ^ t9;
2645 t12 = a | d;
2646 b = t11 ^ t12;
2647 t15 = t3 ^ t12;
2648 c = t14 ^ t15
2649 a ^= key[4 * 10 + 8]
2650 b ^= key[4 * 10 + 9]
2651 c ^= key[4 * 10 + 10]
2652 d ^= key[4 * 10 + 11]
2653 c = rotr32(c, 22)
2654 a = rotr32(a, 5)
2655 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2656 a ^= b ^ d
2657 d = rotr32(d, 7)
2658 b = rotr32(b, 1)
2659 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2660 b ^= a ^ c
2661 c = rotr32(c, 3)
2662 a = rotr32(a, 13)
2663 t1 = a ^ d;
2664 t2 = a & b;
2665 t3 = b ^ c;
2666 t4 = a ^ t3;
2667 t5 = b | d;
2668 t7 = c | t1;
2669 h = t4 ^ t5;
2670 t8 = b ^ t7;
2671 t11 = (~t2) % 0x100000000;
2672 t9 = t4 & t8;
2673 f = t1 ^ t9;
2674 t13 = t9 ^ t11;
2675 t12 = h & f;
2676 g = t12 ^ t13;
2677 t15 = a & d;
2678 t16 = c ^ t13;
2679 e = t15 ^ t16
2680 e ^= key[4 * 9 + 8]
2681 f ^= key[4 * 9 + 9]
2682 g ^= key[4 * 9 + 10]
2683 h ^= key[4 * 9 + 11]
2684 g = rotr32(g, 22)
2685 e = rotr32(e, 5)
2686 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2687 e ^= f ^ h
2688 h = rotr32(h, 7)
2689 f = rotr32(f, 1)
2690 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2691 f ^= e ^ g
2692 g = rotr32(g, 3)
2693 e = rotr32(e, 13)
2694 t1 = (~e) % 0x100000000
2695 t2 = e ^ f
2696 t3 = t1 | t2
2697 t4 = h ^ t3
2698 t7 = h & t2
2699 t5 = g ^ t4
2700 t8 = t1 ^ t7
2701 c = t2 ^ t5
2702 t11 = e & t4
2703 t9 = c & t8
2704 t14 = t5 ^ t8
2705 b = t4 ^ t9
2706 t12 = t5 | b
2707 d = t11 ^ t12
2708 a = d ^ t14
2709 a ^= key[4 * 8 + 8]
2710 b ^= key[4 * 8 + 9]
2711 c ^= key[4 * 8 + 10]
2712 d ^= key[4 * 8 + 11]
2713 c = rotr32(c, 22)
2714 a = rotr32(a, 5)
2715 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2716 a ^= b ^ d
2717 d = rotr32(d, 7)
2718 b = rotr32(b, 1)
2719 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2720 b ^= a ^ c
2721 c = rotr32(c, 3)
2722 a = rotr32(a, 13)
2723 t1 = a & b;
2724 t2 = a | b;
2725 t3 = c | t1;
2726 t4 = d & t2;
2727 h = t3 ^ t4;
2728 t6 = (~d) % 0x100000000;
2729 t7 = b ^ t4;
2730 t8 = h ^ t6;
2731 t11 = c ^ t7;
2732 t9 = t7 | t8;
2733 f = a ^ t9;
2734 t12 = d | f;
2735 e = t11 ^ t12;
2736 t14 = a & h;
2737 t15 = t3 ^ f;
2738 t16 = e ^ t14;
2739 g = t15 ^ t16
2740 e ^= key[4 * 7 + 8]
2741 f ^= key[4 * 7 + 9]
2742 g ^= key[4 * 7 + 10]
2743 h ^= key[4 * 7 + 11]
2744 g = rotr32(g, 22)
2745 e = rotr32(e, 5)
2746 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2747 e ^= f ^ h
2748 h = rotr32(h, 7)
2749 f = rotr32(f, 1)
2750 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2751 f ^= e ^ g
2752 g = rotr32(g, 3)
2753 e = rotr32(e, 13)
2754 t1 = (~e) % 0x100000000;
2755 t2 = e ^ f;
2756 t3 = g ^ t2;
2757 t4 = g | t1;
2758 t5 = h ^ t4;
2759 t13 = h & t1;
2760 b = t3 ^ t5;
2761 t7 = t3 & t5;
2762 t8 = t2 ^ t7;
2763 t9 = f | t8;
2764 d = t5 ^ t9;
2765 t11 = f | d;
2766 a = t8 ^ t11;
2767 t14 = t3 ^ t11;
2768 c = t13 ^ t14
2769 a ^= key[4 * 6 + 8]
2770 b ^= key[4 * 6 + 9]
2771 c ^= key[4 * 6 + 10]
2772 d ^= key[4 * 6 + 11]
2773 c = rotr32(c, 22)
2774 a = rotr32(a, 5)
2775 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2776 a ^= b ^ d
2777 d = rotr32(d, 7)
2778 b = rotr32(b, 1)
2779 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2780 b ^= a ^ c
2781 c = rotr32(c, 3)
2782 a = rotr32(a, 13)
2783 t1 = (~c) % 0x100000000;
2784 t2 = b & t1;
2785 t3 = d ^ t2;
2786 t4 = a & t3;
2787 t5 = b ^ t1;
2788 h = t4 ^ t5;
2789 t7 = b | h;
2790 t8 = a & t7;
2791 f = t3 ^ t8;
2792 t10 = a | d;
2793 t11 = t1 ^ t7;
2794 e = t10 ^ t11;
2795 t13 = a ^ c;
2796 t14 = b & t10;
2797 t15 = t4 | t13;
2798 g = t14 ^ t15
2799 e ^= key[4 * 5 + 8]
2800 f ^= key[4 * 5 + 9]
2801 g ^= key[4 * 5 + 10]
2802 h ^= key[4 * 5 + 11]
2803 g = rotr32(g, 22)
2804 e = rotr32(e, 5)
2805 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2806 e ^= f ^ h
2807 h = rotr32(h, 7)
2808 f = rotr32(f, 1)
2809 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2810 f ^= e ^ g
2811 g = rotr32(g, 3)
2812 e = rotr32(e, 13)
2813 t1 = g ^ h;
2814 t2 = g | h;
2815 t3 = f ^ t2;
2816 t4 = e & t3;
2817 b = t1 ^ t4;
2818 t6 = e ^ h;
2819 t7 = f | h;
2820 t8 = t6 & t7;
2821 d = t3 ^ t8;
2822 t10 = (~e) % 0x100000000;
2823 t11 = g ^ d;
2824 t12 = t10 | t11;
2825 a = t3 ^ t12;
2826 t14 = g | t4;
2827 t15 = t7 ^ t14;
2828 t16 = d | t10;
2829 c = t15 ^ t16
2830 a ^= key[4 * 4 + 8]
2831 b ^= key[4 * 4 + 9]
2832 c ^= key[4 * 4 + 10]
2833 d ^= key[4 * 4 + 11]
2834 c = rotr32(c, 22)
2835 a = rotr32(a, 5)
2836 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2837 a ^= b ^ d
2838 d = rotr32(d, 7)
2839 b = rotr32(b, 1)
2840 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2841 b ^= a ^ c
2842 c = rotr32(c, 3)
2843 a = rotr32(a, 13)
2844 t1 = b ^ c;
2845 t2 = b | c;
2846 t3 = a ^ c;
2847 t7 = a ^ d;
2848 t4 = t2 ^ t3;
2849 t5 = d | t4;
2850 t9 = t2 ^ t7;
2851 e = t1 ^ t5;
2852 t8 = t1 | t5;
2853 t11 = a & t4;
2854 g = t8 ^ t9;
2855 t12 = e | t9;
2856 f = t11 ^ t12;
2857 t14 = a & g;
2858 t15 = t2 ^ t14;
2859 t16 = e & t15;
2860 h = t4 ^ t16
2861 e ^= key[4 * 3 + 8]
2862 f ^= key[4 * 3 + 9]
2863 g ^= key[4 * 3 + 10]
2864 h ^= key[4 * 3 + 11]
2865 g = rotr32(g, 22)
2866 e = rotr32(e, 5)
2867 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2868 e ^= f ^ h
2869 h = rotr32(h, 7)
2870 f = rotr32(f, 1)
2871 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2872 f ^= e ^ g
2873 g = rotr32(g, 3)
2874 e = rotr32(e, 13)
2875 t1 = f ^ h;
2876 t2 = (~t1) % 0x100000000;
2877 t3 = e ^ g;
2878 t4 = g ^ t1;
2879 t7 = e | t2;
2880 t5 = f & t4;
2881 t8 = h ^ t7;
2882 t11 = (~t4) % 0x100000000;
2883 a = t3 ^ t5;
2884 t9 = t3 | t8;
2885 t14 = h & t11;
2886 d = t1 ^ t9;
2887 t12 = a | d;
2888 b = t11 ^ t12;
2889 t15 = t3 ^ t12;
2890 c = t14 ^ t15
2891 a ^= key[4 * 2 + 8]
2892 b ^= key[4 * 2 + 9]
2893 c ^= key[4 * 2 + 10]
2894 d ^= key[4 * 2 + 11]
2895 c = rotr32(c, 22)
2896 a = rotr32(a, 5)
2897 c ^= d ^ ((b << 7) & 0xFFFFFFFF)
2898 a ^= b ^ d
2899 d = rotr32(d, 7)
2900 b = rotr32(b, 1)
2901 d ^= c ^ ((a << 3) & 0xFFFFFFFF)
2902 b ^= a ^ c
2903 c = rotr32(c, 3)
2904 a = rotr32(a, 13)
2905 t1 = a ^ d;
2906 t2 = a & b;
2907 t3 = b ^ c;
2908 t4 = a ^ t3;
2909 t5 = b | d;
2910 t7 = c | t1;
2911 h = t4 ^ t5;
2912 t8 = b ^ t7;
2913 t11 = (~t2) % 0x100000000;
2914 t9 = t4 & t8;
2915 f = t1 ^ t9;
2916 t13 = t9 ^ t11;
2917 t12 = h & f;
2918 g = t12 ^ t13;
2919 t15 = a & d;
2920 t16 = c ^ t13;
2921 e = t15 ^ t16
2922 e ^= key[4 * 1 + 8]
2923 f ^= key[4 * 1 + 9]
2924 g ^= key[4 * 1 + 10]
2925 h ^= key[4 * 1 + 11]
2926 g = rotr32(g, 22)
2927 e = rotr32(e, 5)
2928 g ^= h ^ ((f << 7) & 0xFFFFFFFF)
2929 e ^= f ^ h
2930 h = rotr32(h, 7)
2931 f = rotr32(f, 1)
2932 h ^= g ^ ((e << 3) & 0xFFFFFFFF)
2933 f ^= e ^ g
2934 g = rotr32(g, 3)
2935 e = rotr32(e, 13)
2936 t1 = (~e) % 0x100000000
2937 t2 = e ^ f
2938 t3 = t1 | t2
2939 t4 = h ^ t3
2940 t7 = h & t2
2941 t5 = g ^ t4
2942 t8 = t1 ^ t7
2943 c = t2 ^ t5
2944 t11 = e & t4
2945 t9 = c & t8
2946 t14 = t5 ^ t8
2947 b = t4 ^ t9
2948 t12 = t5 | b
2949 d = t11 ^ t12
2950 a = d ^ t14
2951 a ^= key[4 * 0 + 8]
2952 b ^= key[4 * 0 + 9]
2953 c ^= key[4 * 0 + 10]
2954 d ^= key[4 * 0 + 11]
2955 if WORD_BIGENDIAN:
2956 a = byteswap32(a)
2957 b = byteswap32(b)
2958 c = byteswap32(c)
2959 d = byteswap32(d)
2960 in_blk[0] = a
2961 in_blk[1] = b
2962 in_blk[2] = c
2963 in_blk[3] = d
2965 __testkey = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
2966 __testdat = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
2967 assert '\xde&\x9f\xf83\xe42\xb8[.\x88\xd2p\x1c\xe7\\' == Serpent(__testkey).encrypt(__testdat)
2968 assert __testdat == Serpent(__testkey).decrypt('\xde&\x9f\xf83\xe42\xb8[.\x88\xd2p\x1c\xe7\\')