Changeset 5a93405


Ignore:
Timestamp:
Nov 23, 2011 10:12:47 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f69f06b
Parents:
df8cd90
Message:
  • CryptixAESEngine: Fix bogus bounds checks
Location:
core/java/src/net/i2p/crypto
Files:
2 edited

Legend:

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

    rdf8cd90 r5a93405  
    195195    }
    196196   
    197     /** encrypt exactly 16 bytes using the session key */
     197    /** encrypt exactly 16 bytes using the session key
     198     * @param payload plaintext data, 16 bytes starting at inIndex
     199     * @param sessionKey private session key
     200     * @param out out parameter, 16 bytes starting at outIndex
     201     */
    198202    @Override
    199203    public final void encryptBlock(byte payload[], int inIndex, SessionKey sessionKey, byte out[], int outIndex) {
     
    208212        }
    209213       
    210         CryptixRijndael_Algorithm.blockEncrypt(payload, out, inIndex, outIndex, sessionKey.getPreparedKey(), 16);
     214        CryptixRijndael_Algorithm.blockEncrypt(payload, out, inIndex, outIndex, sessionKey.getPreparedKey());
    211215    }
    212216
    213217    /** decrypt exactly 16 bytes of data with the session key provided
    214      * @param payload encrypted data
     218     * @param payload encrypted data, 16 bytes starting at inIndex
    215219     * @param sessionKey private session key
     220     * @param rv out parameter, 16 bytes starting at outIndex
    216221     */
    217222    @Override
    218223    public final void decryptBlock(byte payload[], int inIndex, SessionKey sessionKey, byte rv[], int outIndex) {
    219         if ( (payload == null) || (rv == null) )
    220             throw new IllegalArgumentException("null block args");
    221         if (payload.length - inIndex > rv.length - outIndex)
    222             throw new IllegalArgumentException("bad block args [payload.len=" + payload.length
    223                                                + " inIndex=" + inIndex + " rv.len=" + rv.length
    224                                                + " outIndex="+outIndex);
     224        // just let it throw NPE or IAE later for speed, you'll figure it out
     225        //if ( (payload == null) || (rv == null) )
     226        //    throw new IllegalArgumentException("null block args");
     227        //if (payload.length - inIndex > rv.length - outIndex)
     228        //    throw new IllegalArgumentException("bad block args [payload.len=" + payload.length
     229        //                                       + " inIndex=" + inIndex + " rv.len=" + rv.length
     230        //                                       + " outIndex="+outIndex);
    225231        if (sessionKey.getPreparedKey() == null) {
    226232            try {
     
    233239        }
    234240
    235         CryptixRijndael_Algorithm.blockDecrypt(payload, rv, inIndex, outIndex, sessionKey.getPreparedKey(), 16);
     241        CryptixRijndael_Algorithm.blockDecrypt(payload, rv, inIndex, outIndex, sessionKey.getPreparedKey());
    236242    }
    237243   
  • core/java/src/net/i2p/crypto/CryptixRijndael_Algorithm.java

    rdf8cd90 r5a93405  
    456456     */
    457457    public static final void blockDecrypt(byte[] in, byte[] result, int inOffset, int outOffset, Object sessionKey) {
    458         if (in.length - inOffset > result.length - outOffset)
    459             throw new IllegalArgumentException("result too small: in.len=" + in.length + " in.offset=" + inOffset
     458        if (result.length - outOffset <= 15)
     459            throw new IllegalArgumentException("result too small:"
    460460                                               + " result.len=" + result.length + " result.offset=" + outOffset);
    461461        if (in.length - inOffset <= 15)
Note: See TracChangeset for help on using the changeset viewer.