OpenVAS Scanner  7.0.0~git
arc4.c
Go to the documentation of this file.
1 /* Copyright (C) Jeremy Allison 2005.
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 #include <stdlib.h>
21 /*****************************************************************
22  Initialize state for an arc4 crypt/decrpyt.
23  arc4 state is 258 bytes - last 2 bytes are the index bytes.
24 *****************************************************************/
25 
26 void
27 smb_arc4_init_ntlmssp (unsigned char arc4_state_out[258],
28  const unsigned char *key, size_t keylen)
29 {
30  size_t ind;
31  unsigned char j = 0;
32 
33  for (ind = 0; ind < 256; ind++)
34  {
35  arc4_state_out[ind] = (unsigned char) ind;
36  }
37 
38  for (ind = 0; ind < 256; ind++)
39  {
40  unsigned char tc;
41 
42  j += (arc4_state_out[ind] + key[ind % keylen]);
43 
44  tc = arc4_state_out[ind];
45  arc4_state_out[ind] = arc4_state_out[j];
46  arc4_state_out[j] = tc;
47  }
48  arc4_state_out[256] = 0;
49  arc4_state_out[257] = 0;
50 }
51 
52 /*****************************************************************
53  Do the arc4 crypt/decrpyt.
54  arc4 state is 258 bytes - last 2 bytes are the index bytes.
55 *****************************************************************/
56 
57 void
58 smb_arc4_crypt_ntlmssp (unsigned char arc4_state_inout[258],
59  unsigned char *data, size_t len)
60 {
61  unsigned char index_i = arc4_state_inout[256];
62  unsigned char index_j = arc4_state_inout[257];
63  size_t ind;
64 
65  for (ind = 0; ind < len; ind++)
66  {
67  unsigned char tc;
68  unsigned char t;
69 
70  index_i++;
71  index_j += arc4_state_inout[index_i];
72 
73  tc = arc4_state_inout[index_i];
74  arc4_state_inout[index_i] = arc4_state_inout[index_j];
75  arc4_state_inout[index_j] = tc;
76 
77  t = arc4_state_inout[index_i] + arc4_state_inout[index_j];
78  data[ind] = data[ind] ^ arc4_state_inout[t];
79  }
80 
81  arc4_state_inout[256] = index_i;
82  arc4_state_inout[257] = index_j;
83 }
smb_arc4_crypt_ntlmssp
void smb_arc4_crypt_ntlmssp(unsigned char arc4_state_inout[258], unsigned char *data, size_t len)
Definition: arc4.c:58
smb_arc4_init_ntlmssp
void smb_arc4_init_ntlmssp(unsigned char arc4_state_out[258], const unsigned char *key, size_t keylen)
Definition: arc4.c:27