diff src/ch/ethz/ssh2/crypto/dh/DhExchange.java @ 307:071eccdff8ea ganymed

fix java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:16:58 -0700
parents 91a31873c42a
children cb179051f0f2
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/crypto/dh/DhExchange.java	Wed Jul 30 12:09:51 2014 -0700
+++ b/src/ch/ethz/ssh2/crypto/dh/DhExchange.java	Wed Jul 30 14:16:58 2014 -0700
@@ -19,43 +19,41 @@
 public class DhExchange {
     private static final Logger log = Logger.getLogger(DhExchange.class);
 
-	/* Given by the standard */
+    /* Given by the standard */
 
     static final BigInteger p1, p14;
     static final BigInteger g;
 
     BigInteger p;
 
-	/* Client public and private */
+    /* Client public and private */
 
     BigInteger e;
     BigInteger x;
 
-	/* Server public and private */
+    /* Server public and private */
 
     BigInteger f;
     BigInteger y;
 
-	/* Shared secret */
+    /* Shared secret */
 
     BigInteger k;
 
     static {
         final String p1_string = "17976931348623159077083915679378745319786029604875"
-                + "60117064444236841971802161585193689478337958649255415021805654859805036464"
-                + "40548199239100050792877003355816639229553136239076508735759914822574862575"
-                + "00742530207744771258955095793777842444242661733472762929938766870920560605"
-                + "0270810842907692932019128194467627007";
-
+                                 + "60117064444236841971802161585193689478337958649255415021805654859805036464"
+                                 + "40548199239100050792877003355816639229553136239076508735759914822574862575"
+                                 + "00742530207744771258955095793777842444242661733472762929938766870920560605"
+                                 + "0270810842907692932019128194467627007";
         final String p14_string = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129"
-                + "024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0"
-                + "A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB"
-                + "6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A"
-                + "163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208"
-                + "552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36C"
-                + "E3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF69558171"
-                + "83995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF";
-
+                                  + "024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0"
+                                  + "A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB"
+                                  + "6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A"
+                                  + "163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208"
+                                  + "552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36C"
+                                  + "E3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF69558171"
+                                  + "83995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF";
         p1 = new BigInteger(p1_string);
         p14 = new BigInteger(p14_string, 16);
         g = new BigInteger("2");
@@ -67,19 +65,20 @@
     public void clientInit(int group, SecureRandom rnd) {
         k = null;
 
-        if(group == 1) {
+        if (group == 1) {
             p = p1;
         }
-        else if(group == 14) {
+        else if (group == 14) {
             p = p14;
         }
         else {
             throw new IllegalArgumentException("Unknown DH group " + group);
         }
 
-        while(true) {
+        while (true) {
             x = new BigInteger(p.bitLength() - 1, rnd);
-            if(x.compareTo(BigInteger.ONE) > 0) {
+
+            if (x.compareTo(BigInteger.ONE) > 0) {
                 break;
             }
         }
@@ -90,10 +89,10 @@
     public void serverInit(int group, SecureRandom rnd) {
         k = null;
 
-        if(group == 1) {
+        if (group == 1) {
             p = p1;
         }
-        else if(group == 14) {
+        else if (group == 14) {
             p = p14;
         }
         else {
@@ -101,7 +100,6 @@
         }
 
         y = new BigInteger(p.bitLength() - 1, rnd);
-
         f = g.modPow(y, p);
     }
 
@@ -110,7 +108,7 @@
      * @throws IllegalStateException
      */
     public BigInteger getE() {
-        if(e == null) {
+        if (e == null) {
             throw new IllegalStateException("DhDsaExchange not initialized!");
         }
 
@@ -122,7 +120,7 @@
      * @throws IllegalStateException
      */
     public BigInteger getF() {
-        if(f == null) {
+        if (f == null) {
             throw new IllegalStateException("DhDsaExchange not initialized!");
         }
 
@@ -134,7 +132,7 @@
      * @throws IllegalStateException
      */
     public BigInteger getK() {
-        if(k == null) {
+        if (k == null) {
             throw new IllegalStateException("Shared secret not yet known, need f first!");
         }
 
@@ -145,11 +143,11 @@
      * @param f
      */
     public void setF(BigInteger f) {
-        if(e == null) {
+        if (e == null) {
             throw new IllegalStateException("DhDsaExchange not initialized!");
         }
 
-        if(BigInteger.ZERO.compareTo(f) >= 0 || p.compareTo(f) <= 0) {
+        if (BigInteger.ZERO.compareTo(f) >= 0 || p.compareTo(f) <= 0) {
             throw new IllegalArgumentException("Invalid f specified!");
         }
 
@@ -161,11 +159,11 @@
      * @param e
      */
     public void setE(BigInteger e) {
-        if(f == null) {
+        if (f == null) {
             throw new IllegalStateException("DhDsaExchange not initialized!");
         }
 
-        if(BigInteger.ZERO.compareTo(e) >= 0 || p.compareTo(e) <= 0) {
+        if (BigInteger.ZERO.compareTo(e) >= 0 || p.compareTo(e) <= 0) {
             throw new IllegalArgumentException("Invalid e specified!");
         }
 
@@ -177,7 +175,7 @@
                              byte[] serverKexPayload, byte[] hostKey) throws IOException {
         HashForSSH2Types hash = new HashForSSH2Types("SHA1");
 
-        if(log.isInfoEnabled()) {
+        if (log.isInfoEnabled()) {
             log.info("Client: '" + StringEncoder.GetString(clientversion) + "'");
             log.info("Server: '" + StringEncoder.GetString(serverversion) + "'");
         }
@@ -190,7 +188,6 @@
         hash.updateBigInt(e);
         hash.updateBigInt(f);
         hash.updateBigInt(k);
-
         return hash.getDigest();
     }
 }