Changeset efd7d65 for core


Ignore:
Timestamp:
May 10, 2017 2:00:59 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
610af51
Parents:
d139892
Message:

AES: Cleanups (ticket #1989)

Location:
core/java/src/net/i2p
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/CryptixAESEngine.java

    rd139892 refd7d65  
    209209    @Override
    210210    public final void encryptBlock(byte payload[], int inIndex, SessionKey sessionKey, byte out[], int outIndex) {
    211         if (sessionKey.getPreparedKey() == null) {
     211        Object pkey = sessionKey.getPreparedKey();
     212        if (pkey == null) {
    212213            try {
    213                 Object key = CryptixRijndael_Algorithm.makeKey(sessionKey.getData(), 16);
    214                 sessionKey.setPreparedKey(key);
     214                pkey = CryptixRijndael_Algorithm.makeKey(sessionKey.getData(), 16);
     215                sessionKey.setPreparedKey(pkey);
    215216            } catch (InvalidKeyException ike) {
    216217                _log.log(Log.CRIT, "Invalid key", ike);
     
    219220        }
    220221       
    221         CryptixRijndael_Algorithm.blockEncrypt(payload, out, inIndex, outIndex, sessionKey.getPreparedKey());
     222        CryptixRijndael_Algorithm.blockEncrypt(payload, out, inIndex, outIndex, pkey);
    222223    }
    223224
     
    236237        //                                       + " inIndex=" + inIndex + " rv.len=" + rv.length
    237238        //                                       + " outIndex="+outIndex);
    238         if (sessionKey.getPreparedKey() == null) {
     239        Object pkey = sessionKey.getPreparedKey();
     240        if (pkey == null) {
    239241            try {
    240                 Object key = CryptixRijndael_Algorithm.makeKey(sessionKey.getData(), 16);
    241                 sessionKey.setPreparedKey(key);
     242                pkey = CryptixRijndael_Algorithm.makeKey(sessionKey.getData(), 16);
     243                sessionKey.setPreparedKey(pkey);
    242244            } catch (InvalidKeyException ike) {
    243245                _log.log(Log.CRIT, "Invalid key", ike);
     
    246248        }
    247249
    248         CryptixRijndael_Algorithm.blockDecrypt(payload, rv, inIndex, outIndex, sessionKey.getPreparedKey());
     250        CryptixRijndael_Algorithm.blockDecrypt(payload, rv, inIndex, outIndex, pkey);
    249251    }
    250252   
  • core/java/src/net/i2p/crypto/CryptixRijndael_Algorithm.java

    rd139892 refd7d65  
    55package net.i2p.crypto;
    66
    7 import java.io.PrintWriter;
     7//import java.io.PrintWriter;
    88import java.security.InvalidKeyException;
    99
    10 import net.i2p.util.Clock;
     10//import net.i2p.util.Clock;
    1111
    1212//...........................................................................
     
    553553     * @throws  InvalidKeyException  If the key is invalid.
    554554     */
    555     public static final/* synchronized */Object makeKey(byte[] k, int blockSize) throws InvalidKeyException {
     555    public static final Object makeKey(byte[] k, int blockSize) throws InvalidKeyException {
    556556        return makeKey(k, blockSize, null);
    557557    }
    558     public static final/* synchronized */Object makeKey(byte[] k, int blockSize, CryptixAESKeyCache.KeyCacheEntry keyData) throws InvalidKeyException {
     558
     559    public static final Object makeKey(byte[] k, int blockSize, CryptixAESKeyCache.KeyCacheEntry keyData) throws InvalidKeyException {
    559560        //if (_RDEBUG) trace(_IN, "makeKey(" + k + ", " + blockSize + ")");
    560561        if (k == null) throw new InvalidKeyException("Empty key");
     
    563564        int ROUNDS = getRounds(k.length, blockSize);
    564565        int BC = blockSize / 4;
    565         int[][] Ke = null; // new int[ROUNDS + 1][BC]; // encryption round keys
    566         int[][] Kd = null; // new int[ROUNDS + 1][BC]; // decryption round keys
     566        int[][] Ke; // new int[ROUNDS + 1][BC]; // encryption round keys
     567        int[][] Kd; // new int[ROUNDS + 1][BC]; // decryption round keys
    567568        int ROUND_KEY_COUNT = (ROUNDS + 1) * BC;
    568569        int KC = k.length / 4;
    569         int[] tk = null; // new int[KC];
     570        int[] tk; // new int[KC];
    570571        int i, j;
    571572       
     
    629630            }
    630631        }
    631         for (int r = 1; r < ROUNDS; r++)
     632        for (int r = 1; r < ROUNDS; r++) {
    632633            // inverse MixColumn where needed
    633634            for (j = 0; j < BC; j++) {
     
    635636                Kd[r][j] = _U1[(tt >>> 24) & 0xFF] ^ _U2[(tt >>> 16) & 0xFF] ^ _U3[(tt >>> 8) & 0xFF] ^ _U4[tt & 0xFF];
    636637            }
     638        }
    637639        // assemble the encryption (Ke) and decryption (Kd) round keys into
    638640        // one sessionKey object
    639         Object[] sessionKey = null;
     641        Object[] sessionKey;
    640642        if (keyData == null)
    641643            sessionKey = new Object[] { Ke, Kd};
  • core/java/src/net/i2p/data/SessionKey.java

    rd139892 refd7d65  
    3838
    3939    /**
    40      * caveat: this method isn't synchronized with the preparedKey, so don't
    41      * try to *change* the key data after already doing some
    42      * encryption/decryption (or if you do change it, be sure this object isn't
    43      * mid decrypt)
     40     * Sets the data.
     41     * @param data 32 bytes, or null
     42     * @throws IllegalArgumentException if data is not the legal number of bytes (but null is ok)
     43     * @throws RuntimeException if data already set.
    4444     */
    4545    @Override
    4646    public void setData(byte[] data) {
    4747        super.setData(data);
    48         _preparedKey = null;
    4948    }
    5049   
Note: See TracChangeset for help on using the changeset viewer.