1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Reindent the section that was marked `XXX The lines below should be

reindented before this is committed'. Unfortunately not before it
was committed, but you can't have everything :-)

[originally from svn r7499]
This commit is contained in:
Simon Tatham 2007-05-01 12:26:44 +00:00
parent dad558a1e5
commit 723d834a13

192
ssh.c
View File

@ -5573,112 +5573,110 @@ static int do_ssh2_transport(Ssh ssh, void *vin, int inlen,
}
if (ssh->kex->main_type == KEXTYPE_DH) {
/* XXX The lines below should be reindented before this is committed.*/
/*
* Work out the number of bits of key we will need from the key
* exchange. We start with the maximum key length of either
* cipher...
*/
{
int csbits, scbits;
/*
* Work out the number of bits of key we will need from the
* key exchange. We start with the maximum key length of
* either cipher...
*/
{
int csbits, scbits;
csbits = s->cscipher_tobe->keylen;
scbits = s->sccipher_tobe->keylen;
s->nbits = (csbits > scbits ? csbits : scbits);
}
/* The keys only have hlen-bit entropy, since they're based on
* a hash. So cap the key size at hlen bits. */
if (s->nbits > ssh->kex->hash->hlen * 8)
s->nbits = ssh->kex->hash->hlen * 8;
csbits = s->cscipher_tobe->keylen;
scbits = s->sccipher_tobe->keylen;
s->nbits = (csbits > scbits ? csbits : scbits);
}
/* The keys only have hlen-bit entropy, since they're based on
* a hash. So cap the key size at hlen bits. */
if (s->nbits > ssh->kex->hash->hlen * 8)
s->nbits = ssh->kex->hash->hlen * 8;
/*
* If we're doing Diffie-Hellman group exchange, start by
* requesting a group.
*/
if (!ssh->kex->pdata) {
logevent("Doing Diffie-Hellman group exchange");
ssh->pkt_ctx |= SSH2_PKTCTX_DHGEX;
/*
* Work out how big a DH group we will need to allow that
* much data.
*/
s->pbits = 512 << ((s->nbits - 1) / 64);
s->pktout = ssh2_pkt_init(SSH2_MSG_KEX_DH_GEX_REQUEST);
ssh2_pkt_adduint32(s->pktout, s->pbits);
ssh2_pkt_send_noqueue(ssh, s->pktout);
/*
* If we're doing Diffie-Hellman group exchange, start by
* requesting a group.
*/
if (!ssh->kex->pdata) {
logevent("Doing Diffie-Hellman group exchange");
ssh->pkt_ctx |= SSH2_PKTCTX_DHGEX;
/*
* Work out how big a DH group we will need to allow that
* much data.
*/
s->pbits = 512 << ((s->nbits - 1) / 64);
s->pktout = ssh2_pkt_init(SSH2_MSG_KEX_DH_GEX_REQUEST);
ssh2_pkt_adduint32(s->pktout, s->pbits);
ssh2_pkt_send_noqueue(ssh, s->pktout);
crWaitUntil(pktin);
if (pktin->type != SSH2_MSG_KEX_DH_GEX_GROUP) {
bombout(("expected key exchange group packet from server"));
crStop(0);
}
s->p = ssh2_pkt_getmp(pktin);
s->g = ssh2_pkt_getmp(pktin);
if (!s->p || !s->g) {
bombout(("unable to read mp-ints from incoming group packet"));
crStop(0);
}
ssh->kex_ctx = dh_setup_gex(s->p, s->g);
s->kex_init_value = SSH2_MSG_KEX_DH_GEX_INIT;
s->kex_reply_value = SSH2_MSG_KEX_DH_GEX_REPLY;
} else {
ssh->pkt_ctx |= SSH2_PKTCTX_DHGROUP;
ssh->kex_ctx = dh_setup_group(ssh->kex);
s->kex_init_value = SSH2_MSG_KEXDH_INIT;
s->kex_reply_value = SSH2_MSG_KEXDH_REPLY;
logeventf(ssh, "Using Diffie-Hellman with standard group \"%s\"",
ssh->kex->groupname);
}
crWaitUntil(pktin);
if (pktin->type != SSH2_MSG_KEX_DH_GEX_GROUP) {
bombout(("expected key exchange group packet from server"));
crStop(0);
}
s->p = ssh2_pkt_getmp(pktin);
s->g = ssh2_pkt_getmp(pktin);
if (!s->p || !s->g) {
bombout(("unable to read mp-ints from incoming group packet"));
crStop(0);
}
ssh->kex_ctx = dh_setup_gex(s->p, s->g);
s->kex_init_value = SSH2_MSG_KEX_DH_GEX_INIT;
s->kex_reply_value = SSH2_MSG_KEX_DH_GEX_REPLY;
} else {
ssh->pkt_ctx |= SSH2_PKTCTX_DHGROUP;
ssh->kex_ctx = dh_setup_group(ssh->kex);
s->kex_init_value = SSH2_MSG_KEXDH_INIT;
s->kex_reply_value = SSH2_MSG_KEXDH_REPLY;
logeventf(ssh, "Using Diffie-Hellman with standard group \"%s\"",
ssh->kex->groupname);
}
logeventf(ssh, "Doing Diffie-Hellman key exchange with hash %s",
ssh->kex->hash->text_name);
/*
* Now generate and send e for Diffie-Hellman.
*/
set_busy_status(ssh->frontend, BUSY_CPU); /* this can take a while */
s->e = dh_create_e(ssh->kex_ctx, s->nbits * 2);
s->pktout = ssh2_pkt_init(s->kex_init_value);
ssh2_pkt_addmp(s->pktout, s->e);
ssh2_pkt_send_noqueue(ssh, s->pktout);
logeventf(ssh, "Doing Diffie-Hellman key exchange with hash %s",
ssh->kex->hash->text_name);
/*
* Now generate and send e for Diffie-Hellman.
*/
set_busy_status(ssh->frontend, BUSY_CPU); /* this can take a while */
s->e = dh_create_e(ssh->kex_ctx, s->nbits * 2);
s->pktout = ssh2_pkt_init(s->kex_init_value);
ssh2_pkt_addmp(s->pktout, s->e);
ssh2_pkt_send_noqueue(ssh, s->pktout);
set_busy_status(ssh->frontend, BUSY_WAITING); /* wait for server */
crWaitUntil(pktin);
if (pktin->type != s->kex_reply_value) {
bombout(("expected key exchange reply packet from server"));
crStop(0);
}
set_busy_status(ssh->frontend, BUSY_CPU); /* cogitate */
ssh_pkt_getstring(pktin, &s->hostkeydata, &s->hostkeylen);
s->hkey = ssh->hostkey->newkey(s->hostkeydata, s->hostkeylen);
s->f = ssh2_pkt_getmp(pktin);
if (!s->f) {
bombout(("unable to parse key exchange reply packet"));
crStop(0);
}
ssh_pkt_getstring(pktin, &s->sigdata, &s->siglen);
set_busy_status(ssh->frontend, BUSY_WAITING); /* wait for server */
crWaitUntil(pktin);
if (pktin->type != s->kex_reply_value) {
bombout(("expected key exchange reply packet from server"));
crStop(0);
}
set_busy_status(ssh->frontend, BUSY_CPU); /* cogitate */
ssh_pkt_getstring(pktin, &s->hostkeydata, &s->hostkeylen);
s->hkey = ssh->hostkey->newkey(s->hostkeydata, s->hostkeylen);
s->f = ssh2_pkt_getmp(pktin);
if (!s->f) {
bombout(("unable to parse key exchange reply packet"));
crStop(0);
}
ssh_pkt_getstring(pktin, &s->sigdata, &s->siglen);
s->K = dh_find_K(ssh->kex_ctx, s->f);
s->K = dh_find_K(ssh->kex_ctx, s->f);
/* We assume everything from now on will be quick, and it might
* involve user interaction. */
set_busy_status(ssh->frontend, BUSY_NOT);
/* We assume everything from now on will be quick, and it might
* involve user interaction. */
set_busy_status(ssh->frontend, BUSY_NOT);
hash_string(ssh->kex->hash, ssh->exhash, s->hostkeydata, s->hostkeylen);
if (!ssh->kex->pdata) {
hash_uint32(ssh->kex->hash, ssh->exhash, s->pbits);
hash_mpint(ssh->kex->hash, ssh->exhash, s->p);
hash_mpint(ssh->kex->hash, ssh->exhash, s->g);
}
hash_mpint(ssh->kex->hash, ssh->exhash, s->e);
hash_mpint(ssh->kex->hash, ssh->exhash, s->f);
hash_string(ssh->kex->hash, ssh->exhash, s->hostkeydata, s->hostkeylen);
if (!ssh->kex->pdata) {
hash_uint32(ssh->kex->hash, ssh->exhash, s->pbits);
hash_mpint(ssh->kex->hash, ssh->exhash, s->p);
hash_mpint(ssh->kex->hash, ssh->exhash, s->g);
}
hash_mpint(ssh->kex->hash, ssh->exhash, s->e);
hash_mpint(ssh->kex->hash, ssh->exhash, s->f);
dh_cleanup(ssh->kex_ctx);
freebn(s->f);
if (!ssh->kex->pdata) {
freebn(s->g);
freebn(s->p);
}
/* XXX end incorrectly-indented section */
dh_cleanup(ssh->kex_ctx);
freebn(s->f);
if (!ssh->kex->pdata) {
freebn(s->g);
freebn(s->p);
}
} else {
logeventf(ssh, "Doing RSA key exchange with hash %s",
ssh->kex->hash->text_name);