* 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:
zzz
2011-07-08 13:51:50 +00:00
parent dd4906258d
commit 32d9204e4a
9 changed files with 104 additions and 12 deletions

View File

@@ -46,6 +46,10 @@ package gnu.crypto.hash;
/**
* <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 $
*/
public abstract class BaseHashStandalone implements IMessageDigestStandalone {

View File

@@ -49,6 +49,10 @@ package gnu.crypto.hash;
* <p>A hash (or message digest) algorithm produces its output by iterating a
* 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 $
*/
public interface IMessageDigestStandalone extends Cloneable {

View File

@@ -59,6 +59,10 @@ package gnu.crypto.hash;
* renamed from Sha256 to avoid conflicts with JVMs using gnu-crypto as their JCE
* 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 $
*/
public class Sha256Standalone extends BaseHashStandalone {

View 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>

View File

@@ -41,19 +41,19 @@ exception statement from your version. */
package gnu.crypto.prng;
import gnu.crypto.hash.Sha256Standalone;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import net.i2p.crypto.CryptixAESKeyCache;
import net.i2p.crypto.CryptixRijndael_Algorithm;
import net.i2p.crypto.SHA256Generator;
/**
* 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
* 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
{
@@ -103,7 +104,7 @@ public class FortunaStandalone extends BasePRNGStandalone implements Serializabl
static final int NUM_POOLS = 32;
static final int MIN_POOL_SIZE = 64;
final Generator generator;
final Sha256Standalone[] pools;
final MessageDigest[] pools;
long lastReseed;
int pool;
int pool0Count;
@@ -117,9 +118,9 @@ public class FortunaStandalone extends BasePRNGStandalone implements Serializabl
{
super("Fortuna i2p");
generator = new Generator();
pools = new Sha256Standalone[NUM_POOLS];
pools = new MessageDigest[NUM_POOLS];
for (int i = 0; i < NUM_POOLS; i++)
pools[i] = new Sha256Standalone();
pools[i] = SHA256Generator.getDigestInstance();
lastReseed = 0;
pool = 0;
pool0Count = 0;
@@ -227,7 +228,7 @@ public class FortunaStandalone extends BasePRNGStandalone implements Serializabl
private static final int LIMIT = 1 << 20;
private final Sha256Standalone hash;
private final MessageDigest hash;
private final byte[] counter;
private final byte[] key;
/** current encryption key built from the keying material */
@@ -238,7 +239,7 @@ public class FortunaStandalone extends BasePRNGStandalone implements Serializabl
public Generator ()
{
super("Fortuna.generator.i2p");
this.hash = new Sha256Standalone();
this.hash = SHA256Generator.getDigestInstance();
counter = new byte[16]; //cipher.defaultBlockSize()];
buffer = new byte[16]; //cipher.defaultBlockSize()];
int keysize = 32;