summaryrefslogtreecommitdiffstats
path: root/cipher.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-04-01 11:09:21 +1000
committerDamien Miller <djm@mindrot.org>2000-04-01 11:09:21 +1000
commitb38eff8e4ff901df9cf1113a9f14d64c3565a401 (patch)
tree9a856898f15f7760ed95c5d47789a6f954b4ad2f /cipher.c
parent450a7a1ff40fe7c2d84c93b83cf2df53445d807d (diff)
- Big OpenBSD CVS update (mainly beginnings of SSH2 infrastructure)
- [auth.c session.c sshd.c auth.h] split sshd.c -> auth.c session.c sshd.c plus cleanup and goto-removal - [bufaux.c bufaux.h] support ssh2 bignums - [channels.c channels.h clientloop.c sshd.c nchan.c nchan.h packet.c] [readconf.c ssh.c ssh.h serverloop.c] replace big switch() with function tables (prepare for ssh2) - [ssh2.h] ssh2 message type codes - [sshd.8] reorder Xr to avoid cutting - [serverloop.c] close(fdin) if fdin != fdout, shutdown otherwise, ok theo@ - [channels.c] missing close allow bigger packets - [cipher.c cipher.h] support ssh2 ciphers - [compress.c] cleanup, less code - [dispatch.c dispatch.h] function tables for different message types - [log-server.c] do not log() if debuggin to stderr rename a cpp symbol, to avoid param.h collision - [mpaux.c] KNF - [nchan.c] sync w/ channels.c
Diffstat (limited to 'cipher.c')
-rw-r--r--cipher.c123
1 files changed, 121 insertions, 2 deletions
diff --git a/cipher.c b/cipher.c
index bf1518de..f7b7b472 100644
--- a/cipher.c
+++ b/cipher.c
@@ -12,7 +12,7 @@
*/
#include "includes.h"
-RCSID("$Id: cipher.c,v 1.14 2000/03/26 03:04:52 damien Exp $");
+RCSID("$Id: cipher.c,v 1.15 2000/04/01 01:09:23 damien Exp $");
#include "ssh.h"
#include "cipher.h"
@@ -122,7 +122,12 @@ static char *cipher_names[] =
"3des",
"tss",
"rc4",
- "blowfish"
+ "blowfish",
+ "reserved",
+ "blowfish-cbc",
+ "3des-cbc",
+ "arcfour",
+ "cast128-cbc"
};
/*
@@ -137,6 +142,10 @@ cipher_mask()
unsigned int mask = 0;
mask |= 1 << SSH_CIPHER_3DES; /* Mandatory */
mask |= 1 << SSH_CIPHER_BLOWFISH;
+ mask |= 1 << SSH_CIPHER_BLOWFISH_CBC;
+ mask |= 1 << SSH_CIPHER_3DES_CBC;
+ mask |= 1 << SSH_CIPHER_ARCFOUR;
+ mask |= 1 << SSH_CIPHER_CAST128_CBC;
return mask;
}
@@ -233,16 +242,84 @@ cipher_set_key(CipherContext *context, int cipher,
break;
case SSH_CIPHER_BLOWFISH:
+ if (keylen < 16)
+ error("Key length %d is insufficient for blowfish.", keylen);
BF_set_key(&context->u.bf.key, keylen, padded);
memset(context->u.bf.iv, 0, 8);
break;
+ case SSH_CIPHER_3DES_CBC:
+ case SSH_CIPHER_BLOWFISH_CBC:
+ case SSH_CIPHER_ARCFOUR:
+ case SSH_CIPHER_CAST128_CBC:
+ fatal("cipher_set_key: illegal cipher: %s", cipher_name(cipher));
+ break;
+
default:
fatal("cipher_set_key: unknown cipher: %s", cipher_name(cipher));
}
memset(padded, 0, sizeof(padded));
}
+
+void
+cipher_set_key_iv(CipherContext * context, int cipher,
+ const unsigned char *key, int keylen,
+ const unsigned char *iv, int ivlen)
+{
+ /* Set cipher type. */
+ context->type = cipher;
+
+ /* Initialize the initialization vector. */
+ switch (cipher) {
+ case SSH_CIPHER_NONE:
+ break;
+
+ case SSH_CIPHER_3DES:
+ case SSH_CIPHER_BLOWFISH:
+ fatal("cipher_set_key_iv: illegal cipher: %s", cipher_name(cipher));
+ break;
+
+ case SSH_CIPHER_3DES_CBC:
+ if (keylen < 24)
+ error("Key length %d is insufficient for 3des-cbc.", keylen);
+ des_set_key((void *) key, context->u.des3.key1);
+ des_set_key((void *) (key+8), context->u.des3.key2);
+ des_set_key((void *) (key+16), context->u.des3.key3);
+ if (ivlen < 8)
+ error("IV length %d is insufficient for 3des-cbc.", ivlen);
+ memcpy(context->u.des3.iv3, (char *)iv, 8);
+ break;
+
+ case SSH_CIPHER_BLOWFISH_CBC:
+ if (keylen < 16)
+ error("Key length %d is insufficient for blowfish.", keylen);
+ if (ivlen < 8)
+ error("IV length %d is insufficient for blowfish.", ivlen);
+ BF_set_key(&context->u.bf.key, keylen, (unsigned char *)key);
+ memcpy(context->u.bf.iv, (char *)iv, 8);
+ break;
+
+ case SSH_CIPHER_ARCFOUR:
+ if (keylen < 16)
+ error("Key length %d is insufficient for arcfour.", keylen);
+ RC4_set_key(&context->u.rc4, keylen, (unsigned char *)key);
+ break;
+
+ case SSH_CIPHER_CAST128_CBC:
+ if (keylen < 16)
+ error("Key length %d is insufficient for cast128.", keylen);
+ if (ivlen < 8)
+ error("IV length %d is insufficient for cast128.", ivlen);
+ CAST_set_key(&context->u.cast.key, keylen, (unsigned char *) key);
+ memcpy(context->u.cast.iv, (char *)iv, 8);
+ break;
+
+ default:
+ fatal("cipher_set_key: unknown cipher: %s", cipher_name(cipher));
+ }
+}
+
/* Encrypts data using the cipher. */
void
@@ -272,6 +349,27 @@ cipher_encrypt(CipherContext *context, unsigned char *dest,
swap_bytes(dest, dest, len);
break;
+ case SSH_CIPHER_BLOWFISH_CBC:
+ BF_cbc_encrypt((void *)src, dest, len,
+ &context->u.bf.key, context->u.bf.iv,
+ BF_ENCRYPT);
+ break;
+
+ case SSH_CIPHER_3DES_CBC:
+ des_ede3_cbc_encrypt(src, dest, len,
+ context->u.des3.key1, context->u.des3.key2,
+ context->u.des3.key3, &context->u.des3.iv3, DES_ENCRYPT);
+ break;
+
+ case SSH_CIPHER_ARCFOUR:
+ RC4(&context->u.rc4, len, (unsigned char *)src, dest);
+ break;
+
+ case SSH_CIPHER_CAST128_CBC:
+ CAST_cbc_encrypt(src, dest, len,
+ &context->u.cast.key, context->u.cast.iv, CAST_ENCRYPT);
+ break;
+
default:
fatal("cipher_encrypt: unknown cipher: %s", cipher_name(context->type));
}
@@ -306,6 +404,27 @@ cipher_decrypt(CipherContext *context, unsigned char *dest,
swap_bytes(dest, dest, len);
break;
+ case SSH_CIPHER_BLOWFISH_CBC:
+ BF_cbc_encrypt((void *) src, dest, len,
+ &context->u.bf.key, context->u.bf.iv,
+ BF_DECRYPT);
+ break;
+
+ case SSH_CIPHER_3DES_CBC:
+ des_ede3_cbc_encrypt(src, dest, len,
+ context->u.des3.key1, context->u.des3.key2,
+ context->u.des3.key3, &context->u.des3.iv3, DES_DECRYPT);
+ break;
+
+ case SSH_CIPHER_ARCFOUR:
+ RC4(&context->u.rc4, len, (unsigned char *)src, dest);
+ break;
+
+ case SSH_CIPHER_CAST128_CBC:
+ CAST_cbc_encrypt(src, dest, len,
+ &context->u.cast.key, context->u.cast.iv, CAST_DECRYPT);
+ break;
+
default:
fatal("cipher_decrypt: unknown cipher: %s", cipher_name(context->type));
}