]> andersk Git - gssapi-openssh.git/blobdiff - openssh/dh.c
The man2html from jbasney on pkilab2 works whereas the standard one doesn't.
[gssapi-openssh.git] / openssh / dh.c
index c7a3e18be82afb4bebe659ce1c9e1a8e16aa1a51..fa2508af7a258ebace49da048e36b1a368c9c1e0 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: dh.c,v 1.26 2003/12/16 15:51:54 markus Exp $");
+RCSID("$OpenBSD: dh.c,v 1.17 2001/06/23 15:12:18 itojun Exp $");
 
 #include "xmalloc.h"
 
@@ -50,7 +50,7 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
        /* Ignore leading whitespace */
        if (*arg == '\0')
                arg = strdelim(&cp);
-       if (!arg || !*arg || *arg == '#')
+       if (!*arg || *arg == '#')
                return 0;
 
        /* time */
@@ -78,10 +78,8 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
        if (cp != NULL || *prime == '\0')
                goto fail;
 
-       if ((dhg->g = BN_new()) == NULL)
-               fatal("parse_prime: BN_new failed");
-       if ((dhg->p = BN_new()) == NULL)
-               fatal("parse_prime: BN_new failed");
+       dhg->g = BN_new();
+       dhg->p = BN_new();
        if (BN_hex2bn(&dhg->g, gen) == 0)
                goto failclean;
 
@@ -94,8 +92,8 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
        return (1);
 
  failclean:
-       BN_clear_free(dhg->g);
-       BN_clear_free(dhg->p);
+       BN_free(dhg->g);
+       BN_free(dhg->p);
  fail:
        error("Bad prime description in line %d", linenum);
        return (0);
@@ -112,7 +110,7 @@ choose_dh(int min, int wantbits, int max)
 
        if ((f = fopen(_PATH_DH_MODULI, "r")) == NULL &&
            (f = fopen(_PATH_DH_PRIMES, "r")) == NULL) {
-               logit("WARNING: %s does not exist, using old modulus", _PATH_DH_MODULI);
+               log("WARNING: %s does not exist, using old modulus", _PATH_DH_MODULI);
                return (dh_new_group1());
        }
 
@@ -122,8 +120,8 @@ choose_dh(int min, int wantbits, int max)
                linenum++;
                if (!parse_prime(linenum, line, &dhg))
                        continue;
-               BN_clear_free(dhg.g);
-               BN_clear_free(dhg.p);
+               BN_free(dhg.g);
+               BN_free(dhg.p);
 
                if (dhg.size > max || dhg.size < min)
                        continue;
@@ -140,7 +138,7 @@ choose_dh(int min, int wantbits, int max)
 
        if (bestcount == 0) {
                fclose(f);
-               logit("WARNING: no suitable primes in %s", _PATH_DH_PRIMES);
+               log("WARNING: no suitable primes in %s", _PATH_DH_PRIMES);
                return (NULL);
        }
 
@@ -152,8 +150,8 @@ choose_dh(int min, int wantbits, int max)
                if ((dhg.size > max || dhg.size < min) ||
                    dhg.size != best ||
                    linenum++ != which) {
-                       BN_clear_free(dhg.g);
-                       BN_clear_free(dhg.p);
+                       BN_free(dhg.g);
+                       BN_free(dhg.p);
                        continue;
                }
                break;
@@ -176,18 +174,18 @@ dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
        int bits_set = 0;
 
        if (dh_pub->neg) {
-               logit("invalid public DH value: negativ");
+               log("invalid public DH value: negativ");
                return 0;
        }
        for (i = 0; i <= n; i++)
                if (BN_is_bit_set(dh_pub, i))
                        bits_set++;
-       debug2("bits set: %d/%d", bits_set, BN_num_bits(dh->p));
+       debug("bits set: %d/%d", bits_set, BN_num_bits(dh->p));
 
        /* if g==2 and bits_set==1 then computing log_g(dh_pub) is trivial */
        if (bits_set > 1 && (BN_cmp(dh_pub, dh->p) == -1))
                return 1;
-       logit("invalid public DH value (%d/%d)", bits_set, BN_num_bits(dh->p));
+       log("invalid public DH value (%d/%d)", bits_set, BN_num_bits(dh->p));
        return 0;
 }
 
@@ -198,13 +196,14 @@ dh_gen_key(DH *dh, int need)
 
        if (dh->p == NULL)
                fatal("dh_gen_key: dh->p == NULL");
-       if (need > INT_MAX / 2 || 2 * need >= BN_num_bits(dh->p))
+       if (2*need >= BN_num_bits(dh->p))
                fatal("dh_gen_key: group too small: %d (2*need %d)",
                    BN_num_bits(dh->p), 2*need);
        do {
                if (dh->priv_key != NULL)
-                       BN_clear_free(dh->priv_key);
-               if ((dh->priv_key = BN_new()) == NULL)
+                       BN_free(dh->priv_key);
+               dh->priv_key = BN_new();
+               if (dh->priv_key == NULL)
                        fatal("dh_gen_key: BN_new failed");
                /* generate a 2*need bits random private exponent */
                if (!BN_rand(dh->priv_key, 2*need, 0, 0))
@@ -214,7 +213,7 @@ dh_gen_key(DH *dh, int need)
                for (i = 0; i <= BN_num_bits(dh->priv_key); i++)
                        if (BN_is_bit_set(dh->priv_key, i))
                                bits_set++;
-               debug2("dh_gen_key: priv key bits set: %d/%d",
+               debug("dh_gen_key: priv key bits set: %d/%d",
                    bits_set, BN_num_bits(dh->priv_key));
                if (tries++ > 10)
                        fatal("dh_gen_key: too many bad keys: giving up");
@@ -226,8 +225,9 @@ dh_new_group_asc(const char *gen, const char *modulus)
 {
        DH *dh;
 
-       if ((dh = DH_new()) == NULL)
-               fatal("dh_new_group_asc: DH_new");
+       dh = DH_new();
+       if (dh == NULL)
+               fatal("DH_new");
 
        if (BN_hex2bn(&dh->p, modulus) == 0)
                fatal("BN_hex2bn p");
@@ -247,8 +247,9 @@ dh_new_group(BIGNUM *gen, BIGNUM *modulus)
 {
        DH *dh;
 
-       if ((dh = DH_new()) == NULL)
-               fatal("dh_new_group: DH_new");
+       dh = DH_new();
+       if (dh == NULL)
+               fatal("DH_new");
        dh->p = modulus;
        dh->g = gen;
 
@@ -279,9 +280,11 @@ int
 dh_estimate(int bits)
 {
 
-       if (bits <= 128)
+       if (bits < 64)
+               return (512);   /* O(2**63) */
+       if (bits < 128)
                return (1024);  /* O(2**86) */
-       if (bits <= 192)
+       if (bits < 192)
                return (2048);  /* O(2**116) */
        return (4096);          /* O(2**156) */
 }
This page took 0.155694 seconds and 4 git commands to generate.