Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
fix: Improved getPaddingByteValue method in ArbitraryTailPadding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schwab committed Aug 13, 2020
1 parent e9bc64b commit 83776c2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/de/db/bcm/tupw/crypto/ArbitraryTailPadding.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* 2019-08-23: V2.0.5: Use SecureRandom singleton. fhs
* 2020-03-13: V2.1.0: Added checks for null. fhs
* 2020-03-23: V2.2.0: Restructured source code according to DBS programming guidelines. fhs
* 2020-08-13: V2.2.1: Improved getPaddingByteValue method. fhs
*/
package de.db.bcm.tupw.crypto;

Expand All @@ -39,7 +40,7 @@
* Implements arbitrary tail padding for block ciphers
*
* @author Frank Schwab, DB Systel GmbH
* @version 2.2.0
* @version 2.2.1
*/
public class ArbitraryTailPadding {
//******************************************************************
Expand Down Expand Up @@ -138,14 +139,14 @@ private static void checkBlockSize(final int blockSize) throws IllegalArgumentEx
private static byte getPaddingByteValue(final byte[] unpaddedSourceData) {
final byte[] padByte = new byte[1];

SECURE_PRNG.nextBytes(padByte);

if (unpaddedSourceData.length > 0) {
final byte lastByte = unpaddedSourceData[unpaddedSourceData.length - 1];

do
while (padByte[0] == lastByte)
SECURE_PRNG.nextBytes(padByte);
while (padByte[0] == lastByte);
} else
SECURE_PRNG.nextBytes(padByte);
}

return padByte[0];
}
Expand Down

0 comments on commit 83776c2

Please sign in to comment.