diff src/ch/ethz/ssh2/crypto/dh/DhGroupExchange.java @ 309:cb179051f0f2 ganymed

add ecdsa key support everywhere
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:29:39 -0700
parents 071eccdff8ea
children 1442be38051b
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/crypto/dh/DhGroupExchange.java	Wed Jul 30 14:21:50 2014 -0700
+++ b/src/ch/ethz/ssh2/crypto/dh/DhGroupExchange.java	Wed Jul 30 14:29:39 2014 -0700
@@ -1,21 +1,18 @@
-/*
- * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
- * Please refer to the LICENSE.txt for licensing details.
- */
+
 package ch.ethz.ssh2.crypto.dh;
 
-import java.io.IOException;
 import java.math.BigInteger;
 import java.security.SecureRandom;
 
 import ch.ethz.ssh2.DHGexParameters;
 import ch.ethz.ssh2.crypto.digest.HashForSSH2Types;
 
+
 /**
  * DhGroupExchange.
  *
- * @author Christian Plattner
- * @version 2.50, 03/15/10
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: DhGroupExchange.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
  */
 public class DhGroupExchange {
     /* Given by the standard */
@@ -51,9 +48,8 @@
      * @return Returns the e.
      */
     public BigInteger getE() {
-        if (e == null) {
+        if (e == null)
             throw new IllegalStateException("Not initialized!");
-        }
 
         return e;
     }
@@ -62,9 +58,8 @@
      * @return Returns the shared secret k.
      */
     public BigInteger getK() {
-        if (k == null) {
+        if (k == null)
             throw new IllegalStateException("Shared secret not yet known, need f first!");
-        }
 
         return k;
     }
@@ -73,38 +68,34 @@
      * Sets f and calculates the shared secret.
      */
     public void setF(BigInteger f) {
-        if (e == null) {
+        if (e == null)
             throw new IllegalStateException("Not initialized!");
-        }
 
         BigInteger zero = BigInteger.valueOf(0);
 
-        if (zero.compareTo(f) >= 0 || p.compareTo(f) <= 0) {
+        if (zero.compareTo(f) >= 0 || p.compareTo(f) <= 0)
             throw new IllegalArgumentException("Invalid f specified!");
-        }
 
         this.f = f;
         this.k = f.modPow(x, p);
     }
 
-    public byte[] calculateH(byte[] clientversion, byte[] serverversion, byte[] clientKexPayload,
-                             byte[] serverKexPayload, byte[] hostKey, DHGexParameters para) throws IOException {
-        HashForSSH2Types hash = new HashForSSH2Types("SHA1");
+    public byte[] calculateH(String hashAlgo, byte[] clientversion, byte[] serverversion,
+                             byte[] clientKexPayload, byte[] serverKexPayload, byte[] hostKey, DHGexParameters para) {
+        HashForSSH2Types hash = new HashForSSH2Types(hashAlgo);
         hash.updateByteString(clientversion);
         hash.updateByteString(serverversion);
         hash.updateByteString(clientKexPayload);
         hash.updateByteString(serverKexPayload);
         hash.updateByteString(hostKey);
 
-        if (para.getMin_group_len() > 0) {
+        if (para.getMin_group_len() > 0)
             hash.updateUINT32(para.getMin_group_len());
-        }
 
         hash.updateUINT32(para.getPref_group_len());
 
-        if (para.getMax_group_len() > 0) {
+        if (para.getMax_group_len() > 0)
             hash.updateUINT32(para.getMax_group_len());
-        }
 
         hash.updateBigInt(p);
         hash.updateBigInt(g);