From: Elizabeth Figura zfigura@codeweavers.com
--- dlls/advapi32/advapi32.spec | 38 +++--- dlls/advapi32/crypt_lmhash.c | 180 ----------------------------- dlls/cryptsp/Makefile.in | 3 +- dlls/cryptsp/cryptsp.spec | 34 +++--- dlls/cryptsp/lmhash.c | 217 +++++++++++++++++++++++++++++++++++ 5 files changed, 255 insertions(+), 217 deletions(-) create mode 100644 dlls/cryptsp/lmhash.c
diff --git a/dlls/advapi32/advapi32.spec b/dlls/advapi32/advapi32.spec index 41eb3e7a32c..60855c8b526 100644 --- a/dlls/advapi32/advapi32.spec +++ b/dlls/advapi32/advapi32.spec @@ -782,28 +782,28 @@ @ stdcall SystemFunction003(ptr ptr) @ stdcall SystemFunction004(ptr ptr ptr) @ stdcall SystemFunction005(ptr ptr ptr) -@ stdcall SystemFunction006(ptr ptr) +@ stdcall SystemFunction006(ptr ptr) cryptsp.SystemFunction006 @ stdcall SystemFunction007(ptr ptr) -@ stdcall SystemFunction008(ptr ptr ptr) -@ stdcall SystemFunction009(ptr ptr ptr) +@ stdcall SystemFunction008(ptr ptr ptr) cryptsp.SystemFunction008 +@ stdcall SystemFunction009(ptr ptr ptr) cryptsp.SystemFunction009 @ stdcall SystemFunction010(ptr ptr ptr) @ stdcall SystemFunction011(ptr ptr ptr) SystemFunction010 -@ stdcall SystemFunction012(ptr ptr ptr) -@ stdcall SystemFunction013(ptr ptr ptr) -@ stdcall SystemFunction014(ptr ptr ptr) SystemFunction012 -@ stdcall SystemFunction015(ptr ptr ptr) SystemFunction013 -@ stdcall SystemFunction016(ptr ptr ptr) SystemFunction012 -@ stdcall SystemFunction017(ptr ptr ptr) SystemFunction013 -@ stdcall SystemFunction018(ptr ptr ptr) SystemFunction012 -@ stdcall SystemFunction019(ptr ptr ptr) SystemFunction013 -@ stdcall SystemFunction020(ptr ptr ptr) SystemFunction012 -@ stdcall SystemFunction021(ptr ptr ptr) SystemFunction013 -@ stdcall SystemFunction022(ptr ptr ptr) SystemFunction012 -@ stdcall SystemFunction023(ptr ptr ptr) SystemFunction013 -@ stdcall SystemFunction024(ptr ptr ptr) -@ stdcall SystemFunction025(ptr ptr ptr) -@ stdcall SystemFunction026(ptr ptr ptr) SystemFunction024 -@ stdcall SystemFunction027(ptr ptr ptr) SystemFunction025 +@ stdcall SystemFunction012(ptr ptr ptr) cryptsp.SystemFunction012 +@ stdcall SystemFunction013(ptr ptr ptr) cryptsp.SystemFunction013 +@ stdcall SystemFunction014(ptr ptr ptr) cryptsp.SystemFunction014 +@ stdcall SystemFunction015(ptr ptr ptr) cryptsp.SystemFunction015 +@ stdcall SystemFunction016(ptr ptr ptr) cryptsp.SystemFunction016 +@ stdcall -import SystemFunction017(ptr ptr ptr) SystemFunction013 +@ stdcall SystemFunction018(ptr ptr ptr) cryptsp.SystemFunction018 +@ stdcall -import SystemFunction019(ptr ptr ptr) SystemFunction013 +@ stdcall SystemFunction020(ptr ptr ptr) cryptsp.SystemFunction020 +@ stdcall SystemFunction021(ptr ptr ptr) cryptsp.SystemFunction021 +@ stdcall SystemFunction022(ptr ptr ptr) cryptsp.SystemFunction022 +@ stdcall SystemFunction023(ptr ptr ptr) cryptsp.SystemFunction023 +@ stdcall SystemFunction024(ptr ptr ptr) cryptsp.SystemFunction024 +@ stdcall SystemFunction025(ptr ptr ptr) cryptsp.SystemFunction025 +@ stdcall SystemFunction026(ptr ptr ptr) cryptsp.SystemFunction026 +@ stdcall SystemFunction027(ptr ptr ptr) cryptsp.SystemFunction027 @ stub SystemFunction028 @ stub SystemFunction029 @ stdcall SystemFunction030(ptr ptr) diff --git a/dlls/advapi32/crypt_lmhash.c b/dlls/advapi32/crypt_lmhash.c index 345c89ddb73..3f4283171b5 100644 --- a/dlls/advapi32/crypt_lmhash.c +++ b/dlls/advapi32/crypt_lmhash.c @@ -32,72 +32,6 @@ static const unsigned char CRYPT_LMhash_Magic[8] = { 'K', 'G', 'S', '!', '@', '#', '$', '%' };
-static void CRYPT_LMhash( unsigned char *dst, const unsigned char *pwd, const int len ) -{ - int i, max = 14; - unsigned char tmp_pwd[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; - - max = len > max ? max : len; - - for (i = 0; i < max; i++) - tmp_pwd[i] = pwd[i]; - - CRYPT_DEShash( dst, tmp_pwd, CRYPT_LMhash_Magic ); - CRYPT_DEShash( &dst[8], &tmp_pwd[7], CRYPT_LMhash_Magic ); -} - -NTSTATUS WINAPI SystemFunction006( LPCSTR password, LPSTR hash ) -{ - CRYPT_LMhash( (unsigned char*)hash, (const unsigned char*)password, strlen(password) ); - - 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 BYTE *challenge, const BYTE *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; -} - -/****************************************************************************** - * SystemFunction009 [ADVAPI32.@] - * - * Seems to do the same as SystemFunction008 ... - */ -NTSTATUS WINAPI SystemFunction009(const BYTE *challenge, const BYTE *hash, LPBYTE response) -{ - return SystemFunction008(challenge, hash, response); -} - /****************************************************************************** * SystemFunction001 [ADVAPI32.@] * @@ -288,117 +222,3 @@ NTSTATUS WINAPI SystemFunction005(const struct ustring *in,
return STATUS_SUCCESS; } - -/****************************************************************************** - * SystemFunction012 [ADVAPI32.@] - * SystemFunction014 [ADVAPI32.@] - * SystemFunction016 [ADVAPI32.@] - * SystemFunction018 [ADVAPI32.@] - * SystemFunction020 [ADVAPI32.@] - * SystemFunction022 [ADVAPI32.@] - * - * Encrypts two DES blocks with two keys - * - * PARAMS - * data [I] data to encrypt (16 bytes) - * key [I] key data (two lots of 7 bytes) - * output [O] buffer to receive encrypted data (16 bytes) - * - * RETURNS - * Success: STATUS_SUCCESS - * Failure: STATUS_UNSUCCESSFUL if the input or output buffer is NULL - */ -NTSTATUS WINAPI SystemFunction012(const BYTE *in, const BYTE *key, LPBYTE out) -{ - if (!in || !out) - return STATUS_UNSUCCESSFUL; - - CRYPT_DEShash(out, key, in); - CRYPT_DEShash(out+8, key+7, in+8); - return STATUS_SUCCESS; -} - -/****************************************************************************** - * SystemFunction013 [ADVAPI32.@] - * SystemFunction015 [ADVAPI32.@] - * SystemFunction017 [ADVAPI32.@] - * SystemFunction019 [ADVAPI32.@] - * SystemFunction021 [ADVAPI32.@] - * SystemFunction023 [ADVAPI32.@] - * - * Decrypts two DES blocks with two keys - * - * PARAMS - * data [I] data to decrypt (16 bytes) - * key [I] key data (two lots of 7 bytes) - * output [O] buffer to receive decrypted data (16 bytes) - * - * RETURNS - * Success: STATUS_SUCCESS - * Failure: STATUS_UNSUCCESSFUL if the input or output buffer is NULL - */ -NTSTATUS WINAPI SystemFunction013(const BYTE *in, const BYTE *key, LPBYTE out) -{ - if (!in || !out) - return STATUS_UNSUCCESSFUL; - - CRYPT_DESunhash(out, key, in); - CRYPT_DESunhash(out+8, key+7, in+8); - return STATUS_SUCCESS; -} - -/****************************************************************************** - * SystemFunction024 [ADVAPI32.@] - * - * Encrypts two DES blocks with a 32 bit key... - * - * PARAMS - * data [I] data to encrypt (16 bytes) - * key [I] key data (4 bytes) - * output [O] buffer to receive encrypted data (16 bytes) - * - * RETURNS - * Success: STATUS_SUCCESS - */ -NTSTATUS WINAPI SystemFunction024(const BYTE *in, const BYTE *key, LPBYTE out) -{ - BYTE deskey[0x10]; - - memcpy(deskey, key, 4); - memcpy(deskey+4, key, 4); - memcpy(deskey+8, key, 4); - memcpy(deskey+12, key, 4); - - CRYPT_DEShash(out, deskey, in); - CRYPT_DEShash(out+8, deskey+7, in+8); - - return STATUS_SUCCESS; -} - -/****************************************************************************** - * SystemFunction025 [ADVAPI32.@] - * - * Decrypts two DES blocks with a 32 bit key... - * - * PARAMS - * data [I] data to encrypt (16 bytes) - * key [I] key data (4 bytes) - * output [O] buffer to receive encrypted data (16 bytes) - * - * RETURNS - * Success: STATUS_SUCCESS - */ -NTSTATUS WINAPI SystemFunction025(const BYTE *in, const BYTE *key, LPBYTE out) -{ - BYTE deskey[0x10]; - - memcpy(deskey, key, 4); - memcpy(deskey+4, key, 4); - memcpy(deskey+8, key, 4); - memcpy(deskey+12, key, 4); - - CRYPT_DESunhash(out, deskey, in); - CRYPT_DESunhash(out+8, deskey+7, in+8); - - return STATUS_SUCCESS; -} diff --git a/dlls/cryptsp/Makefile.in b/dlls/cryptsp/Makefile.in index 4a2a7c4ef5d..8d466541625 100644 --- a/dlls/cryptsp/Makefile.in +++ b/dlls/cryptsp/Makefile.in @@ -3,4 +3,5 @@ IMPORTLIB = cryptsp IMPORTS = advapi32
SOURCES = \ - arc4.c + arc4.c \ + lmhash.c diff --git a/dlls/cryptsp/cryptsp.spec b/dlls/cryptsp/cryptsp.spec index 545e5294a4d..6e541c9ec82 100644 --- a/dlls/cryptsp/cryptsp.spec +++ b/dlls/cryptsp/cryptsp.spec @@ -38,26 +38,26 @@ @ stdcall -import CryptSignHashW(long long wstr long ptr ptr) @ stdcall -import CryptVerifySignatureA(long ptr long long str long) @ stdcall -import CryptVerifySignatureW(long ptr long long wstr long) -@ stdcall -import SystemFunction006(ptr ptr) +@ stdcall SystemFunction006(ptr ptr) @ stdcall -import SystemFunction007(ptr ptr) -@ stdcall -import SystemFunction008(ptr ptr ptr) -@ stdcall -import SystemFunction009(ptr ptr ptr) +@ stdcall SystemFunction008(ptr ptr ptr) +@ stdcall SystemFunction009(ptr ptr ptr) SystemFunction008 @ stdcall -import SystemFunction010(ptr ptr ptr) @ stdcall -import SystemFunction011(ptr ptr ptr) -@ stdcall -import SystemFunction012(ptr ptr ptr) -@ stdcall -import SystemFunction013(ptr ptr ptr) -@ stdcall -import SystemFunction014(ptr ptr ptr) -@ stdcall -import SystemFunction015(ptr ptr ptr) -@ stdcall -import SystemFunction016(ptr ptr ptr) -@ stdcall -import SystemFunction018(ptr ptr ptr) -@ stdcall -import SystemFunction020(ptr ptr ptr) -@ stdcall -import SystemFunction021(ptr ptr ptr) -@ stdcall -import SystemFunction022(ptr ptr ptr) -@ stdcall -import SystemFunction023(ptr ptr ptr) -@ stdcall -import SystemFunction024(ptr ptr ptr) -@ stdcall -import SystemFunction025(ptr ptr ptr) -@ stdcall -import SystemFunction026(ptr ptr ptr) -@ stdcall -import SystemFunction027(ptr ptr ptr) +@ stdcall SystemFunction012(ptr ptr ptr) +@ stdcall SystemFunction013(ptr ptr ptr) +@ stdcall SystemFunction014(ptr ptr ptr) SystemFunction012 +@ stdcall SystemFunction015(ptr ptr ptr) SystemFunction013 +@ stdcall SystemFunction016(ptr ptr ptr) SystemFunction012 +@ stdcall SystemFunction018(ptr ptr ptr) SystemFunction012 +@ stdcall SystemFunction020(ptr ptr ptr) SystemFunction012 +@ stdcall SystemFunction021(ptr ptr ptr) SystemFunction013 +@ stdcall SystemFunction022(ptr ptr ptr) SystemFunction012 +@ stdcall SystemFunction023(ptr ptr ptr) SystemFunction013 +@ stdcall SystemFunction024(ptr ptr ptr) +@ stdcall SystemFunction025(ptr ptr ptr) +@ stdcall SystemFunction026(ptr ptr ptr) SystemFunction024 +@ stdcall SystemFunction027(ptr ptr ptr) SystemFunction025 @ stdcall -import SystemFunction030(ptr ptr) @ stdcall -import SystemFunction031(ptr ptr) @ stdcall SystemFunction032(ptr ptr) diff --git a/dlls/cryptsp/lmhash.c b/dlls/cryptsp/lmhash.c new file mode 100644 index 00000000000..4e347a29c32 --- /dev/null +++ b/dlls/cryptsp/lmhash.c @@ -0,0 +1,217 @@ +/* + * Copyright 2004 Hans Leidekker + * + * Based on LMHash.c from libcifs + * + * Copyright (C) 2004 by Christopher R. Hertel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdarg.h> + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winternl.h" + +NTSTATUS WINAPI SystemFunction001(const BYTE *data, const BYTE *key, BYTE *output); +NTSTATUS WINAPI SystemFunction002(const BYTE *data, const BYTE *key, BYTE *output); + +static void DEShash( BYTE *output, const BYTE *key, const BYTE *data ) +{ + SystemFunction001( data, key, output ); +} + +static void DESunhash( BYTE *output, const BYTE *key, const BYTE *data ) +{ + SystemFunction002( data, key, output ); +} + +static const unsigned char LMhash_Magic[8] = {'K','G','S','!','@','#','$','%'}; + +static void LMhash( unsigned char *dst, const unsigned char *pwd, const int len ) +{ + int i, max = 14; + unsigned char tmp_pwd[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; + + max = len > max ? max : len; + + for (i = 0; i < max; i++) + tmp_pwd[i] = pwd[i]; + + DEShash( dst, tmp_pwd, LMhash_Magic ); + DEShash( &dst[8], &tmp_pwd[7], LMhash_Magic ); +} + +/****************************************************************************** + * SystemFunction006 (cryptsp.@) + */ +NTSTATUS WINAPI SystemFunction006( const char *password, char *hash ) +{ + LMhash( (unsigned char *)hash, (const unsigned char *)password, strlen( password ) ); + + return STATUS_SUCCESS; +} + +/****************************************************************************** + * SystemFunction008 (cryptsp.@) + * SystemFunction009 (cryptsp.@) + * + * 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 BYTE *challenge, const BYTE *hash, BYTE *response ) +{ + BYTE key[7 * 3]; + + if (!challenge || !response) + return STATUS_UNSUCCESSFUL; + + memset( key, 0, sizeof(key) ); + memcpy( key, hash, 0x10 ); + + DEShash( response, key, challenge ); + DEShash( response + 8, key + 7, challenge ); + DEShash( response + 16, key + 14, challenge ); + + return STATUS_SUCCESS; +} + +/****************************************************************************** + * SystemFunction012 (cryptsp.@) + * SystemFunction014 (cryptsp.@) + * SystemFunction016 (cryptsp.@) + * SystemFunction018 (cryptsp.@) + * SystemFunction020 (cryptsp.@) + * SystemFunction022 (cryptsp.@) + * + * Encrypts two DES blocks with two keys + * + * PARAMS + * data [I] data to encrypt (16 bytes) + * key [I] key data (two lots of 7 bytes) + * output [O] buffer to receive encrypted data (16 bytes) + * + * RETURNS + * Success: STATUS_SUCCESS + * Failure: STATUS_UNSUCCESSFUL if the input or output buffer is NULL + */ +NTSTATUS WINAPI SystemFunction012( const BYTE *in, const BYTE *key, BYTE *out ) +{ + if (!in || !out) + return STATUS_UNSUCCESSFUL; + + DEShash( out, key, in ); + DEShash( out + 8, key + 7, in + 8 ); + return STATUS_SUCCESS; +} + +/****************************************************************************** + * SystemFunction013 (cryptsp.@) + * SystemFunction015 (cryptsp.@) + * SystemFunction021 (cryptsp.@) + * SystemFunction023 (cryptsp.@) + * + * Decrypts two DES blocks with two keys + * + * PARAMS + * data [I] data to decrypt (16 bytes) + * key [I] key data (two lots of 7 bytes) + * output [O] buffer to receive decrypted data (16 bytes) + * + * RETURNS + * Success: STATUS_SUCCESS + * Failure: STATUS_UNSUCCESSFUL if the input or output buffer is NULL + */ +NTSTATUS WINAPI SystemFunction013( const BYTE *in, const BYTE *key, BYTE *out ) +{ + if (!in || !out) + return STATUS_UNSUCCESSFUL; + + DESunhash( out, key, in ); + DESunhash( out + 8, key + 7, in + 8 ); + return STATUS_SUCCESS; +} + +/****************************************************************************** + * SystemFunction024 (cryptsp.@) + * SystemFunction026 (cryptsp.@) + * + * Encrypts two DES blocks with a 32 bit key... + * + * PARAMS + * data [I] data to encrypt (16 bytes) + * key [I] key data (4 bytes) + * output [O] buffer to receive encrypted data (16 bytes) + * + * RETURNS + * Success: STATUS_SUCCESS + */ +NTSTATUS WINAPI SystemFunction024( const BYTE *in, const BYTE *key, BYTE *out ) +{ + BYTE deskey[0x10]; + + memcpy( deskey, key, 4 ); + memcpy( deskey + 4, key, 4 ); + memcpy( deskey + 8, key, 4 ); + memcpy( deskey + 12, key, 4 ); + + DEShash( out, deskey, in ); + DEShash( out + 8, deskey + 7, in + 8 ); + + return STATUS_SUCCESS; +} + +/****************************************************************************** + * SystemFunction025 (cryptsp.@) + * SystemFunction027 (cryptsp.@) + * + * Decrypts two DES blocks with a 32 bit key... + * + * PARAMS + * data [I] data to encrypt (16 bytes) + * key [I] key data (4 bytes) + * output [O] buffer to receive encrypted data (16 bytes) + * + * RETURNS + * Success: STATUS_SUCCESS + */ +NTSTATUS WINAPI SystemFunction025( const BYTE *in, const BYTE *key, BYTE *out ) +{ + BYTE deskey[0x10]; + + memcpy( deskey, key, 4 ); + memcpy( deskey + 4, key, 4 ); + memcpy( deskey + 8, key, 4 ); + memcpy( deskey + 12, key, 4 ); + + DESunhash( out, deskey, in ); + DESunhash( out + 8, deskey + 7, in + 8 ); + + return STATUS_SUCCESS; +}