Update of /cvsroot/freenet/freenet/src/freenet/crypt
In directory sc8-pr-cvs1:/tmp/cvs-serv25857/src/freenet/crypt

Modified Files:
      Tag: stable
        CipherOutputStream.java DSA.java DSAGroup.java 
        DSAPublicKey.java DSASignature.java DiffieHellman.java 
        Yarrow.java 
Added Files:
      Tag: stable
        ThrottledAsyncEntropyYarrow.java 
Log Message:
5029: Merge from unstable after months of work. MASSIVE changes.
Highlights:
* Next Generation Routing, massive related changes
* Major changes to handling of messages and connections (PeerHandler and related 
changes)
* Even more non-blocking I/O
* Documentation improvements
* Lots of new diagnostics and config options
* Lots of bug fixes and performance tweaking
* Probably lots of new bugs too!


--- NEW FILE: ThrottledAsyncEntropyYarrow.java ---
/*
 * Created on Oct 27, 2003

 */
package freenet.crypt;

import freenet.support.BlockingQueue;

/**
 * @author Iakin
 * 
 * Exactly the same as Yarrow except that supplied entropy will be added 
asynchronously and that some
 * entropy additions might be ignored
 * 
 */
public class ThrottledAsyncEntropyYarrow extends Yarrow {
        long maxEntropyQueueSize;
        Thread entropyProcessor;
        BlockingQueue entropy;
        private class EntropyQueueItem {
                EntropySource source;
                long data;
                int entropyGuess;
                EntropyQueueItem(EntropySource source, long data, int entropyGuess) {
                        this.source = source;
                        this.data = data;
                        this.entropyGuess = entropyGuess;
                }
        }
        public ThrottledAsyncEntropyYarrow(String seed, String digest, String 
cipher,long maxEntropyQueueSize)
        {
                super(seed,digest,cipher);
                this.maxEntropyQueueSize = maxEntropyQueueSize;
                initialize();
        }

        public int acceptEntropy(EntropySource source, long data, int entropyGuess) {
                int i;
                if(entropy.size() < maxEntropyQueueSize)
                        entropy.enqueue(new 
EntropyQueueItem(source,data,entropyGuess));
                else
                        i = 0;
                return 32; //TODO: What should we do here.. seem like no part of fred 
currently uses the retuned value /[EMAIL PROTECTED]
        }
        private void initialize() {
                //entropy = new BlockingQueue(); Done in readStartupEntropy below
                entropyProcessor = new Thread(new Runnable() {
                        public void run() {
                                while (true)
                                        try {
                                                EntropyQueueItem e = 
(EntropyQueueItem) entropy.dequeue();
                                                
ThrottledAsyncEntropyYarrow.super.acceptEntropy(e.source, e.data, e.entropyGuess);
                                        } catch (InterruptedException e) {
                                        }
                        }
                });
                entropyProcessor.setDaemon(true);
                entropyProcessor.setName("PRNG/Yarrow entropy processing thread");
                entropyProcessor.start();
        }

        protected void readStartupEntropy(EntropySource startupEntropy) {
                //This method is called during Yarrow:s initialization which is run 
before our own..
                //this is how I splice in the instanciation of the BlockingQueue and a 
temporary queuesize..
                //Quite ugly way of doing it but, well if someone knows a better way 
of doing it then
                //feel free...
                if(maxEntropyQueueSize == 0) 
                        maxEntropyQueueSize = 100;
                entropy = new BlockingQueue();
                super.readStartupEntropy(startupEntropy);
        }

}

Index: CipherOutputStream.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/crypt/CipherOutputStream.java,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.6.1
diff -u -w -r1.1.1.1 -r1.1.1.1.6.1
--- CipherOutputStream.java     13 Jan 2002 05:24:23 -0000      1.1.1.1
+++ CipherOutputStream.java     28 Oct 2003 20:20:30 -0000      1.1.1.1.6.1
@@ -17,6 +17,10 @@
 
     private final PCFBMode ctx;
 
+    public PCFBMode getCipher() {
+       return ctx;
+    }
+    
     public CipherOutputStream(BlockCipher c, OutputStream out) 
                                         throws IOException {
         this(new PCFBMode(c), out);

Index: DSA.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/crypt/DSA.java,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.6.1
diff -u -w -r1.1.1.1 -r1.1.1.1.6.1
--- DSA.java    13 Jan 2002 05:24:23 -0000      1.1.1.1
+++ DSA.java    28 Oct 2003 20:20:30 -0000      1.1.1.1.6.1
@@ -71,6 +71,7 @@
     public static boolean verify(DSAPublicKey kp,
                                 DSASignature sig,
                                 BigInteger m) {
+       try {
        BigInteger w=sig.getS().modInverse(kp.getQ());
        BigInteger u1=m.multiply(w).mod(kp.getQ());
        BigInteger u2=sig.getR().multiply(w).mod(kp.getQ());
@@ -78,6 +79,12 @@
        BigInteger v2=kp.getY().modPow(u2, kp.getP());
        BigInteger v=v1.multiply(v2).mod(kp.getP()).mod(kp.getQ());
        return v.equals(sig.getR());
+
+
+           //FIXME: is there a better way to handle this exception raised on the 'w=' 
line above?
+       } catch (ArithmeticException e) {  // catch error raised by invalid data
+           return false;                  // and report that that data is bad.
+       }
     }
 
     public static void main(String[] args) throws Exception {

Index: DSAGroup.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/crypt/DSAGroup.java,v
retrieving revision 1.1.1.1.4.1.2.2
retrieving revision 1.1.1.1.4.1.2.3
diff -u -w -r1.1.1.1.4.1.2.2 -r1.1.1.1.4.1.2.3
--- DSAGroup.java       9 Jul 2003 00:38:47 -0000       1.1.1.1.4.1.2.2
+++ DSAGroup.java       28 Oct 2003 20:20:30 -0000      1.1.1.1.4.1.2.3
@@ -36,7 +36,7 @@
                catch (NullPointerException e) {
                        // yea, i know, don't catch NPEs .. but _some_ JVMs don't
                        // throw the NFE like they are supposed to (*cough* kaffe)
-                       throw new NumberFormatException(""+e);
+                       throw new NumberFormatException(e+" while converting 
"+pAsHexString+","+qAsHexString+" and "+gAsHexString+" to integers");
                }
        }
     

Index: DSAPublicKey.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/crypt/DSAPublicKey.java,v
retrieving revision 1.1.1.1.4.1.2.1
retrieving revision 1.1.1.1.4.1.2.2
diff -u -w -r1.1.1.1.4.1.2.1 -r1.1.1.1.4.1.2.2
--- DSAPublicKey.java   9 Jul 2003 00:38:47 -0000       1.1.1.1.4.1.2.1
+++ DSAPublicKey.java   28 Oct 2003 20:20:30 -0000      1.1.1.1.4.1.2.2
@@ -10,11 +10,14 @@
     private final String yAsHexString; //A cache of the hexadecimal string 
representation of y 
     private final DSAGroup group;
     
+       private byte[] fingerprint = null;
+    
     public DSAPublicKey(DSAGroup g, BigInteger y) {
                this.y=y;
                this.yAsHexString = y.toString(16);
                this.group=g;
     }
+       
     //Use this constructor if you have a Hex:ed version of y already available, will 
save some conversions and string allocations
        public DSAPublicKey(DSAGroup g, String yAsHexString) throws 
NumberFormatException {
                this.y=new BigInteger(yAsHexString,16);
@@ -119,7 +122,11 @@
     }
 
     public byte[] fingerprint() {
-               return fingerprint(new BigInteger[] {y});
+               synchronized(this) {
+                       if(fingerprint == null)
+                               fingerprint = fingerprint(new BigInteger[] {y});
+                       return fingerprint;
+               }
     }
        
     public boolean equals(DSAPublicKey o) {

Index: DSASignature.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/crypt/DSASignature.java,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.6.1
diff -u -w -r1.1.1.1 -r1.1.1.1.6.1
--- DSASignature.java   13 Jan 2002 05:24:24 -0000      1.1.1.1
+++ DSASignature.java   28 Oct 2003 20:20:30 -0000      1.1.1.1.6.1
@@ -8,6 +8,7 @@
 public class DSASignature implements CryptoElement, java.io.Serializable {
 
     private final BigInteger r, s;
+    private String toStringCached; //toString() cache 
 
     public DSASignature(InputStream in) throws IOException {
        r=Util.readMPI(in);
@@ -53,6 +54,8 @@
     public DSASignature(BigInteger r, BigInteger s) {
        this.r=r;
        this.s=s;
+               if(r == null || s == null) //Do not allow this sice we wont do any 
sanity checking beyond this place
+                       throw new NullPointerException();
     }
 
     public BigInteger getR() {
@@ -68,7 +71,9 @@
         //sb.append(r.toString(16).toUpperCase()).append(',');
         //sb.append(s.toString(16).toUpperCase());
         //return sb.toString();
-        return r.toString(16) + "," + s.toString(16);
+               if(toStringCached == null)
+                       toStringCached = r.toString(16) + "," + s.toString(16);
+        return toStringCached;
     }
                  
 }

Index: DiffieHellman.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/crypt/DiffieHellman.java,v
retrieving revision 1.2.6.1
retrieving revision 1.2.6.2
diff -u -w -r1.2.6.1 -r1.2.6.2
--- DiffieHellman.java  4 Jul 2003 02:45:06 -0000       1.2.6.1
+++ DiffieHellman.java  28 Oct 2003 20:20:30 -0000      1.2.6.2
@@ -13,7 +13,7 @@
 
 public class DiffieHellman {
     private static final int PRECALC = 15;
-    private static Random r = Core.randSource;
+    private static Random r = Core.getRandSource();
     private static DHGroup group = Global.DHgroupA;
     private static Stack precalcBuffer = new Stack();
 

Index: Yarrow.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/crypt/Yarrow.java,v
retrieving revision 1.7.6.1
retrieving revision 1.7.6.2
diff -u -w -r1.7.6.1 -r1.7.6.2
--- Yarrow.java 9 Apr 2003 20:30:51 -0000       1.7.6.1
+++ Yarrow.java 28 Oct 2003 20:20:30 -0000      1.7.6.2
@@ -39,7 +39,7 @@
  *
  * @author Scott G. Miller <[EMAIL PROTECTED]>
  */
-public final class Yarrow extends RandomSource {
+public class Yarrow extends RandomSource {
 
     /**
      * Security parameters
@@ -82,14 +82,18 @@
            consumeString(java.net.InetAddress.getLocalHost().toString());
        } catch (Exception e) {}
 
+       readStartupEntropy(startupEntropy);
+
+       read_seed(seed);
+    }
+
+    protected void readStartupEntropy(EntropySource startupEntropy) {
        // Consume the current time
        acceptEntropy(startupEntropy, System.currentTimeMillis(), 0);
        // Free memory
        acceptEntropy(startupEntropy, Runtime.getRuntime().freeMemory(), 0);
        // Total memory
        acceptEntropy(startupEntropy, Runtime.getRuntime().totalMemory(), 0);
-
-       read_seed(seed);
     }
 
     /**
@@ -374,7 +378,9 @@
        rekey(tmp);
        Util.wipe(v0);
        fast_entropy=0;
+       if (! (seedfile.toString()).equals("/dev/urandom")) {
        write_seed(seedfile);
+    }
     }
 
     private void slow_pool_reseed() {

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to