Reporting Issues
Bug 2507 - Support architecture-specific openssl acceleration
Summary: Support architecture-specific openssl acceleration
Status: RESOLVED FIXED
Alias: None
Product: Tianocore Feature Requests
Classification: Unclassified
Component: Code (show other bugs)
Version: Current
Hardware: All All
: Normal normal
Assignee: sunguk-bin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-07 18:18 UTC by Eugene Cohen
Modified: 2022-11-11 15:04 UTC (History)
7 users (show)

See Also:
EDK II Code First industry standard specifications: ---
Branch URL:
Release(s) the issue is observed: EDK II Master
The OS the target platform is running: ---
Package: CryptoPkg
Release(s) the issues must be fixed: EDK II Master
Tianocore documents:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Cohen 2020-02-07 18:18:34 UTC
OpenSSL supports accelerating certain operations like SHA and AES using processor architecture specific mechanisms.  This can be selected in the OpenSSL configuration process with configurations that inherit from architecture specific configs like asm("aarch64_asm") or asm("x86_64_asm").  We will likely need to update the UEFI config to add these configs like:

  inherit_from     => [ "BASE_unix", asm("x86_64_asm"), , asm("aarch64_asm") ],

To further complicate things the assembly language implementation in openssl requires a perl script to generate the appropriate assembly syntax for the requested toolchain, e.g.:

  perl crypto/aes/asm/aesv8-armx.pl linux64 crypto/aes/aesv8-armx.S

The perl assembly generation will need to occur before the build - perhaps from the process_files.pl which resides in the OpensslLib directory.

Lastly some changes will likely be required to get the build working for UEFI - hopefully these can be upstreamed to openssl.
Comment 1 Christopher Zurcher 2020-02-21 19:34:04 UTC
I have already implemented the necessary changes, and will be sending a review soon. The current plan is to check in the generated assembly files just as we check in the generated header files.
The initial OpenSSL changes are committed here but do not include aarch64:
https://github.com/openssl/openssl/commit/1b72105076bb2e73f3c8461f9c0ca5ecefe007c8
Comment 2 Eugene Cohen 2020-02-21 23:32:28 UTC
Thanks Chris, I added Ard in hopes of getting AArch64 support.
Comment 3 sunguk-bin 2020-10-27 21:53:04 UTC
There is another problem to use HW acceleration. CryptLib is not using EVP and it should be changed to use EVP.
Comment 4 gaoliming 2020-10-27 22:01:02 UTC
Eugene Cohen: can you work on it?
Comment 5 gaoliming 2020-10-27 22:11:47 UTC
Sung takes it.
Comment 6 gaoliming 2021-06-20 21:15:01 UTC
this is a new feature.
Comment 7 Christopher Zurcher 2021-07-30 18:18:56 UTC
This has been partially resolved with these commits:

878a92a887ef4ca879d336f323e91b13cc767a59
147f34b56ce0e2e18285ef7d0695753ac0aa5085

Acceleration of SHA variants is now possible. The current AES implementation in OpensslLib does not use the correct API to access the accelerated code in OpenSSL.
Comment 8 sunguk-bin 2021-08-04 04:46:03 UTC
I was able to use ARM crypto extension for openssl with some patches that Chris provided.
https://edk2.groups.io/g/devel/message/66701
https://edk2.groups.io/g/devel/message/66704?p=,,,20,0,0,0::recentpostdate%252Fsticky,,Add+EVP+implementation,20,2,0,77870226

There was a problem building openssl/crypto/armcap.c. This is because armcap.c is using some signal related functions like sigsetjmp, siglongjmp, etc. These functions are used to check if crypto instructions are supported. Since I already knew the capabilities of our system, I changed armcap.c and forced OPENSSL_armcap_P to a specific value.

To support arm crypto extension fully in UEFI, I think that openssl code(armcap.c) should be updated.
Comment 9 Christopher Zurcher 2021-08-04 18:40:06 UTC
From the EDK2 side, we cannot change the OpenSSL code, since it's pulled in as a submodule directly from OpenSSL. You might be able to add functionality to the getenv() function in CrtWrapper.c, and pre-populate the "OPENSSL_armcap" value somehow.
Comment 10 Michael Kinney 2022-11-11 15:04:24 UTC
The following commits add IA32/X64 optimized versions

https://github.com/tianocore/edk2/commit/a8e8c43a0ef25af133dc5ef1021befd897f71b12
https://github.com/tianocore/edk2/commit/4102950a21dc726239505b8f7b8e017b6e9175ec
https://github.com/tianocore/edk2/commit/03f708090b9da25909935e556c351a4d9445fd3f

And the following commit combines the optimized INFs

https://github.com/tianocore/edk2/commit/ea6d859b50b692577c4ccbeac0fb8686fad83a6e

With these changes, this feature can be closed as Resolved/Fixed.

If optimization work is required for more openssl APIs or for other CPU atchs, then those can be entered as new feature requests.