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