1 /* Copyright (C) Andrew Tridgell 1998-2000
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /**
21  * @file smb_crypt.h
22  * @brief Unix SMB/Netbios implementation. Version 1.9.
23  *
24  * a partial implementation of DES designed for use in the
25  * SMB authentication protocol
26  */
27 
28 #ifndef NASL_SMB_CRYPT_H
29 #define NASL_SMB_CRYPT_H
30 #include "byteorder.h"
31 #include "charset.h"
32 #include "hmacmd5.h"
33 #include "md4.h"
34 #include "md5.h"
35 
36 #ifndef uchar
37 #define uchar unsigned char
38 #endif
39 
40 #ifndef uint8
41 #define uint8 uint8_t
42 #endif
43 
44 typedef unsigned int bool;
45 #define False 0
46 #define True 1
47 
48 void
49 E_P24 (const uchar *p21, const uchar *c8, uchar *p24);
50 void
51 E_P16 (uchar *p14, uchar *p16);
52 
53 int
54 strupper_w (smb_ucs2_t *s); /*implemented in smb_crypt2.c*/
55 
56 void
57 SMBsesskeygen_lm_sess_key_ntlmssp (const uchar lm_hash[16],
58                                    const uchar lm_resp[24], uint8 sess_key[16]);
59 
60 void
61 SMBsesskeygen_ntv1_ntlmssp (const uchar kr[16], const uchar *nt_resp,
62                             uint8 sess_key[16]);
63 
64 void
65 SMBOWFencrypt_ntlmssp (const uchar passwd[16], const uchar *c8, uchar p24[24]);
66 
67 void
68 SMBencrypt_hash_ntlmssp (const uchar lm_hash[16], const uchar *c8,
69                          uchar p24[24]);
70 
71 void
72 SMBNTencrypt_hash_ntlmssp (const uchar nt_hash[16], uchar *c8, uchar *p24);
73 
74 bool
75 E_deshash_ntlmssp (const char *passwd, uint8_t pass_len, uchar p16[16]);
76 
77 void
78 SamOEMhash (uchar *data, const uchar *key, int val);
79 
80 /* Does the md5 encryption from the Key Response for NTLMv2. */
81 void
82 SMBOWFencrypt_ntv2_ntlmssp (const uchar kr[16], const uint8_t *srv_chal,
83                             int srv_chal_len, const uint8_t *cli_chal,
84                             int cli_chal_len, uchar resp_buf[16]);
85 
86 void
87 SMBsesskeygen_ntv2_ntlmssp (const uchar kr[16], const uchar *nt_resp,
88                             uint8 sess_key[16]);
89 
90 uint8_t *
91 NTLMv2_generate_client_data_ntlmssp (const char *addr_list,
92                                      int address_list_len);
93 
94 void
95 NTLMv2_generate_response_ntlmssp (const uchar ntlm_v2_hash[16],
96                                   const char *server_chal,
97                                   const char *address_list,
98                                   int address_list_len, uint8_t *nt_response);
99 
100 void
101 LMv2_generate_response_ntlmssp (const uchar ntlm_v2_hash[16],
102                                 const char *server_chal, uint8_t *lm_response);
103 
104 void
105 SMBNTLMv2encrypt_hash_ntlmssp (const char *user, const char *domain,
106                                uchar ntlm_v2_hash[16], const char *server_chal,
107                                const char *address_list, int address_list_len,
108                                unsigned char *lm_response,
109                                unsigned char *nt_response,
110                                unsigned char *user_session_key);
111 
112 #endif
113