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

PSA PAKE: Check input_length against PSA_PAKE_INPUT_SIZE() in psa_pake_input #7331

Merged
merged 5 commits into from
Apr 17, 2023

Conversation

mprse
Copy link
Contributor

@mprse mprse commented Mar 23, 2023

Description

  • Check input_length against PSA_PAKE_INPUT_SIZE.
  • Adapt tests.
  • Adapt documentation.

Resolves #7226

Gatekeeper checklist

  • changelog provided, or not required
  • backport done, or not required
  • tests provided, or not required

Tests provided.
Backport and changelog not needed.

Notes for the submitter

Please refer to the contributing guidelines, especially the
checklist for PR contributors.

mprse added 3 commits March 23, 2023 08:05
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
@mprse mprse added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review labels Mar 23, 2023
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
@mprse mprse added enhancement component-psa PSA keystore/dispatch layer (storage, drivers, …) and removed needs-ci Needs to pass CI tests labels Mar 27, 2023
@AndrzejKurek AndrzejKurek self-requested a review March 27, 2023 09:03
AndrzejKurek
AndrzejKurek previously approved these changes Mar 27, 2023
Copy link
Contributor

@AndrzejKurek AndrzejKurek left a comment

Choose a reason for hiding this comment

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

Looks good.

@davidhorstmann-arm davidhorstmann-arm self-requested a review March 30, 2023 16:20
Copy link
Contributor

@davidhorstmann-arm davidhorstmann-arm left a comment

Choose a reason for hiding this comment

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

Replying to the comment. I'll finish my review proper shortly.

library/psa_crypto.c Show resolved Hide resolved
Copy link
Contributor

@davidhorstmann-arm davidhorstmann-arm left a comment

Choose a reason for hiding this comment

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

LGTM, my existing comment stands as a nice-to-have but it's not a blocker.

@AndrzejKurek AndrzejKurek removed needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Apr 13, 2023
@@ -7920,7 +7925,8 @@ psa_status_t psa_pake_input(
goto exit;
}

if (input_length == 0 || input_length > PSA_PAKE_INPUT_MAX_SIZE) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: double newline

@@ -2106,6 +2106,8 @@ struct psa_pake_operation_s {
unsigned int MBEDTLS_PRIVATE(id);
/* Algorithm of the PAKE operation */
psa_algorithm_t MBEDTLS_PRIVATE(alg);
/* A primitive of type compatible with algorithm */
psa_pake_primitive_t MBEDTLS_PRIVATE(primitive);
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing that I would suggest to consider is moving the new structure field to the end to conserve backward ABI compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure about moving this field to the end of the structure as locating it with id and alg values makes more sense. Then we have unions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's a question to one of our gatekeepers? Whether we prefer backwards ABI compatibility or better readability.

Copy link
Contributor

Choose a reason for hiding this comment

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

We end up breaking ABI compatibility in pretty much every release these days. So one more ABI break doesn't matter. (Except in LTS, there we want to preserve the ABI as well as the API.)

Beyond readability for grouping, there are other considerations for the ordering of struct fields. I haven't checked what might apply here.

  • Avoid holes due to alignment. E.g. prefer {char; char; short;} or {short; char; char} to {char; short; char;} since the first two typically fill 4 bytes but the last one typically needs 6 bytes, with two padding bytes.
  • For long structures: on Cortex-M, it takes less code to access the first 128 elements, so it's better to put often-accessed byte fields within the first 128 bytes, 2-byte fields within 256 bytes, 4-byte fields within 512 bytes. Here, “often-accessed” is about the number of places in the code that access the field, not about how frequent the accesses are at runtime. Of course the very first field is even cheaper. See Report on structure fields #5234
  • For long structures: if some fields are often accessed at the same time, it helps if they're on the same cache line. The size of a cache line depends on the architecture, of course, but what this means is that it helps if they're close together.
  • If some parts of a structure depend on compilation option, it's usually easier to follow things in a debugger if all the common parts are at the beginning.

@AndrzejKurek
Copy link
Contributor

Apart from some suggestions to consider before marking this PR as approved, please also update the PR description of backport, tests, and changelog fields.

@mprse
Copy link
Contributor Author

mprse commented Apr 14, 2023

Apart from some suggestions to consider before marking this PR as approved, please also update the PR description of backport, tests, and changelog fields.

Tests are provided but I'm not sure if we need changelog for this change. I think backport is not needed.

@AndrzejKurek
Copy link
Contributor

Tests are provided but I'm not sure if we need changelog for this change. I think backport is not needed.

Sure, what I mean is to update the description at the top, so that the gatekeepers can see a justification :)

@davidhorstmann-arm davidhorstmann-arm added the approved Design and code approved - may be waiting for CI or backports label Apr 14, 2023
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
@mprse mprse dismissed stale reviews from davidhorstmann-arm and AndrzejKurek via 7921a03 April 17, 2023 10:32
@mprse
Copy link
Contributor Author

mprse commented Apr 17, 2023

  • Fixed documentation for PSA_PAKE_INPUT/OUTPUT_MAX_SIZE
  • removed empty line
  • didn't change the order of fields in struct
  • Updated descryption

@davidhorstmann-arm davidhorstmann-arm added needs-review Every commit must be reviewed by at least two team members, and removed approved Design and code approved - may be waiting for CI or backports labels Apr 17, 2023
Copy link
Contributor

@davidhorstmann-arm davidhorstmann-arm left a comment

Choose a reason for hiding this comment

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

LGTM

@davidhorstmann-arm davidhorstmann-arm added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Apr 17, 2023
@mprse mprse added the needs-ci Needs to pass CI tests label Apr 17, 2023
@paul-elliott-arm paul-elliott-arm merged commit 4359bad into Mbed-TLS:development Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports component-psa PSA keystore/dispatch layer (storage, drivers, …) enhancement needs-ci Needs to pass CI tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PSA PAKE: Check input_length against PSA_PAKE_INPUT_SIZE() in psa_pake_input
5 participants