Skip to content

Missing Override in OpenSSLCipherRSA #317

Open

Description

@carl-mastrangelo

CipherSpi includes 3 overloads of engineDoFinal. OpenSSLCipherRSA overloads 2 of them, but not the 3rd one engineDoFinal(ByteBuffer, ByteBuffer). This method is called by Cipher when invoking doFinal.

Unfortunately, the CipherSpi implementation of engineDoFinal calls Cipher.bufferCrypt, which is slow. It makes array copies of the inputs if they are not backed by arrays. When using direct ByteBuffers, multiple unnecessary allocations and copies are made.

CC: @nmittler

Activity

  1. added this to the 1.0.0 milestone on Sep 1, 2017
  2. nmittler commented on Sep 1, 2017

    @nmittler
    Contributor

    @carl-mastrangelo what exactly is this issue for? Adding an override or performance work?

  3. carl-mastrangelo commented on Sep 1, 2017

    @carl-mastrangelo
    Author

    It's performance. The API call that leads to it is:

        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
        cipher.init(
            Cipher.ENCRYPT_MODE,
            new SecretKeySpec(key, "AES"),
            new GCMParameterSpec(TAG_LENGTH * 8, nonce));
        cipher.doFinal(plaintext, buffer);
    

    Bother buffer and plaintext are direct buffers. If you profile that you can see the slowdown in the function I mentioned Cipher.bufferCrypt

  4. nmittler commented on Sep 1, 2017

    @nmittler
    Contributor

    @carl-mastrangelo ah ok ... so the hope is that by adding the extra override, we will fix the perf issue. Should be an easy fix?

  5. carl-mastrangelo commented on Sep 1, 2017

    @carl-mastrangelo
    Author

    @nmittler Yeah, but I am really not that familiar with the Conscrypt APIs. I also thought maybe it wasn't implemented on purpose.

  6. nmittler commented on Sep 1, 2017

    @nmittler
    Contributor

    @kruton @flooey any thoughts?

  7. flooey commented on Sep 5, 2017

    @flooey
    Contributor

    Yep, this just looks like an oversight (the same problem exists in OpenSSLCipher). Should be relatively easy to fix.

  8. nmittler commented on Sep 12, 2017

    @nmittler
    Contributor

    FYI, I've been working on putting together a bechmark for our ciphers, but it's currently blocked by #330

  9. nmittler commented on Sep 18, 2017

    @nmittler
    Contributor

    Just added the cipher benchmark as a place to start from. A couple of things that I noticed that we can start with:

    • We're currently always passing arrays (or heap buffers) to JNI, which is known to be very slow. We should look into using direct ByteBuffers instead.

    • All the methods that take two ByteBuffers needlessly copy twice.

    I suspect that resolving these two items my get us to where we need.

  10. nmittler commented on Sep 20, 2017

    @nmittler
    Contributor

    @flooey I spent some time hacking our ciphers to see if I could improve the performance. I created this branch. Running with GCM, I see a significant increase in performance, although we're still not as fast as the JDK. More investigation is needed, but we're getting closer.

    Stepping back for a second ... Given that these ciphers do not impact TLS performance, I think we can defer this issue until after 1.0.0.

  11. modified the milestones: 1.0.0, 1.0.1 on Sep 20, 2017
  12. added a commit that references this issue on Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions