-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
AES: Add accelerator only mode #7384
Changes from all commits
0d4f4e5
d767cc4
2f26a59
315fd30
4d030f3
1b3ab36
3fcf2b5
8840a8c
3660623
d76ded0
4dfbb2e
02b1519
9e3e3dd
e77c4d9
6943681
1414029
69dd441
1221a31
17a9d2e
8a599c0
193cbc0
c935aa6
2700ef6
29c91ba
b241db3
fce351d
9c0b7d1
7802f65
5fcdd6a
c4508c0
a7de78d
76a51b9
ba42b07
13696bb
8189f32
240bb11
e62ff09
cc068ae
c628486
b6d39c2
506759f
3ce0398
516cf27
bdd96b9
35b59d7
2319af0
9e62862
1b4c7ed
f258d17
e9c6b53
6c6b9f6
3a0f044
9608447
372f7a0
61fc5ed
0a6272d
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Features | ||
* New configuration option MBEDTLS_AES_USE_HARDWARE_ONLY introduced. When | ||
using CPU-accelerated AES (e.g., Arm Crypto Extensions), this option | ||
disables the plain C implementation and the run-time detection for the | ||
CPU feature, which reduces code size and avoids the vulnerability of the | ||
plain C implementation. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4006,4 +4006,18 @@ | |
*/ | ||
//#define MBEDTLS_ECP_WITH_MPI_UINT | ||
|
||
/* | ||
* Disable plain C implementation for AES. | ||
* | ||
* When the plain C implementation is enabled, and an implementation using a | ||
* special CPU feature (such as MBEDTLS_AESCE_C) is also enabled, runtime | ||
* detection will be used to select between them. | ||
* | ||
* If only one implementation is present, runtime detection will not be used. | ||
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. We should clarify that attempts to use AES will invoke the accelerator code, which will cause an instruction fault if the code is running on a platform that lacks the acceleration instructions. |
||
* This configuration will crash at runtime if running on a CPU without the | ||
* necessary features. It will not build unless at least one of MBEDTLS_AESCE_C | ||
* and/or MBEDTLS_AESNI_C is enabled & present in the build. | ||
*/ | ||
daverodgman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//#define MBEDTLS_AES_USE_HARDWARE_ONLY | ||
|
||
daverodgman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** \} name SECTION: Module configuration options */ |
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 need to auto-enable 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. No. 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. When What I want to ask is, do we need to eliminate the plain C implementation when 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.
Yes. The first name of 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. And I think it should just remove plain C . MBEDTLS_AES_[EN|DE]CRYPT_ALT will remove both hardware and software built-in aes |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,13 +35,20 @@ | |
/* Can we do AESNI with inline assembly? | ||
* (Only implemented with gas syntax, only for 64-bit.) | ||
*/ | ||
#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \ | ||
daverodgman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(defined(__amd64__) || defined(__x86_64__)) && \ | ||
!defined(MBEDTLS_HAVE_X86_64) | ||
#if !defined(MBEDTLS_HAVE_X86_64) && \ | ||
(defined(__amd64__) || defined(__x86_64__) || \ | ||
defined(_M_X64) || defined(_M_AMD64)) && \ | ||
!defined(_M_ARM64EC) | ||
#define MBEDTLS_HAVE_X86_64 | ||
#endif | ||
|
||
#if defined(MBEDTLS_AESNI_C) | ||
#if !defined(MBEDTLS_HAVE_X86) && \ | ||
(defined(__i386__) || defined(_M_IX86)) | ||
#define MBEDTLS_HAVE_X86 | ||
#endif | ||
|
||
#if defined(MBEDTLS_AESNI_C) && \ | ||
(defined(MBEDTLS_HAVE_X86_64) || defined(MBEDTLS_HAVE_X86)) | ||
|
||
/* Can we do AESNI with intrinsics? | ||
* (Only implemented with certain compilers, only for certain targets.) | ||
|
@@ -67,8 +74,13 @@ | |
* In the long run, we will likely remove the assembly implementation. */ | ||
#if defined(MBEDTLS_AESNI_HAVE_INTRINSICS) | ||
#define MBEDTLS_AESNI_HAVE_CODE 2 // via intrinsics | ||
#elif defined(MBEDTLS_HAVE_X86_64) | ||
#elif defined(MBEDTLS_HAVE_ASM) && \ | ||
defined(__GNUC__) && defined(MBEDTLS_HAVE_X86_64) | ||
#define MBEDTLS_AESNI_HAVE_CODE 1 // via assembly | ||
#elif defined(__GNUC__) | ||
# error "Must use `-mpclmul -msse2 -maes` for MBEDTLS_AESNI_C" | ||
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 prefer add These checks should be moved to C file like other modules. And I do not think the module should be disabled silently. 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 still need assembly code ? With pragma, we can not cover assembly code in CI. 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. We were planning to maybe remove the assembly code. It's still useful for older runtimes that don't have the intrinsics. The question is, do we still care about these old runtimes? 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. Also the assembly still gets used when compiling without the 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. With
Yes. But my question is how old is it? I think we should check compilers and make the decision. I am looking for old compilers. I can not get gcc <4.6 binary and I am not sure old clang can work on my environment. 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. gcc 4.6.1 is from 2011, 12 years ago. It is reasonable for development to require a compiler from the last 10 years. We certainly don't need to go back that far for clang - in 2014 clang 3.5 couldn't build 95% of the Debian archive, and it wasn't until 2018 that it was used to build Firefox for Windows. I have a Docker environment for clang 6.0.1-14 on x86_64, which seems a reasonable oldest to support, although I would be happy with requiring an even more recent minimum version if necessary 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. Could you share the environment? 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. It was built from my base 20.04 Ubuntu aarch64 (runs in virtual environment on M1 Mac) environment with just
which makes me think it should be do-able on any Ubuntu 20.04 The system parts of my 20.04 setup are
|
||
#else | ||
#error "MBEDTLS_AESNI_C defined, but neither intrinsics nor assembly available" | ||
#endif | ||
|
||
#if defined(MBEDTLS_AESNI_HAVE_CODE) | ||
|
@@ -88,7 +100,11 @@ extern "C" { | |
* | ||
* \return 1 if CPU has support for the feature, 0 otherwise | ||
*/ | ||
#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY) | ||
int mbedtls_aesni_has_support(unsigned int what); | ||
#else | ||
#define mbedtls_aesni_has_support(what) 1 | ||
#endif | ||
|
||
/** | ||
* \brief Internal AES-NI AES-ECB block encryption and decryption | ||
|
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.
If the ChangeLog is information for library users, this doesn't really tell me whether I need it or not. Should we add something like
Enable if - but only if - you know the library will only be used on systems with CPU-accelerated AES
And I wonder if a sentence like that might be useful in the config file too?
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 the documentation in
mbedtls_config
is pretty clear now (it says it will crash at runtime if you don't have CPU support). Anyone who uses this feature will read that for the full details.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.
Agree with Dave. The information should be put at document of option.
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.
It's just that, reading both the ChangeLog entry and the config file entry after being away from it for a few days, neither gives me a sense of when I might want to enable it. The ChangeLog entry says what happens, but doesn't give reasons why enabling it might be a good idea.
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.
Surely "reduces code size and avoids the vulnerability" tells users why they might want it?