Changeset 32d9204


Ignore:
Timestamp:
Jul 8, 2011 1:51:50 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ef40282
Parents:
dd49062
Message:
  • 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
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/gnu/crypto/hash/BaseHashStandalone.java

    rdd49062 r32d9204  
    4747 * <p>A base abstract class to facilitate hash implementations.</p>
    4848 *
     49 * WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a
     50 * MessageDigest that will be faster in almost all cases.
     51 * See SHA256Generator for more information.
     52 *
    4953 * @version $Revision: 1.1 $
    5054 */
  • core/java/src/gnu/crypto/hash/IMessageDigestStandalone.java

    rdd49062 r32d9204  
    4949 * <p>A hash (or message digest) algorithm produces its output by iterating a
    5050 * basic compression function on blocks of data.</p>
     51 *
     52 * WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a
     53 * MessageDigest that will be faster in almost all cases.
     54 * See SHA256Generator for more information.
    5155 *
    5256 * @version $Revision: 1.1 $
  • core/java/src/gnu/crypto/hash/Sha256Standalone.java

    rdd49062 r32d9204  
    5959 * renamed from Sha256 to avoid conflicts with JVMs using gnu-crypto as their JCE
    6060 * provider.
     61 *
     62 * WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a
     63 * MessageDigest that will be faster in almost all cases.
     64 * See SHA256Generator for more information.
    6165 *
    6266 * @version $Revision: 1.2 $
  • core/java/src/gnu/crypto/prng/FortunaStandalone.java

    rdd49062 r32d9204  
    4242package gnu.crypto.prng;
    4343
    44 import gnu.crypto.hash.Sha256Standalone;
    45 
    4644import java.io.IOException;
    4745import java.io.ObjectInputStream;
     
    4947import java.io.Serializable;
    5048import java.security.InvalidKeyException;
     49import java.security.MessageDigest;
    5150import java.util.Arrays;
    5251import java.util.HashMap;
     
    5554import net.i2p.crypto.CryptixAESKeyCache;
    5655import net.i2p.crypto.CryptixRijndael_Algorithm;
     56import net.i2p.crypto.SHA256Generator;
    5757
    5858/**
     
    9494 * gnu-crypto implementation, which has been imported into GNU/classpath
    9595 *
     96 * NOTE: As of 0.8.8, uses the java.security.MessageDigest instead of GNU Sha256Standalone
    9697 */
    9798public class FortunaStandalone extends BasePRNGStandalone implements Serializable, RandomEventListenerStandalone
     
    104105  static final int MIN_POOL_SIZE = 64;
    105106  final Generator generator;
    106   final Sha256Standalone[] pools;
     107  final MessageDigest[] pools;
    107108  long lastReseed;
    108109  int pool;
     
    118119    super("Fortuna i2p");
    119120    generator = new Generator();
    120     pools = new Sha256Standalone[NUM_POOLS];
     121    pools = new MessageDigest[NUM_POOLS];
    121122    for (int i = 0; i < NUM_POOLS; i++)
    122       pools[i] = new Sha256Standalone();
     123      pools[i] = SHA256Generator.getDigestInstance();
    123124    lastReseed = 0;
    124125    pool = 0;
     
    228229    private static final int LIMIT = 1 << 20;
    229230
    230     private final Sha256Standalone hash;
     231    private final MessageDigest hash;
    231232    private final byte[] counter;
    232233    private final byte[] key;
     
    239240    {
    240241      super("Fortuna.generator.i2p");
    241       this.hash = new Sha256Standalone();
     242      this.hash = SHA256Generator.getDigestInstance();
    242243      counter = new byte[16]; //cipher.defaultBlockSize()];
    243244      buffer = new byte[16]; //cipher.defaultBlockSize()];
  • core/java/src/net/i2p/crypto/SHA256Generator.java

    rdd49062 r32d9204  
    9191    }
    9292   
    93     private static MessageDigest getDigestInstance() {
     93    /**
     94     *  Return a new MessageDigest from the system libs unless unavailable
     95     *  in this JVM, in that case return a wrapped GNU Sha256Standalone
     96     *  @since 0.8.7, public since 0.8.8 for FortunaStandalone
     97     */
     98    public static MessageDigest getDigestInstance() {
    9499        if (!_useGnu) {
    95100            try {
  • core/java/src/net/i2p/data/DataHelper.java

    rdd49062 r32d9204  
    2727import java.io.UnsupportedEncodingException;
    2828import java.math.BigInteger;
     29import java.security.MessageDigest;
    2930import java.text.DecimalFormat;
    3031import java.util.ArrayList;
     
    10111012     * Warning - not UTF-8
    10121013     */
    1013     public static String readLine(InputStream in) throws IOException { return readLine(in, (Sha256Standalone)null); }
     1014    public static String readLine(InputStream in) throws IOException { return readLine(in, (MessageDigest) null); }
    10141015
    10151016    /**
     
    10181019     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
    10191020     * Warning - not UTF-8
     1021     * @deprecated use MessageDigest version
    10201022     */
    10211023    public static String readLine(InputStream in, Sha256Standalone hash) throws IOException {
     
    10291031
    10301032    /**
     1033     * update the hash along the way
     1034     * Warning - strips \n but not \r
     1035     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
     1036     * Warning - not UTF-8
     1037     * @since 0.8.8
     1038     */
     1039    public static String readLine(InputStream in, MessageDigest hash) throws IOException {
     1040        StringBuilder buf = new StringBuilder(128);
     1041        boolean ok = readLine(in, buf, hash);
     1042        if (ok)
     1043            return buf.toString();
     1044        else
     1045            return null;
     1046    }
     1047
     1048    /**
    10311049     * Read in a line, placing it into the buffer (excluding the newline).
    10321050     * Warning - strips \n but not \r
     
    10511069     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
    10521070     * Warning - not UTF-8
    1053      * @deprecated use StringBuilder version
     1071     * @deprecated use StringBuilder / MessageDigest version
    10541072     */
    10551073    @Deprecated
     
    10811099     */
    10821100    public static boolean readLine(InputStream in, StringBuilder buf) throws IOException {
    1083         return readLine(in, buf, null);
     1101        return readLine(in, buf, (MessageDigest) null);
    10841102    }
    10851103
     
    10891107     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
    10901108     * Warning - not UTF-8
     1109     * @deprecated use MessageDigest version
    10911110     */
    10921111    public static boolean readLine(InputStream in, StringBuilder buf, Sha256Standalone hash) throws IOException {
     
    11041123    }
    11051124   
     1125    /**
     1126     * update the hash along the way
     1127     * Warning - strips \n but not \r
     1128     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
     1129     * Warning - not UTF-8
     1130     * @since 0.8.8
     1131     */
     1132    public static boolean readLine(InputStream in, StringBuilder buf, MessageDigest hash) throws IOException {
     1133        int c = -1;
     1134        int i = 0;
     1135        while ( (c = in.read()) != -1) {
     1136            if (++i > MAX_LINE_LENGTH)
     1137                throw new IOException("Line too long - max " + MAX_LINE_LENGTH);
     1138            if (hash != null) hash.update((byte)c);
     1139            if (c == '\n')
     1140                break;
     1141            buf.append((char)c);
     1142        }
     1143        return c != -1;
     1144    }
     1145   
     1146    /**
     1147     *  update the hash along the way
     1148     *  @deprecated use MessageDigest version
     1149     */
    11061150    public static void write(OutputStream out, byte data[], Sha256Standalone hash) throws IOException {
     1151        hash.update(data);
     1152        out.write(data);
     1153    }
     1154   
     1155    /**
     1156     *  update the hash along the way
     1157     *  @since 0.8.8
     1158     */
     1159    public static void write(OutputStream out, byte data[], MessageDigest hash) throws IOException {
    11071160        hash.update(data);
    11081161        out.write(data);
  • history.txt

    rdd49062 r32d9204  
     12011-07-08 zzz
     2  * NetDB: Fix NPE at startup (ticket #493)
     3  * Sha256Standalone:
     4    - Use system SHA-256 MessageDigest instead of Sha256Standalone in PRNG
     5    - Deprecate DataHelper functions using Sha256Standalone arguments;
     6      used only by Syndie
     7    - Note deprecation in javadocs
     8
    192011-07-07 zzz
    210  * Blockfile:
  • router/java/src/net/i2p/router/RouterVersion.java

    rdd49062 r32d9204  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 6;
     21    public final static long BUILD = 7;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.