1rc4(n)                         RC4 Stream Cipher                        rc4(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       rc4 - Implementation of the RC4 stream cipher
9

SYNOPSIS

11       package require Tcl  8.2
12
13       package require rc4  ?1.1.0?
14
15       ::rc4::rc4  ?-hex?  -key  keyvalue  ?-command lst? ?-out channel? [ -in
16       channel | -infile filename | string ]
17
18       ::rc4::RC4Init keydata
19
20       ::rc4::RC4 Key data
21
22       ::rc4::RC4Final Key
23
24______________________________________________________________________________
25

DESCRIPTION

27       This package is an implementation in  Tcl  of  the  RC4  stream  cipher
28       developed  by  Ron  Rivest  of  RSA Data Security Inc. The cipher was a
29       trade secret of RSA but was reverse-engineered  and  published  to  the
30       internet  in  1994.  It  is  used  in a number of network protocols for
31       securing communications. To evade trademark restrictions this cipher is
32       sometimes known as ARCFOUR.
33

COMMANDS

35       ::rc4::rc4  ?-hex?  -key  keyvalue  ?-command lst? ?-out channel? [ -in
36       channel | -infile filename | string ]
37              Perform the RC4 algorithm on either the  data  provided  by  the
38              argument  or  on  the data read from the -in channel. If an -out
39              channel is given then the result will be written to  this  chan‐
40              nel.   Giving  the -hex option will return a hexadecimal encoded
41              version of the result if not using an -out channel.
42
43              The data to be processes can be specified  either  as  a  string
44              argument  to  the  rc4 command, or as a filename or a pre-opened
45              channel. If the -infile argument  is  given  then  the  file  is
46              opened,  the  data read and processed and the file is closed. If
47              the -in argument is given then data is  read  from  the  channel
48              until  the  end  of file. The channel is not closed. If the -out
49              argument is given then the processing result is written to  this
50              channel.
51
52              If  -command  is  provided  then the rc4 command does not return
53              anything. Instead the command provided is called  with  the  rc4
54              result data appended as the final parameter. This is most useful
55              when reading from Tcl channels as a fileevent is  setup  on  the
56              channel and the data processed in chunks
57
58              Only one of -infile, -in or string should be given.
59

PROGRAMMING INTERFACE

61       ::rc4::RC4Init keydata
62              Initialize  a  new  RC4 key. The keydata is any amount of binary
63              data and is used to initialize the cipher internal state.
64
65       ::rc4::RC4 Key data
66              Encrypt or decrypt the input data  using  the  key  obtained  by
67              calling RC4Init.
68
69       ::rc4::RC4Final Key
70              This should be called to clean up resources associated with Key.
71              Once this function has been called the key is destroyed.
72

EXAMPLES

74              % set keydata [binary format H* 0123456789abcdef]
75              % rc4::rc4 -hex -key $keydata HelloWorld
76              3cf1ae8b7f1c670b612f
77              % rc4::rc4 -hex -key $keydata [binary format H* 3cf1ae8b7f1c670b612f]
78              HelloWorld
79
80
81
82               set Key [rc4::RC4Init "key data"]
83               append ciphertext [rc4::RC4 $Key $plaintext]
84               append ciphertext [rc4::RC4 $Key $additional_plaintext]
85               rc4::RC4Final $Key
86
87
88
89               proc ::Finish {myState data} {
90                   DoStuffWith $myState $data
91               }
92               rc4::rc4 -in $socket -command [list ::Finish $ApplicationState]
93
94

AUTHORS

96       Pat Thoyts
97

BUGS, IDEAS, FEEDBACK

99       This document, and the package it describes, will  undoubtedly  contain
100       bugs and other problems.  Please report such in the category rc4 of the
101       Tcllib Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please  also
102       report  any  ideas  for  enhancements  you  may have for either package
103       and/or documentation.
104
105       When proposing code changes, please provide unified diffs, i.e the out‐
106       put of diff -u.
107
108       Note  further  that  attachments  are  strongly  preferred over inlined
109       patches. Attachments can be made by going  to  the  Edit  form  of  the
110       ticket  immediately  after  its  creation, and then using the left-most
111       button in the secondary navigation bar.
112

SEE ALSO

114       aes(n), blowfish(n), des(n)
115

KEYWORDS

117       arcfour, data integrity, encryption, rc4, security, stream cipher
118

CATEGORY

120       Hashes, checksums, and encryption
121
123       Copyright (c) 2003, Pat Thoyts <patthoyts@users.sourceforge.net>
124
125
126
127
128tcllib                               1.1.0                              rc4(n)
Impressum