More changes.
[libgcrypt.git] / cipher / rijndael.c
1 /* Rijndael (AES) for GnuPG
2  *      Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3  *
4  * This file is part of Libgcrypt.
5  *
6  * Libgcrypt is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as
8  * published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * Libgcrypt is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19  *******************************************************************
20  * The code here is based on the optimized implementation taken from
21  * http://www.esat.kuleuven.ac.be/~rijmen/rijndael/ on Oct 2, 2000,
22  * which carries this notice:
23  *------------------------------------------
24  * rijndael-alg-fst.c   v2.3   April '2000
25  *
26  * Optimised ANSI C code
27  *
28  * authors: v1.0: Antoon Bosselaers
29  *          v2.0: Vincent Rijmen
30  *          v2.3: Paulo Barreto
31  *
32  * This code is placed in the public domain.
33  *------------------------------------------
34  */
35 \f
36 #include <config.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h> /* for memcmp() */
40
41 #include "types.h"  /* for byte and u32 typedefs */
42 #include "g10lib.h"
43 #include "cipher.h"
44
45 #define MAXKC                   (256/32)
46 #define MAXROUNDS               14
47
48
49 static const char *selftest(void);
50
51 typedef struct 
52 {
53   int   ROUNDS;                   /* key-length-dependent number of rounds */
54   int decryption_prepared;
55   union 
56   {
57     PROPERLY_ALIGNED_TYPE dummy;
58     byte keyschedule[MAXROUNDS+1][4][4];
59   } u1;
60   union
61   {
62     PROPERLY_ALIGNED_TYPE dummy;
63     byte keyschedule[MAXROUNDS+1][4][4];        
64   } u2;
65 } RIJNDAEL_context;
66
67 #define keySched  u1.keyschedule
68 #define keySched2 u2.keyschedule
69
70
71 static const byte S[256] = {
72     99, 124, 119, 123, 242, 107, 111, 197,
73     48,   1, 103,  43, 254, 215, 171, 118, 
74     202, 130, 201, 125, 250,  89,  71, 240,
75     173, 212, 162, 175, 156, 164, 114, 192, 
76     183, 253, 147,  38,  54,  63, 247, 204,
77     52, 165, 229, 241, 113, 216,  49,  21, 
78     4, 199,  35, 195,  24, 150,   5, 154,
79     7,  18, 128, 226, 235,  39, 178, 117, 
80     9, 131,  44,  26,  27, 110,  90, 160, 
81     82,  59, 214, 179,  41, 227,  47, 132, 
82     83, 209,   0, 237,  32, 252, 177,  91,
83     106, 203, 190,  57,  74,  76,  88, 207, 
84     208, 239, 170, 251,  67,  77,  51, 133,
85     69, 249,   2, 127,  80,  60, 159, 168, 
86     81, 163,  64, 143, 146, 157,  56, 245,
87     188, 182, 218,  33,  16, 255, 243, 210, 
88     205,  12,  19, 236,  95, 151,  68,  23,
89     196, 167, 126,  61, 100,  93,  25, 115, 
90     96, 129,  79, 220,  34,  42, 144, 136,
91     70, 238, 184,  20, 222,  94,  11, 219, 
92     224,  50,  58,  10,  73,   6,  36,  92,
93     194, 211, 172,  98, 145, 149, 228, 121, 
94     231, 200,  55, 109, 141, 213,  78, 169, 
95     108,  86, 244, 234, 101, 122, 174,   8, 
96     186, 120,  37,  46,  28, 166, 180, 198, 
97     232, 221, 116,  31,  75, 189, 139, 138, 
98     112,  62, 181, 102,  72,   3, 246,  14,
99     97,  53,  87, 185, 134, 193,  29, 158, 
100     225, 248, 152,  17, 105, 217, 142, 148,
101     155,  30, 135, 233, 206,  85,  40, 223, 
102     140, 161, 137,  13, 191, 230,  66, 104, 
103     65, 153,  45,  15, 176,  84, 187,  22
104 };
105
106
107 static const byte T1[256][4] = {
108     { 0xc6,0x63,0x63,0xa5 }, { 0xf8,0x7c,0x7c,0x84 },
109     { 0xee,0x77,0x77,0x99 }, { 0xf6,0x7b,0x7b,0x8d }, 
110     { 0xff,0xf2,0xf2,0x0d }, { 0xd6,0x6b,0x6b,0xbd },
111     { 0xde,0x6f,0x6f,0xb1 }, { 0x91,0xc5,0xc5,0x54 }, 
112     { 0x60,0x30,0x30,0x50 }, { 0x02,0x01,0x01,0x03 },
113     { 0xce,0x67,0x67,0xa9 }, { 0x56,0x2b,0x2b,0x7d }, 
114     { 0xe7,0xfe,0xfe,0x19 }, { 0xb5,0xd7,0xd7,0x62 },
115     { 0x4d,0xab,0xab,0xe6 }, { 0xec,0x76,0x76,0x9a }, 
116     { 0x8f,0xca,0xca,0x45 }, { 0x1f,0x82,0x82,0x9d },
117     { 0x89,0xc9,0xc9,0x40 }, { 0xfa,0x7d,0x7d,0x87 }, 
118     { 0xef,0xfa,0xfa,0x15 }, { 0xb2,0x59,0x59,0xeb }, 
119     { 0x8e,0x47,0x47,0xc9 }, { 0xfb,0xf0,0xf0,0x0b }, 
120     { 0x41,0xad,0xad,0xec }, { 0xb3,0xd4,0xd4,0x67 },
121     { 0x5f,0xa2,0xa2,0xfd }, { 0x45,0xaf,0xaf,0xea }, 
122     { 0x23,0x9c,0x9c,0xbf }, { 0x53,0xa4,0xa4,0xf7 },
123     { 0xe4,0x72,0x72,0x96 }, { 0x9b,0xc0,0xc0,0x5b }, 
124     { 0x75,0xb7,0xb7,0xc2 }, { 0xe1,0xfd,0xfd,0x1c },
125     { 0x3d,0x93,0x93,0xae }, { 0x4c,0x26,0x26,0x6a }, 
126     { 0x6c,0x36,0x36,0x5a }, { 0x7e,0x3f,0x3f,0x41 },
127     { 0xf5,0xf7,0xf7,0x02 }, { 0x83,0xcc,0xcc,0x4f }, 
128     { 0x68,0x34,0x34,0x5c }, { 0x51,0xa5,0xa5,0xf4 }, 
129     { 0xd1,0xe5,0xe5,0x34 }, { 0xf9,0xf1,0xf1,0x08 }, 
130     { 0xe2,0x71,0x71,0x93 }, { 0xab,0xd8,0xd8,0x73 },
131     { 0x62,0x31,0x31,0x53 }, { 0x2a,0x15,0x15,0x3f }, 
132     { 0x08,0x04,0x04,0x0c }, { 0x95,0xc7,0xc7,0x52 },
133     { 0x46,0x23,0x23,0x65 }, { 0x9d,0xc3,0xc3,0x5e }, 
134     { 0x30,0x18,0x18,0x28 }, { 0x37,0x96,0x96,0xa1 },
135     { 0x0a,0x05,0x05,0x0f }, { 0x2f,0x9a,0x9a,0xb5 }, 
136     { 0x0e,0x07,0x07,0x09 }, { 0x24,0x12,0x12,0x36 },
137     { 0x1b,0x80,0x80,0x9b }, { 0xdf,0xe2,0xe2,0x3d }, 
138     { 0xcd,0xeb,0xeb,0x26 }, { 0x4e,0x27,0x27,0x69 },
139     { 0x7f,0xb2,0xb2,0xcd }, { 0xea,0x75,0x75,0x9f }, 
140     { 0x12,0x09,0x09,0x1b }, { 0x1d,0x83,0x83,0x9e },
141     { 0x58,0x2c,0x2c,0x74 }, { 0x34,0x1a,0x1a,0x2e }, 
142     { 0x36,0x1b,0x1b,0x2d }, { 0xdc,0x6e,0x6e,0xb2 }, 
143     { 0xb4,0x5a,0x5a,0xee }, { 0x5b,0xa0,0xa0,0xfb }, 
144     { 0xa4,0x52,0x52,0xf6 }, { 0x76,0x3b,0x3b,0x4d },
145     { 0xb7,0xd6,0xd6,0x61 }, { 0x7d,0xb3,0xb3,0xce }, 
146     { 0x52,0x29,0x29,0x7b }, { 0xdd,0xe3,0xe3,0x3e }, 
147     { 0x5e,0x2f,0x2f,0x71 }, { 0x13,0x84,0x84,0x97 }, 
148     { 0xa6,0x53,0x53,0xf5 }, { 0xb9,0xd1,0xd1,0x68 }, 
149     { 0x00,0x00,0x00,0x00 }, { 0xc1,0xed,0xed,0x2c }, 
150     { 0x40,0x20,0x20,0x60 }, { 0xe3,0xfc,0xfc,0x1f },
151     { 0x79,0xb1,0xb1,0xc8 }, { 0xb6,0x5b,0x5b,0xed }, 
152     { 0xd4,0x6a,0x6a,0xbe }, { 0x8d,0xcb,0xcb,0x46 },
153     { 0x67,0xbe,0xbe,0xd9 }, { 0x72,0x39,0x39,0x4b }, 
154     { 0x94,0x4a,0x4a,0xde }, { 0x98,0x4c,0x4c,0xd4 },
155     { 0xb0,0x58,0x58,0xe8 }, { 0x85,0xcf,0xcf,0x4a }, 
156     { 0xbb,0xd0,0xd0,0x6b }, { 0xc5,0xef,0xef,0x2a },
157     { 0x4f,0xaa,0xaa,0xe5 }, { 0xed,0xfb,0xfb,0x16 }, 
158     { 0x86,0x43,0x43,0xc5 }, { 0x9a,0x4d,0x4d,0xd7 },
159     { 0x66,0x33,0x33,0x55 }, { 0x11,0x85,0x85,0x94 }, 
160     { 0x8a,0x45,0x45,0xcf }, { 0xe9,0xf9,0xf9,0x10 },
161     { 0x04,0x02,0x02,0x06 }, { 0xfe,0x7f,0x7f,0x81 }, 
162     { 0xa0,0x50,0x50,0xf0 }, { 0x78,0x3c,0x3c,0x44 },
163     { 0x25,0x9f,0x9f,0xba }, { 0x4b,0xa8,0xa8,0xe3 }, 
164     { 0xa2,0x51,0x51,0xf3 }, { 0x5d,0xa3,0xa3,0xfe },
165     { 0x80,0x40,0x40,0xc0 }, { 0x05,0x8f,0x8f,0x8a }, 
166     { 0x3f,0x92,0x92,0xad }, { 0x21,0x9d,0x9d,0xbc },
167     { 0x70,0x38,0x38,0x48 }, { 0xf1,0xf5,0xf5,0x04 }, 
168     { 0x63,0xbc,0xbc,0xdf }, { 0x77,0xb6,0xb6,0xc1 },
169     { 0xaf,0xda,0xda,0x75 }, { 0x42,0x21,0x21,0x63 }, 
170     { 0x20,0x10,0x10,0x30 }, { 0xe5,0xff,0xff,0x1a },
171     { 0xfd,0xf3,0xf3,0x0e }, { 0xbf,0xd2,0xd2,0x6d }, 
172     { 0x81,0xcd,0xcd,0x4c }, { 0x18,0x0c,0x0c,0x14 },
173     { 0x26,0x13,0x13,0x35 }, { 0xc3,0xec,0xec,0x2f }, 
174     { 0xbe,0x5f,0x5f,0xe1 }, { 0x35,0x97,0x97,0xa2 },
175     { 0x88,0x44,0x44,0xcc }, { 0x2e,0x17,0x17,0x39 }, 
176     { 0x93,0xc4,0xc4,0x57 }, { 0x55,0xa7,0xa7,0xf2 },
177     { 0xfc,0x7e,0x7e,0x82 }, { 0x7a,0x3d,0x3d,0x47 }, 
178     { 0xc8,0x64,0x64,0xac }, { 0xba,0x5d,0x5d,0xe7 },
179     { 0x32,0x19,0x19,0x2b }, { 0xe6,0x73,0x73,0x95 }, 
180     { 0xc0,0x60,0x60,0xa0 }, { 0x19,0x81,0x81,0x98 },
181     { 0x9e,0x4f,0x4f,0xd1 }, { 0xa3,0xdc,0xdc,0x7f }, 
182     { 0x44,0x22,0x22,0x66 }, { 0x54,0x2a,0x2a,0x7e },
183     { 0x3b,0x90,0x90,0xab }, { 0x0b,0x88,0x88,0x83 }, 
184     { 0x8c,0x46,0x46,0xca }, { 0xc7,0xee,0xee,0x29 },
185     { 0x6b,0xb8,0xb8,0xd3 }, { 0x28,0x14,0x14,0x3c }, 
186     { 0xa7,0xde,0xde,0x79 }, { 0xbc,0x5e,0x5e,0xe2 },
187     { 0x16,0x0b,0x0b,0x1d }, { 0xad,0xdb,0xdb,0x76 }, 
188     { 0xdb,0xe0,0xe0,0x3b }, { 0x64,0x32,0x32,0x56 },
189     { 0x74,0x3a,0x3a,0x4e }, { 0x14,0x0a,0x0a,0x1e }, 
190     { 0x92,0x49,0x49,0xdb }, { 0x0c,0x06,0x06,0x0a },
191     { 0x48,0x24,0x24,0x6c }, { 0xb8,0x5c,0x5c,0xe4 }, 
192     { 0x9f,0xc2,0xc2,0x5d }, { 0xbd,0xd3,0xd3,0x6e },
193     { 0x43,0xac,0xac,0xef }, { 0xc4,0x62,0x62,0xa6 }, 
194     { 0x39,0x91,0x91,0xa8 }, { 0x31,0x95,0x95,0xa4 },
195     { 0xd3,0xe4,0xe4,0x37 }, { 0xf2,0x79,0x79,0x8b }, 
196     { 0xd5,0xe7,0xe7,0x32 }, { 0x8b,0xc8,0xc8,0x43 },
197     { 0x6e,0x37,0x37,0x59 }, { 0xda,0x6d,0x6d,0xb7 }, 
198     { 0x01,0x8d,0x8d,0x8c }, { 0xb1,0xd5,0xd5,0x64 },
199     { 0x9c,0x4e,0x4e,0xd2 }, { 0x49,0xa9,0xa9,0xe0 }, 
200     { 0xd8,0x6c,0x6c,0xb4 }, { 0xac,0x56,0x56,0xfa },
201     { 0xf3,0xf4,0xf4,0x07 }, { 0xcf,0xea,0xea,0x25 }, 
202     { 0xca,0x65,0x65,0xaf }, { 0xf4,0x7a,0x7a,0x8e },
203     { 0x47,0xae,0xae,0xe9 }, { 0x10,0x08,0x08,0x18 }, 
204     { 0x6f,0xba,0xba,0xd5 }, { 0xf0,0x78,0x78,0x88 },
205     { 0x4a,0x25,0x25,0x6f }, { 0x5c,0x2e,0x2e,0x72 }, 
206     { 0x38,0x1c,0x1c,0x24 }, { 0x57,0xa6,0xa6,0xf1 },
207     { 0x73,0xb4,0xb4,0xc7 }, { 0x97,0xc6,0xc6,0x51 }, 
208     { 0xcb,0xe8,0xe8,0x23 }, { 0xa1,0xdd,0xdd,0x7c },
209     { 0xe8,0x74,0x74,0x9c }, { 0x3e,0x1f,0x1f,0x21 }, 
210     { 0x96,0x4b,0x4b,0xdd }, { 0x61,0xbd,0xbd,0xdc }, 
211     { 0x0d,0x8b,0x8b,0x86 }, { 0x0f,0x8a,0x8a,0x85 }, 
212     { 0xe0,0x70,0x70,0x90 }, { 0x7c,0x3e,0x3e,0x42 },
213     { 0x71,0xb5,0xb5,0xc4 }, { 0xcc,0x66,0x66,0xaa }, 
214     { 0x90,0x48,0x48,0xd8 }, { 0x06,0x03,0x03,0x05 },
215     { 0xf7,0xf6,0xf6,0x01 }, { 0x1c,0x0e,0x0e,0x12 }, 
216     { 0xc2,0x61,0x61,0xa3 }, { 0x6a,0x35,0x35,0x5f },
217     { 0xae,0x57,0x57,0xf9 }, { 0x69,0xb9,0xb9,0xd0 }, 
218     { 0x17,0x86,0x86,0x91 }, { 0x99,0xc1,0xc1,0x58 },
219     { 0x3a,0x1d,0x1d,0x27 }, { 0x27,0x9e,0x9e,0xb9 }, 
220     { 0xd9,0xe1,0xe1,0x38 }, { 0xeb,0xf8,0xf8,0x13 },
221     { 0x2b,0x98,0x98,0xb3 }, { 0x22,0x11,0x11,0x33 }, 
222     { 0xd2,0x69,0x69,0xbb }, { 0xa9,0xd9,0xd9,0x70 },
223     { 0x07,0x8e,0x8e,0x89 }, { 0x33,0x94,0x94,0xa7 }, 
224     { 0x2d,0x9b,0x9b,0xb6 }, { 0x3c,0x1e,0x1e,0x22 },
225     { 0x15,0x87,0x87,0x92 }, { 0xc9,0xe9,0xe9,0x20 }, 
226     { 0x87,0xce,0xce,0x49 }, { 0xaa,0x55,0x55,0xff },
227     { 0x50,0x28,0x28,0x78 }, { 0xa5,0xdf,0xdf,0x7a }, 
228     { 0x03,0x8c,0x8c,0x8f }, { 0x59,0xa1,0xa1,0xf8 },
229     { 0x09,0x89,0x89,0x80 }, { 0x1a,0x0d,0x0d,0x17 }, 
230     { 0x65,0xbf,0xbf,0xda }, { 0xd7,0xe6,0xe6,0x31 },
231     { 0x84,0x42,0x42,0xc6 }, { 0xd0,0x68,0x68,0xb8 }, 
232     { 0x82,0x41,0x41,0xc3 }, { 0x29,0x99,0x99,0xb0 },
233     { 0x5a,0x2d,0x2d,0x77 }, { 0x1e,0x0f,0x0f,0x11 }, 
234     { 0x7b,0xb0,0xb0,0xcb }, { 0xa8,0x54,0x54,0xfc },
235     { 0x6d,0xbb,0xbb,0xd6 }, { 0x2c,0x16,0x16,0x3a }
236 };
237
238 static const byte T2[256][4] = {
239     { 0xa5,0xc6,0x63,0x63 }, { 0x84,0xf8,0x7c,0x7c },
240     { 0x99,0xee,0x77,0x77 }, { 0x8d,0xf6,0x7b,0x7b }, 
241     { 0x0d,0xff,0xf2,0xf2 }, { 0xbd,0xd6,0x6b,0x6b },
242     { 0xb1,0xde,0x6f,0x6f }, { 0x54,0x91,0xc5,0xc5 }, 
243     { 0x50,0x60,0x30,0x30 }, { 0x03,0x02,0x01,0x01 },
244     { 0xa9,0xce,0x67,0x67 }, { 0x7d,0x56,0x2b,0x2b }, 
245     { 0x19,0xe7,0xfe,0xfe }, { 0x62,0xb5,0xd7,0xd7 }, 
246     { 0xe6,0x4d,0xab,0xab }, { 0x9a,0xec,0x76,0x76 }, 
247     { 0x45,0x8f,0xca,0xca }, { 0x9d,0x1f,0x82,0x82 }, 
248     { 0x40,0x89,0xc9,0xc9 }, { 0x87,0xfa,0x7d,0x7d }, 
249     { 0x15,0xef,0xfa,0xfa }, { 0xeb,0xb2,0x59,0x59 }, 
250     { 0xc9,0x8e,0x47,0x47 }, { 0x0b,0xfb,0xf0,0xf0 }, 
251     { 0xec,0x41,0xad,0xad }, { 0x67,0xb3,0xd4,0xd4 }, 
252     { 0xfd,0x5f,0xa2,0xa2 }, { 0xea,0x45,0xaf,0xaf }, 
253     { 0xbf,0x23,0x9c,0x9c }, { 0xf7,0x53,0xa4,0xa4 }, 
254     { 0x96,0xe4,0x72,0x72 }, { 0x5b,0x9b,0xc0,0xc0 }, 
255     { 0xc2,0x75,0xb7,0xb7 }, { 0x1c,0xe1,0xfd,0xfd }, 
256     { 0xae,0x3d,0x93,0x93 }, { 0x6a,0x4c,0x26,0x26 }, 
257     { 0x5a,0x6c,0x36,0x36 }, { 0x41,0x7e,0x3f,0x3f },
258     { 0x02,0xf5,0xf7,0xf7 }, { 0x4f,0x83,0xcc,0xcc }, 
259     { 0x5c,0x68,0x34,0x34 }, { 0xf4,0x51,0xa5,0xa5 },
260     { 0x34,0xd1,0xe5,0xe5 }, { 0x08,0xf9,0xf1,0xf1 }, 
261     { 0x93,0xe2,0x71,0x71 }, { 0x73,0xab,0xd8,0xd8 },
262     { 0x53,0x62,0x31,0x31 }, { 0x3f,0x2a,0x15,0x15 }, 
263     { 0x0c,0x08,0x04,0x04 }, { 0x52,0x95,0xc7,0xc7 }, 
264     { 0x65,0x46,0x23,0x23 }, { 0x5e,0x9d,0xc3,0xc3 }, 
265     { 0x28,0x30,0x18,0x18 }, { 0xa1,0x37,0x96,0x96 }, 
266     { 0x0f,0x0a,0x05,0x05 }, { 0xb5,0x2f,0x9a,0x9a }, 
267     { 0x09,0x0e,0x07,0x07 }, { 0x36,0x24,0x12,0x12 },
268     { 0x9b,0x1b,0x80,0x80 }, { 0x3d,0xdf,0xe2,0xe2 }, 
269     { 0x26,0xcd,0xeb,0xeb }, { 0x69,0x4e,0x27,0x27 }, 
270     { 0xcd,0x7f,0xb2,0xb2 }, { 0x9f,0xea,0x75,0x75 }, 
271     { 0x1b,0x12,0x09,0x09 }, { 0x9e,0x1d,0x83,0x83 },
272     { 0x74,0x58,0x2c,0x2c }, { 0x2e,0x34,0x1a,0x1a }, 
273     { 0x2d,0x36,0x1b,0x1b }, { 0xb2,0xdc,0x6e,0x6e },
274     { 0xee,0xb4,0x5a,0x5a }, { 0xfb,0x5b,0xa0,0xa0 }, 
275     { 0xf6,0xa4,0x52,0x52 }, { 0x4d,0x76,0x3b,0x3b },
276     { 0x61,0xb7,0xd6,0xd6 }, { 0xce,0x7d,0xb3,0xb3 }, 
277     { 0x7b,0x52,0x29,0x29 }, { 0x3e,0xdd,0xe3,0xe3 }, 
278     { 0x71,0x5e,0x2f,0x2f }, { 0x97,0x13,0x84,0x84 }, 
279     { 0xf5,0xa6,0x53,0x53 }, { 0x68,0xb9,0xd1,0xd1 }, 
280     { 0x00,0x00,0x00,0x00 }, { 0x2c,0xc1,0xed,0xed }, 
281     { 0x60,0x40,0x20,0x20 }, { 0x1f,0xe3,0xfc,0xfc }, 
282     { 0xc8,0x79,0xb1,0xb1 }, { 0xed,0xb6,0x5b,0x5b }, 
283     { 0xbe,0xd4,0x6a,0x6a }, { 0x46,0x8d,0xcb,0xcb }, 
284     { 0xd9,0x67,0xbe,0xbe }, { 0x4b,0x72,0x39,0x39 }, 
285     { 0xde,0x94,0x4a,0x4a }, { 0xd4,0x98,0x4c,0x4c }, 
286     { 0xe8,0xb0,0x58,0x58 }, { 0x4a,0x85,0xcf,0xcf }, 
287     { 0x6b,0xbb,0xd0,0xd0 }, { 0x2a,0xc5,0xef,0xef },
288     { 0xe5,0x4f,0xaa,0xaa }, { 0x16,0xed,0xfb,0xfb }, 
289     { 0xc5,0x86,0x43,0x43 }, { 0xd7,0x9a,0x4d,0x4d }, 
290     { 0x55,0x66,0x33,0x33 }, { 0x94,0x11,0x85,0x85 }, 
291     { 0xcf,0x8a,0x45,0x45 }, { 0x10,0xe9,0xf9,0xf9 }, 
292     { 0x06,0x04,0x02,0x02 }, { 0x81,0xfe,0x7f,0x7f }, 
293     { 0xf0,0xa0,0x50,0x50 }, { 0x44,0x78,0x3c,0x3c },
294     { 0xba,0x25,0x9f,0x9f }, { 0xe3,0x4b,0xa8,0xa8 }, 
295     { 0xf3,0xa2,0x51,0x51 }, { 0xfe,0x5d,0xa3,0xa3 },
296     { 0xc0,0x80,0x40,0x40 }, { 0x8a,0x05,0x8f,0x8f }, 
297     { 0xad,0x3f,0x92,0x92 }, { 0xbc,0x21,0x9d,0x9d },
298     { 0x48,0x70,0x38,0x38 }, { 0x04,0xf1,0xf5,0xf5 }, 
299     { 0xdf,0x63,0xbc,0xbc }, { 0xc1,0x77,0xb6,0xb6 },
300     { 0x75,0xaf,0xda,0xda }, { 0x63,0x42,0x21,0x21 }, 
301     { 0x30,0x20,0x10,0x10 }, { 0x1a,0xe5,0xff,0xff },
302     { 0x0e,0xfd,0xf3,0xf3 }, { 0x6d,0xbf,0xd2,0xd2 }, 
303     { 0x4c,0x81,0xcd,0xcd }, { 0x14,0x18,0x0c,0x0c },
304     { 0x35,0x26,0x13,0x13 }, { 0x2f,0xc3,0xec,0xec }, 
305     { 0xe1,0xbe,0x5f,0x5f }, { 0xa2,0x35,0x97,0x97 },
306     { 0xcc,0x88,0x44,0x44 }, { 0x39,0x2e,0x17,0x17 }, 
307     { 0x57,0x93,0xc4,0xc4 }, { 0xf2,0x55,0xa7,0xa7 },
308     { 0x82,0xfc,0x7e,0x7e }, { 0x47,0x7a,0x3d,0x3d }, 
309     { 0xac,0xc8,0x64,0x64 }, { 0xe7,0xba,0x5d,0x5d },
310     { 0x2b,0x32,0x19,0x19 }, { 0x95,0xe6,0x73,0x73 }, 
311     { 0xa0,0xc0,0x60,0x60 }, { 0x98,0x19,0x81,0x81 }, 
312     { 0xd1,0x9e,0x4f,0x4f }, { 0x7f,0xa3,0xdc,0xdc }, 
313     { 0x66,0x44,0x22,0x22 }, { 0x7e,0x54,0x2a,0x2a }, 
314     { 0xab,0x3b,0x90,0x90 }, { 0x83,0x0b,0x88,0x88 }, 
315     { 0xca,0x8c,0x46,0x46 }, { 0x29,0xc7,0xee,0xee },
316     { 0xd3,0x6b,0xb8,0xb8 }, { 0x3c,0x28,0x14,0x14 }, 
317     { 0x79,0xa7,0xde,0xde }, { 0xe2,0xbc,0x5e,0x5e },
318     { 0x1d,0x16,0x0b,0x0b }, { 0x76,0xad,0xdb,0xdb }, 
319     { 0x3b,0xdb,0xe0,0xe0 }, { 0x56,0x64,0x32,0x32 },
320     { 0x4e,0x74,0x3a,0x3a }, { 0x1e,0x14,0x0a,0x0a }, 
321     { 0xdb,0x92,0x49,0x49 }, { 0x0a,0x0c,0x06,0x06 },
322     { 0x6c,0x48,0x24,0x24 }, { 0xe4,0xb8,0x5c,0x5c }, 
323     { 0x5d,0x9f,0xc2,0xc2 }, { 0x6e,0xbd,0xd3,0xd3 }, 
324     { 0xef,0x43,0xac,0xac }, { 0xa6,0xc4,0x62,0x62 }, 
325     { 0xa8,0x39,0x91,0x91 }, { 0xa4,0x31,0x95,0x95 },
326     { 0x37,0xd3,0xe4,0xe4 }, { 0x8b,0xf2,0x79,0x79 }, 
327     { 0x32,0xd5,0xe7,0xe7 }, { 0x43,0x8b,0xc8,0xc8 },
328     { 0x59,0x6e,0x37,0x37 }, { 0xb7,0xda,0x6d,0x6d }, 
329     { 0x8c,0x01,0x8d,0x8d }, { 0x64,0xb1,0xd5,0xd5 },
330     { 0xd2,0x9c,0x4e,0x4e }, { 0xe0,0x49,0xa9,0xa9 }, 
331     { 0xb4,0xd8,0x6c,0x6c }, { 0xfa,0xac,0x56,0x56 },
332     { 0x07,0xf3,0xf4,0xf4 }, { 0x25,0xcf,0xea,0xea }, 
333     { 0xaf,0xca,0x65,0x65 }, { 0x8e,0xf4,0x7a,0x7a },
334     { 0xe9,0x47,0xae,0xae }, { 0x18,0x10,0x08,0x08 }, 
335     { 0xd5,0x6f,0xba,0xba }, { 0x88,0xf0,0x78,0x78 }, 
336     { 0x6f,0x4a,0x25,0x25 }, { 0x72,0x5c,0x2e,0x2e }, 
337     { 0x24,0x38,0x1c,0x1c }, { 0xf1,0x57,0xa6,0xa6 }, 
338     { 0xc7,0x73,0xb4,0xb4 }, { 0x51,0x97,0xc6,0xc6 }, 
339     { 0x23,0xcb,0xe8,0xe8 }, { 0x7c,0xa1,0xdd,0xdd },
340     { 0x9c,0xe8,0x74,0x74 }, { 0x21,0x3e,0x1f,0x1f }, 
341     { 0xdd,0x96,0x4b,0x4b }, { 0xdc,0x61,0xbd,0xbd },
342     { 0x86,0x0d,0x8b,0x8b }, { 0x85,0x0f,0x8a,0x8a }, 
343     { 0x90,0xe0,0x70,0x70 }, { 0x42,0x7c,0x3e,0x3e }, 
344     { 0xc4,0x71,0xb5,0xb5 }, { 0xaa,0xcc,0x66,0x66 }, 
345     { 0xd8,0x90,0x48,0x48 }, { 0x05,0x06,0x03,0x03 },
346     { 0x01,0xf7,0xf6,0xf6 }, { 0x12,0x1c,0x0e,0x0e }, 
347     { 0xa3,0xc2,0x61,0x61 }, { 0x5f,0x6a,0x35,0x35 },
348     { 0xf9,0xae,0x57,0x57 }, { 0xd0,0x69,0xb9,0xb9 }, 
349     { 0x91,0x17,0x86,0x86 }, { 0x58,0x99,0xc1,0xc1 }, 
350     { 0x27,0x3a,0x1d,0x1d }, { 0xb9,0x27,0x9e,0x9e }, 
351     { 0x38,0xd9,0xe1,0xe1 }, { 0x13,0xeb,0xf8,0xf8 },
352     { 0xb3,0x2b,0x98,0x98 }, { 0x33,0x22,0x11,0x11 }, 
353     { 0xbb,0xd2,0x69,0x69 }, { 0x70,0xa9,0xd9,0xd9 },
354     { 0x89,0x07,0x8e,0x8e }, { 0xa7,0x33,0x94,0x94 }, 
355     { 0xb6,0x2d,0x9b,0x9b }, { 0x22,0x3c,0x1e,0x1e },
356     { 0x92,0x15,0x87,0x87 }, { 0x20,0xc9,0xe9,0xe9 }, 
357     { 0x49,0x87,0xce,0xce }, { 0xff,0xaa,0x55,0x55 },
358     { 0x78,0x50,0x28,0x28 }, { 0x7a,0xa5,0xdf,0xdf }, 
359     { 0x8f,0x03,0x8c,0x8c }, { 0xf8,0x59,0xa1,0xa1 }, 
360     { 0x80,0x09,0x89,0x89 }, { 0x17,0x1a,0x0d,0x0d }, 
361     { 0xda,0x65,0xbf,0xbf }, { 0x31,0xd7,0xe6,0xe6 },
362     { 0xc6,0x84,0x42,0x42 }, { 0xb8,0xd0,0x68,0x68 }, 
363     { 0xc3,0x82,0x41,0x41 }, { 0xb0,0x29,0x99,0x99 }, 
364     { 0x77,0x5a,0x2d,0x2d }, { 0x11,0x1e,0x0f,0x0f }, 
365     { 0xcb,0x7b,0xb0,0xb0 }, { 0xfc,0xa8,0x54,0x54 }, 
366     { 0xd6,0x6d,0xbb,0xbb }, { 0x3a,0x2c,0x16,0x16 }
367 };
368
369 static const byte T3[256][4] = {
370     { 0x63,0xa5,0xc6,0x63 }, { 0x7c,0x84,0xf8,0x7c },
371     { 0x77,0x99,0xee,0x77 }, { 0x7b,0x8d,0xf6,0x7b }, 
372     { 0xf2,0x0d,0xff,0xf2 }, { 0x6b,0xbd,0xd6,0x6b },
373     { 0x6f,0xb1,0xde,0x6f }, { 0xc5,0x54,0x91,0xc5 }, 
374     { 0x30,0x50,0x60,0x30 }, { 0x01,0x03,0x02,0x01 },
375     { 0x67,0xa9,0xce,0x67 }, { 0x2b,0x7d,0x56,0x2b }, 
376     { 0xfe,0x19,0xe7,0xfe }, { 0xd7,0x62,0xb5,0xd7 }, 
377     { 0xab,0xe6,0x4d,0xab }, { 0x76,0x9a,0xec,0x76 }, 
378     { 0xca,0x45,0x8f,0xca }, { 0x82,0x9d,0x1f,0x82 },
379     { 0xc9,0x40,0x89,0xc9 }, { 0x7d,0x87,0xfa,0x7d }, 
380     { 0xfa,0x15,0xef,0xfa }, { 0x59,0xeb,0xb2,0x59 }, 
381     { 0x47,0xc9,0x8e,0x47 }, { 0xf0,0x0b,0xfb,0xf0 }, 
382     { 0xad,0xec,0x41,0xad }, { 0xd4,0x67,0xb3,0xd4 }, 
383     { 0xa2,0xfd,0x5f,0xa2 }, { 0xaf,0xea,0x45,0xaf }, 
384     { 0x9c,0xbf,0x23,0x9c }, { 0xa4,0xf7,0x53,0xa4 },
385     { 0x72,0x96,0xe4,0x72 }, { 0xc0,0x5b,0x9b,0xc0 }, 
386     { 0xb7,0xc2,0x75,0xb7 }, { 0xfd,0x1c,0xe1,0xfd }, 
387     { 0x93,0xae,0x3d,0x93 }, { 0x26,0x6a,0x4c,0x26 }, 
388     { 0x36,0x5a,0x6c,0x36 }, { 0x3f,0x41,0x7e,0x3f },
389     { 0xf7,0x02,0xf5,0xf7 }, { 0xcc,0x4f,0x83,0xcc }, 
390     { 0x34,0x5c,0x68,0x34 }, { 0xa5,0xf4,0x51,0xa5 },
391     { 0xe5,0x34,0xd1,0xe5 }, { 0xf1,0x08,0xf9,0xf1 }, 
392     { 0x71,0x93,0xe2,0x71 }, { 0xd8,0x73,0xab,0xd8 },
393     { 0x31,0x53,0x62,0x31 }, { 0x15,0x3f,0x2a,0x15 }, 
394     { 0x04,0x0c,0x08,0x04 }, { 0xc7,0x52,0x95,0xc7 }, 
395     { 0x23,0x65,0x46,0x23 }, { 0xc3,0x5e,0x9d,0xc3 }, 
396     { 0x18,0x28,0x30,0x18 }, { 0x96,0xa1,0x37,0x96 },
397     { 0x05,0x0f,0x0a,0x05 }, { 0x9a,0xb5,0x2f,0x9a }, 
398     { 0x07,0x09,0x0e,0x07 }, { 0x12,0x36,0x24,0x12 }, 
399     { 0x80,0x9b,0x1b,0x80 }, { 0xe2,0x3d,0xdf,0xe2 }, 
400     { 0xeb,0x26,0xcd,0xeb }, { 0x27,0x69,0x4e,0x27 },
401     { 0xb2,0xcd,0x7f,0xb2 }, { 0x75,0x9f,0xea,0x75 }, 
402     { 0x09,0x1b,0x12,0x09 }, { 0x83,0x9e,0x1d,0x83 },
403     { 0x2c,0x74,0x58,0x2c }, { 0x1a,0x2e,0x34,0x1a }, 
404     { 0x1b,0x2d,0x36,0x1b }, { 0x6e,0xb2,0xdc,0x6e },
405     { 0x5a,0xee,0xb4,0x5a }, { 0xa0,0xfb,0x5b,0xa0 }, 
406     { 0x52,0xf6,0xa4,0x52 }, { 0x3b,0x4d,0x76,0x3b },
407     { 0xd6,0x61,0xb7,0xd6 }, { 0xb3,0xce,0x7d,0xb3 }, 
408     { 0x29,0x7b,0x52,0x29 }, { 0xe3,0x3e,0xdd,0xe3 }, 
409     { 0x2f,0x71,0x5e,0x2f }, { 0x84,0x97,0x13,0x84 }, 
410     { 0x53,0xf5,0xa6,0x53 }, { 0xd1,0x68,0xb9,0xd1 },
411     { 0x00,0x00,0x00,0x00 }, { 0xed,0x2c,0xc1,0xed }, 
412     { 0x20,0x60,0x40,0x20 }, { 0xfc,0x1f,0xe3,0xfc },
413     { 0xb1,0xc8,0x79,0xb1 }, { 0x5b,0xed,0xb6,0x5b }, 
414     { 0x6a,0xbe,0xd4,0x6a }, { 0xcb,0x46,0x8d,0xcb },
415     { 0xbe,0xd9,0x67,0xbe }, { 0x39,0x4b,0x72,0x39 }, 
416     { 0x4a,0xde,0x94,0x4a }, { 0x4c,0xd4,0x98,0x4c },
417     { 0x58,0xe8,0xb0,0x58 }, { 0xcf,0x4a,0x85,0xcf }, 
418     { 0xd0,0x6b,0xbb,0xd0 }, { 0xef,0x2a,0xc5,0xef },
419     { 0xaa,0xe5,0x4f,0xaa }, { 0xfb,0x16,0xed,0xfb }, 
420     { 0x43,0xc5,0x86,0x43 }, { 0x4d,0xd7,0x9a,0x4d },
421     { 0x33,0x55,0x66,0x33 }, { 0x85,0x94,0x11,0x85 }, 
422     { 0x45,0xcf,0x8a,0x45 }, { 0xf9,0x10,0xe9,0xf9 },
423     { 0x02,0x06,0x04,0x02 }, { 0x7f,0x81,0xfe,0x7f }, 
424     { 0x50,0xf0,0xa0,0x50 }, { 0x3c,0x44,0x78,0x3c },
425     { 0x9f,0xba,0x25,0x9f }, { 0xa8,0xe3,0x4b,0xa8 }, 
426     { 0x51,0xf3,0xa2,0x51 }, { 0xa3,0xfe,0x5d,0xa3 },
427     { 0x40,0xc0,0x80,0x40 }, { 0x8f,0x8a,0x05,0x8f }, 
428     { 0x92,0xad,0x3f,0x92 }, { 0x9d,0xbc,0x21,0x9d },
429     { 0x38,0x48,0x70,0x38 }, { 0xf5,0x04,0xf1,0xf5 }, 
430     { 0xbc,0xdf,0x63,0xbc }, { 0xb6,0xc1,0x77,0xb6 },
431     { 0xda,0x75,0xaf,0xda }, { 0x21,0x63,0x42,0x21 }, 
432     { 0x10,0x30,0x20,0x10 }, { 0xff,0x1a,0xe5,0xff },
433     { 0xf3,0x0e,0xfd,0xf3 }, { 0xd2,0x6d,0xbf,0xd2 }, 
434     { 0xcd,0x4c,0x81,0xcd }, { 0x0c,0x14,0x18,0x0c }, 
435     { 0x13,0x35,0x26,0x13 }, { 0xec,0x2f,0xc3,0xec }, 
436     { 0x5f,0xe1,0xbe,0x5f }, { 0x97,0xa2,0x35,0x97 },
437     { 0x44,0xcc,0x88,0x44 }, { 0x17,0x39,0x2e,0x17 }, 
438     { 0xc4,0x57,0x93,0xc4 }, { 0xa7,0xf2,0x55,0xa7 },
439     { 0x7e,0x82,0xfc,0x7e }, { 0x3d,0x47,0x7a,0x3d }, 
440     { 0x64,0xac,0xc8,0x64 }, { 0x5d,0xe7,0xba,0x5d },
441     { 0x19,0x2b,0x32,0x19 }, { 0x73,0x95,0xe6,0x73 }, 
442     { 0x60,0xa0,0xc0,0x60 }, { 0x81,0x98,0x19,0x81 },
443     { 0x4f,0xd1,0x9e,0x4f }, { 0xdc,0x7f,0xa3,0xdc }, 
444     { 0x22,0x66,0x44,0x22 }, { 0x2a,0x7e,0x54,0x2a },
445     { 0x90,0xab,0x3b,0x90 }, { 0x88,0x83,0x0b,0x88 }, 
446     { 0x46,0xca,0x8c,0x46 }, { 0xee,0x29,0xc7,0xee },
447     { 0xb8,0xd3,0x6b,0xb8 }, { 0x14,0x3c,0x28,0x14 }, 
448     { 0xde,0x79,0xa7,0xde }, { 0x5e,0xe2,0xbc,0x5e }, 
449     { 0x0b,0x1d,0x16,0x0b }, { 0xdb,0x76,0xad,0xdb }, 
450     { 0xe0,0x3b,0xdb,0xe0 }, { 0x32,0x56,0x64,0x32 },
451     { 0x3a,0x4e,0x74,0x3a }, { 0x0a,0x1e,0x14,0x0a }, 
452     { 0x49,0xdb,0x92,0x49 }, { 0x06,0x0a,0x0c,0x06 },
453     { 0x24,0x6c,0x48,0x24 }, { 0x5c,0xe4,0xb8,0x5c }, 
454     { 0xc2,0x5d,0x9f,0xc2 }, { 0xd3,0x6e,0xbd,0xd3 },
455     { 0xac,0xef,0x43,0xac }, { 0x62,0xa6,0xc4,0x62 }, 
456     { 0x91,0xa8,0x39,0x91 }, { 0x95,0xa4,0x31,0x95 },
457     { 0xe4,0x37,0xd3,0xe4 }, { 0x79,0x8b,0xf2,0x79 }, 
458     { 0xe7,0x32,0xd5,0xe7 }, { 0xc8,0x43,0x8b,0xc8 }, 
459     { 0x37,0x59,0x6e,0x37 }, { 0x6d,0xb7,0xda,0x6d }, 
460     { 0x8d,0x8c,0x01,0x8d }, { 0xd5,0x64,0xb1,0xd5 }, 
461     { 0x4e,0xd2,0x9c,0x4e }, { 0xa9,0xe0,0x49,0xa9 }, 
462     { 0x6c,0xb4,0xd8,0x6c }, { 0x56,0xfa,0xac,0x56 },
463     { 0xf4,0x07,0xf3,0xf4 }, { 0xea,0x25,0xcf,0xea }, 
464     { 0x65,0xaf,0xca,0x65 }, { 0x7a,0x8e,0xf4,0x7a }, 
465     { 0xae,0xe9,0x47,0xae }, { 0x08,0x18,0x10,0x08 }, 
466     { 0xba,0xd5,0x6f,0xba }, { 0x78,0x88,0xf0,0x78 }, 
467     { 0x25,0x6f,0x4a,0x25 }, { 0x2e,0x72,0x5c,0x2e }, 
468     { 0x1c,0x24,0x38,0x1c }, { 0xa6,0xf1,0x57,0xa6 }, 
469     { 0xb4,0xc7,0x73,0xb4 }, { 0xc6,0x51,0x97,0xc6 }, 
470     { 0xe8,0x23,0xcb,0xe8 }, { 0xdd,0x7c,0xa1,0xdd },
471     { 0x74,0x9c,0xe8,0x74 }, { 0x1f,0x21,0x3e,0x1f }, 
472     { 0x4b,0xdd,0x96,0x4b }, { 0xbd,0xdc,0x61,0xbd },
473     { 0x8b,0x86,0x0d,0x8b }, { 0x8a,0x85,0x0f,0x8a }, 
474     { 0x70,0x90,0xe0,0x70 }, { 0x3e,0x42,0x7c,0x3e },
475     { 0xb5,0xc4,0x71,0xb5 }, { 0x66,0xaa,0xcc,0x66 }, 
476     { 0x48,0xd8,0x90,0x48 }, { 0x03,0x05,0x06,0x03 },
477     { 0xf6,0x01,0xf7,0xf6 }, { 0x0e,0x12,0x1c,0x0e }, 
478     { 0x61,0xa3,0xc2,0x61 }, { 0x35,0x5f,0x6a,0x35 },
479     { 0x57,0xf9,0xae,0x57 }, { 0xb9,0xd0,0x69,0xb9 }, 
480     { 0x86,0x91,0x17,0x86 }, { 0xc1,0x58,0x99,0xc1 }, 
481     { 0x1d,0x27,0x3a,0x1d }, { 0x9e,0xb9,0x27,0x9e }, 
482     { 0xe1,0x38,0xd9,0xe1 }, { 0xf8,0x13,0xeb,0xf8 },
483     { 0x98,0xb3,0x2b,0x98 }, { 0x11,0x33,0x22,0x11 }, 
484     { 0x69,0xbb,0xd2,0x69 }, { 0xd9,0x70,0xa9,0xd9 },
485     { 0x8e,0x89,0x07,0x8e }, { 0x94,0xa7,0x33,0x94 }, 
486     { 0x9b,0xb6,0x2d,0x9b }, { 0x1e,0x22,0x3c,0x1e },
487     { 0x87,0x92,0x15,0x87 }, { 0xe9,0x20,0xc9,0xe9 }, 
488     { 0xce,0x49,0x87,0xce }, { 0x55,0xff,0xaa,0x55 },
489     { 0x28,0x78,0x50,0x28 }, { 0xdf,0x7a,0xa5,0xdf }, 
490     { 0x8c,0x8f,0x03,0x8c }, { 0xa1,0xf8,0x59,0xa1 },
491     { 0x89,0x80,0x09,0x89 }, { 0x0d,0x17,0x1a,0x0d }, 
492     { 0xbf,0xda,0x65,0xbf }, { 0xe6,0x31,0xd7,0xe6 },
493     { 0x42,0xc6,0x84,0x42 }, { 0x68,0xb8,0xd0,0x68 }, 
494     { 0x41,0xc3,0x82,0x41 }, { 0x99,0xb0,0x29,0x99 },
495     { 0x2d,0x77,0x5a,0x2d }, { 0x0f,0x11,0x1e,0x0f }, 
496     { 0xb0,0xcb,0x7b,0xb0 }, { 0x54,0xfc,0xa8,0x54 },
497     { 0xbb,0xd6,0x6d,0xbb }, { 0x16,0x3a,0x2c,0x16 }
498 };
499
500 static const byte T4[256][4] = {
501     { 0x63,0x63,0xa5,0xc6 }, { 0x7c,0x7c,0x84,0xf8 },
502     { 0x77,0x77,0x99,0xee }, { 0x7b,0x7b,0x8d,0xf6 }, 
503     { 0xf2,0xf2,0x0d,0xff }, { 0x6b,0x6b,0xbd,0xd6 }, 
504     { 0x6f,0x6f,0xb1,0xde }, { 0xc5,0xc5,0x54,0x91 }, 
505     { 0x30,0x30,0x50,0x60 }, { 0x01,0x01,0x03,0x02 },
506     { 0x67,0x67,0xa9,0xce }, { 0x2b,0x2b,0x7d,0x56 }, 
507     { 0xfe,0xfe,0x19,0xe7 }, { 0xd7,0xd7,0x62,0xb5 },
508     { 0xab,0xab,0xe6,0x4d }, { 0x76,0x76,0x9a,0xec }, 
509     { 0xca,0xca,0x45,0x8f }, { 0x82,0x82,0x9d,0x1f },
510     { 0xc9,0xc9,0x40,0x89 }, { 0x7d,0x7d,0x87,0xfa }, 
511     { 0xfa,0xfa,0x15,0xef }, { 0x59,0x59,0xeb,0xb2 },
512     { 0x47,0x47,0xc9,0x8e }, { 0xf0,0xf0,0x0b,0xfb }, 
513     { 0xad,0xad,0xec,0x41 }, { 0xd4,0xd4,0x67,0xb3 },
514     { 0xa2,0xa2,0xfd,0x5f }, { 0xaf,0xaf,0xea,0x45 }, 
515     { 0x9c,0x9c,0xbf,0x23 }, { 0xa4,0xa4,0xf7,0x53 },
516     { 0x72,0x72,0x96,0xe4 }, { 0xc0,0xc0,0x5b,0x9b }, 
517     { 0xb7,0xb7,0xc2,0x75 }, { 0xfd,0xfd,0x1c,0xe1 },
518     { 0x93,0x93,0xae,0x3d }, { 0x26,0x26,0x6a,0x4c }, 
519     { 0x36,0x36,0x5a,0x6c }, { 0x3f,0x3f,0x41,0x7e },
520     { 0xf7,0xf7,0x02,0xf5 }, { 0xcc,0xcc,0x4f,0x83 }, 
521     { 0x34,0x34,0x5c,0x68 }, { 0xa5,0xa5,0xf4,0x51 },
522     { 0xe5,0xe5,0x34,0xd1 }, { 0xf1,0xf1,0x08,0xf9 }, 
523     { 0x71,0x71,0x93,0xe2 }, { 0xd8,0xd8,0x73,0xab },
524     { 0x31,0x31,0x53,0x62 }, { 0x15,0x15,0x3f,0x2a }, 
525     { 0x04,0x04,0x0c,0x08 }, { 0xc7,0xc7,0x52,0x95 },
526     { 0x23,0x23,0x65,0x46 }, { 0xc3,0xc3,0x5e,0x9d }, 
527     { 0x18,0x18,0x28,0x30 }, { 0x96,0x96,0xa1,0x37 },
528     { 0x05,0x05,0x0f,0x0a }, { 0x9a,0x9a,0xb5,0x2f }, 
529     { 0x07,0x07,0x09,0x0e }, { 0x12,0x12,0x36,0x24 },
530     { 0x80,0x80,0x9b,0x1b }, { 0xe2,0xe2,0x3d,0xdf }, 
531     { 0xeb,0xeb,0x26,0xcd }, { 0x27,0x27,0x69,0x4e },
532     { 0xb2,0xb2,0xcd,0x7f }, { 0x75,0x75,0x9f,0xea }, 
533     { 0x09,0x09,0x1b,0x12 }, { 0x83,0x83,0x9e,0x1d },
534     { 0x2c,0x2c,0x74,0x58 }, { 0x1a,0x1a,0x2e,0x34 }, 
535     { 0x1b,0x1b,0x2d,0x36 }, { 0x6e,0x6e,0xb2,0xdc },
536     { 0x5a,0x5a,0xee,0xb4 }, { 0xa0,0xa0,0xfb,0x5b }, 
537     { 0x52,0x52,0xf6,0xa4 }, { 0x3b,0x3b,0x4d,0x76 },
538     { 0xd6,0xd6,0x61,0xb7 }, { 0xb3,0xb3,0xce,0x7d }, 
539     { 0x29,0x29,0x7b,0x52 }, { 0xe3,0xe3,0x3e,0xdd },
540     { 0x2f,0x2f,0x71,0x5e }, { 0x84,0x84,0x97,0x13 }, 
541     { 0x53,0x53,0xf5,0xa6 }, { 0xd1,0xd1,0x68,0xb9 },
542     { 0x00,0x00,0x00,0x00 }, { 0xed,0xed,0x2c,0xc1 }, 
543     { 0x20,0x20,0x60,0x40 }, { 0xfc,0xfc,0x1f,0xe3 },
544     { 0xb1,0xb1,0xc8,0x79 }, { 0x5b,0x5b,0xed,0xb6 }, 
545     { 0x6a,0x6a,0xbe,0xd4 }, { 0xcb,0xcb,0x46,0x8d },
546     { 0xbe,0xbe,0xd9,0x67 }, { 0x39,0x39,0x4b,0x72 }, 
547     { 0x4a,0x4a,0xde,0x94 }, { 0x4c,0x4c,0xd4,0x98 },
548     { 0x58,0x58,0xe8,0xb0 }, { 0xcf,0xcf,0x4a,0x85 }, 
549     { 0xd0,0xd0,0x6b,0xbb }, { 0xef,0xef,0x2a,0xc5 },
550     { 0xaa,0xaa,0xe5,0x4f }, { 0xfb,0xfb,0x16,0xed }, 
551     { 0x43,0x43,0xc5,0x86 }, { 0x4d,0x4d,0xd7,0x9a },
552     { 0x33,0x33,0x55,0x66 }, { 0x85,0x85,0x94,0x11 }, 
553     { 0x45,0x45,0xcf,0x8a }, { 0xf9,0xf9,0x10,0xe9 },
554     { 0x02,0x02,0x06,0x04 }, { 0x7f,0x7f,0x81,0xfe }, 
555     { 0x50,0x50,0xf0,0xa0 }, { 0x3c,0x3c,0x44,0x78 },
556     { 0x9f,0x9f,0xba,0x25 }, { 0xa8,0xa8,0xe3,0x4b }, 
557     { 0x51,0x51,0xf3,0xa2 }, { 0xa3,0xa3,0xfe,0x5d },
558     { 0x40,0x40,0xc0,0x80 }, { 0x8f,0x8f,0x8a,0x05 }, 
559     { 0x92,0x92,0xad,0x3f }, { 0x9d,0x9d,0xbc,0x21 },
560     { 0x38,0x38,0x48,0x70 }, { 0xf5,0xf5,0x04,0xf1 }, 
561     { 0xbc,0xbc,0xdf,0x63 }, { 0xb6,0xb6,0xc1,0x77 },
562     { 0xda,0xda,0x75,0xaf }, { 0x21,0x21,0x63,0x42 }, 
563     { 0x10,0x10,0x30,0x20 }, { 0xff,0xff,0x1a,0xe5 },
564     { 0xf3,0xf3,0x0e,0xfd }, { 0xd2,0xd2,0x6d,0xbf }, 
565     { 0xcd,0xcd,0x4c,0x81 }, { 0x0c,0x0c,0x14,0x18 },
566     { 0x13,0x13,0x35,0x26 }, { 0xec,0xec,0x2f,0xc3 }, 
567     { 0x5f,0x5f,0xe1,0xbe }, { 0x97,0x97,0xa2,0x35 },
568     { 0x44,0x44,0xcc,0x88 }, { 0x17,0x17,0x39,0x2e }, 
569     { 0xc4,0xc4,0x57,0x93 }, { 0xa7,0xa7,0xf2,0x55 },
570     { 0x7e,0x7e,0x82,0xfc }, { 0x3d,0x3d,0x47,0x7a }, 
571     { 0x64,0x64,0xac,0xc8 }, { 0x5d,0x5d,0xe7,0xba },
572     { 0x19,0x19,0x2b,0x32 }, { 0x73,0x73,0x95,0xe6 }, 
573     { 0x60,0x60,0xa0,0xc0 }, { 0x81,0x81,0x98,0x19 },
574     { 0x4f,0x4f,0xd1,0x9e }, { 0xdc,0xdc,0x7f,0xa3 }, 
575     { 0x22,0x22,0x66,0x44 }, { 0x2a,0x2a,0x7e,0x54 },
576     { 0x90,0x90,0xab,0x3b }, { 0x88,0x88,0x83,0x0b }, 
577     { 0x46,0x46,0xca,0x8c }, { 0xee,0xee,0x29,0xc7 },
578     { 0xb8,0xb8,0xd3,0x6b }, { 0x14,0x14,0x3c,0x28 }, 
579     { 0xde,0xde,0x79,0xa7 }, { 0x5e,0x5e,0xe2,0xbc },
580     { 0x0b,0x0b,0x1d,0x16 }, { 0xdb,0xdb,0x76,0xad }, 
581     { 0xe0,0xe0,0x3b,0xdb }, { 0x32,0x32,0x56,0x64 },
582     { 0x3a,0x3a,0x4e,0x74 }, { 0x0a,0x0a,0x1e,0x14 }, 
583     { 0x49,0x49,0xdb,0x92 }, { 0x06,0x06,0x0a,0x0c },
584     { 0x24,0x24,0x6c,0x48 }, { 0x5c,0x5c,0xe4,0xb8 }, 
585     { 0xc2,0xc2,0x5d,0x9f }, { 0xd3,0xd3,0x6e,0xbd },
586     { 0xac,0xac,0xef,0x43 }, { 0x62,0x62,0xa6,0xc4 }, 
587     { 0x91,0x91,0xa8,0x39 }, { 0x95,0x95,0xa4,0x31 },
588     { 0xe4,0xe4,0x37,0xd3 }, { 0x79,0x79,0x8b,0xf2 }, 
589     { 0xe7,0xe7,0x32,0xd5 }, { 0xc8,0xc8,0x43,0x8b },
590     { 0x37,0x37,0x59,0x6e }, { 0x6d,0x6d,0xb7,0xda }, 
591     { 0x8d,0x8d,0x8c,0x01 }, { 0xd5,0xd5,0x64,0xb1 }, 
592     { 0x4e,0x4e,0xd2,0x9c }, { 0xa9,0xa9,0xe0,0x49 }, 
593     { 0x6c,0x6c,0xb4,0xd8 }, { 0x56,0x56,0xfa,0xac }, 
594     { 0xf4,0xf4,0x07,0xf3 }, { 0xea,0xea,0x25,0xcf }, 
595     { 0x65,0x65,0xaf,0xca }, { 0x7a,0x7a,0x8e,0xf4 }, 
596     { 0xae,0xae,0xe9,0x47 }, { 0x08,0x08,0x18,0x10 }, 
597     { 0xba,0xba,0xd5,0x6f }, { 0x78,0x78,0x88,0xf0 }, 
598     { 0x25,0x25,0x6f,0x4a }, { 0x2e,0x2e,0x72,0x5c }, 
599     { 0x1c,0x1c,0x24,0x38 }, { 0xa6,0xa6,0xf1,0x57 },
600     { 0xb4,0xb4,0xc7,0x73 }, { 0xc6,0xc6,0x51,0x97 }, 
601     { 0xe8,0xe8,0x23,0xcb }, { 0xdd,0xdd,0x7c,0xa1 },
602     { 0x74,0x74,0x9c,0xe8 }, { 0x1f,0x1f,0x21,0x3e }, 
603     { 0x4b,0x4b,0xdd,0x96 }, { 0xbd,0xbd,0xdc,0x61 },
604     { 0x8b,0x8b,0x86,0x0d }, { 0x8a,0x8a,0x85,0x0f }, 
605     { 0x70,0x70,0x90,0xe0 }, { 0x3e,0x3e,0x42,0x7c },
606     { 0xb5,0xb5,0xc4,0x71 }, { 0x66,0x66,0xaa,0xcc }, 
607     { 0x48,0x48,0xd8,0x90 }, { 0x03,0x03,0x05,0x06 },
608     { 0xf6,0xf6,0x01,0xf7 }, { 0x0e,0x0e,0x12,0x1c }, 
609     { 0x61,0x61,0xa3,0xc2 }, { 0x35,0x35,0x5f,0x6a },
610     { 0x57,0x57,0xf9,0xae }, { 0xb9,0xb9,0xd0,0x69 }, 
611     { 0x86,0x86,0x91,0x17 }, { 0xc1,0xc1,0x58,0x99 },
612     { 0x1d,0x1d,0x27,0x3a }, { 0x9e,0x9e,0xb9,0x27 }, 
613     { 0xe1,0xe1,0x38,0xd9 }, { 0xf8,0xf8,0x13,0xeb },
614     { 0x98,0x98,0xb3,0x2b }, { 0x11,0x11,0x33,0x22 }, 
615     { 0x69,0x69,0xbb,0xd2 }, { 0xd9,0xd9,0x70,0xa9 },
616     { 0x8e,0x8e,0x89,0x07 }, { 0x94,0x94,0xa7,0x33 }, 
617     { 0x9b,0x9b,0xb6,0x2d }, { 0x1e,0x1e,0x22,0x3c },
618     { 0x87,0x87,0x92,0x15 }, { 0xe9,0xe9,0x20,0xc9 }, 
619     { 0xce,0xce,0x49,0x87 }, { 0x55,0x55,0xff,0xaa },
620     { 0x28,0x28,0x78,0x50 }, { 0xdf,0xdf,0x7a,0xa5 }, 
621     { 0x8c,0x8c,0x8f,0x03 }, { 0xa1,0xa1,0xf8,0x59 },
622     { 0x89,0x89,0x80,0x09 }, { 0x0d,0x0d,0x17,0x1a }, 
623     { 0xbf,0xbf,0xda,0x65 }, { 0xe6,0xe6,0x31,0xd7 }, 
624     { 0x42,0x42,0xc6,0x84 }, { 0x68,0x68,0xb8,0xd0 }, 
625     { 0x41,0x41,0xc3,0x82 }, { 0x99,0x99,0xb0,0x29 },
626     { 0x2d,0x2d,0x77,0x5a }, { 0x0f,0x0f,0x11,0x1e }, 
627     { 0xb0,0xb0,0xcb,0x7b }, { 0x54,0x54,0xfc,0xa8 },
628     { 0xbb,0xbb,0xd6,0x6d }, { 0x16,0x16,0x3a,0x2c }
629 };
630
631 static const byte T5[256][4] = {
632     { 0x51,0xf4,0xa7,0x50 }, { 0x7e,0x41,0x65,0x53 }, 
633     { 0x1a,0x17,0xa4,0xc3 }, { 0x3a,0x27,0x5e,0x96 }, 
634     { 0x3b,0xab,0x6b,0xcb }, { 0x1f,0x9d,0x45,0xf1 },
635     { 0xac,0xfa,0x58,0xab }, { 0x4b,0xe3,0x03,0x93 }, 
636     { 0x20,0x30,0xfa,0x55 }, { 0xad,0x76,0x6d,0xf6 },
637     { 0x88,0xcc,0x76,0x91 }, { 0xf5,0x02,0x4c,0x25 }, 
638     { 0x4f,0xe5,0xd7,0xfc }, { 0xc5,0x2a,0xcb,0xd7 },
639     { 0x26,0x35,0x44,0x80 }, { 0xb5,0x62,0xa3,0x8f }, 
640     { 0xde,0xb1,0x5a,0x49 }, { 0x25,0xba,0x1b,0x67 },
641     { 0x45,0xea,0x0e,0x98 }, { 0x5d,0xfe,0xc0,0xe1 }, 
642     { 0xc3,0x2f,0x75,0x02 }, { 0x81,0x4c,0xf0,0x12 },
643     { 0x8d,0x46,0x97,0xa3 }, { 0x6b,0xd3,0xf9,0xc6 }, 
644     { 0x03,0x8f,0x5f,0xe7 }, { 0x15,0x92,0x9c,0x95 },
645     { 0xbf,0x6d,0x7a,0xeb }, { 0x95,0x52,0x59,0xda }, 
646     { 0xd4,0xbe,0x83,0x2d }, { 0x58,0x74,0x21,0xd3 },
647     { 0x49,0xe0,0x69,0x29 }, { 0x8e,0xc9,0xc8,0x44 }, 
648     { 0x75,0xc2,0x89,0x6a }, { 0xf4,0x8e,0x79,0x78 },
649     { 0x99,0x58,0x3e,0x6b }, { 0x27,0xb9,0x71,0xdd }, 
650     { 0xbe,0xe1,0x4f,0xb6 }, { 0xf0,0x88,0xad,0x17 },
651     { 0xc9,0x20,0xac,0x66 }, { 0x7d,0xce,0x3a,0xb4 }, 
652     { 0x63,0xdf,0x4a,0x18 }, { 0xe5,0x1a,0x31,0x82 },
653     { 0x97,0x51,0x33,0x60 }, { 0x62,0x53,0x7f,0x45 }, 
654     { 0xb1,0x64,0x77,0xe0 }, { 0xbb,0x6b,0xae,0x84 }, 
655     { 0xfe,0x81,0xa0,0x1c }, { 0xf9,0x08,0x2b,0x94 }, 
656     { 0x70,0x48,0x68,0x58 }, { 0x8f,0x45,0xfd,0x19 }, 
657     { 0x94,0xde,0x6c,0x87 }, { 0x52,0x7b,0xf8,0xb7 }, 
658     { 0xab,0x73,0xd3,0x23 }, { 0x72,0x4b,0x02,0xe2 },
659     { 0xe3,0x1f,0x8f,0x57 }, { 0x66,0x55,0xab,0x2a }, 
660     { 0xb2,0xeb,0x28,0x07 }, { 0x2f,0xb5,0xc2,0x03 },
661     { 0x86,0xc5,0x7b,0x9a }, { 0xd3,0x37,0x08,0xa5 }, 
662     { 0x30,0x28,0x87,0xf2 }, { 0x23,0xbf,0xa5,0xb2 },
663     { 0x02,0x03,0x6a,0xba }, { 0xed,0x16,0x82,0x5c }, 
664     { 0x8a,0xcf,0x1c,0x2b }, { 0xa7,0x79,0xb4,0x92 },
665     { 0xf3,0x07,0xf2,0xf0 }, { 0x4e,0x69,0xe2,0xa1 }, 
666     { 0x65,0xda,0xf4,0xcd }, { 0x06,0x05,0xbe,0xd5 },
667     { 0xd1,0x34,0x62,0x1f }, { 0xc4,0xa6,0xfe,0x8a }, 
668     { 0x34,0x2e,0x53,0x9d }, { 0xa2,0xf3,0x55,0xa0 },
669     { 0x05,0x8a,0xe1,0x32 }, { 0xa4,0xf6,0xeb,0x75 }, 
670     { 0x0b,0x83,0xec,0x39 }, { 0x40,0x60,0xef,0xaa },
671     { 0x5e,0x71,0x9f,0x06 }, { 0xbd,0x6e,0x10,0x51 }, 
672     { 0x3e,0x21,0x8a,0xf9 }, { 0x96,0xdd,0x06,0x3d }, 
673     { 0xdd,0x3e,0x05,0xae }, { 0x4d,0xe6,0xbd,0x46 }, 
674     { 0x91,0x54,0x8d,0xb5 }, { 0x71,0xc4,0x5d,0x05 }, 
675     { 0x04,0x06,0xd4,0x6f }, { 0x60,0x50,0x15,0xff }, 
676     { 0x19,0x98,0xfb,0x24 }, { 0xd6,0xbd,0xe9,0x97 },
677     { 0x89,0x40,0x43,0xcc }, { 0x67,0xd9,0x9e,0x77 }, 
678     { 0xb0,0xe8,0x42,0xbd }, { 0x07,0x89,0x8b,0x88 },
679     { 0xe7,0x19,0x5b,0x38 }, { 0x79,0xc8,0xee,0xdb }, 
680     { 0xa1,0x7c,0x0a,0x47 }, { 0x7c,0x42,0x0f,0xe9 },
681     { 0xf8,0x84,0x1e,0xc9 }, { 0x00,0x00,0x00,0x00 }, 
682     { 0x09,0x80,0x86,0x83 }, { 0x32,0x2b,0xed,0x48 },
683     { 0x1e,0x11,0x70,0xac }, { 0x6c,0x5a,0x72,0x4e }, 
684     { 0xfd,0x0e,0xff,0xfb }, { 0x0f,0x85,0x38,0x56 },
685     { 0x3d,0xae,0xd5,0x1e }, { 0x36,0x2d,0x39,0x27 }, 
686     { 0x0a,0x0f,0xd9,0x64 }, { 0x68,0x5c,0xa6,0x21 },
687     { 0x9b,0x5b,0x54,0xd1 }, { 0x24,0x36,0x2e,0x3a }, 
688     { 0x0c,0x0a,0x67,0xb1 }, { 0x93,0x57,0xe7,0x0f },
689     { 0xb4,0xee,0x96,0xd2 }, { 0x1b,0x9b,0x91,0x9e }, 
690     { 0x80,0xc0,0xc5,0x4f }, { 0x61,0xdc,0x20,0xa2 },
691     { 0x5a,0x77,0x4b,0x69 }, { 0x1c,0x12,0x1a,0x16 }, 
692     { 0xe2,0x93,0xba,0x0a }, { 0xc0,0xa0,0x2a,0xe5 }, 
693     { 0x3c,0x22,0xe0,0x43 }, { 0x12,0x1b,0x17,0x1d }, 
694     { 0x0e,0x09,0x0d,0x0b }, { 0xf2,0x8b,0xc7,0xad }, 
695     { 0x2d,0xb6,0xa8,0xb9 }, { 0x14,0x1e,0xa9,0xc8 }, 
696     { 0x57,0xf1,0x19,0x85 }, { 0xaf,0x75,0x07,0x4c }, 
697     { 0xee,0x99,0xdd,0xbb }, { 0xa3,0x7f,0x60,0xfd }, 
698     { 0xf7,0x01,0x26,0x9f }, { 0x5c,0x72,0xf5,0xbc },
699     { 0x44,0x66,0x3b,0xc5 }, { 0x5b,0xfb,0x7e,0x34 }, 
700     { 0x8b,0x43,0x29,0x76 }, { 0xcb,0x23,0xc6,0xdc },
701     { 0xb6,0xed,0xfc,0x68 }, { 0xb8,0xe4,0xf1,0x63 }, 
702     { 0xd7,0x31,0xdc,0xca }, { 0x42,0x63,0x85,0x10 },
703     { 0x13,0x97,0x22,0x40 }, { 0x84,0xc6,0x11,0x20 }, 
704     { 0x85,0x4a,0x24,0x7d }, { 0xd2,0xbb,0x3d,0xf8 }, 
705     { 0xae,0xf9,0x32,0x11 }, { 0xc7,0x29,0xa1,0x6d }, 
706     { 0x1d,0x9e,0x2f,0x4b }, { 0xdc,0xb2,0x30,0xf3 },
707     { 0x0d,0x86,0x52,0xec }, { 0x77,0xc1,0xe3,0xd0 }, 
708     { 0x2b,0xb3,0x16,0x6c }, { 0xa9,0x70,0xb9,0x99 },
709     { 0x11,0x94,0x48,0xfa }, { 0x47,0xe9,0x64,0x22 }, 
710     { 0xa8,0xfc,0x8c,0xc4 }, { 0xa0,0xf0,0x3f,0x1a },
711     { 0x56,0x7d,0x2c,0xd8 }, { 0x22,0x33,0x90,0xef }, 
712     { 0x87,0x49,0x4e,0xc7 }, { 0xd9,0x38,0xd1,0xc1 }, 
713     { 0x8c,0xca,0xa2,0xfe }, { 0x98,0xd4,0x0b,0x36 }, 
714     { 0xa6,0xf5,0x81,0xcf }, { 0xa5,0x7a,0xde,0x28 }, 
715     { 0xda,0xb7,0x8e,0x26 }, { 0x3f,0xad,0xbf,0xa4 }, 
716     { 0x2c,0x3a,0x9d,0xe4 }, { 0x50,0x78,0x92,0x0d }, 
717     { 0x6a,0x5f,0xcc,0x9b }, { 0x54,0x7e,0x46,0x62 }, 
718     { 0xf6,0x8d,0x13,0xc2 }, { 0x90,0xd8,0xb8,0xe8 }, 
719     { 0x2e,0x39,0xf7,0x5e }, { 0x82,0xc3,0xaf,0xf5 }, 
720     { 0x9f,0x5d,0x80,0xbe }, { 0x69,0xd0,0x93,0x7c },
721     { 0x6f,0xd5,0x2d,0xa9 }, { 0xcf,0x25,0x12,0xb3 }, 
722     { 0xc8,0xac,0x99,0x3b }, { 0x10,0x18,0x7d,0xa7 },
723     { 0xe8,0x9c,0x63,0x6e }, { 0xdb,0x3b,0xbb,0x7b }, 
724     { 0xcd,0x26,0x78,0x09 }, { 0x6e,0x59,0x18,0xf4 },
725     { 0xec,0x9a,0xb7,0x01 }, { 0x83,0x4f,0x9a,0xa8 }, 
726     { 0xe6,0x95,0x6e,0x65 }, { 0xaa,0xff,0xe6,0x7e }, 
727     { 0x21,0xbc,0xcf,0x08 }, { 0xef,0x15,0xe8,0xe6 }, 
728     { 0xba,0xe7,0x9b,0xd9 }, { 0x4a,0x6f,0x36,0xce }, 
729     { 0xea,0x9f,0x09,0xd4 }, { 0x29,0xb0,0x7c,0xd6 }, 
730     { 0x31,0xa4,0xb2,0xaf }, { 0x2a,0x3f,0x23,0x31 }, 
731     { 0xc6,0xa5,0x94,0x30 }, { 0x35,0xa2,0x66,0xc0 }, 
732     { 0x74,0x4e,0xbc,0x37 }, { 0xfc,0x82,0xca,0xa6 }, 
733     { 0xe0,0x90,0xd0,0xb0 }, { 0x33,0xa7,0xd8,0x15 }, 
734     { 0xf1,0x04,0x98,0x4a }, { 0x41,0xec,0xda,0xf7 },
735     { 0x7f,0xcd,0x50,0x0e }, { 0x17,0x91,0xf6,0x2f }, 
736     { 0x76,0x4d,0xd6,0x8d }, { 0x43,0xef,0xb0,0x4d },
737     { 0xcc,0xaa,0x4d,0x54 }, { 0xe4,0x96,0x04,0xdf }, 
738     { 0x9e,0xd1,0xb5,0xe3 }, { 0x4c,0x6a,0x88,0x1b },
739     { 0xc1,0x2c,0x1f,0xb8 }, { 0x46,0x65,0x51,0x7f }, 
740     { 0x9d,0x5e,0xea,0x04 }, { 0x01,0x8c,0x35,0x5d },
741     { 0xfa,0x87,0x74,0x73 }, { 0xfb,0x0b,0x41,0x2e }, 
742     { 0xb3,0x67,0x1d,0x5a }, { 0x92,0xdb,0xd2,0x52 },
743     { 0xe9,0x10,0x56,0x33 }, { 0x6d,0xd6,0x47,0x13 }, 
744     { 0x9a,0xd7,0x61,0x8c }, { 0x37,0xa1,0x0c,0x7a },
745     { 0x59,0xf8,0x14,0x8e }, { 0xeb,0x13,0x3c,0x89 }, 
746     { 0xce,0xa9,0x27,0xee }, { 0xb7,0x61,0xc9,0x35 },
747     { 0xe1,0x1c,0xe5,0xed }, { 0x7a,0x47,0xb1,0x3c }, 
748     { 0x9c,0xd2,0xdf,0x59 }, { 0x55,0xf2,0x73,0x3f }, 
749     { 0x18,0x14,0xce,0x79 }, { 0x73,0xc7,0x37,0xbf }, 
750     { 0x53,0xf7,0xcd,0xea }, { 0x5f,0xfd,0xaa,0x5b },
751     { 0xdf,0x3d,0x6f,0x14 }, { 0x78,0x44,0xdb,0x86 }, 
752     { 0xca,0xaf,0xf3,0x81 }, { 0xb9,0x68,0xc4,0x3e }, 
753     { 0x38,0x24,0x34,0x2c }, { 0xc2,0xa3,0x40,0x5f }, 
754     { 0x16,0x1d,0xc3,0x72 }, { 0xbc,0xe2,0x25,0x0c }, 
755     { 0x28,0x3c,0x49,0x8b }, { 0xff,0x0d,0x95,0x41 }, 
756     { 0x39,0xa8,0x01,0x71 }, { 0x08,0x0c,0xb3,0xde }, 
757     { 0xd8,0xb4,0xe4,0x9c }, { 0x64,0x56,0xc1,0x90 }, 
758     { 0x7b,0xcb,0x84,0x61 }, { 0xd5,0x32,0xb6,0x70 },
759     { 0x48,0x6c,0x5c,0x74 }, { 0xd0,0xb8,0x57,0x42 }
760 };
761
762 static const byte T6[256][4] = {
763     { 0x50,0x51,0xf4,0xa7 }, { 0x53,0x7e,0x41,0x65 }, 
764     { 0xc3,0x1a,0x17,0xa4 }, { 0x96,0x3a,0x27,0x5e }, 
765     { 0xcb,0x3b,0xab,0x6b }, { 0xf1,0x1f,0x9d,0x45 },
766     { 0xab,0xac,0xfa,0x58 }, { 0x93,0x4b,0xe3,0x03 }, 
767     { 0x55,0x20,0x30,0xfa }, { 0xf6,0xad,0x76,0x6d },
768     { 0x91,0x88,0xcc,0x76 }, { 0x25,0xf5,0x02,0x4c }, 
769     { 0xfc,0x4f,0xe5,0xd7 }, { 0xd7,0xc5,0x2a,0xcb },
770     { 0x80,0x26,0x35,0x44 }, { 0x8f,0xb5,0x62,0xa3 }, 
771     { 0x49,0xde,0xb1,0x5a }, { 0x67,0x25,0xba,0x1b }, 
772     { 0x98,0x45,0xea,0x0e }, { 0xe1,0x5d,0xfe,0xc0 }, 
773     { 0x02,0xc3,0x2f,0x75 }, { 0x12,0x81,0x4c,0xf0 },
774     { 0xa3,0x8d,0x46,0x97 }, { 0xc6,0x6b,0xd3,0xf9 }, 
775     { 0xe7,0x03,0x8f,0x5f }, { 0x95,0x15,0x92,0x9c },
776     { 0xeb,0xbf,0x6d,0x7a }, { 0xda,0x95,0x52,0x59 }, 
777     { 0x2d,0xd4,0xbe,0x83 }, { 0xd3,0x58,0x74,0x21 },
778     { 0x29,0x49,0xe0,0x69 }, { 0x44,0x8e,0xc9,0xc8 }, 
779     { 0x6a,0x75,0xc2,0x89 }, { 0x78,0xf4,0x8e,0x79 },
780     { 0x6b,0x99,0x58,0x3e }, { 0xdd,0x27,0xb9,0x71 }, 
781     { 0xb6,0xbe,0xe1,0x4f }, { 0x17,0xf0,0x88,0xad },
782     { 0x66,0xc9,0x20,0xac }, { 0xb4,0x7d,0xce,0x3a }, 
783     { 0x18,0x63,0xdf,0x4a }, { 0x82,0xe5,0x1a,0x31 },
784     { 0x60,0x97,0x51,0x33 }, { 0x45,0x62,0x53,0x7f }, 
785     { 0xe0,0xb1,0x64,0x77 }, { 0x84,0xbb,0x6b,0xae },
786     { 0x1c,0xfe,0x81,0xa0 }, { 0x94,0xf9,0x08,0x2b }, 
787     { 0x58,0x70,0x48,0x68 }, { 0x19,0x8f,0x45,0xfd },
788     { 0x87,0x94,0xde,0x6c }, { 0xb7,0x52,0x7b,0xf8 }, 
789     { 0x23,0xab,0x73,0xd3 }, { 0xe2,0x72,0x4b,0x02 },
790     { 0x57,0xe3,0x1f,0x8f }, { 0x2a,0x66,0x55,0xab }, 
791     { 0x07,0xb2,0xeb,0x28 }, { 0x03,0x2f,0xb5,0xc2 },
792     { 0x9a,0x86,0xc5,0x7b }, { 0xa5,0xd3,0x37,0x08 }, 
793     { 0xf2,0x30,0x28,0x87 }, { 0xb2,0x23,0xbf,0xa5 },
794     { 0xba,0x02,0x03,0x6a }, { 0x5c,0xed,0x16,0x82 }, 
795     { 0x2b,0x8a,0xcf,0x1c }, { 0x92,0xa7,0x79,0xb4 },
796     { 0xf0,0xf3,0x07,0xf2 }, { 0xa1,0x4e,0x69,0xe2 }, 
797     { 0xcd,0x65,0xda,0xf4 }, { 0xd5,0x06,0x05,0xbe },
798     { 0x1f,0xd1,0x34,0x62 }, { 0x8a,0xc4,0xa6,0xfe }, 
799     { 0x9d,0x34,0x2e,0x53 }, { 0xa0,0xa2,0xf3,0x55 },
800     { 0x32,0x05,0x8a,0xe1 }, { 0x75,0xa4,0xf6,0xeb }, 
801     { 0x39,0x0b,0x83,0xec }, { 0xaa,0x40,0x60,0xef },
802     { 0x06,0x5e,0x71,0x9f }, { 0x51,0xbd,0x6e,0x10 }, 
803     { 0xf9,0x3e,0x21,0x8a }, { 0x3d,0x96,0xdd,0x06 },
804     { 0xae,0xdd,0x3e,0x05 }, { 0x46,0x4d,0xe6,0xbd }, 
805     { 0xb5,0x91,0x54,0x8d }, { 0x05,0x71,0xc4,0x5d },
806     { 0x6f,0x04,0x06,0xd4 }, { 0xff,0x60,0x50,0x15 }, 
807     { 0x24,0x19,0x98,0xfb }, { 0x97,0xd6,0xbd,0xe9 },
808     { 0xcc,0x89,0x40,0x43 }, { 0x77,0x67,0xd9,0x9e }, 
809     { 0xbd,0xb0,0xe8,0x42 }, { 0x88,0x07,0x89,0x8b },
810     { 0x38,0xe7,0x19,0x5b }, { 0xdb,0x79,0xc8,0xee }, 
811     { 0x47,0xa1,0x7c,0x0a }, { 0xe9,0x7c,0x42,0x0f },
812     { 0xc9,0xf8,0x84,0x1e }, { 0x00,0x00,0x00,0x00 }, 
813     { 0x83,0x09,0x80,0x86 }, { 0x48,0x32,0x2b,0xed },
814     { 0xac,0x1e,0x11,0x70 }, { 0x4e,0x6c,0x5a,0x72 }, 
815     { 0xfb,0xfd,0x0e,0xff }, { 0x56,0x0f,0x85,0x38 },
816     { 0x1e,0x3d,0xae,0xd5 }, { 0x27,0x36,0x2d,0x39 }, 
817     { 0x64,0x0a,0x0f,0xd9 }, { 0x21,0x68,0x5c,0xa6 },
818     { 0xd1,0x9b,0x5b,0x54 }, { 0x3a,0x24,0x36,0x2e }, 
819     { 0xb1,0x0c,0x0a,0x67 }, { 0x0f,0x93,0x57,0xe7 },
820     { 0xd2,0xb4,0xee,0x96 }, { 0x9e,0x1b,0x9b,0x91 }, 
821     { 0x4f,0x80,0xc0,0xc5 }, { 0xa2,0x61,0xdc,0x20 }, 
822     { 0x69,0x5a,0x77,0x4b }, { 0x16,0x1c,0x12,0x1a }, 
823     { 0x0a,0xe2,0x93,0xba }, { 0xe5,0xc0,0xa0,0x2a },
824     { 0x43,0x3c,0x22,0xe0 }, { 0x1d,0x12,0x1b,0x17 }, 
825     { 0x0b,0x0e,0x09,0x0d }, { 0xad,0xf2,0x8b,0xc7 },
826     { 0xb9,0x2d,0xb6,0xa8 }, { 0xc8,0x14,0x1e,0xa9 }, 
827     { 0x85,0x57,0xf1,0x19 }, { 0x4c,0xaf,0x75,0x07 },
828     { 0xbb,0xee,0x99,0xdd }, { 0xfd,0xa3,0x7f,0x60 }, 
829     { 0x9f,0xf7,0x01,0x26 }, { 0xbc,0x5c,0x72,0xf5 },
830     { 0xc5,0x44,0x66,0x3b }, { 0x34,0x5b,0xfb,0x7e }, 
831     { 0x76,0x8b,0x43,0x29 }, { 0xdc,0xcb,0x23,0xc6 },
832     { 0x68,0xb6,0xed,0xfc }, { 0x63,0xb8,0xe4,0xf1 }, 
833     { 0xca,0xd7,0x31,0xdc }, { 0x10,0x42,0x63,0x85 },
834     { 0x40,0x13,0x97,0x22 }, { 0x20,0x84,0xc6,0x11 }, 
835     { 0x7d,0x85,0x4a,0x24 }, { 0xf8,0xd2,0xbb,0x3d },
836     { 0x11,0xae,0xf9,0x32 }, { 0x6d,0xc7,0x29,0xa1 }, 
837     { 0x4b,0x1d,0x9e,0x2f }, { 0xf3,0xdc,0xb2,0x30 },
838     { 0xec,0x0d,0x86,0x52 }, { 0xd0,0x77,0xc1,0xe3 }, 
839     { 0x6c,0x2b,0xb3,0x16 }, { 0x99,0xa9,0x70,0xb9 }, 
840     { 0xfa,0x11,0x94,0x48 }, { 0x22,0x47,0xe9,0x64 }, 
841     { 0xc4,0xa8,0xfc,0x8c }, { 0x1a,0xa0,0xf0,0x3f }, 
842     { 0xd8,0x56,0x7d,0x2c }, { 0xef,0x22,0x33,0x90 }, 
843     { 0xc7,0x87,0x49,0x4e }, { 0xc1,0xd9,0x38,0xd1 },
844     { 0xfe,0x8c,0xca,0xa2 }, { 0x36,0x98,0xd4,0x0b }, 
845     { 0xcf,0xa6,0xf5,0x81 }, { 0x28,0xa5,0x7a,0xde }, 
846     { 0x26,0xda,0xb7,0x8e }, { 0xa4,0x3f,0xad,0xbf }, 
847     { 0xe4,0x2c,0x3a,0x9d }, { 0x0d,0x50,0x78,0x92 }, 
848     { 0x9b,0x6a,0x5f,0xcc }, { 0x62,0x54,0x7e,0x46 }, 
849     { 0xc2,0xf6,0x8d,0x13 }, { 0xe8,0x90,0xd8,0xb8 }, 
850     { 0x5e,0x2e,0x39,0xf7 }, { 0xf5,0x82,0xc3,0xaf }, 
851     { 0xbe,0x9f,0x5d,0x80 }, { 0x7c,0x69,0xd0,0x93 },
852     { 0xa9,0x6f,0xd5,0x2d }, { 0xb3,0xcf,0x25,0x12 }, 
853     { 0x3b,0xc8,0xac,0x99 }, { 0xa7,0x10,0x18,0x7d }, 
854     { 0x6e,0xe8,0x9c,0x63 }, { 0x7b,0xdb,0x3b,0xbb }, 
855     { 0x09,0xcd,0x26,0x78 }, { 0xf4,0x6e,0x59,0x18 },
856     { 0x01,0xec,0x9a,0xb7 }, { 0xa8,0x83,0x4f,0x9a }, 
857     { 0x65,0xe6,0x95,0x6e }, { 0x7e,0xaa,0xff,0xe6 }, 
858     { 0x08,0x21,0xbc,0xcf }, { 0xe6,0xef,0x15,0xe8 }, 
859     { 0xd9,0xba,0xe7,0x9b }, { 0xce,0x4a,0x6f,0x36 },
860     { 0xd4,0xea,0x9f,0x09 }, { 0xd6,0x29,0xb0,0x7c }, 
861     { 0xaf,0x31,0xa4,0xb2 }, { 0x31,0x2a,0x3f,0x23 },
862     { 0x30,0xc6,0xa5,0x94 }, { 0xc0,0x35,0xa2,0x66 }, 
863     { 0x37,0x74,0x4e,0xbc }, { 0xa6,0xfc,0x82,0xca }, 
864     { 0xb0,0xe0,0x90,0xd0 }, { 0x15,0x33,0xa7,0xd8 }, 
865     { 0x4a,0xf1,0x04,0x98 }, { 0xf7,0x41,0xec,0xda },
866     { 0x0e,0x7f,0xcd,0x50 }, { 0x2f,0x17,0x91,0xf6 }, 
867     { 0x8d,0x76,0x4d,0xd6 }, { 0x4d,0x43,0xef,0xb0 },
868     { 0x54,0xcc,0xaa,0x4d }, { 0xdf,0xe4,0x96,0x04 }, 
869     { 0xe3,0x9e,0xd1,0xb5 }, { 0x1b,0x4c,0x6a,0x88 },
870     { 0xb8,0xc1,0x2c,0x1f }, { 0x7f,0x46,0x65,0x51 }, 
871     { 0x04,0x9d,0x5e,0xea }, { 0x5d,0x01,0x8c,0x35 },
872     { 0x73,0xfa,0x87,0x74 }, { 0x2e,0xfb,0x0b,0x41 }, 
873     { 0x5a,0xb3,0x67,0x1d }, { 0x52,0x92,0xdb,0xd2 },
874     { 0x33,0xe9,0x10,0x56 }, { 0x13,0x6d,0xd6,0x47 }, 
875     { 0x8c,0x9a,0xd7,0x61 }, { 0x7a,0x37,0xa1,0x0c }, 
876     { 0x8e,0x59,0xf8,0x14 }, { 0x89,0xeb,0x13,0x3c }, 
877     { 0xee,0xce,0xa9,0x27 }, { 0x35,0xb7,0x61,0xc9 },
878     { 0xed,0xe1,0x1c,0xe5 }, { 0x3c,0x7a,0x47,0xb1 }, 
879     { 0x59,0x9c,0xd2,0xdf }, { 0x3f,0x55,0xf2,0x73 },
880     { 0x79,0x18,0x14,0xce }, { 0xbf,0x73,0xc7,0x37 }, 
881     { 0xea,0x53,0xf7,0xcd }, { 0x5b,0x5f,0xfd,0xaa },
882     { 0x14,0xdf,0x3d,0x6f }, { 0x86,0x78,0x44,0xdb }, 
883     { 0x81,0xca,0xaf,0xf3 }, { 0x3e,0xb9,0x68,0xc4 },
884     { 0x2c,0x38,0x24,0x34 }, { 0x5f,0xc2,0xa3,0x40 }, 
885     { 0x72,0x16,0x1d,0xc3 }, { 0x0c,0xbc,0xe2,0x25 },
886     { 0x8b,0x28,0x3c,0x49 }, { 0x41,0xff,0x0d,0x95 }, 
887     { 0x71,0x39,0xa8,0x01 }, { 0xde,0x08,0x0c,0xb3 },
888     { 0x9c,0xd8,0xb4,0xe4 }, { 0x90,0x64,0x56,0xc1 }, 
889     { 0x61,0x7b,0xcb,0x84 }, { 0x70,0xd5,0x32,0xb6 },
890     { 0x74,0x48,0x6c,0x5c }, { 0x42,0xd0,0xb8,0x57 }
891 };
892
893 static const byte T7[256][4] = {
894     { 0xa7,0x50,0x51,0xf4 }, { 0x65,0x53,0x7e,0x41 },
895     { 0xa4,0xc3,0x1a,0x17 }, { 0x5e,0x96,0x3a,0x27 }, 
896     { 0x6b,0xcb,0x3b,0xab }, { 0x45,0xf1,0x1f,0x9d },
897     { 0x58,0xab,0xac,0xfa }, { 0x03,0x93,0x4b,0xe3 }, 
898     { 0xfa,0x55,0x20,0x30 }, { 0x6d,0xf6,0xad,0x76 },
899     { 0x76,0x91,0x88,0xcc }, { 0x4c,0x25,0xf5,0x02 }, 
900     { 0xd7,0xfc,0x4f,0xe5 }, { 0xcb,0xd7,0xc5,0x2a },
901     { 0x44,0x80,0x26,0x35 }, { 0xa3,0x8f,0xb5,0x62 }, 
902     { 0x5a,0x49,0xde,0xb1 }, { 0x1b,0x67,0x25,0xba }, 
903     { 0x0e,0x98,0x45,0xea }, { 0xc0,0xe1,0x5d,0xfe }, 
904     { 0x75,0x02,0xc3,0x2f }, { 0xf0,0x12,0x81,0x4c },
905     { 0x97,0xa3,0x8d,0x46 }, { 0xf9,0xc6,0x6b,0xd3 }, 
906     { 0x5f,0xe7,0x03,0x8f }, { 0x9c,0x95,0x15,0x92 },
907     { 0x7a,0xeb,0xbf,0x6d }, { 0x59,0xda,0x95,0x52 }, 
908     { 0x83,0x2d,0xd4,0xbe }, { 0x21,0xd3,0x58,0x74 },
909     { 0x69,0x29,0x49,0xe0 }, { 0xc8,0x44,0x8e,0xc9 }, 
910     { 0x89,0x6a,0x75,0xc2 }, { 0x79,0x78,0xf4,0x8e }, 
911     { 0x3e,0x6b,0x99,0x58 }, { 0x71,0xdd,0x27,0xb9 }, 
912     { 0x4f,0xb6,0xbe,0xe1 }, { 0xad,0x17,0xf0,0x88 },
913     { 0xac,0x66,0xc9,0x20 }, { 0x3a,0xb4,0x7d,0xce }, 
914     { 0x4a,0x18,0x63,0xdf }, { 0x31,0x82,0xe5,0x1a },
915     { 0x33,0x60,0x97,0x51 }, { 0x7f,0x45,0x62,0x53 }, 
916     { 0x77,0xe0,0xb1,0x64 }, { 0xae,0x84,0xbb,0x6b },
917     { 0xa0,0x1c,0xfe,0x81 }, { 0x2b,0x94,0xf9,0x08 }, 
918     { 0x68,0x58,0x70,0x48 }, { 0xfd,0x19,0x8f,0x45 },
919     { 0x6c,0x87,0x94,0xde }, { 0xf8,0xb7,0x52,0x7b }, 
920     { 0xd3,0x23,0xab,0x73 }, { 0x02,0xe2,0x72,0x4b },
921     { 0x8f,0x57,0xe3,0x1f }, { 0xab,0x2a,0x66,0x55 }, 
922     { 0x28,0x07,0xb2,0xeb }, { 0xc2,0x03,0x2f,0xb5 },
923     { 0x7b,0x9a,0x86,0xc5 }, { 0x08,0xa5,0xd3,0x37 }, 
924     { 0x87,0xf2,0x30,0x28 }, { 0xa5,0xb2,0x23,0xbf },
925     { 0x6a,0xba,0x02,0x03 }, { 0x82,0x5c,0xed,0x16 }, 
926     { 0x1c,0x2b,0x8a,0xcf }, { 0xb4,0x92,0xa7,0x79 }, 
927     { 0xf2,0xf0,0xf3,0x07 }, { 0xe2,0xa1,0x4e,0x69 }, 
928     { 0xf4,0xcd,0x65,0xda }, { 0xbe,0xd5,0x06,0x05 },
929     { 0x62,0x1f,0xd1,0x34 }, { 0xfe,0x8a,0xc4,0xa6 }, 
930     { 0x53,0x9d,0x34,0x2e }, { 0x55,0xa0,0xa2,0xf3 },
931     { 0xe1,0x32,0x05,0x8a }, { 0xeb,0x75,0xa4,0xf6 }, 
932     { 0xec,0x39,0x0b,0x83 }, { 0xef,0xaa,0x40,0x60 },
933     { 0x9f,0x06,0x5e,0x71 }, { 0x10,0x51,0xbd,0x6e }, 
934     { 0x8a,0xf9,0x3e,0x21 }, { 0x06,0x3d,0x96,0xdd },
935     { 0x05,0xae,0xdd,0x3e }, { 0xbd,0x46,0x4d,0xe6 }, 
936     { 0x8d,0xb5,0x91,0x54 }, { 0x5d,0x05,0x71,0xc4 },
937     { 0xd4,0x6f,0x04,0x06 }, { 0x15,0xff,0x60,0x50 }, 
938     { 0xfb,0x24,0x19,0x98 }, { 0xe9,0x97,0xd6,0xbd }, 
939     { 0x43,0xcc,0x89,0x40 }, { 0x9e,0x77,0x67,0xd9 }, 
940     { 0x42,0xbd,0xb0,0xe8 }, { 0x8b,0x88,0x07,0x89 },
941     { 0x5b,0x38,0xe7,0x19 }, { 0xee,0xdb,0x79,0xc8 }, 
942     { 0x0a,0x47,0xa1,0x7c }, { 0x0f,0xe9,0x7c,0x42 },
943     { 0x1e,0xc9,0xf8,0x84 }, { 0x00,0x00,0x00,0x00 }, 
944     { 0x86,0x83,0x09,0x80 }, { 0xed,0x48,0x32,0x2b },
945     { 0x70,0xac,0x1e,0x11 }, { 0x72,0x4e,0x6c,0x5a }, 
946     { 0xff,0xfb,0xfd,0x0e }, { 0x38,0x56,0x0f,0x85 },
947     { 0xd5,0x1e,0x3d,0xae }, { 0x39,0x27,0x36,0x2d }, 
948     { 0xd9,0x64,0x0a,0x0f }, { 0xa6,0x21,0x68,0x5c },
949     { 0x54,0xd1,0x9b,0x5b }, { 0x2e,0x3a,0x24,0x36 }, 
950     { 0x67,0xb1,0x0c,0x0a }, { 0xe7,0x0f,0x93,0x57 },
951     { 0x96,0xd2,0xb4,0xee }, { 0x91,0x9e,0x1b,0x9b }, 
952     { 0xc5,0x4f,0x80,0xc0 }, { 0x20,0xa2,0x61,0xdc },
953     { 0x4b,0x69,0x5a,0x77 }, { 0x1a,0x16,0x1c,0x12 }, 
954     { 0xba,0x0a,0xe2,0x93 }, { 0x2a,0xe5,0xc0,0xa0 },
955     { 0xe0,0x43,0x3c,0x22 }, { 0x17,0x1d,0x12,0x1b }, 
956     { 0x0d,0x0b,0x0e,0x09 }, { 0xc7,0xad,0xf2,0x8b },
957     { 0xa8,0xb9,0x2d,0xb6 }, { 0xa9,0xc8,0x14,0x1e }, 
958     { 0x19,0x85,0x57,0xf1 }, { 0x07,0x4c,0xaf,0x75 },
959     { 0xdd,0xbb,0xee,0x99 }, { 0x60,0xfd,0xa3,0x7f }, 
960     { 0x26,0x9f,0xf7,0x01 }, { 0xf5,0xbc,0x5c,0x72 },
961     { 0x3b,0xc5,0x44,0x66 }, { 0x7e,0x34,0x5b,0xfb }, 
962     { 0x29,0x76,0x8b,0x43 }, { 0xc6,0xdc,0xcb,0x23 },
963     { 0xfc,0x68,0xb6,0xed }, { 0xf1,0x63,0xb8,0xe4 }, 
964     { 0xdc,0xca,0xd7,0x31 }, { 0x85,0x10,0x42,0x63 },
965     { 0x22,0x40,0x13,0x97 }, { 0x11,0x20,0x84,0xc6 }, 
966     { 0x24,0x7d,0x85,0x4a }, { 0x3d,0xf8,0xd2,0xbb },
967     { 0x32,0x11,0xae,0xf9 }, { 0xa1,0x6d,0xc7,0x29 }, 
968     { 0x2f,0x4b,0x1d,0x9e }, { 0x30,0xf3,0xdc,0xb2 },
969     { 0x52,0xec,0x0d,0x86 }, { 0xe3,0xd0,0x77,0xc1 }, 
970     { 0x16,0x6c,0x2b,0xb3 }, { 0xb9,0x99,0xa9,0x70 },
971     { 0x48,0xfa,0x11,0x94 }, { 0x64,0x22,0x47,0xe9 }, 
972     { 0x8c,0xc4,0xa8,0xfc }, { 0x3f,0x1a,0xa0,0xf0 },
973     { 0x2c,0xd8,0x56,0x7d }, { 0x90,0xef,0x22,0x33 }, 
974     { 0x4e,0xc7,0x87,0x49 }, { 0xd1,0xc1,0xd9,0x38 },
975     { 0xa2,0xfe,0x8c,0xca }, { 0x0b,0x36,0x98,0xd4 }, 
976     { 0x81,0xcf,0xa6,0xf5 }, { 0xde,0x28,0xa5,0x7a },
977     { 0x8e,0x26,0xda,0xb7 }, { 0xbf,0xa4,0x3f,0xad }, 
978     { 0x9d,0xe4,0x2c,0x3a }, { 0x92,0x0d,0x50,0x78 },
979     { 0xcc,0x9b,0x6a,0x5f }, { 0x46,0x62,0x54,0x7e }, 
980     { 0x13,0xc2,0xf6,0x8d }, { 0xb8,0xe8,0x90,0xd8 },
981     { 0xf7,0x5e,0x2e,0x39 }, { 0xaf,0xf5,0x82,0xc3 }, 
982     { 0x80,0xbe,0x9f,0x5d }, { 0x93,0x7c,0x69,0xd0 },
983     { 0x2d,0xa9,0x6f,0xd5 }, { 0x12,0xb3,0xcf,0x25 }, 
984     { 0x99,0x3b,0xc8,0xac }, { 0x7d,0xa7,0x10,0x18 },
985     { 0x63,0x6e,0xe8,0x9c }, { 0xbb,0x7b,0xdb,0x3b }, 
986     { 0x78,0x09,0xcd,0x26 }, { 0x18,0xf4,0x6e,0x59 }, 
987     { 0xb7,0x01,0xec,0x9a }, { 0x9a,0xa8,0x83,0x4f }, 
988     { 0x6e,0x65,0xe6,0x95 }, { 0xe6,0x7e,0xaa,0xff },
989     { 0xcf,0x08,0x21,0xbc }, { 0xe8,0xe6,0xef,0x15 }, 
990     { 0x9b,0xd9,0xba,0xe7 }, { 0x36,0xce,0x4a,0x6f },
991     { 0x09,0xd4,0xea,0x9f }, { 0x7c,0xd6,0x29,0xb0 }, 
992     { 0xb2,0xaf,0x31,0xa4 }, { 0x23,0x31,0x2a,0x3f },
993     { 0x94,0x30,0xc6,0xa5 }, { 0x66,0xc0,0x35,0xa2 }, 
994     { 0xbc,0x37,0x74,0x4e }, { 0xca,0xa6,0xfc,0x82 },
995     { 0xd0,0xb0,0xe0,0x90 }, { 0xd8,0x15,0x33,0xa7 }, 
996     { 0x98,0x4a,0xf1,0x04 }, { 0xda,0xf7,0x41,0xec },
997     { 0x50,0x0e,0x7f,0xcd }, { 0xf6,0x2f,0x17,0x91 }, 
998     { 0xd6,0x8d,0x76,0x4d }, { 0xb0,0x4d,0x43,0xef }, 
999     { 0x4d,0x54,0xcc,0xaa }, { 0x04,0xdf,0xe4,0x96 }, 
1000     { 0xb5,0xe3,0x9e,0xd1 }, { 0x88,0x1b,0x4c,0x6a },
1001     { 0x1f,0xb8,0xc1,0x2c }, { 0x51,0x7f,0x46,0x65 }, 
1002     { 0xea,0x04,0x9d,0x5e }, { 0x35,0x5d,0x01,0x8c },
1003     { 0x74,0x73,0xfa,0x87 }, { 0x41,0x2e,0xfb,0x0b }, 
1004     { 0x1d,0x5a,0xb3,0x67 }, { 0xd2,0x52,0x92,0xdb },
1005     { 0x56,0x33,0xe9,0x10 }, { 0x47,0x13,0x6d,0xd6 }, 
1006     { 0x61,0x8c,0x9a,0xd7 }, { 0x0c,0x7a,0x37,0xa1 },
1007     { 0x14,0x8e,0x59,0xf8 }, { 0x3c,0x89,0xeb,0x13 }, 
1008     { 0x27,0xee,0xce,0xa9 }, { 0xc9,0x35,0xb7,0x61 },
1009     { 0xe5,0xed,0xe1,0x1c }, { 0xb1,0x3c,0x7a,0x47 }, 
1010     { 0xdf,0x59,0x9c,0xd2 }, { 0x73,0x3f,0x55,0xf2 },
1011     { 0xce,0x79,0x18,0x14 }, { 0x37,0xbf,0x73,0xc7 }, 
1012     { 0xcd,0xea,0x53,0xf7 }, { 0xaa,0x5b,0x5f,0xfd },
1013     { 0x6f,0x14,0xdf,0x3d }, { 0xdb,0x86,0x78,0x44 }, 
1014     { 0xf3,0x81,0xca,0xaf }, { 0xc4,0x3e,0xb9,0x68 },
1015     { 0x34,0x2c,0x38,0x24 }, { 0x40,0x5f,0xc2,0xa3 }, 
1016     { 0xc3,0x72,0x16,0x1d }, { 0x25,0x0c,0xbc,0xe2 },
1017     { 0x49,0x8b,0x28,0x3c }, { 0x95,0x41,0xff,0x0d }, 
1018     { 0x01,0x71,0x39,0xa8 }, { 0xb3,0xde,0x08,0x0c },
1019     { 0xe4,0x9c,0xd8,0xb4 }, { 0xc1,0x90,0x64,0x56 }, 
1020     { 0x84,0x61,0x7b,0xcb }, { 0xb6,0x70,0xd5,0x32 },
1021     { 0x5c,0x74,0x48,0x6c }, { 0x57,0x42,0xd0,0xb8 }
1022 };
1023
1024 static const byte  T8[256][4] = {
1025     { 0xf4,0xa7,0x50,0x51 }, { 0x41,0x65,0x53,0x7e },
1026     { 0x17,0xa4,0xc3,0x1a }, { 0x27,0x5e,0x96,0x3a }, 
1027     { 0xab,0x6b,0xcb,0x3b }, { 0x9d,0x45,0xf1,0x1f },
1028     { 0xfa,0x58,0xab,0xac }, { 0xe3,0x03,0x93,0x4b }, 
1029     { 0x30,0xfa,0x55,0x20 }, { 0x76,0x6d,0xf6,0xad },
1030     { 0xcc,0x76,0x91,0x88 }, { 0x02,0x4c,0x25,0xf5 }, 
1031     { 0xe5,0xd7,0xfc,0x4f }, { 0x2a,0xcb,0xd7,0xc5 },
1032     { 0x35,0x44,0x80,0x26 }, { 0x62,0xa3,0x8f,0xb5 }, 
1033     { 0xb1,0x5a,0x49,0xde }, { 0xba,0x1b,0x67,0x25 },
1034     { 0xea,0x0e,0x98,0x45 }, { 0xfe,0xc0,0xe1,0x5d }, 
1035     { 0x2f,0x75,0x02,0xc3 }, { 0x4c,0xf0,0x12,0x81 },
1036     { 0x46,0x97,0xa3,0x8d }, { 0xd3,0xf9,0xc6,0x6b }, 
1037     { 0x8f,0x5f,0xe7,0x03 }, { 0x92,0x9c,0x95,0x15 },
1038     { 0x6d,0x7a,0xeb,0xbf }, { 0x52,0x59,0xda,0x95 }, 
1039     { 0xbe,0x83,0x2d,0xd4 }, { 0x74,0x21,0xd3,0x58 },
1040     { 0xe0,0x69,0x29,0x49 }, { 0xc9,0xc8,0x44,0x8e }, 
1041     { 0xc2,0x89,0x6a,0x75 }, { 0x8e,0x79,0x78,0xf4 },
1042     { 0x58,0x3e,0x6b,0x99 }, { 0xb9,0x71,0xdd,0x27 }, 
1043     { 0xe1,0x4f,0xb6,0xbe }, { 0x88,0xad,0x17,0xf0 },
1044     { 0x20,0xac,0x66,0xc9 }, { 0xce,0x3a,0xb4,0x7d }, 
1045     { 0xdf,0x4a,0x18,0x63 }, { 0x1a,0x31,0x82,0xe5 },
1046     { 0x51,0x33,0x60,0x97 }, { 0x53,0x7f,0x45,0x62 }, 
1047     { 0x64,0x77,0xe0,0xb1 }, { 0x6b,0xae,0x84,0xbb },
1048     { 0x81,0xa0,0x1c,0xfe }, { 0x08,0x2b,0x94,0xf9 }, 
1049     { 0x48,0x68,0x58,0x70 }, { 0x45,0xfd,0x19,0x8f },
1050     { 0xde,0x6c,0x87,0x94 }, { 0x7b,0xf8,0xb7,0x52 }, 
1051     { 0x73,0xd3,0x23,0xab }, { 0x4b,0x02,0xe2,0x72 },
1052     { 0x1f,0x8f,0x57,0xe3 }, { 0x55,0xab,0x2a,0x66 }, 
1053     { 0xeb,0x28,0x07,0xb2 }, { 0xb5,0xc2,0x03,0x2f },
1054     { 0xc5,0x7b,0x9a,0x86 }, { 0x37,0x08,0xa5,0xd3 }, 
1055     { 0x28,0x87,0xf2,0x30 }, { 0xbf,0xa5,0xb2,0x23 },
1056     { 0x03,0x6a,0xba,0x02 }, { 0x16,0x82,0x5c,0xed }, 
1057     { 0xcf,0x1c,0x2b,0x8a }, { 0x79,0xb4,0x92,0xa7 },
1058     { 0x07,0xf2,0xf0,0xf3 }, { 0x69,0xe2,0xa1,0x4e }, 
1059     { 0xda,0xf4,0xcd,0x65 }, { 0x05,0xbe,0xd5,0x06 },
1060     { 0x34,0x62,0x1f,0xd1 }, { 0xa6,0xfe,0x8a,0xc4 }, 
1061     { 0x2e,0x53,0x9d,0x34 }, { 0xf3,0x55,0xa0,0xa2 },
1062     { 0x8a,0xe1,0x32,0x05 }, { 0xf6,0xeb,0x75,0xa4 }, 
1063     { 0x83,0xec,0x39,0x0b }, { 0x60,0xef,0xaa,0x40 },
1064     { 0x71,0x9f,0x06,0x5e }, { 0x6e,0x10,0x51,0xbd }, 
1065     { 0x21,0x8a,0xf9,0x3e }, { 0xdd,0x06,0x3d,0x96 },
1066     { 0x3e,0x05,0xae,0xdd }, { 0xe6,0xbd,0x46,0x4d }, 
1067     { 0x54,0x8d,0xb5,0x91 }, { 0xc4,0x5d,0x05,0x71 },
1068     { 0x06,0xd4,0x6f,0x04 }, { 0x50,0x15,0xff,0x60 }, 
1069     { 0x98,0xfb,0x24,0x19 }, { 0xbd,0xe9,0x97,0xd6 },
1070     { 0x40,0x43,0xcc,0x89 }, { 0xd9,0x9e,0x77,0x67 }, 
1071     { 0xe8,0x42,0xbd,0xb0 }, { 0x89,0x8b,0x88,0x07 },
1072     { 0x19,0x5b,0x38,0xe7 }, { 0xc8,0xee,0xdb,0x79 }, 
1073     { 0x7c,0x0a,0x47,0xa1 }, { 0x42,0x0f,0xe9,0x7c },
1074     { 0x84,0x1e,0xc9,0xf8 }, { 0x00,0x00,0x00,0x00 }, 
1075     { 0x80,0x86,0x83,0x09 }, { 0x2b,0xed,0x48,0x32 },
1076     { 0x11,0x70,0xac,0x1e }, { 0x5a,0x72,0x4e,0x6c }, 
1077     { 0x0e,0xff,0xfb,0xfd }, { 0x85,0x38,0x56,0x0f }, 
1078     { 0xae,0xd5,0x1e,0x3d }, { 0x2d,0x39,0x27,0x36 }, 
1079     { 0x0f,0xd9,0x64,0x0a }, { 0x5c,0xa6,0x21,0x68 },
1080     { 0x5b,0x54,0xd1,0x9b }, { 0x36,0x2e,0x3a,0x24 }, 
1081     { 0x0a,0x67,0xb1,0x0c }, { 0x57,0xe7,0x0f,0x93 },
1082     { 0xee,0x96,0xd2,0xb4 }, { 0x9b,0x91,0x9e,0x1b }, 
1083     { 0xc0,0xc5,0x4f,0x80 }, { 0xdc,0x20,0xa2,0x61 },
1084     { 0x77,0x4b,0x69,0x5a }, { 0x12,0x1a,0x16,0x1c }, 
1085     { 0x93,0xba,0x0a,0xe2 }, { 0xa0,0x2a,0xe5,0xc0 },
1086     { 0x22,0xe0,0x43,0x3c }, { 0x1b,0x17,0x1d,0x12 }, 
1087     { 0x09,0x0d,0x0b,0x0e }, { 0x8b,0xc7,0xad,0xf2 },
1088     { 0xb6,0xa8,0xb9,0x2d }, { 0x1e,0xa9,0xc8,0x14 }, 
1089     { 0xf1,0x19,0x85,0x57 }, { 0x75,0x07,0x4c,0xaf },
1090     { 0x99,0xdd,0xbb,0xee }, { 0x7f,0x60,0xfd,0xa3 }, 
1091     { 0x01,0x26,0x9f,0xf7 }, { 0x72,0xf5,0xbc,0x5c },
1092     { 0x66,0x3b,0xc5,0x44 }, { 0xfb,0x7e,0x34,0x5b }, 
1093     { 0x43,0x29,0x76,0x8b }, { 0x23,0xc6,0xdc,0xcb },
1094     { 0xed,0xfc,0x68,0xb6 }, { 0xe4,0xf1,0x63,0xb8 }, 
1095     { 0x31,0xdc,0xca,0xd7 }, { 0x63,0x85,0x10,0x42 },
1096     { 0x97,0x22,0x40,0x13 }, { 0xc6,0x11,0x20,0x84 }, 
1097     { 0x4a,0x24,0x7d,0x85 }, { 0xbb,0x3d,0xf8,0xd2 }, 
1098     { 0xf9,0x32,0x11,0xae }, { 0x29,0xa1,0x6d,0xc7 }, 
1099     { 0x9e,0x2f,0x4b,0x1d }, { 0xb2,0x30,0xf3,0xdc },
1100     { 0x86,0x52,0xec,0x0d }, { 0xc1,0xe3,0xd0,0x77 }, 
1101     { 0xb3,0x16,0x6c,0x2b }, { 0x70,0xb9,0x99,0xa9 },
1102     { 0x94,0x48,0xfa,0x11 }, { 0xe9,0x64,0x22,0x47 }, 
1103     { 0xfc,0x8c,0xc4,0xa8 }, { 0xf0,0x3f,0x1a,0xa0 },
1104     { 0x7d,0x2c,0xd8,0x56 }, { 0x33,0x90,0xef,0x22 }, 
1105     { 0x49,0x4e,0xc7,0x87 }, { 0x38,0xd1,0xc1,0xd9 },
1106     { 0xca,0xa2,0xfe,0x8c }, { 0xd4,0x0b,0x36,0x98 }, 
1107     { 0xf5,0x81,0xcf,0xa6 }, { 0x7a,0xde,0x28,0xa5 },
1108     { 0xb7,0x8e,0x26,0xda }, { 0xad,0xbf,0xa4,0x3f }, 
1109     { 0x3a,0x9d,0xe4,0x2c }, { 0x78,0x92,0x0d,0x50 },
1110     { 0x5f,0xcc,0x9b,0x6a }, { 0x7e,0x46,0x62,0x54 }, 
1111     { 0x8d,0x13,0xc2,0xf6 }, { 0xd8,0xb8,0xe8,0x90 },
1112     { 0x39,0xf7,0x5e,0x2e }, { 0xc3,0xaf,0xf5,0x82 }, 
1113     { 0x5d,0x80,0xbe,0x9f }, { 0xd0,0x93,0x7c,0x69 },
1114     { 0xd5,0x2d,0xa9,0x6f }, { 0x25,0x12,0xb3,0xcf }, 
1115     { 0xac,0x99,0x3b,0xc8 }, { 0x18,0x7d,0xa7,0x10 },
1116     { 0x9c,0x63,0x6e,0xe8 }, { 0x3b,0xbb,0x7b,0xdb }, 
1117     { 0x26,0x78,0x09,0xcd }, { 0x59,0x18,0xf4,0x6e },
1118     { 0x9a,0xb7,0x01,0xec }, { 0x4f,0x9a,0xa8,0x83 }, 
1119     { 0x95,0x6e,0x65,0xe6 }, { 0xff,0xe6,0x7e,0xaa },
1120     { 0xbc,0xcf,0x08,0x21 }, { 0x15,0xe8,0xe6,0xef }, 
1121     { 0xe7,0x9b,0xd9,0xba }, { 0x6f,0x36,0xce,0x4a },
1122     { 0x9f,0x09,0xd4,0xea }, { 0xb0,0x7c,0xd6,0x29 }, 
1123     { 0xa4,0xb2,0xaf,0x31 }, { 0x3f,0x23,0x31,0x2a },
1124     { 0xa5,0x94,0x30,0xc6 }, { 0xa2,0x66,0xc0,0x35 }, 
1125     { 0x4e,0xbc,0x37,0x74 }, { 0x82,0xca,0xa6,0xfc },
1126     { 0x90,0xd0,0xb0,0xe0 }, { 0xa7,0xd8,0x15,0x33 }, 
1127     { 0x04,0x98,0x4a,0xf1 }, { 0xec,0xda,0xf7,0x41 },
1128     { 0xcd,0x50,0x0e,0x7f }, { 0x91,0xf6,0x2f,0x17 }, 
1129     { 0x4d,0xd6,0x8d,0x76 }, { 0xef,0xb0,0x4d,0x43 }, 
1130     { 0xaa,0x4d,0x54,0xcc }, { 0x96,0x04,0xdf,0xe4 }, 
1131     { 0xd1,0xb5,0xe3,0x9e }, { 0x6a,0x88,0x1b,0x4c },
1132     { 0x2c,0x1f,0xb8,0xc1 }, { 0x65,0x51,0x7f,0x46 }, 
1133     { 0x5e,0xea,0x04,0x9d }, { 0x8c,0x35,0x5d,0x01 },
1134     { 0x87,0x74,0x73,0xfa }, { 0x0b,0x41,0x2e,0xfb }, 
1135     { 0x67,0x1d,0x5a,0xb3 }, { 0xdb,0xd2,0x52,0x92 },
1136     { 0x10,0x56,0x33,0xe9 }, { 0xd6,0x47,0x13,0x6d }, 
1137     { 0xd7,0x61,0x8c,0x9a }, { 0xa1,0x0c,0x7a,0x37 },
1138     { 0xf8,0x14,0x8e,0x59 }, { 0x13,0x3c,0x89,0xeb }, 
1139     { 0xa9,0x27,0xee,0xce }, { 0x61,0xc9,0x35,0xb7 },
1140     { 0x1c,0xe5,0xed,0xe1 }, { 0x47,0xb1,0x3c,0x7a }, 
1141     { 0xd2,0xdf,0x59,0x9c }, { 0xf2,0x73,0x3f,0x55 },
1142     { 0x14,0xce,0x79,0x18 }, { 0xc7,0x37,0xbf,0x73 }, 
1143     { 0xf7,0xcd,0xea,0x53 }, { 0xfd,0xaa,0x5b,0x5f },
1144     { 0x3d,0x6f,0x14,0xdf }, { 0x44,0xdb,0x86,0x78 }, 
1145     { 0xaf,0xf3,0x81,0xca }, { 0x68,0xc4,0x3e,0xb9 },
1146     { 0x24,0x34,0x2c,0x38 }, { 0xa3,0x40,0x5f,0xc2 }, 
1147     { 0x1d,0xc3,0x72,0x16 }, { 0xe2,0x25,0x0c,0xbc },
1148     { 0x3c,0x49,0x8b,0x28 }, { 0x0d,0x95,0x41,0xff }, 
1149     { 0xa8,0x01,0x71,0x39 }, { 0x0c,0xb3,0xde,0x08 },
1150     { 0xb4,0xe4,0x9c,0xd8 }, { 0x56,0xc1,0x90,0x64 }, 
1151     { 0xcb,0x84,0x61,0x7b }, { 0x32,0xb6,0x70,0xd5 },
1152     { 0x6c,0x5c,0x74,0x48 }, { 0xb8,0x57,0x42,0xd0 }
1153 };
1154
1155 static const byte S5[256] = {
1156     0x52,0x09,0x6a,0xd5,0x30,0x36,0xa5,0x38,
1157     0xbf,0x40,0xa3,0x9e,0x81,0xf3,0xd7,0xfb,
1158     0x7c,0xe3,0x39,0x82,0x9b,0x2f,0xff,0x87,
1159     0x34,0x8e,0x43,0x44,0xc4,0xde,0xe9,0xcb,
1160     0x54,0x7b,0x94,0x32,0xa6,0xc2,0x23,0x3d,
1161     0xee,0x4c,0x95,0x0b,0x42,0xfa,0xc3,0x4e,
1162     0x08,0x2e,0xa1,0x66,0x28,0xd9,0x24,0xb2,
1163     0x76,0x5b,0xa2,0x49,0x6d,0x8b,0xd1,0x25,
1164     0x72,0xf8,0xf6,0x64,0x86,0x68,0x98,0x16,
1165     0xd4,0xa4,0x5c,0xcc,0x5d,0x65,0xb6,0x92,
1166     0x6c,0x70,0x48,0x50,0xfd,0xed,0xb9,0xda,
1167     0x5e,0x15,0x46,0x57,0xa7,0x8d,0x9d,0x84,
1168     0x90,0xd8,0xab,0x00,0x8c,0xbc,0xd3,0x0a,
1169     0xf7,0xe4,0x58,0x05,0xb8,0xb3,0x45,0x06,
1170     0xd0,0x2c,0x1e,0x8f,0xca,0x3f,0x0f,0x02,
1171     0xc1,0xaf,0xbd,0x03,0x01,0x13,0x8a,0x6b,
1172     0x3a,0x91,0x11,0x41,0x4f,0x67,0xdc,0xea,
1173     0x97,0xf2,0xcf,0xce,0xf0,0xb4,0xe6,0x73,
1174     0x96,0xac,0x74,0x22,0xe7,0xad,0x35,0x85,
1175     0xe2,0xf9,0x37,0xe8,0x1c,0x75,0xdf,0x6e,
1176     0x47,0xf1,0x1a,0x71,0x1d,0x29,0xc5,0x89,
1177     0x6f,0xb7,0x62,0x0e,0xaa,0x18,0xbe,0x1b,
1178     0xfc,0x56,0x3e,0x4b,0xc6,0xd2,0x79,0x20,
1179     0x9a,0xdb,0xc0,0xfe,0x78,0xcd,0x5a,0xf4,
1180     0x1f,0xdd,0xa8,0x33,0x88,0x07,0xc7,0x31,
1181     0xb1,0x12,0x10,0x59,0x27,0x80,0xec,0x5f,
1182     0x60,0x51,0x7f,0xa9,0x19,0xb5,0x4a,0x0d,
1183     0x2d,0xe5,0x7a,0x9f,0x93,0xc9,0x9c,0xef,
1184     0xa0,0xe0,0x3b,0x4d,0xae,0x2a,0xf5,0xb0,
1185     0xc8,0xeb,0xbb,0x3c,0x83,0x53,0x99,0x61,
1186     0x17,0x2b,0x04,0x7e,0xba,0x77,0xd6,0x26,
1187     0xe1,0x69,0x14,0x63,0x55,0x21,0x0c,0x7d
1188 };
1189
1190 static const byte U1[256][4] = {
1191     { 0x00,0x00,0x00,0x00 }, { 0x0e,0x09,0x0d,0x0b },
1192     { 0x1c,0x12,0x1a,0x16 }, { 0x12,0x1b,0x17,0x1d }, 
1193     { 0x38,0x24,0x34,0x2c }, { 0x36,0x2d,0x39,0x27 },
1194     { 0x24,0x36,0x2e,0x3a }, { 0x2a,0x3f,0x23,0x31 }, 
1195     { 0x70,0x48,0x68,0x58 }, { 0x7e,0x41,0x65,0x53 },
1196     { 0x6c,0x5a,0x72,0x4e }, { 0x62,0x53,0x7f,0x45 }, 
1197     { 0x48,0x6c,0x5c,0x74 }, { 0x46,0x65,0x51,0x7f },
1198     { 0x54,0x7e,0x46,0x62 }, { 0x5a,0x77,0x4b,0x69 }, 
1199     { 0xe0,0x90,0xd0,0xb0 }, { 0xee,0x99,0xdd,0xbb },
1200     { 0xfc,0x82,0xca,0xa6 }, { 0xf2,0x8b,0xc7,0xad }, 
1201     { 0xd8,0xb4,0xe4,0x9c }, { 0xd6,0xbd,0xe9,0x97 },
1202     { 0xc4,0xa6,0xfe,0x8a }, { 0xca,0xaf,0xf3,0x81 }, 
1203     { 0x90,0xd8,0xb8,0xe8 }, { 0x9e,0xd1,0xb5,0xe3 },
1204     { 0x8c,0xca,0xa2,0xfe }, { 0x82,0xc3,0xaf,0xf5 }, 
1205     { 0xa8,0xfc,0x8c,0xc4 }, { 0xa6,0xf5,0x81,0xcf },
1206     { 0xb4,0xee,0x96,0xd2 }, { 0xba,0xe7,0x9b,0xd9 }, 
1207     { 0xdb,0x3b,0xbb,0x7b }, { 0xd5,0x32,0xb6,0x70 },
1208     { 0xc7,0x29,0xa1,0x6d }, { 0xc9,0x20,0xac,0x66 }, 
1209     { 0xe3,0x1f,0x8f,0x57 }, { 0xed,0x16,0x82,0x5c },
1210     { 0xff,0x0d,0x95,0x41 }, { 0xf1,0x04,0x98,0x4a }, 
1211     { 0xab,0x73,0xd3,0x23 }, { 0xa5,0x7a,0xde,0x28 },
1212     { 0xb7,0x61,0xc9,0x35 }, { 0xb9,0x68,0xc4,0x3e }, 
1213     { 0x93,0x57,0xe7,0x0f }, { 0x9d,0x5e,0xea,0x04 },
1214     { 0x8f,0x45,0xfd,0x19 }, { 0x81,0x4c,0xf0,0x12 }, 
1215     { 0x3b,0xab,0x6b,0xcb }, { 0x35,0xa2,0x66,0xc0 },
1216     { 0x27,0xb9,0x71,0xdd }, { 0x29,0xb0,0x7c,0xd6 }, 
1217     { 0x03,0x8f,0x5f,0xe7 }, { 0x0d,0x86,0x52,0xec },
1218     { 0x1f,0x9d,0x45,0xf1 }, { 0x11,0x94,0x48,0xfa }, 
1219     { 0x4b,0xe3,0x03,0x93 }, { 0x45,0xea,0x0e,0x98 },
1220     { 0x57,0xf1,0x19,0x85 }, { 0x59,0xf8,0x14,0x8e }, 
1221     { 0x73,0xc7,0x37,0xbf }, { 0x7d,0xce,0x3a,0xb4 },
1222     { 0x6f,0xd5,0x2d,0xa9 }, { 0x61,0xdc,0x20,0xa2 }, 
1223     { 0xad,0x76,0x6d,0xf6 }, { 0xa3,0x7f,0x60,0xfd },
1224     { 0xb1,0x64,0x77,0xe0 }, { 0xbf,0x6d,0x7a,0xeb }, 
1225     { 0x95,0x52,0x59,0xda }, { 0x9b,0x5b,0x54,0xd1 },
1226     { 0x89,0x40,0x43,0xcc }, { 0x87,0x49,0x4e,0xc7 }, 
1227     { 0xdd,0x3e,0x05,0xae }, { 0xd3,0x37,0x08,0xa5 },
1228     { 0xc1,0x2c,0x1f,0xb8 }, { 0xcf,0x25,0x12,0xb3 }, 
1229     { 0xe5,0x1a,0x31,0x82 }, { 0xeb,0x13,0x3c,0x89 },
1230     { 0xf9,0x08,0x2b,0x94 }, { 0xf7,0x01,0x26,0x9f }, 
1231     { 0x4d,0xe6,0xbd,0x46 }, { 0x43,0xef,0xb0,0x4d },
1232     { 0x51,0xf4,0xa7,0x50 }, { 0x5f,0xfd,0xaa,0x5b }, 
1233     { 0x75,0xc2,0x89,0x6a }, { 0x7b,0xcb,0x84,0x61 },
1234     { 0x69,0xd0,0x93,0x7c }, { 0x67,0xd9,0x9e,0x77 }, 
1235     { 0x3d,0xae,0xd5,0x1e }, { 0x33,0xa7,0xd8,0x15 },
1236     { 0x21,0xbc,0xcf,0x08 }, { 0x2f,0xb5,0xc2,0x03 }, 
1237     { 0x05,0x8a,0xe1,0x32 }, { 0x0b,0x83,0xec,0x39 },
1238     { 0x19,0x98,0xfb,0x24 }, { 0x17,0x91,0xf6,0x2f }, 
1239     { 0x76,0x4d,0xd6,0x8d }, { 0x78,0x44,0xdb,0x86 },
1240     { 0x6a,0x5f,0xcc,0x9b }, { 0x64,0x56,0xc1,0x90 }, 
1241     { 0x4e,0x69,0xe2,0xa1 }, { 0x40,0x60,0xef,0xaa },
1242     { 0x52,0x7b,0xf8,0xb7 }, { 0x5c,0x72,0xf5,0xbc }, 
1243     { 0x06,0x05,0xbe,0xd5 }, { 0x08,0x0c,0xb3,0xde },
1244     { 0x1a,0x17,0xa4,0xc3 }, { 0x14,0x1e,0xa9,0xc8 }, 
1245     { 0x3e,0x21,0x8a,0xf9 }, { 0x30,0x28,0x87,0xf2 },
1246     { 0x22,0x33,0x90,0xef }, { 0x2c,0x3a,0x9d,0xe4 }, 
1247     { 0x96,0xdd,0x06,0x3d }, { 0x98,0xd4,0x0b,0x36 },
1248     { 0x8a,0xcf,0x1c,0x2b }, { 0x84,0xc6,0x11,0x20 }, 
1249     { 0xae,0xf9,0x32,0x11 }, { 0xa0,0xf0,0x3f,0x1a },
1250     { 0xb2,0xeb,0x28,0x07 }, { 0xbc,0xe2,0x25,0x0c }, 
1251     { 0xe6,0x95,0x6e,0x65 }, { 0xe8,0x9c,0x63,0x6e },
1252     { 0xfa,0x87,0x74,0x73 }, { 0xf4,0x8e,0x79,0x78 }, 
1253     { 0xde,0xb1,0x5a,0x49 }, { 0xd0,0xb8,0x57,0x42 },
1254     { 0xc2,0xa3,0x40,0x5f }, { 0xcc,0xaa,0x4d,0x54 }, 
1255     { 0x41,0xec,0xda,0xf7 }, { 0x4f,0xe5,0xd7,0xfc },
1256     { 0x5d,0xfe,0xc0,0xe1 }, { 0x53,0xf7,0xcd,0xea }, 
1257     { 0x79,0xc8,0xee,0xdb }, { 0x77,0xc1,0xe3,0xd0 },
1258     { 0x65,0xda,0xf4,0xcd }, { 0x6b,0xd3,0xf9,0xc6 }, 
1259     { 0x31,0xa4,0xb2,0xaf }, { 0x3f,0xad,0xbf,0xa4 },
1260     { 0x2d,0xb6,0xa8,0xb9 }, { 0x23,0xbf,0xa5,0xb2 }, 
1261     { 0x09,0x80,0x86,0x83 }, { 0x07,0x89,0x8b,0x88 },
1262     { 0x15,0x92,0x9c,0x95 }, { 0x1b,0x9b,0x91,0x9e }, 
1263     { 0xa1,0x7c,0x0a,0x47 }, { 0xaf,0x75,0x07,0x4c },
1264     { 0xbd,0x6e,0x10,0x51 }, { 0xb3,0x67,0x1d,0x5a }, 
1265     { 0x99,0x58,0x3e,0x6b }, { 0x97,0x51,0x33,0x60 },
1266     { 0x85,0x4a,0x24,0x7d }, { 0x8b,0x43,0x29,0x76 }, 
1267     { 0xd1,0x34,0x62,0x1f }, { 0xdf,0x3d,0x6f,0x14 },
1268     { 0xcd,0x26,0x78,0x09 }, { 0xc3,0x2f,0x75,0x02 }, 
1269     { 0xe9,0x10,0x56,0x33 }, { 0xe7,0x19,0x5b,0x38 },
1270     { 0xf5,0x02,0x4c,0x25 }, { 0xfb,0x0b,0x41,0x2e }, 
1271     { 0x9a,0xd7,0x61,0x8c }, { 0x94,0xde,0x6c,0x87 }, 
1272     { 0x86,0xc5,0x7b,0x9a }, { 0x88,0xcc,0x76,0x91 }, 
1273     { 0xa2,0xf3,0x55,0xa0 }, { 0xac,0xfa,0x58,0xab },
1274     { 0xbe,0xe1,0x4f,0xb6 }, { 0xb0,0xe8,0x42,0xbd }, 
1275     { 0xea,0x9f,0x09,0xd4 }, { 0xe4,0x96,0x04,0xdf },
1276     { 0xf6,0x8d,0x13,0xc2 }, { 0xf8,0x84,0x1e,0xc9 }, 
1277     { 0xd2,0xbb,0x3d,0xf8 }, { 0xdc,0xb2,0x30,0xf3 },
1278     { 0xce,0xa9,0x27,0xee }, { 0xc0,0xa0,0x2a,0xe5 }, 
1279     { 0x7a,0x47,0xb1,0x3c }, { 0x74,0x4e,0xbc,0x37 }, 
1280     { 0x66,0x55,0xab,0x2a }, { 0x68,0x5c,0xa6,0x21 }, 
1281     { 0x42,0x63,0x85,0x10 }, { 0x4c,0x6a,0x88,0x1b },
1282     { 0x5e,0x71,0x9f,0x06 }, { 0x50,0x78,0x92,0x0d }, 
1283     { 0x0a,0x0f,0xd9,0x64 }, { 0x04,0x06,0xd4,0x6f },
1284     { 0x16,0x1d,0xc3,0x72 }, { 0x18,0x14,0xce,0x79 }, 
1285     { 0x32,0x2b,0xed,0x48 }, { 0x3c,0x22,0xe0,0x43 },
1286     { 0x2e,0x39,0xf7,0x5e }, { 0x20,0x30,0xfa,0x55 }, 
1287     { 0xec,0x9a,0xb7,0x01 }, { 0xe2,0x93,0xba,0x0a },
1288     { 0xf0,0x88,0xad,0x17 }, { 0xfe,0x81,0xa0,0x1c }, 
1289     { 0xd4,0xbe,0x83,0x2d }, { 0xda,0xb7,0x8e,0x26 },
1290     { 0xc8,0xac,0x99,0x3b }, { 0xc6,0xa5,0x94,0x30 }, 
1291     { 0x9c,0xd2,0xdf,0x59 }, { 0x92,0xdb,0xd2,0x52 },
1292     { 0x80,0xc0,0xc5,0x4f }, { 0x8e,0xc9,0xc8,0x44 }, 
1293     { 0xa4,0xf6,0xeb,0x75 }, { 0xaa,0xff,0xe6,0x7e },
1294     { 0xb8,0xe4,0xf1,0x63 }, { 0xb6,0xed,0xfc,0x68 }, 
1295     { 0x0c,0x0a,0x67,0xb1 }, { 0x02,0x03,0x6a,0xba },
1296     { 0x10,0x18,0x7d,0xa7 }, { 0x1e,0x11,0x70,0xac }, 
1297     { 0x34,0x2e,0x53,0x9d }, { 0x3a,0x27,0x5e,0x96 },
1298     { 0x28,0x3c,0x49,0x8b }, { 0x26,0x35,0x44,0x80 }, 
1299     { 0x7c,0x42,0x0f,0xe9 }, { 0x72,0x4b,0x02,0xe2 },
1300     { 0x60,0x50,0x15,0xff }, { 0x6e,0x59,0x18,0xf4 }, 
1301     { 0x44,0x66,0x3b,0xc5 }, { 0x4a,0x6f,0x36,0xce },
1302     { 0x58,0x74,0x21,0xd3 }, { 0x56,0x7d,0x2c,0xd8 }, 
1303     { 0x37,0xa1,0x0c,0x7a }, { 0x39,0xa8,0x01,0x71 },
1304     { 0x2b,0xb3,0x16,0x6c }, { 0x25,0xba,0x1b,0x67 }, 
1305     { 0x0f,0x85,0x38,0x56 }, { 0x01,0x8c,0x35,0x5d },
1306     { 0x13,0x97,0x22,0x40 }, { 0x1d,0x9e,0x2f,0x4b }, 
1307     { 0x47,0xe9,0x64,0x22 }, { 0x49,0xe0,0x69,0x29 },
1308     { 0x5b,0xfb,0x7e,0x34 }, { 0x55,0xf2,0x73,0x3f }, 
1309     { 0x7f,0xcd,0x50,0x0e }, { 0x71,0xc4,0x5d,0x05 },
1310     { 0x63,0xdf,0x4a,0x18 }, { 0x6d,0xd6,0x47,0x13 }, 
1311     { 0xd7,0x31,0xdc,0xca }, { 0xd9,0x38,0xd1,0xc1 },
1312     { 0xcb,0x23,0xc6,0xdc }, { 0xc5,0x2a,0xcb,0xd7 }, 
1313     { 0xef,0x15,0xe8,0xe6 }, { 0xe1,0x1c,0xe5,0xed },
1314     { 0xf3,0x07,0xf2,0xf0 }, { 0xfd,0x0e,0xff,0xfb }, 
1315     { 0xa7,0x79,0xb4,0x92 }, { 0xa9,0x70,0xb9,0x99 },
1316     { 0xbb,0x6b,0xae,0x84 }, { 0xb5,0x62,0xa3,0x8f }, 
1317     { 0x9f,0x5d,0x80,0xbe }, { 0x91,0x54,0x8d,0xb5 },
1318     { 0x83,0x4f,0x9a,0xa8 }, { 0x8d,0x46,0x97,0xa3 }
1319 };
1320
1321 static const byte U2[256][4] = {
1322     { 0x00,0x00,0x00,0x00 }, { 0x0b,0x0e,0x09,0x0d },
1323     { 0x16,0x1c,0x12,0x1a }, { 0x1d,0x12,0x1b,0x17 }, 
1324     { 0x2c,0x38,0x24,0x34 }, { 0x27,0x36,0x2d,0x39 },
1325     { 0x3a,0x24,0x36,0x2e }, { 0x31,0x2a,0x3f,0x23 }, 
1326     { 0x58,0x70,0x48,0x68 }, { 0x53,0x7e,0x41,0x65 }, 
1327     { 0x4e,0x6c,0x5a,0x72 }, { 0x45,0x62,0x53,0x7f }, 
1328     { 0x74,0x48,0x6c,0x5c }, { 0x7f,0x46,0x65,0x51 },
1329     { 0x62,0x54,0x7e,0x46 }, { 0x69,0x5a,0x77,0x4b }, 
1330     { 0xb0,0xe0,0x90,0xd0 }, { 0xbb,0xee,0x99,0xdd }, 
1331     { 0xa6,0xfc,0x82,0xca }, { 0xad,0xf2,0x8b,0xc7 }, 
1332     { 0x9c,0xd8,0xb4,0xe4 }, { 0x97,0xd6,0xbd,0xe9 }, 
1333     { 0x8a,0xc4,0xa6,0xfe }, { 0x81,0xca,0xaf,0xf3 }, 
1334     { 0xe8,0x90,0xd8,0xb8 }, { 0xe3,0x9e,0xd1,0xb5 },
1335     { 0xfe,0x8c,0xca,0xa2 }, { 0xf5,0x82,0xc3,0xaf }, 
1336     { 0xc4,0xa8,0xfc,0x8c }, { 0xcf,0xa6,0xf5,0x81 }, 
1337     { 0xd2,0xb4,0xee,0x96 }, { 0xd9,0xba,0xe7,0x9b }, 
1338     { 0x7b,0xdb,0x3b,0xbb }, { 0x70,0xd5,0x32,0xb6 }, 
1339     { 0x6d,0xc7,0x29,0xa1 }, { 0x66,0xc9,0x20,0xac }, 
1340     { 0x57,0xe3,0x1f,0x8f }, { 0x5c,0xed,0x16,0x82 }, 
1341     { 0x41,0xff,0x0d,0x95 }, { 0x4a,0xf1,0x04,0x98 }, 
1342     { 0x23,0xab,0x73,0xd3 }, { 0x28,0xa5,0x7a,0xde },
1343     { 0x35,0xb7,0x61,0xc9 }, { 0x3e,0xb9,0x68,0xc4 }, 
1344     { 0x0f,0x93,0x57,0xe7 }, { 0x04,0x9d,0x5e,0xea },
1345     { 0x19,0x8f,0x45,0xfd }, { 0x12,0x81,0x4c,0xf0 }, 
1346     { 0xcb,0x3b,0xab,0x6b }, { 0xc0,0x35,0xa2,0x66 },
1347     { 0xdd,0x27,0xb9,0x71 }, { 0xd6,0x29,0xb0,0x7c }, 
1348     { 0xe7,0x03,0x8f,0x5f }, { 0xec,0x0d,0x86,0x52 },
1349     { 0xf1,0x1f,0x9d,0x45 }, { 0xfa,0x11,0x94,0x48 }, 
1350     { 0x93,0x4b,0xe3,0x03 }, { 0x98,0x45,0xea,0x0e }, 
1351     { 0x85,0x57,0xf1,0x19 }, { 0x8e,0x59,0xf8,0x14 }, 
1352     { 0xbf,0x73,0xc7,0x37 }, { 0xb4,0x7d,0xce,0x3a },
1353     { 0xa9,0x6f,0xd5,0x2d }, { 0xa2,0x61,0xdc,0x20 }, 
1354     { 0xf6,0xad,0x76,0x6d }, { 0xfd,0xa3,0x7f,0x60 }, 
1355     { 0xe0,0xb1,0x64,0x77 }, { 0xeb,0xbf,0x6d,0x7a }, 
1356     { 0xda,0x95,0x52,0x59 }, { 0xd1,0x9b,0x5b,0x54 }, 
1357     { 0xcc,0x89,0x40,0x43 }, { 0xc7,0x87,0x49,0x4e }, 
1358     { 0xae,0xdd,0x3e,0x05 }, { 0xa5,0xd3,0x37,0x08 },
1359     { 0xb8,0xc1,0x2c,0x1f }, { 0xb3,0xcf,0x25,0x12 }, 
1360     { 0x82,0xe5,0x1a,0x31 }, { 0x89,0xeb,0x13,0x3c },
1361     { 0x94,0xf9,0x08,0x2b }, { 0x9f,0xf7,0x01,0x26 }, 
1362     { 0x46,0x4d,0xe6,0xbd }, { 0x4d,0x43,0xef,0xb0 },
1363     { 0x50,0x51,0xf4,0xa7 }, { 0x5b,0x5f,0xfd,0xaa }, 
1364     { 0x6a,0x75,0xc2,0x89 }, { 0x61,0x7b,0xcb,0x84 },
1365     { 0x7c,0x69,0xd0,0x93 }, { 0x77,0x67,0xd9,0x9e }, 
1366     { 0x1e,0x3d,0xae,0xd5 }, { 0x15,0x33,0xa7,0xd8 },
1367     { 0x08,0x21,0xbc,0xcf }, { 0x03,0x2f,0xb5,0xc2 }, 
1368     { 0x32,0x05,0x8a,0xe1 }, { 0x39,0x0b,0x83,0xec },
1369     { 0x24,0x19,0x98,0xfb }, { 0x2f,0x17,0x91,0xf6 }, 
1370     { 0x8d,0x76,0x4d,0xd6 }, { 0x86,0x78,0x44,0xdb },
1371     { 0x9b,0x6a,0x5f,0xcc }, { 0x90,0x64,0x56,0xc1 }, 
1372     { 0xa1,0x4e,0x69,0xe2 }, { 0xaa,0x40,0x60,0xef },
1373     { 0xb7,0x52,0x7b,0xf8 }, { 0xbc,0x5c,0x72,0xf5 }, 
1374     { 0xd5,0x06,0x05,0xbe }, { 0xde,0x08,0x0c,0xb3 },
1375     { 0xc3,0x1a,0x17,0xa4 }, { 0xc8,0x14,0x1e,0xa9 }, 
1376     { 0xf9,0x3e,0x21,0x8a }, { 0xf2,0x30,0x28,0x87 },
1377     { 0xef,0x22,0x33,0x90 }, { 0xe4,0x2c,0x3a,0x9d }, 
1378     { 0x3d,0x96,0xdd,0x06 }, { 0x36,0x98,0xd4,0x0b },
1379     { 0x2b,0x8a,0xcf,0x1c }, { 0x20,0x84,0xc6,0x11 }, 
1380     { 0x11,0xae,0xf9,0x32 }, { 0x1a,0xa0,0xf0,0x3f },
1381     { 0x07,0xb2,0xeb,0x28 }, { 0x0c,0xbc,0xe2,0x25 }, 
1382     { 0x65,0xe6,0x95,0x6e }, { 0x6e,0xe8,0x9c,0x63 },
1383     { 0x73,0xfa,0x87,0x74 }, { 0x78,0xf4,0x8e,0x79 }, 
1384     { 0x49,0xde,0xb1,0x5a }, { 0x42,0xd0,0xb8,0x57 },
1385     { 0x5f,0xc2,0xa3,0x40 }, { 0x54,0xcc,0xaa,0x4d }, 
1386     { 0xf7,0x41,0xec,0xda }, { 0xfc,0x4f,0xe5,0xd7 },
1387     { 0xe1,0x5d,0xfe,0xc0 }, { 0xea,0x53,0xf7,0xcd }, 
1388     { 0xdb,0x79,0xc8,0xee }, { 0xd0,0x77,0xc1,0xe3 },
1389     { 0xcd,0x65,0xda,0xf4 }, { 0xc6,0x6b,0xd3,0xf9 }, 
1390     { 0xaf,0x31,0xa4,0xb2 }, { 0xa4,0x3f,0xad,0xbf },
1391     { 0xb9,0x2d,0xb6,0xa8 }, { 0xb2,0x23,0xbf,0xa5 }, 
1392     { 0x83,0x09,0x80,0x86 }, { 0x88,0x07,0x89,0x8b },
1393     { 0x95,0x15,0x92,0x9c }, { 0x9e,0x1b,0x9b,0x91 }, 
1394     { 0x47,0xa1,0x7c,0x0a }, { 0x4c,0xaf,0x75,0x07 },
1395     { 0x51,0xbd,0x6e,0x10 }, { 0x5a,0xb3,0x67,0x1d }, 
1396     { 0x6b,0x99,0x58,0x3e }, { 0x60,0x97,0x51,0x33 },
1397     { 0x7d,0x85,0x4a,0x24 }, { 0x76,0x8b,0x43,0x29 }, 
1398     { 0x1f,0xd1,0x34,0x62 }, { 0x14,0xdf,0x3d,0x6f },
1399     { 0x09,0xcd,0x26,0x78 }, { 0x02,0xc3,0x2f,0x75 }, 
1400     { 0x33,0xe9,0x10,0x56 }, { 0x38,0xe7,0x19,0x5b },
1401     { 0x25,0xf5,0x02,0x4c }, { 0x2e,0xfb,0x0b,0x41 }, 
1402     { 0x8c,0x9a,0xd7,0x61 }, { 0x87,0x94,0xde,0x6c },
1403     { 0x9a,0x86,0xc5,0x7b }, { 0x91,0x88,0xcc,0x76 }, 
1404     { 0xa0,0xa2,0xf3,0x55 }, { 0xab,0xac,0xfa,0x58 },
1405     { 0xb6,0xbe,0xe1,0x4f }, { 0xbd,0xb0,0xe8,0x42 }, 
1406     { 0xd4,0xea,0x9f,0x09 }, { 0xdf,0xe4,0x96,0x04 },
1407     { 0xc2,0xf6,0x8d,0x13 }, { 0xc9,0xf8,0x84,0x1e }, 
1408     { 0xf8,0xd2,0xbb,0x3d }, { 0xf3,0xdc,0xb2,0x30 },
1409     { 0xee,0xce,0xa9,0x27 }, { 0xe5,0xc0,0xa0,0x2a }, 
1410     { 0x3c,0x7a,0x47,0xb1 }, { 0x37,0x74,0x4e,0xbc },
1411     { 0x2a,0x66,0x55,0xab }, { 0x21,0x68,0x5c,0xa6 }, 
1412     { 0x10,0x42,0x63,0x85 }, { 0x1b,0x4c,0x6a,0x88 },
1413     { 0x06,0x5e,0x71,0x9f }, { 0x0d,0x50,0x78,0x92 }, 
1414     { 0x64,0x0a,0x0f,0xd9 }, { 0x6f,0x04,0x06,0xd4 },
1415     { 0x72,0x16,0x1d,0xc3 }, { 0x79,0x18,0x14,0xce }, 
1416     { 0x48,0x32,0x2b,0xed }, { 0x43,0x3c,0x22,0xe0 },
1417     { 0x5e,0x2e,0x39,0xf7 }, { 0x55,0x20,0x30,0xfa }, 
1418     { 0x01,0xec,0x9a,0xb7 }, { 0x0a,0xe2,0x93,0xba },
1419     { 0x17,0xf0,0x88,0xad }, { 0x1c,0xfe,0x81,0xa0 }, 
1420     { 0x2d,0xd4,0xbe,0x83 }, { 0x26,0xda,0xb7,0x8e },
1421     { 0x3b,0xc8,0xac,0x99 }, { 0x30,0xc6,0xa5,0x94 }, 
1422     { 0x59,0x9c,0xd2,0xdf }, { 0x52,0x92,0xdb,0xd2 },
1423     { 0x4f,0x80,0xc0,0xc5 }, { 0x44,0x8e,0xc9,0xc8 }, 
1424     { 0x75,0xa4,0xf6,0xeb }, { 0x7e,0xaa,0xff,0xe6 },
1425     { 0x63,0xb8,0xe4,0xf1 }, { 0x68,0xb6,0xed,0xfc }, 
1426     { 0xb1,0x0c,0x0a,0x67 }, { 0xba,0x02,0x03,0x6a },
1427     { 0xa7,0x10,0x18,0x7d }, { 0xac,0x1e,0x11,0x70 }, 
1428     { 0x9d,0x34,0x2e,0x53 }, { 0x96,0x3a,0x27,0x5e },
1429     { 0x8b,0x28,0x3c,0x49 }, { 0x80,0x26,0x35,0x44 }, 
1430     { 0xe9,0x7c,0x42,0x0f }, { 0xe2,0x72,0x4b,0x02 },
1431     { 0xff,0x60,0x50,0x15 }, { 0xf4,0x6e,0x59,0x18 }, 
1432     { 0xc5,0x44,0x66,0x3b }, { 0xce,0x4a,0x6f,0x36 },
1433     { 0xd3,0x58,0x74,0x21 }, { 0xd8,0x56,0x7d,0x2c }, 
1434     { 0x7a,0x37,0xa1,0x0c }, { 0x71,0x39,0xa8,0x01 },
1435     { 0x6c,0x2b,0xb3,0x16 }, { 0x67,0x25,0xba,0x1b }, 
1436     { 0x56,0x0f,0x85,0x38 }, { 0x5d,0x01,0x8c,0x35 },
1437     { 0x40,0x13,0x97,0x22 }, { 0x4b,0x1d,0x9e,0x2f }, 
1438     { 0x22,0x47,0xe9,0x64 }, { 0x29,0x49,0xe0,0x69 },
1439     { 0x34,0x5b,0xfb,0x7e }, { 0x3f,0x55,0xf2,0x73 }, 
1440     { 0x0e,0x7f,0xcd,0x50 }, { 0x05,0x71,0xc4,0x5d },
1441     { 0x18,0x63,0xdf,0x4a }, { 0x13,0x6d,0xd6,0x47 }, 
1442     { 0xca,0xd7,0x31,0xdc }, { 0xc1,0xd9,0x38,0xd1 },
1443     { 0xdc,0xcb,0x23,0xc6 }, { 0xd7,0xc5,0x2a,0xcb }, 
1444     { 0xe6,0xef,0x15,0xe8 }, { 0xed,0xe1,0x1c,0xe5 },
1445     { 0xf0,0xf3,0x07,0xf2 }, { 0xfb,0xfd,0x0e,0xff }, 
1446     { 0x92,0xa7,0x79,0xb4 }, { 0x99,0xa9,0x70,0xb9 },
1447     { 0x84,0xbb,0x6b,0xae }, { 0x8f,0xb5,0x62,0xa3 }, 
1448     { 0xbe,0x9f,0x5d,0x80 }, { 0xb5,0x91,0x54,0x8d },
1449     { 0xa8,0x83,0x4f,0x9a }, { 0xa3,0x8d,0x46,0x97 }
1450 };
1451
1452 static const byte U3[256][4] = {
1453     { 0x00,0x00,0x00,0x00 }, { 0x0d,0x0b,0x0e,0x09 },
1454     { 0x1a,0x16,0x1c,0x12 }, { 0x17,0x1d,0x12,0x1b }, 
1455     { 0x34,0x2c,0x38,0x24 }, { 0x39,0x27,0x36,0x2d },
1456     { 0x2e,0x3a,0x24,0x36 }, { 0x23,0x31,0x2a,0x3f }, 
1457     { 0x68,0x58,0x70,0x48 }, { 0x65,0x53,0x7e,0x41 },
1458     { 0x72,0x4e,0x6c,0x5a }, { 0x7f,0x45,0x62,0x53 }, 
1459     { 0x5c,0x74,0x48,0x6c }, { 0x51,0x7f,0x46,0x65 },
1460     { 0x46,0x62,0x54,0x7e }, { 0x4b,0x69,0x5a,0x77 }, 
1461     { 0xd0,0xb0,0xe0,0x90 }, { 0xdd,0xbb,0xee,0x99 },
1462     { 0xca,0xa6,0xfc,0x82 }, { 0xc7,0xad,0xf2,0x8b }, 
1463     { 0xe4,0x9c,0xd8,0xb4 }, { 0xe9,0x97,0xd6,0xbd },
1464     { 0xfe,0x8a,0xc4,0xa6 }, { 0xf3,0x81,0xca,0xaf }, 
1465     { 0xb8,0xe8,0x90,0xd8 }, { 0xb5,0xe3,0x9e,0xd1 },
1466     { 0xa2,0xfe,0x8c,0xca }, { 0xaf,0xf5,0x82,0xc3 }, 
1467     { 0x8c,0xc4,0xa8,0xfc }, { 0x81,0xcf,0xa6,0xf5 },
1468     { 0x96,0xd2,0xb4,0xee }, { 0x9b,0xd9,0xba,0xe7 }, 
1469     { 0xbb,0x7b,0xdb,0x3b }, { 0xb6,0x70,0xd5,0x32 },
1470     { 0xa1,0x6d,0xc7,0x29 }, { 0xac,0x66,0xc9,0x20 }, 
1471     { 0x8f,0x57,0xe3,0x1f }, { 0x82,0x5c,0xed,0x16 },
1472     { 0x95,0x41,0xff,0x0d }, { 0x98,0x4a,0xf1,0x04 }, 
1473     { 0xd3,0x23,0xab,0x73 }, { 0xde,0x28,0xa5,0x7a },
1474     { 0xc9,0x35,0xb7,0x61 }, { 0xc4,0x3e,0xb9,0x68 }, 
1475     { 0xe7,0x0f,0x93,0x57 }, { 0xea,0x04,0x9d,0x5e },
1476     { 0xfd,0x19,0x8f,0x45 }, { 0xf0,0x12,0x81,0x4c }, 
1477     { 0x6b,0xcb,0x3b,0xab }, { 0x66,0xc0,0x35,0xa2 },
1478     { 0x71,0xdd,0x27,0xb9 }, { 0x7c,0xd6,0x29,0xb0 }, 
1479     { 0x5f,0xe7,0x03,0x8f }, { 0x52,0xec,0x0d,0x86 },
1480     { 0x45,0xf1,0x1f,0x9d }, { 0x48,0xfa,0x11,0x94 }, 
1481     { 0x03,0x93,0x4b,0xe3 }, { 0x0e,0x98,0x45,0xea },
1482     { 0x19,0x85,0x57,0xf1 }, { 0x14,0x8e,0x59,0xf8 }, 
1483     { 0x37,0xbf,0x73,0xc7 }, { 0x3a,0xb4,0x7d,0xce }, 
1484     { 0x2d,0xa9,0x6f,0xd5 }, { 0x20,0xa2,0x61,0xdc }, 
1485     { 0x6d,0xf6,0xad,0x76 }, { 0x60,0xfd,0xa3,0x7f },
1486     { 0x77,0xe0,0xb1,0x64 }, { 0x7a,0xeb,0xbf,0x6d }, 
1487     { 0x59,0xda,0x95,0x52 }, { 0x54,0xd1,0x9b,0x5b },
1488     { 0x43,0xcc,0x89,0x40 }, { 0x4e,0xc7,0x87,0x49 }, 
1489     { 0x05,0xae,0xdd,0x3e }, { 0x08,0xa5,0xd3,0x37 },
1490     { 0x1f,0xb8,0xc1,0x2c }, { 0x12,0xb3,0xcf,0x25 }, 
1491     { 0x31,0x82,0xe5,0x1a }, { 0x3c,0x89,0xeb,0x13 }, 
1492     { 0x2b,0x94,0xf9,0x08 }, { 0x26,0x9f,0xf7,0x01 }, 
1493     { 0xbd,0x46,0x4d,0xe6 }, { 0xb0,0x4d,0x43,0xef }, 
1494     { 0xa7,0x50,0x51,0xf4 }, { 0xaa,0x5b,0x5f,0xfd }, 
1495     { 0x89,0x6a,0x75,0xc2 }, { 0x84,0x61,0x7b,0xcb }, 
1496     { 0x93,0x7c,0x69,0xd0 }, { 0x9e,0x77,0x67,0xd9 }, 
1497     { 0xd5,0x1e,0x3d,0xae }, { 0xd8,0x15,0x33,0xa7 },
1498     { 0xcf,0x08,0x21,0xbc }, { 0xc2,0x03,0x2f,0xb5 }, 
1499     { 0xe1,0x32,0x05,0x8a }, { 0xec,0x39,0x0b,0x83 },
1500     { 0xfb,0x24,0x19,0x98 }, { 0xf6,0x2f,0x17,0x91 }, 
1501     { 0xd6,0x8d,0x76,0x4d }, { 0xdb,0x86,0x78,0x44 }, 
1502     { 0xcc,0x9b,0x6a,0x5f }, { 0xc1,0x90,0x64,0x56 }, 
1503     { 0xe2,0xa1,0x4e,0x69 }, { 0xef,0xaa,0x40,0x60 }, 
1504     { 0xf8,0xb7,0x52,0x7b }, { 0xf5,0xbc,0x5c,0x72 }, 
1505     { 0xbe,0xd5,0x06,0x05 }, { 0xb3,0xde,0x08,0x0c }, 
1506     { 0xa4,0xc3,0x1a,0x17 }, { 0xa9,0xc8,0x14,0x1e }, 
1507     { 0x8a,0xf9,0x3e,0x21 }, { 0x87,0xf2,0x30,0x28 },
1508     { 0x90,0xef,0x22,0x33 }, { 0x9d,0xe4,0x2c,0x3a }, 
1509     { 0x06,0x3d,0x96,0xdd }, { 0x0b,0x36,0x98,0xd4 },
1510     { 0x1c,0x2b,0x8a,0xcf }, { 0x11,0x20,0x84,0xc6 }, 
1511     { 0x32,0x11,0xae,0xf9 }, { 0x3f,0x1a,0xa0,0xf0 },
1512     { 0x28,0x07,0xb2,0xeb }, { 0x25,0x0c,0xbc,0xe2 }, 
1513     { 0x6e,0x65,0xe6,0x95 }, { 0x63,0x6e,0xe8,0x9c },
1514     { 0x74,0x73,0xfa,0x87 }, { 0x79,0x78,0xf4,0x8e }, 
1515     { 0x5a,0x49,0xde,0xb1 }, { 0x57,0x42,0xd0,0xb8 },
1516     { 0x40,0x5f,0xc2,0xa3 }, { 0x4d,0x54,0xcc,0xaa }, 
1517     { 0xda,0xf7,0x41,0xec }, { 0xd7,0xfc,0x4f,0xe5 },
1518     { 0xc0,0xe1,0x5d,0xfe }, { 0xcd,0xea,0x53,0xf7 }, 
1519     { 0xee,0xdb,0x79,0xc8 }, { 0xe3,0xd0,0x77,0xc1 },
1520     { 0xf4,0xcd,0x65,0xda }, { 0xf9,0xc6,0x6b,0xd3 }, 
1521     { 0xb2,0xaf,0x31,0xa4 }, { 0xbf,0xa4,0x3f,0xad },
1522     { 0xa8,0xb9,0x2d,0xb6 }, { 0xa5,0xb2,0x23,0xbf }, 
1523     { 0x86,0x83,0x09,0x80 }, { 0x8b,0x88,0x07,0x89 },
1524     { 0x9c,0x95,0x15,0x92 }, { 0x91,0x9e,0x1b,0x9b }, 
1525     { 0x0a,0x47,0xa1,0x7c }, { 0x07,0x4c,0xaf,0x75 },
1526     { 0x10,0x51,0xbd,0x6e }, { 0x1d,0x5a,0xb3,0x67 }, 
1527     { 0x3e,0x6b,0x99,0x58 }, { 0x33,0x60,0x97,0x51 },
1528     { 0x24,0x7d,0x85,0x4a }, { 0x29,0x76,0x8b,0x43 }, 
1529     { 0x62,0x1f,0xd1,0x34 }, { 0x6f,0x14,0xdf,0x3d },
1530     { 0x78,0x09,0xcd,0x26 }, { 0x75,0x02,0xc3,0x2f }, 
1531     { 0x56,0x33,0xe9,0x10 }, { 0x5b,0x38,0xe7,0x19 },
1532     { 0x4c,0x25,0xf5,0x02 }, { 0x41,0x2e,0xfb,0x0b }, 
1533     { 0x61,0x8c,0x9a,0xd7 }, { 0x6c,0x87,0x94,0xde },
1534     { 0x7b,0x9a,0x86,0xc5 }, { 0x76,0x91,0x88,0xcc }, 
1535     { 0x55,0xa0,0xa2,0xf3 }, { 0x58,0xab,0xac,0xfa },
1536     { 0x4f,0xb6,0xbe,0xe1 }, { 0x42,0xbd,0xb0,0xe8 }, 
1537     { 0x09,0xd4,0xea,0x9f }, { 0x04,0xdf,0xe4,0x96 },
1538     { 0x13,0xc2,0xf6,0x8d }, { 0x1e,0xc9,0xf8,0x84 }, 
1539     { 0x3d,0xf8,0xd2,0xbb }, { 0x30,0xf3,0xdc,0xb2 },
1540     { 0x27,0xee,0xce,0xa9 }, { 0x2a,0xe5,0xc0,0xa0 }, 
1541     { 0xb1,0x3c,0x7a,0x47 }, { 0xbc,0x37,0x74,0x4e },
1542     { 0xab,0x2a,0x66,0x55 }, { 0xa6,0x21,0x68,0x5c }, 
1543     { 0x85,0x10,0x42,0x63 }, { 0x88,0x1b,0x4c,0x6a },
1544     { 0x9f,0x06,0x5e,0x71 }, { 0x92,0x0d,0x50,0x78 }, 
1545     { 0xd9,0x64,0x0a,0x0f }, { 0xd4,0x6f,0x04,0x06 },
1546     { 0xc3,0x72,0x16,0x1d }, { 0xce,0x79,0x18,0x14 }, 
1547     { 0xed,0x48,0x32,0x2b }, { 0xe0,0x43,0x3c,0x22 },
1548     { 0xf7,0x5e,0x2e,0x39 }, { 0xfa,0x55,0x20,0x30 }, 
1549     { 0xb7,0x01,0xec,0x9a }, { 0xba,0x0a,0xe2,0x93 },
1550     { 0xad,0x17,0xf0,0x88 }, { 0xa0,0x1c,0xfe,0x81 }, 
1551     { 0x83,0x2d,0xd4,0xbe }, { 0x8e,0x26,0xda,0xb7 },
1552     { 0x99,0x3b,0xc8,0xac }, { 0x94,0x30,0xc6,0xa5 }, 
1553     { 0xdf,0x59,0x9c,0xd2 }, { 0xd2,0x52,0x92,0xdb },
1554     { 0xc5,0x4f,0x80,0xc0 }, { 0xc8,0x44,0x8e,0xc9 }, 
1555     { 0xeb,0x75,0xa4,0xf6 }, { 0xe6,0x7e,0xaa,0xff },
1556     { 0xf1,0x63,0xb8,0xe4 }, { 0xfc,0x68,0xb6,0xed }, 
1557     { 0x67,0xb1,0x0c,0x0a }, { 0x6a,0xba,0x02,0x03 },
1558     { 0x7d,0xa7,0x10,0x18 }, { 0x70,0xac,0x1e,0x11 }, 
1559     { 0x53,0x9d,0x34,0x2e }, { 0x5e,0x96,0x3a,0x27 },
1560     { 0x49,0x8b,0x28,0x3c }, { 0x44,0x80,0x26,0x35 }, 
1561     { 0x0f,0xe9,0x7c,0x42 }, { 0x02,0xe2,0x72,0x4b },
1562     { 0x15,0xff,0x60,0x50 }, { 0x18,0xf4,0x6e,0x59 }, 
1563     { 0x3b,0xc5,0x44,0x66 }, { 0x36,0xce,0x4a,0x6f },
1564     { 0x21,0xd3,0x58,0x74 }, { 0x2c,0xd8,0x56,0x7d }, 
1565     { 0x0c,0x7a,0x37,0xa1 }, { 0x01,0x71,0x39,0xa8 },
1566     { 0x16,0x6c,0x2b,0xb3 }, { 0x1b,0x67,0x25,0xba }, 
1567     { 0x38,0x56,0x0f,0x85 }, { 0x35,0x5d,0x01,0x8c },
1568     { 0x22,0x40,0x13,0x97 }, { 0x2f,0x4b,0x1d,0x9e }, 
1569     { 0x64,0x22,0x47,0xe9 }, { 0x69,0x29,0x49,0xe0 },
1570     { 0x7e,0x34,0x5b,0xfb }, { 0x73,0x3f,0x55,0xf2 }, 
1571     { 0x50,0x0e,0x7f,0xcd }, { 0x5d,0x05,0x71,0xc4 },
1572     { 0x4a,0x18,0x63,0xdf }, { 0x47,0x13,0x6d,0xd6 }, 
1573     { 0xdc,0xca,0xd7,0x31 }, { 0xd1,0xc1,0xd9,0x38 },
1574     { 0xc6,0xdc,0xcb,0x23 }, { 0xcb,0xd7,0xc5,0x2a }, 
1575     { 0xe8,0xe6,0xef,0x15 }, { 0xe5,0xed,0xe1,0x1c },
1576     { 0xf2,0xf0,0xf3,0x07 }, { 0xff,0xfb,0xfd,0x0e }, 
1577     { 0xb4,0x92,0xa7,0x79 }, { 0xb9,0x99,0xa9,0x70 },
1578     { 0xae,0x84,0xbb,0x6b }, { 0xa3,0x8f,0xb5,0x62 }, 
1579     { 0x80,0xbe,0x9f,0x5d }, { 0x8d,0xb5,0x91,0x54 },
1580     { 0x9a,0xa8,0x83,0x4f }, { 0x97,0xa3,0x8d,0x46 }
1581 };
1582
1583 static const byte U4[256][4] = {
1584     { 0x00,0x00,0x00,0x00 }, { 0x09,0x0d,0x0b,0x0e },
1585     { 0x12,0x1a,0x16,0x1c }, { 0x1b,0x17,0x1d,0x12 }, 
1586     { 0x24,0x34,0x2c,0x38 }, { 0x2d,0x39,0x27,0x36 },
1587     { 0x36,0x2e,0x3a,0x24 }, { 0x3f,0x23,0x31,0x2a }, 
1588     { 0x48,0x68,0x58,0x70 }, { 0x41,0x65,0x53,0x7e },
1589     { 0x5a,0x72,0x4e,0x6c }, { 0x53,0x7f,0x45,0x62 }, 
1590     { 0x6c,0x5c,0x74,0x48 }, { 0x65,0x51,0x7f,0x46 },
1591     { 0x7e,0x46,0x62,0x54 }, { 0x77,0x4b,0x69,0x5a }, 
1592     { 0x90,0xd0,0xb0,0xe0 }, { 0x99,0xdd,0xbb,0xee },
1593     { 0x82,0xca,0xa6,0xfc }, { 0x8b,0xc7,0xad,0xf2 }, 
1594     { 0xb4,0xe4,0x9c,0xd8 }, { 0xbd,0xe9,0x97,0xd6 },
1595     { 0xa6,0xfe,0x8a,0xc4 }, { 0xaf,0xf3,0x81,0xca }, 
1596     { 0xd8,0xb8,0xe8,0x90 }, { 0xd1,0xb5,0xe3,0x9e },
1597     { 0xca,0xa2,0xfe,0x8c }, { 0xc3,0xaf,0xf5,0x82 }, 
1598     { 0xfc,0x8c,0xc4,0xa8 }, { 0xf5,0x81,0xcf,0xa6 },
1599     { 0xee,0x96,0xd2,0xb4 }, { 0xe7,0x9b,0xd9,0xba }, 
1600     { 0x3b,0xbb,0x7b,0xdb }, { 0x32,0xb6,0x70,0xd5 },
1601     { 0x29,0xa1,0x6d,0xc7 }, { 0x20,0xac,0x66,0xc9 }, 
1602     { 0x1f,0x8f,0x57,0xe3 }, { 0x16,0x82,0x5c,0xed },
1603     { 0x0d,0x95,0x41,0xff }, { 0x04,0x98,0x4a,0xf1 }, 
1604     { 0x73,0xd3,0x23,0xab }, { 0x7a,0xde,0x28,0xa5 },
1605     { 0x61,0xc9,0x35,0xb7 }, { 0x68,0xc4,0x3e,0xb9 }, 
1606     { 0x57,0xe7,0x0f,0x93 }, { 0x5e,0xea,0x04,0x9d },
1607     { 0x45,0xfd,0x19,0x8f }, { 0x4c,0xf0,0x12,0x81 }, 
1608     { 0xab,0x6b,0xcb,0x3b }, { 0xa2,0x66,0xc0,0x35 },
1609     { 0xb9,0x71,0xdd,0x27 }, { 0xb0,0x7c,0xd6,0x29 }, 
1610     { 0x8f,0x5f,0xe7,0x03 }, { 0x86,0x52,0xec,0x0d },
1611     { 0x9d,0x45,0xf1,0x1f }, { 0x94,0x48,0xfa,0x11 }, 
1612     { 0xe3,0x03,0x93,0x4b }, { 0xea,0x0e,0x98,0x45 },
1613     { 0xf1,0x19,0x85,0x57 }, { 0xf8,0x14,0x8e,0x59 }, 
1614     { 0xc7,0x37,0xbf,0x73 }, { 0xce,0x3a,0xb4,0x7d },
1615     { 0xd5,0x2d,0xa9,0x6f }, { 0xdc,0x20,0xa2,0x61 }, 
1616     { 0x76,0x6d,0xf6,0xad }, { 0x7f,0x60,0xfd,0xa3 },
1617     { 0x64,0x77,0xe0,0xb1 }, { 0x6d,0x7a,0xeb,0xbf }, 
1618     { 0x52,0x59,0xda,0x95 }, { 0x5b,0x54,0xd1,0x9b },
1619     { 0x40,0x43,0xcc,0x89 }, { 0x49,0x4e,0xc7,0x87 }, 
1620     { 0x3e,0x05,0xae,0xdd }, { 0x37,0x08,0xa5,0xd3 },
1621     { 0x2c,0x1f,0xb8,0xc1 }, { 0x25,0x12,0xb3,0xcf }, 
1622     { 0x1a,0x31,0x82,0xe5 }, { 0x13,0x3c,0x89,0xeb },
1623     { 0x08,0x2b,0x94,0xf9 }, { 0x01,0x26,0x9f,0xf7 }, 
1624     { 0xe6,0xbd,0x46,0x4d }, { 0xef,0xb0,0x4d,0x43 },
1625     { 0xf4,0xa7,0x50,0x51 }, { 0xfd,0xaa,0x5b,0x5f }, 
1626     { 0xc2,0x89,0x6a,0x75 }, { 0xcb,0x84,0x61,0x7b },
1627     { 0xd0,0x93,0x7c,0x69 }, { 0xd9,0x9e,0x77,0x67 }, 
1628     { 0xae,0xd5,0x1e,0x3d }, { 0xa7,0xd8,0x15,0x33 },
1629     { 0xbc,0xcf,0x08,0x21 }, { 0xb5,0xc2,0x03,0x2f }, 
1630     { 0x8a,0xe1,0x32,0x05 }, { 0x83,0xec,0x39,0x0b },
1631     { 0x98,0xfb,0x24,0x19 }, { 0x91,0xf6,0x2f,0x17 }, 
1632     { 0x4d,0xd6,0x8d,0x76 }, { 0x44,0xdb,0x86,0x78 },
1633     { 0x5f,0xcc,0x9b,0x6a }, { 0x56,0xc1,0x90,0x64 }, 
1634     { 0x69,0xe2,0xa1,0x4e }, { 0x60,0xef,0xaa,0x40 },
1635     { 0x7b,0xf8,0xb7,0x52 }, { 0x72,0xf5,0xbc,0x5c }, 
1636     { 0x05,0xbe,0xd5,0x06 }, { 0x0c,0xb3,0xde,0x08 },
1637     { 0x17,0xa4,0xc3,0x1a }, { 0x1e,0xa9,0xc8,0x14 }, 
1638     { 0x21,0x8a,0xf9,0x3e }, { 0x28,0x87,0xf2,0x30 },
1639     { 0x33,0x90,0xef,0x22 }, { 0x3a,0x9d,0xe4,0x2c }, 
1640     { 0xdd,0x06,0x3d,0x96 }, { 0xd4,0x0b,0x36,0x98 },
1641     { 0xcf,0x1c,0x2b,0x8a }, { 0xc6,0x11,0x20,0x84 }, 
1642     { 0xf9,0x32,0x11,0xae }, { 0xf0,0x3f,0x1a,0xa0 },
1643     { 0xeb,0x28,0x07,0xb2 }, { 0xe2,0x25,0x0c,0xbc }, 
1644     { 0x95,0x6e,0x65,0xe6 }, { 0x9c,0x63,0x6e,0xe8 },
1645     { 0x87,0x74,0x73,0xfa }, { 0x8e,0x79,0x78,0xf4 }, 
1646     { 0xb1,0x5a,0x49,0xde }, { 0xb8,0x57,0x42,0xd0 },
1647     { 0xa3,0x40,0x5f,0xc2 }, { 0xaa,0x4d,0x54,0xcc }, 
1648     { 0xec,0xda,0xf7,0x41 }, { 0xe5,0xd7,0xfc,0x4f },
1649     { 0xfe,0xc0,0xe1,0x5d }, { 0xf7,0xcd,0xea,0x53 }, 
1650     { 0xc8,0xee,0xdb,0x79 }, { 0xc1,0xe3,0xd0,0x77 },
1651     { 0xda,0xf4,0xcd,0x65 }, { 0xd3,0xf9,0xc6,0x6b }, 
1652     { 0xa4,0xb2,0xaf,0x31 }, { 0xad,0xbf,0xa4,0x3f },
1653     { 0xb6,0xa8,0xb9,0x2d }, { 0xbf,0xa5,0xb2,0x23 }, 
1654     { 0x80,0x86,0x83,0x09 }, { 0x89,0x8b,0x88,0x07 },
1655     { 0x92,0x9c,0x95,0x15 }, { 0x9b,0x91,0x9e,0x1b }, 
1656     { 0x7c,0x0a,0x47,0xa1 }, { 0x75,0x07,0x4c,0xaf },
1657     { 0x6e,0x10,0x51,0xbd }, { 0x67,0x1d,0x5a,0xb3 }, 
1658     { 0x58,0x3e,0x6b,0x99 }, { 0x51,0x33,0x60,0x97 },
1659     { 0x4a,0x24,0x7d,0x85 }, { 0x43,0x29,0x76,0x8b }, 
1660     { 0x34,0x62,0x1f,0xd1 }, { 0x3d,0x6f,0x14,0xdf },
1661     { 0x26,0x78,0x09,0xcd }, { 0x2f,0x75,0x02,0xc3 }, 
1662     { 0x10,0x56,0x33,0xe9 }, { 0x19,0x5b,0x38,0xe7 },
1663     { 0x02,0x4c,0x25,0xf5 }, { 0x0b,0x41,0x2e,0xfb }, 
1664     { 0xd7,0x61,0x8c,0x9a }, { 0xde,0x6c,0x87,0x94 },
1665     { 0xc5,0x7b,0x9a,0x86 }, { 0xcc,0x76,0x91,0x88 }, 
1666     { 0xf3,0x55,0xa0,0xa2 }, { 0xfa,0x58,0xab,0xac },
1667     { 0xe1,0x4f,0xb6,0xbe }, { 0xe8,0x42,0xbd,0xb0 }, 
1668     { 0x9f,0x09,0xd4,0xea }, { 0x96,0x04,0xdf,0xe4 },
1669     { 0x8d,0x13,0xc2,0xf6 }, { 0x84,0x1e,0xc9,0xf8 }, 
1670     { 0xbb,0x3d,0xf8,0xd2 }, { 0xb2,0x30,0xf3,0xdc },
1671     { 0xa9,0x27,0xee,0xce }, { 0xa0,0x2a,0xe5,0xc0 }, 
1672     { 0x47,0xb1,0x3c,0x7a }, { 0x4e,0xbc,0x37,0x74 },
1673     { 0x55,0xab,0x2a,0x66 }, { 0x5c,0xa6,0x21,0x68 }, 
1674     { 0x63,0x85,0x10,0x42 }, { 0x6a,0x88,0x1b,0x4c },
1675     { 0x71,0x9f,0x06,0x5e }, { 0x78,0x92,0x0d,0x50 }, 
1676     { 0x0f,0xd9,0x64,0x0a }, { 0x06,0xd4,0x6f,0x04 },
1677     { 0x1d,0xc3,0x72,0x16 }, { 0x14,0xce,0x79,0x18 }, 
1678     { 0x2b,0xed,0x48,0x32 }, { 0x22,0xe0,0x43,0x3c },
1679     { 0x39,0xf7,0x5e,0x2e }, { 0x30,0xfa,0x55,0x20 }, 
1680     { 0x9a,0xb7,0x01,0xec }, { 0x93,0xba,0x0a,0xe2 }, 
1681     { 0x88,0xad,0x17,0xf0 }, { 0x81,0xa0,0x1c,0xfe }, 
1682     { 0xbe,0x83,0x2d,0xd4 }, { 0xb7,0x8e,0x26,0xda },
1683     { 0xac,0x99,0x3b,0xc8 }, { 0xa5,0x94,0x30,0xc6 }, 
1684     { 0xd2,0xdf,0x59,0x9c }, { 0xdb,0xd2,0x52,0x92 }, 
1685     { 0xc0,0xc5,0x4f,0x80 }, { 0xc9,0xc8,0x44,0x8e }, 
1686     { 0xf6,0xeb,0x75,0xa4 }, { 0xff,0xe6,0x7e,0xaa },
1687     { 0xe4,0xf1,0x63,0xb8 }, { 0xed,0xfc,0x68,0xb6 }, 
1688     { 0x0a,0x67,0xb1,0x0c }, { 0x03,0x6a,0xba,0x02 },
1689     { 0x18,0x7d,0xa7,0x10 }, { 0x11,0x70,0xac,0x1e }, 
1690     { 0x2e,0x53,0x9d,0x34 }, { 0x27,0x5e,0x96,0x3a },
1691     { 0x3c,0x49,0x8b,0x28 }, { 0x35,0x44,0x80,0x26 }, 
1692     { 0x42,0x0f,0xe9,0x7c }, { 0x4b,0x02,0xe2,0x72 }, 
1693     { 0x50,0x15,0xff,0x60 }, { 0x59,0x18,0xf4,0x6e }, 
1694     { 0x66,0x3b,0xc5,0x44 }, { 0x6f,0x36,0xce,0x4a },
1695     { 0x74,0x21,0xd3,0x58 }, { 0x7d,0x2c,0xd8,0x56 }, 
1696     { 0xa1,0x0c,0x7a,0x37 }, { 0xa8,0x01,0x71,0x39 },
1697     { 0xb3,0x16,0x6c,0x2b }, { 0xba,0x1b,0x67,0x25 }, 
1698     { 0x85,0x38,0x56,0x0f }, { 0x8c,0x35,0x5d,0x01 },
1699     { 0x97,0x22,0x40,0x13 }, { 0x9e,0x2f,0x4b,0x1d }, 
1700     { 0xe9,0x64,0x22,0x47 }, { 0xe0,0x69,0x29,0x49 }, 
1701     { 0xfb,0x7e,0x34,0x5b }, { 0xf2,0x73,0x3f,0x55 }, 
1702     { 0xcd,0x50,0x0e,0x7f }, { 0xc4,0x5d,0x05,0x71 },
1703     { 0xdf,0x4a,0x18,0x63 }, { 0xd6,0x47,0x13,0x6d }, 
1704     { 0x31,0xdc,0xca,0xd7 }, { 0x38,0xd1,0xc1,0xd9 },
1705     { 0x23,0xc6,0xdc,0xcb }, { 0x2a,0xcb,0xd7,0xc5 }, 
1706     { 0x15,0xe8,0xe6,0xef }, { 0x1c,0xe5,0xed,0xe1 },
1707     { 0x07,0xf2,0xf0,0xf3 }, { 0x0e,0xff,0xfb,0xfd }, 
1708     { 0x79,0xb4,0x92,0xa7 }, { 0x70,0xb9,0x99,0xa9 },
1709     { 0x6b,0xae,0x84,0xbb }, { 0x62,0xa3,0x8f,0xb5 }, 
1710     { 0x5d,0x80,0xbe,0x9f }, { 0x54,0x8d,0xb5,0x91 },
1711     { 0x4f,0x9a,0xa8,0x83 }, { 0x46,0x97,0xa3,0x8d }
1712 };
1713
1714 static const u32 rcon[30] = { 
1715     0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
1716     0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35,
1717     0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91
1718 };
1719
1720 \f
1721
1722
1723 /* Perform the key setup.
1724  */  
1725 static gcry_err_code_t
1726 do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
1727 {
1728   static int initialized = 0;
1729   static const char *selftest_failed=0;
1730   int ROUNDS;
1731   byte k[MAXKC][4];
1732   int i,j, r, t, rconpointer = 0;
1733   byte tk[MAXKC][4];
1734   int KC;
1735   
1736   if (!initialized)
1737     {
1738       initialized = 1;
1739       selftest_failed = selftest ();
1740       if( selftest_failed )
1741         log_error ("%s\n", selftest_failed );
1742     }
1743   if( selftest_failed )
1744     return GPG_ERR_SELFTEST_FAILED;
1745
1746   if( keylen == 128/8 )
1747     {
1748       ROUNDS = 10;
1749       KC = 4;
1750     }
1751   else if ( keylen == 192/8 )
1752     {
1753       ROUNDS = 12;
1754       KC = 6;
1755     }
1756   else if ( keylen == 256/8 )
1757     {
1758       ROUNDS = 14;
1759       KC = 8;
1760     }
1761   else
1762     return GPG_ERR_INV_KEYLEN;
1763
1764   ctx->ROUNDS = ROUNDS;
1765   ctx->decryption_prepared = 0;
1766
1767   for (i = 0; i < keylen; i++) 
1768     {
1769       k[i >> 2][i & 3] = key[i]; 
1770     }
1771 #define W (ctx->keySched)
1772
1773   for (j = KC-1; j >= 0; j--) 
1774     {
1775       *((u32*)tk[j]) = *((u32*)k[j]);
1776     }
1777   r = 0;
1778   t = 0;
1779   /* copy values into round key array */
1780   for (j = 0; (j < KC) && (r < ROUNDS + 1); )
1781     {
1782       for (; (j < KC) && (t < 4); j++, t++)
1783         {
1784           *((u32*)W[r][t]) = *((u32*)tk[j]);
1785         }
1786       if (t == 4)
1787         {
1788           r++;
1789           t = 0;
1790         }
1791     }
1792                 
1793   while (r < ROUNDS + 1)
1794     {
1795       /* While not enough round key material calculated */
1796       /* calculate new values. */
1797       tk[0][0] ^= S[tk[KC-1][1]];
1798       tk[0][1] ^= S[tk[KC-1][2]];
1799       tk[0][2] ^= S[tk[KC-1][3]];
1800       tk[0][3] ^= S[tk[KC-1][0]];
1801       tk[0][0] ^= rcon[rconpointer++];
1802         
1803       if (KC != 8)
1804         {
1805           for (j = 1; j < KC; j++) 
1806             {
1807               *((u32*)tk[j]) ^= *((u32*)tk[j-1]);
1808             }
1809         } 
1810       else 
1811         {
1812           for (j = 1; j < KC/2; j++)
1813             {
1814               *((u32*)tk[j]) ^= *((u32*)tk[j-1]);
1815             }
1816           tk[KC/2][0] ^= S[tk[KC/2 - 1][0]];
1817           tk[KC/2][1] ^= S[tk[KC/2 - 1][1]];
1818           tk[KC/2][2] ^= S[tk[KC/2 - 1][2]];
1819           tk[KC/2][3] ^= S[tk[KC/2 - 1][3]];
1820           for (j = KC/2 + 1; j < KC; j++)
1821             {
1822               *((u32*)tk[j]) ^= *((u32*)tk[j-1]);
1823             }
1824         }
1825
1826       /* Copy values into round key array. */
1827       for (j = 0; (j < KC) && (r < ROUNDS + 1); )
1828         {
1829           for (; (j < KC) && (t < 4); j++, t++)
1830             {
1831               *((u32*)W[r][t]) = *((u32*)tk[j]);
1832             }
1833           if (t == 4)
1834             {
1835               r++;
1836               t = 0;
1837             }
1838         }
1839     }           
1840     
1841 #undef W    
1842   return 0;
1843 }
1844
1845 static gcry_err_code_t
1846 rijndael_setkey (void *context, const byte *key, const unsigned keylen)
1847 {
1848   RIJNDAEL_context *ctx = context;
1849
1850   int rc = do_setkey (ctx, key, keylen);
1851   _gcry_burn_stack ( 100 + 16*sizeof(int));
1852   return rc;
1853 }
1854
1855
1856 /* Make a decryption key from an encryption key. */
1857 static void
1858 prepare_decryption( RIJNDAEL_context *ctx )
1859 {
1860   int r;
1861   byte *w;
1862
1863   for (r=0; r < MAXROUNDS+1; r++ )
1864     {
1865       *((u32*)ctx->keySched2[r][0]) = *((u32*)ctx->keySched[r][0]);
1866       *((u32*)ctx->keySched2[r][1]) = *((u32*)ctx->keySched[r][1]);
1867       *((u32*)ctx->keySched2[r][2]) = *((u32*)ctx->keySched[r][2]);
1868       *((u32*)ctx->keySched2[r][3]) = *((u32*)ctx->keySched[r][3]);
1869     }
1870 #define W (ctx->keySched2)
1871   for (r = 1; r < ctx->ROUNDS; r++)
1872     {
1873       w = W[r][0];
1874       *((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
1875         ^ *((u32*)U3[w[2]]) ^ *((u32*)U4[w[3]]);
1876        
1877       w = W[r][1];
1878       *((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
1879         ^ *((u32*)U3[w[2]]) ^ *((u32*)U4[w[3]]);
1880         
1881       w = W[r][2];
1882       *((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
1883         ^ *((u32*)U3[w[2]]) ^ *((u32*)U4[w[3]]);
1884         
1885       w = W[r][3];
1886       *((u32*)w) = *((u32*)U1[w[0]]) ^ *((u32*)U2[w[1]])
1887         ^ *((u32*)U3[w[2]]) ^ *((u32*)U4[w[3]]);
1888     }
1889 #undef W
1890 }       
1891
1892
1893 \f
1894 /* Encrypt one block.  A and B may be the same. */
1895 static void
1896 do_encrypt (const RIJNDAEL_context *ctx, byte *bx, const byte *ax)
1897 {
1898   /* FIXME: Ugly code, replace by straighter implementaion and use
1899      optimized assembler for common CPUs. */
1900
1901   int r;
1902   union
1903   {
1904     u32  tempu32[4];  /* Force correct alignment. */
1905     byte temp[4][4];
1906   } u;
1907   int ROUNDS = ctx->ROUNDS;
1908 #define rk (ctx->keySched)
1909
1910   /* BX and AX are not necessary correctly aligned.  Thus we need to
1911      copy them here. */
1912   union
1913   {
1914     u32  dummy[4]; 
1915     byte a[16];
1916   } a;
1917   union
1918   {
1919     u32  dummy[4]; 
1920     byte b[16];
1921   } b;
1922
1923   memcpy (a.a, ax, 16);
1924
1925   *((u32*)u.temp[0]) = *((u32*)(a.a   )) ^ *((u32*)rk[0][0]);
1926   *((u32*)u.temp[1]) = *((u32*)(a.a+ 4)) ^ *((u32*)rk[0][1]);
1927   *((u32*)u.temp[2]) = *((u32*)(a.a+ 8)) ^ *((u32*)rk[0][2]);
1928   *((u32*)u.temp[3]) = *((u32*)(a.a+12)) ^ *((u32*)rk[0][3]);
1929   *((u32*)(b.b    )) = (*((u32*)T1[u.temp[0][0]])
1930                       ^ *((u32*)T2[u.temp[1][1]])
1931                       ^ *((u32*)T3[u.temp[2][2]]) 
1932                       ^ *((u32*)T4[u.temp[3][3]]));
1933   *((u32*)(b.b + 4)) = (*((u32*)T1[u.temp[1][0]])
1934                       ^ *((u32*)T2[u.temp[2][1]])
1935                       ^ *((u32*)T3[u.temp[3][2]]) 
1936                       ^ *((u32*)T4[u.temp[0][3]]));
1937   *((u32*)(b.b + 8)) = (*((u32*)T1[u.temp[2][0]])
1938                       ^ *((u32*)T2[u.temp[3][1]])
1939                       ^ *((u32*)T3[u.temp[0][2]]) 
1940                       ^ *((u32*)T4[u.temp[1][3]]));
1941   *((u32*)(b.b +12)) = (*((u32*)T1[u.temp[3][0]])
1942                       ^ *((u32*)T2[u.temp[0][1]])
1943                       ^ *((u32*)T3[u.temp[1][2]]) 
1944                       ^ *((u32*)T4[u.temp[2][3]]));
1945
1946   for (r = 1; r < ROUNDS-1; r++)
1947     {
1948       *((u32*)u.temp[0]) = *((u32*)(b.b   )) ^ *((u32*)rk[r][0]);
1949       *((u32*)u.temp[1]) = *((u32*)(b.b+ 4)) ^ *((u32*)rk[r][1]);
1950       *((u32*)u.temp[2]) = *((u32*)(b.b+ 8)) ^ *((u32*)rk[r][2]);
1951       *((u32*)u.temp[3]) = *((u32*)(b.b+12)) ^ *((u32*)rk[r][3]);
1952
1953       *((u32*)(b.b    )) = (*((u32*)T1[u.temp[0][0]])
1954                           ^ *((u32*)T2[u.temp[1][1]])
1955                           ^ *((u32*)T3[u.temp[2][2]]) 
1956                           ^ *((u32*)T4[u.temp[3][3]]));
1957       *((u32*)(b.b + 4)) = (*((u32*)T1[u.temp[1][0]])
1958                           ^ *((u32*)T2[u.temp[2][1]])
1959                           ^ *((u32*)T3[u.temp[3][2]]) 
1960                           ^ *((u32*)T4[u.temp[0][3]]));
1961       *((u32*)(b.b + 8)) = (*((u32*)T1[u.temp[2][0]])
1962                           ^ *((u32*)T2[u.temp[3][1]])
1963                           ^ *((u32*)T3[u.temp[0][2]]) 
1964                           ^ *((u32*)T4[u.temp[1][3]]));
1965       *((u32*)(b.b +12)) = (*((u32*)T1[u.temp[3][0]])
1966                           ^ *((u32*)T2[u.temp[0][1]])
1967                           ^ *((u32*)T3[u.temp[1][2]]) 
1968                           ^ *((u32*)T4[u.temp[2][3]]));
1969     }
1970
1971   /* Last round is special. */   
1972   *((u32*)u.temp[0]) = *((u32*)(b.b   )) ^ *((u32*)rk[ROUNDS-1][0]);
1973   *((u32*)u.temp[1]) = *((u32*)(b.b+ 4)) ^ *((u32*)rk[ROUNDS-1][1]);
1974   *((u32*)u.temp[2]) = *((u32*)(b.b+ 8)) ^ *((u32*)rk[ROUNDS-1][2]);
1975   *((u32*)u.temp[3]) = *((u32*)(b.b+12)) ^ *((u32*)rk[ROUNDS-1][3]);
1976   b.b[ 0] = T1[u.temp[0][0]][1];
1977   b.b[ 1] = T1[u.temp[1][1]][1];
1978   b.b[ 2] = T1[u.temp[2][2]][1];
1979   b.b[ 3] = T1[u.temp[3][3]][1];
1980   b.b[ 4] = T1[u.temp[1][0]][1];
1981   b.b[ 5] = T1[u.temp[2][1]][1];
1982   b.b[ 6] = T1[u.temp[3][2]][1];
1983   b.b[ 7] = T1[u.temp[0][3]][1];
1984   b.b[ 8] = T1[u.temp[2][0]][1];
1985   b.b[ 9] = T1[u.temp[3][1]][1];
1986   b.b[10] = T1[u.temp[0][2]][1];
1987   b.b[11] = T1[u.temp[1][3]][1];
1988   b.b[12] = T1[u.temp[3][0]][1];
1989   b.b[13] = T1[u.temp[0][1]][1];
1990   b.b[14] = T1[u.temp[1][2]][1];
1991   b.b[15] = T1[u.temp[2][3]][1];
1992   *((u32*)(b.b   )) ^= *((u32*)rk[ROUNDS][0]);
1993   *((u32*)(b.b+ 4)) ^= *((u32*)rk[ROUNDS][1]);
1994   *((u32*)(b.b+ 8)) ^= *((u32*)rk[ROUNDS][2]);
1995   *((u32*)(b.b+12)) ^= *((u32*)rk[ROUNDS][3]);
1996
1997   memcpy (bx, b.b, 16);
1998 #undef rk
1999 }
2000
2001 static void
2002 rijndael_encrypt (void *context, byte *b, const byte *a)
2003 {
2004   RIJNDAEL_context *ctx = context;
2005
2006   do_encrypt (ctx, b, a);
2007   _gcry_burn_stack (48 + 2*sizeof(int));
2008 }
2009
2010
2011 \f
2012 /* Decrypt one block.  a and b may be the same. */
2013 static void
2014 do_decrypt (RIJNDAEL_context *ctx, byte *bx, const byte *ax)
2015 {
2016 #define rk  (ctx->keySched2)
2017   int ROUNDS = ctx->ROUNDS; 
2018   int r;
2019   union {
2020     u32  tempu32[4];  /* Force correct alignment. */
2021     byte temp[4][4];
2022   } u;
2023
2024   /* BX and AX are not necessary correctly aligned.  Thus we need to
2025      copy them here. */
2026   union
2027   {
2028     u32  dummy[4]; 
2029     byte a[16];
2030   } a;
2031   union
2032   {
2033     u32  dummy[4]; 
2034     byte b[16];
2035   } b;
2036
2037   memcpy (a.a, ax, 16);
2038
2039   if ( !ctx->decryption_prepared )
2040     {
2041       prepare_decryption ( ctx );
2042       _gcry_burn_stack (64);
2043       ctx->decryption_prepared = 1;
2044     }
2045     
2046   *((u32*)u.temp[0]) = *((u32*)(a.a   )) ^ *((u32*)rk[ROUNDS][0]);
2047   *((u32*)u.temp[1]) = *((u32*)(a.a+ 4)) ^ *((u32*)rk[ROUNDS][1]);
2048   *((u32*)u.temp[2]) = *((u32*)(a.a+ 8)) ^ *((u32*)rk[ROUNDS][2]);
2049   *((u32*)u.temp[3]) = *((u32*)(a.a+12)) ^ *((u32*)rk[ROUNDS][3]);
2050   
2051   *((u32*)(b.b   )) = (*((u32*)T5[u.temp[0][0]])
2052                      ^ *((u32*)T6[u.temp[3][1]])
2053                      ^ *((u32*)T7[u.temp[2][2]]) 
2054                      ^ *((u32*)T8[u.temp[1][3]]));
2055   *((u32*)(b.b+ 4)) = (*((u32*)T5[u.temp[1][0]])
2056                      ^ *((u32*)T6[u.temp[0][1]])
2057                      ^ *((u32*)T7[u.temp[3][2]]) 
2058                      ^ *((u32*)T8[u.temp[2][3]]));
2059   *((u32*)(b.b+ 8)) = (*((u32*)T5[u.temp[2][0]])
2060                      ^ *((u32*)T6[u.temp[1][1]])
2061                      ^ *((u32*)T7[u.temp[0][2]]) 
2062                      ^ *((u32*)T8[u.temp[3][3]]));
2063   *((u32*)(b.b+12)) = (*((u32*)T5[u.temp[3][0]])
2064                      ^ *((u32*)T6[u.temp[2][1]])
2065                      ^ *((u32*)T7[u.temp[1][2]]) 
2066                      ^ *((u32*)T8[u.temp[0][3]]));
2067
2068   for (r = ROUNDS-1; r > 1; r--)
2069     {
2070       *((u32*)u.temp[0]) = *((u32*)(b.b   )) ^ *((u32*)rk[r][0]);
2071       *((u32*)u.temp[1]) = *((u32*)(b.b+ 4)) ^ *((u32*)rk[r][1]);
2072       *((u32*)u.temp[2]) = *((u32*)(b.b+ 8)) ^ *((u32*)rk[r][2]);
2073       *((u32*)u.temp[3]) = *((u32*)(b.b+12)) ^ *((u32*)rk[r][3]);
2074       *((u32*)(b.b   )) = (*((u32*)T5[u.temp[0][0]])
2075                          ^ *((u32*)T6[u.temp[3][1]])
2076                          ^ *((u32*)T7[u.temp[2][2]]) 
2077                          ^ *((u32*)T8[u.temp[1][3]]));
2078       *((u32*)(b.b+ 4)) = (*((u32*)T5[u.temp[1][0]])
2079                          ^ *((u32*)T6[u.temp[0][1]])
2080                          ^ *((u32*)T7[u.temp[3][2]]) 
2081                          ^ *((u32*)T8[u.temp[2][3]]));
2082       *((u32*)(b.b+ 8)) = (*((u32*)T5[u.temp[2][0]])
2083                          ^ *((u32*)T6[u.temp[1][1]])
2084                          ^ *((u32*)T7[u.temp[0][2]]) 
2085                          ^ *((u32*)T8[u.temp[3][3]]));
2086       *((u32*)(b.b+12)) = (*((u32*)T5[u.temp[3][0]])
2087                          ^ *((u32*)T6[u.temp[2][1]])
2088                          ^ *((u32*)T7[u.temp[1][2]]) 
2089                          ^ *((u32*)T8[u.temp[0][3]]));
2090     }
2091
2092   /* Last round is special. */   
2093   *((u32*)u.temp[0]) = *((u32*)(b.b   )) ^ *((u32*)rk[1][0]);
2094   *((u32*)u.temp[1]) = *((u32*)(b.b+ 4)) ^ *((u32*)rk[1][1]);
2095   *((u32*)u.temp[2]) = *((u32*)(b.b+ 8)) ^ *((u32*)rk[1][2]);
2096   *((u32*)u.temp[3]) = *((u32*)(b.b+12)) ^ *((u32*)rk[1][3]);
2097   b.b[ 0] = S5[u.temp[0][0]];
2098   b.b[ 1] = S5[u.temp[3][1]];
2099   b.b[ 2] = S5[u.temp[2][2]];
2100   b.b[ 3] = S5[u.temp[1][3]];
2101   b.b[ 4] = S5[u.temp[1][0]];
2102   b.b[ 5] = S5[u.temp[0][1]];
2103   b.b[ 6] = S5[u.temp[3][2]];
2104   b.b[ 7] = S5[u.temp[2][3]];
2105   b.b[ 8] = S5[u.temp[2][0]];
2106   b.b[ 9] = S5[u.temp[1][1]];
2107   b.b[10] = S5[u.temp[0][2]];
2108   b.b[11] = S5[u.temp[3][3]];
2109   b.b[12] = S5[u.temp[3][0]];
2110   b.b[13] = S5[u.temp[2][1]];
2111   b.b[14] = S5[u.temp[1][2]];
2112   b.b[15] = S5[u.temp[0][3]];
2113   *((u32*)(b.b   )) ^= *((u32*)rk[0][0]);
2114   *((u32*)(b.b+ 4)) ^= *((u32*)rk[0][1]);
2115   *((u32*)(b.b+ 8)) ^= *((u32*)rk[0][2]);
2116   *((u32*)(b.b+12)) ^= *((u32*)rk[0][3]);
2117
2118   memcpy (bx, b.b, 16);
2119 #undef rk
2120 }
2121
2122 static void
2123 rijndael_decrypt (void *context, byte *b, const byte *a)
2124 {
2125   RIJNDAEL_context *ctx = context;
2126
2127   do_decrypt (ctx, b, a);
2128   _gcry_burn_stack (48+2*sizeof(int));
2129 }
2130
2131 \f
2132 /* Test a single encryption and decryption with each key size. */
2133 static const char*
2134 selftest (void)
2135 {
2136   RIJNDAEL_context ctx;
2137   byte scratch[16];        
2138
2139   /* The test vectors are from the AES supplied ones; more or less 
2140    * randomly taken from ecb_tbl.txt (I=42,81,14)
2141    */
2142   static byte plaintext[16] = {
2143     0x01,0x4B,0xAF,0x22,0x78,0xA6,0x9D,0x33,
2144     0x1D,0x51,0x80,0x10,0x36,0x43,0xE9,0x9A
2145   };
2146   static byte key[16] = {
2147     0xE8,0xE9,0xEA,0xEB,0xED,0xEE,0xEF,0xF0,
2148     0xF2,0xF3,0xF4,0xF5,0xF7,0xF8,0xF9,0xFA
2149   };
2150   static const byte ciphertext[16] = {
2151     0x67,0x43,0xC3,0xD1,0x51,0x9A,0xB4,0xF2,
2152     0xCD,0x9A,0x78,0xAB,0x09,0xA5,0x11,0xBD
2153   };
2154
2155   static byte plaintext_192[16] = {
2156     0x76,0x77,0x74,0x75,0xF1,0xF2,0xF3,0xF4,
2157     0xF8,0xF9,0xE6,0xE7,0x77,0x70,0x71,0x72
2158   };
2159   static byte key_192[24] = {
2160     0x04,0x05,0x06,0x07,0x09,0x0A,0x0B,0x0C,
2161     0x0E,0x0F,0x10,0x11,0x13,0x14,0x15,0x16,
2162     0x18,0x19,0x1A,0x1B,0x1D,0x1E,0x1F,0x20
2163   };
2164   static const byte ciphertext_192[16] = {
2165     0x5D,0x1E,0xF2,0x0D,0xCE,0xD6,0xBC,0xBC,
2166     0x12,0x13,0x1A,0xC7,0xC5,0x47,0x88,0xAA
2167   };
2168     
2169   static byte plaintext_256[16] = {
2170     0x06,0x9A,0x00,0x7F,0xC7,0x6A,0x45,0x9F,
2171     0x98,0xBA,0xF9,0x17,0xFE,0xDF,0x95,0x21
2172   };
2173   static byte key_256[32] = {
2174     0x08,0x09,0x0A,0x0B,0x0D,0x0E,0x0F,0x10,
2175     0x12,0x13,0x14,0x15,0x17,0x18,0x19,0x1A,
2176     0x1C,0x1D,0x1E,0x1F,0x21,0x22,0x23,0x24,
2177     0x26,0x27,0x28,0x29,0x2B,0x2C,0x2D,0x2E
2178   };
2179   static const byte ciphertext_256[16] = {
2180     0x08,0x0E,0x95,0x17,0xEB,0x16,0x77,0x71,
2181     0x9A,0xCF,0x72,0x80,0x86,0x04,0x0A,0xE3
2182   };
2183
2184   rijndael_setkey (&ctx, key, sizeof(key));
2185   rijndael_encrypt (&ctx, scratch, plaintext);
2186   if (memcmp (scratch, ciphertext, sizeof (ciphertext)))
2187     return "Rijndael-128 test encryption failed.";
2188   rijndael_decrypt (&ctx, scratch, scratch);
2189   if (memcmp (scratch, plaintext, sizeof (plaintext)))
2190     return "Rijndael-128 test decryption failed.";
2191
2192   rijndael_setkey (&ctx, key_192, sizeof(key_192));
2193   rijndael_encrypt (&ctx, scratch, plaintext_192);
2194   if (memcmp (scratch, ciphertext_192, sizeof (ciphertext_192)))
2195     return "Rijndael-192 test encryption failed.";
2196   rijndael_decrypt (&ctx, scratch, scratch);
2197   if (memcmp (scratch, plaintext_192, sizeof (plaintext_192)))
2198     return "Rijndael-192 test decryption failed.";
2199     
2200   rijndael_setkey (&ctx, key_256, sizeof(key_256));
2201   rijndael_encrypt (&ctx, scratch, plaintext_256);
2202   if (memcmp (scratch, ciphertext_256, sizeof (ciphertext_256)))
2203     return "Rijndael-256 test encryption failed.";
2204   rijndael_decrypt (&ctx, scratch, scratch);
2205   if (memcmp (scratch, plaintext_256, sizeof (plaintext_256)))
2206     return "Rijndael-256 test decryption failed.";
2207     
2208   return NULL;
2209 }
2210
2211 \f
2212
2213 static const char *rijndael_names[] =
2214   {
2215     "RIJNDAEL",
2216     NULL,
2217   };
2218
2219 static gcry_cipher_oid_spec_t rijndael_oids[] =
2220   {
2221     { "2.16.840.1.101.3.4.1.1", GCRY_CIPHER_MODE_ECB },
2222     { "2.16.840.1.101.3.4.1.2", GCRY_CIPHER_MODE_CBC },
2223     { "2.16.840.1.101.3.4.1.3", GCRY_CIPHER_MODE_OFB },
2224     { "2.16.840.1.101.3.4.1.4", GCRY_CIPHER_MODE_CFB },
2225     { NULL }
2226   };
2227
2228 gcry_cipher_spec_t _gcry_cipher_spec_aes =
2229   {
2230     "AES", rijndael_names, rijndael_oids, 16, 128, sizeof (RIJNDAEL_context),
2231     rijndael_setkey, rijndael_encrypt, rijndael_decrypt,
2232   };
2233
2234 static const char *rijndael192_names[] =
2235   {
2236     "RIJNDAEL192",
2237     NULL,
2238   };
2239
2240 static gcry_cipher_oid_spec_t rijndael192_oids[] =
2241   {
2242     { "2.16.840.1.101.3.4.1.21", GCRY_CIPHER_MODE_ECB },
2243     { "2.16.840.1.101.3.4.1.22", GCRY_CIPHER_MODE_CBC },
2244     { "2.16.840.1.101.3.4.1.23", GCRY_CIPHER_MODE_OFB },
2245     { "2.16.840.1.101.3.4.1.24", GCRY_CIPHER_MODE_CFB },
2246     { NULL }
2247   };
2248
2249 gcry_cipher_spec_t _gcry_cipher_spec_aes192 =
2250   {
2251     "AES192", rijndael192_names, rijndael192_oids, 16, 192, sizeof (RIJNDAEL_context),
2252     rijndael_setkey, rijndael_encrypt, rijndael_decrypt,
2253   };
2254
2255 static const char *rijndael256_names[] =
2256   {
2257     "RIJNDAEL256",
2258     NULL,
2259   };
2260
2261 static gcry_cipher_oid_spec_t rijndael256_oids[] =
2262   {
2263     { "2.16.840.1.101.3.4.1.41", GCRY_CIPHER_MODE_ECB },
2264     { "2.16.840.1.101.3.4.1.42", GCRY_CIPHER_MODE_CBC },
2265     { "2.16.840.1.101.3.4.1.43", GCRY_CIPHER_MODE_OFB },
2266     { "2.16.840.1.101.3.4.1.44", GCRY_CIPHER_MODE_CFB },
2267     { NULL }
2268   };
2269
2270 gcry_cipher_spec_t _gcry_cipher_spec_aes256 =
2271   {
2272     "AES256", rijndael256_names, rijndael256_oids, 16, 256,
2273     sizeof (RIJNDAEL_context),
2274     rijndael_setkey, rijndael_encrypt, rijndael_decrypt,
2275   };