Skip to content

8334999: RISC-V: implement AES single block encryption/decryption intrinsics #19960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from

Conversation

ArsenyBochkarev
Copy link
Contributor

@ArsenyBochkarev ArsenyBochkarev commented Jun 30, 2024

Hello everyone! Please review this port of vector AES single block encryption/decryption intrinsics. On my QEMU with Zvkned extension enabled the test/hotspot/jtreg/compiler/codegen/aes/TestAESMain.java test is OK. I know that currently hardware implementing this extension is not available on the market but I suppose this PR can be a good starting point on supporting AES intrinsics for RISC-V in OpenJDK.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8334999: RISC-V: implement AES single block encryption/decryption intrinsics (Sub-task - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19960/head:pull/19960
$ git checkout pull/19960

Update a local copy of the PR:
$ git checkout pull/19960
$ git pull https://git.openjdk.org/jdk.git pull/19960/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19960

View PR using the GUI difftool:
$ git pr show -t 19960

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19960.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 30, 2024

👋 Welcome back ArsenyBochkarev! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 30, 2024

@ArsenyBochkarev This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8334999: RISC-V: implement AES single block encryption/decryption intrinsics

Reviewed-by: fyang, rehn, yzhu

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 76 new commits pushed to the master branch:

  • c40bb76: 8343296: IGV: Show pre/main/post at CountedLoopNodes
  • dee0982: 8343132: Remove temporary transitions from Virtual thread implementation
  • 2f1ba5e: 8343307: Throw ZipException instead of IAE in ZipFile.Source::initCEN
  • 388d44f: 8342156: C2: Compilation failure with fewer arguments after JDK-8329032
  • 688e92e: 8342642: Class loading failure due to archived map issue in ModuleLoaderMap.Mapper
  • f340ab2: 8342181: Update tests to use stronger Key and Salt size
  • cc2fb4d: 8337276: jcmd man page update for PID in output filenames
  • 02ea4b5: 8342635: javax/swing/JFileChooser/FileSystemView/WindowsDefaultIconSizeTest.java creates tmp file in src dir
  • 7461dfe: 8341788: Fix ExceptionOccurred in hotspot
  • 9a9ac1d: 8341927: Replace hardcoded security providers with new test.provider.name system property
  • ... and 66 more: https://git.openjdk.org/jdk/compare/d1540e2a49c7a41eb771fc9896c367187d070dec...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@robehn, @RealFYang) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 30, 2024
@openjdk
Copy link

openjdk bot commented Jun 30, 2024

@ArsenyBochkarev The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Jun 30, 2024
@mlbridge
Copy link

mlbridge bot commented Jun 30, 2024

Copy link
Contributor

@robehn robehn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looks good!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 1, 2024
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jul 7, 2024
@ArsenyBochkarev
Copy link
Contributor Author

As for comparison with the openssl version: first of all, thanks for the sources, @RealFYang! The main difference that I see is that they introduced three different different versions of encryption depending on the key sizes, which allows them to skip a couple of instructions, like when I did vaesem_vv(res, vzero) followed by vxor_vv(res, res, vtemp1). So I thought it'll be more efficient to replace the current version by something openssl-lookalike. The only problem I see is increasing code size a bit. Please let me know if we are not interested in this change for some reason

@RealFYang
Copy link
Member

RealFYang commented Jul 18, 2024

As for comparison with the openssl version: first of all, thanks for the sources, @RealFYang! The main difference that I see is that they introduced three different different versions of encryption depending on the key sizes, which allows them to skip a couple of instructions, like when I did vaesem_vv(res, vzero) followed by vxor_vv(res, res, vtemp1). So I thought it'll be more efficient to replace the current version by something openssl-lookalike. The only problem I see is increasing code size a bit. Please let me know if we are not interested in this change for some reason

Does vaesz_vs help in anyway? And what about the generate_aescrypt_decryptBlock? [1]

[1] https://github.com/openssl/openssl/blob/master/crypto/aes/asm/aes-riscv64-zvkned.pl#L451

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 15, 2024

@ArsenyBochkarev This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@ArsenyBochkarev
Copy link
Contributor Author

ArsenyBochkarev commented Sep 8, 2024

Hello @RealFYang! Sorry for such a late reply.

Does vaesz_vs help in anyway?

As far as I know, the vaesz_vs instruction is just an alias for vxor, so it was already utilized in this patch.

generate_aescrypt_decryptBlock

I missed this case in initial multiversioning commit, so I multiversioned the decrypt intrisic also, thanks for pointing it out!

@luhenry
Copy link
Member

luhenry commented Sep 19, 2024

@RealFYang following up on your questions. I would love to see this one go through as it promises some pretty significant gains on compatible hardware! Thanks again

@RealFYang
Copy link
Member

@RealFYang following up on your questions. I would love to see this one go through as it promises some pretty significant gains on compatible hardware! Thanks again

Yeah, will take another look. Have you tried this on real hardware? Interesting to see the numbers.

@luhenry
Copy link
Member

luhenry commented Sep 20, 2024

Yeah, will take another look. Have you tried this on real hardware? Interesting to see the numbers.

There is no real hardware that I know of that have vector crypto just yet. I expect it's one of these that we'll want to test as soon as hardware is available, and even possibly enable by default then

@ArsenyBochkarev
Copy link
Contributor Author

Hi all! I'm sorry for such a late replies. I was able to optimize decryption sequence by using keys from encryption stage with reversed rounds order

@yhzhu20
Copy link

yhzhu20 commented Oct 22, 2024

Thanks for the update. Do you mind several more minor cleanups? Looks good to me otherwise. Thanks.
addon-cleanup.diff.txt

@ArsenyBochkarev
Copy link
Contributor Author

@yhzhu20 Done!

@openjdk
Copy link

openjdk bot commented Oct 24, 2024

@ArsenyBochkarev Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@yhzhu20
Copy link

yhzhu20 commented Oct 25, 2024

@yhzhu20 Done!

Thank you. Approved.

Copy link
Member

@RealFYang RealFYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. Two comments remain. seems fine otherwise.

Copy link
Member

@RealFYang RealFYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 31, 2024
@ArsenyBochkarev
Copy link
Contributor Author

Thanks everyone for all the comments and reviews!

@ArsenyBochkarev
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 31, 2024
@openjdk
Copy link

openjdk bot commented Oct 31, 2024

@ArsenyBochkarev
Your change (at version a620b6a) is now ready to be sponsored by a Committer.

@VladimirKempik
Copy link

/sponsor

@openjdk
Copy link

openjdk bot commented Oct 31, 2024

Going to push as commit e5bbad0.
Since your change was applied there have been 76 commits pushed to the master branch:

  • c40bb76: 8343296: IGV: Show pre/main/post at CountedLoopNodes
  • dee0982: 8343132: Remove temporary transitions from Virtual thread implementation
  • 2f1ba5e: 8343307: Throw ZipException instead of IAE in ZipFile.Source::initCEN
  • 388d44f: 8342156: C2: Compilation failure with fewer arguments after JDK-8329032
  • 688e92e: 8342642: Class loading failure due to archived map issue in ModuleLoaderMap.Mapper
  • f340ab2: 8342181: Update tests to use stronger Key and Salt size
  • cc2fb4d: 8337276: jcmd man page update for PID in output filenames
  • 02ea4b5: 8342635: javax/swing/JFileChooser/FileSystemView/WindowsDefaultIconSizeTest.java creates tmp file in src dir
  • 7461dfe: 8341788: Fix ExceptionOccurred in hotspot
  • 9a9ac1d: 8341927: Replace hardcoded security providers with new test.provider.name system property
  • ... and 66 more: https://git.openjdk.org/jdk/compare/d1540e2a49c7a41eb771fc9896c367187d070dec...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 31, 2024
@openjdk openjdk bot closed this Oct 31, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Oct 31, 2024
@openjdk
Copy link

openjdk bot commented Oct 31, 2024

@VladimirKempik @ArsenyBochkarev Pushed as commit e5bbad0.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

6 participants