]> andersk Git - openssh.git/blobdiff - cipher.c
- (bal) auth1.c minor resync while looking at the code.
[openssh.git] / cipher.c
index b18c701fb03168024f7e750e49c7b3e8b326c76a..b5d38747ed8039124eb2a7ec61ee1f8db95da621 100644 (file)
--- a/cipher.c
+++ b/cipher.c
@@ -35,7 +35,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: cipher.c,v 1.59 2002/06/19 18:01:00 markus Exp $");
+RCSID("$OpenBSD: cipher.c,v 1.62 2002/11/21 22:45:31 markus Exp $");
 
 #include "xmalloc.h"
 #include "log.h"
@@ -95,11 +95,13 @@ cipher_blocksize(Cipher *c)
 {
        return (c->block_size);
 }
+
 u_int
 cipher_keylen(Cipher *c)
 {
        return (c->key_len);
 }
+
 u_int
 cipher_get_number(Cipher *c)
 {
@@ -237,7 +239,7 @@ cipher_init(CipherContext *cc, Cipher *cipher,
                    cipher->name);
        klen = EVP_CIPHER_CTX_key_length(&cc->evp);
        if (klen > 0 && keylen != klen) {
-               debug("cipher_init: set keylen (%d -> %d)", klen, keylen);
+               debug2("cipher_init: set keylen (%d -> %d)", klen, keylen);
                if (EVP_CIPHER_CTX_set_key_length(&cc->evp, keylen) == 0)
                        fatal("cipher_init: set keylen failed (%d -> %d)",
                            klen, keylen);
@@ -314,6 +316,7 @@ struct ssh1_3des_ctx
 {
        EVP_CIPHER_CTX  k1, k2, k3;
 };
+
 static int
 ssh1_3des_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
     int enc)
@@ -356,6 +359,7 @@ ssh1_3des_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
 #endif
        return (1);
 }
+
 static int
 ssh1_3des_cbc(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src, u_int len)
 {
@@ -377,6 +381,7 @@ ssh1_3des_cbc(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src, u_int len)
 #endif
        return (1);
 }
+
 static int
 ssh1_3des_cleanup(EVP_CIPHER_CTX *ctx)
 {
@@ -389,6 +394,7 @@ ssh1_3des_cleanup(EVP_CIPHER_CTX *ctx)
        }
        return (1);
 }
+
 static const EVP_CIPHER *
 evp_ssh1_3des(void)
 {
@@ -430,7 +436,21 @@ swap_bytes(const u_char *src, u_char *dst, int n)
                *dst++ = c[3];
        }
 }
+
+#ifdef SSH_OLD_EVP
+static void bf_ssh1_init (EVP_CIPHER_CTX * ctx, const unsigned char *key,
+                         const unsigned char *iv, int enc)
+{
+       if (iv != NULL)
+               memcpy (&(ctx->oiv[0]), iv, 8);
+       memcpy (&(ctx->iv[0]), &(ctx->oiv[0]), 8);
+       if (key != NULL)
+               BF_set_key (&(ctx->c.bf_ks), EVP_CIPHER_CTX_key_length (ctx),
+                           key);
+}
+#endif
 static int (*orig_bf)(EVP_CIPHER_CTX *, u_char *, const u_char *, u_int) = NULL;
+
 static int
 bf_ssh1_cipher(EVP_CIPHER_CTX *ctx, u_char *out, const u_char *in, u_int len)
 {
@@ -441,6 +461,7 @@ bf_ssh1_cipher(EVP_CIPHER_CTX *ctx, u_char *out, const u_char *in, u_int len)
        swap_bytes(out, out, len);
        return (ret);
 }
+
 static const EVP_CIPHER *
 evp_ssh1_bf(void)
 {
@@ -449,6 +470,9 @@ evp_ssh1_bf(void)
        memcpy(&ssh1_bf, EVP_bf_cbc(), sizeof(EVP_CIPHER));
        orig_bf = ssh1_bf.do_cipher;
        ssh1_bf.nid = NID_undef;
+#ifdef SSH_OLD_EVP
+       ssh1_bf.init = bf_ssh1_init;
+#endif
        ssh1_bf.do_cipher = bf_ssh1_cipher;
        ssh1_bf.key_len = 32;
        return (&ssh1_bf);
@@ -483,6 +507,7 @@ ssh_rijndael_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
                memcpy(c->r_iv, iv, RIJNDAEL_BLOCKSIZE);
        return (1);
 }
+
 static int
 ssh_rijndael_cbc(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src,
     u_int len)
@@ -528,6 +553,7 @@ ssh_rijndael_cbc(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src,
        }
        return (1);
 }
+
 static int
 ssh_rijndael_cleanup(EVP_CIPHER_CTX *ctx)
 {
@@ -540,6 +566,7 @@ ssh_rijndael_cleanup(EVP_CIPHER_CTX *ctx)
        }
        return (1);
 }
+
 static const EVP_CIPHER *
 evp_rijndael(void)
 {
@@ -555,7 +582,7 @@ evp_rijndael(void)
        rijndal_cbc.do_cipher = ssh_rijndael_cbc;
 #ifndef SSH_OLD_EVP
        rijndal_cbc.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
-           EVP_CIPH_ALWAYS_CALL_INIT;
+           EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
 #endif
        return (&rijndal_cbc);
 }
This page took 0.038555 seconds and 4 git commands to generate.