Author: j16sdiz
Date: 2008-05-04 09:43:00 +0000 (Sun, 04 May 2008)
New Revision: 19725

Modified:
   trunk/freenet/src/freenet/keys/ClientKSK.java
   trunk/freenet/src/freenet/keys/ClientSSK.java
   trunk/freenet/src/freenet/keys/InsertableClientSSK.java
   trunk/freenet/src/freenet/support/io/BucketTools.java
Log:
indent


Modified: trunk/freenet/src/freenet/keys/ClientKSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientKSK.java       2008-05-04 09:42:31 UTC 
(rev 19724)
+++ trunk/freenet/src/freenet/keys/ClientKSK.java       2008-05-04 09:43:00 UTC 
(rev 19725)
@@ -36,21 +36,21 @@
        public static ClientKSK create(String keyword) {
                MessageDigest md256 = SHA256.getMessageDigest();
                try {
-               byte[] keywordHash;
-               try {
-                       keywordHash = md256.digest(keyword.getBytes("UTF-8"));
-               } catch (UnsupportedEncodingException e) {
-                       throw new Error(e);
-               }
-               MersenneTwister mt = new MersenneTwister(keywordHash);
-               DSAPrivateKey privKey = new DSAPrivateKey(Global.DSAgroupBigA, 
mt);
-               DSAPublicKey pubKey = new DSAPublicKey(Global.DSAgroupBigA, 
privKey);
-               byte[] pubKeyHash = md256.digest(pubKey.asBytes());
-               try {
-                       return new ClientKSK(keyword, pubKeyHash, pubKey, 
privKey, keywordHash);
-               } catch (MalformedURLException e) {
-                       throw new Error(e);
-               }
+                       byte[] keywordHash;
+                       try {
+                               keywordHash = 
md256.digest(keyword.getBytes("UTF-8"));
+                       } catch (UnsupportedEncodingException e) {
+                               throw new Error(e);
+                       }
+                       MersenneTwister mt = new MersenneTwister(keywordHash);
+                       DSAPrivateKey privKey = new 
DSAPrivateKey(Global.DSAgroupBigA, mt);
+                       DSAPublicKey pubKey = new 
DSAPublicKey(Global.DSAgroupBigA, privKey);
+                       byte[] pubKeyHash = md256.digest(pubKey.asBytes());
+                       try {
+                               return new ClientKSK(keyword, pubKeyHash, 
pubKey, privKey, keywordHash);
+                       } catch (MalformedURLException e) {
+                               throw new Error(e);
+                       }
                } finally {
                        SHA256.returnMessageDigest(md256);
                }

Modified: trunk/freenet/src/freenet/keys/ClientSSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientSSK.java       2008-05-04 09:42:31 UTC 
(rev 19724)
+++ trunk/freenet/src/freenet/keys/ClientSSK.java       2008-05-04 09:43:00 UTC 
(rev 19725)
@@ -52,30 +52,30 @@
                        throw new MalformedURLException("Decryption key wrong 
length: "+cryptoKey.length+" should be "+CRYPTO_KEY_LENGTH);
                MessageDigest md = SHA256.getMessageDigest();
                try {
-               if(pubKey != null) {
-                       byte[] pubKeyAsBytes = pubKey.asBytes();
-                       md.update(pubKeyAsBytes);
-                       byte[] otherPubKeyHash = md.digest();
-                       if(!Arrays.equals(otherPubKeyHash, pubKeyHash))
-                               throw new IllegalArgumentException();
-               }
-               this.cryptoKey = cryptoKey;
-               try {
-                       md.update(docName.getBytes("UTF-8"));
-               } catch (UnsupportedEncodingException e) {
-                       throw new Error(e);
-               }
-               byte[] buf = md.digest();
-               try {
-                       Rijndael aes = new Rijndael(256,256);
-                       aes.initialize(cryptoKey);
-                       aes.encipher(buf, buf);
-                       ehDocname = buf;
-               } catch (UnsupportedCipherException e) {
-                       throw new Error(e);
-               }
+                       if (pubKey != null) {
+                               byte[] pubKeyAsBytes = pubKey.asBytes();
+                               md.update(pubKeyAsBytes);
+                               byte[] otherPubKeyHash = md.digest();
+                               if (!Arrays.equals(otherPubKeyHash, pubKeyHash))
+                                       throw new IllegalArgumentException();
+                       }
+                       this.cryptoKey = cryptoKey;
+                       try {
+                               md.update(docName.getBytes("UTF-8"));
+                       } catch (UnsupportedEncodingException e) {
+                               throw new Error(e);
+                       }
+                       byte[] buf = md.digest();
+                       try {
+                               Rijndael aes = new Rijndael(256, 256);
+                               aes.initialize(cryptoKey);
+                               aes.encipher(buf, buf);
+                               ehDocname = buf;
+                       } catch (UnsupportedCipherException e) {
+                               throw new Error(e);
+                       }
                } finally {
-               SHA256.returnMessageDigest(md);
+                       SHA256.returnMessageDigest(md);
                }
        }


Modified: trunk/freenet/src/freenet/keys/InsertableClientSSK.java
===================================================================
--- trunk/freenet/src/freenet/keys/InsertableClientSSK.java     2008-05-04 
09:42:31 UTC (rev 19724)
+++ trunk/freenet/src/freenet/keys/InsertableClientSSK.java     2008-05-04 
09:43:00 UTC (rev 19725)
@@ -84,105 +84,109 @@
                        throw new SSKEncodeException(e.getMessage(), e);
                }
                // Pad it
-        MessageDigest md256 = SHA256.getMessageDigest();
-        try {
-        byte[] data;
-        // First pad it
-        if(compressedData.length != SSKBlock.DATA_LENGTH) {
-            // Hash the data
-            if(compressedData.length != 0)
-               md256.update(compressedData);
-            byte[] digest = md256.digest();
-            MersenneTwister mt = new MersenneTwister(digest);
-            data = new byte[SSKBlock.DATA_LENGTH];
-            if(compressedData.length > data.length) {
-               throw new RuntimeException("compressedData.length = 
"+compressedData.length+" but data.length="+data.length);
-            }
-            System.arraycopy(compressedData, 0, data, 0, 
compressedData.length);
-            byte[] randomBytes = new 
byte[SSKBlock.DATA_LENGTH-compressedData.length];
-            mt.nextBytes(randomBytes);
-            System.arraycopy(randomBytes, 0, data, compressedData.length, 
SSKBlock.DATA_LENGTH-compressedData.length);
-        } else {
-               data = compressedData;
-        }
-        
-        // Implicit hash of data
-        byte[] origDataHash = md256.digest(data);
+               MessageDigest md256 = SHA256.getMessageDigest();
+               try {
+                       byte[] data;
+                       // First pad it
+                       if (compressedData.length != SSKBlock.DATA_LENGTH) {
+                               // Hash the data
+                               if (compressedData.length != 0)
+                                       md256.update(compressedData);
+                               byte[] digest = md256.digest();
+                               MersenneTwister mt = new 
MersenneTwister(digest);
+                               data = new byte[SSKBlock.DATA_LENGTH];
+                               if (compressedData.length > data.length) {
+                                       throw new 
RuntimeException("compressedData.length = " + compressedData.length + " but 
data.length="
+                                                       + data.length);
+                               }
+                               System.arraycopy(compressedData, 0, data, 0, 
compressedData.length);
+                               byte[] randomBytes = new 
byte[SSKBlock.DATA_LENGTH - compressedData.length];
+                               mt.nextBytes(randomBytes);
+                               System.arraycopy(randomBytes, 0, data, 
compressedData.length, SSKBlock.DATA_LENGTH
+                                               - compressedData.length);
+                       } else {
+                               data = compressedData;
+                       }

-        Rijndael aes;
-        try {
-                       aes = new Rijndael(256, 256);
-               } catch (UnsupportedCipherException e) {
-                       throw new Error("256/256 Rijndael not supported!");
-               }
+                       // Implicit hash of data
+                       byte[] origDataHash = md256.digest(data);

-               // Encrypt data. Data encryption key = H(plaintext data).
-               
-               aes.initialize(origDataHash);
-               PCFBMode pcfb = PCFBMode.create(aes);
-               pcfb.reset(origDataHash);
-               
-               pcfb.blockEncipher(data, 0, data.length);
-               
-               byte[] encryptedDataHash = md256.digest(data);
-               
-        // Create headers
-        
-        byte[] headers = new byte[SSKBlock.TOTAL_HEADERS_LENGTH];
-        // First two bytes = hash ID
-        int x = 0;
-        headers[x++] = (byte) (KeyBlock.HASH_SHA256 >> 8);
-        headers[x++] = (byte) (KeyBlock.HASH_SHA256);
-        // Then crypto ID
-        headers[x++] = (byte) (Key.ALGO_AES_PCFB_256_SHA256 >> 8);
-        headers[x++] = Key.ALGO_AES_PCFB_256_SHA256;
-        // Then E(H(docname))
-               // Copy to headers
-               System.arraycopy(ehDocname, 0, headers, x, ehDocname.length);
-               x += ehDocname.length;
-               // Now the encrypted headers
-               byte[] encryptedHeaders = new 
byte[SSKBlock.ENCRYPTED_HEADERS_LENGTH];
-               System.arraycopy(origDataHash, 0, encryptedHeaders, 0, 
origDataHash.length);
-               int y = origDataHash.length;
-               short len = (short) compressedData.length;
-               if(asMetadata) len |= 32768;
-               encryptedHeaders[y++] = (byte)(len >> 8);
-               encryptedHeaders[y++] = (byte)len;
-               encryptedHeaders[y++] = (byte)(compressionAlgo >> 8);
-               encryptedHeaders[y++] = (byte)compressionAlgo;
-               if(encryptedHeaders.length != y)
-                       throw new IllegalStateException("Have more bytes to 
generate encoding SSK");
-               aes.initialize(cryptoKey);
-               pcfb.reset(ehDocname);
-               pcfb.blockEncipher(encryptedHeaders, 0, 
encryptedHeaders.length);
-               System.arraycopy(encryptedHeaders, 0, headers, x, 
encryptedHeaders.length);
-               x+=encryptedHeaders.length;
-               // Generate implicit overall hash.
-               md256.update(headers, 0, x);
-               md256.update(encryptedDataHash);
-               byte[] overallHash = md256.digest();
-               // Now sign it
-               DSASignature sig = DSA.sign(pubKey.getGroup(), privKey, new 
NativeBigInteger(1, overallHash), r);
-               // Pack R and S into 32 bytes each, and copy to headers.
-               
-               // Then create and return the ClientSSKBlock.
-               byte[] rBuf = truncate(sig.getR().toByteArray(), 
SSKBlock.SIG_R_LENGTH);
-               byte[] sBuf = truncate(sig.getS().toByteArray(), 
SSKBlock.SIG_S_LENGTH);
-               System.arraycopy(rBuf, 0, headers, x, rBuf.length);
-               x+=rBuf.length;
-               System.arraycopy(sBuf, 0, headers, x, sBuf.length);
-               x+=sBuf.length;
-               if(x != SSKBlock.TOTAL_HEADERS_LENGTH)
-                       throw new IllegalStateException("Too long");
-               try {
-                       return new ClientSSKBlock(data, headers, this, false); 
// FIXME set last arg to true to not verify
-               } catch (SSKVerifyException e) {
-                       IllegalStateException exception=new 
IllegalStateException("Impossible encoding error: "+e.getMessage());
-                       exception.initCause(e);
+                       Rijndael aes;
+                       try {
+                               aes = new Rijndael(256, 256);
+                       } catch (UnsupportedCipherException e) {
+                               throw new Error("256/256 Rijndael not 
supported!");
+                       }

-                       throw exception;
-               }
-        } finally {
+                       // Encrypt data. Data encryption key = H(plaintext 
data).
+
+                       aes.initialize(origDataHash);
+                       PCFBMode pcfb = PCFBMode.create(aes);
+                       pcfb.reset(origDataHash);
+
+                       pcfb.blockEncipher(data, 0, data.length);
+
+                       byte[] encryptedDataHash = md256.digest(data);
+
+                       // Create headers
+
+                       byte[] headers = new 
byte[SSKBlock.TOTAL_HEADERS_LENGTH];
+                       // First two bytes = hash ID
+                       int x = 0;
+                       headers[x++] = (byte) (KeyBlock.HASH_SHA256 >> 8);
+                       headers[x++] = (byte) (KeyBlock.HASH_SHA256);
+                       // Then crypto ID
+                       headers[x++] = (byte) (Key.ALGO_AES_PCFB_256_SHA256 >> 
8);
+                       headers[x++] = Key.ALGO_AES_PCFB_256_SHA256;
+                       // Then E(H(docname))
+                       // Copy to headers
+                       System.arraycopy(ehDocname, 0, headers, x, 
ehDocname.length);
+                       x += ehDocname.length;
+                       // Now the encrypted headers
+                       byte[] encryptedHeaders = new 
byte[SSKBlock.ENCRYPTED_HEADERS_LENGTH];
+                       System.arraycopy(origDataHash, 0, encryptedHeaders, 0, 
origDataHash.length);
+                       int y = origDataHash.length;
+                       short len = (short) compressedData.length;
+                       if (asMetadata)
+                               len |= 32768;
+                       encryptedHeaders[y++] = (byte) (len >> 8);
+                       encryptedHeaders[y++] = (byte) len;
+                       encryptedHeaders[y++] = (byte) (compressionAlgo >> 8);
+                       encryptedHeaders[y++] = (byte) compressionAlgo;
+                       if (encryptedHeaders.length != y)
+                               throw new IllegalStateException("Have more 
bytes to generate encoding SSK");
+                       aes.initialize(cryptoKey);
+                       pcfb.reset(ehDocname);
+                       pcfb.blockEncipher(encryptedHeaders, 0, 
encryptedHeaders.length);
+                       System.arraycopy(encryptedHeaders, 0, headers, x, 
encryptedHeaders.length);
+                       x += encryptedHeaders.length;
+                       // Generate implicit overall hash.
+                       md256.update(headers, 0, x);
+                       md256.update(encryptedDataHash);
+                       byte[] overallHash = md256.digest();
+                       // Now sign it
+                       DSASignature sig = DSA.sign(pubKey.getGroup(), privKey, 
new NativeBigInteger(1, overallHash), r);
+                       // Pack R and S into 32 bytes each, and copy to headers.
+
+                       // Then create and return the ClientSSKBlock.
+                       byte[] rBuf = truncate(sig.getR().toByteArray(), 
SSKBlock.SIG_R_LENGTH);
+                       byte[] sBuf = truncate(sig.getS().toByteArray(), 
SSKBlock.SIG_S_LENGTH);
+                       System.arraycopy(rBuf, 0, headers, x, rBuf.length);
+                       x += rBuf.length;
+                       System.arraycopy(sBuf, 0, headers, x, sBuf.length);
+                       x += sBuf.length;
+                       if (x != SSKBlock.TOTAL_HEADERS_LENGTH)
+                               throw new IllegalStateException("Too long");
+                       try {
+                               return new ClientSSKBlock(data, headers, this, 
false); // FIXME set last arg to true to not verify
+                       } catch (SSKVerifyException e) {
+                               IllegalStateException exception = new 
IllegalStateException("Impossible encoding error: "
+                                               + e.getMessage());
+                               exception.initCause(e);
+
+                               throw exception;
+                       }
+               } finally {
                        SHA256.returnMessageDigest(md256);
                }
        }

Modified: trunk/freenet/src/freenet/support/io/BucketTools.java
===================================================================
--- trunk/freenet/src/freenet/support/io/BucketTools.java       2008-05-04 
09:42:31 UTC (rev 19724)
+++ trunk/freenet/src/freenet/support/io/BucketTools.java       2008-05-04 
09:43:00 UTC (rev 19725)
@@ -245,22 +245,23 @@
                try {
                        MessageDigest md = SHA256.getMessageDigest();
                        try { 
-                       long bucketLength = data.size();
-                       long bytesRead = 0;
-                       byte[] buf = new byte[4096];
-                       while((bytesRead < bucketLength) || (bucketLength == 
-1)) {
-                               int readBytes = is.read(buf);
-                               if(readBytes < 0) break;
-                               bytesRead += readBytes;
-                               if(readBytes > 0)
-                                       md.update(buf, 0, readBytes);
-                       }
-                       if((bytesRead < bucketLength) && (bucketLength > 0))
-                               throw new EOFException();
-                       if((bytesRead != bucketLength) && (bucketLength > 0))
-                               throw new IOException("Read "+bytesRead+" but 
bucket length "+bucketLength+ '!');
-                       byte[] retval = md.digest();
-                       return retval;
+                               long bucketLength = data.size();
+                               long bytesRead = 0;
+                               byte[] buf = new byte[4096];
+                               while ((bytesRead < bucketLength) || 
(bucketLength == -1)) {
+                                       int readBytes = is.read(buf);
+                                       if (readBytes < 0)
+                                               break;
+                                       bytesRead += readBytes;
+                                       if (readBytes > 0)
+                                               md.update(buf, 0, readBytes);
+                               }
+                               if ((bytesRead < bucketLength) && (bucketLength 
> 0))
+                                       throw new EOFException();
+                               if ((bytesRead != bucketLength) && 
(bucketLength > 0))
+                                       throw new IOException("Read " + 
bytesRead + " but bucket length " + bucketLength + '!');
+                               byte[] retval = md.digest();
+                               return retval;
                        } finally {
                                SHA256.returnMessageDigest(md);
                        }


Reply via email to