[freenet-cvs] r13677 - trunk/freenet/src/freenet/node

nextgens at freenetproject.org nextgens at freenetproject.org
Thu Jun 21 09:26:28 UTC 2007


Author: nextgens
Date: 2007-06-21 09:26:28 +0000 (Thu, 21 Jun 2007)
New Revision: 13677

Modified:
   trunk/freenet/src/freenet/node/FNPPacketMangler.java
   trunk/freenet/src/freenet/node/Node.java
Log:
Implement 1445: Use a mersenne twister or something for packet padding, not Yarrow

Both the padding length and the padding itself are generated from MT... MT is seeded once for all at node's startup; it should be enough for our purpose as the period is 2^19937 - 1 (analysis of the randomness probably costy enough).

Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java	2007-06-20 23:09:21 UTC (rev 13676)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java	2007-06-21 09:26:28 UTC (rev 13677)
@@ -438,7 +438,7 @@
         BlockCipher cipher = pn.outgoingSetupCipher;
         if(logMINOR) Logger.minor(this, "Outgoing cipher: "+HexUtil.bytesToHex(pn.outgoingSetupKey));
         PCFBMode pcfb = PCFBMode.create(cipher);
-        int paddingLength = node.random.nextInt(100);
+        int paddingLength = node.fastWeakRandom.nextInt(100);
         byte[] iv = new byte[pcfb.lengthIV()];
         node.random.nextBytes(iv);
         byte[] hash = SHA256.digest(output);
@@ -454,8 +454,7 @@
         pcfb.blockEncipher(output, 0, output.length);
         System.arraycopy(output, 0, data, hash.length+iv.length+2, output.length);
         byte[] random = new byte[paddingLength];
-        // FIXME don't use node.random
-        node.random.nextBytes(random);
+        node.fastWeakRandom.nextBytes(random);
         System.arraycopy(random, 0, data, hash.length+iv.length+2+output.length, random.length);
         try {
         	sendPacket(data, replyTo, pn, 0);
@@ -1254,11 +1253,11 @@
         // Ideally we'd mimic the size profile - and the session bytes! - of a common protocol.
         
         int paddedLen = ((packetLength + 63) / 64) * 64;
-        paddedLen += node.random.nextInt(64);
+        paddedLen += node.fastWeakRandom.nextInt(64);
         if(packetLength <= 1280 && paddedLen > 1280) paddedLen = 1280;
 
         byte[] padding = new byte[paddedLen - packetLength];
-        node.random.nextBytes(padding);
+        node.fastWeakRandom.nextBytes(padding);
         
         packetLength = paddedLen;
         

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java	2007-06-20 23:09:21 UTC (rev 13676)
+++ trunk/freenet/src/freenet/node/Node.java	2007-06-21 09:26:28 UTC (rev 13677)
@@ -28,10 +28,12 @@
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.MissingResourceException;
+import java.util.Random;
 import java.util.zip.DeflaterOutputStream;
 
 import net.i2p.util.NativeBigInteger;
 
+import org.spaceroots.mantissa.random.MersenneTwister;
 import org.tanukisoftware.wrapper.WrapperManager;
 
 import com.sleepycat.je.DatabaseException;
@@ -318,7 +320,6 @@
 	private DSAPrivateKey myPrivKey;
 	/** My public key */
 	private DSAPublicKey myPubKey;
-	
 	/** My ARK SSK private key */
 	InsertableClientSSK myARK;
 	/** My ARK sequence number */
@@ -370,6 +371,8 @@
 	final File extraPeerDataDir;
 	/** Strong RNG */
 	public final RandomSource random;
+	/** Weak but fast RNG */
+	public final Random fastWeakRandom;
 	final UdpSocketManager usm;
 	final FNPPacketMangler packetMangler;
 	final DNSRequester dnsr;
@@ -732,6 +735,8 @@
 		recentlyCompletedIDs = new LRUQueue();
 		this.config = config;
 		this.random = random;
+		// Seeding it with anything longer than an int is useless
+		this.fastWeakRandom = new MersenneTwister(random.nextInt());
 		cachedPubKeys = new LRUHashtable();
 		lm = new LocationManager(random);
 




More information about the cvs mailing list