mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
De-duplicate code in KEXINIT generation.
There's no need to have identical code generating server-to-client and client-to-server versions of the cipher and MAC lists; a couple of twice-around loops will do fine. [originally from svn r9610]
This commit is contained in:
parent
8e0ab8be59
commit
e148dd97e3
56
ssh.c
56
ssh.c
@ -5533,7 +5533,7 @@ static int do_ssh2_transport(Ssh ssh, void *vin, int inlen,
|
||||
begin_key_exchange:
|
||||
ssh->pkt_kctx = SSH2_PKTCTX_NOKEX;
|
||||
{
|
||||
int i, j, commalist_started;
|
||||
int i, j, k, commalist_started;
|
||||
|
||||
/*
|
||||
* Set up the preferred key exchange. (NULL => warn below here)
|
||||
@ -5645,46 +5645,30 @@ static int do_ssh2_transport(Ssh ssh, void *vin, int inlen,
|
||||
if (i < lenof(hostkey_algs) - 1)
|
||||
ssh2_pkt_addstring_str(s->pktout, ",");
|
||||
}
|
||||
/* List client->server encryption algorithms. */
|
||||
ssh2_pkt_addstring_start(s->pktout);
|
||||
commalist_started = 0;
|
||||
for (i = 0; i < s->n_preferred_ciphers; i++) {
|
||||
const struct ssh2_ciphers *c = s->preferred_ciphers[i];
|
||||
if (!c) continue; /* warning flag */
|
||||
for (j = 0; j < c->nciphers; j++) {
|
||||
if (commalist_started)
|
||||
ssh2_pkt_addstring_str(s->pktout, ",");
|
||||
ssh2_pkt_addstring_str(s->pktout, c->list[j]->name);
|
||||
commalist_started = 1;
|
||||
/* List encryption algorithms (client->server then server->client). */
|
||||
for (k = 0; k < 2; k++) {
|
||||
ssh2_pkt_addstring_start(s->pktout);
|
||||
commalist_started = 0;
|
||||
for (i = 0; i < s->n_preferred_ciphers; i++) {
|
||||
const struct ssh2_ciphers *c = s->preferred_ciphers[i];
|
||||
if (!c) continue; /* warning flag */
|
||||
for (j = 0; j < c->nciphers; j++) {
|
||||
if (commalist_started)
|
||||
ssh2_pkt_addstring_str(s->pktout, ",");
|
||||
ssh2_pkt_addstring_str(s->pktout, c->list[j]->name);
|
||||
commalist_started = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* List server->client encryption algorithms. */
|
||||
ssh2_pkt_addstring_start(s->pktout);
|
||||
commalist_started = 0;
|
||||
for (i = 0; i < s->n_preferred_ciphers; i++) {
|
||||
const struct ssh2_ciphers *c = s->preferred_ciphers[i];
|
||||
if (!c) continue; /* warning flag */
|
||||
for (j = 0; j < c->nciphers; j++) {
|
||||
if (commalist_started)
|
||||
/* List MAC algorithms (client->server then server->client). */
|
||||
for (j = 0; j < 2; j++) {
|
||||
ssh2_pkt_addstring_start(s->pktout);
|
||||
for (i = 0; i < s->nmacs; i++) {
|
||||
ssh2_pkt_addstring_str(s->pktout, s->maclist[i]->name);
|
||||
if (i < s->nmacs - 1)
|
||||
ssh2_pkt_addstring_str(s->pktout, ",");
|
||||
ssh2_pkt_addstring_str(s->pktout, c->list[j]->name);
|
||||
commalist_started = 1;
|
||||
}
|
||||
}
|
||||
/* List client->server MAC algorithms. */
|
||||
ssh2_pkt_addstring_start(s->pktout);
|
||||
for (i = 0; i < s->nmacs; i++) {
|
||||
ssh2_pkt_addstring_str(s->pktout, s->maclist[i]->name);
|
||||
if (i < s->nmacs - 1)
|
||||
ssh2_pkt_addstring_str(s->pktout, ",");
|
||||
}
|
||||
/* List server->client MAC algorithms. */
|
||||
ssh2_pkt_addstring_start(s->pktout);
|
||||
for (i = 0; i < s->nmacs; i++) {
|
||||
ssh2_pkt_addstring_str(s->pktout, s->maclist[i]->name);
|
||||
if (i < s->nmacs - 1)
|
||||
ssh2_pkt_addstring_str(s->pktout, ",");
|
||||
}
|
||||
/* List client->server compression algorithms,
|
||||
* then server->client compression algorithms. (We use the
|
||||
* same set twice.) */
|
||||
|
Loading…
Reference in New Issue
Block a user