src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java	Fri Jun 26 17:30:20 2015
--- new/src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java	Fri Jun 26 17:30:19 2015

*** 36,45 **** --- 36,48 ---- package com.sun.crypto.provider; import java.security.InvalidKeyException; import java.util.Arrays; + import java.util.Objects; + + import jdk.internal.HotSpotIntrinsicCandidate; /** * Rijndael --pronounced Reindaal-- is a symmetric cipher with a 128-bit * block size and variable key-size (128-, 192- and 256-bit). * <p>
*** 344,353 **** --- 347,365 ---- /** * Encrypt exactly one block of plaintext. */ void encryptBlock(byte[] in, int inOffset, + byte[] out, int outOffset) { + cryptBlockCheck(in, inOffset); + cryptBlockCheck(out, outOffset); + implEncryptBlock(in, inOffset, out, outOffset); + } + + // Encryption operation. Possibly replaced with a compiler intrinsic. + @HotSpotIntrinsicCandidate + private void implEncryptBlock(byte[] in, int inOffset, byte[] out, int outOffset) { int keyOffset = 0; int t0 = ((in[inOffset++] ) << 24 | (in[inOffset++] & 0xFF) << 16 |
*** 410,424 **** --- 422,444 ---- out[outOffset++] = (byte)(S[(t0 >>> 16) & 0xFF] ^ (tt >>> 16)); out[outOffset++] = (byte)(S[(t1 >>> 8) & 0xFF] ^ (tt >>> 8)); out[outOffset ] = (byte)(S[(t2 ) & 0xFF] ^ (tt )); } /** * Decrypt exactly one block of plaintext. */ void decryptBlock(byte[] in, int inOffset, + byte[] out, int outOffset) { + cryptBlockCheck(in, inOffset); + cryptBlockCheck(out, outOffset); + implDecryptBlock(in, inOffset, out, outOffset); + } + + // Decrypt operation. Possibly replaced with a compiler intrinsic. + @HotSpotIntrinsicCandidate + private void implDecryptBlock(byte[] in, int inOffset, byte[] out, int outOffset) { int keyOffset = 4; int t0 = ((in[inOffset++] ) << 24 | (in[inOffset++] & 0xFF) << 16 |
*** 570,579 **** --- 590,618 ---- out[outOffset++] = (byte)(Si[(a2 >>> 16) & 0xFF] ^ (t1 >>> 16)); out[outOffset++] = (byte)(Si[(a1 >>> 8) & 0xFF] ^ (t1 >>> 8)); out[outOffset ] = (byte)(Si[(a0 ) & 0xFF] ^ (t1 )); } + // Used to perform all checks required by the Java semantics + // (i.e., null checks and bounds checks) on the input parameters + // to encryptBlock and to decryptBlock. + // Normally, the Java Runtime performs these checks, however, as + // encryptBlock and decryptBlock are possibly replaced with + // compiler intrinsics, the JDK performs the required checks instead. + // Does not check accesses to class-internal (private) arrays. + private static void cryptBlockCheck(byte[] array, int offset) { + Objects.requireNonNull(array); + + if (offset < 0 || offset >= array.length) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + int largestIndex = offset + AES_BLOCK_SIZE - 1; + if (largestIndex < 0 || largestIndex >= array.length) { + throw new ArrayIndexOutOfBoundsException(largestIndex); + } + } /** * Expand a user-supplied key material into a session key. * * @param k The 128/192/256-bit cipher key to use.

src/java.base/share/classes/com/sun/crypto/provider/AESCrypt.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File