diff options
author | markus@openbsd.org <markus@openbsd.org> | 2015-01-19 20:16:15 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2015-01-20 09:19:39 +1100 |
commit | 57d10cbe861a235dd269c74fb2fe248469ecee9d (patch) | |
tree | c65deed24700490bd3b20300c4829d4d5466ff6d /kexgex.c | |
parent | 3fdc88a0def4f86aa88a5846ac079dc964c0546a (diff) |
upstream commit
adapt kex to sshbuf and struct ssh; ok djm@
Diffstat (limited to 'kexgex.c')
-rw-r--r-- | kexgex.c | 105 |
1 files changed, 53 insertions, 52 deletions
@@ -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. |
@@ -33,69 +33,70 @@ | |||
33 | #include <openssl/evp.h> | 33 | #include <openssl/evp.h> |
34 | #include <signal.h> | 34 | #include <signal.h> |
35 | 35 | ||
36 | #include "buffer.h" | 36 | #include "sshkey.h" |
37 | #include "key.h" | ||
38 | #include "cipher.h" | 37 | #include "cipher.h" |
39 | #include "kex.h" | 38 | #include "kex.h" |
40 | #include "ssh2.h" | 39 | #include "ssh2.h" |
40 | #include "ssherr.h" | ||
41 | #include "sshbuf.h" | ||
41 | #include "digest.h" | 42 | #include "digest.h" |
42 | #include "log.h" | ||
43 | 43 | ||
44 | void | 44 | int |
45 | kexgex_hash( | 45 | kexgex_hash( |
46 | int hash_alg, | 46 | int hash_alg, |
47 | char *client_version_string, | 47 | const char *client_version_string, |
48 | char *server_version_string, | 48 | const char *server_version_string, |
49 | char *ckexinit, int ckexinitlen, | 49 | const u_char *ckexinit, size_t ckexinitlen, |
50 | char *skexinit, int skexinitlen, | 50 | const u_char *skexinit, size_t skexinitlen, |
51 | u_char *serverhostkeyblob, int sbloblen, | 51 | const u_char *serverhostkeyblob, size_t sbloblen, |
52 | int min, int wantbits, int max, BIGNUM *prime, BIGNUM *gen, | 52 | int min, int wantbits, int max, |
53 | BIGNUM *client_dh_pub, | 53 | const BIGNUM *prime, |
54 | BIGNUM *server_dh_pub, | 54 | const BIGNUM *gen, |
55 | BIGNUM *shared_secret, | 55 | const BIGNUM *client_dh_pub, |
56 | u_char **hash, u_int *hashlen) | 56 | const BIGNUM *server_dh_pub, |
57 | const BIGNUM *shared_secret, | ||
58 | u_char *hash, size_t *hashlen) | ||
57 | { | 59 | { |
58 | Buffer b; | 60 | struct sshbuf *b; |
59 | static u_char digest[SSH_DIGEST_MAX_LENGTH]; | 61 | int r; |
60 | 62 | ||
61 | buffer_init(&b); | 63 | if (*hashlen < ssh_digest_bytes(SSH_DIGEST_SHA1)) |
62 | buffer_put_cstring(&b, client_version_string); | 64 | return SSH_ERR_INVALID_ARGUMENT; |
63 | buffer_put_cstring(&b, server_version_string); | 65 | if ((b = sshbuf_new()) == NULL) |
64 | 66 | return SSH_ERR_ALLOC_FAIL; | |
65 | /* kexinit messages: fake header: len+SSH2_MSG_KEXINIT */ | 67 | if ((r = sshbuf_put_cstring(b, client_version_string)) != 0 || |
66 | buffer_put_int(&b, ckexinitlen+1); | 68 | (r = sshbuf_put_cstring(b, server_version_string)) != 0 || |
67 | buffer_put_char(&b, SSH2_MSG_KEXINIT); | 69 | /* kexinit messages: fake header: len+SSH2_MSG_KEXINIT */ |
68 | buffer_append(&b, ckexinit, ckexinitlen); | 70 | (r = sshbuf_put_u32(b, ckexinitlen+1)) != 0 || |
69 | buffer_put_int(&b, skexinitlen+1); | 71 | (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) != 0 || |
70 | buffer_put_char(&b, SSH2_MSG_KEXINIT); | 72 | (r = sshbuf_put(b, ckexinit, ckexinitlen)) != 0 || |
71 | buffer_append(&b, skexinit, skexinitlen); | 73 | (r = sshbuf_put_u32(b, skexinitlen+1)) != 0 || |
72 | 74 | (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) != 0 || | |
73 | buffer_put_string(&b, serverhostkeyblob, sbloblen); | 75 | (r = sshbuf_put(b, skexinit, skexinitlen)) != 0 || |
74 | if (min == -1 || max == -1) | 76 | (r = sshbuf_put_string(b, serverhostkeyblob, sbloblen)) != 0 || |
75 | buffer_put_int(&b, wantbits); | 77 | (min != -1 && (r = sshbuf_put_u32(b, min)) != 0) || |
76 | else { | 78 | (r = sshbuf_put_u32(b, wantbits)) != 0 || |
77 | buffer_put_int(&b, min); | 79 | (max != -1 && (r = sshbuf_put_u32(b, max)) != 0) || |
78 | buffer_put_int(&b, wantbits); | 80 | (r = sshbuf_put_bignum2(b, prime)) != 0 || |
79 | buffer_put_int(&b, max); | 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; | ||
80 | } | 87 | } |
81 | buffer_put_bignum2(&b, prime); | ||
82 | buffer_put_bignum2(&b, gen); | ||
83 | buffer_put_bignum2(&b, client_dh_pub); | ||
84 | buffer_put_bignum2(&b, server_dh_pub); | ||
85 | buffer_put_bignum2(&b, shared_secret); | ||
86 | |||
87 | #ifdef DEBUG_KEXDH | 88 | #ifdef DEBUG_KEXDH |
88 | buffer_dump(&b); | 89 | sshbuf_dump(b, stderr); |
89 | #endif | 90 | #endif |
90 | if (ssh_digest_buffer(hash_alg, &b, digest, sizeof(digest)) != 0) | 91 | if (ssh_digest_buffer(hash_alg, b, hash, *hashlen) != 0) { |
91 | fatal("%s: ssh_digest_buffer failed", __func__); | 92 | sshbuf_free(b); |
92 | 93 | return SSH_ERR_LIBCRYPTO_ERROR; | |
93 | buffer_free(&b); | 94 | } |
94 | 95 | sshbuf_free(b); | |
95 | #ifdef DEBUG_KEX | ||
96 | dump_digest("hash", digest, ssh_digest_bytes(hash_alg)); | ||
97 | #endif | ||
98 | *hash = digest; | ||
99 | *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; | ||
100 | } | 101 | } |
101 | #endif /* WITH_OPENSSL */ | 102 | #endif /* WITH_OPENSSL */ |