Skip to content
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

Introduce config option of 128-bit key only in AES calculation #7451

Merged
merged 31 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
732ca32
AES: add macro of MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Apr 14, 2023
0f06618
AES: skip 192bit and 256bit key in selftest if 128bit_only enabled
Apr 20, 2023
b1c626b
AES: adjust AES RAM usage according to config options
Apr 14, 2023
a870467
Add checks if MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH enabled
Apr 20, 2023
3eb50e7
all.sh: add test for AES_ONLY_128_BIT_KEY_LENGTH
Apr 14, 2023
ecb6a02
Add AES 128-bit key dependency for tests data
Apr 19, 2023
d98ae2f
Add AES 128-bit key dependency in test_suite_psa_crypto.data
Apr 21, 2023
a9808ce
Add AES 128-bit key dependency in test_suite_ssl.data
Apr 21, 2023
3f41744
generate_psa_tests.py: add extra dependencies based on key bit
Apr 21, 2023
3d4d146
mbedtls_config.h: fix issue in grammar
May 5, 2023
4a7fdff
mbedtls_config.h: paraphrase code size saving in comment
May 5, 2023
8b9877b
aes.h: add comment for round key buffer in aes context
May 5, 2023
1ed226f
Auto-enable CTR_DRBG_USE_128_BIT_KEY with AES_ONLY_128_BIT_KEY_LENGTH
May 5, 2023
374c3ae
all.sh: add test for AES-128bit only without MBEDTLS_CTR_DRBG_C
May 5, 2023
d9bf370
add ChangeLog entry
May 5, 2023
e2bc158
aesce.c: add macro of MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
May 8, 2023
5dd429c
generate_psa_tests.py: fix typo
May 10, 2023
ab4fb0d
aes.h: rewrite comment for aes round key buf
May 10, 2023
a30c72f
rewrite ChangeLog
May 10, 2023
d2ae432
mbedtls_config.h: rewrite comment for AES_ONLY_128_BIT_KEY_LENGTH
May 10, 2023
7265bab
mbedtls_config.h: remove empty * line before closing */ line
May 10, 2023
463351d
ChangeLog: remove issue number as this is a new feature
May 10, 2023
62c9991
aes selftest: remove non-128-bit data if aes_128bit_only enabled
May 11, 2023
59c2dfa
aes selftest: determine selftest loop limit in runtime
May 11, 2023
dd56add
cmac selftest: add macro for non-128-bit data/test
May 11, 2023
d329c69
gcm selftest: remove non-128-bit data if aes_128bit_only enabled
May 11, 2023
93533b5
gcm.c: do not set length for some arrays in selftest
May 11, 2023
d896fcb
nist_kw.c: remove non-128-bit data if aes_128bit_only enabled
May 11, 2023
012b6bb
all.sh: test AES built-in implementation in AES-128-bit key only
May 11, 2023
4292441
all.sh: use clang for one test of AES_ONLY_128_BIT_KEY_LENGTH
Jun 14, 2023
55ef22c
mbedtls_config.h: add description for CTR_DRBG about AES-128 only
Jun 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.d/add-aes-128bit-only.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Features
* Add support to restrict AES to 128-bit keys in order to save code size.
A new configuration option, MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH, can be
used to enable this feature.
5 changes: 5 additions & 0 deletions include/mbedtls/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ typedef struct mbedtls_aes_context {
int MBEDTLS_PRIVATE(nr); /*!< The number of rounds. */
size_t MBEDTLS_PRIVATE(rk_offset); /*!< The offset in array elements to AES
round keys in the buffer. */
#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && !defined(MBEDTLS_PADLOCK_C)
uint32_t MBEDTLS_PRIVATE(buf)[44]; /*!< Aligned data buffer to hold
10 round keys for 128-bit case. */
#else
uint32_t MBEDTLS_PRIVATE(buf)[68]; /*!< Unaligned data buffer. This buffer can
hold 32 extra Bytes, which can be used for
one of the following purposes:
Expand All @@ -84,6 +88,7 @@ typedef struct mbedtls_aes_context {
<li>Simplifying key expansion in the 256-bit
case by generating an extra round key.
</li></ul> */
#endif /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH && !MBEDTLS_PADLOCK_C */
}
mbedtls_aes_context;

Expand Down
8 changes: 8 additions & 0 deletions include/mbedtls/build_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
#include MBEDTLS_USER_CONFIG_FILE
#endif

/* Auto-enable MBEDTLS_CTR_DRBG_USE_128_BIT_KEY if
* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH and MBEDTLS_CTR_DRBG_C defined
* to ensure a 128-bit key size in CTR_DRBG.
*/
#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && defined(MBEDTLS_CTR_DRBG_C)
#define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
#endif

/* Auto-enable MBEDTLS_MD_C if needed by a module that didn't require it
* in a previous release, to ensure backwards compatibility.
*/
Expand Down
24 changes: 21 additions & 3 deletions include/mbedtls/mbedtls_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@
* performance if ROM access is slower than RAM access.
*
* This option is independent of \c MBEDTLS_AES_FEWER_TABLES.
*
*/
//#define MBEDTLS_AES_ROM_TABLES

Expand All @@ -518,10 +517,26 @@
* depends on the system and memory details.
*
* This option is independent of \c MBEDTLS_AES_ROM_TABLES.
*
*/
//#define MBEDTLS_AES_FEWER_TABLES

/**
* \def MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
*
* Use only 128-bit keys in AES operations to save ROM.
*
* Uncomment this macro to remove support for AES operations that use 192-
* or 256-bit keys.
*
* Uncommenting this macro reduces the size of AES code by ~300 bytes
* on v8-M/Thumb2.
tom-cosgrove-arm marked this conversation as resolved.
Show resolved Hide resolved
*
* Module: library/aes.c
*
* Requires: MBEDTLS_AES_C
*/
//#define MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH

/**
* \def MBEDTLS_CAMELLIA_SMALL_MEMORY
*
Expand Down Expand Up @@ -640,7 +655,8 @@
/** \def MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
*
* Uncomment this macro to use a 128-bit key in the CTR_DRBG module.
* By default, CTR_DRBG uses a 256-bit key.
* Without this, CTR_DRBG uses a 256-bit key
* unless \c MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH is set.
*/
//#define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY

Expand Down Expand Up @@ -2413,6 +2429,8 @@
* The CTR_DRBG generator uses AES-256 by default.
* To use AES-128 instead, enable \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY above.
*
* \note AES-128 will be used if \c MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH is set.
*
* \note To achieve a 256-bit security strength with CTR_DRBG,
* you must use AES-256 *and* use sufficient entropy.
* See ctr_drbg.h for more details.
Expand Down
Loading