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

Diff for /src/usr.bin/ssh/dh.c between version 1.53 and 1.54

version 1.53, 2013/11/21 00:45:44 version 1.54, 2015/01/19 20:16:15
Line 36 
Line 36 
 #include "pathnames.h"  #include "pathnames.h"
 #include "log.h"  #include "log.h"
 #include "misc.h"  #include "misc.h"
   #include "ssherr.h"
   
 static int  static int
 parse_prime(int linenum, char *line, struct dhgroup *dhg)  parse_prime(int linenum, char *line, struct dhgroup *dhg)
Line 104 
Line 105 
                 goto fail;                  goto fail;
         }          }
   
         if ((dhg->g = BN_new()) == NULL)          if ((dhg->g = BN_new()) == NULL ||
                 fatal("parse_prime: BN_new failed");              (dhg->p = BN_new()) == NULL) {
         if ((dhg->p = BN_new()) == NULL)                  error("parse_prime: BN_new failed");
                 fatal("parse_prime: BN_new failed");                  goto fail;
           }
         if (BN_hex2bn(&dhg->g, gen) == 0) {          if (BN_hex2bn(&dhg->g, gen) == 0) {
                 error("moduli:%d: could not parse generator value", linenum);                  error("moduli:%d: could not parse generator value", linenum);
                 goto fail;                  goto fail;
Line 125 
Line 127 
                 error("moduli:%d: generator is invalid", linenum);                  error("moduli:%d: generator is invalid", linenum);
                 goto fail;                  goto fail;
         }          }
   
         return 1;          return 1;
   
  fail:   fail:
Line 134 
Line 135 
         if (dhg->p != NULL)          if (dhg->p != NULL)
                 BN_clear_free(dhg->p);                  BN_clear_free(dhg->p);
         dhg->g = dhg->p = NULL;          dhg->g = dhg->p = NULL;
         error("Bad prime description in line %d", linenum);  
         return 0;          return 0;
 }  }
   
Line 197 
Line 197 
                 break;                  break;
         }          }
         fclose(f);          fclose(f);
         if (linenum != which+1)          if (linenum != which+1) {
                 fatal("WARNING: line %d disappeared in %s, giving up",                  logit("WARNING: line %d disappeared in %s, giving up",
                     which, _PATH_DH_PRIMES);                      which, _PATH_DH_PRIMES);
                   return (dh_new_group14());
           }
   
         return (dh_new_group(dhg.g, dhg.p));          return (dh_new_group(dhg.g, dhg.p));
 }  }
Line 248 
Line 250 
         return 0;          return 0;
 }  }
   
 void  int
 dh_gen_key(DH *dh, int need)  dh_gen_key(DH *dh, int need)
 {  {
         int pbits;          int pbits;
   
         if (need <= 0)          if (need < 0 || dh->p == NULL ||
                 fatal("%s: need <= 0", __func__);              (pbits = BN_num_bits(dh->p)) <= 0 ||
         if (dh->p == NULL)              need > INT_MAX / 2 || 2 * need >= pbits)
                 fatal("%s: dh->p == NULL", __func__);                  return SSH_ERR_INVALID_ARGUMENT;
         if ((pbits = BN_num_bits(dh->p)) <= 0)  
                 fatal("%s: bits(p) <= 0", __func__);  
         dh->length = MIN(need * 2, pbits - 1);          dh->length = MIN(need * 2, pbits - 1);
         if (DH_generate_key(dh) == 0)          if (DH_generate_key(dh) == 0 ||
                 fatal("%s: key generation failed", __func__);              !dh_pub_is_valid(dh, dh->pub_key)) {
         if (!dh_pub_is_valid(dh, dh->pub_key))                  BN_clear_free(dh->priv_key);
                 fatal("%s: generated invalid key", __func__);                  return SSH_ERR_LIBCRYPTO_ERROR;
           }
           return 0;
 }  }
   
 DH *  DH *
Line 272 
Line 274 
         DH *dh;          DH *dh;
   
         if ((dh = DH_new()) == NULL)          if ((dh = DH_new()) == NULL)
                 fatal("dh_new_group_asc: DH_new");                  return NULL;
           if (BN_hex2bn(&dh->p, modulus) == 0 ||
         if (BN_hex2bn(&dh->p, modulus) == 0)              BN_hex2bn(&dh->g, gen) == 0) {
                 fatal("BN_hex2bn p");                  DH_free(dh);
         if (BN_hex2bn(&dh->g, gen) == 0)                  return NULL;
                 fatal("BN_hex2bn g");          }
   
         return (dh);          return (dh);
 }  }
   
Line 293 
Line 294 
         DH *dh;          DH *dh;
   
         if ((dh = DH_new()) == NULL)          if ((dh = DH_new()) == NULL)
                 fatal("dh_new_group: DH_new");                  return NULL;
         dh->p = modulus;          dh->p = modulus;
         dh->g = gen;          dh->g = gen;
   
Line 341 
Line 342 
  * from RFC4419 section 3.   * from RFC4419 section 3.
  */   */
   
 int  u_int
 dh_estimate(int bits)  dh_estimate(int bits)
 {  {
         if (bits <= 112)          if (bits <= 112)

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.54