-
Notifications
You must be signed in to change notification settings - Fork 122
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
Changes from 1 commit
b02247a
6f45e71
ea282cc
d59fb85
f7a1fc8
98786e6
91ca217
0ac1741
eabffd0
d617845
cb6f30a
0b74ef5
e4aa5d9
772ebde
0eedccb
76e06d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
include(cmake/go.cmake) | ||
|
||
enable_language(C) | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Removed. Thanks. |
||
if(ENABLE_DATA_INDEPENDENT_TIMING) | ||
add_definitions(-DMAKE_DIT_AVAILABLE) | ||
endif() | ||
|
||
if(USE_CUSTOM_LIBCXX) | ||
if(NOT CLANG) | ||
message(FATAL_ERROR "USE_CUSTOM_LIBCXX only supported with Clang") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,4 +49,44 @@ void handle_cpu_env(uint32_t *out, const char *in) { | |
} | ||
} | ||
|
||
#if defined(MAKE_DIT_AVAILABLE) && !defined(OPENSSL_WINDOWS) | ||
// "DIT" is not recognised as a register name by clang-10 (at least) | ||
// Register's encoded name is from e.g. | ||
// 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
uint64_t val = 0; | ||
if (CRYPTO_is_ARMv8_DIT_capable()) { | ||
__asm__ volatile("mrs %0, s3_3_c4_c2_5" : "=r" (val)); | ||
} | ||
return val >> 24; | ||
dkostic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// See https://github.com/torvalds/linux/blob/53eaeb7fbe2702520125ae7d72742362c071a1f2/arch/arm64/include/asm/sysreg.h#L82 | ||
// As per Arm ARM for v8-A, Section "C.5.1.3 op0 == 0b00, architectural hints, | ||
// barriers and CLREX, and PSTATE access", ARM DDI 0487 J.a, system instructions | ||
// for accessing PSTATE fields have the following encoding | ||
// and C5.2.4 DIT, Data Independent Timing: | ||
// Op0 = 0, CRn = 4 | ||
// Op1 (3 for DIT) , Op2 (5 for DIT) encodes the PSTATE field modified and defines the constraints. | ||
// CRm = Imm4 (#0 or #1 below) | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. do we have to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. Thanks. |
||
// Encoding of "msr dit, #1" | ||
__asm__ volatile(".long 0xd503415f"); | ||
} | ||
return original_dit; | ||
dkostic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
void armv8_restore_dit(volatile uint64_t *original_dit) { | ||
if (CRYPTO_is_ARMv8_DIT_capable() && *original_dit != 1) { | ||
// Encoding of "msr dit, #0" | ||
__asm__ volatile(".long 0xd503405f"); | ||
} | ||
} | ||
#endif // MAKE_DIT_AVAILABLE && !OPENSSL_WINDOWS | ||
|
||
#endif // OPENSSL_AARCH64 && !OPENSSL_STATIC_ARMCAP |
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?