1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski #include <sal/types.h>
24*b1cdbd2cSJim Jagielski #include <osl/diagnose.h>
25*b1cdbd2cSJim Jagielski #include <rtl/cipher.h>
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski #include <stdio.h>
28*b1cdbd2cSJim Jagielski #include <string.h>
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski #define NUM_VARIABLE_KEY_TESTS 34
31*b1cdbd2cSJim Jagielski #define NUM_SET_KEY_TESTS 24
32*b1cdbd2cSJim Jagielski
33*b1cdbd2cSJim Jagielski /* plaintext bytes -- left halves */
34*b1cdbd2cSJim Jagielski unsigned long plaintext_l[NUM_VARIABLE_KEY_TESTS + NUM_SET_KEY_TESTS] = {
35*b1cdbd2cSJim Jagielski 0x00000000l, 0xFFFFFFFFl, 0x10000000l, 0x11111111l, 0x11111111l,
36*b1cdbd2cSJim Jagielski 0x01234567l, 0x00000000l, 0x01234567l, 0x01A1D6D0l, 0x5CD54CA8l,
37*b1cdbd2cSJim Jagielski 0x0248D438l, 0x51454B58l, 0x42FD4430l, 0x059B5E08l, 0x0756D8E0l,
38*b1cdbd2cSJim Jagielski 0x762514B8l, 0x3BDD1190l, 0x26955F68l, 0x164D5E40l, 0x6B056E18l,
39*b1cdbd2cSJim Jagielski 0x004BD6EFl, 0x480D3900l, 0x437540C8l, 0x072D43A0l, 0x02FE5577l,
40*b1cdbd2cSJim Jagielski 0x1D9D5C50l, 0x30553228l, 0x01234567l, 0x01234567l, 0x01234567l,
41*b1cdbd2cSJim Jagielski 0xFFFFFFFFl, 0x00000000l, 0x00000000l, 0xFFFFFFFFl, 0xFEDCBA98l,
42*b1cdbd2cSJim Jagielski 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l,
43*b1cdbd2cSJim Jagielski 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l,
44*b1cdbd2cSJim Jagielski 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l,
45*b1cdbd2cSJim Jagielski 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l,
46*b1cdbd2cSJim Jagielski 0xFEDCBA98l, 0xFEDCBA98l, 0xFEDCBA98l };
47*b1cdbd2cSJim Jagielski
48*b1cdbd2cSJim Jagielski /* plaintext bytes -- right halves */
49*b1cdbd2cSJim Jagielski unsigned long plaintext_r[NUM_VARIABLE_KEY_TESTS + NUM_SET_KEY_TESTS] = {
50*b1cdbd2cSJim Jagielski 0x00000000l, 0xFFFFFFFFl, 0x00000001l, 0x11111111l, 0x11111111l,
51*b1cdbd2cSJim Jagielski 0x89ABCDEFl, 0x00000000l, 0x89ABCDEFl, 0x39776742l, 0x3DEF57DAl,
52*b1cdbd2cSJim Jagielski 0x06F67172l, 0x2DDF440Al, 0x59577FA2l, 0x51CF143Al, 0x774761D2l,
53*b1cdbd2cSJim Jagielski 0x29BF486Al, 0x49372802l, 0x35AF609Al, 0x4F275232l, 0x759F5CCAl,
54*b1cdbd2cSJim Jagielski 0x09176062l, 0x6EE762F2l, 0x698F3CFAl, 0x77075292l, 0x8117F12Al,
55*b1cdbd2cSJim Jagielski 0x18F728C2l, 0x6D6F295Al, 0x89ABCDEFl, 0x89ABCDEFl, 0x89ABCDEFl,
56*b1cdbd2cSJim Jagielski 0xFFFFFFFFl, 0x00000000l, 0x00000000l, 0xFFFFFFFFl, 0x76543210l,
57*b1cdbd2cSJim Jagielski 0x76543210l, 0x76543210l, 0x76543210l, 0x76543210l, 0x76543210l,
58*b1cdbd2cSJim Jagielski 0x76543210l, 0x76543210l, 0x76543210l, 0x76543210l, 0x76543210l,
59*b1cdbd2cSJim Jagielski 0x76543210l, 0x76543210l, 0x76543210l, 0x76543210l, 0x76543210l,
60*b1cdbd2cSJim Jagielski 0x76543210l, 0x76543210l, 0x76543210l, 0x76543210l, 0x76543210l,
61*b1cdbd2cSJim Jagielski 0x76543210l, 0x76543210l, 0x76543210l };
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielski /* key bytes for variable key tests */
64*b1cdbd2cSJim Jagielski unsigned char variable_key[NUM_VARIABLE_KEY_TESTS][8] = {
65*b1cdbd2cSJim Jagielski { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
66*b1cdbd2cSJim Jagielski { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
67*b1cdbd2cSJim Jagielski { 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
68*b1cdbd2cSJim Jagielski { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
69*b1cdbd2cSJim Jagielski { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
70*b1cdbd2cSJim Jagielski { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
71*b1cdbd2cSJim Jagielski { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
72*b1cdbd2cSJim Jagielski { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
73*b1cdbd2cSJim Jagielski { 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 },
74*b1cdbd2cSJim Jagielski { 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E },
75*b1cdbd2cSJim Jagielski { 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 },
76*b1cdbd2cSJim Jagielski { 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E },
77*b1cdbd2cSJim Jagielski { 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 },
78*b1cdbd2cSJim Jagielski { 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE },
79*b1cdbd2cSJim Jagielski { 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 },
80*b1cdbd2cSJim Jagielski { 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE },
81*b1cdbd2cSJim Jagielski { 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 },
82*b1cdbd2cSJim Jagielski { 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F },
83*b1cdbd2cSJim Jagielski { 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 },
84*b1cdbd2cSJim Jagielski { 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E },
85*b1cdbd2cSJim Jagielski { 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
86*b1cdbd2cSJim Jagielski { 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 },
87*b1cdbd2cSJim Jagielski { 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F },
88*b1cdbd2cSJim Jagielski { 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 },
89*b1cdbd2cSJim Jagielski { 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF },
90*b1cdbd2cSJim Jagielski { 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 },
91*b1cdbd2cSJim Jagielski { 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF },
92*b1cdbd2cSJim Jagielski { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
93*b1cdbd2cSJim Jagielski { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
94*b1cdbd2cSJim Jagielski { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
95*b1cdbd2cSJim Jagielski { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
96*b1cdbd2cSJim Jagielski { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
97*b1cdbd2cSJim Jagielski { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
98*b1cdbd2cSJim Jagielski { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }};
99*b1cdbd2cSJim Jagielski
100*b1cdbd2cSJim Jagielski /* key bytes for set key tests */
101*b1cdbd2cSJim Jagielski unsigned char set_key[24] = {
102*b1cdbd2cSJim Jagielski 0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87,
103*b1cdbd2cSJim Jagielski 0x78, 0x69, 0x5A, 0x4B, 0x3C, 0x2D, 0x1E, 0x0F,
104*b1cdbd2cSJim Jagielski 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
105*b1cdbd2cSJim Jagielski
106*b1cdbd2cSJim Jagielski /* ciphertext bytes -- left halves */
107*b1cdbd2cSJim Jagielski unsigned long ciphertext_l[NUM_VARIABLE_KEY_TESTS + NUM_SET_KEY_TESTS] = {
108*b1cdbd2cSJim Jagielski 0x4EF99745l, 0x51866FD5l, 0x7D856F9Al, 0x2466DD87l, 0x61F9C380l,
109*b1cdbd2cSJim Jagielski 0x7D0CC630l, 0x4EF99745l, 0x0ACEAB0Fl, 0x59C68245l, 0xB1B8CC0Bl,
110*b1cdbd2cSJim Jagielski 0x1730E577l, 0xA25E7856l, 0x353882B1l, 0x48F4D088l, 0x432193B7l,
111*b1cdbd2cSJim Jagielski 0x13F04154l, 0x2EEDDA93l, 0xD887E039l, 0x5F99D04Fl, 0x4A057A3Bl,
112*b1cdbd2cSJim Jagielski 0x452031C1l, 0x7555AE39l, 0x53C55F9Cl, 0x7A8E7BFAl, 0xCF9C5D7Al,
113*b1cdbd2cSJim Jagielski 0xD1ABB290l, 0x55CB3774l, 0xFA34EC48l, 0xA7907951l, 0xC39E072Dl,
114*b1cdbd2cSJim Jagielski 0x014933E0l, 0xF21E9A77l, 0x24594688l, 0x6B5C5A9Cl, 0xF9AD597Cl,
115*b1cdbd2cSJim Jagielski 0xE91D21C1l, 0xE9C2B70Al, 0xBE1E6394l, 0xB39E4448l, 0x9457AA83l,
116*b1cdbd2cSJim Jagielski 0x8BB77032l, 0xE87A244El, 0x15750E7Al, 0x122BA70Bl, 0x3A833C9Al,
117*b1cdbd2cSJim Jagielski 0x9409DA87l, 0x884F8062l, 0x1F85031Cl, 0x79D9373Al, 0x93142887l,
118*b1cdbd2cSJim Jagielski 0x03429E83l, 0xA4299E27l, 0xAFD5AED1l, 0x10851C0El, 0xE6F51ED7l,
119*b1cdbd2cSJim Jagielski 0x64A6E14Al, 0x80C7D7D4l, 0x05044B62l };
120*b1cdbd2cSJim Jagielski
121*b1cdbd2cSJim Jagielski /* ciphertext bytes -- right halves */
122*b1cdbd2cSJim Jagielski unsigned long ciphertext_r[NUM_VARIABLE_KEY_TESTS + NUM_SET_KEY_TESTS] = {
123*b1cdbd2cSJim Jagielski 0x6198DD78l, 0xB85ECB8Al, 0x613063F2l, 0x8B963C9Dl, 0x2281B096l,
124*b1cdbd2cSJim Jagielski 0xAFDA1EC7l, 0x6198DD78l, 0xC6A0A28Dl, 0xEB05282Bl, 0x250F09A0l,
125*b1cdbd2cSJim Jagielski 0x8BEA1DA4l, 0xCF2651EBl, 0x09CE8F1Al, 0x4C379918l, 0x8951FC98l,
126*b1cdbd2cSJim Jagielski 0xD69D1AE5l, 0xFFD39C79l, 0x3C2DA6E3l, 0x5B163969l, 0x24D3977Bl,
127*b1cdbd2cSJim Jagielski 0xE4FADA8El, 0xF59B87BDl, 0xB49FC019l, 0x937E89A3l, 0x4986ADB5l,
128*b1cdbd2cSJim Jagielski 0x658BC778l, 0xD13EF201l, 0x47B268B2l, 0x08EA3CAEl, 0x9FAC631Dl,
129*b1cdbd2cSJim Jagielski 0xCDAFF6E4l, 0xB71C49BCl, 0x5754369Al, 0x5D9E0A5Al, 0x49DB005El,
130*b1cdbd2cSJim Jagielski 0xD961A6D6l, 0x1BC65CF3l, 0x08640F05l, 0x1BDB1E6El, 0xB1928C0Dl,
131*b1cdbd2cSJim Jagielski 0xF960629Dl, 0x2CC85E82l, 0x4F4EC577l, 0x3AB64AE0l, 0xFFC537F6l,
132*b1cdbd2cSJim Jagielski 0xA90F6BF2l, 0x5060B8B4l, 0x19E11968l, 0x714CA34Fl, 0xEE3BE15Cl,
133*b1cdbd2cSJim Jagielski 0x8CE2D14Bl, 0x469FF67Bl, 0xC1BC96A8l, 0x3858DA9Fl, 0x9B9DB21Fl,
134*b1cdbd2cSJim Jagielski 0xFD36B46Fl, 0x5A5479ADl, 0xFA52D080l };
135*b1cdbd2cSJim Jagielski
136*b1cdbd2cSJim Jagielski
137*b1cdbd2cSJim Jagielski static sal_uInt8 cbc_key[16] =
138*b1cdbd2cSJim Jagielski {
139*b1cdbd2cSJim Jagielski 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
140*b1cdbd2cSJim Jagielski 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87
141*b1cdbd2cSJim Jagielski };
142*b1cdbd2cSJim Jagielski static sal_uInt8 cbc_iv[8] =
143*b1cdbd2cSJim Jagielski {
144*b1cdbd2cSJim Jagielski 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
145*b1cdbd2cSJim Jagielski };
146*b1cdbd2cSJim Jagielski
147*b1cdbd2cSJim Jagielski static sal_Char cbc_data[40] = "7654321 Now is the time for ";
148*b1cdbd2cSJim Jagielski
149*b1cdbd2cSJim Jagielski static sal_uInt8 ecb_ok[32] =
150*b1cdbd2cSJim Jagielski {
151*b1cdbd2cSJim Jagielski 0x2A, 0xFD, 0x7D, 0xAA, 0x60, 0x62, 0x6B, 0xA3,
152*b1cdbd2cSJim Jagielski 0x86, 0x16, 0x46, 0x8C, 0xC2, 0x9C, 0xF6, 0xE1,
153*b1cdbd2cSJim Jagielski 0x29, 0x1E, 0x81, 0x7C, 0xC7, 0x40, 0x98, 0x2D,
154*b1cdbd2cSJim Jagielski 0x6F, 0x87, 0xAC, 0x5F, 0x17, 0x1A, 0xAB, 0xEA
155*b1cdbd2cSJim Jagielski };
156*b1cdbd2cSJim Jagielski static sal_uInt8 cbc_ok[32] =
157*b1cdbd2cSJim Jagielski {
158*b1cdbd2cSJim Jagielski 0x6B, 0x77, 0xB4, 0xD6, 0x30, 0x06, 0xDE, 0xE6,
159*b1cdbd2cSJim Jagielski 0x05, 0xB1, 0x56, 0xE2, 0x74, 0x03, 0x97, 0x93,
160*b1cdbd2cSJim Jagielski 0x58, 0xDE, 0xB9, 0xE7, 0x15, 0x46, 0x16, 0xD9,
161*b1cdbd2cSJim Jagielski 0x59, 0xF1, 0x65, 0x2B, 0xD5, 0xFF, 0x92, 0xCC
162*b1cdbd2cSJim Jagielski };
163*b1cdbd2cSJim Jagielski static sal_uInt8 cfb_ok[] =
164*b1cdbd2cSJim Jagielski {
165*b1cdbd2cSJim Jagielski 0xE7, 0x32, 0x14, 0xA2, 0x82, 0x21, 0x39, 0xCA,
166*b1cdbd2cSJim Jagielski 0xF2, 0x6E, 0xCF, 0x6D, 0x2E, 0xB9, 0xE7, 0x6E,
167*b1cdbd2cSJim Jagielski 0x3D, 0xA3, 0xDE, 0x04, 0xD1, 0x51, 0x72, 0x00,
168*b1cdbd2cSJim Jagielski 0x51, 0x9D, 0x57, 0xA6, 0xC3
169*b1cdbd2cSJim Jagielski };
170*b1cdbd2cSJim Jagielski
171*b1cdbd2cSJim Jagielski static sal_uInt8 arcfour_key[6][30] =
172*b1cdbd2cSJim Jagielski {
173*b1cdbd2cSJim Jagielski { 8, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
174*b1cdbd2cSJim Jagielski { 8, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
175*b1cdbd2cSJim Jagielski { 8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
176*b1cdbd2cSJim Jagielski { 4, 0xef, 0x01, 0x23, 0x45 },
177*b1cdbd2cSJim Jagielski { 8, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
178*b1cdbd2cSJim Jagielski { 4, 0xef, 0x01, 0x23, 0x45 }
179*b1cdbd2cSJim Jagielski };
180*b1cdbd2cSJim Jagielski static sal_uInt8 arcfour_data_len[6] =
181*b1cdbd2cSJim Jagielski {
182*b1cdbd2cSJim Jagielski 8, 8, 8, 20, 28, 10
183*b1cdbd2cSJim Jagielski };
184*b1cdbd2cSJim Jagielski static sal_uInt8 arcfour_data[6][30] =
185*b1cdbd2cSJim Jagielski {
186*b1cdbd2cSJim Jagielski { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff },
187*b1cdbd2cSJim Jagielski { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff },
188*b1cdbd2cSJim Jagielski { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff },
189*b1cdbd2cSJim Jagielski { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
190*b1cdbd2cSJim Jagielski 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
191*b1cdbd2cSJim Jagielski 0x00, 0x00, 0x00, 0x00, 0xff },
192*b1cdbd2cSJim Jagielski { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
193*b1cdbd2cSJim Jagielski 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
194*b1cdbd2cSJim Jagielski 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
195*b1cdbd2cSJim Jagielski 0x12, 0x34, 0x56, 0x78, 0xff },
196*b1cdbd2cSJim Jagielski { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197*b1cdbd2cSJim Jagielski 0x00, 0x00, 0xff }
198*b1cdbd2cSJim Jagielski };
199*b1cdbd2cSJim Jagielski static sal_uInt8 arcfour_ok[6][30] =
200*b1cdbd2cSJim Jagielski {
201*b1cdbd2cSJim Jagielski { 0x75, 0xb7, 0x87, 0x80, 0x99, 0xe0, 0xc5, 0x96, 0x00},
202*b1cdbd2cSJim Jagielski { 0x74, 0x94, 0xc2, 0xe7, 0x10, 0x4b, 0x08, 0x79, 0x00},
203*b1cdbd2cSJim Jagielski { 0xde, 0x18, 0x89, 0x41, 0xa3, 0x37, 0x5d, 0x3a, 0x00},
204*b1cdbd2cSJim Jagielski { 0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf,
205*b1cdbd2cSJim Jagielski 0xbd, 0x61, 0x5a, 0x11, 0x62, 0xe1, 0xc7, 0xba,
206*b1cdbd2cSJim Jagielski 0x36, 0xb6, 0x78, 0x58, 0x00 },
207*b1cdbd2cSJim Jagielski { 0x66, 0xa0, 0x94, 0x9f, 0x8a, 0xf7, 0xd6, 0x89,
208*b1cdbd2cSJim Jagielski 0x1f, 0x7f, 0x83, 0x2b, 0xa8, 0x33, 0xc0, 0x0c,
209*b1cdbd2cSJim Jagielski 0x89, 0x2e, 0xbe, 0x30, 0x14, 0x3c, 0xe2, 0x87,
210*b1cdbd2cSJim Jagielski 0x40, 0x01, 0x1e, 0xcf, 0x00 },
211*b1cdbd2cSJim Jagielski { 0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf,
212*b1cdbd2cSJim Jagielski 0xbd, 0x61, 0x00}
213*b1cdbd2cSJim Jagielski };
214*b1cdbd2cSJim Jagielski
main(int argc,char * argv)215*b1cdbd2cSJim Jagielski int SAL_CALL main (int argc, char *argv)
216*b1cdbd2cSJim Jagielski {
217*b1cdbd2cSJim Jagielski rtlCipher cipher;
218*b1cdbd2cSJim Jagielski
219*b1cdbd2cSJim Jagielski /* ECB */
220*b1cdbd2cSJim Jagielski cipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
221*b1cdbd2cSJim Jagielski OSL_ASSERT(cipher != 0);
222*b1cdbd2cSJim Jagielski if (cipher != 0)
223*b1cdbd2cSJim Jagielski {
224*b1cdbd2cSJim Jagielski rtlCipherError result;
225*b1cdbd2cSJim Jagielski sal_uInt8 ecb_in[40], ecb_out[40];
226*b1cdbd2cSJim Jagielski sal_uInt32 length = strlen(cbc_data) + 1;
227*b1cdbd2cSJim Jagielski
228*b1cdbd2cSJim Jagielski result = rtl_cipher_init (
229*b1cdbd2cSJim Jagielski cipher, rtl_Cipher_DirectionBoth,
230*b1cdbd2cSJim Jagielski cbc_key, sizeof(cbc_key), NULL, 0);
231*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
232*b1cdbd2cSJim Jagielski
233*b1cdbd2cSJim Jagielski memset (ecb_out, 0, sizeof(ecb_out));
234*b1cdbd2cSJim Jagielski result = rtl_cipher_encode (
235*b1cdbd2cSJim Jagielski cipher, cbc_data, length, ecb_out, sizeof(ecb_out));
236*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
237*b1cdbd2cSJim Jagielski OSL_ASSERT(memcmp (ecb_out, ecb_ok, sizeof(ecb_ok)) == 0);
238*b1cdbd2cSJim Jagielski
239*b1cdbd2cSJim Jagielski memset (ecb_in, 0, sizeof(ecb_in));
240*b1cdbd2cSJim Jagielski result = rtl_cipher_decode (
241*b1cdbd2cSJim Jagielski cipher, ecb_out, length, ecb_in, sizeof(ecb_in));
242*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
243*b1cdbd2cSJim Jagielski OSL_ASSERT(memcmp (ecb_in, cbc_data, length) == 0);
244*b1cdbd2cSJim Jagielski
245*b1cdbd2cSJim Jagielski rtl_cipher_destroy (cipher);
246*b1cdbd2cSJim Jagielski }
247*b1cdbd2cSJim Jagielski
248*b1cdbd2cSJim Jagielski /* CBC */
249*b1cdbd2cSJim Jagielski cipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
250*b1cdbd2cSJim Jagielski OSL_ASSERT(cipher != 0);
251*b1cdbd2cSJim Jagielski if (cipher != 0)
252*b1cdbd2cSJim Jagielski {
253*b1cdbd2cSJim Jagielski rtlCipherError result;
254*b1cdbd2cSJim Jagielski sal_uInt8 cbc_in[40], cbc_out[40];
255*b1cdbd2cSJim Jagielski sal_uInt32 length = strlen(cbc_data) + 1;
256*b1cdbd2cSJim Jagielski
257*b1cdbd2cSJim Jagielski result = rtl_cipher_init (
258*b1cdbd2cSJim Jagielski cipher, rtl_Cipher_DirectionEncode,
259*b1cdbd2cSJim Jagielski cbc_key, sizeof(cbc_key), cbc_iv, sizeof(cbc_iv));
260*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
261*b1cdbd2cSJim Jagielski
262*b1cdbd2cSJim Jagielski memset (cbc_out, 0, sizeof(cbc_out));
263*b1cdbd2cSJim Jagielski result = rtl_cipher_encode (
264*b1cdbd2cSJim Jagielski cipher, cbc_data, length, cbc_out, sizeof(cbc_out));
265*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
266*b1cdbd2cSJim Jagielski OSL_ASSERT(memcmp (cbc_out, cbc_ok, sizeof(cbc_ok)) == 0);
267*b1cdbd2cSJim Jagielski
268*b1cdbd2cSJim Jagielski result = rtl_cipher_init (
269*b1cdbd2cSJim Jagielski cipher, rtl_Cipher_DirectionDecode,
270*b1cdbd2cSJim Jagielski cbc_key, sizeof(cbc_key), cbc_iv, sizeof(cbc_iv));
271*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
272*b1cdbd2cSJim Jagielski
273*b1cdbd2cSJim Jagielski memset (cbc_in, 0, sizeof(cbc_in));
274*b1cdbd2cSJim Jagielski result = rtl_cipher_decode (
275*b1cdbd2cSJim Jagielski cipher, cbc_out, length, cbc_in, sizeof(cbc_in));
276*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
277*b1cdbd2cSJim Jagielski OSL_ASSERT(memcmp (cbc_in, cbc_data, length) == 0);
278*b1cdbd2cSJim Jagielski
279*b1cdbd2cSJim Jagielski rtl_cipher_destroy (cipher);
280*b1cdbd2cSJim Jagielski }
281*b1cdbd2cSJim Jagielski
282*b1cdbd2cSJim Jagielski /* CFB */
283*b1cdbd2cSJim Jagielski cipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
284*b1cdbd2cSJim Jagielski OSL_ASSERT(cipher != 0);
285*b1cdbd2cSJim Jagielski if (cipher != 0)
286*b1cdbd2cSJim Jagielski {
287*b1cdbd2cSJim Jagielski rtlCipherError result;
288*b1cdbd2cSJim Jagielski sal_uInt8 cfb_in[40], cfb_out[40];
289*b1cdbd2cSJim Jagielski sal_uInt32 length = strlen(cbc_data) + 1;
290*b1cdbd2cSJim Jagielski
291*b1cdbd2cSJim Jagielski result = rtl_cipher_init (
292*b1cdbd2cSJim Jagielski cipher, rtl_Cipher_DirectionEncode,
293*b1cdbd2cSJim Jagielski cbc_key, sizeof(cbc_key), cbc_iv, sizeof(cbc_iv));
294*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
295*b1cdbd2cSJim Jagielski
296*b1cdbd2cSJim Jagielski memset (cfb_out, 0, sizeof(cfb_out));
297*b1cdbd2cSJim Jagielski result = rtl_cipher_encode (
298*b1cdbd2cSJim Jagielski cipher, cbc_data, length, cfb_out, sizeof(cfb_out));
299*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
300*b1cdbd2cSJim Jagielski OSL_ASSERT(memcmp (cfb_out, cfb_ok, sizeof(cfb_ok)) == 0);
301*b1cdbd2cSJim Jagielski
302*b1cdbd2cSJim Jagielski result = rtl_cipher_init (
303*b1cdbd2cSJim Jagielski cipher, rtl_Cipher_DirectionDecode,
304*b1cdbd2cSJim Jagielski cbc_key, sizeof(cbc_key), cbc_iv, sizeof(cbc_iv));
305*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
306*b1cdbd2cSJim Jagielski
307*b1cdbd2cSJim Jagielski memset (cfb_in, 0, sizeof(cfb_in));
308*b1cdbd2cSJim Jagielski result = rtl_cipher_decode (
309*b1cdbd2cSJim Jagielski cipher, cfb_out, length, cfb_in, sizeof(cfb_in));
310*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
311*b1cdbd2cSJim Jagielski OSL_ASSERT(memcmp (cfb_in, cbc_data, length) == 0);
312*b1cdbd2cSJim Jagielski
313*b1cdbd2cSJim Jagielski rtl_cipher_destroy (cipher);
314*b1cdbd2cSJim Jagielski }
315*b1cdbd2cSJim Jagielski
316*b1cdbd2cSJim Jagielski /* ARCFOUR */
317*b1cdbd2cSJim Jagielski cipher = rtl_cipher_create (rtl_Cipher_AlgorithmARCFOUR, rtl_Cipher_ModeStream);
318*b1cdbd2cSJim Jagielski OSL_ASSERT(cipher != 0);
319*b1cdbd2cSJim Jagielski if (cipher != 0)
320*b1cdbd2cSJim Jagielski {
321*b1cdbd2cSJim Jagielski rtlCipherError result;
322*b1cdbd2cSJim Jagielski sal_uInt8 arcfour_out[40];
323*b1cdbd2cSJim Jagielski sal_Size length;
324*b1cdbd2cSJim Jagielski int i, n;
325*b1cdbd2cSJim Jagielski
326*b1cdbd2cSJim Jagielski n = sizeof(arcfour_data_len) / sizeof(arcfour_data_len[0]);
327*b1cdbd2cSJim Jagielski for (i = 0; i < n; i++)
328*b1cdbd2cSJim Jagielski {
329*b1cdbd2cSJim Jagielski length = arcfour_data_len[i];
330*b1cdbd2cSJim Jagielski
331*b1cdbd2cSJim Jagielski result = rtl_cipher_init (
332*b1cdbd2cSJim Jagielski cipher, rtl_Cipher_DirectionBoth,
333*b1cdbd2cSJim Jagielski &(arcfour_key[i][1]), arcfour_key[i][0], 0, 0);
334*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
335*b1cdbd2cSJim Jagielski
336*b1cdbd2cSJim Jagielski memset (arcfour_out, 0, sizeof(arcfour_out));
337*b1cdbd2cSJim Jagielski result = rtl_cipher_encode (
338*b1cdbd2cSJim Jagielski cipher, &(arcfour_data[i][0]), length,
339*b1cdbd2cSJim Jagielski arcfour_out, sizeof(arcfour_out));
340*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
341*b1cdbd2cSJim Jagielski OSL_ASSERT(memcmp (arcfour_out, arcfour_ok[i], length) == 0);
342*b1cdbd2cSJim Jagielski }
343*b1cdbd2cSJim Jagielski
344*b1cdbd2cSJim Jagielski n = arcfour_data_len[3];
345*b1cdbd2cSJim Jagielski for (i = 1; i < n; i++)
346*b1cdbd2cSJim Jagielski {
347*b1cdbd2cSJim Jagielski length = i;
348*b1cdbd2cSJim Jagielski
349*b1cdbd2cSJim Jagielski result = rtl_cipher_init (
350*b1cdbd2cSJim Jagielski cipher, rtl_Cipher_DirectionBoth,
351*b1cdbd2cSJim Jagielski &(arcfour_key[3][1]), arcfour_key[3][0], 0, 0);
352*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
353*b1cdbd2cSJim Jagielski
354*b1cdbd2cSJim Jagielski memset (arcfour_out, 0, sizeof(arcfour_out));
355*b1cdbd2cSJim Jagielski result = rtl_cipher_encode (
356*b1cdbd2cSJim Jagielski cipher, &(arcfour_data[3][0]), length,
357*b1cdbd2cSJim Jagielski arcfour_out, sizeof(arcfour_out));
358*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
359*b1cdbd2cSJim Jagielski OSL_ASSERT(memcmp (arcfour_out, arcfour_ok[3], length) == 0);
360*b1cdbd2cSJim Jagielski OSL_ASSERT(arcfour_out[length] == 0);
361*b1cdbd2cSJim Jagielski }
362*b1cdbd2cSJim Jagielski
363*b1cdbd2cSJim Jagielski n = arcfour_data_len[3];
364*b1cdbd2cSJim Jagielski for (i = 1; i < n; i++)
365*b1cdbd2cSJim Jagielski {
366*b1cdbd2cSJim Jagielski length = i;
367*b1cdbd2cSJim Jagielski
368*b1cdbd2cSJim Jagielski result = rtl_cipher_init (
369*b1cdbd2cSJim Jagielski cipher, rtl_Cipher_DirectionBoth,
370*b1cdbd2cSJim Jagielski &(arcfour_key[3][1]), arcfour_key[3][0], 0, 0);
371*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
372*b1cdbd2cSJim Jagielski
373*b1cdbd2cSJim Jagielski memset (arcfour_out, 0, sizeof(arcfour_out));
374*b1cdbd2cSJim Jagielski result = rtl_cipher_encode (
375*b1cdbd2cSJim Jagielski cipher, &(arcfour_data[3][0]), length,
376*b1cdbd2cSJim Jagielski &(arcfour_out[0]), sizeof(arcfour_out));
377*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
378*b1cdbd2cSJim Jagielski
379*b1cdbd2cSJim Jagielski result = rtl_cipher_encode (
380*b1cdbd2cSJim Jagielski cipher, &(arcfour_data[3][length]), n - length,
381*b1cdbd2cSJim Jagielski &(arcfour_out[length]), sizeof(arcfour_out) - length);
382*b1cdbd2cSJim Jagielski OSL_ASSERT(result == rtl_Cipher_E_None);
383*b1cdbd2cSJim Jagielski
384*b1cdbd2cSJim Jagielski OSL_ASSERT(memcmp (arcfour_out, arcfour_ok[3], length) == 0);
385*b1cdbd2cSJim Jagielski }
386*b1cdbd2cSJim Jagielski
387*b1cdbd2cSJim Jagielski rtl_cipher_destroy (cipher);
388*b1cdbd2cSJim Jagielski }
389*b1cdbd2cSJim Jagielski
390*b1cdbd2cSJim Jagielski /* Done */
391*b1cdbd2cSJim Jagielski return 0;
392*b1cdbd2cSJim Jagielski }
393