8266103: Better specified spec values

Backport-of: 9bd20b57e1d79bd2bb386fb5df48e681fbbbd981
This commit is contained in:
Prasadrao Koppula
2021-08-05 09:45:24 +00:00
committed by Rob McKenna
parent 2cb686567b
commit 55c8adf6c6
3 changed files with 20 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -76,13 +76,16 @@ public class IvParameterSpec implements AlgorithmParameterSpec {
if (iv == null) {
throw new IllegalArgumentException("IV missing");
}
if (iv.length - offset < len) {
throw new IllegalArgumentException
("IV buffer too short for given offset/length combination");
if (offset < 0) {
throw new ArrayIndexOutOfBoundsException("offset is negative");
}
if (len < 0) {
throw new ArrayIndexOutOfBoundsException("len is negative");
}
if (iv.length - offset < len) {
throw new IllegalArgumentException
("IV buffer too short for given offset/length combination");
}
this.iv = new byte[len];
System.arraycopy(iv, offset, this.iv, 0, len);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -114,7 +114,12 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec {
this.version = version;
this.rounds = rounds;
this.wordSize = wordSize;
if (iv == null) throw new IllegalArgumentException("IV missing");
if (iv == null) {
throw new IllegalArgumentException("IV missing");
}
if (offset < 0) {
throw new ArrayIndexOutOfBoundsException("offset is negative");
}
int blockSize = (wordSize / 8) * 2;
if (iv.length - offset < blockSize) {
throw new IllegalArgumentException("IV too short");

View File

@@ -157,13 +157,16 @@ public class SecretKeySpec implements KeySpec, SecretKey {
if (key.length == 0) {
throw new IllegalArgumentException("Empty key");
}
if (key.length-offset < len) {
throw new IllegalArgumentException
("Invalid offset/length combination");
if (offset < 0) {
throw new ArrayIndexOutOfBoundsException("offset is negative");
}
if (len < 0) {
throw new ArrayIndexOutOfBoundsException("len is negative");
}
if (key.length - offset < len) {
throw new IllegalArgumentException
("Invalid offset/length combination");
}
this.key = new byte[len];
System.arraycopy(key, offset, this.key, 0, len);
this.algorithm = algorithm;