-
Notifications
You must be signed in to change notification settings - Fork 3k
Update Mbed TLS HW acceleration partner code to new hashing API #5973
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
Update Mbed TLS HW acceleration partner code to new hashing API #5973
Conversation
@hanno-arm Can you assign reviewers please? |
@0xc0170: I expect @mazimkhan and myself to review it - I can't request the review here, though. Could you please do that? |
@k-stachowiak Please resolve conflicts |
Conflicts resolved. |
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.
Some of MBEDTLS_ERR_<XYZ>_HW_ACCEL_FAILED
are not defined. Unless they are generated in some way. Please explain or fix.
} | ||
if (st_md5_save_hw_context(ctx) != 1) { | ||
return; // return HASH_BUSY timeout Error here | ||
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout |
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.
A general error MBEDTLS_ERR_MD5_HW_ACCEL_FAILED
here hides the timeout error 'HASH_BUSY' that could simply be to indicate that a retry after a delay may succeed. In general we have to preserve status indications from HW that do not mean actual failure. This should be reviewed by original developer to confirm if error code is correct.
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.
The HW_ACCEK_FAILED codes have been added upstream in Mbed TLS, which have not yet been merged to master in Mbed OS. Neither has the int returning API. This PR must be somehow synchronized with the import of the newest upstream Mbed TLS code.
I agree that the codes should be agreed with the original developer. My intention was to return any reasonable error code from the already available ones while maintaining the information about the errors in the comments as it was provided in the first place.
I think that fine tuning the actual return codes (maybe expanding the error code space for the HW acceleration) may be a task big enough for a separate PR, however I am open to suggestions about changing the return codes in this PR.
{ | ||
/* HASH IP initialization */ | ||
if (HAL_HASH_DeInit(&ctx->hhash_md5) != 0) { | ||
// error found to be returned | ||
return; | ||
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; |
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.
MBEDTLS_ERR_MD5_HW_ACCEL_FAILED
is used but not defined. Can't see a header file change.
{ | ||
/* Deinitializes the HASH peripheral */ | ||
if (HAL_HASH_DeInit(&ctx->hhash_sha1) == HAL_ERROR) { | ||
// error found to be returned | ||
return; | ||
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; |
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.
MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED
used but not defined.
} | ||
if (st_sha256_save_hw_context(ctx) != 1) { | ||
return; // return HASH_BUSY timeout Error here | ||
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout |
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.
MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED
used but not defined.
@0xc0170 this PR updates interface of the hashing functions by adding return value. This has to be utilised by the HW acceleration code. Is there a plan to notify partners to update their code and utilise new interface? |
ARM Internal Ref: IOTSSL-2072 |
Making a note here that this PR will need to come in before #6040 (comment) can be continued. |
The features/mbedtls/targets/TARGET_STM/* files include constant needed for the error codes returned from the MD functions. The features/mbedtls/targets/hash_wrappers.c provides thin redirection layer for the hardware accelerated MD implementations that rely on the old API. The TESTS/mbedtls/multi/main.cpp has been changed to use the new API as its build environment does not rely on the translation unit containing the necessary wrappers.
929e1bc
to
e1d42a5
Compare
@0xc0170 It seems that the CIs are green so far. I am not sure how long will the other CI tasks take, so maybe it is a good time to resume the review? |
/morph build |
Build : FAILUREBuild number : 1137 |
Please review the build failures |
f149937
to
2e9243f
Compare
/morph build |
Build : SUCCESSBuild number : 1139 Triggering tests/morph test |
Test : SUCCESSBuild number : 945 |
Exporter Build : SUCCESSBuild number : 814 |
@hanno-arm this PR has been merged without our approval. Please continue review and provide comments on dependent PR #6040 |
@hanno-arm @mazimkhan My mistake on that. Won't happen again. |
@cmonr no worries at all. |
As observed by @LiyouZhou, this PR currently breaks the build for two reasons: 1. The new hashing API hasn't yet been merged into Mbed OS. 2. Alternative implementations must implement both the new and the legacy API: The dummy wrappers from |
@k-stachowiak how did this not caught in the CI and wasn't these wrappers suppose to provide legacy API? |
@mazimkhan I don't know how this PR broke the build. I tested it locally and pushed here for the CI to perform tests. Neither my test nor the CIs have failed. While I agree that the PR should have been reviewed before merging, the automated tests gave misleadingly positive results. I did not expect anything here to break before the introduction of Mbed TLS 2.7.0. |
Testing some how does not catch this. |
Thanks @LiyouZhou
@k-stachowiak This PR shall be reverted if causing build problems. Can you fix the problem asap? |
This might explain your error #6176 (comment) |
Description
This pull request updates partner code in the Mbed TLS feature regarding the hardware acceleration for hashing on certain target devices.
Status
READY
Migrations
NO
This PR changes the alternative implementations of the following hashes:
for the following targets (families):
No user code needs to be changed as the old API has been maintained (however marked as deprecated) as a thin layer of functions calling the new implementations but ignoring the return codes. It is advisable, but not necessary, to refactor users' code to use the new API.
Related PRs
As of creating this PR the upstream functionality has not yet been merged into Mbed OS, therefore this PR should not be merged until Mbed TLS has been updated.
Todos
Deploy notes
None
Steps to test or reproduce
None