Skip to content

Conversation

valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented Sep 19, 2025

This work tries to anticipate the changes required for the next Mbed TLS/TF-PSA-Crypto release (4.0/1.0) by removing usages of legacy crypto in favor of PSA API. Since there are several crypto algorithms that need to be replaced, this PR only focuses on hash algorithms, i.e. MD5, SHA1/224/256/384/512, and HMAC.

@valeriosetti valeriosetti force-pushed the remove-legacy-hash branch 4 times, most recently from 99f36a7 to 3bc96bf Compare September 23, 2025 07:21
@valeriosetti valeriosetti force-pushed the remove-legacy-hash branch 2 times, most recently from 032c040 to 65f1716 Compare October 7, 2025 15:43
@valeriosetti valeriosetti marked this pull request as ready for review October 7, 2025 21:20
- create an ad-hoc Kconfig file to hold all the Mbed TLS Kconfigs that are
  going to be deprecated;
- add Kconfig MBEDTLS_MD5 to the new Kconfig.deprecated file;
- remove usages of mbedtls_md5_xxx() form tests;
- replace CONFIG_MBEDTLS_MD5 with CONFIG_PSA_WANT_ALG_MD5 in the codebase;
- add migration-guide note about this deprecation.

Signed-off-by: Valerio Setti <[email protected]>
- add Kconfig MBEDTLS_SHA1 to Kconfig.deprecated;
- remove usages of mbedtls_sha1_xxx() form Zephyr codebase;
- replace CONFIG_MBEDTLS_SHA1 with CONFIG_PSA_WANT_ALG_SHA_1;
- add migration-guide note about this deprecation.

Signed-off-by: Valerio Setti <[email protected]>
- add Kconfig MBEDTLS_SHA224 to Kconfig.deprecated;
- add migration-guide note about this deprecation.

Signed-off-by: Valerio Setti <[email protected]>
- add Kconfig MBEDTLS_SHA256 to Kconfig.deprecated;
- remove usages of mbedtls_sha256_xxx() form Zephyr codebase;
- replace CONFIG_MBEDTLS_SHA256 with CONFIG_PSA_WANT_ALG_SHA_256;
- add migration-guide note about this deprecation.

Signed-off-by: Valerio Setti <[email protected]>
- add Kconfig MBEDTLS_SHA384 to Kconfig.deprecated;
- replace CONFIG_MBEDTLS_SHA348 with CONFIG_PSA_WANT_ALG_SHA_384;
- add migration-guide note about this deprecation.

Signed-off-by: Valerio Setti <[email protected]>
- add Kconfig MBEDTLS_SHA512 to Kconfig.deprecated;
- replace CONFIG_MBEDTLS_SHA512 with CONFIG_PSA_WANT_ALG_SHA_512;
- add migration-guide note about this deprecation.

Signed-off-by: Valerio Setti <[email protected]>
MD remains a public interface in the upcoming TF-PSA-Crypto 1.0 release,
but it still bring connections to legacy crypto and extra footprint
related to its wrapping functionalities. Since in most of the cases the
required hash algorithm is known, it's better to use the proper PSA
solution instead.

Unfortunately MBEDTLS_MD Kconfig cannot be deprecated as the other hash
related Kconfigs because it's still used in TLS.

This commit also adds a test for HMAC_SHA_256 (one of the functions that is
replaced in this commit) in "tests/crypto/mbedtls_psa".

Signed-off-by: Valerio Setti <[email protected]>
This is the last step in order to fully deprecate all Kcofnigs that are
related to legacy Mbed TLS hash support. A new Kconfig is added
(CONFIG_PSA_WANT_ALG_HASH_ALL) to replace the deprecated symbol in a PSA
fashion.

Signed-off-by: Valerio Setti <[email protected]>
The file "mbedtls.c" was copied from upstream Mbed TLS several years ago
and since then only minor fixes has been added when failing, no real
upgrade was made since then.

Reasons for removal include:
- some of the symbols were already removed (ex: MD2, MD4, RIPEMD160, ARC4, etc)
  but their testing was not removed;
- most of the code is guarded but "prj.conf" doesn't set any Kconfig related
  to the crypto features in Mbed TLS, so likely only the default ones are
  really tested;
- last but not least all of these "mbedtls_xxx_self_test()" function will
  disappear in the next TF-PSA-Crypto release so they cannot be maintained
  here.

This suite is replaced with tests in "zephyr/tests/crypto/mbedtls_psa".

"MAINTAINERS.yml" was also updated in this commit in order to reflect
this removal and add path for existing tests.

Signed-off-by: Valerio Setti <[email protected]>
The previous source file was copied from Mbed TLS several years ago and
since then not many updates were made. For example:
- testing stopped at CTR-DRBG exiting with failure;
- emulation wasn't really catching any output so a timeout of 60 seconds
  was required in order to fully complete the testing;
- the "harness: crypto" was preventing the code from being really tested
  with twister.

Last but not least, all of the functions used here belong to the legacy
Mbed TLS crypto support that is going to be removed from the next TF-PSA-Crypto
release.

The goal of this commit is to renew the test code making it really usable
and testable. For the time being hash and ciphers are tested, but asymmetric
key testing can be added in the future if desired.

Signed-off-by: Valerio Setti <[email protected]>
Copy link

sonarqubecloud bot commented Oct 8, 2025

@valeriosetti
Copy link
Contributor Author

I realized that this PR is touching a bit too many files and it's not easy to review. I will close it and split into sub-PRs. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants