Skip to content
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

adjusting size of sliding window array to correct size. #3592

Merged
merged 4 commits into from
Sep 9, 2020

Conversation

d-otte
Copy link
Contributor

@d-otte d-otte commented Aug 21, 2020

Probably the W[2 << MBEDTLS_MPI_WINDOW_SIZE] notation is based on a transcription of 2**MBEDTLS_MPI_WINDOW_SIZE.

This PR fixes #3591 [edited by mpg to use github keyword]

Status

READY

Requires Backporting

This change is easy to backport, but is not strictly required.

I would recommend to backport it to all LTS branches.

Migrations

No API changes

Additional comments

This change would improve stack usage significantly.

Todos

  • Changelog updated
  • Backported

Probably the `W[2 << MBEDTLS_MPI_WINDOW_SIZE]` notation is based on a transcription of 2**MBEDTLS_MPI_WINDOW_SIZE.

Signed-off-by: Daniel Otte <d.otte@wut.de>
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

The change looks sensible to me. Thanks for spotting this!

Please update the comment in bignum.h as well. (And while you're at it, would you mind making a commit to change “Maximum windows size” to “Maximum window size” in bignum.h and config.h?) By the way, this comment confirms the intent, since it claims that 2 << MBEDTLS_MPI_WINDOW_SIZE is 64 when MBEDTLS_MPI_WINDOW_SIZE is 6.

Please add a changelog entry file in ChangeLog.d (section: Changes).

We don't normally backport performance improvements, but this one is very simple and has no drawback (e.g. no code size vs performance trade-off), so I think we should backport it.

@gilles-peskine-arm gilles-peskine-arm requested a review from mpg August 21, 2020 22:04
@gilles-peskine-arm gilles-peskine-arm added component-crypto Crypto primitives and low-level interfaces enhancement needs-backports Backports are missing or are pending review and approval. needs: changelog needs-review Every commit must be reviewed by at least two team members, labels Aug 21, 2020
@gilles-peskine-arm gilles-peskine-arm removed the request for review from mpg August 21, 2020 22:06
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

Other that the things already pointed out by Gilles, this looks good to me. Thanks for spotting and fixing this!

With the default configuration, the stack saving is 64 * sizeof (mbedtls_mpi) which appears to be 768 bytes on ARMv6-M and 1536 bytes on x86-64. That's quite significant, so I agree that it would be great to have this backported, as there is no drawback.

@d-otte
Copy link
Contributor Author

d-otte commented Sep 7, 2020

Now, back from vacation, I included your recommendations. I also changed the notation in the comment from 2 << MBEDTLS_MPI_WINDOW_SIZE to 2 ** MBEDTLS_MPI_WINDOW_SIZE. I found several occasions in other source files which use ** to denote exponentiation.

Since some time had passed, should I rebase my changes?

@gilles-peskine-arm
Copy link
Contributor

Thanks for updating. You don't need to rebase, but you can if you want. Rebasing after review makes it harder to review large changes, but this is a very small change so here it isn't an issue.

Please note that all commits must have a signed-off-by line to indicate that you warrant that you have the right to submit it. We can't accept the pull request if the DCO check fails.

Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

Thanks for making the suggested changes. Looks good to me except for two things:

  1. I think this deserves a ChangeLog entry, saving 768 of stack in the default config in 32-bit platforms is significant. (As Gilles suggested earlier, I think the "Changes" section is appropriate.)
  2. As Gilles pointed out, we need the Signed-Off-By line in the last two commits as well.

Signed-off-by: Daniel Otte <d.otte@wut.de>
The comment now uses '**' as exponentiation operator.

Signed-off-by: Daniel Otte <d.otte@wut.de>
Signed-off-by: Daniel Otte <d.otte@wut.de>
@d-otte
Copy link
Contributor Author

d-otte commented Sep 7, 2020

I added the Signed-off-by: lines, but had to force the push. I hope this does not confuse the history to much.

Thanks for reminding me to take credit in the ChangeLog 😆.

I used the description significant to designate the improvement, since it might vary from platform to platform. sizeof(mbedtls_mpi) depends on the size of int , size_t, mbedtls_mpi_uint and maybe alignment or padding, but the most common cases will indeed be 768 byte for 32-bit systems and 1536 bytes for 64-bit systems.

Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

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

Looks all good to me.

@mpg mpg self-assigned this Sep 8, 2020
@gilles-peskine-arm gilles-peskine-arm removed the needs-review Every commit must be reviewed by at least two team members, label Sep 8, 2020
@gilles-peskine-arm
Copy link
Contributor

Thanks! Would you mind submitting backports to mbedtls-2.16 and mbedtls-2.7 as well?

@d-otte
Copy link
Contributor Author

d-otte commented Sep 8, 2020

Would you mind submitting backports to mbedtls-2.16 and mbedtls-2.7 as well?
I will try to get this done today. But since I will probably be away the next seven weeks, maybe someone else has to finish this.

Should I base my changes on the mbedtls-2.16 and mbedtls-2.7 branch and create two dedicate PRs?

And I'm a bit unsure about the Mbed OS Testing failures. Do I have to care about them? I can't view the details, so I have no idea what they are about.

@mpg
Copy link
Contributor

mpg commented Sep 8, 2020

I will try to get this done today. But since I will probably be away the next seven weeks, maybe someone else has to finish this.

Ok, if you can create backports before you go, that would be very helpful and we'll be sure to review them quickly, otherwise we'll take care of the backports.

Should I base my changes on the mbedtls-2.16 and mbedtls-2.7 branch and create two dedicate PRs?

Precisely! The description of the new PRs can be just "Backport of #3592 to the xxx branch." (Usually git cherry-pick is helpful creating backports.)

And I'm a bit unsure about the Mbed OS Testing failures. Do I have to care about them? I can't view the details, so I have no idea what they are about.

Thanks for asking, but you don't need to care about them, we're actually going to remove them from our CI, see #3650

@mpg mpg removed the needs-backports Backports are missing or are pending review and approval. label Sep 9, 2020
@mpg mpg merged commit 628ed4e into Mbed-TLS:development Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-crypto Crypto primitives and low-level interfaces enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stack usage in sliding-window exponentiation
3 participants