diff --git a/LICENSE.txt b/LICENSE.txt index 2788d2e27..766691a55 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -36,7 +36,7 @@ Public domain except as listed below: Copyright (c) 2003, TheCrypto See licenses/LICENSE-ElGamalDSA.txt - SHA256 and HMAC: + HMAC: Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle See licenses/LICENSE-SHA256.txt @@ -64,7 +64,7 @@ Public domain except as listed below: Copyright 2006 Gregory Rubin grrubin@gmail.com See licenses/LICENSE-HashCash.txt - GettextResource from gettext v0.18: + GettextResource from gettext v0.19.8: Copyright (C) 2001, 2007 Free Software Foundation, Inc. See licenses/LICENSE-LGPLv2.1.txt @@ -161,6 +161,8 @@ Jbigi Libraries (jbigi.jar): GMP 4.3.2 / 5.0.2: Copyright 1991, 1996, 1999, 2000, 2007 Free Software Foundation, Inc. See licenses/LICENSE-LGPLv3.txt + GMP 6.0.0: + See licenses/LICENSE-GPLv2.txt Applications: diff --git a/core/java/src/gnu/crypto/hash/BaseHashStandalone.java b/core/java/src/gnu/crypto/hash/BaseHashStandalone.java deleted file mode 100644 index 4c77ff9d3..000000000 --- a/core/java/src/gnu/crypto/hash/BaseHashStandalone.java +++ /dev/null @@ -1,205 +0,0 @@ -package gnu.crypto.hash; - -// ---------------------------------------------------------------------------- -// $Id: BaseHashStandalone.java,v 1.1 2006/02/26 16:30:59 jrandom Exp $ -// -// Copyright (C) 2001, 2002, Free Software Foundation, Inc. -// -// This file is part of GNU Crypto. -// -// GNU Crypto is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2, or (at your option) -// any later version. -// -// GNU Crypto is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, write to the -// -// Free Software Foundation Inc., -// 51 Franklin Street, Fifth Floor, -// Boston, MA 02110-1301 -// USA -// -// Linking this library statically or dynamically with other modules is -// making a combined work based on this library. Thus, the terms and -// conditions of the GNU General Public License cover the whole -// combination. -// -// As a special exception, the copyright holders of this library give -// you permission to link this library with independent modules to -// produce an executable, regardless of the license terms of these -// independent modules, and to copy and distribute the resulting -// executable under terms of your choice, provided that you also meet, -// for each linked independent module, the terms and conditions of the -// license of that module. An independent module is a module which is -// not derived from or based on this library. If you modify this -// library, you may extend this exception to your version of the -// library, but you are not obligated to do so. If you do not wish to -// do so, delete this exception statement from your version. -// ---------------------------------------------------------------------------- - -/** - *
A base abstract class to facilitate hash implementations.
- * - * WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a - * MessageDigest that will be faster in almost all cases. - * See SHA256Generator for more information. - * - * @version $Revision: 1.1 $ - * @deprecated to be removed in 0.9.27 - */ -@Deprecated -public abstract class BaseHashStandalone implements IMessageDigestStandalone { - - // Constants and variables - // ------------------------------------------------------------------------- - - /** The canonical name prefix of the hash. */ - protected String name; - - /** The hash (output) size in bytes. */ - protected int hashSize; - - /** The hash (inner) block size in bytes. */ - protected int blockSize; - - /** Number of bytes processed so far. */ - protected long count; - - /** Temporary input buffer. */ - protected byte[] buffer; - - // Constructor(s) - // ------------------------------------------------------------------------- - - /** - *Trivial constructor for use by concrete subclasses.
- * - * @param name the canonical name prefix of this instance. - * @param hashSize the block size of the output in bytes. - * @param blockSize the block size of the internal transform. - */ - protected BaseHashStandalone(String name, int hashSize, int blockSize) { - super(); - - this.name = name; - this.hashSize = hashSize; - this.blockSize = blockSize; - this.buffer = new byte[blockSize]; - - resetContext(); - } - - // Class methods - // ------------------------------------------------------------------------- - - // Instance methods - // ------------------------------------------------------------------------- - - // IMessageDigestStandalone interface implementation --------------------------------- - - public String name() { - return name; - } - - public int hashSize() { - return hashSize; - } - - public int blockSize() { - return blockSize; - } - - public void update(byte b) { - // compute number of bytes still unhashed; ie. present in buffer - int i = (int)(count % blockSize); - count++; - buffer[i] = b; - if (i == (blockSize - 1)) { - transform(buffer, 0); - } - } - - public void update(byte[] b) { - update(b, 0, b.length); - } - - public void update(byte[] b, int offset, int len) { - int n = (int)(count % blockSize); - count += len; - int partLen = blockSize - n; - int i = 0; - - if (len >= partLen) { - System.arraycopy(b, offset, buffer, n, partLen); - transform(buffer, 0); - for (i = partLen; i + blockSize - 1 < len; i+= blockSize) { - transform(b, offset + i); - } - n = 0; - } - - if (i < len) { - System.arraycopy(b, offset + i, buffer, n, len - i); - } - } - - public byte[] digest() { - byte[] tail = padBuffer(); // pad remaining bytes in buffer - update(tail, 0, tail.length); // last transform of a message - byte[] result = getResult(); // make a result out of context - - reset(); // reset this instance for future re-use - - return result; - } - - public void reset() { // reset this instance for future re-use - count = 0L; - for (int i = 0; i < blockSize; ) { - buffer[i++] = 0; - } - - resetContext(); - } - - // methods to be implemented by concrete subclasses ------------------------ - - @Override - public abstract Object clone(); - - public abstract boolean selfTest(); - - /** - *Returns the byte array to use as padding before completing a hash - * operation.
- * - * @return the bytes to pad the remaining bytes in the buffer before - * completing a hash operation. - */ - protected abstract byte[] padBuffer(); - - /** - *Constructs the result from the contents of the current context.
- * - * @return the output of the completed hash operation. - */ - protected abstract byte[] getResult(); - - /** Resets the instance for future re-use. */ - protected abstract void resetContext(); - - /** - *The block digest transformation per se.
- * - * @param in the blockSize long block, as an array of bytes to digest. - * @param offset the index where the data to digest is located within the - * input buffer. - */ - protected abstract void transform(byte[] in, int offset); -} diff --git a/core/java/src/gnu/crypto/hash/IMessageDigestStandalone.java b/core/java/src/gnu/crypto/hash/IMessageDigestStandalone.java deleted file mode 100644 index b19b3ac8b..000000000 --- a/core/java/src/gnu/crypto/hash/IMessageDigestStandalone.java +++ /dev/null @@ -1,147 +0,0 @@ -package gnu.crypto.hash; - -// ---------------------------------------------------------------------------- -// $Id: IMessageDigestStandalone.java,v 1.1 2006/02/26 16:30:59 jrandom Exp $ -// -// Copyright (C) 2001, 2002, Free Software Foundation, Inc. -// -// This file is part of GNU Crypto. -// -// GNU Crypto is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2, or (at your option) -// any later version. -// -// GNU Crypto is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, write to the -// -// Free Software Foundation Inc., -// 51 Franklin Street, Fifth Floor, -// Boston, MA 02110-1301 -// USA -// -// Linking this library statically or dynamically with other modules is -// making a combined work based on this library. Thus, the terms and -// conditions of the GNU General Public License cover the whole -// combination. -// -// As a special exception, the copyright holders of this library give -// you permission to link this library with independent modules to -// produce an executable, regardless of the license terms of these -// independent modules, and to copy and distribute the resulting -// executable under terms of your choice, provided that you also meet, -// for each linked independent module, the terms and conditions of the -// license of that module. An independent module is a module which is -// not derived from or based on this library. If you modify this -// library, you may extend this exception to your version of the -// library, but you are not obligated to do so. If you do not wish to -// do so, delete this exception statement from your version. -// ---------------------------------------------------------------------------- - -/** - *The basic visible methods of any hash algorithm.
- * - *A hash (or message digest) algorithm produces its output by iterating a - * basic compression function on blocks of data.
- * - * WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a - * MessageDigest that will be faster in almost all cases. - * See SHA256Generator for more information. - * - * @version $Revision: 1.1 $ - * @deprecated to be removed in 0.9.27 - */ -@Deprecated -public interface IMessageDigestStandalone extends Cloneable { - - // Constants - // ------------------------------------------------------------------------- - - // Methods - // ------------------------------------------------------------------------- - - /** - *Returns the canonical name of this algorithm.
- * - * @return the canonical name of this instance. - */ - String name(); - - /** - *Returns the output length in bytes of this message digest algorithm.
- * - * @return the output length in bytes of this message digest algorithm. - */ - int hashSize(); - - /** - *Returns the algorithm's (inner) block size in bytes.
- * - * @return the algorithm's inner block size in bytes. - */ - int blockSize(); - - /** - *Continues a message digest operation using the input byte.
- * - * @param b the input byte to digest. - */ - void update(byte b); - - /** - *Continues a message digest operation, by filling the buffer, processing - * data in the algorithm's HASH_SIZE-bit block(s), updating the context and - * count, and buffering the remaining bytes in buffer for the next - * operation.
- * - * @param in the input block. - */ - void update(byte[] in); - - /** - *Continues a message digest operation, by filling the buffer, processing - * data in the algorithm's HASH_SIZE-bit block(s), updating the context and - * count, and buffering the remaining bytes in buffer for the next - * operation.
- * - * @param in the input block. - * @param offset start of meaningful bytes in input block. - * @param length number of bytes, in input block, to consider. - */ - void update(byte[] in, int offset, int length); - - /** - *Completes the message digest by performing final operations such as - * padding and resetting the instance.
- * - * @return the array of bytes representing the hash value. - */ - byte[] digest(); - - /** - *Resets the current context of this instance clearing any eventually cached - * intermediary values.
- */ - void reset(); - - /** - *A basic test. Ensures that the digest of a pre-determined message is equal - * to a known pre-computed value.
- * - * @return true if the implementation passes a basic self-test. - * Returns false otherwise. - */ - boolean selfTest(); - - /** - *Returns a clone copy of this instance.
- * - * @return a clone copy of this instance. - */ - Object clone(); -} diff --git a/core/java/src/gnu/crypto/hash/Sha256Standalone.java b/core/java/src/gnu/crypto/hash/Sha256Standalone.java deleted file mode 100644 index a966b20cf..000000000 --- a/core/java/src/gnu/crypto/hash/Sha256Standalone.java +++ /dev/null @@ -1,282 +0,0 @@ -package gnu.crypto.hash; - -// ---------------------------------------------------------------------------- -// $Id: Sha256Standalone.java,v 1.2 2006/03/16 16:45:19 jrandom Exp $ -// -// Copyright (C) 2003 Free Software Foundation, Inc. -// -// This file is part of GNU Crypto. -// -// GNU Crypto is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2, or (at your option) -// any later version. -// -// GNU Crypto is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; see the file COPYING. If not, write to the -// -// Free Software Foundation Inc., -// 51 Franklin Street, Fifth Floor, -// Boston, MA 02110-1301 -// USA -// -// Linking this library statically or dynamically with other modules is -// making a combined work based on this library. Thus, the terms and -// conditions of the GNU General Public License cover the whole -// combination. -// -// As a special exception, the copyright holders of this library give -// you permission to link this library with independent modules to -// produce an executable, regardless of the license terms of these -// independent modules, and to copy and distribute the resulting -// executable under terms of your choice, provided that you also meet, -// for each linked independent module, the terms and conditions of the -// license of that module. An independent module is a module which is -// not derived from or based on this library. If you modify this -// library, you may extend this exception to your version of the -// library, but you are not obligated to do so. If you do not wish to -// do so, delete this exception statement from your version. -// ---------------------------------------------------------------------------- - -//import gnu.crypto.util.Util; - -/** - *Implementation of SHA2-1 [SHA-256] per the IETF Draft Specification.
- * - *References:
- *Private constructor for cloning purposes.
- * - * @param md the instance to clone. - */ - private Sha256Standalone(Sha256Standalone md) { - this(); - - this.h0 = md.h0; - this.h1 = md.h1; - this.h2 = md.h2; - this.h3 = md.h3; - this.h4 = md.h4; - this.h5 = md.h5; - this.h6 = md.h6; - this.h7 = md.h7; - this.count = md.count; - this.buffer = md.buffer.clone(); - } - - // Class methods - // ------------------------------------------------------------------------- - - /* - public static final int[] G(int hh0, int hh1, int hh2, int hh3, int hh4, - int hh5, int hh6, int hh7, byte[] in, int offset) { - return sha(hh0, hh1, hh2, hh3, hh4, hh5, hh6, hh7, in, offset); - } - */ - - // Instance methods - // ------------------------------------------------------------------------- - - // java.lang.Cloneable interface implementation ---------------------------- - - public Object clone() { - return new Sha256Standalone(this); - } - - // Implementation of concrete methods in BaseHashStandalone -------------------------- - - private int transformResult[] = new int[8]; - protected void transform(byte[] in, int offset) { - //int[] result = sha(h0, h1, h2, h3, h4, h5, h6, h7, in, offset); - sha(h0, h1, h2, h3, h4, h5, h6, h7, in, offset, transformResult); - - h0 = transformResult[0]; - h1 = transformResult[1]; - h2 = transformResult[2]; - h3 = transformResult[3]; - h4 = transformResult[4]; - h5 = transformResult[5]; - h6 = transformResult[6]; - h7 = transformResult[7]; - } - - protected byte[] padBuffer() { - int n = (int) (count % BLOCK_SIZE); - int padding = (n < 56) ? (56 - n) : (120 - n); - byte[] result = new byte[padding + 8]; - - // padding is always binary 1 followed by binary 0s - result[0] = (byte) 0x80; - - // save number of bits, casting the long to an array of 8 bytes - long bits = count << 3; - result[padding++] = (byte)(bits >>> 56); - result[padding++] = (byte)(bits >>> 48); - result[padding++] = (byte)(bits >>> 40); - result[padding++] = (byte)(bits >>> 32); - result[padding++] = (byte)(bits >>> 24); - result[padding++] = (byte)(bits >>> 16); - result[padding++] = (byte)(bits >>> 8); - result[padding ] = (byte) bits; - - return result; - } - - protected byte[] getResult() { - return new byte[] { - (byte)(h0 >>> 24), (byte)(h0 >>> 16), (byte)(h0 >>> 8), (byte) h0, - (byte)(h1 >>> 24), (byte)(h1 >>> 16), (byte)(h1 >>> 8), (byte) h1, - (byte)(h2 >>> 24), (byte)(h2 >>> 16), (byte)(h2 >>> 8), (byte) h2, - (byte)(h3 >>> 24), (byte)(h3 >>> 16), (byte)(h3 >>> 8), (byte) h3, - (byte)(h4 >>> 24), (byte)(h4 >>> 16), (byte)(h4 >>> 8), (byte) h4, - (byte)(h5 >>> 24), (byte)(h5 >>> 16), (byte)(h5 >>> 8), (byte) h5, - (byte)(h6 >>> 24), (byte)(h6 >>> 16), (byte)(h6 >>> 8), (byte) h6, - (byte)(h7 >>> 24), (byte)(h7 >>> 16), (byte)(h7 >>> 8), (byte) h7 - }; - } - - protected void resetContext() { - // magic SHA-256 initialisation constants - h0 = 0x6a09e667; - h1 = 0xbb67ae85; - h2 = 0x3c6ef372; - h3 = 0xa54ff53a; - h4 = 0x510e527f; - h5 = 0x9b05688c; - h6 = 0x1f83d9ab; - h7 = 0x5be0cd19; - } - - public boolean selfTest() { - if (valid == null) { - Sha256Standalone md = new Sha256Standalone(); - md.update((byte) 0x61); // a - md.update((byte) 0x62); // b - md.update((byte) 0x63); // c - String result = "broken"; //Util.toString(md.digest()); - valid = Boolean.valueOf(DIGEST0.equals(result)); - } - - return valid.booleanValue(); - } - - // SHA specific methods ---------------------------------------------------- - - private static final synchronized void - sha(int hh0, int hh1, int hh2, int hh3, int hh4, int hh5, int hh6, int hh7, byte[] in, int offset, int out[]) { - int A = hh0; - int B = hh1; - int C = hh2; - int D = hh3; - int E = hh4; - int F = hh5; - int G = hh6; - int H = hh7; - int r, T, T2; - - for (r = 0; r < 16; r++) { - w[r] = in[offset++] << 24 | - (in[offset++] & 0xFF) << 16 | - (in[offset++] & 0xFF) << 8 | - (in[offset++] & 0xFF); - } - for (r = 16; r < 64; r++) { - T = w[r - 2]; - T2 = w[r - 15]; - w[r] = (((T >>> 17) | (T << 15)) ^ ((T >>> 19) | (T << 13)) ^ (T >>> 10)) + w[r - 7] + (((T2 >>> 7) | (T2 << 25)) ^ ((T2 >>> 18) | (T2 << 14)) ^ (T2 >>> 3)) + w[r - 16]; - } - - for (r = 0; r < 64; r++) { - T = H + (((E >>> 6) | (E << 26)) ^ ((E >>> 11) | (E << 21)) ^ ((E >>> 25) | (E << 7))) + ((E & F) ^ (~E & G)) + k[r] + w[r]; - T2 = (((A >>> 2) | (A << 30)) ^ ((A >>> 13) | (A << 19)) ^ ((A >>> 22) | (A << 10))) + ((A & B) ^ (A & C) ^ (B & C)); - H = G; - G = F; - F = E; - E = D + T; - D = C; - C = B; - B = A; - A = T + T2; - } - - /* - return new int[] { - hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, hh5 + F, hh6 + G, hh7 + H - }; - */ - out[0] = hh0 + A; - out[1] = hh1 + B; - out[2] = hh2 + C; - out[3] = hh3 + D; - out[4] = hh4 + E; - out[5] = hh5 + F; - out[6] = hh6 + G; - out[7] = hh7 + H; - } -} diff --git a/core/java/src/gnu/crypto/hash/package.html b/core/java/src/gnu/crypto/hash/package.html deleted file mode 100644 index bf26a4ab3..000000000 --- a/core/java/src/gnu/crypto/hash/package.html +++ /dev/null @@ -1,13 +0,0 @@ - --WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a -MessageDigest that will be faster in almost all cases. -
-This is the old GNU SHA-256 Hash implementation. -It is deprecated and mostly unused, unless the java.security.MessageDigest -implementation for SHA-256 is not available in the JVM. -And it always should be, right? -Do not instantiate this directly - use I2PAppContext.sha(). -See net.i2p.crypto.SHA256Generator for more information and test results. -
- diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index 6fa421fd4..84b77ae4a 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -9,8 +9,6 @@ package net.i2p.data; * */ -import gnu.crypto.hash.Sha256Standalone; - import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; @@ -1318,26 +1316,6 @@ public class DataHelper { */ public static String readLine(InputStream in) throws IOException { return readLine(in, (MessageDigest) null); } - /** - * update the hash along the way - * Warning - strips \n but not \r - * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded - * Warning - not UTF-8 - * - * @param hash null OK - * @return null on EOF - * @deprecated use MessageDigest version to be removed in 0.9.27 - */ - @Deprecated - public static String readLine(InputStream in, Sha256Standalone hash) throws IOException { - StringBuilder buf = new StringBuilder(128); - boolean ok = readLine(in, buf, hash); - if (ok) - return buf.toString(); - else - return null; - } - /** * update the hash along the way * Warning - strips \n but not \r @@ -1357,49 +1335,9 @@ public class DataHelper { return null; } - /** - * Read in a line, placing it into the buffer (excluding the newline). - * Warning - strips \n but not \r - * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded - * Warning - not UTF-8 - * - * @deprecated use StringBuilder version - * @return true if the line was read, false if eof was reached on an empty line - * (returns true for non-empty last line without a newline) - */ - @Deprecated - public static boolean readLine(InputStream in, StringBuffer buf) throws IOException { - return readLine(in, buf, null); - } - /** ridiculously long, just to prevent OOM DOS @since 0.7.13 */ private static final int MAX_LINE_LENGTH = 8*1024; - /** - * update the hash along the way - * Warning - strips \n but not \r - * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded - * Warning - not UTF-8 - * - * @return true if the line was read, false if eof was reached on an empty line - * (returns true for non-empty last line without a newline) - * @deprecated use StringBuilder / MessageDigest version, to be removed in 0.9.27 - */ - @Deprecated - public static boolean readLine(InputStream in, StringBuffer buf, Sha256Standalone hash) throws IOException { - int c = -1; - int i = 0; - while ( (c = in.read()) != -1) { - if (++i > MAX_LINE_LENGTH) - throw new IOException("Line too long - max " + MAX_LINE_LENGTH); - if (hash != null) hash.update((byte)c); - if (c == '\n') - break; - buf.append((char)c); - } - return c != -1 || i > 0; - } - /** * Read in a line, placing it into the buffer (excluding the newline). * Warning - strips \n but not \r @@ -1412,33 +1350,6 @@ public class DataHelper { public static boolean readLine(InputStream in, StringBuilder buf) throws IOException { return readLine(in, buf, (MessageDigest) null); } - - /** - * update the hash along the way - * Warning - strips \n but not \r - * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded - * Warning - not UTF-8 - * - * - * @param hash null OK - * @return true if the line was read, false if eof was reached on an empty line - * (returns true for non-empty last line without a newline) - * @deprecated use MessageDigest version, to be removed in 0.9.27 - */ - @Deprecated - public static boolean readLine(InputStream in, StringBuilder buf, Sha256Standalone hash) throws IOException { - int c = -1; - int i = 0; - while ( (c = in.read()) != -1) { - if (++i > MAX_LINE_LENGTH) - throw new IOException("Line too long - max " + MAX_LINE_LENGTH); - if (hash != null) hash.update((byte)c); - if (c == '\n') - break; - buf.append((char)c); - } - return c != -1 || i > 0; - } /** * update the hash along the way @@ -1465,16 +1376,6 @@ public class DataHelper { return c != -1 || i > 0; } - /** - * update the hash along the way - * @deprecated use MessageDigest version, to be removed in 0.9.27 - */ - @Deprecated - public static void write(OutputStream out, byte data[], Sha256Standalone hash) throws IOException { - hash.update(data); - out.write(data); - } - /** * update the hash along the way * @since 0.8.8