xref: /plan9/sys/src/cmd/ssh1/cipherblowfish.c (revision 63afb9a5d3f910047231762bcce0ee49fed3d07c)
1 #include "ssh.h"
2 
3 struct CipherState
4 {
5 	BFstate enc;
6 	BFstate dec;
7 };
8 
9 static CipherState*
initblowfish(Conn * c,int)10 initblowfish(Conn *c, int)
11 {
12 	CipherState *cs;
13 
14 	cs = emalloc(sizeof(CipherState));
15 	setupBFstate(&cs->enc, c->sesskey, SESSKEYLEN, nil);
16 	setupBFstate(&cs->dec, c->sesskey, SESSKEYLEN, nil);
17 	return cs;
18 }
19 
20 static void
encryptblowfish(CipherState * cs,uchar * buf,int nbuf)21 encryptblowfish(CipherState *cs, uchar *buf, int nbuf)
22 {
23 	bfCBCencrypt(buf, nbuf, &cs->enc);
24 }
25 
26 static void
decryptblowfish(CipherState * cs,uchar * buf,int nbuf)27 decryptblowfish(CipherState *cs, uchar *buf, int nbuf)
28 {
29 	bfCBCdecrypt(buf, nbuf, &cs->dec);
30 }
31 
32 Cipher cipherblowfish =
33 {
34 	SSH_CIPHER_BLOWFISH,
35 	"blowfish",
36 	initblowfish,
37 	encryptblowfish,
38 	decryptblowfish,
39 };
40 
41