Skip to content

Initial implementation of Cypress Crypto hardware acceleration for mbedTLS #11046

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 7 commits into from
Sep 5, 2019

Conversation

kotkcy
Copy link
Contributor

@kotkcy kotkcy commented Jul 14, 2019

Kind request for ARM team!!!

Could you please make a review as soon as possible - we need this for our customer. Ideally at start on the next week.

Description

This PR brings the following major updates to the Cypress PSoC 6 targets for Mbed TLS library resides in Mbed OS 5.13:

  • Initial implementation of the Cypress hardware acceleration target for mbedTLS (features/mbedtls/targets/TARGET_Cypress)
  • Updated Cypress CSP HAL to support all crypto hardware resources (targets/TARGET_Cypress/TARGET_PSOC6/psoc6csp/hal/)
  • Updated targets.json file to enable mbedTLS hardware acceleration for Cypress MCUs (targets/targets.json)

This PR is based on PR #11018, so actual changes only related to crypto acceleration support in MbedTLS library.

Pull request type

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

Reviewers

Please suggest

Release Notes

@kotkcy kotkcy changed the title Pr/cy mbedtls alt Initial implementation of Cypress Crypto hardware acceleration for mbedTLS Jul 14, 2019
@ciarmcom ciarmcom requested review from a team July 14, 2019 13:00
@ciarmcom
Copy link
Member

@kotkcy, thank you for your changes.
@ARMmbed/mbed-os-maintainers @ARMmbed/mbed-os-storage @ARMmbed/mbed-os-crypto @ARMmbed/mbed-os-tools please review.

@ciarmcom ciarmcom requested a review from a team July 14, 2019 13:00
Copy link
Contributor

@SeppoTakalo SeppoTakalo left a comment

Choose a reason for hiding this comment

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

Many .py files are missing their license headers.
Please add.

Then there is Oracle Binary Code License Agreement is this needed, and why? I need to seek advice whether this can be accepted.

@bulislaw
Copy link
Member

@Patater do we even accept code into mbed TLS copy that resides in Mbed OS? I have a feeling they'll be lost during an update.

@kotkcy
Copy link
Contributor Author

kotkcy commented Jul 16, 2019

Many .py files are missing their license headers.
Please add.

Then there is Oracle Binary Code License Agreement is this needed, and why? I need to seek advice whether this can be accepted.

@kotkcy kotkcy closed this Jul 16, 2019
@kotkcy kotkcy reopened this Jul 16, 2019
romanjoe added a commit to romanjoe/mbed-os that referenced this pull request Jul 16, 2019
@SeppoTakalo
Copy link
Contributor

Why is the Oracle binary license required?

@kotkcy
Copy link
Contributor Author

kotkcy commented Jul 19, 2019

Many .py files are missing their license headers.
Please add.
@SeppoTakalo please look into the newly uploaded files that have required licenses.

@Patater
Copy link
Contributor

Patater commented Jul 19, 2019

@Patater do we even accept code into mbed TLS copy that resides in Mbed OS? I have a feeling they'll be lost during an update.

We generally don't accept code into the copies of Mbed TLS or Mbed Crypto that resides in Mbed OS. Exactly as you say, the changes will be lost upon the next update of Mbed TLS and Mbed Crypto. Any changes to Mbed TLS or Mbed Crypto should be raised as PRs to https://github.com/ARMmbed/mbedtls and https://github.com/ARMmbed/mbed-crypto

Copy link
Contributor

@SeppoTakalo SeppoTakalo left a comment

Choose a reason for hiding this comment

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

This PR now seems to contain test changes TESTS/mbed_platform/atomic/main.cpp as well as API changes Atomic.h.
And various smaller touches to AT_cellular stuff.

Those have nothing to do with "Initial implementatation of Cypress Crypto" and should therefore be separated to own PR.

@kotkcy kotkcy force-pushed the pr/cy_mbedtls_alt branch 2 times, most recently from 0f0177a to 6a123d3 Compare July 26, 2019 09:21
kotkcy pushed a commit to kotkcy/mbed-os that referenced this pull request Jul 26, 2019
@vmedcy
Copy link
Contributor

vmedcy commented Jul 26, 2019

@SeppoTakalo: the presence of unrelated changes was caused by the wrong branch used as a base of contributions (GitHub PRs always display difference against latest master).

This PR is now rebased against master + #11018 commits included. Once CY8CPROTO_064_SB target is merged, this PR will contain single commit 6a123d3.

I recommend to focus the review on this commit, and track CY8CPROTO_064_SB related issues in #11018

@kotkcy kotkcy force-pushed the pr/cy_mbedtls_alt branch 2 times, most recently from 07f8cb9 to 1c4e2ab Compare August 8, 2019 15:07
kotkcy pushed a commit to kotkcy/mbed-os that referenced this pull request Aug 8, 2019
@0xc0170
Copy link
Contributor

0xc0170 commented Aug 9, 2019

#11018 is moving forward. Once it is in, this should be rebased. Meanwhile, can this PR be made on its own (so we can focus on reviewing just crypto implementation) ?

At least share range of commits for review here.

Copy link
Contributor Author

@kotkcy kotkcy left a comment

Choose a reason for hiding this comment

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

just alignment in some mbedtls files (tabs used?)

All TABs are changed to spaces in the commit 08fd157.

hugueskamba pushed a commit to hugueskamba/mbed-os that referenced this pull request Sep 2, 2019
Copy link
Contributor

@mark-edgeworth mark-edgeworth left a comment

Choose a reason for hiding this comment

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

Generally there are quite a few cases where some really complex C code has been used and which could be simplified to make later maintenance/bug fixing much easier. I appreciate that this stuff is complex, but using longer and more descriptive variable names might help too. Putting braces around statements within every 'if' statement is usually recommended.

MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &R->Z, &E, &R->Z ) ); MOD_MUL( R->Z );

cleanup:
mbedtls_mpi_free( &A ); mbedtls_mpi_free( &AA ); mbed
Copy link
Contributor

Choose a reason for hiding this comment

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

Not required as this is the next statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please look into ecp.c line 2281.

/*
* Domain parameters for secp192r1
*/
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these numbers ok to be included here or are they hackable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please look into ecp_curves.c line 95.

#endif

#ifndef PUT_UINT64_LE
#define PUT_UINT64_LE(n,b,i) \
Copy link
Contributor

Choose a reason for hiding this comment

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

Two issues:

  1. If any of the input parameters have a side effect then this macro will not work as intended.
  2. What happens if 'n' is signed and negative? C standard says undefined; could be sign extended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was captured to support XTS cipher mode from aes.c. Please look into line 1129.


/* Endianess with 64 bits values */
#ifndef GET_UINT64_LE
#define GET_UINT64_LE(n,b,i) \
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential for error if any parameter has a side effect. Also might read better if 'n' was the result of the macro being used as an R-value, eg result = GET_UINT64_LE(buff, offset)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was captured to support XTS cipher mode from aes.c. Please look into line 1116.

@mark-edgeworth
Copy link
Contributor

Generally it looks like lots of this code was copied from elsewhere in mbed-os, and the original code has quite a few 'clever' (aka difficult to maintain/understand) bits of C in it that are being replicated here. I have highlighted several places where improvements could be made to improve readability, and a couple of cases where incipient bugs might lurk.

Copy link
Contributor

@Patater Patater 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 just one remaining question about how the AES hardware sharing works with regard to XTS mode (which uses two AES contexts at the same time). The underlying driver handles multiple concurrent operations, but I did not review how that is done.

@0xc0170 0xc0170 self-requested a review September 3, 2019 11:40
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 3, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Sep 3, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-IAR

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 3, 2019

Because of 5.14.0-rc1 CI jobs, we aborted CI job here. We will restart once 5.14.0rc1 is ready.

@kotkcy
Copy link
Contributor Author

kotkcy commented Sep 3, 2019

I have just one remaining question about how the AES hardware sharing works with regard to XTS mode (which uses two AES contexts at the same time). The underlying driver handles multiple concurrent operations, but I did not review how that is done.

PDL crypto driver provides a separated contexts for all AES objects that hold all needed information inside.

So we can use many AES objects at the same time at driver layer not in the hardware.

@Patater
Copy link
Contributor

Patater commented Sep 3, 2019

I have just one remaining question about how the AES hardware sharing works with regard to XTS mode (which uses two AES contexts at the same time). The underlying driver handles multiple concurrent operations, but I did not review how that is done.

PDL crypto driver provides a separated contexts for all AES objects that hold all needed information inside.

So we can use many AES objects at the same time at driver layer not in the hardware.

Sounds good to me. Thanks for the explanation.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 4, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Sep 4, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-IAR

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 4, 2019

CI restarted

@kotkcy
Copy link
Contributor Author

kotkcy commented Sep 4, 2019

CI restarted

@0xc0170 I removed mbedTLS hardware support from Sequana targets, so please restart CI asap

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 4, 2019

CI aborted and restarted

@mbed-ci
Copy link

mbed-ci commented Sep 4, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-GCC_ARM

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 4, 2019

New CI is running, old one was aborted quite late.. ^^

@mbed-ci
Copy link

mbed-ci commented Sep 4, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 4
Build artifacts

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.