OpenVAS Libraries  9.0.3
smb_signing.c
Go to the documentation of this file.
1 /*
2  Unix SMB/CIFS implementation.
3  SMB Signing Code
4  Copyright (C) Jeremy Allison 2003.
5  Copyright (C) Andrew Bartlett <abartlet@samba.org> 2002-2003
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 
21  Modified by Preeti Subramanian <spreeti@secpod.com> for OpenVAS:
22  simple packet signature function argument struct smb_basic_signing_context
23  *data to uint8_t* mac_key and henceforth used mac_key in the implementation
24 */
25 #include "smb_signing.h"
26 
27 void simple_packet_signature_ntlmssp(uint8_t *mac_key, const uchar *buf, uint32 seq_number, unsigned char *calc_md5_mac)
28 {
29  const size_t offset_end_of_sig = (smb_ss_field + 8);
30  unsigned char sequence_buf[8];
31  struct MD5Context md5_ctx;
32 
33  /*
34  * Firstly put the sequence number into the first 4 bytes.
35  * and zero out the next 4 bytes.
36  *
37  * We do this here, to avoid modifying the packet.
38  */
39 
40  SIVAL(sequence_buf, 0, seq_number);
41  SIVAL(sequence_buf, 4, 0);
42 
43  /* Calculate the 16 byte MAC - but don't alter the data in the
44  incoming packet.
45 
46  This makes for a bit of fussing about, but it's not too bad.
47  */
48  MD5Init(&md5_ctx);
49 
50  /* intialise with the key */
51  MD5Update(&md5_ctx, mac_key, 16);
52 
53  /* copy in the first bit of the SMB header */
54  MD5Update(&md5_ctx, buf + 4, smb_ss_field - 4);
55 
56  /* copy in the sequence number, instead of the signature */
57  MD5Update(&md5_ctx, sequence_buf, sizeof(sequence_buf));
58 
59  /* copy in the rest of the packet in, skipping the signature */
60  MD5Update(&md5_ctx, buf + offset_end_of_sig,
61  smb_len(buf) - (offset_end_of_sig - 4));
62 
63  /* calculate the MD5 sig */
64  MD5Final(calc_md5_mac, &md5_ctx);
65 }
66 
#define uchar
Definition: hmacmd5.h:28
#define uint32
Definition: genrand.c:49
void simple_packet_signature_ntlmssp(uint8_t *mac_key, const uchar *buf, uint32 seq_number, unsigned char *calc_md5_mac)
Definition: smb_signing.c:27
#define smb_len(buf)
Definition: smb.h:181
uint32 buf[4]
Definition: md5.h:47
#define smb_ss_field
Definition: smb.h:56
#define SIVAL(buf, pos, val)
Definition: byteorder.h:123
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
Definition: md5.c:107
void MD5Init(struct MD5Context *ctx)
Definition: md5.c:44
Definition: md5.h:46
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
Definition: md5.c:59