Simplify boundary checks

This commit is contained in:
Pietro Oliva 2020-09-02 15:12:31 -04:00
parent 3b897f2d68
commit 95fa4af798
3 changed files with 6 additions and 6 deletions

View File

@ -187,7 +187,7 @@ class AESGCMFallbackCipherState implements CipherState {
int space;
if (ciphertextOffset < 0 || ciphertextOffset > ciphertext.length)
throw new IllegalArgumentException();
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || plaintextOffset + length < plaintextOffset || plaintextOffset + length > plaintext.length)
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || length > plaintext.length || (plaintext.length - plaintextOffset) < length)
throw new IllegalArgumentException();
space = ciphertext.length - ciphertextOffset;
if (!haskey) {
@ -221,7 +221,7 @@ class AESGCMFallbackCipherState implements CipherState {
space = ciphertext.length - ciphertextOffset;
if (length > space)
throw new ShortBufferException();
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || plaintextOffset + length < plaintextOffset || plaintextOffset + length > plaintext.length)
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || length > plaintext.length || (plaintext.length - plaintextOffset) < length)
throw new IllegalArgumentException();
space = plaintext.length - plaintextOffset;
if (!haskey) {

View File

@ -220,7 +220,7 @@ class AESGCMOnCtrCipherState implements CipherState {
int space;
if (ciphertextOffset < 0 || ciphertextOffset > ciphertext.length)
throw new IllegalArgumentException();
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || plaintextOffset + length < plaintextOffset || plaintextOffset + length > plaintext.length)
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || length > plaintext.length || (plaintext.length - plaintextOffset) < length)
throw new IllegalArgumentException();
space = ciphertext.length - ciphertextOffset;
if (keySpec == null) {
@ -269,7 +269,7 @@ class AESGCMOnCtrCipherState implements CipherState {
space = ciphertext.length - ciphertextOffset;
if (length > space)
throw new ShortBufferException();
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || plaintextOffset + length < plaintextOffset || plaintextOffset + length > plaintext.length)
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || length > plaintext.length || (plaintext.length - plaintextOffset) < length)
throw new IllegalArgumentException();
space = plaintext.length - plaintextOffset;
if (keySpec == null) {

View File

@ -216,7 +216,7 @@ class ChaChaPolyCipherState implements CipherState {
int space;
if (ciphertextOffset < 0 || ciphertextOffset > ciphertext.length)
throw new IllegalArgumentException();
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || plaintextOffset + length < plaintextOffset || plaintextOffset + length > plaintext.length)
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || length > plaintext.length || (plaintext.length - plaintextOffset) < length)
throw new IllegalArgumentException();
space = ciphertext.length - ciphertextOffset;
if (!haskey) {
@ -248,7 +248,7 @@ class ChaChaPolyCipherState implements CipherState {
space = ciphertext.length - ciphertextOffset;
if (length > space)
throw new ShortBufferException();
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || plaintextOffset + length < plaintextOffset || plaintextOffset + length > plaintext.length)
if (length < 0 || plaintextOffset < 0 || plaintextOffset > plaintext.length || length > plaintext.length || (plaintext.length - plaintextOffset) < length)
throw new IllegalArgumentException();
space = plaintext.length - plaintextOffset;
if (!haskey) {