changeset 16214:b9cdffb87bea

8158517: Minor optimizations to ISO10126PADDING Reviewed-by: mullan Contributed-by: adam.petcher@oracle.com, ecki@zusammenkunft.net
author mullan
date Wed, 07 Dec 2016 10:55:13 -0500
parents c1b4d9879aea
children 26c1193265d6
files src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java	Wed Dec 07 09:32:32 2016 +0000
+++ b/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;
         }