summaryrefslogtreecommitdiff
path: root/rc4.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-12-07 15:38:31 +1100
committerDamien Miller <djm@mindrot.org>1999-12-07 15:38:31 +1100
commit037a0dc0835bb5a442bdcbeecdd5baed723f0b45 (patch)
treed02954d57ac437fd036e3e9544f24559ca8f0f0f /rc4.c
parenteabf3417bc73ca9546a3ed489cd809ffdf303853 (diff)
- Merged more OpenBSD changes:
- [atomicio.c authfd.c scp.c serverloop.c ssh.h sshconnect.c sshd.c] move atomicio into it's own file. wrap all socket write()s which were doing write(sock, buf, len) != len, with atomicio() calls. - [auth-skey.c] fd leak - [authfile.c] properly name fd variable - [channels.c] display great hatred towards strcpy - [pty.c pty.h sshd.c] use openpty() if it exists (it does on BSD4_4) - [tildexpand.c] check for ~ expansion past MAXPATHLEN - Modified helper.c to use new atomicio function. - Reformat Makefile a little - Moved RC4 routines from rc4.[ch] into helper.c - Added autoconf code to detect /dev/ptmx (Solaris) and /dev/ptc (AIX)
Diffstat (limited to 'rc4.c')
-rw-r--r--rc4.c109
1 files changed, 0 insertions, 109 deletions
diff --git a/rc4.c b/rc4.c
deleted file mode 100644
index 998a10774..000000000
--- a/rc4.c
+++ /dev/null
@@ -1,109 +0,0 @@
1/*! \file rc4.c
2 \brief Source file for RC4 stream cipher routines
3 \author Damien Miller <djm@mindrot.org>
4 \version 0.0.0
5 \date 1999
6
7 A simple implementation of the RC4 stream cipher, based on the
8 description given in _Bruce Schneier's_ "Applied Cryptography"
9 2nd edition.
10
11 Copyright 1999 Damien Miller
12
13 Permission is hereby granted, free of charge, to any person
14 obtaining a copy of this software and associated documentation
15 files (the "Software"), to deal in the Software without
16 restriction, including without limitation the rights to use, copy,
17 modify, merge, publish, distribute, sublicense, and/or sell copies
18 of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be
22 included in all copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
25 KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
26 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
27 AND NONINFRINGEMENT. IN NO EVENT SHALL DAMIEN MILLER BE LIABLE
28 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
32 \warning None of these functions clears its memory after use. It
33 \warning is the responsability of the calling routines to ensure
34 \warning that any sensitive data (keystream, key or plaintext) is
35 \warning properly erased after use.
36
37 \warning The name "RC4" is trademarked in the United States,
38 \warning you may need to use "RC4 compatible" or "ARC4"
39 \warning (Alleged RC4).
40*/
41
42/* $Id: rc4.c,v 1.1.1.1 1999/10/26 05:48:13 damien Exp $ */
43
44#include "config.h"
45
46#ifndef HAVE_ARC4RANDOM
47#include "rc4.h"
48
49
50void rc4_key(rc4_t *r, unsigned char *key, int len)
51{
52 int t;
53
54 for(r->i = 0; r->i < 256; r->i++)
55 r->s[r->i] = r->i;
56
57 r->j = 0;
58 for(r->i = 0; r->i < 256; r->i++)
59 {
60 r->j = (r->j + r->s[r->i] + key[r->i % len]) % 256;
61 t = r->s[r->i];
62 r->s[r->i] = r->s[r->j];
63 r->s[r->j] = t;
64 }
65 r->i = r->j = 0;
66}
67
68void rc4_crypt(rc4_t *r, unsigned char *plaintext, int len)
69{
70 int t;
71 int c;
72
73 c = 0;
74 while(c < len)
75 {
76 r->i = (r->i + 1) % 256;
77 r->j = (r->j + r->s[r->i]) % 256;
78 t = r->s[r->i];
79 r->s[r->i] = r->s[r->j];
80 r->s[r->j] = t;
81
82 t = (r->s[r->i] + r->s[r->j]) % 256;
83
84 plaintext[c] ^= r->s[t];
85 c++;
86 }
87}
88
89void rc4_getbytes(rc4_t *r, unsigned char *buffer, int len)
90{
91 int t;
92 int c;
93
94 c = 0;
95 while(c < len)
96 {
97 r->i = (r->i + 1) % 256;
98 r->j = (r->j + r->s[r->i]) % 256;
99 t = r->s[r->i];
100 r->s[r->i] = r->s[r->j];
101 r->s[r->j] = t;
102
103 t = (r->s[r->i] + r->s[r->j]) % 256;
104
105 buffer[c] = r->s[t];
106 c++;
107 }
108}
109#endif /* !HAVE_ARC4RANDOM */