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

Minor optimizations to ISO10126PADDING

    Details

    • Subcomponent:
    • Resolved In Build:
      b149
    • Verification:
      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;

          Issue Links

            Activity

            mullan Sean Mullan created issue -
            mullan Sean Mullan made changes -
            Field Original Value New Value
            Status New [ 10000 ] Open [ 1 ]
            apetcher Adam Petcher made changes -
            Assignee Adam Petcher [ apetcher ]
            apetcher Adam Petcher made changes -
            Labels noreg-cleanup
            apetcher Adam Petcher made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            Understanding Fix Understood [ 10001 ]
            apetcher Adam Petcher made changes -
            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;

            BTW: the JCA Standards Names documentation refer to W3C XML Encryption Standard 5.2 which does not mandate or suggest to use random padding. It allows any value. So a possible optimization would be to not use random bytes. If you think random bytes (and therefore non deterministic padding) is a desireable property I would suggest to actually document it in the SunJCE documentation. "This implements padding as defined by the JCA Standard Names using random padding bytes.
            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;
            mullan Sean Mullan made changes -
            Link This issue relates to JDK-8170762 [ JDK-8170762 ]
            hgupdate HG Updates made changes -
            Status In Progress [ 3 ] Resolved [ 5 ]
            Resolved In Build team [ 17324 ]
            Understanding Fix Understood [ 10001 ]
            Fix Version/s 9 [ 14949 ]
            Resolution Fixed [ 1 ]
            hgupdate HG Updates made changes -
            Resolved In Build team [ 17324 ] master [ 18256 ]
            hgupdate HG Updates made changes -
            Resolved In Build master [ 18256 ] b149 [ 17715 ]
            sqetools SQE Tools made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            Verification Not verified [ 17001 ]
            sqetools SQE Tools made changes -
            Labels noreg-cleanup autoverify noreg-cleanup
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8177485 [ JDK-8177485 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8178987 [ JDK-8178987 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8179208 [ JDK-8179208 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8181966 [ JDK-8181966 ]
            asaha Abhijit Saha made changes -
            Link This issue backported by JDK-8182112 [ JDK-8182112 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8182232 [ JDK-8182232 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8182955 [ JDK-8182955 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8184366 [ JDK-8184366 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8184526 [ JDK-8184526 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8189461 [ JDK-8189461 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8192383 [ JDK-8192383 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8193974 [ JDK-8193974 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8197082 [ JDK-8197082 ]

              People

              • Assignee:
                apetcher Adam Petcher
                Reporter:
                mullan Sean Mullan
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: