Changeset b93be8b for router


Ignore:
Timestamp:
Nov 25, 2018 3:23:17 PM (20 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a8bacd8
Parents:
9badfd0
Message:

Crypto: Define ElG length constants

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/crypto/ElGamalAESEngine.java

    r9badfd0 rb93be8b  
    4343    /** enforced since release 0.6 */
    4444    public static final int MAX_TAGS_RECEIVED = 200;
     45    private static final int ELG_CLEARTEXT_LENGTH = 222;
     46    private static final int ELG_ENCRYPTED_LENGTH = 514;
    4547
    4648    public ElGamalAESEngine(I2PAppContext ctx) {
     
    179181            //if (_log.shouldLog(Log.WARN)) _log.warn("Data is null, unable to decrypt new session");
    180182            return null;
    181         } else if (data.length < 514) {
     183        } else if (data.length < ELG_ENCRYPTED_LENGTH) {
    182184            //if (_log.shouldLog(Log.WARN)) _log.warn("Data length is too small (" + data.length + ")");
    183185            return null;
    184186        }
    185         byte elgEncr[] = new byte[514];
    186         if (data.length > 514) {
    187             System.arraycopy(data, 0, elgEncr, 0, 514);
     187        byte elgEncr[] = new byte[ELG_ENCRYPTED_LENGTH];
     188        if (data.length > ELG_ENCRYPTED_LENGTH) {
     189            System.arraycopy(data, 0, elgEncr, 0, ELG_ENCRYPTED_LENGTH);
    188190        } else {
    189             System.arraycopy(data, 0, elgEncr, 514 - data.length, data.length);
     191            System.arraycopy(data, 0, elgEncr, ELG_ENCRYPTED_LENGTH - data.length, data.length);
    190192        }
    191193        byte elgDecr[] = _context.elGamalEngine().decrypt(elgEncr, targetPrivateKey);
     
    218220        _context.random().harvester().feedEntropy("ElG/AES", elgDecr, offset, elgDecr.length - offset);
    219221
    220         byte aesDecr[] = decryptAESBlock(data, 514, data.length-514, usedKey, iv, null, foundTags, foundKey);
     222        byte aesDecr[] = decryptAESBlock(data, ELG_ENCRYPTED_LENGTH, data.length - ELG_ENCRYPTED_LENGTH,
     223                                         usedKey, iv, null, foundTags, foundKey);
    221224        SimpleByteCache.release(iv);
    222225
     
    509512                                    SessionKey newKey, long paddedSize) {
    510513        //_log.debug("Encrypting to a NEW session");
    511         byte elgSrcData[] = new byte[SessionKey.KEYSIZE_BYTES+32+158];
     514        byte elgSrcData[] = new byte[ELG_CLEARTEXT_LENGTH];
    512515        System.arraycopy(key.getData(), 0, elgSrcData, 0, SessionKey.KEYSIZE_BYTES);
    513516        // get both the preIV and the padding at once, then copy to the preIV array
    514         _context.random().nextBytes(elgSrcData, SessionKey.KEYSIZE_BYTES, 32 + 158);
     517        _context.random().nextBytes(elgSrcData, SessionKey.KEYSIZE_BYTES, ELG_CLEARTEXT_LENGTH - SessionKey.KEYSIZE_BYTES);
    515518        byte preIV[] = SimpleByteCache.acquire(32);
    516519        System.arraycopy(elgSrcData, SessionKey.KEYSIZE_BYTES, preIV, 0, 32);
     
    524527            _log.info("elgEngine.encrypt of the session key took " + (after - before) + "ms");
    525528        }
    526         if (elgEncr.length < 514) {
     529        if (elgEncr.length < ELG_ENCRYPTED_LENGTH) {
    527530            // ??? ElGamalEngine.encrypt() always returns 514 bytes
    528             byte elg[] = new byte[514];
     531            byte elg[] = new byte[ELG_ENCRYPTED_LENGTH];
    529532            int diff = elg.length - elgEncr.length;
    530533            //if (_log.shouldLog(Log.DEBUG)) _log.debug("Difference in size: " + diff);
Note: See TracChangeset for help on using the changeset viewer.