]> andersk Git - gssapi-openssh.git/blobdiff - openssh/kex.c
merged OpenSSH 4.4p1 to trunk
[gssapi-openssh.git] / openssh / kex.c
index 59327f038516adf67056d4e7c8e4219cedfc31f9..b4685a694aff8717a60a788d7aca45efeb3cfb43 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenBSD: kex.c,v 1.76 2006/08/03 03:34:42 deraadt Exp $ */
 /*
  * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
  *
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: kex.c,v 1.65 2005/11/04 05:15:59 djm Exp $");
+
+#include <sys/param.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include <openssl/crypto.h>
 
-#include "ssh2.h"
 #include "xmalloc.h"
+#include "ssh2.h"
 #include "buffer.h"
-#include "bufaux.h"
 #include "packet.h"
 #include "compat.h"
 #include "cipher.h"
-#include "kex.h"
 #include "key.h"
+#include "kex.h"
 #include "log.h"
 #include "mac.h"
 #include "match.h"
@@ -48,6 +55,14 @@ RCSID("$OpenBSD: kex.c,v 1.65 2005/11/04 05:15:59 djm Exp $");
 
 #define KEX_COOKIE_LEN 16
 
+#if OPENSSL_VERSION_NUMBER >= 0x00907000L
+# if defined(HAVE_EVP_SHA256)
+# define evp_ssh_sha256 EVP_sha256
+# else
+extern const EVP_MD *evp_ssh_sha256(void);
+# endif
+#endif
+
 /* prototype */
 static void kex_kexinit_finish(Kex *);
 static void kex_choose_conf(Kex *);
@@ -79,7 +94,7 @@ kex_buf2prop(Buffer *raw, int *first_kex_follows)
        int i;
        char **proposal;
 
-       proposal = xmalloc(PROPOSAL_MAX * sizeof(char *));
+       proposal = xcalloc(PROPOSAL_MAX, sizeof(char *));
 
        buffer_init(&b);
        buffer_append(&b, buffer_ptr(raw), buffer_len(raw));
@@ -214,8 +229,7 @@ kex_setup(char *proposal[PROPOSAL_MAX])
 {
        Kex *kex;
 
-       kex = xmalloc(sizeof(*kex));
-       memset(kex, 0, sizeof(*kex));
+       kex = xcalloc(1, sizeof(*kex));
        buffer_init(&kex->peer);
        buffer_init(&kex->my);
        kex_prop2buf(&kex->my, proposal);
@@ -258,6 +272,7 @@ choose_enc(Enc *enc, char *client, char *server)
        enc->key_len = cipher_keylen(enc->cipher);
        enc->block_size = cipher_blocksize(enc->cipher);
 }
+
 static void
 choose_mac(Mac *mac, char *client, char *server)
 {
@@ -273,6 +288,7 @@ choose_mac(Mac *mac, char *client, char *server)
        mac->key = NULL;
        mac->enabled = 0;
 }
+
 static void
 choose_comp(Comp *comp, char *client, char *server)
 {
@@ -290,6 +306,7 @@ choose_comp(Comp *comp, char *client, char *server)
        }
        comp->name = name;
 }
+
 static void
 choose_kex(Kex *k, char *client, char *server)
 {
@@ -314,6 +331,11 @@ choose_kex(Kex *k, char *client, char *server)
            sizeof(KEX_GSS_GRP1_SHA1_ID)-1) == 0) {
                k->kex_type = KEX_GSS_GRP1_SHA1;
                k->evp_md = EVP_sha1();
+#endif
+#if OPENSSL_VERSION_NUMBER >= 0x00907000L
+       } else if (strcmp(k->name, KEX_DHGEX_SHA256) == 0) {
+               k->kex_type = KEX_DH_GEX_SHA256;
+               k->evp_md = evp_ssh_sha256();
 #endif
        } else
                fatal("bad kex alg %s", k->name);
@@ -378,8 +400,7 @@ kex_choose_conf(Kex *kex)
 
        /* Algorithm Negotiation */
        for (mode = 0; mode < MODE_MAX; mode++) {
-               newkeys = xmalloc(sizeof(*newkeys));
-               memset(newkeys, 0, sizeof(*newkeys));
+               newkeys = xcalloc(1, sizeof(*newkeys));
                kex->newkeys[mode] = newkeys;
                ctos = (!kex->server && mode == MODE_OUT) || (kex->server && mode == MODE_IN);
                nenc  = ctos ? PROPOSAL_ENC_ALGS_CTOS  : PROPOSAL_ENC_ALGS_STOC;
@@ -434,7 +455,7 @@ derive_key(Kex *kex, int id, u_int need, u_char *hash, u_int hashlen,
 
        if ((mdsz = EVP_MD_size(kex->evp_md)) <= 0)
                fatal("bad kex md size %d", mdsz);
-       digest = xmalloc(roundup(need, mdsz));
+       digest = xmalloc(roundup(need, mdsz));
 
        buffer_init(&b);
        buffer_put_bignum2(&b, shared_secret);
@@ -487,7 +508,8 @@ kex_derive_keys(Kex *kex, u_char *hash, u_int hashlen, BIGNUM *shared_secret)
        for (mode = 0; mode < MODE_MAX; mode++) {
                current_keys[mode] = kex->newkeys[mode];
                kex->newkeys[mode] = NULL;
-               ctos = (!kex->server && mode == MODE_OUT) || (kex->server && mode == MODE_IN);
+               ctos = (!kex->server && mode == MODE_OUT) ||
+                   (kex->server && mode == MODE_IN);
                current_keys[mode]->enc.iv  = keys[ctos ? 0 : 1];
                current_keys[mode]->enc.key = keys[ctos ? 2 : 3];
                current_keys[mode]->mac.key = keys[ctos ? 4 : 5];
This page took 0.041041 seconds and 4 git commands to generate.