14ee05c3e15552207ea896cb865ff4fe5057221e
[reactos.git] / reactos / dll / advapi32 / crypt / 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 <advapi32.h>
24 #include "crypt.h"
25
26
27 static const unsigned char CRYPT_LMhash_Magic[8] =
28 { 'K', 'G', 'S', '!', '@', '#', '$', '%' };
29
30 static void CRYPT_LMhash(LPSTR dst, LPCSTR pwd, const int len)
31 {
32 int i, max = 14;
33 CHAR tmp_pwd[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
34
35 max = len > max ? max : len;
36
37 for (i = 0; i < max; i++)
38 tmp_pwd[i] = pwd[i];
39
40 CRYPT_DEShash((PUCHAR)dst, (PUCHAR)tmp_pwd, CRYPT_LMhash_Magic);
41 CRYPT_DEShash((PUCHAR)&dst[8], (PUCHAR)&tmp_pwd[7], CRYPT_LMhash_Magic);
42 }
43
44 NTSTATUS WINAPI SystemFunction006(LPCSTR password, LPSTR hash)
45 {
46 CRYPT_LMhash(hash, password, strlen(password));
47
48 return STATUS_SUCCESS;
49 }