summaryrefslogtreecommitdiff
path: root/sys/src/cmd/ssh/cipher3des.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/ssh/cipher3des.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/ssh/cipher3des.c')
-rwxr-xr-xsys/src/cmd/ssh/cipher3des.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/sys/src/cmd/ssh/cipher3des.c b/sys/src/cmd/ssh/cipher3des.c
new file mode 100755
index 000000000..b7b2b641c
--- /dev/null
+++ b/sys/src/cmd/ssh/cipher3des.c
@@ -0,0 +1,47 @@
+#include "ssh.h"
+
+struct CipherState
+{
+ DESstate enc3des[3];
+ DESstate dec3des[3];
+};
+
+static CipherState*
+init3des(Conn *c, int)
+{
+ int i;
+ CipherState *cs;
+
+ cs = emalloc(sizeof(CipherState));
+ for(i=0; i<3; i++){
+ setupDESstate(&cs->enc3des[i], c->sesskey+8*i, nil);
+ setupDESstate(&cs->dec3des[i], c->sesskey+8*i, nil);
+ }
+ return cs;
+}
+
+static void
+encrypt3des(CipherState *cs, uchar *buf, int nbuf)
+{
+ desCBCencrypt(buf, nbuf, &cs->enc3des[0]);
+ desCBCdecrypt(buf, nbuf, &cs->enc3des[1]);
+ desCBCencrypt(buf, nbuf, &cs->enc3des[2]);
+}
+
+static void
+decrypt3des(CipherState *cs, uchar *buf, int nbuf)
+{
+ desCBCdecrypt(buf, nbuf, &cs->dec3des[2]);
+ desCBCencrypt(buf, nbuf, &cs->dec3des[1]);
+ desCBCdecrypt(buf, nbuf, &cs->dec3des[0]);
+}
+
+Cipher cipher3des =
+{
+ SSH_CIPHER_3DES,
+ "3des",
+ init3des,
+ encrypt3des,
+ decrypt3des,
+};
+