Author: nextgens
Date: 2008-11-21 01:14:01 +0000 (Fri, 21 Nov 2008)
New Revision: 23766

Modified:
   trunk/freenet/src/freenet/crypt/Yarrow.java
Log:
Add a new flag to Yarrow's constructor in order to disable startup reseeding 
(to make its behaviour deterministic)

TO NOT USE IT ANYWHERE BUT IN UNIT TESTS!

Modified: trunk/freenet/src/freenet/crypt/Yarrow.java
===================================================================
--- trunk/freenet/src/freenet/crypt/Yarrow.java 2008-11-21 00:56:19 UTC (rev 
23765)
+++ trunk/freenet/src/freenet/crypt/Yarrow.java 2008-11-21 01:14:01 UTC (rev 
23766)
@@ -71,8 +71,12 @@
        public Yarrow(String seed, String digest, String cipher, boolean 
updateSeed, boolean canBlock) {
                this(new File(seed), digest, cipher, updateSeed, canBlock);
        }
-
+       
        public Yarrow(File seed, String digest, String cipher, boolean 
updateSeed, boolean canBlock) {
+               this(seed, digest, cipher, updateSeed, canBlock, true);
+       }
+       
+       public Yarrow(File seed, String digest, String cipher, boolean 
updateSeed, boolean canBlock, boolean reseedOnStartup) {
                SecureRandom s;
                try {
                        s = SecureRandom.getInstance("SHA1PRNG");
@@ -88,18 +92,23 @@
                        Logger.error(this, "Could not init pools trying to 
getInstance(" + digest + "): " + e, e);
                        throw new RuntimeException("Cannot initialize Yarrow!: 
" + e, e);
                }
-               entropy_init(seed);
-               seedFromExternalStuff(canBlock);
+               
                if(updateSeed && !(seed.toString()).equals("/dev/urandom")) 
//Dont try to update the seedfile if we know that it wont be possible anyways 
                        seedfile = seed;
                else
                        seedfile = null;
-               /**
-                * If we don't reseed at this point, we will be predictable,
-                * because the startup entropy won't cause a reseed.
-                */
-               fast_pool_reseed();
-               slow_pool_reseed();
+               if(reseedOnStartup) {
+                       entropy_init(seed);
+                       seedFromExternalStuff(canBlock);
+                       /**
+                        * If we don't reseed at this point, we will be 
predictable,
+                        * because the startup entropy won't cause a reseed.
+                        */
+                       fast_pool_reseed();
+                       slow_pool_reseed();
+               } else {
+                       read_seed(seed);
+               }
        }
 
        private void seedFromExternalStuff(boolean canBlock) {

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to