summaryrefslogtreecommitdiff
path: root/kex.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2005-06-17 12:59:34 +1000
committerDamien Miller <djm@mindrot.org>2005-06-17 12:59:34 +1000
commiteccb9de72aa29da5a3fad87a4287b32438689c1f (patch)
tree9b8ef20a7e454b984e0ad67b54b2bdc5577aa2fa /kex.c
parent677257fe07dd2b9a58817e1d42fc2c25bb618a4d (diff)
- djm@cvs.openbsd.org 2005/06/17 02:44:33
[auth-rsa.c auth.c auth1.c auth2-chall.c auth2-gss.c authfd.c authfile.c] [bufaux.c canohost.c channels.c cipher.c clientloop.c dns.c gss-serv.c] [kex.c kex.h key.c mac.c match.c misc.c packet.c packet.h scp.c] [servconf.c session.c session.h sftp-client.c sftp-server.c sftp.c] [ssh-keyscan.c ssh-rsa.c sshconnect.c sshconnect1.c sshconnect2.c sshd.c] make this -Wsign-compare clean; ok avsm@ markus@ NB. auth1.c changes not committed yet (conflicts with uncommitted sync) NB2. more work may be needed to make portable Wsign-compare clean
Diffstat (limited to 'kex.c')
-rw-r--r--kex.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/kex.c b/kex.c
index a668346c3..8736aa286 100644
--- a/kex.c
+++ b/kex.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: kex.c,v 1.60 2004/06/21 17:36:31 avsm Exp $"); 26RCSID("$OpenBSD: kex.c,v 1.61 2005/06/17 02:44:32 djm Exp $");
27 27
28#include <openssl/crypto.h> 28#include <openssl/crypto.h>
29 29
@@ -52,7 +52,7 @@ static void kex_choose_conf(Kex *);
52static void 52static void
53kex_prop2buf(Buffer *b, char *proposal[PROPOSAL_MAX]) 53kex_prop2buf(Buffer *b, char *proposal[PROPOSAL_MAX])
54{ 54{
55 int i; 55 u_int i;
56 56
57 buffer_clear(b); 57 buffer_clear(b);
58 /* 58 /*
@@ -101,7 +101,7 @@ kex_buf2prop(Buffer *raw, int *first_kex_follows)
101static void 101static void
102kex_prop_free(char **proposal) 102kex_prop_free(char **proposal)
103{ 103{
104 int i; 104 u_int i;
105 105
106 for (i = 0; i < PROPOSAL_MAX; i++) 106 for (i = 0; i < PROPOSAL_MAX; i++)
107 xfree(proposal[i]); 107 xfree(proposal[i]);
@@ -150,7 +150,7 @@ kex_send_kexinit(Kex *kex)
150{ 150{
151 u_int32_t rnd = 0; 151 u_int32_t rnd = 0;
152 u_char *cookie; 152 u_char *cookie;
153 int i; 153 u_int i;
154 154
155 if (kex == NULL) { 155 if (kex == NULL) {
156 error("kex_send_kexinit: no kex, cannot rekey"); 156 error("kex_send_kexinit: no kex, cannot rekey");
@@ -183,8 +183,7 @@ void
183kex_input_kexinit(int type, u_int32_t seq, void *ctxt) 183kex_input_kexinit(int type, u_int32_t seq, void *ctxt)
184{ 184{
185 char *ptr; 185 char *ptr;
186 int dlen; 186 u_int i, dlen;
187 int i;
188 Kex *kex = (Kex *)ctxt; 187 Kex *kex = (Kex *)ctxt;
189 188
190 debug("SSH2_MSG_KEXINIT received"); 189 debug("SSH2_MSG_KEXINIT received");
@@ -343,9 +342,7 @@ kex_choose_conf(Kex *kex)
343 char **my, **peer; 342 char **my, **peer;
344 char **cprop, **sprop; 343 char **cprop, **sprop;
345 int nenc, nmac, ncomp; 344 int nenc, nmac, ncomp;
346 int mode; 345 u_int mode, ctos, need;
347 int ctos; /* direction: if true client-to-server */
348 int need;
349 int first_kex_follows, type; 346 int first_kex_follows, type;
350 347
351 my = kex_buf2prop(&kex->my, NULL); 348 my = kex_buf2prop(&kex->my, NULL);
@@ -405,15 +402,19 @@ kex_choose_conf(Kex *kex)
405} 402}
406 403
407static u_char * 404static u_char *
408derive_key(Kex *kex, int id, int need, u_char *hash, BIGNUM *shared_secret) 405derive_key(Kex *kex, int id, u_int need, u_char *hash, BIGNUM *shared_secret)
409{ 406{
410 Buffer b; 407 Buffer b;
411 const EVP_MD *evp_md = EVP_sha1(); 408 const EVP_MD *evp_md = EVP_sha1();
412 EVP_MD_CTX md; 409 EVP_MD_CTX md;
413 char c = id; 410 char c = id;
414 int have; 411 u_int have;
415 int mdsz = EVP_MD_size(evp_md); 412 int mdsz = EVP_MD_size(evp_md);
416 u_char *digest = xmalloc(roundup(need, mdsz)); 413 u_char *digest;
414
415 if (mdsz < 0)
416 fatal("derive_key: mdsz < 0");
417 digest = xmalloc(roundup(need, mdsz));
417 418
418 buffer_init(&b); 419 buffer_init(&b);
419 buffer_put_bignum2(&b, shared_secret); 420 buffer_put_bignum2(&b, shared_secret);
@@ -455,7 +456,7 @@ void
455kex_derive_keys(Kex *kex, u_char *hash, BIGNUM *shared_secret) 456kex_derive_keys(Kex *kex, u_char *hash, BIGNUM *shared_secret)
456{ 457{
457 u_char *keys[NKEYS]; 458 u_char *keys[NKEYS];
458 int i, mode, ctos; 459 u_int i, mode, ctos;
459 460
460 for (i = 0; i < NKEYS; i++) 461 for (i = 0; i < NKEYS; i++)
461 keys[i] = derive_key(kex, 'A'+i, kex->we_need, hash, shared_secret); 462 keys[i] = derive_key(kex, 'A'+i, kex->we_need, hash, shared_secret);
@@ -493,13 +494,13 @@ derive_ssh1_session_id(BIGNUM *host_modulus, BIGNUM *server_modulus,
493 EVP_DigestInit(&md, evp_md); 494 EVP_DigestInit(&md, evp_md);
494 495
495 len = BN_num_bytes(host_modulus); 496 len = BN_num_bytes(host_modulus);
496 if (len < (512 / 8) || len > sizeof(nbuf)) 497 if (len < (512 / 8) || (u_int)len > sizeof(nbuf))
497 fatal("%s: bad host modulus (len %d)", __func__, len); 498 fatal("%s: bad host modulus (len %d)", __func__, len);
498 BN_bn2bin(host_modulus, nbuf); 499 BN_bn2bin(host_modulus, nbuf);
499 EVP_DigestUpdate(&md, nbuf, len); 500 EVP_DigestUpdate(&md, nbuf, len);
500 501
501 len = BN_num_bytes(server_modulus); 502 len = BN_num_bytes(server_modulus);
502 if (len < (512 / 8) || len > sizeof(nbuf)) 503 if (len < (512 / 8) || (u_int)len > sizeof(nbuf))
503 fatal("%s: bad server modulus (len %d)", __func__, len); 504 fatal("%s: bad server modulus (len %d)", __func__, len);
504 BN_bn2bin(server_modulus, nbuf); 505 BN_bn2bin(server_modulus, nbuf);
505 EVP_DigestUpdate(&md, nbuf, len); 506 EVP_DigestUpdate(&md, nbuf, len);
@@ -518,7 +519,7 @@ derive_ssh1_session_id(BIGNUM *host_modulus, BIGNUM *server_modulus,
518void 519void
519dump_digest(char *msg, u_char *digest, int len) 520dump_digest(char *msg, u_char *digest, int len)
520{ 521{
521 int i; 522 u_int i;
522 523
523 fprintf(stderr, "%s\n", msg); 524 fprintf(stderr, "%s\n", msg);
524 for (i = 0; i< len; i++) { 525 for (i = 0; i< len; i++) {