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