]> andersk Git - openssh.git/blobdiff - cipher.c
- (djm) Fix server not exiting with jobs in background.
[openssh.git] / cipher.c
index d38543b1c636170f3b6dd300cae1b3560275bae3..a44e51d98a2947198428dc83bfccaca2115ea004 100644 (file)
--- a/cipher.c
+++ b/cipher.c
@@ -1,32 +1,29 @@
 /*
- * 
+ *
  * cipher.c
- * 
+ *
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
- * 
+ *
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  *                    All rights reserved
- * 
+ *
  * Created: Wed Apr 19 17:41:39 1995 ylo
- * 
+ *
  */
 
 #include "includes.h"
-RCSID("$Id$");
+RCSID("$OpenBSD: cipher.c,v 1.29 2000/07/10 16:30:25 ho Exp $");
 
 #include "ssh.h"
 #include "cipher.h"
-#include "config.h"
+#include "xmalloc.h"
 
-#ifdef HAVE_OPENSSL
 #include <openssl/md5.h>
-#endif
-#ifdef HAVE_SSL
-#include <ssl/md5.h>
-#endif
 
 /*
- * What kind of tripple DES are these 2 routines?
+ * This is used by SSH1:
+ *
+ * What kind of triple DES are these 2 routines?
  *
  * Why is there a redundant initialization vector?
  *
@@ -81,7 +78,7 @@ SSH_3CBC_DECRYPT(des_key_schedule ks1,
 }
 
 /*
- * SSH uses a variation on Blowfish, all bytes must be swapped before
+ * SSH1 uses a variation on Blowfish, all bytes must be swapped before
  * and after encryption/decryption. Thus the swap_bytes stuff (yuk).
  */
 static void
@@ -136,7 +133,7 @@ static char *cipher_names[] =
  * supported cipher.
  */
 
-unsigned int 
+unsigned int
 cipher_mask1()
 {
        unsigned int mask = 0;
@@ -144,7 +141,7 @@ cipher_mask1()
        mask |= 1 << SSH_CIPHER_BLOWFISH;
        return mask;
 }
-unsigned int 
+unsigned int
 cipher_mask2()
 {
        unsigned int mask = 0;
@@ -154,7 +151,7 @@ cipher_mask2()
        mask |= 1 << SSH_CIPHER_CAST128_CBC;
        return mask;
 }
-unsigned int 
+unsigned int
 cipher_mask()
 {
        return cipher_mask1() | cipher_mask2();
@@ -167,10 +164,35 @@ cipher_name(int cipher)
 {
        if (cipher < 0 || cipher >= sizeof(cipher_names) / sizeof(cipher_names[0]) ||
            cipher_names[cipher] == NULL)
-               fatal("cipher_name: bad cipher number: %d", cipher);
+               fatal("cipher_name: bad cipher name: %d", cipher);
        return cipher_names[cipher];
 }
 
+/* Returns 1 if the name of the ciphers are valid. */
+
+#define        CIPHER_SEP      ","
+int
+ciphers_valid(const char *names)
+{
+       char *ciphers, *cp;
+       char *p;
+       int i;
+
+       if (names == NULL || strcmp(names, "") == 0)
+               return 0;
+       ciphers = cp = xstrdup(names);
+       for ((p = strsep(&cp, CIPHER_SEP)); p && *p != '\0'; 
+            (p = strsep(&cp, CIPHER_SEP))) {
+               i = cipher_number(p);
+               if (i == -1 || !(cipher_mask2() & (1 << i))) {
+                       xfree(ciphers);
+                       return 0;
+               }
+       }
+       xfree(ciphers);
+       return 1;
+}
+
 /*
  * Parses the name of the cipher.  Returns the number of the corresponding
  * cipher, or -1 on error.
@@ -180,6 +202,8 @@ int
 cipher_number(const char *name)
 {
        int i;
+       if (name == NULL)
+               return -1;
        for (i = 0; i < sizeof(cipher_names) / sizeof(cipher_names[0]); i++)
                if (strcmp(cipher_names[i], name) == 0 &&
                    (cipher_mask() & (1 << i)))
@@ -192,7 +216,7 @@ cipher_number(const char *name)
  * passphrase and using the resulting 16 bytes as the key.
  */
 
-void 
+void
 cipher_set_key_string(CipherContext *context, int cipher, const char *passphrase)
 {
        MD5_CTX md;
@@ -210,7 +234,7 @@ cipher_set_key_string(CipherContext *context, int cipher, const char *passphrase
 
 /* Selects the cipher to use and sets the key. */
 
-void 
+void
 cipher_set_key(CipherContext *context, int cipher, const unsigned char *key,
     int keylen)
 {
@@ -271,10 +295,9 @@ cipher_set_key(CipherContext *context, int cipher, const unsigned char *key,
        memset(padded, 0, sizeof(padded));
 }
 
-
-void 
+void
 cipher_set_key_iv(CipherContext * context, int cipher,
-    const unsigned char *key, int keylen, 
+    const unsigned char *key, int keylen,
     const unsigned char *iv, int ivlen)
 {
        /* Set cipher type. */
@@ -332,7 +355,7 @@ cipher_set_key_iv(CipherContext * context, int cipher,
 
 /* Encrypts data using the cipher. */
 
-void 
+void
 cipher_encrypt(CipherContext *context, unsigned char *dest,
               const unsigned char *src, unsigned int len)
 {
@@ -354,14 +377,14 @@ cipher_encrypt(CipherContext *context, unsigned char *dest,
        case SSH_CIPHER_BLOWFISH:
                swap_bytes(src, dest, len);
                BF_cbc_encrypt(dest, dest, len,
-                              &context->u.bf.key, context->u.bf.iv,
+                              &context->u.bf.key, context->u.bf.iv,
                               BF_ENCRYPT);
                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,
+                              &context->u.bf.key, context->u.bf.iv,
                               BF_ENCRYPT);
                break;
 
@@ -387,7 +410,7 @@ cipher_encrypt(CipherContext *context, unsigned char *dest,
 
 /* Decrypts data using the cipher. */
 
-void 
+void
 cipher_decrypt(CipherContext *context, unsigned char *dest,
               const unsigned char *src, unsigned int len)
 {
This page took 0.040302 seconds and 4 git commands to generate.