src/share/classes/javax/crypto/CipherSpi.java
Print this page
8012900: CICO ignores AAD in GCM mode
@@ -784,11 +784,13 @@
int outOfs = output.arrayOffset() + outPos;
byte[] inArray = new byte[getTempArraySize(inLen)];
int total = 0;
do {
int chunk = Math.min(inLen, inArray.length);
+ if (chunk > 0) {
input.get(inArray, 0, chunk);
+ }
int n;
if (isUpdate || (inLen != chunk)) {
n = engineUpdate(inArray, 0, chunk, outArray, outOfs);
} else {
n = engineDoFinal(inArray, 0, chunk, outArray, outOfs);
@@ -812,12 +814,13 @@
byte[] outArray = new byte[getTempArraySize(outLenNeeded)];
int outSize = outArray.length;
int total = 0;
boolean resized = false;
do {
- int chunk = Math.min(inLen, outSize);
- if ((a1 == false) && (resized == false)) {
+ int chunk =
+ Math.min(inLen, (outSize == 0? inArray.length : outSize));
+ if (!a1 && !resized && chunk > 0) {
input.get(inArray, 0, chunk);
inOfs = 0;
}
try {
int n;
@@ -827,26 +830,30 @@
n = engineDoFinal(inArray, inOfs, chunk, outArray, 0);
}
resized = false;
inOfs += chunk;
inLen -= chunk;
+ if (n > 0) {
output.put(outArray, 0, n);
total += n;
+ }
} catch (ShortBufferException e) {
if (resized) {
// we just resized the output buffer, but it still
// did not work. Bug in the provider, abort
throw (ProviderException)new ProviderException
("Could not determine buffer size").initCause(e);
}
// output buffer is too small, realloc and try again
resized = true;
- int newOut = engineGetOutputSize(chunk);
- outArray = new byte[newOut];
+ outSize = engineGetOutputSize(chunk);
+ outArray = new byte[outSize];
}
} while (inLen > 0);
+ if (a1) {
input.position(inLimit);
+ }
return total;
}
}
/**