Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8158517

Minor optimizations to ISO10126PADDING

    XMLWordPrintable

Details

    • b149
    • Not verified

    Backports

      Description

        Posted on http://mail.openjdk.java.net/pipermail/security-dev/2016-May/013856.html:

        while looking at ISO10126Padding I noticed a few minor optimizations are possible:

        http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/com/sun/crypto/provider/ISO10126Padding.java?av=f

        unpad() - there is already a int cast done to this value:
        104 int start = off + len - ((int)lastByte & 0x0ff);

        can be changed into "int start = off + len - padValue;"

        padWithLen() - we can request one byte less from PRNG and copy one less:
        71 byte[] padding = new byte[len];
        72 SunJCE.getRandom().nextBytes(padding);
        73 padding[len-1] = paddingOctet;
        74 System.arraycopy(padding, 0, in, off, len);

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

        Attachments

          Issue Links

            Activity

              People

                apetcher Adam Petcher (Inactive)
                mullan Sean Mullan
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: