[BACK]Return to kex.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/kex.c between version 1.60 and 1.60.4.2

version 1.60, 2004/06/21 17:36:31 version 1.60.4.2, 2006/02/03 02:53:44
Line 52 
Line 52 
 static void  static void
 kex_prop2buf(Buffer *b, char *proposal[PROPOSAL_MAX])  kex_prop2buf(Buffer *b, char *proposal[PROPOSAL_MAX])
 {  {
         int i;          u_int i;
   
         buffer_clear(b);          buffer_clear(b);
         /*          /*
Line 101 
Line 101 
 static void  static void
 kex_prop_free(char **proposal)  kex_prop_free(char **proposal)
 {  {
         int i;          u_int i;
   
         for (i = 0; i < PROPOSAL_MAX; i++)          for (i = 0; i < PROPOSAL_MAX; i++)
                 xfree(proposal[i]);                  xfree(proposal[i]);
Line 150 
Line 150 
 {  {
         u_int32_t rnd = 0;          u_int32_t rnd = 0;
         u_char *cookie;          u_char *cookie;
         int i;          u_int i;
   
         if (kex == NULL) {          if (kex == NULL) {
                 error("kex_send_kexinit: no kex, cannot rekey");                  error("kex_send_kexinit: no kex, cannot rekey");
Line 183 
Line 183 
 kex_input_kexinit(int type, u_int32_t seq, void *ctxt)  kex_input_kexinit(int type, u_int32_t seq, void *ctxt)
 {  {
         char *ptr;          char *ptr;
         int dlen;          u_int i, dlen;
         int i;  
         Kex *kex = (Kex *)ctxt;          Kex *kex = (Kex *)ctxt;
   
         debug("SSH2_MSG_KEXINIT received");          debug("SSH2_MSG_KEXINIT received");
Line 276 
Line 275 
         char *name = match_list(client, server, NULL);          char *name = match_list(client, server, NULL);
         if (name == NULL)          if (name == NULL)
                 fatal("no matching comp found: client %s server %s", client, server);                  fatal("no matching comp found: client %s server %s", client, server);
         if (strcmp(name, "zlib") == 0) {          if (strcmp(name, "zlib@openssh.com") == 0) {
                 comp->type = 1;                  comp->type = COMP_DELAYED;
           } else if (strcmp(name, "zlib") == 0) {
                   comp->type = COMP_ZLIB;
         } else if (strcmp(name, "none") == 0) {          } else if (strcmp(name, "none") == 0) {
                 comp->type = 0;                  comp->type = COMP_NONE;
         } else {          } else {
                 fatal("unsupported comp %s", name);                  fatal("unsupported comp %s", name);
         }          }
Line 293 
Line 294 
                 fatal("no kex alg");                  fatal("no kex alg");
         if (strcmp(k->name, KEX_DH1) == 0) {          if (strcmp(k->name, KEX_DH1) == 0) {
                 k->kex_type = KEX_DH_GRP1_SHA1;                  k->kex_type = KEX_DH_GRP1_SHA1;
                   k->evp_md = EVP_sha1();
         } else if (strcmp(k->name, KEX_DH14) == 0) {          } else if (strcmp(k->name, KEX_DH14) == 0) {
                 k->kex_type = KEX_DH_GRP14_SHA1;                  k->kex_type = KEX_DH_GRP14_SHA1;
         } else if (strcmp(k->name, KEX_DHGEX) == 0) {                  k->evp_md = EVP_sha1();
           } else if (strcmp(k->name, KEX_DHGEX_SHA1) == 0) {
                 k->kex_type = KEX_DH_GEX_SHA1;                  k->kex_type = KEX_DH_GEX_SHA1;
                   k->evp_md = EVP_sha1();
         } else          } else
                 fatal("bad kex alg %s", k->name);                  fatal("bad kex alg %s", k->name);
 }  }
   
 static void  static void
 choose_hostkeyalg(Kex *k, char *client, char *server)  choose_hostkeyalg(Kex *k, char *client, char *server)
 {  {
Line 343 
Line 348 
         char **my, **peer;          char **my, **peer;
         char **cprop, **sprop;          char **cprop, **sprop;
         int nenc, nmac, ncomp;          int nenc, nmac, ncomp;
         int mode;          u_int mode, ctos, need;
         int ctos;                               /* direction: if true client-to-server */  
         int need;  
         int first_kex_follows, type;          int first_kex_follows, type;
   
         my   = kex_buf2prop(&kex->my, NULL);          my   = kex_buf2prop(&kex->my, NULL);
Line 395 
Line 398 
   
         /* ignore the next message if the proposals do not match */          /* ignore the next message if the proposals do not match */
         if (first_kex_follows && !proposals_match(my, peer) &&          if (first_kex_follows && !proposals_match(my, peer) &&
            !(datafellows & SSH_BUG_FIRSTKEX)) {              !(datafellows & SSH_BUG_FIRSTKEX)) {
                 type = packet_read();                  type = packet_read();
                 debug2("skipping next packet (type %u)", type);                  debug2("skipping next packet (type %u)", type);
         }          }
Line 405 
Line 408 
 }  }
   
 static u_char *  static u_char *
 derive_key(Kex *kex, int id, int need, u_char *hash, BIGNUM *shared_secret)  derive_key(Kex *kex, int id, u_int need, u_char *hash, u_int hashlen,
       BIGNUM *shared_secret)
 {  {
         Buffer b;          Buffer b;
         const EVP_MD *evp_md = EVP_sha1();  
         EVP_MD_CTX md;          EVP_MD_CTX md;
         char c = id;          char c = id;
         int have;          u_int have;
         int mdsz = EVP_MD_size(evp_md);          int mdsz;
         u_char *digest = xmalloc(roundup(need, mdsz));          u_char *digest;
   
           if ((mdsz = EVP_MD_size(kex->evp_md)) <= 0)
                   fatal("bad kex md size %d", mdsz);
           digest = xmalloc(roundup(need, mdsz));
   
         buffer_init(&b);          buffer_init(&b);
         buffer_put_bignum2(&b, shared_secret);          buffer_put_bignum2(&b, shared_secret);
   
         /* K1 = HASH(K || H || "A" || session_id) */          /* K1 = HASH(K || H || "A" || session_id) */
         EVP_DigestInit(&md, evp_md);          EVP_DigestInit(&md, kex->evp_md);
         if (!(datafellows & SSH_BUG_DERIVEKEY))          if (!(datafellows & SSH_BUG_DERIVEKEY))
                 EVP_DigestUpdate(&md, buffer_ptr(&b), buffer_len(&b));                  EVP_DigestUpdate(&md, buffer_ptr(&b), buffer_len(&b));
         EVP_DigestUpdate(&md, hash, mdsz);          EVP_DigestUpdate(&md, hash, hashlen);
         EVP_DigestUpdate(&md, &c, 1);          EVP_DigestUpdate(&md, &c, 1);
         EVP_DigestUpdate(&md, kex->session_id, kex->session_id_len);          EVP_DigestUpdate(&md, kex->session_id, kex->session_id_len);
         EVP_DigestFinal(&md, digest, NULL);          EVP_DigestFinal(&md, digest, NULL);
Line 433 
Line 440 
          * Key = K1 || K2 || ... || Kn           * Key = K1 || K2 || ... || Kn
          */           */
         for (have = mdsz; need > have; have += mdsz) {          for (have = mdsz; need > have; have += mdsz) {
                 EVP_DigestInit(&md, evp_md);                  EVP_DigestInit(&md, kex->evp_md);
                 if (!(datafellows & SSH_BUG_DERIVEKEY))                  if (!(datafellows & SSH_BUG_DERIVEKEY))
                         EVP_DigestUpdate(&md, buffer_ptr(&b), buffer_len(&b));                          EVP_DigestUpdate(&md, buffer_ptr(&b), buffer_len(&b));
                 EVP_DigestUpdate(&md, hash, mdsz);                  EVP_DigestUpdate(&md, hash, hashlen);
                 EVP_DigestUpdate(&md, digest, have);                  EVP_DigestUpdate(&md, digest, have);
                 EVP_DigestFinal(&md, digest + have, NULL);                  EVP_DigestFinal(&md, digest + have, NULL);
         }          }
Line 452 
Line 459 
   
 #define NKEYS   6  #define NKEYS   6
 void  void
 kex_derive_keys(Kex *kex, u_char *hash, BIGNUM *shared_secret)  kex_derive_keys(Kex *kex, u_char *hash, u_int hashlen, BIGNUM *shared_secret)
 {  {
         u_char *keys[NKEYS];          u_char *keys[NKEYS];
         int i, mode, ctos;          u_int i, mode, ctos;
   
         for (i = 0; i < NKEYS; i++)          for (i = 0; i < NKEYS; i++) {
                 keys[i] = derive_key(kex, 'A'+i, kex->we_need, hash, shared_secret);                  keys[i] = derive_key(kex, 'A'+i, kex->we_need, hash, hashlen,
                       shared_secret);
           }
   
         debug2("kex_derive_keys");          debug2("kex_derive_keys");
         for (mode = 0; mode < MODE_MAX; mode++) {          for (mode = 0; mode < MODE_MAX; mode++) {
Line 493 
Line 502 
         EVP_DigestInit(&md, evp_md);          EVP_DigestInit(&md, evp_md);
   
         len = BN_num_bytes(host_modulus);          len = BN_num_bytes(host_modulus);
         if (len < (512 / 8) || len > sizeof(nbuf))          if (len < (512 / 8) || (u_int)len > sizeof(nbuf))
                 fatal("%s: bad host modulus (len %d)", __func__, len);                  fatal("%s: bad host modulus (len %d)", __func__, len);
         BN_bn2bin(host_modulus, nbuf);          BN_bn2bin(host_modulus, nbuf);
         EVP_DigestUpdate(&md, nbuf, len);          EVP_DigestUpdate(&md, nbuf, len);
   
         len = BN_num_bytes(server_modulus);          len = BN_num_bytes(server_modulus);
         if (len < (512 / 8) || len > sizeof(nbuf))          if (len < (512 / 8) || (u_int)len > sizeof(nbuf))
                 fatal("%s: bad server modulus (len %d)", __func__, len);                  fatal("%s: bad server modulus (len %d)", __func__, len);
         BN_bn2bin(server_modulus, nbuf);          BN_bn2bin(server_modulus, nbuf);
         EVP_DigestUpdate(&md, nbuf, len);          EVP_DigestUpdate(&md, nbuf, len);
Line 518 
Line 527 
 void  void
 dump_digest(char *msg, u_char *digest, int len)  dump_digest(char *msg, u_char *digest, int len)
 {  {
         int i;          u_int i;
   
         fprintf(stderr, "%s\n", msg);          fprintf(stderr, "%s\n", msg);
         for (i = 0; i< len; i++) {          for (i = 0; i< len; i++) {

Legend:
Removed from v.1.60  
changed lines
  Added in v.1.60.4.2