From df8736b785eea30c5138ffe8b75201c48e46bcf2 Mon Sep 17 00:00:00 2001 From: Adam Petcher Date: Wed, 7 Dec 2016 10:55:13 -0500 Subject: [PATCH] 8158517: Minor optimizations to ISO10126PADDING Co-authored-by: Bernd Eckenfels Reviewed-by: mullan --- .../com/sun/crypto/provider/ISO10126Padding.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jdk/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java b/jdk/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java index 7377fab0a9c..a7134238e14 100644 --- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java +++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/ISO10126Padding.java @@ -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 @@ final class ISO10126Padding implements Padding { } 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 @@ final class ISO10126Padding implements Padding { return -1; } - int start = off + len - ((int)lastByte & 0x0ff); + int start = off + len - padValue; if (start < off) { return -1; }