Mike McCormack : advapi32: Implement and test SystemFunction008.

Alexandre Julliard julliard at wine.codeweavers.com
Wed May 10 12:56:58 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 4f520dbd06e2524263714359adcd41dd39355c5e
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=4f520dbd06e2524263714359adcd41dd39355c5e

Author: Mike McCormack <mike at codeweavers.com>
Date:   Wed May 10 18:16:34 2006 +0900

advapi32: Implement and test SystemFunction008.

---

 dlls/advapi32/advapi32.spec        |    2 +
 dlls/advapi32/crypt_lmhash.c       |   35 ++++++++++++++++++++++
 dlls/advapi32/tests/crypt_lmhash.c |   58 +++++++++++++++++++++++++++++++++---
 3 files changed, 89 insertions(+), 6 deletions(-)

diff --git a/dlls/advapi32/advapi32.spec b/dlls/advapi32/advapi32.spec
index 1f23818..abec4e7 100644
--- a/dlls/advapi32/advapi32.spec
+++ b/dlls/advapi32/advapi32.spec
@@ -602,7 +602,7 @@ # @ stub StopTraceW
 @ stub SystemFunction005
 @ stdcall SystemFunction006(ptr ptr)
 @ stub SystemFunction007
-@ stub SystemFunction008
+@ stdcall SystemFunction008(ptr ptr ptr)
 @ stub SystemFunction009
 @ stub SystemFunction010
 @ stub SystemFunction011
diff --git a/dlls/advapi32/crypt_lmhash.c b/dlls/advapi32/crypt_lmhash.c
index c8a8b44..dbe07ba 100644
--- a/dlls/advapi32/crypt_lmhash.c
+++ b/dlls/advapi32/crypt_lmhash.c
@@ -54,3 +54,38 @@ NTSTATUS WINAPI SystemFunction006( LPCST
 
     return STATUS_SUCCESS;
 }
+
+/******************************************************************************
+ * SystemFunction008  [ADVAPI32.@]
+ *
+ * Creates a LM response from a challenge and a password hash
+ *
+ * PARAMS
+ *   challenge  [I] Challenge from authentication server
+ *   hash       [I] NTLM hash (from SystemFunction006)
+ *   response   [O] response to send back to the server
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL
+ *
+ * NOTES
+ *  see http://davenport.sourceforge.net/ntlm.html#theLmResponse
+ *
+ */
+NTSTATUS WINAPI SystemFunction008(const LPBYTE challenge, const LPBYTE hash, LPBYTE response)
+{
+    BYTE key[7*3];
+
+    if (!challenge || !response)
+        return STATUS_UNSUCCESSFUL;
+
+    memset(key, 0, sizeof key);
+    memcpy(key, hash, 0x10);
+
+    CRYPT_DEShash(response, key, challenge);
+    CRYPT_DEShash(response+8, key+7, challenge);
+    CRYPT_DEShash(response+16, key+14, challenge);
+
+    return STATUS_SUCCESS;
+}
diff --git a/dlls/advapi32/tests/crypt_lmhash.c b/dlls/advapi32/tests/crypt_lmhash.c
index bf3eb47..c389fb2 100644
--- a/dlls/advapi32/tests/crypt_lmhash.c
+++ b/dlls/advapi32/tests/crypt_lmhash.c
@@ -1,7 +1,8 @@
 /*
- * Unit tests for SystemFunction006 (LMHash?)
+ * Unit tests for SystemFunctionXXX (LMHash?)
  *
  * Copyright 2004 Hans Leidekker
+ * Copyright 2006 Mike McCormack
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -20,12 +21,18 @@
 
 #include <stdio.h>
 
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
 #include "wine/test.h"
 #include "windef.h"
 #include "winbase.h"
+#include "winternl.h"
 
 typedef VOID (WINAPI *fnSystemFunction006)( PCSTR passwd, PSTR lmhash );
+typedef DWORD (WINAPI *fnSystemFunction008)(const LPBYTE, const LPBYTE, LPBYTE);
+
 fnSystemFunction006 pSystemFunction006;
+fnSystemFunction008 pSystemFunction008;
 
 static void test_SystemFunction006(void)
 {
@@ -45,6 +52,47 @@ static void test_SystemFunction006(void)
         lmhash[12], lmhash[13], lmhash[14], lmhash[15] );
 }
 
+static void test_SystemFunction008(void)
+{
+    /* example data from http://davenport.sourceforge.net/ntlm.html */
+    unsigned char hash[0x40] = {
+        0xff, 0x37, 0x50, 0xbc, 0xc2, 0xb2, 0x24, 0x12,
+        0xc2, 0x26, 0x5b, 0x23, 0x73, 0x4e, 0x0d, 0xac };
+    unsigned char challenge[0x40] = {
+        0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
+    unsigned char expected[0x18] = {
+        0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97,
+        0x82, 0xa6, 0x67, 0xaf, 0x6d, 0x42, 0x7c, 0x6d,
+        0xe6, 0x7c, 0x20, 0xc2, 0xd3, 0xe7, 0x7c, 0x56 };
+    unsigned char output[0x18];
+    NTSTATUS r;
+
+    r = pSystemFunction008(0,0,0);
+    ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
+
+    r = pSystemFunction008(challenge,0,0);
+    ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
+
+    r = pSystemFunction008(challenge, hash, 0);
+    ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
+
+    /* crashes */
+    if (0)
+    {
+        r = pSystemFunction008(challenge, 0, output);
+        ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
+    }
+
+    r = pSystemFunction008(0, 0, output);
+    ok( r == STATUS_UNSUCCESSFUL, "wrong error code\n");
+
+    memset(output, 0, sizeof output);
+    r = pSystemFunction008(challenge, hash, output);
+    ok( r == STATUS_SUCCESS, "wrong error code\n");
+
+    ok( !memcmp(output, expected, sizeof expected), "response wrong\n");
+}
+
 START_TEST(crypt_lmhash)
 {
     HMODULE module;
@@ -52,12 +100,12 @@ START_TEST(crypt_lmhash)
     if (!(module = LoadLibrary("advapi32.dll"))) return;
 
     pSystemFunction006 = (fnSystemFunction006)GetProcAddress( module, "SystemFunction006" );
-
-    if (!pSystemFunction006) goto out;
-
     if (pSystemFunction006) 
         test_SystemFunction006();
 
-out:
+    pSystemFunction008 = (fnSystemFunction008)GetProcAddress( module, "SystemFunction008" );
+    if (pSystemFunction008)
+        test_SystemFunction008();
+
     FreeLibrary( module );
 }




More information about the wine-cvs mailing list