OpenVAS Scanner  7.0.1~git
smb_crypt2.c
Go to the documentation of this file.
1 /* Copyright (C) Andrew Tridgell 1992-1998
2  * Modified by Jeremy Allison 1995.
3  * Copyright (C) Jeremy Allison 1995-2000.
4  * Copyright (C) Luke Kennethc Casson Leighton 1996-2000.
5  * Copyright (C) Andrew Bartlett <abartlet@samba.org> 2002-2003
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
29 #include "hmacmd5.h"
30 
31 #include <ctype.h>
32 
33 /*******************************************************************
34  Convert a wchar to upper case.
35 ********************************************************************/
36 
39 {
40  return UCS2_CHAR (islower (val) ? toupper (val) : val);
41 }
42 
43 /*******************************************************************
44  Convert a string to upper case.
45  return True if any char is converted
46 ********************************************************************/
47 int
49 {
50  int ret = 0;
51  while (*s)
52  {
53  smb_ucs2_t v = toupper_w (*s);
54  if (v != *s)
55  {
56  *s = v;
57  ret = 1;
58  }
59  s++;
60  }
61  return ret;
62 }
63 
64 /* Does the md5 encryption from the NT hash for NTLMv2. */
65 void
66 SMBOWFencrypt_ntv2_ntlmssp (const uchar *kr, const uchar *srv_chal_data,
67  int srv_chal_len, const uchar *cli_chal_data,
68  int cli_chal_len, uchar resp_buf[16])
69 {
70  HMACMD5Context ctx;
71 
72  hmac_md5_init_limK_to_64 (kr, 16, &ctx);
73  hmac_md5_update (srv_chal_data, srv_chal_len, &ctx);
74  hmac_md5_update (cli_chal_data, cli_chal_len, &ctx);
75  hmac_md5_final (resp_buf, &ctx);
76 }
77 
78 /* Example:
79 
80 -smb_session_setup_NTLMv1()
81 
82 - if(pawword)
83 - {
84 - NT_H = nt_owf_gen(password);
85 - LM_H = lm_owf_gen(password);
86 -
87 - lm = NTLMv1_HASH(cryptkey:cs, passhash:LM_H);
88 - nt = NTLMv1_HASH(cryptkey:cs, passhash:NT_H);
89 
90 +smb_session_setup_NTLMv2()
91 
92 + if(password) {
93 + nt_hash = nt_owf_gen(password);
94 + ntlm_v2_hash =
95 ntv2_owf_gen(owf:nt_hash,login:login,domain:domain); + lm=
96 NTLMv2_HASH(cryptkey:cs, passhash:ntlm_v2_hash, length:8); + nt=
97 NTLMv2_HASH(cryptkey:cs, passhash:ntlm_v2_hash, length:64); + }
98 
99 */
#define uchar
Definition: hmacmd5.h:35
const char * val
Definition: nasl_init.c:378
void hmac_md5_init_limK_to_64(const uchar *key, int key_len, HMACMD5Context *ctx)
The microsoft version of hmac_md5 initialisation.
Definition: hmacmd5.c:37
int strupper_w(smb_ucs2_t *s)
Definition: smb_crypt2.c:48
void SMBOWFencrypt_ntv2_ntlmssp(const uchar *kr, const uchar *srv_chal_data, int srv_chal_len, const uchar *cli_chal_data, int cli_chal_len, uchar resp_buf[16])
Definition: smb_crypt2.c:66
Unix SMB/CIFS implementation. HMAC MD5 code for use in NTLMv2.
void hmac_md5_final(uchar *digest, HMACMD5Context *ctx)
Finish off hmac_md5 "inner" buffer and generate outer one.
Definition: hmacmd5.c:77
void hmac_md5_update(const uchar *text, int text_len, HMACMD5Context *ctx)
Update hmac_md5 "inner" buffer.
Definition: hmacmd5.c:68
#define UCS2_CHAR(c)
Definition: hmacmd5.h:74
smb_ucs2_t toupper_w(smb_ucs2_t val)
Definition: smb_crypt2.c:38
uint16 smb_ucs2_t
Definition: hmacmd5.h:65