Author: nextgens
Date: 2007-09-10 13:49:03 +0000 (Mon, 10 Sep 2007)
New Revision: 15118

Modified:
   branches/freenet-jfk/src/freenet/crypt/DiffieHellmanLightContext.java
Log:
Add a new method to DiffieHellmanLightContext : getHMACKey ... Calling it is 
costy.

Modified: branches/freenet-jfk/src/freenet/crypt/DiffieHellmanLightContext.java
===================================================================
--- branches/freenet-jfk/src/freenet/crypt/DiffieHellmanLightContext.java       
2007-09-10 13:06:23 UTC (rev 15117)
+++ branches/freenet-jfk/src/freenet/crypt/DiffieHellmanLightContext.java       
2007-09-10 13:49:03 UTC (rev 15118)
@@ -1,5 +1,7 @@
 package freenet.crypt;

+import freenet.support.Logger;
+
 import net.i2p.util.NativeBigInteger;

 public class DiffieHellmanLightContext {
@@ -12,6 +14,8 @@
        public final DHGroup group;
        /** The signature of (g^r, grpR) */
        public DSASignature signature = null;
+       
+       private final boolean logMINOR;

        public String toString() {
                StringBuffer sb = new StringBuffer();
@@ -28,9 +32,24 @@
                this.myExponent = myExponent;
                this.myExponential = myExponential;
                this.group = group;
+               logMINOR = Logger.shouldLog(Logger.MINOR, this);
        }

        public void setSignature(DSASignature sig) {
                this.signature = sig;
        }
+       
+       /*
+        * Calling the following is costy; avoid
+        */
+       public NativeBigInteger getHMACKey(NativeBigInteger peerExponential, 
NativeBigInteger groupP) {         
+               if(logMINOR)
+                       Logger.minor(this, "My exponent: 
"+myExponent.toHexString()+", my exponential: "+myExponential.toHexString()+", 
peer's exponential: "+peerExponential.toHexString());
+               NativeBigInteger sharedSecret =
+                       (NativeBigInteger) peerExponential.modPow(myExponent, 
groupP);
+               if(logMINOR)
+                       Logger.minor(this, "g^ir mod p = " + 
sharedSecret.toString());
+               
+               return sharedSecret;
+       }
 }
\ No newline at end of file


Reply via email to