De-duplicate code in KEXINIT generation.
authorben <ben@cda61777-01e9-0310-a592-d414129be87e>
Tue, 21 Aug 2012 22:33:31 +0000 (22:33 +0000)
committerben <ben@cda61777-01e9-0310-a592-d414129be87e>
Tue, 21 Aug 2012 22:33:31 +0000 (22:33 +0000)
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.

git-svn-id: svn://svn.tartarus.org/sgt/putty@9610 cda61777-01e9-0310-a592-d414129be87e

ssh.c

diff --git a/ssh.c b/ssh.c
index ae49ba1..439f115 100644 (file)
--- a/ssh.c
+++ b/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.) */