summaryrefslogtreecommitdiff
path: root/kexgex.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2015-08-19 14:23:50 +0100
committerColin Watson <cjwatson@debian.org>2015-08-19 14:23:50 +0100
commitbaccdb349b31c47cd76fb63211f754ed33a9707e (patch)
treed03653f975fd4eb8bf71bb0c9d168614401202fa /kexgex.c
parent487bdb3a5ef6075887b830ccb8a0b14f6da78e93 (diff)
parent9f82e5a9042f2d872e98f48a876fcab3e25dd9bb (diff)
Import openssh_6.8p1.orig.tar.gz
Diffstat (limited to 'kexgex.c')
-rw-r--r--kexgex.c108
1 files changed, 56 insertions, 52 deletions
diff --git a/kexgex.c b/kexgex.c
index c2e6bc16d..8b0d83332 100644
--- a/kexgex.c
+++ b/kexgex.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexgex.c,v 1.28 2014/01/09 23:20:00 djm Exp $ */ 1/* $OpenBSD: kexgex.c,v 1.29 2015/01/19 20:16:15 markus Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2000 Niels Provos. All rights reserved.
4 * Copyright (c) 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2001 Markus Friedl. All rights reserved.
@@ -26,73 +26,77 @@
26 26
27#include "includes.h" 27#include "includes.h"
28 28
29#ifdef WITH_OPENSSL
30
29#include <sys/types.h> 31#include <sys/types.h>
30 32
31#include <openssl/evp.h> 33#include <openssl/evp.h>
32#include <signal.h> 34#include <signal.h>
33 35
34#include "buffer.h" 36#include "sshkey.h"
35#include "key.h"
36#include "cipher.h" 37#include "cipher.h"
37#include "kex.h" 38#include "kex.h"
38#include "ssh2.h" 39#include "ssh2.h"
40#include "ssherr.h"
41#include "sshbuf.h"
39#include "digest.h" 42#include "digest.h"
40#include "log.h"
41 43
42void 44int
43kexgex_hash( 45kexgex_hash(
44 int hash_alg, 46 int hash_alg,
45 char *client_version_string, 47 const char *client_version_string,
46 char *server_version_string, 48 const char *server_version_string,
47 char *ckexinit, int ckexinitlen, 49 const u_char *ckexinit, size_t ckexinitlen,
48 char *skexinit, int skexinitlen, 50 const u_char *skexinit, size_t skexinitlen,
49 u_char *serverhostkeyblob, int sbloblen, 51 const u_char *serverhostkeyblob, size_t sbloblen,
50 int min, int wantbits, int max, BIGNUM *prime, BIGNUM *gen, 52 int min, int wantbits, int max,
51 BIGNUM *client_dh_pub, 53 const BIGNUM *prime,
52 BIGNUM *server_dh_pub, 54 const BIGNUM *gen,
53 BIGNUM *shared_secret, 55 const BIGNUM *client_dh_pub,
54 u_char **hash, u_int *hashlen) 56 const BIGNUM *server_dh_pub,
57 const BIGNUM *shared_secret,
58 u_char *hash, size_t *hashlen)
55{ 59{
56 Buffer b; 60 struct sshbuf *b;
57 static u_char digest[SSH_DIGEST_MAX_LENGTH]; 61 int r;
58
59 buffer_init(&b);
60 buffer_put_cstring(&b, client_version_string);
61 buffer_put_cstring(&b, server_version_string);
62
63 /* kexinit messages: fake header: len+SSH2_MSG_KEXINIT */
64 buffer_put_int(&b, ckexinitlen+1);
65 buffer_put_char(&b, SSH2_MSG_KEXINIT);
66 buffer_append(&b, ckexinit, ckexinitlen);
67 buffer_put_int(&b, skexinitlen+1);
68 buffer_put_char(&b, SSH2_MSG_KEXINIT);
69 buffer_append(&b, skexinit, skexinitlen);
70 62
71 buffer_put_string(&b, serverhostkeyblob, sbloblen); 63 if (*hashlen < ssh_digest_bytes(SSH_DIGEST_SHA1))
72 if (min == -1 || max == -1) 64 return SSH_ERR_INVALID_ARGUMENT;
73 buffer_put_int(&b, wantbits); 65 if ((b = sshbuf_new()) == NULL)
74 else { 66 return SSH_ERR_ALLOC_FAIL;
75 buffer_put_int(&b, min); 67 if ((r = sshbuf_put_cstring(b, client_version_string)) != 0 ||
76 buffer_put_int(&b, wantbits); 68 (r = sshbuf_put_cstring(b, server_version_string)) != 0 ||
77 buffer_put_int(&b, max); 69 /* kexinit messages: fake header: len+SSH2_MSG_KEXINIT */
70 (r = sshbuf_put_u32(b, ckexinitlen+1)) != 0 ||
71 (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) != 0 ||
72 (r = sshbuf_put(b, ckexinit, ckexinitlen)) != 0 ||
73 (r = sshbuf_put_u32(b, skexinitlen+1)) != 0 ||
74 (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) != 0 ||
75 (r = sshbuf_put(b, skexinit, skexinitlen)) != 0 ||
76 (r = sshbuf_put_string(b, serverhostkeyblob, sbloblen)) != 0 ||
77 (min != -1 && (r = sshbuf_put_u32(b, min)) != 0) ||
78 (r = sshbuf_put_u32(b, wantbits)) != 0 ||
79 (max != -1 && (r = sshbuf_put_u32(b, max)) != 0) ||
80 (r = sshbuf_put_bignum2(b, prime)) != 0 ||
81 (r = sshbuf_put_bignum2(b, gen)) != 0 ||
82 (r = sshbuf_put_bignum2(b, client_dh_pub)) != 0 ||
83 (r = sshbuf_put_bignum2(b, server_dh_pub)) != 0 ||
84 (r = sshbuf_put_bignum2(b, shared_secret)) != 0) {
85 sshbuf_free(b);
86 return r;
78 } 87 }
79 buffer_put_bignum2(&b, prime);
80 buffer_put_bignum2(&b, gen);
81 buffer_put_bignum2(&b, client_dh_pub);
82 buffer_put_bignum2(&b, server_dh_pub);
83 buffer_put_bignum2(&b, shared_secret);
84
85#ifdef DEBUG_KEXDH 88#ifdef DEBUG_KEXDH
86 buffer_dump(&b); 89 sshbuf_dump(b, stderr);
87#endif
88 if (ssh_digest_buffer(hash_alg, &b, digest, sizeof(digest)) != 0)
89 fatal("%s: ssh_digest_buffer failed", __func__);
90
91 buffer_free(&b);
92
93#ifdef DEBUG_KEX
94 dump_digest("hash", digest, ssh_digest_bytes(hash_alg));
95#endif 90#endif
96 *hash = digest; 91 if (ssh_digest_buffer(hash_alg, b, hash, *hashlen) != 0) {
92 sshbuf_free(b);
93 return SSH_ERR_LIBCRYPTO_ERROR;
94 }
95 sshbuf_free(b);
97 *hashlen = ssh_digest_bytes(hash_alg); 96 *hashlen = ssh_digest_bytes(hash_alg);
97#ifdef DEBUG_KEXDH
98 dump_digest("hash", hash, *hashlen);
99#endif
100 return 0;
98} 101}
102#endif /* WITH_OPENSSL */