xref: /plan9/sys/src/cmd/ssh2/cipherrc4.c (revision 63afb9a5d3f910047231762bcce0ee49fed3d07c)
1 #include <u.h>
2 #include <libc.h>
3 #include <mp.h>
4 #include <fcall.h>
5 #include <thread.h>
6 #include <9p.h>
7 #include <libsec.h>
8 #include "netssh.h"
9 
10 struct CipherState {
11 	RC4state state;
12 };
13 
14 static CipherState*
initrc4(Conn * c,int dir)15 initrc4(Conn *c, int dir)
16 {
17 	CipherState *cs;
18 
19 	cs = emalloc9p(sizeof(CipherState));
20 	if(dir)
21 		setupRC4state(&cs->state, c->s2cek, 16);
22 	else
23 		setupRC4state(&cs->state, c->c2sek, 16);
24 	return cs;
25 }
26 
27 static void
encryptrc4(CipherState * cs,uchar * buf,int nbuf)28 encryptrc4(CipherState *cs, uchar *buf, int nbuf)
29 {
30 	rc4(&cs->state, buf, nbuf);
31 }
32 
33 static void
decryptrc4(CipherState * cs,uchar * buf,int nbuf)34 decryptrc4(CipherState *cs, uchar *buf, int nbuf)
35 {
36 	rc4(&cs->state, buf, nbuf);
37 }
38 
39 Cipher cipherrc4 = {
40 	"arcfour",
41 	8,
42 	initrc4,
43 	encryptrc4,
44 	decryptrc4,
45 };
46 
47