2 * Unit tests for SystemFunctionXXX (LMHash?)
4 * Copyright 2004 Hans Leidekker
5 * Copyright 2006 Mike McCormack
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define WIN32_NO_STATUS
26 #include "wine/test.h"
31 typedef VOID (WINAPI *fnSystemFunction006)( PCSTR passwd, PSTR lmhash );
32 typedef NTSTATUS (WINAPI *fnSystemFunction008)(const LPBYTE, const LPBYTE, LPBYTE);
33 typedef NTSTATUS (WINAPI *fnSystemFunction001)(const LPBYTE, const LPBYTE, LPBYTE);
35 fnSystemFunction006 pSystemFunction006;
36 fnSystemFunction008 pSystemFunction008;
37 fnSystemFunction001 pSystemFunction001;
39 static void test_SystemFunction006(void)
43 char passwd[] = { 's','e','c','r','e','t', 0, 0, 0, 0, 0, 0, 0, 0 };
44 unsigned char expect[] =
45 { 0x85, 0xf5, 0x28, 0x9f, 0x09, 0xdc, 0xa7, 0xeb,
46 0xaa, 0xd3, 0xb4, 0x35, 0xb5, 0x14, 0x04, 0xee };
48 pSystemFunction006( passwd, lmhash );
50 ok( !memcmp( lmhash, expect, sizeof(expect) ),
51 "lmhash: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
52 lmhash[0], lmhash[1], lmhash[2], lmhash[3], lmhash[4], lmhash[5],
53 lmhash[6], lmhash[7], lmhash[8], lmhash[9], lmhash[10], lmhash[11],
54 lmhash[12], lmhash[13], lmhash[14], lmhash[15] );
57 static void test_SystemFunction008(void)
59 /* example data from http://davenport.sourceforge.net/ntlm.html */
60 unsigned char hash[0x40] = {
61 0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24, 0x12,
62 0xc2, 0x26, 0x5b, 0x23, 0x73, 0x4e, 0x0d, 0xac };
63 unsigned char challenge[0x40] = {
64 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
65 unsigned char expected[0x18] = {
66 0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97,
67 0x82, 0xa6, 0x67, 0xaf, 0x6d, 0x42, 0x7c, 0x6d,
68 0xe6, 0x7c, 0x20, 0xc2, 0xd3, 0xe7, 0x7c, 0x56 };
69 unsigned char output[0x18];
72 r = pSystemFunction008(0,0,0);
73 ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
75 r = pSystemFunction008(challenge,0,0);
76 ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
78 r = pSystemFunction008(challenge, hash, 0);
79 ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
84 r = pSystemFunction008(challenge, 0, output);
85 ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
88 r = pSystemFunction008(0, 0, output);
89 ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
91 memset(output, 0, sizeof output);
92 r = pSystemFunction008(challenge, hash, output);
93 ok( r == STATUS_SUCCESS, "wrong error code\n");
95 ok( !memcmp(output, expected, sizeof expected), "response wrong\n");
98 static void test_SystemFunction001(void)
100 unsigned char key[8] = { 0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24, 0 };
101 unsigned char data[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
102 unsigned char expected[8] = { 0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97 };
103 unsigned char output[16];
106 r = pSystemFunction001(0,0,0);
107 ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
109 memset(output, 0, sizeof output);
111 r = pSystemFunction001(data,key,output);
112 ok( r == STATUS_SUCCESS, "wrong error code\n");
114 ok(!memcmp(output, expected, sizeof expected), "response wrong\n");
117 START_TEST(crypt_lmhash)
121 if (!(module = LoadLibrary("advapi32.dll"))) return;
123 pSystemFunction006 = (fnSystemFunction006)GetProcAddress( module, "SystemFunction006" );
124 if (pSystemFunction006)
125 test_SystemFunction006();
127 pSystemFunction008 = (fnSystemFunction008)GetProcAddress( module, "SystemFunction008" );
128 if (pSystemFunction008)
129 test_SystemFunction008();
131 pSystemFunction001 = (fnSystemFunction001)GetProcAddress( module, "SystemFunction001" );
132 if (pSystemFunction001)
133 test_SystemFunction001();
135 FreeLibrary( module );