summaryrefslogtreecommitdiff
path: root/kexdh.c
diff options
context:
space:
mode:
authormarkus@openbsd.org <markus@openbsd.org>2015-01-19 20:16:15 +0000
committerDamien Miller <djm@mindrot.org>2015-01-20 09:19:39 +1100
commit57d10cbe861a235dd269c74fb2fe248469ecee9d (patch)
treec65deed24700490bd3b20300c4829d4d5466ff6d /kexdh.c
parent3fdc88a0def4f86aa88a5846ac079dc964c0546a (diff)
upstream commit
adapt kex to sshbuf and struct ssh; ok djm@
Diffstat (limited to 'kexdh.c')
-rw-r--r--kexdh.c87
1 files changed, 45 insertions, 42 deletions
diff --git a/kexdh.c b/kexdh.c
index 2c1dfb6f5..feea6697d 100644
--- a/kexdh.c
+++ b/kexdh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexdh.c,v 1.24 2014/01/09 23:20:00 djm Exp $ */ 1/* $OpenBSD: kexdh.c,v 1.25 2015/01/19 20:16:15 markus Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -33,58 +33,61 @@
33 33
34#include <openssl/evp.h> 34#include <openssl/evp.h>
35 35
36#include "buffer.h"
37#include "ssh2.h" 36#include "ssh2.h"
38#include "key.h" 37#include "sshkey.h"
39#include "cipher.h" 38#include "cipher.h"
40#include "kex.h" 39#include "kex.h"
40#include "ssherr.h"
41#include "sshbuf.h"
41#include "digest.h" 42#include "digest.h"
42#include "log.h"
43 43
44void 44int
45kex_dh_hash( 45kex_dh_hash(
46 char *client_version_string, 46 const char *client_version_string,
47 char *server_version_string, 47 const char *server_version_string,
48 char *ckexinit, int ckexinitlen, 48 const u_char *ckexinit, size_t ckexinitlen,
49 char *skexinit, int skexinitlen, 49 const u_char *skexinit, size_t skexinitlen,
50 u_char *serverhostkeyblob, int sbloblen, 50 const u_char *serverhostkeyblob, size_t sbloblen,
51 BIGNUM *client_dh_pub, 51 const BIGNUM *client_dh_pub,
52 BIGNUM *server_dh_pub, 52 const BIGNUM *server_dh_pub,
53 BIGNUM *shared_secret, 53 const BIGNUM *shared_secret,
54 u_char **hash, u_int *hashlen) 54 u_char *hash, size_t *hashlen)
55{ 55{
56 Buffer b; 56 struct sshbuf *b;
57 static u_char digest[SSH_DIGEST_MAX_LENGTH]; 57 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
71 buffer_put_string(&b, serverhostkeyblob, sbloblen);
72 buffer_put_bignum2(&b, client_dh_pub);
73 buffer_put_bignum2(&b, server_dh_pub);
74 buffer_put_bignum2(&b, shared_secret);
75 58
59 if (*hashlen < ssh_digest_bytes(SSH_DIGEST_SHA1))
60 return SSH_ERR_INVALID_ARGUMENT;
61 if ((b = sshbuf_new()) == NULL)
62 return SSH_ERR_ALLOC_FAIL;
63 if ((r = sshbuf_put_cstring(b, client_version_string)) != 0 ||
64 (r = sshbuf_put_cstring(b, server_version_string)) != 0 ||
65 /* kexinit messages: fake header: len+SSH2_MSG_KEXINIT */
66 (r = sshbuf_put_u32(b, ckexinitlen+1)) != 0 ||
67 (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) != 0 ||
68 (r = sshbuf_put(b, ckexinit, ckexinitlen)) != 0 ||
69 (r = sshbuf_put_u32(b, skexinitlen+1)) != 0 ||
70 (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) != 0 ||
71 (r = sshbuf_put(b, skexinit, skexinitlen)) != 0 ||
72 (r = sshbuf_put_string(b, serverhostkeyblob, sbloblen)) != 0 ||
73 (r = sshbuf_put_bignum2(b, client_dh_pub)) != 0 ||
74 (r = sshbuf_put_bignum2(b, server_dh_pub)) != 0 ||
75 (r = sshbuf_put_bignum2(b, shared_secret)) != 0) {
76 sshbuf_free(b);
77 return r;
78 }
76#ifdef DEBUG_KEX 79#ifdef DEBUG_KEX
77 buffer_dump(&b); 80 sshbuf_dump(b, stderr);
78#endif 81#endif
79 if (ssh_digest_buffer(SSH_DIGEST_SHA1, &b, digest, sizeof(digest)) != 0) 82 if (ssh_digest_buffer(SSH_DIGEST_SHA1, b, hash, *hashlen) != 0) {
80 fatal("%s: ssh_digest_buffer failed", __func__); 83 sshbuf_free(b);
81 84 return SSH_ERR_LIBCRYPTO_ERROR;
82 buffer_free(&b); 85 }
83 86 sshbuf_free(b);
87 *hashlen = ssh_digest_bytes(SSH_DIGEST_SHA1);
84#ifdef DEBUG_KEX 88#ifdef DEBUG_KEX
85 dump_digest("hash", digest, ssh_digest_bytes(SSH_DIGEST_SHA1)); 89 dump_digest("hash", hash, *hashlen);
86#endif 90#endif
87 *hash = digest; 91 return 0;
88 *hashlen = ssh_digest_bytes(SSH_DIGEST_SHA1);
89} 92}
90#endif /* WITH_OPENSSL */ 93#endif /* WITH_OPENSSL */