-
Notifications
You must be signed in to change notification settings - Fork 119
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
Enabling DIT flag in AArch64. #1687
Conversation
- Add a compile flag to enable it. - DIT APIs and macro are available for external use. - Add the macro to Speed() commented out. That is where it was experimented with. Enabling it there make the benchmarks similar to not having DIT enabled. This is to suggest that the macro can be used by AWS-LC callers in their own scope around multiple calls to the library to improve the performance since DIT would not switch on and off at the entry/exit of the library functions.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1687 +/- ##
=======================================
Coverage 78.43% 78.44%
=======================================
Files 580 580
Lines 96756 96779 +23
Branches 13877 13864 -13
=======================================
+ Hits 75888 75915 +27
+ Misses 20249 20248 -1
+ Partials 619 616 -3 ☔ View full report in Codecov by Sentry. |
CMakeLists.txt
Outdated
@@ -23,6 +23,7 @@ option(ENABLE_DILITHIUM "Enable Dilithium signatures in the EVP API" OFF) | |||
option(DISABLE_PERL "Disable Perl for AWS-LC" OFF) | |||
option(DISABLE_GO "Disable Go for AWS-LC" OFF) | |||
option(ENABLE_FIPS_ENTROPY_CPU_JITTER "Enable FIPS entropy source: CPU Jitter" OFF) | |||
option(ENABLE_DATA_INDEPENDENT_TIMING "Enable Data-Independent Timing (DIT) flag" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a bit more specific?
option(ENABLE_DATA_INDEPENDENT_TIMING "Enable Data-Independent Timing (DIT) flag" OFF) | |
option(ENABLE_DATA_INDEPENDENT_TIMING_AARCH64 "Enable Data-Independent Timing (DIT) flag" OFF) |
CMakeLists.txt
Outdated
@@ -801,6 +802,11 @@ else() | |||
set(ARCH "generic") | |||
endif() | |||
|
|||
#if(ENABLE_DATA_INDEPENDENT_TIMING AND ARCH EQUAL "aarch64") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. Thanks.
// Rt = 0x1f | ||
uint64_t armv8_enable_dit(void) { | ||
uint64_t original_dit = armv8_get_dit(); | ||
if (CRYPTO_is_ARMv8_DIT_capable() && original_dit != 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have to check original_dit != 1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. Thanks.
include/openssl/crypto.h
Outdated
uint64_t armv8_enable_dit(void); | ||
void armv8_restore_dit(volatile uint64_t *original_dit); | ||
|
||
#define ENABLE_DIT_ALL \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like this is unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks dkostic. Removed.
include/openssl/crypto.h
Outdated
OPENSSL_UNUSED = armv8_enable_dit(); | ||
|
||
|
||
#define ENABLE_DIT_AUTO_DISABLE \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having both enable and disable in the name is a bit confusing. can we do SET_DIT_AUTO_DISABLE
or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…unction following it.
// https://github.com/ashwio/arm64-sysreg-lib/blob/d421e249a026f6f14653cb6f9c4edd8c5d898595/include/sysreg/dit.h#L286 | ||
#define DIT_REGISTER s3_3_c4_c2_5 | ||
|
||
uint64_t armv8_get_dit(void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function can be static since it's not used outside this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I don't see any documentation about how, if all the DIT twiddling cause perf degradation, at a higher level in the program DIT could be enabled. Is it worth documentating that somewhere to try and define an API for that that other crypto libs would also adopt? |
crypto/fipsmodule/cipher/cipher.c
Outdated
@@ -114,6 +114,7 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) { | |||
return 0; | |||
} | |||
GUARD_PTR(out); | |||
SET_DIT_AUTO_DISABLE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have a convention to always add at the beginning of a function? That the error path might take a negligible amount of extra time is fine IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
const BIGNUM *DH_get0_pub_key(const DH *dh) { return dh->pub_key; } | ||
const BIGNUM *DH_get0_pub_key(const DH *dh) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed when simply returning a pointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adopted the mind set of protecting access to structs that contain secret data that can cause memory prefetching.
@@ -97,6 +97,7 @@ DH *DH_new_by_nid(int nid) { | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed calculate_rfc7919_DH_from_p()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I guess those are public parameters...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I don't see any secret used or accessed (even nearby) in this function.
tool/speed.cc
Outdated
@@ -2584,6 +2584,7 @@ static bool parseStringVectorToIntegerVector( | |||
} | |||
|
|||
bool Speed(const std::vector<std::string> &args) { | |||
//SET_DIT_AUTO_DISABLE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add this as an option to the speed tool
crypto/fipsmodule/tls/kdf.c
Outdated
@@ -58,7 +58,7 @@ | |||
#include <openssl/mem.h> | |||
|
|||
#include "../../internal.h" | |||
|
|||
#include "../service_indicator/internal.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why include?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. Thanks.
- Also add documentation to the user on the use of the macro and the functions. - Enable the use of DIT flag in speed test via a command line option.
Thank you @AGSaidi, I added the documentation to BUILDING.md and to crypto.h. |
Issues:
Addresses CryptoAlg-2501
Description of changes:
-dit
to the speed test that's available in a build that used the compile flag.Enabling it makes the benchmarks closer to not having DIT enabled.
This is to suggest that the macro can be used by AWS-LC callers in their own scope
around multiple calls to the library to improve the performance since,
in that case, DIT would not switch on and off at the entry/exit of the library functions.
Call-outs:
N/A
Testing:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.