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