@Test(expectedExceptions = IllegalArgumentException.class) public void translateByteRangeThrowsWithLargeStartInclusive() { AesCtrCipherDetails.INSTANCE_128_BIT.translateByteRange(Long.MAX_VALUE, 0); }
@Override public ByteRangeConversion translateByteRange(final long startInclusive, final long endInclusive) { final long plaintextMax = getMaximumPlaintextSizeInBytes(); if (startInclusive > endInclusive) { String msg = "Start position must be precede end position (startInclusive=" + startInclusive + ", endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive < 0) { String msg = "Start position must be zero or higher (startInclusive=" + startInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive >= plaintextMax) { String msg = "Start position must be less than maximum plaintext size (startInclusive=" + startInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } if (endInclusive < 0) { String msg = "End position must be zero or higher (endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (endInclusive >= plaintextMax) { String msg = "End position must be less than maximum plaintext size (endInclusive=" + endInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } final int blockSize = getBlockSizeInBytes(); final long plaintextBytesToSkipInitially = startInclusive % blockSize; final long startingBlockNumberInclusive = startInclusive / blockSize; final long ciphertextStartPositionInclusive = startingBlockNumberInclusive * blockSize; final long endingBlockNumberInclusive = endInclusive / blockSize; final long ciphertextEndPositionInclusive = ((endingBlockNumberInclusive + 1) * blockSize) - 1; final long lengthOfPlaintextIncludingSkipBytes = (endInclusive - startInclusive) + (plaintextBytesToSkipInitially + 1); return new ByteRangeConversion(ciphertextStartPositionInclusive, plaintextBytesToSkipInitially, ciphertextEndPositionInclusive, lengthOfPlaintextIncludingSkipBytes, startingBlockNumberInclusive); }
AesCtrCipherDetails extends AbstractAesCipherDetails { @Override public ByteRangeConversion translateByteRange(final long startInclusive, final long endInclusive) { final long plaintextMax = getMaximumPlaintextSizeInBytes(); if (startInclusive > endInclusive) { String msg = "Start position must be precede end position (startInclusive=" + startInclusive + ", endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive < 0) { String msg = "Start position must be zero or higher (startInclusive=" + startInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive >= plaintextMax) { String msg = "Start position must be less than maximum plaintext size (startInclusive=" + startInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } if (endInclusive < 0) { String msg = "End position must be zero or higher (endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (endInclusive >= plaintextMax) { String msg = "End position must be less than maximum plaintext size (endInclusive=" + endInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } final int blockSize = getBlockSizeInBytes(); final long plaintextBytesToSkipInitially = startInclusive % blockSize; final long startingBlockNumberInclusive = startInclusive / blockSize; final long ciphertextStartPositionInclusive = startingBlockNumberInclusive * blockSize; final long endingBlockNumberInclusive = endInclusive / blockSize; final long ciphertextEndPositionInclusive = ((endingBlockNumberInclusive + 1) * blockSize) - 1; final long lengthOfPlaintextIncludingSkipBytes = (endInclusive - startInclusive) + (plaintextBytesToSkipInitially + 1); return new ByteRangeConversion(ciphertextStartPositionInclusive, plaintextBytesToSkipInitially, ciphertextEndPositionInclusive, lengthOfPlaintextIncludingSkipBytes, startingBlockNumberInclusive); } }
AesCtrCipherDetails extends AbstractAesCipherDetails { @Override public ByteRangeConversion translateByteRange(final long startInclusive, final long endInclusive) { final long plaintextMax = getMaximumPlaintextSizeInBytes(); if (startInclusive > endInclusive) { String msg = "Start position must be precede end position (startInclusive=" + startInclusive + ", endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive < 0) { String msg = "Start position must be zero or higher (startInclusive=" + startInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive >= plaintextMax) { String msg = "Start position must be less than maximum plaintext size (startInclusive=" + startInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } if (endInclusive < 0) { String msg = "End position must be zero or higher (endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (endInclusive >= plaintextMax) { String msg = "End position must be less than maximum plaintext size (endInclusive=" + endInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } final int blockSize = getBlockSizeInBytes(); final long plaintextBytesToSkipInitially = startInclusive % blockSize; final long startingBlockNumberInclusive = startInclusive / blockSize; final long ciphertextStartPositionInclusive = startingBlockNumberInclusive * blockSize; final long endingBlockNumberInclusive = endInclusive / blockSize; final long ciphertextEndPositionInclusive = ((endingBlockNumberInclusive + 1) * blockSize) - 1; final long lengthOfPlaintextIncludingSkipBytes = (endInclusive - startInclusive) + (plaintextBytesToSkipInitially + 1); return new ByteRangeConversion(ciphertextStartPositionInclusive, plaintextBytesToSkipInitially, ciphertextEndPositionInclusive, lengthOfPlaintextIncludingSkipBytes, startingBlockNumberInclusive); } protected  AesCtrCipherDetails(final int keyLengthBits); }
AesCtrCipherDetails extends AbstractAesCipherDetails { @Override public ByteRangeConversion translateByteRange(final long startInclusive, final long endInclusive) { final long plaintextMax = getMaximumPlaintextSizeInBytes(); if (startInclusive > endInclusive) { String msg = "Start position must be precede end position (startInclusive=" + startInclusive + ", endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive < 0) { String msg = "Start position must be zero or higher (startInclusive=" + startInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive >= plaintextMax) { String msg = "Start position must be less than maximum plaintext size (startInclusive=" + startInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } if (endInclusive < 0) { String msg = "End position must be zero or higher (endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (endInclusive >= plaintextMax) { String msg = "End position must be less than maximum plaintext size (endInclusive=" + endInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } final int blockSize = getBlockSizeInBytes(); final long plaintextBytesToSkipInitially = startInclusive % blockSize; final long startingBlockNumberInclusive = startInclusive / blockSize; final long ciphertextStartPositionInclusive = startingBlockNumberInclusive * blockSize; final long endingBlockNumberInclusive = endInclusive / blockSize; final long ciphertextEndPositionInclusive = ((endingBlockNumberInclusive + 1) * blockSize) - 1; final long lengthOfPlaintextIncludingSkipBytes = (endInclusive - startInclusive) + (plaintextBytesToSkipInitially + 1); return new ByteRangeConversion(ciphertextStartPositionInclusive, plaintextBytesToSkipInitially, ciphertextEndPositionInclusive, lengthOfPlaintextIncludingSkipBytes, startingBlockNumberInclusive); } protected  AesCtrCipherDetails(final int keyLengthBits); @Override long ciphertextSize(final long plaintextSize); @Override long plaintextSize(final long ciphertextSize); @Override boolean plaintextSizeCalculationIsAnEstimate(); @Override ByteRangeConversion translateByteRange(final long startInclusive, final long endInclusive); @Override AlgorithmParameterSpec getEncryptionParameterSpec(final byte[] iv, final long position); @Override long updateCipherToPosition(final Cipher cipher, final long position); @Override boolean supportsRandomAccess(); }
AesCtrCipherDetails extends AbstractAesCipherDetails { @Override public ByteRangeConversion translateByteRange(final long startInclusive, final long endInclusive) { final long plaintextMax = getMaximumPlaintextSizeInBytes(); if (startInclusive > endInclusive) { String msg = "Start position must be precede end position (startInclusive=" + startInclusive + ", endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive < 0) { String msg = "Start position must be zero or higher (startInclusive=" + startInclusive + ")"; throw new IllegalArgumentException(msg); } if (startInclusive >= plaintextMax) { String msg = "Start position must be less than maximum plaintext size (startInclusive=" + startInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } if (endInclusive < 0) { String msg = "End position must be zero or higher (endInclusive=" + endInclusive + ")"; throw new IllegalArgumentException(msg); } if (endInclusive >= plaintextMax) { String msg = "End position must be less than maximum plaintext size (endInclusive=" + endInclusive + ", plaintextMax=" + plaintextMax + ")"; throw new IllegalArgumentException(msg); } final int blockSize = getBlockSizeInBytes(); final long plaintextBytesToSkipInitially = startInclusive % blockSize; final long startingBlockNumberInclusive = startInclusive / blockSize; final long ciphertextStartPositionInclusive = startingBlockNumberInclusive * blockSize; final long endingBlockNumberInclusive = endInclusive / blockSize; final long ciphertextEndPositionInclusive = ((endingBlockNumberInclusive + 1) * blockSize) - 1; final long lengthOfPlaintextIncludingSkipBytes = (endInclusive - startInclusive) + (plaintextBytesToSkipInitially + 1); return new ByteRangeConversion(ciphertextStartPositionInclusive, plaintextBytesToSkipInitially, ciphertextEndPositionInclusive, lengthOfPlaintextIncludingSkipBytes, startingBlockNumberInclusive); } protected  AesCtrCipherDetails(final int keyLengthBits); @Override long ciphertextSize(final long plaintextSize); @Override long plaintextSize(final long ciphertextSize); @Override boolean plaintextSizeCalculationIsAnEstimate(); @Override ByteRangeConversion translateByteRange(final long startInclusive, final long endInclusive); @Override AlgorithmParameterSpec getEncryptionParameterSpec(final byte[] iv, final long position); @Override long updateCipherToPosition(final Cipher cipher, final long position); @Override boolean supportsRandomAccess(); static final SupportedCipherDetails INSTANCE_128_BIT; static final SupportedCipherDetails INSTANCE_192_BIT; static final SupportedCipherDetails INSTANCE_256_BIT; }