]> andersk Git - openssh.git/commitdiff
- OpenBSD CVS Sync
authordjm <djm>
Fri, 30 Mar 2001 00:50:10 +0000 (00:50 +0000)
committerdjm <djm>
Fri, 30 Mar 2001 00:50:10 +0000 (00:50 +0000)
   - markus@cvs.openbsd.org 2001/03/29 21:17:40
     [dh.c dh.h kex.c kex.h]
     prepare for rekeying: move DH code to dh.c

ChangeLog
dh.c
dh.h
kex.c
kex.h

index 80007b9229d59591052c3d184447cdb55fa698a2..a328c8576f6d2af5630c4ff8d67b175c5b4489f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,9 @@
    - stevesk@cvs.openbsd.org 2001/03/29 21:06:21
      [sshconnect2.c sshd.c]
      need to set both STOC and CTOS for SSH_BUG_BIGENDIANAES; ok markus@
+   - markus@cvs.openbsd.org 2001/03/29 21:17:40
+     [dh.c dh.h kex.c kex.h]
+     prepare for rekeying: move DH code to dh.c
 
 20010329
  - OpenBSD CVS Sync
diff --git a/dh.c b/dh.c
index 636758fa8bb5ace7d5ed60d400e089704bded467..6c53b0038d0175c7c8ff8be46d6151eba9691f78 100644 (file)
--- a/dh.c
+++ b/dh.c
@@ -23,7 +23,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: dh.c,v 1.10 2001/03/28 22:04:57 provos Exp $");
+RCSID("$OpenBSD: dh.c,v 1.11 2001/03/29 21:17:39 markus Exp $");
 
 #include "xmalloc.h"
 
@@ -166,3 +166,110 @@ choose_dh(int min, int wantbits, int max)
 
        return (dh_new_group(dhg.g, dhg.p));
 }
+
+/* diffie-hellman-group1-sha1 */
+
+int
+dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
+{
+       int i;
+       int n = BN_num_bits(dh_pub);
+       int bits_set = 0;
+
+       if (dh_pub->neg) {
+               log("invalid public DH value: negativ");
+               return 0;
+       }
+       for (i = 0; i <= n; i++)
+               if (BN_is_bit_set(dh_pub, i))
+                       bits_set++;
+       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;
+       log("invalid public DH value (%d/%d)", bits_set, BN_num_bits(dh->p));
+       return 0;
+}
+
+void
+dh_gen_key(DH *dh, int need)
+{
+       int i, bits_set = 0, tries = 0;
+
+       if (dh->p == NULL)
+               fatal("dh_gen_key: dh->p == NULL");
+       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_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))
+                       fatal("dh_gen_key: BN_rand failed");
+               if (DH_generate_key(dh) == 0)
+                       fatal("DH_generate_key");
+               for (i = 0; i <= BN_num_bits(dh->priv_key); i++)
+                       if (BN_is_bit_set(dh->priv_key, i))
+                               bits_set++;
+               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");
+       } while (!dh_pub_is_valid(dh, dh->pub_key));
+}
+
+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)
+               fatal("BN_hex2bn p");
+       if ((ret = BN_hex2bn(&dh->g, gen)) < 0)
+               fatal("BN_hex2bn g");
+
+       return (dh);
+}
+
+/*
+ * This just returns the group, we still need to generate the exchange
+ * value.
+ */
+
+DH *
+dh_new_group(BIGNUM *gen, BIGNUM *modulus)
+{
+       DH *dh;
+
+       dh = DH_new();
+       if (dh == NULL)
+               fatal("DH_new");
+       dh->p = modulus;
+       dh->g = gen;
+
+       return (dh);
+}
+
+DH *
+dh_new_group1(void)
+{
+       static char *gen = "2", *group1 =
+           "FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" "C4C6628B" "80DC1CD1"
+           "29024E08" "8A67CC74" "020BBEA6" "3B139B22" "514A0879" "8E3404DD"
+           "EF9519B3" "CD3A431B" "302B0A6D" "F25F1437" "4FE1356D" "6D51C245"
+           "E485B576" "625E7EC6" "F44C42E9" "A637ED6B" "0BFF5CB6" "F406B7ED"
+           "EE386BFB" "5A899FA5" "AE9F2411" "7C4B1FE6" "49286651" "ECE65381"
+           "FFFFFFFF" "FFFFFFFF";
+
+       return (dh_new_group_asc(gen, group1));
+}
diff --git a/dh.h b/dh.h
index 70b326e9fa759e92bb5af5f4c2abb65818b7866d..13d2fa1620e396ad1c20992098bae49b7cc1c343 100644 (file)
--- a/dh.h
+++ b/dh.h
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dh.h,v 1.3 2001/03/27 17:46:49 provos Exp $   */
+/*     $OpenBSD: dh.h,v 1.4 2001/03/29 21:17:39 markus Exp $   */
 
 /*
  * Copyright (c) 2000 Niels Provos.  All rights reserved.
@@ -32,7 +32,13 @@ struct dhgroup {
        BIGNUM *p;
 };
 
-DH *choose_dh(int min, int nbits, int max);
+DH     *choose_dh(int min, int nbits, int max);
+DH     *dh_new_group_asc(const char *, const char *);
+DH     *dh_new_group(BIGNUM *, BIGNUM *);
+DH     *dh_new_group1(void);
+
+void   dh_gen_key(DH *, int);
+int    dh_pub_is_valid(DH *dh, BIGNUM *dh_pub);
 
 #define DH_GRP_MIN     1024
 #define DH_GRP_MAX     8192
diff --git a/kex.c b/kex.c
index 38c813d8bcb22cf972e1512d03e1efb8bd213633..576d4b56e774fa9a6772f256bb1d68095ea028d7 100644 (file)
--- a/kex.c
+++ b/kex.c
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: kex.c,v 1.24 2001/03/28 21:59:40 provos Exp $");
+RCSID("$OpenBSD: kex.c,v 1.25 2001/03/29 21:17:39 markus Exp $");
 
 #include <openssl/crypto.h>
 #include <openssl/bio.h>
 #include <openssl/bn.h>
-#include <openssl/dh.h>
 #include <openssl/pem.h>
 
 #include "ssh2.h"
@@ -113,113 +112,6 @@ kex_exchange_kexinit(
        debug("done");
 }
 
-/* diffie-hellman-group1-sha1 */
-
-int
-dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
-{
-       int i;
-       int n = BN_num_bits(dh_pub);
-       int bits_set = 0;
-
-       if (dh_pub->neg) {
-               log("invalid public DH value: negativ");
-               return 0;
-       }
-       for (i = 0; i <= n; i++)
-               if (BN_is_bit_set(dh_pub, i))
-                       bits_set++;
-       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;
-       log("invalid public DH value (%d/%d)", bits_set, BN_num_bits(dh->p));
-       return 0;
-}
-
-void
-dh_gen_key(DH *dh, int need)
-{
-       int i, bits_set = 0, tries = 0;
-
-       if (dh->p == NULL)
-               fatal("dh_gen_key: dh->p == NULL");
-       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_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))
-                       fatal("dh_gen_key: BN_rand failed");
-               if (DH_generate_key(dh) == 0)
-                       fatal("DH_generate_key");
-               for (i = 0; i <= BN_num_bits(dh->priv_key); i++)
-                       if (BN_is_bit_set(dh->priv_key, i))
-                               bits_set++;
-               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");
-       } while (!dh_pub_is_valid(dh, dh->pub_key));
-}
-
-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)
-               fatal("BN_hex2bn p");
-       if ((ret = BN_hex2bn(&dh->g, gen)) < 0)
-               fatal("BN_hex2bn g");
-
-       return (dh);
-}
-
-/*
- * This just returns the group, we still need to generate the exchange
- * value.
- */
-
-DH *
-dh_new_group(BIGNUM *gen, BIGNUM *modulus)
-{
-       DH *dh;
-
-       dh = DH_new();
-       if (dh == NULL)
-               fatal("DH_new");
-       dh->p = modulus;
-       dh->g = gen;
-
-       return (dh);
-}
-
-DH *
-dh_new_group1(void)
-{
-       static char *gen = "2", *group1 =
-           "FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" "C4C6628B" "80DC1CD1"
-           "29024E08" "8A67CC74" "020BBEA6" "3B139B22" "514A0879" "8E3404DD"
-           "EF9519B3" "CD3A431B" "302B0A6D" "F25F1437" "4FE1356D" "6D51C245"
-           "E485B576" "625E7EC6" "F44C42E9" "A637ED6B" "0BFF5CB6" "F406B7ED"
-           "EE386BFB" "5A899FA5" "AE9F2411" "7C4B1FE6" "49286651" "ECE65381"
-           "FFFFFFFF" "FFFFFFFF";
-
-       return (dh_new_group_asc(gen, group1));
-}
-
 #ifdef DEBUG_KEX
 void
 dump_digest(u_char *digest, int len)
diff --git a/kex.h b/kex.h
index 41337680a9cbff88b7049699ce6be52ac948bd1e..4cc87d52707bdf42baa60ed9ee1ccf44c5fee5dc 100644 (file)
--- a/kex.h
+++ b/kex.h
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kex.h,v 1.16 2001/03/28 21:59:40 provos Exp $ */
+/*     $OpenBSD: kex.h,v 1.17 2001/03/29 21:17:40 markus Exp $ */
 
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
@@ -103,11 +103,6 @@ kex_choose_conf(char *cprop[PROPOSAL_MAX],
     char *sprop[PROPOSAL_MAX], int server);
 int    kex_derive_keys(Kex *k, u_char *hash, BIGNUM *shared_secret);
 void   packet_set_kex(Kex *k);
-int    dh_pub_is_valid(DH *dh, BIGNUM *dh_pub);
-DH     *dh_new_group_asc(const char *, const char *);
-DH     *dh_new_group(BIGNUM *, BIGNUM *);
-void   dh_gen_key(DH *, int);
-DH     *dh_new_group1(void);
 
 u_char *
 kex_hash(
This page took 0.159167 seconds and 5 git commands to generate.