OpenVAS Scanner  22.7.9
smb_crypt2.c
Go to the documentation of this file.
1 /* SPDX-FileCopyrightText: 2023 Greenbone AG
2  * SPDX-FileCopyrightText: 2002-2003 Andrew Bartlett <abartlet@samba.org>
3  * SPDX-FileCopyrightText: 1996-2000 Luke Kennethc Casson Leighton
4  * SPDX-FileCopyrightText: 1995-2000 Jeremy Allison
5  * SPDX-FileCopyrightText: 1992-1998 Andrew Tridgell
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
15 #include "hmacmd5.h"
16 #include "smb_crypt.h"
17 
18 #include <ctype.h>
19 
20 /*******************************************************************
21  Convert a wchar to upper case.
22 ********************************************************************/
23 
24 static smb_ucs2_t
26 {
27  return UCS2_CHAR (islower (val) ? toupper (val) : val);
28 }
29 
30 /*******************************************************************
31  Convert a string to upper case.
32  return True if any char is converted
33 ********************************************************************/
34 int
36 {
37  int ret = 0;
38  while (*s)
39  {
40  smb_ucs2_t v = toupper_w (*s);
41  if (v != *s)
42  {
43  *s = v;
44  ret = 1;
45  }
46  s++;
47  }
48  return ret;
49 }
50 
51 /* Does the md5 encryption from the NT hash for NTLMv2. */
52 void
53 SMBOWFencrypt_ntv2_ntlmssp (const uchar *kr, const uchar *srv_chal_data,
54  int srv_chal_len, const uchar *cli_chal_data,
55  int cli_chal_len, uchar resp_buf[16])
56 {
57  HMACMD5Context ctx;
58 
59  hmac_md5_init_limK_to_64 (kr, 16, &ctx);
60  hmac_md5_update (srv_chal_data, srv_chal_len, &ctx);
61  hmac_md5_update (cli_chal_data, cli_chal_len, &ctx);
62  hmac_md5_final (resp_buf, &ctx);
63 }
64 
65 /* Example:
66 
67 -smb_session_setup_NTLMv1()
68 
69 - if(pawword)
70 - {
71 - NT_H = nt_owf_gen(password);
72 - LM_H = lm_owf_gen(password);
73 -
74 - lm = NTLMv1_HASH(cryptkey:cs, passhash:LM_H);
75 - nt = NTLMv1_HASH(cryptkey:cs, passhash:NT_H);
76 
77 +smb_session_setup_NTLMv2()
78 
79 + if(password) {
80 + nt_hash = nt_owf_gen(password);
81 + ntlm_v2_hash =
82 ntv2_owf_gen(owf:nt_hash,login:login,domain:domain); + lm=
83 NTLMv2_HASH(cryptkey:cs, passhash:ntlm_v2_hash, length:8); + nt=
84 NTLMv2_HASH(cryptkey:cs, passhash:ntlm_v2_hash, length:64); + }
85 
86 */
HMACMD5Context
Definition: hmacmd5.h:29
uchar
#define uchar
Definition: hmacmd5.h:22
hmac_md5_init_limK_to_64
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:24
strupper_w
int strupper_w(smb_ucs2_t *s)
Definition: smb_crypt2.c:35
hmac_md5_update
void hmac_md5_update(const uchar *text, int text_len, HMACMD5Context *ctx)
Update hmac_md5 "inner" buffer.
Definition: hmacmd5.c:55
smb_ucs2_t
uint16 smb_ucs2_t
Definition: hmacmd5.h:52
UCS2_CHAR
#define UCS2_CHAR(c)
Definition: hmacmd5.h:61
hmacmd5.h
Unix SMB/CIFS implementation. HMAC MD5 code for use in NTLMv2.
hmac_md5_final
void hmac_md5_final(uchar *digest, HMACMD5Context *ctx)
Finish off hmac_md5 "inner" buffer and generate outer one.
Definition: hmacmd5.c:64
val
const char * val
Definition: nasl_init.c:412
SMBOWFencrypt_ntv2_ntlmssp
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:53
smb_crypt.h
Unix SMB/Netbios implementation. Version 1.9.
toupper_w
static smb_ucs2_t toupper_w(smb_ucs2_t val)
Definition: smb_crypt2.c:25