2 Unix SMB/Netbios implementation.
5 a implementation of arcfour designed for use in the
6 SMB password change protocol based on the description
7 in 'Applied Cryptography', 2nd Edition.
9 Copyright (C) Jeremy Allison 1997
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 void set_arc4_key(unsigned char *data
, int key_length
, arc4_key
*arckey
)
33 unsigned char *s_box
= &arckey
->s_box
[0];
37 for(i
= 0; i
< 256; i
++)
38 s_box
[i
] = (unsigned char)i
;
41 for( i
= 0; i
< 256; i
++)
43 j
+= (s_box
[i
] + data
[i
%key_length
]);
50 void arc4(arc4_key
*arckey
, unsigned char *data_in
, unsigned char *data_out
,
57 unsigned char *s_box
= &arckey
->s_box
[0];
59 for( ind
= 0; ind
< length
; ind
++)
61 i
= ++arckey
->index_i
;
62 j
= arckey
->index_j
+= s_box
[i
];
66 t
= s_box
[i
] + s_box
[j
];
67 *data_out
++ = *data_in
++ ^ s_box
[t
];
73 unsigned char key_data
[] = { 0x61, 0x8a, 0x63, 0xd2, 0xfb };
74 unsigned char plaintext
[] = { 0xdc, 0xee, 0x4c, 0xf9, 0x2c };
75 unsigned char ciphertext
[] = { 0xf1, 0x38, 0x29, 0xc9, 0xde };
77 int main(int argc
, char *argv
[])
82 set_arc4_key(key_data
, 5, &key
);
83 arc4(&key
, plaintext
, out
, 5);
85 if(memcmp(out
, ciphertext
, 5) ==0)
86 printf("Test ok !\n");
88 printf("Test fail !\n");