Reserve extra space for conversions.
[wine] / dlls / advapi32 / crypt_lmhash.c
1 /*
2  *  Copyright 2004 Hans Leidekker
3  *
4  *  Based on LMHash.c from libcifs
5  *
6  *  Copyright (C) 2004 by Christopher R. Hertel
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2.1 of the License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "winternl.h"
29 #include "ntstatus.h"
30
31 #include "crypt.h"
32
33 static const unsigned char CRYPT_LMhash_Magic[8] =
34     { 'K', 'G', 'S', '!', '@', '#', '$', '%' };
35
36 static void CRYPT_LMhash( unsigned char *dst, const unsigned char *pwd, const int len )
37 {
38     int i, max = 14;
39     unsigned char tmp_pwd[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
40
41     max = len > max ? max : len;
42
43     for (i = 0; i < max; i++)
44         tmp_pwd[i] = pwd[i];
45
46     CRYPT_DEShash( dst, tmp_pwd, CRYPT_LMhash_Magic );
47     CRYPT_DEShash( &dst[8], &tmp_pwd[7], CRYPT_LMhash_Magic );
48 }
49
50 NTSTATUS WINAPI SystemFunction006( LPCSTR password, LPSTR hash )
51 {
52     CRYPT_LMhash( (unsigned char*)hash, (unsigned char*)password, strlen(password) );
53
54     return STATUS_SUCCESS;
55 }