[PATCH] 8158517: Minor optimizations to ISO10126PADDING

Adam Petcher adam.petcher at oracle.com
Wed Dec 7 14:14:24 UTC 2016


Minor improvement/optimization to ISO10126Padding. Simplifies the code a 
bit and requests one fewer random byte. No regression test is provided 
because this is a code cleanup, and the functionality is covered by 
existing tests.

Bug: https://bugs.openjdk.java.net/browse/JDK-8158517

Diff:

diff --git 
a/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java 
b/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java
--- 
a/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java
+++ 
b/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java
@@ -68,10 +68,10 @@
          }

          byte paddingOctet = (byte) (len & 0xff);
-        byte[] padding = new byte[len];
+        byte[] padding = new byte[len - 1];
          SunJCE.getRandom().nextBytes(padding);
-        padding[len-1] = paddingOctet;
-        System.arraycopy(padding, 0, in, off, len);
+        System.arraycopy(padding, 0, in, off, len - 1);
+        in[off + len - 1] = paddingOctet;
          return;
      }

@@ -101,7 +101,7 @@
              return -1;
          }

-        int start = off + len - ((int)lastByte & 0x0ff);
+        int start = off + len - padValue;
          if (start < off) {
              return -1;
          }



More information about the security-dev mailing list