OpenVAS Libraries  4.0+rc3.SVN
nasl/smb_crypt.h
00001 /*
00002    Unix SMB/Netbios implementation.
00003    Version 1.9.
00004 
00005    a partial implementation of DES designed for use in the
00006    SMB authentication protocol
00007 
00008    Copyright (C) Andrew Tridgell 1998-2000
00009 
00010    This program is free software; you can redistribute it and/or modify
00011    it under the terms of the GNU General Public License as published by
00012    the Free Software Foundation; either version 2 of the License, or
00013    (at your option) any later version.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License
00021    along with this program; if not, write to the Free Software Foundation,
00022    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00023 */
00024 
00025 #ifndef NASL_SMB_CRYPT_H
00026 #define NASL_SMB_CRYPT_H
00027 #include "system.h"
00028 #include "md5.h"
00029 #include "md4.h"
00030 #include "hmacmd5.h"
00031 #include "charset.h"
00032 #include "byteorder.h"
00033 
00034 #ifndef uchar
00035 #define uchar unsigned char
00036 #endif
00037 
00038 #ifndef uint8
00039 #define uint8 uint8_t
00040 #endif
00041 
00042 typedef unsigned int bool;
00043 #define False 0
00044 #define True 1
00045 
00046 void E_P24(const uchar *p21, const uchar *c8, uchar *p24);
00047 void E_P16(uchar *p14,uchar *p16);
00048 
00049 int strupper_w(smb_ucs2_t *s);/*implemented in smb_crypt2.c*/
00050 
00051 void SMBsesskeygen_lm_sess_key_ntlmssp(const uchar lm_hash[16], const uchar lm_resp[24], uint8 sess_key[16]);
00052 
00053 void SMBsesskeygen_ntv1_ntlmssp(const uchar kr[16], const uchar * nt_resp, uint8 sess_key[16]);
00054 
00055 void SMBOWFencrypt_ntlmssp(const uchar passwd[16], const uchar *c8, uchar p24[24]);
00056 
00057 void SMBencrypt_ntlmssp(const char *passwd, const uchar *c8, uchar p24[24]);
00058 
00059 void SMBencrypt_hash_ntlmssp(const uchar lm_hash[16], const uchar *c8, uchar p24[24]);
00060 
00061 void SMBNTencrypt_hash_ntlmssp(const uchar nt_hash[16], uchar *c8, uchar *p24);
00062 
00063 void E_md5hash_ntlmssp(const uchar salt[16], const uchar nthash[16], uchar hash_out[16]);
00064 
00065 bool E_deshash_ntlmssp(const char *passwd, uchar p16[16]);
00066 
00067 void SamOEMhash( uchar *data, const uchar *key, int val);
00068 
00069 /* Does the md5 encryption from the Key Response for NTLMv2. */
00070 void SMBOWFencrypt_ntv2_ntlmssp(const uchar kr[16],
00071                         const uint8_t *srv_chal,
00072                         int srv_chal_len,
00073                         const uint8_t *cli_chal,
00074                         int cli_chal_len,
00075                         uchar resp_buf[16]);
00076 
00077 void SMBsesskeygen_ntv2_ntlmssp(const uchar kr[16],
00078                         const uchar * nt_resp, uint8 sess_key[16]);
00079 
00080 uint8_t * NTLMv2_generate_client_data_ntlmssp(const char *addr_list, int address_list_len);
00081 
00082 void NTLMv2_generate_response_ntlmssp(const uchar ntlm_v2_hash[16],
00083                                           const char *server_chal,
00084                                           const char *address_list, int address_list_len, uint8_t *nt_response);
00085 
00086 void LMv2_generate_response_ntlmssp(const uchar ntlm_v2_hash[16],
00087                                         const char *server_chal, uint8_t *lm_response);
00088 
00089 void SMBNTLMv2encrypt_hash_ntlmssp(const char *user, const char *domain, uchar ntlm_v2_hash[16],
00090                       const char *server_chal,
00091                       const char *address_list, int address_list_len,
00092                       unsigned char *lm_response, unsigned char *nt_response,
00093                       unsigned char *user_session_key);
00094 
00095 #endif