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