forked from I2P_Developers/i2p.i2p
* Sha256Standalone:
- Use system SHA-256 MessageDigest instead of Sha256Standalone in PRNG - Deprecate DataHelper functions using Sha256Standalone arguments; used only by Syndie - Note deprecation in javadocs
This commit is contained in:
@ -46,6 +46,10 @@ package gnu.crypto.hash;
|
|||||||
/**
|
/**
|
||||||
* <p>A base abstract class to facilitate hash implementations.</p>
|
* <p>A base abstract class to facilitate hash implementations.</p>
|
||||||
*
|
*
|
||||||
|
* 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 $
|
* @version $Revision: 1.1 $
|
||||||
*/
|
*/
|
||||||
public abstract class BaseHashStandalone implements IMessageDigestStandalone {
|
public abstract class BaseHashStandalone implements IMessageDigestStandalone {
|
||||||
|
@ -49,6 +49,10 @@ package gnu.crypto.hash;
|
|||||||
* <p>A hash (or message digest) algorithm produces its output by iterating a
|
* <p>A hash (or message digest) algorithm produces its output by iterating a
|
||||||
* basic compression function on blocks of data.</p>
|
* basic compression function on blocks of data.</p>
|
||||||
*
|
*
|
||||||
|
* 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 $
|
* @version $Revision: 1.1 $
|
||||||
*/
|
*/
|
||||||
public interface IMessageDigestStandalone extends Cloneable {
|
public interface IMessageDigestStandalone extends Cloneable {
|
||||||
|
@ -59,6 +59,10 @@ package gnu.crypto.hash;
|
|||||||
* renamed from Sha256 to avoid conflicts with JVMs using gnu-crypto as their JCE
|
* renamed from Sha256 to avoid conflicts with JVMs using gnu-crypto as their JCE
|
||||||
* provider.
|
* provider.
|
||||||
*
|
*
|
||||||
|
* 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.2 $
|
* @version $Revision: 1.2 $
|
||||||
*/
|
*/
|
||||||
public class Sha256Standalone extends BaseHashStandalone {
|
public class Sha256Standalone extends BaseHashStandalone {
|
||||||
|
13
core/java/src/gnu/crypto/hash/package.html
Normal file
13
core/java/src/gnu/crypto/hash/package.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<html><body>
|
||||||
|
<p>
|
||||||
|
WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a
|
||||||
|
MessageDigest that will be faster in almost all cases.
|
||||||
|
</p><p>
|
||||||
|
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.
|
||||||
|
</p>
|
||||||
|
</body></html>
|
@ -41,19 +41,19 @@ exception statement from your version. */
|
|||||||
|
|
||||||
package gnu.crypto.prng;
|
package gnu.crypto.prng;
|
||||||
|
|
||||||
import gnu.crypto.hash.Sha256Standalone;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.MessageDigest;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.i2p.crypto.CryptixAESKeyCache;
|
import net.i2p.crypto.CryptixAESKeyCache;
|
||||||
import net.i2p.crypto.CryptixRijndael_Algorithm;
|
import net.i2p.crypto.CryptixRijndael_Algorithm;
|
||||||
|
import net.i2p.crypto.SHA256Generator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Fortuna continuously-seeded pseudo-random number generator. This
|
* The Fortuna continuously-seeded pseudo-random number generator. This
|
||||||
@ -93,6 +93,7 @@ import net.i2p.crypto.CryptixRijndael_Algorithm;
|
|||||||
* Renamed from Fortuna to FortunaStandalone so it doesn't conflict with the
|
* Renamed from Fortuna to FortunaStandalone so it doesn't conflict with the
|
||||||
* gnu-crypto implementation, which has been imported into GNU/classpath
|
* gnu-crypto implementation, which has been imported into GNU/classpath
|
||||||
*
|
*
|
||||||
|
* NOTE: As of 0.8.8, uses the java.security.MessageDigest instead of GNU Sha256Standalone
|
||||||
*/
|
*/
|
||||||
public class FortunaStandalone extends BasePRNGStandalone implements Serializable, RandomEventListenerStandalone
|
public class FortunaStandalone extends BasePRNGStandalone implements Serializable, RandomEventListenerStandalone
|
||||||
{
|
{
|
||||||
@ -103,7 +104,7 @@ public class FortunaStandalone extends BasePRNGStandalone implements Serializabl
|
|||||||
static final int NUM_POOLS = 32;
|
static final int NUM_POOLS = 32;
|
||||||
static final int MIN_POOL_SIZE = 64;
|
static final int MIN_POOL_SIZE = 64;
|
||||||
final Generator generator;
|
final Generator generator;
|
||||||
final Sha256Standalone[] pools;
|
final MessageDigest[] pools;
|
||||||
long lastReseed;
|
long lastReseed;
|
||||||
int pool;
|
int pool;
|
||||||
int pool0Count;
|
int pool0Count;
|
||||||
@ -117,9 +118,9 @@ public class FortunaStandalone extends BasePRNGStandalone implements Serializabl
|
|||||||
{
|
{
|
||||||
super("Fortuna i2p");
|
super("Fortuna i2p");
|
||||||
generator = new Generator();
|
generator = new Generator();
|
||||||
pools = new Sha256Standalone[NUM_POOLS];
|
pools = new MessageDigest[NUM_POOLS];
|
||||||
for (int i = 0; i < NUM_POOLS; i++)
|
for (int i = 0; i < NUM_POOLS; i++)
|
||||||
pools[i] = new Sha256Standalone();
|
pools[i] = SHA256Generator.getDigestInstance();
|
||||||
lastReseed = 0;
|
lastReseed = 0;
|
||||||
pool = 0;
|
pool = 0;
|
||||||
pool0Count = 0;
|
pool0Count = 0;
|
||||||
@ -227,7 +228,7 @@ public class FortunaStandalone extends BasePRNGStandalone implements Serializabl
|
|||||||
|
|
||||||
private static final int LIMIT = 1 << 20;
|
private static final int LIMIT = 1 << 20;
|
||||||
|
|
||||||
private final Sha256Standalone hash;
|
private final MessageDigest hash;
|
||||||
private final byte[] counter;
|
private final byte[] counter;
|
||||||
private final byte[] key;
|
private final byte[] key;
|
||||||
/** current encryption key built from the keying material */
|
/** current encryption key built from the keying material */
|
||||||
@ -238,7 +239,7 @@ public class FortunaStandalone extends BasePRNGStandalone implements Serializabl
|
|||||||
public Generator ()
|
public Generator ()
|
||||||
{
|
{
|
||||||
super("Fortuna.generator.i2p");
|
super("Fortuna.generator.i2p");
|
||||||
this.hash = new Sha256Standalone();
|
this.hash = SHA256Generator.getDigestInstance();
|
||||||
counter = new byte[16]; //cipher.defaultBlockSize()];
|
counter = new byte[16]; //cipher.defaultBlockSize()];
|
||||||
buffer = new byte[16]; //cipher.defaultBlockSize()];
|
buffer = new byte[16]; //cipher.defaultBlockSize()];
|
||||||
int keysize = 32;
|
int keysize = 32;
|
||||||
|
@ -90,7 +90,12 @@ public final class SHA256Generator {
|
|||||||
_digests.offer(digest);
|
_digests.offer(digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MessageDigest getDigestInstance() {
|
/**
|
||||||
|
* Return a new MessageDigest from the system libs unless unavailable
|
||||||
|
* in this JVM, in that case return a wrapped GNU Sha256Standalone
|
||||||
|
* @since 0.8.7, public since 0.8.8 for FortunaStandalone
|
||||||
|
*/
|
||||||
|
public static MessageDigest getDigestInstance() {
|
||||||
if (!_useGnu) {
|
if (!_useGnu) {
|
||||||
try {
|
try {
|
||||||
return MessageDigest.getInstance("SHA-256");
|
return MessageDigest.getInstance("SHA-256");
|
||||||
|
@ -26,6 +26,7 @@ import java.io.OutputStreamWriter;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.security.MessageDigest;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -1010,13 +1011,14 @@ public class DataHelper {
|
|||||||
* Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
|
* Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
|
||||||
* Warning - not UTF-8
|
* Warning - not UTF-8
|
||||||
*/
|
*/
|
||||||
public static String readLine(InputStream in) throws IOException { return readLine(in, (Sha256Standalone)null); }
|
public static String readLine(InputStream in) throws IOException { return readLine(in, (MessageDigest) null); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update the hash along the way
|
* update the hash along the way
|
||||||
* Warning - strips \n but not \r
|
* Warning - strips \n but not \r
|
||||||
* Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
|
* Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
|
||||||
* Warning - not UTF-8
|
* Warning - not UTF-8
|
||||||
|
* @deprecated use MessageDigest version
|
||||||
*/
|
*/
|
||||||
public static String readLine(InputStream in, Sha256Standalone hash) throws IOException {
|
public static String readLine(InputStream in, Sha256Standalone hash) throws IOException {
|
||||||
StringBuilder buf = new StringBuilder(128);
|
StringBuilder buf = new StringBuilder(128);
|
||||||
@ -1027,6 +1029,22 @@ public class DataHelper {
|
|||||||
return null;
|
return 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
|
||||||
|
* @since 0.8.8
|
||||||
|
*/
|
||||||
|
public static String readLine(InputStream in, MessageDigest hash) throws IOException {
|
||||||
|
StringBuilder buf = new StringBuilder(128);
|
||||||
|
boolean ok = readLine(in, buf, hash);
|
||||||
|
if (ok)
|
||||||
|
return buf.toString();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read in a line, placing it into the buffer (excluding the newline).
|
* Read in a line, placing it into the buffer (excluding the newline).
|
||||||
* Warning - strips \n but not \r
|
* Warning - strips \n but not \r
|
||||||
@ -1050,7 +1068,7 @@ public class DataHelper {
|
|||||||
* Warning - strips \n but not \r
|
* Warning - strips \n but not \r
|
||||||
* Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
|
* Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
|
||||||
* Warning - not UTF-8
|
* Warning - not UTF-8
|
||||||
* @deprecated use StringBuilder version
|
* @deprecated use StringBuilder / MessageDigest version
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean readLine(InputStream in, StringBuffer buf, Sha256Standalone hash) throws IOException {
|
public static boolean readLine(InputStream in, StringBuffer buf, Sha256Standalone hash) throws IOException {
|
||||||
@ -1080,7 +1098,7 @@ public class DataHelper {
|
|||||||
* newline was found
|
* newline was found
|
||||||
*/
|
*/
|
||||||
public static boolean readLine(InputStream in, StringBuilder buf) throws IOException {
|
public static boolean readLine(InputStream in, StringBuilder buf) throws IOException {
|
||||||
return readLine(in, buf, null);
|
return readLine(in, buf, (MessageDigest) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1088,6 +1106,7 @@ public class DataHelper {
|
|||||||
* Warning - strips \n but not \r
|
* Warning - strips \n but not \r
|
||||||
* Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
|
* Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
|
||||||
* Warning - not UTF-8
|
* Warning - not UTF-8
|
||||||
|
* @deprecated use MessageDigest version
|
||||||
*/
|
*/
|
||||||
public static boolean readLine(InputStream in, StringBuilder buf, Sha256Standalone hash) throws IOException {
|
public static boolean readLine(InputStream in, StringBuilder buf, Sha256Standalone hash) throws IOException {
|
||||||
int c = -1;
|
int c = -1;
|
||||||
@ -1103,10 +1122,44 @@ public class DataHelper {
|
|||||||
return c != -1;
|
return c != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @since 0.8.8
|
||||||
|
*/
|
||||||
|
public static boolean readLine(InputStream in, StringBuilder buf, MessageDigest 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the hash along the way
|
||||||
|
* @deprecated use MessageDigest version
|
||||||
|
*/
|
||||||
public static void write(OutputStream out, byte data[], Sha256Standalone hash) throws IOException {
|
public static void write(OutputStream out, byte data[], Sha256Standalone hash) throws IOException {
|
||||||
hash.update(data);
|
hash.update(data);
|
||||||
out.write(data);
|
out.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the hash along the way
|
||||||
|
* @since 0.8.8
|
||||||
|
*/
|
||||||
|
public static void write(OutputStream out, byte data[], MessageDigest hash) throws IOException {
|
||||||
|
hash.update(data);
|
||||||
|
out.write(data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort based on the Hash of the DataStructure.
|
* Sort based on the Hash of the DataStructure.
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2011-07-08 zzz
|
||||||
|
* NetDB: Fix NPE at startup (ticket #493)
|
||||||
|
* Sha256Standalone:
|
||||||
|
- Use system SHA-256 MessageDigest instead of Sha256Standalone in PRNG
|
||||||
|
- Deprecate DataHelper functions using Sha256Standalone arguments;
|
||||||
|
used only by Syndie
|
||||||
|
- Note deprecation in javadocs
|
||||||
|
|
||||||
2011-07-07 zzz
|
2011-07-07 zzz
|
||||||
* Blockfile:
|
* Blockfile:
|
||||||
- Log error on out-of-order spans
|
- Log error on out-of-order spans
|
||||||
|
@ -18,7 +18,7 @@ public class RouterVersion {
|
|||||||
/** deprecated */
|
/** deprecated */
|
||||||
public final static String ID = "Monotone";
|
public final static String ID = "Monotone";
|
||||||
public final static String VERSION = CoreVersion.VERSION;
|
public final static String VERSION = CoreVersion.VERSION;
|
||||||
public final static long BUILD = 6;
|
public final static long BUILD = 7;
|
||||||
|
|
||||||
/** for example "-test" */
|
/** for example "-test" */
|
||||||
public final static String EXTRA = "";
|
public final static String EXTRA = "";
|
||||||
|
Reference in New Issue
Block a user