]> andersk Git - openssh.git/blobdiff - dh.c
- (djm) Avoid bad and unportable sprintf usage in compat code
[openssh.git] / dh.c
diff --git a/dh.c b/dh.c
index 982064f54a1aa7d18339cf2ebcdc875ab5e041a9..fa2508af7a258ebace49da048e36b1a368c9c1e0 100644 (file)
--- a/dh.c
+++ b/dh.c
@@ -23,7 +23,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: dh.c,v 1.13 2001/04/04 23:09:17 markus Exp $");
+RCSID("$OpenBSD: dh.c,v 1.17 2001/06/23 15:12:18 itojun Exp $");
 
 #include "xmalloc.h"
 
@@ -39,7 +39,7 @@ RCSID("$OpenBSD: dh.c,v 1.13 2001/04/04 23:09:17 markus Exp $");
 #include "log.h"
 #include "misc.h"
 
-int
+static int
 parse_prime(int linenum, char *line, struct dhgroup *dhg)
 {
        char *cp, *arg;
@@ -80,10 +80,10 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
 
        dhg->g = BN_new();
        dhg->p = BN_new();
-       if (BN_hex2bn(&dhg->g, gen) < 0)
+       if (BN_hex2bn(&dhg->g, gen) == 0)
                goto failclean;
 
-       if (BN_hex2bn(&dhg->p, prime) < 0)
+       if (BN_hex2bn(&dhg->p, prime) == 0)
                goto failclean;
 
        if (BN_num_bits(dhg->p) != dhg->size)
@@ -103,14 +103,14 @@ DH *
 choose_dh(int min, int wantbits, int max)
 {
        FILE *f;
-       char line[1024];
+       char line[2048];
        int best, bestcount, which;
        int linenum;
        struct dhgroup dhg;
 
-       f = fopen(_PATH_DH_PRIMES, "r");
-       if (!f) {
-               log("WARNING: %s does not exist, using old prime", _PATH_DH_PRIMES);
+       if ((f = fopen(_PATH_DH_MODULI, "r")) == NULL &&
+           (f = fopen(_PATH_DH_PRIMES, "r")) == NULL) {
+               log("WARNING: %s does not exist, using old modulus", _PATH_DH_MODULI);
                return (dh_new_group1());
        }
 
@@ -134,18 +134,14 @@ choose_dh(int min, int wantbits, int max)
                if (dhg.size == best)
                        bestcount++;
        }
-       fclose (f);
+       rewind(f);
 
        if (bestcount == 0) {
+               fclose(f);
                log("WARNING: no suitable primes in %s", _PATH_DH_PRIMES);
                return (NULL);
        }
 
-       f = fopen(_PATH_DH_PRIMES, "r");
-       if (!f) {
-               fatal("WARNING: %s disappeared, giving up", _PATH_DH_PRIMES);
-       }
-
        linenum = 0;
        which = arc4random() % bestcount;
        while (fgets(line, sizeof(line), f)) {
@@ -228,15 +224,14 @@ DH *
 dh_new_group_asc(const char *gen, const char *modulus)
 {
        DH *dh;
-       int ret;
 
        dh = DH_new();
        if (dh == NULL)
                fatal("DH_new");
 
-       if ((ret = BN_hex2bn(&dh->p, modulus)) < 0)
+       if (BN_hex2bn(&dh->p, modulus) == 0)
                fatal("BN_hex2bn p");
-       if ((ret = BN_hex2bn(&dh->g, gen)) < 0)
+       if (BN_hex2bn(&dh->g, gen) == 0)
                fatal("BN_hex2bn g");
 
        return (dh);
This page took 0.037756 seconds and 4 git commands to generate.