Skip to content

Commit 7a0bed7

Browse files
committed
fixed process block calculation to ensue full buffer processing in multi-block case.
1 parent 6546084 commit 7a0bed7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

core/src/main/java/org/bouncycastle/crypto/BufferedBlockCipher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public int processBytes(
256256

257257
if (mbCipher != null)
258258
{
259-
int blockCount = len / blockSize;
259+
int blockCount = (len / mbCipher.getMultiBlockSize()) * (mbCipher.getMultiBlockSize() / blockSize);
260260

261261
if (blockCount > 0)
262262
{
@@ -351,8 +351,8 @@ public int doFinal(
351351
}
352352

353353
cipher.processBlock(buf, index, buf, index);
354+
System.arraycopy(buf, index, out, outOff + resultLen, bufOff - index);
354355
resultLen += bufOff - index;
355-
System.arraycopy(buf, index, out, outOff, bufOff - index);
356356
bufOff = 0;
357357
}
358358
}

core/src/main/java/org/bouncycastle/crypto/DefaultBufferedBlockCipher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public int processBytes(
258258

259259
if (mbCipher != null)
260260
{
261-
int blockCount = len / blockSize;
261+
int blockCount = (len / mbCipher.getMultiBlockSize()) * (mbCipher.getMultiBlockSize() / blockSize);
262262

263263
if (blockCount > 0)
264264
{
@@ -353,8 +353,8 @@ public int doFinal(
353353
}
354354

355355
cipher.processBlock(buf, index, buf, index);
356+
System.arraycopy(buf, index, out, outOff + resultLen, bufOff - index);
356357
resultLen += bufOff - index;
357-
System.arraycopy(buf, index, out, outOff, bufOff - index);
358358
bufOff = 0;
359359
}
360360
}

0 commit comments

Comments
 (0)