-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix #5079. Support of call to mbedtls_x_finish without calling mbedtls_x_update #5630
Fix #5079. Support of call to mbedtls_x_finish without calling mbedtls_x_update #5630
Conversation
ARM Internal Ref: IOTSSL-1930 |
Hello @andresag01 |
Hi @adustm, thanks for the fix! I have not done a thorough review, but after a quick look the changes look good. However, @mazimkhan and @hanno-arm will be doing the reviews on hardware acceleration-related changes from now on and they need to approve this. In the meantime, I have replied to your question here regarding the linking of MD5. Perhaps it would be good to include the change I suggested in my comment in this PR to ensure the linking problem does not persist? What are your thoughts? |
Hi, The test is now 100% tested and OK. Kind regards |
bump... |
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.
LGTM
@@ -175,6 +175,12 @@ void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] ) | |||
return; // Return error code here | |||
} | |||
} | |||
/* The following test can happen when the input is empty, and mbedtls_md5_update has never been called */ |
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.
- This seems to introduce a redundancy with the pre-existing code https://github.com/ARMmbed/mbed-os/pull/5630/files#diff-00438dce44385c38da7359547815b2daR135 handling the case of an
update
call with an empty buffer. - Why are we not unconditionally calling
HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, ctx->sbuf, ctx->sbuf_len)
here, even ifctx->sbuf_len == 0
? Looking at the code forHAL_HASH_MD5_Accumulate
, it always performs the same check forhhash_md5.Phase
and updatesHASH->CR
if it findsHAL_HASH_PHASE_READY
. Is there any problem with callingHAL_HASH_MD5_Accumulate
with an empty buffer?
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.
Hello @hanno-arm ,
Thank you for this finding.
I've tested your suggested modification and it works fine. I applied this suggestion also for SHA1 and SHA256. You can find it in the next commit.
Kind regards
Dear all,
I did the same for SHA1 and SHA256. Kind regards |
} | ||
/* Last accumulation for extra bytes in sbuf_len */ | ||
/* This allows the HW flags to be in place in case mbedtls_sha256_update has not been called yet */ | ||
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, ctx->sbuf, ctx->sbuf_len) != 0) { |
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.
@adustm Thank you for the changes! As far as I see, there's still a redundancy in xxx_update
: given the current version of xxx_finish
, which always calls HAL_HASH_MD5_Accumulate
, it should be fine for xxx_update
to be a no-op on an empty buffer.
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.
Hello @hanno-arm
If I remove this 2nd redundancy, the md5 mbedtls-selftest is crashing, that's why I've kept it.
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.
@adustm To be sure we understand each other correctly: As far as I understand the code, it should be fine to remove the code-path for currentlen == 0
from xxx_update
- but leaving xxx_finish
as it is now. In particular, it shouldn't yield any change in behavior for the testing of starts-finish
without update
.
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.
Hello @hanno-arm
Thanks for insisting, I have made more tests.
The updated version of the code avoids the remaining redundancy and passes md5_selftest successfully.
Kind regards
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.
@adustm Thank you for the rework!
@adustm, has any progress been made on this PR? |
@adustm, thank you for your changes. You should get some feedback from the following people shortly: @RonEld @hanno-arm @mazimkhan please review. |
…if mbedtls_xxx_udate was not called since mbedtls_xxx_start
7e18ea4
to
88c3b3e
Compare
Hi, Kind regards |
Building whilst waiting on the last review. /morph build |
Build : FAILUREBuild number : 1015 |
Failure unrelated to this PR. In the process of resolving. |
/morph build |
Build : SUCCESSBuild number : 1021 Triggering tests/morph test |
Test : SUCCESSBuild number : 831 |
Exporter Build : SUCCESSBuild number : 707 |
@hanno-arm Can you review the latest update. All your comments should have been addressed. |
Description
Fix #5079
Support of call to mbedtls_x_finish without calling mbedtls_x_update.
Status
READY
Before the PR: failure occurs in case of an empty input and mbedtls_xx_update is not called between xxx_start and xxx_finish
After this PR:
[] To do: test MD5, as it is not compiled in mbed-os (I could not find a way to activate it, can someone help me for this ?)[edit 12.14.2017 -> MD5 link issue is now fixed.]Steps to test or reproduce
Use the test available in #5079