8158517: Minor optimizations to ISO10126PADDING
authormullan
Wed, 07 Dec 2016 10:55:13 -0500
changeset 42441 03cf95ffd04e
parent 42440 ec843594bcc6
child 42442 0e6009a5b092
8158517: Minor optimizations to ISO10126PADDING Reviewed-by: mullan Contributed-by: adam.petcher@oracle.com, ecki@zusammenkunft.net
jdk/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java
--- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java	Wed Dec 07 09:32:32 2016 +0000
+++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java	Wed Dec 07 10:55:13 2016 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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
@@ -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;
         }