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 DES3state state; 12 }; 13 14 static CipherState* 15 init3des(Conn *c, int dir) 16 { 17 CipherState *cs; 18 uchar key[3][8]; 19 20 cs = emalloc9p(sizeof(CipherState)); 21 if(dir){ 22 memmove(key, c->s2cek, sizeof key); 23 setupDES3state(&cs->state, key, c->s2civ); 24 } else { 25 memmove(key, c->c2sek, sizeof key); 26 setupDES3state(&cs->state, key, c->c2siv); 27 } 28 return cs; 29 } 30 31 static void 32 encrypt3des(CipherState *cs, uchar *buf, int nbuf) 33 { 34 des3CBCencrypt(buf, nbuf, &cs->state); 35 } 36 37 static void 38 decrypt3des(CipherState *cs, uchar *buf, int nbuf) 39 { 40 des3CBCdecrypt(buf, nbuf, &cs->state); 41 } 42 43 Cipher cipher3des = { 44 "3des-cbc", 45 8, 46 init3des, 47 encrypt3des, 48 decrypt3des, 49 }; 50