xref: /plan9/sys/src/cmd/ssh1/cipherrc4.c (revision 63afb9a5d3f910047231762bcce0ee49fed3d07c)
1 #include "ssh.h"
2 
3 struct CipherState
4 {
5 	RC4state enc;
6 	RC4state dec;
7 };
8 
9 static CipherState*
initrc4(Conn * c,int isserver)10 initrc4(Conn *c, int isserver)
11 {
12 	CipherState *cs;
13 
14 	cs = emalloc(sizeof(CipherState));
15 	if(isserver){
16 		setupRC4state(&cs->enc, c->sesskey, 16);
17 		setupRC4state(&cs->dec, c->sesskey+16, 16);
18 	}else{
19 		setupRC4state(&cs->dec, c->sesskey, 16);
20 		setupRC4state(&cs->enc, c->sesskey+16, 16);
21 	}
22 	return cs;
23 }
24 
25 static void
encryptrc4(CipherState * cs,uchar * buf,int nbuf)26 encryptrc4(CipherState *cs, uchar *buf, int nbuf)
27 {
28 	rc4(&cs->enc, buf, nbuf);
29 }
30 
31 static void
decryptrc4(CipherState * cs,uchar * buf,int nbuf)32 decryptrc4(CipherState *cs, uchar *buf, int nbuf)
33 {
34 	rc4(&cs->dec, buf, nbuf);
35 }
36 
37 Cipher cipherrc4 =
38 {
39 	SSH_CIPHER_RC4,
40 	"rc4",
41 	initrc4,
42 	encryptrc4,
43 	decryptrc4,
44 };
45 
46