~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/advapi32/tests/crypt_lmhash.c

Version: ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Unit tests for SystemFunctionXXX (LMHash?)
  3  *
  4  * Copyright 2004 Hans Leidekker
  5  * Copyright 2006 Mike McCormack
  6  *
  7  * This library is free software; you can redistribute it and/or
  8  * modify it under the terms of the GNU Lesser General Public
  9  * License as published by the Free Software Foundation; either
 10  * version 2.1 of the License, or (at your option) any later version.
 11  *
 12  * This library is distributed in the hope that it will be useful,
 13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15  * Lesser General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Lesser General Public
 18  * License along with this library; if not, write to the Free Software
 19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 20  */
 21 
 22 #include <stdio.h>
 23 
 24 #include "ntstatus.h"
 25 #define WIN32_NO_STATUS
 26 #include "wine/test.h"
 27 #include "windef.h"
 28 #include "winbase.h"
 29 #include "winternl.h"
 30 
 31 struct ustring {
 32     DWORD Length;
 33     DWORD MaximumLength;
 34     unsigned char *Buffer;
 35 };
 36 
 37 typedef NTSTATUS (WINAPI *fnSystemFunction001)(const BYTE *, const BYTE *, LPBYTE);
 38 typedef NTSTATUS (WINAPI *fnSystemFunction002)(const BYTE *, const BYTE *, LPBYTE);
 39 typedef NTSTATUS (WINAPI *fnSystemFunction003)(const BYTE *, LPBYTE);
 40 typedef NTSTATUS (WINAPI *fnSystemFunction004)(const struct ustring *, const struct ustring *, struct ustring *);
 41 typedef NTSTATUS (WINAPI *fnSystemFunction005)(const struct ustring *, const struct ustring *, struct ustring *);
 42 typedef VOID (WINAPI *fnSystemFunction006)( PCSTR passwd, PSTR lmhash );
 43 typedef NTSTATUS (WINAPI *fnSystemFunction008)(const BYTE *, const BYTE *, LPBYTE);
 44 typedef NTSTATUS (WINAPI *fnSystemFunction009)(const BYTE *, const BYTE *, LPBYTE);
 45 typedef int (WINAPI *descrypt)(unsigned char *, unsigned char *, unsigned char *);
 46 typedef NTSTATUS (WINAPI *fnSystemFunction030)(void*, void*);
 47 typedef NTSTATUS (WINAPI *fnSystemFunction032)(struct ustring *, struct ustring *);
 48 
 49 fnSystemFunction001 pSystemFunction001;
 50 fnSystemFunction002 pSystemFunction002;
 51 fnSystemFunction003 pSystemFunction003;
 52 fnSystemFunction004 pSystemFunction004;
 53 fnSystemFunction004 pSystemFunction005;
 54 fnSystemFunction006 pSystemFunction006;
 55 fnSystemFunction008 pSystemFunction008;
 56 fnSystemFunction008 pSystemFunction009;
 57 
 58 /* encrypt two blocks */
 59 descrypt pSystemFunction012;
 60 descrypt pSystemFunction014;
 61 descrypt pSystemFunction016;
 62 descrypt pSystemFunction018;
 63 descrypt pSystemFunction020;
 64 descrypt pSystemFunction022;
 65 
 66 /* decrypt two blocks */
 67 descrypt pSystemFunction013;
 68 descrypt pSystemFunction015;
 69 descrypt pSystemFunction017;
 70 descrypt pSystemFunction019;
 71 descrypt pSystemFunction021;
 72 descrypt pSystemFunction023;
 73 
 74 /* encrypt two blocks with a 32bit key */
 75 descrypt pSystemFunction024;
 76 descrypt pSystemFunction025;
 77 
 78 /* decrypt two blocks with a 32bit key */
 79 descrypt pSystemFunction026;
 80 descrypt pSystemFunction027;
 81 
 82 typedef int (WINAPI *memcmpfunc)(unsigned char *, unsigned char *);
 83 memcmpfunc pSystemFunction030;
 84 memcmpfunc pSystemFunction031;
 85 
 86 fnSystemFunction032 pSystemFunction032;
 87 
 88 static void test_SystemFunction006(void)
 89 {
 90     char lmhash[16 + 1];
 91 
 92     char passwd[] = { 's','e','c','r','e','t', 0, 0, 0, 0, 0, 0, 0, 0 };
 93     unsigned char expect[] = 
 94         { 0x85, 0xf5, 0x28, 0x9f, 0x09, 0xdc, 0xa7, 0xeb,
 95           0xaa, 0xd3, 0xb4, 0x35, 0xb5, 0x14, 0x04, 0xee };
 96 
 97     pSystemFunction006( passwd, lmhash );
 98 
 99     ok( !memcmp( lmhash, expect, sizeof(expect) ),
100         "lmhash: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
101         lmhash[0], lmhash[1], lmhash[2], lmhash[3], lmhash[4], lmhash[5],
102         lmhash[6], lmhash[7], lmhash[8], lmhash[9], lmhash[10], lmhash[11],
103         lmhash[12], lmhash[13], lmhash[14], lmhash[15] );
104 }
105 
106 static void test_SystemFunction008(void)
107 {
108     /* example data from http://davenport.sourceforge.net/ntlm.html */
109     unsigned char hash[0x40] = {
110         0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24, 0x12,
111         0xc2, 0x26, 0x5b, 0x23, 0x73, 0x4e, 0x0d, 0xac };
112     unsigned char challenge[0x40] = {
113         0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
114     unsigned char expected[0x18] = {
115         0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97,
116         0x82, 0xa6, 0x67, 0xaf, 0x6d, 0x42, 0x7c, 0x6d,
117         0xe6, 0x7c, 0x20, 0xc2, 0xd3, 0xe7, 0x7c, 0x56 };
118     unsigned char output[0x18];
119     NTSTATUS r;
120 
121     r = pSystemFunction008(0,0,0);
122     ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
123 
124     r = pSystemFunction008(challenge,0,0);
125     ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
126 
127     r = pSystemFunction008(challenge, hash, 0);
128     ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
129 
130     /* crashes */
131     if (0)
132     {
133         r = pSystemFunction008(challenge, 0, output);
134         ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
135     }
136 
137     r = pSystemFunction008(0, 0, output);
138     ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
139 
140     memset(output, 0, sizeof output);
141     r = pSystemFunction008(challenge, hash, output);
142     ok( r == STATUS_SUCCESS, "wrong error code\n");
143 
144     ok( !memcmp(output, expected, sizeof expected), "response wrong\n");
145 }
146 
147 static void test_SystemFunction001(void)
148 {
149     unsigned char key[8] = { 0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24, 0 };
150     unsigned char data[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
151     unsigned char expected[8] = { 0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97 };
152     unsigned char output[16];
153     NTSTATUS r;
154 
155     r = pSystemFunction001(0,0,0);
156     ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
157 
158     memset(output, 0, sizeof output);
159 
160     r = pSystemFunction001(data,key,output);
161     ok( r == STATUS_SUCCESS, "wrong error code\n");
162 
163     ok(!memcmp(output, expected, sizeof expected), "response wrong\n");
164 }
165 
166 static void test_SystemFunction002(void)
167 {
168     /* reverse of SystemFunction001 */
169     unsigned char key[8] = { 0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24, 0 };
170     unsigned char expected[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
171     unsigned char data[8] = { 0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97 };
172     unsigned char output[8];
173     int r;
174 
175     memset(output, 0, sizeof output);
176     r = pSystemFunction002(data, key, output);
177     ok(r == STATUS_SUCCESS, "function failed\n");
178     ok(!memcmp(output, expected, sizeof expected), "response wrong\n");
179 }
180 
181 static void test_SystemFunction032(void)
182 {
183     struct ustring key, data;
184     unsigned char szKey[] = { 'f','o','o',0 };
185     unsigned char szData[8] = { 'b','a','r',0 };
186     unsigned char expected[] = {0x28, 0xb9, 0xf8, 0xe1};
187     int r;
188 
189     /* crashes:    pSystemFunction032(NULL,NULL); */
190 
191     key.Buffer = szKey;
192     key.Length = sizeof szKey;
193     key.MaximumLength = key.Length;
194 
195     data.Buffer = szData;
196     data.Length = 4;
197     data.MaximumLength = 8;
198 
199     r = pSystemFunction032(&data, &key);
200     ok(r == STATUS_SUCCESS, "function failed\n");
201 
202     ok(!memcmp(expected, data.Buffer, data.Length), "wrong result\n");
203 }
204 
205 static void test_SystemFunction003(void)
206 {
207     unsigned char output[8], data[8];
208     unsigned char key[7] = { 0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24 };
209     unsigned char exp1[8] = { 0x9d, 0x21, 0xc8, 0x86, 0x6c, 0x21, 0xcf, 0x43 };
210     char exp2[] = "KGS!@#$%";
211     int r;
212 
213     r = pSystemFunction003(NULL, NULL);
214     ok(r == STATUS_UNSUCCESSFUL, "function failed\n");
215 
216     r = pSystemFunction003(key, NULL);
217     ok(r == STATUS_UNSUCCESSFUL, "function failed\n");
218 
219     memset(data, 0, sizeof data);
220     r = pSystemFunction003(key, data);
221     ok(r == STATUS_SUCCESS, "function failed\n");
222     ok( !memcmp(exp1, data, sizeof data), "decrypted message wrong\n");
223 
224     memset(output, 0, sizeof output);
225     r = pSystemFunction002(data, key, output);
226 
227     ok( !memcmp(exp2, output, sizeof output), "decrypted message wrong\n");
228 }
229 
230 static void test_SystemFunction004(void)
231 {
232     unsigned char inbuf[0x100], keybuf[0x100], resbuf[0x100];
233     unsigned char output[8];
234     int r;
235     struct ustring in, key, out;
236 
237     /* crash 
238     r = pSystemFunction004(NULL, NULL, NULL);
239     ok(r == STATUS_UNSUCCESSFUL, "function failed\n");
240     */
241 
242     memset(inbuf, 0, sizeof inbuf);
243     memset(keybuf, 0, sizeof keybuf);
244     memset(resbuf, 0, sizeof resbuf);
245 
246     in.Buffer = NULL;
247     in.Length = in.MaximumLength = 0;
248 
249     key.Buffer = NULL;
250     key.Length = key.MaximumLength = 0;
251 
252     out.Buffer = NULL;
253     out.Length = out.MaximumLength = 0;
254 
255     r = pSystemFunction004(&in, &key, &out);
256     ok(r == STATUS_INVALID_PARAMETER_2, "function failed\n");
257 
258     key.Buffer = keybuf;
259     key.Length = 0x100;
260     key.MaximumLength = 0x100;
261 
262     r = pSystemFunction004(&in, &key, (struct ustring *)&out);
263     ok(r == STATUS_BUFFER_TOO_SMALL, "function failed\n");
264 
265     in.Buffer = inbuf;
266     in.Length = 0x0c;
267     in.MaximumLength = 0;
268 
269     /* add two identical blocks... */
270     inbuf[0] = 1;
271     inbuf[1] = 2;
272     inbuf[2] = 3;
273     inbuf[3] = 4;
274 
275     inbuf[8] = 1;
276     inbuf[9] = 2;
277     inbuf[10] = 3;
278     inbuf[11] = 4;
279 
280     /* check that the Length field is really obeyed */
281     keybuf[6] = 1;
282 
283     key.Buffer = keybuf;
284     key.Length = 6;
285     key.MaximumLength = 0;
286 
287     keybuf[1] = 0x33;
288 
289     out.Buffer = resbuf;
290     out.Length = 0;
291     out.MaximumLength = 0x40;
292     r = pSystemFunction004(&in, &key, &out);
293     ok(r == STATUS_SUCCESS, "function failed\n");
294 
295     keybuf[6] = 0;
296 
297     memset(output, 0, sizeof output);
298     r = pSystemFunction002(out.Buffer, key.Buffer, output);
299 
300     ok(((unsigned int*)output)[0] == in.Length, "crypted length wrong\n");
301     ok(((unsigned int*)output)[1] == 1, "crypted value wrong\n");
302 
303     memset(output, 0, sizeof output);
304     r = pSystemFunction002(out.Buffer+8, key.Buffer, output);
305     ok(!memcmp(output, inbuf, sizeof output), "crypted data wrong\n");
306 
307     memset(output, 0, sizeof output);
308     r = pSystemFunction002(out.Buffer+16, key.Buffer, output);
309     ok(!memcmp(output, inbuf, sizeof output), "crypted data wrong\n");
310 }
311 
312 static void test_SystemFunction005(void)
313 {
314     char output[0x40], result[0x40];
315     int r;
316     struct ustring in, key, out, res;
317     static char datastr[] = "twinkle twinkle little star";
318     static char keystr[]  = "byolnim";
319 
320     in.Buffer = (unsigned char *)datastr;
321     in.Length = strlen(datastr);
322     in.MaximumLength = 0;
323 
324     key.Buffer = (unsigned char *)keystr;
325     key.Length = strlen(keystr);
326     key.MaximumLength = 0;
327 
328     out.Buffer = (unsigned char *)output;
329     out.Length = out.MaximumLength = sizeof output;
330 
331     r = pSystemFunction004(&in, &key, &out);
332     ok(r == STATUS_SUCCESS, "function failed\n");
333 
334     memset(result, 0, sizeof result);
335     res.Buffer = (unsigned char *)result;
336     res.Length = 0;
337     res.MaximumLength = sizeof result;
338 
339     r = pSystemFunction005(&out, &key, &res);
340     ok(r == STATUS_SUCCESS, "function failed\n");
341 
342     r = pSystemFunction005(&out, &key, &res);
343     ok(r == STATUS_SUCCESS, "function failed\n");
344 
345     ok(res.Length == in.Length, "Length wrong\n");
346     ok(!memcmp(res.Buffer, in.Buffer, in.Length), "data wrong\n");
347 
348     out.Length = 0;
349     out.MaximumLength = 0;
350     r = pSystemFunction005(&out, &key, &res);
351     ok(r == STATUS_SUCCESS, "function failed\n");
352 
353     ok(res.Length == in.Length, "Length wrong\n");
354     ok(!memcmp(res.Buffer, in.Buffer, in.Length), "data wrong\n");
355 
356     res.MaximumLength = 0;
357     r = pSystemFunction005(&out, &key, &res);
358     ok(r == STATUS_BUFFER_TOO_SMALL, "function failed\n");
359 
360     key.Length = 1;
361     r = pSystemFunction005(&out, &key, &res);
362     ok(r == STATUS_UNKNOWN_REVISION, "function failed\n");
363 
364     key.Length = 0;
365     r = pSystemFunction005(&out, &key, &res);
366     ok(r == STATUS_INVALID_PARAMETER_2, "function failed\n");
367 }
368 
369 static void test_SystemFunction009(void)
370 {
371     unsigned char hash[0x10] = {
372         0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24, 0x12,
373         0xc2, 0x26, 0x5b, 0x23, 0x73, 0x4e, 0x0d, 0xac };
374     unsigned char challenge[8] = {
375         0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
376     unsigned char expected[0x18] = {
377         0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97,
378         0x82, 0xa6, 0x67, 0xaf, 0x6d, 0x42, 0x7c, 0x6d,
379         0xe6, 0x7c, 0x20, 0xc2, 0xd3, 0xe7, 0x7c, 0x56 };
380     unsigned char output[0x18];
381     int r;
382 
383     memset(output, 0, sizeof output);
384     r = pSystemFunction009(challenge, hash, output);
385     ok( r == STATUS_SUCCESS, "wrong error code\n");
386     ok(!memcmp(output, expected, sizeof expected), "response wrong\n");
387 }
388 
389 static unsigned char des_key[] = { 
390     0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24, 
391     0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24, 
392 };
393 static unsigned char des_plaintext[] = { 
394     0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 
395     0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0 
396 };
397 static unsigned char des_ciphertext[] = { 
398     0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97,
399     0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97, 0
400 };
401 
402 /* test functions that encrypt two DES blocks */
403 static void test_SystemFunction_encrypt(descrypt func, int num)
404 {
405     unsigned char output[0x11];
406     int r;
407 
408     if (!func)
409     {
410         skip("SystemFunction%03d is not available\n", num);
411         return;
412     }
413 
414     r = func(NULL, NULL, NULL);
415     ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
416 
417     memset(output, 0, sizeof output);
418     r = func(des_plaintext, des_key, output);
419     ok( r == STATUS_SUCCESS, "wrong error code\n");
420     ok( !memcmp(des_ciphertext, output, sizeof des_ciphertext), "ciphertext wrong (%d)\n", num);
421 }
422 
423 /* test functions that decrypt two DES blocks */
424 static void test_SystemFunction_decrypt(descrypt func, int num)
425 {
426     unsigned char output[0x11];
427     int r;
428 
429     if (!func)
430     {
431         skip("SystemFunction%03d is not available\n", num);
432         return;
433     }
434 
435     r = func(NULL, NULL, NULL);
436     ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
437 
438     memset(output, 0, sizeof output);
439 
440     r = func(des_ciphertext, des_key, output);
441     ok( r == STATUS_SUCCESS, "wrong error code\n");
442     ok( !memcmp(des_plaintext, output, sizeof des_plaintext), "plaintext wrong (%d)\n", num);
443 }
444 
445 static unsigned char des_ciphertext32[] = { 
446     0x69, 0x51, 0x35, 0x69, 0x0d, 0x29, 0x24, 0xad,
447     0x23, 0x6d, 0xfd, 0x43, 0x0d, 0xd3, 0x25, 0x81, 0
448 };
449 
450 static void test_SystemFunction_enc32(descrypt func, int num)
451 {
452     unsigned char key[4], output[0x11];
453     int r;
454 
455     if (!func)
456     {
457         skip("SystemFunction%03d is not available\n", num);
458         return;
459     }
460 
461     memset(output, 0, sizeof output);
462 
463     /* two keys are generated using 4 bytes, repeated 4 times ... */
464     memcpy(key, "foo", 4);
465 
466     r = func(des_plaintext, key, output);
467     ok( r == STATUS_SUCCESS, "wrong error code (%d)\n", num);
468 
469     ok( !memcmp( output, des_ciphertext32, sizeof des_ciphertext32), "ciphertext wrong (%d)\n", num);
470 }
471 
472 static void test_SystemFunction_dec32(descrypt func, int num)
473 {
474     unsigned char key[4], output[0x11];
475     int r;
476 
477     if (!func)
478     {
479         skip("SystemFunction%03d is not available\n", num);
480         return;
481     }
482 
483     memset(output, 0, sizeof output);
484 
485     /* two keys are generated using 4 bytes, repeated 4 times ... */
486     memcpy(key, "foo", 4);
487 
488     r = func(des_ciphertext32, key, output);
489     ok( r == STATUS_SUCCESS, "wrong error code (%d)\n", num);
490 
491     ok( !memcmp( output, des_plaintext, sizeof des_plaintext), "plaintext wrong (%d)\n", num);
492 }
493 
494 static void test_memcmpfunc(memcmpfunc fn)
495 {
496     unsigned char arg1[0x20], arg2[0x20];
497     int r;
498 
499     if (!fn)
500     {
501         skip("function is not available\n");
502         return;
503     }
504 
505     if (0)
506     {
507         /* crashes */
508         r = fn(NULL, NULL);
509     }
510 
511     memset(arg1, 0, sizeof arg1);
512     memset(arg2, 0, sizeof arg2);
513     arg1[0x10] = 1;
514 
515     r = fn(arg1, arg2);
516     ok( r == 1, "wrong error code\n");
517 
518     memset(arg1, 1, sizeof arg1);
519     memset(arg2, 1, sizeof arg2);
520     arg1[0x10] = 0;
521 
522     r = fn(arg1, arg2);
523     ok( r == 1, "wrong error code\n");
524 
525     memset(arg1, 0, sizeof arg1);
526     memset(arg2, 1, sizeof arg2);
527 
528     r = fn(arg1, arg2);
529     ok( r == 0, "wrong error code\n");
530 
531     memset(arg1, 1, sizeof arg1);
532     memset(arg2, 0, sizeof arg2);
533 
534     r = fn(arg1, arg2);
535     ok( r == 0, "wrong error code\n");
536 }
537 
538 START_TEST(crypt_lmhash)
539 {
540     HMODULE module = GetModuleHandleA("advapi32.dll");
541 
542     pSystemFunction001 = (fnSystemFunction001)GetProcAddress( module, "SystemFunction001" );
543     if (pSystemFunction001)
544         test_SystemFunction001();
545     else
546         skip("SystemFunction001 is not available\n");
547 
548     pSystemFunction002 = (fnSystemFunction002)GetProcAddress( module, "SystemFunction002" );
549     if (pSystemFunction002)
550         test_SystemFunction002();
551     else
552         skip("SystemFunction002 is not available\n");
553 
554     pSystemFunction003 = (fnSystemFunction003)GetProcAddress( module, "SystemFunction003" );
555     if (pSystemFunction003)
556         test_SystemFunction003();
557     else
558         skip("SystemFunction002 is not available\n");
559 
560     pSystemFunction004 = (fnSystemFunction004)GetProcAddress( module, "SystemFunction004" );
561     if (pSystemFunction004)
562         test_SystemFunction004();
563     else
564         skip("SystemFunction004 is not available\n");
565 
566     pSystemFunction005 = (fnSystemFunction005)GetProcAddress( module, "SystemFunction005" );
567     if (pSystemFunction005)
568         test_SystemFunction005();
569     else
570         skip("SystemFunction005 is not available\n");
571 
572     pSystemFunction006 = (fnSystemFunction006)GetProcAddress( module, "SystemFunction006" );
573     if (pSystemFunction006) 
574         test_SystemFunction006();
575     else
576         skip("SystemFunction006 is not available\n");
577 
578     pSystemFunction008 = (fnSystemFunction008)GetProcAddress( module, "SystemFunction008" );
579     if (pSystemFunction008)
580         test_SystemFunction008();
581     else
582         skip("SystemFunction008 is not available\n");
583 
584     pSystemFunction009 = (fnSystemFunction009)GetProcAddress( module, "SystemFunction009" );
585     if (pSystemFunction009)
586         test_SystemFunction009();
587     else
588         skip("SystemFunction009 is not available\n");
589 
590     pSystemFunction012 = (descrypt) GetProcAddress( module, "SystemFunction012");
591     pSystemFunction013 = (descrypt) GetProcAddress( module, "SystemFunction013");
592     pSystemFunction014 = (descrypt) GetProcAddress( module, "SystemFunction014");
593     pSystemFunction015 = (descrypt) GetProcAddress( module, "SystemFunction015");
594     pSystemFunction016 = (descrypt) GetProcAddress( module, "SystemFunction016");
595     pSystemFunction017 = (descrypt) GetProcAddress( module, "SystemFunction017");
596     pSystemFunction018 = (descrypt) GetProcAddress( module, "SystemFunction018");
597     pSystemFunction019 = (descrypt) GetProcAddress( module, "SystemFunction019");
598     pSystemFunction020 = (descrypt) GetProcAddress( module, "SystemFunction020");
599     pSystemFunction021 = (descrypt) GetProcAddress( module, "SystemFunction021");
600     pSystemFunction022 = (descrypt) GetProcAddress( module, "SystemFunction022");
601     pSystemFunction023 = (descrypt) GetProcAddress( module, "SystemFunction023");
602 
603     /* these all encrypt two DES blocks */
604     test_SystemFunction_encrypt(pSystemFunction012, 12);
605     test_SystemFunction_encrypt(pSystemFunction014, 14);
606     test_SystemFunction_encrypt(pSystemFunction016, 16);
607     test_SystemFunction_encrypt(pSystemFunction018, 18);
608     test_SystemFunction_encrypt(pSystemFunction020, 20);
609     test_SystemFunction_encrypt(pSystemFunction022, 22);
610 
611     /* these all decrypt two DES blocks */
612     test_SystemFunction_decrypt(pSystemFunction013, 13);
613     test_SystemFunction_decrypt(pSystemFunction015, 15);
614     test_SystemFunction_decrypt(pSystemFunction017, 17);
615     test_SystemFunction_decrypt(pSystemFunction019, 19);
616     test_SystemFunction_decrypt(pSystemFunction021, 21);
617     test_SystemFunction_decrypt(pSystemFunction023, 23);
618 
619     pSystemFunction024 = (descrypt) GetProcAddress( module, "SystemFunction024");
620     pSystemFunction025 = (descrypt) GetProcAddress( module, "SystemFunction025");
621     pSystemFunction026 = (descrypt) GetProcAddress( module, "SystemFunction026");
622     pSystemFunction027 = (descrypt) GetProcAddress( module, "SystemFunction027");
623 
624     /* these encrypt two DES blocks with a short key */
625     test_SystemFunction_enc32(pSystemFunction024, 24);
626     test_SystemFunction_enc32(pSystemFunction026, 26);
627 
628     /* these descrypt two DES blocks with a short key */
629     test_SystemFunction_dec32(pSystemFunction025, 25);
630     test_SystemFunction_dec32(pSystemFunction027, 27);
631 
632     pSystemFunction030 = (memcmpfunc) GetProcAddress( module, "SystemFunction030" );
633     pSystemFunction031 = (memcmpfunc) GetProcAddress( module, "SystemFunction031" );
634 
635     test_memcmpfunc(pSystemFunction030);
636     test_memcmpfunc(pSystemFunction031);
637 
638     pSystemFunction032 = (fnSystemFunction032)GetProcAddress( module, "SystemFunction032" );
639     if (pSystemFunction032)
640         test_SystemFunction032();
641     else
642         skip("SystemFunction032 is not available\n");
643 }
644 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.