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

Diff for /src/usr.bin/ssh/Attic/kexdhc.c between version 1.27 and 1.28

version 1.27, 2019/01/21 10:00:23 version 1.28, 2019/01/21 10:03:37
Line 79 
Line 79 
 input_kex_dh(int type, u_int32_t seq, struct ssh *ssh)  input_kex_dh(int type, u_int32_t seq, struct ssh *ssh)
 {  {
         struct kex *kex = ssh->kex;          struct kex *kex = ssh->kex;
         BIGNUM *dh_server_pub = NULL, *shared_secret = NULL;          BIGNUM *dh_server_pub = NULL;
         const BIGNUM *pub_key;          const BIGNUM *pub_key;
         struct sshkey *server_host_key = NULL;          struct sshkey *server_host_key = NULL;
         u_char *kbuf = NULL, *server_host_key_blob = NULL, *signature = NULL;          struct sshbuf *shared_secret = NULL;
           u_char *server_host_key_blob = NULL, *signature = NULL;
         u_char hash[SSH_DIGEST_MAX_LENGTH];          u_char hash[SSH_DIGEST_MAX_LENGTH];
         size_t klen = 0, slen, sbloblen, hashlen;          size_t slen, sbloblen, hashlen;
         int kout, r;          int r;
   
         if (kex->verify_host_key == NULL) {          if (kex->verify_host_key == NULL) {
                 r = SSH_ERR_INVALID_ARGUMENT;                  r = SSH_ERR_INVALID_ARGUMENT;
Line 112 
Line 113 
             (r = sshpkt_get_string(ssh, &signature, &slen)) != 0 ||              (r = sshpkt_get_string(ssh, &signature, &slen)) != 0 ||
             (r = sshpkt_get_end(ssh)) != 0)              (r = sshpkt_get_end(ssh)) != 0)
                 goto out;                  goto out;
 #ifdef DEBUG_KEXDH          if ((shared_secret = sshbuf_new()) == NULL) {
         fprintf(stderr, "dh_server_pub= ");  
         BN_print_fp(stderr, dh_server_pub);  
         fprintf(stderr, "\n");  
         debug("bits %d", BN_num_bits(dh_server_pub));  
 #endif  
         if (!dh_pub_is_valid(kex->dh, dh_server_pub)) {  
                 sshpkt_disconnect(ssh, "bad server public DH value");  
                 r = SSH_ERR_MESSAGE_INCOMPLETE;  
                 goto out;  
         }  
   
         klen = DH_size(kex->dh);  
         if ((kbuf = malloc(klen)) == NULL ||  
             (shared_secret = BN_new()) == NULL) {  
                 r = SSH_ERR_ALLOC_FAIL;                  r = SSH_ERR_ALLOC_FAIL;
                 goto out;                  goto out;
         }          }
         if ((kout = DH_compute_key(kbuf, dh_server_pub, kex->dh)) < 0 ||          if ((r = kex_dh_compute_key(kex, dh_server_pub, shared_secret)) != 0)
             BN_bin2bn(kbuf, kout, shared_secret) == NULL) {  
                 r = SSH_ERR_LIBCRYPTO_ERROR;  
                 goto out;                  goto out;
         }  
 #ifdef DEBUG_KEXDH  
         dump_digest("shared secret", kbuf, kout);  
 #endif  
   
         /* calc and verify H */          /* calc and verify H */
         DH_get0_key(kex->dh, &pub_key, NULL);          DH_get0_key(kex->dh, &pub_key, NULL);
Line 151 
Line 132 
             server_host_key_blob, sbloblen,              server_host_key_blob, sbloblen,
             pub_key,              pub_key,
             dh_server_pub,              dh_server_pub,
             shared_secret,              sshbuf_ptr(shared_secret), sshbuf_len(shared_secret),
             hash, &hashlen)) != 0)              hash, &hashlen)) != 0)
                 goto out;                  goto out;
   
Line 159 
Line 140 
             kex->hostkey_alg, ssh->compat)) != 0)              kex->hostkey_alg, ssh->compat)) != 0)
                 goto out;                  goto out;
   
         if ((r = kex_derive_keys_bn(ssh, hash, hashlen, shared_secret)) == 0)          if ((r = kex_derive_keys(ssh, hash, hashlen, shared_secret)) == 0)
                 r = kex_send_newkeys(ssh);                  r = kex_send_newkeys(ssh);
  out:   out:
         explicit_bzero(hash, sizeof(hash));          explicit_bzero(hash, sizeof(hash));
         DH_free(kex->dh);          DH_free(kex->dh);
         kex->dh = NULL;          kex->dh = NULL;
         BN_clear_free(dh_server_pub);          BN_clear_free(dh_server_pub);
         if (kbuf) {          sshbuf_free(shared_secret);
                 explicit_bzero(kbuf, klen);  
                 free(kbuf);  
         }  
         BN_clear_free(shared_secret);  
         sshkey_free(server_host_key);          sshkey_free(server_host_key);
         free(server_host_key_blob);          free(server_host_key_blob);
         free(signature);          free(signature);

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28