Skip to content

Fix issues in Cryptocell 310 ccm_alt discovered by On Target Testing #8704

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

Merged
merged 9 commits into from
Nov 27, 2018

Conversation

RonEld
Copy link
Contributor

@RonEld RonEld commented Nov 11, 2018

Description

Fix issues discovered by On Target Testing on the NRF52840_DK platform:
1. Check add len is not too big.
2. Fix memory overflow, by adding a local buffer for the tag result.
3. Return MBEDTLS_ERR_CCM_AUTH_FAILED where needed.
4. Add unsupported functions for CCM*.
5. Zeroize output buffer, upon authentication faliure.
6. Use mbedtls_platform_zeroize() instead of mbedtls_zeroize()

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

@RonEld
Copy link
Contributor Author

RonEld commented Nov 11, 2018

Note: This PR will conflict with #8643

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 12, 2018

Note: This PR will conflict with #8643

What order they should be integrated? I assume first 8643 and this one rebased afterwards?

@0xc0170 0xc0170 requested a review from a team November 12, 2018 08:58
@RonEld
Copy link
Contributor Author

RonEld commented Nov 12, 2018

@0xc0170 Actually they are not dependent on each other.
The conflict will be because #8643 renames error codes returned by the function, while this PR, returns the previous error code, but added some conditions, in the same changed lines.

This PR fixes exiting bugs, while 8643 resolves future issues ( after newer version of Mbed TLS will be merged)
In summary, I would first integrate this PR, and after that rebase 9643
Note that 9643 is not a blocker, as merging Mbed TLS should not break build, as it was first suspected, and was the incentive for that PR

Copy link
Contributor

@adbridge adbridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appear to be camelcase variables in this code. This contravenes the mbed-os coding guidelines....

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 15, 2018

There appear to be camelcase variables in this code. This contravenes the mbed-os coding guidelines....

From my review, those are the one from SDK, not our functions, so should be good. @RonEld Please recheck

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 15, 2018

@ARMmbed/mbed-os-crypto Please review the latest update

@RonEld
Copy link
Contributor Author

RonEld commented Nov 15, 2018

I wil change all the camelcase variables that are changeable:
CrysRet -> crys_ret
CC_Mac_Res -> cc_mac_res

@RonEld
Copy link
Contributor Author

RonEld commented Nov 15, 2018

@0xc0170 @adbridge I have renamed the camelcase variable.
I have also modified the header files and remove the function declarations, as they are now not needed to be declared in the alternative headers

@yanesca
Copy link
Contributor

yanesca commented Nov 15, 2018

@RonEld The first commit fixes 6 unrelated issues. Could you please split it up to 6 different commits?

@RonEld RonEld force-pushed the cryptocell_ccm_alt_fixes branch 5 times, most recently from 77d64ef to ce86f0f Compare November 15, 2018 16:27
@0xc0170
Copy link
Contributor

0xc0170 commented Nov 15, 2018

Updated, @yanesca please rereview

@0xc0170 0xc0170 requested a review from a team November 15, 2018 16:53
@RonEld
Copy link
Contributor Author

RonEld commented Nov 15, 2018

@yanesca I rebased to split the first commit to 6 different commits.
I also amended the "Additional fix for ccm_alt from On Target Testings" commit with the same fix on the encryption path, which was lost among all the merges \ rebases.
I also amended the style fixes commit with removing whitespaces before the opening parenthesis.

@yanesca
Copy link
Contributor

yanesca commented Nov 16, 2018

Thank you very much, I'll have a look at it as soon as I can!

@RonEld
Copy link
Contributor Author

RonEld commented Nov 16, 2018

@yanesca Thanks!
I've been thinking. The function mbedtls_ccm_setkey(), returns MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE for every key size that is not 128 bits long, because Cryptocell310 only supports this key size. I think it is worth returning MBEDTLS_ERR_CCM_BAD_INPUT in invalid key sizes ( such as 224), and return the MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE for 192 and 256 bits size keys. What do you think? If you agree, I will work on this first thing next week, but I don't think it should block this PR

@yanesca
Copy link
Contributor

yanesca commented Nov 16, 2018

I agree, that would be a nice improvement!

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 26, 2018

@RonEld Please also rebase with the fixing the review above

Once done, we'll start CI

@RonEld
Copy link
Contributor Author

RonEld commented Nov 26, 2018

@0xc0170 Sure, no problem.
Since the fixes are style changes, would you like me to squash the fixes with c314242 ?

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 26, 2018

Since the fixes are style changes, would you like me to squash the fixes with c314242 ?

It could be.

Ron Eldor added 3 commits November 26, 2018 15:32
1. Change camelcase variables to Mbed OS style.
2. Remove functions declarations from the `_alt` header, since they
are now added from the module header regardless whether an alternative
implementation exists.
3. Remove the `extern "c"` declaration from the `_alt` headers.
4. Remove whitespaces before opening parenthesis.
5. Fix alignment of function parameters.
6. Fix indentations.
7. Limit lines to 80 characters.
Return `MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE` only for valid key lengths,
that are not supported by Cryptocell 310. For other key sizes, return
`MBEDTLS_ERR_CCM_BAD_INPUT`
Replace the module specific errors with the `MBEDTLS_ERR_PLATFORM_XXX`
errors.
@RonEld RonEld force-pushed the cryptocell_ccm_alt_fixes branch from b6b1e49 to 5e0223f Compare November 26, 2018 14:23
@RonEld
Copy link
Contributor Author

RonEld commented Nov 26, 2018

@0xc0170 I have rebased to resolve conflicts, and put fixes from review from @dgreen-arm in 1b34927

@yanesca
Copy link
Contributor

yanesca commented Nov 26, 2018

@RonEld do you still have the branch before the rebase? Can you post a link to it so that I can compare?

@bulislaw
Copy link
Member

All the PRs need to be engineering ready (marked as "needs: CI") by the end of the day (Austin time). Otherwise it won't make 5.11 and will need to come in the next release (5.12 for features, 5.11.1 for fixes and new platforms).

@RonEld
Copy link
Contributor Author

RonEld commented Nov 26, 2018

@yanesca UnfortunatelyI don't.. I am working on making a reference branch

@RonEld
Copy link
Contributor Author

RonEld commented Nov 26, 2018

@yanesca I believe the branch before the rebase and style fixes from @dgreen-arm is in https://github.com/RonEld/mbed-os/tree/ccm_alt_reference_brach

Copy link
Contributor

@yanesca yanesca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the rebase and I am happy with the changes.

(@RonEld thanks for putting up a reference branch!)

@mbed-ci
Copy link

mbed-ci commented Nov 27, 2018

Test run: SUCCESS

Summary: 4 of 4 test jobs passed
Build number : 6
Build artifacts
Build logs

@cmonr
Copy link
Contributor

cmonr commented Nov 27, 2018

@ARMmbed/mbed-os-maintainers IF we're ignoring the jenkins_ci/exporter result (the export nodes are currently completely out of space and failing), then this PR is good to come in.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2018

Thanks @cmonr for heads-up! This is ready for merge

@0xc0170 0xc0170 merged commit 86915d9 into ARMmbed:master Nov 27, 2018
@cmonr cmonr removed the risk: G label Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants