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

Conversion function between raw and DER ECDSA signatures #8681

Closed
wants to merge 15 commits into from

Conversation

valeriosetti
Copy link
Contributor

Description

Add ECDSA's conversion functions between raw and DER (ASN.1) format.

Resolves #7765

PR checklist

  • changelog TODO
  • backport not required
  • tests provided

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti valeriosetti added needs-ci Needs to pass CI tests priority-high High priority - will be reviewed soon labels Jan 8, 2024
@valeriosetti valeriosetti requested a review from mpg January 8, 2024 15:53
@valeriosetti valeriosetti self-assigned this Jan 8, 2024
@valeriosetti valeriosetti added this to To Do in Roadmap Board for Mbed TLS via automation Jan 8, 2024
…ersion functions

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
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.

This is mostly a complete review, but there are a few more things I want to do:

  • compare with previous functions
  • check test coverage.

Overall it's looking good even though I had quite a lot to say :)

include/mbedtls/psa_util.h Outdated Show resolved Hide resolved
include/mbedtls/psa_util.h Show resolved Hide resolved
include/mbedtls/psa_util.h Show resolved Hide resolved
library/psa_util.c Outdated Show resolved Hide resolved
library/psa_util.c Show resolved Hide resolved
tests/suites/test_suite_psa_crypto_util.data Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto_util.function Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto_util.function Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto_util.function Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto_util.function Outdated Show resolved Hide resolved
Roadmap Board for Mbed TLS automation moved this from To Do to In Development Jan 9, 2024
@mpg
Copy link
Contributor

mpg commented Jan 9, 2024

Following this discussion with Gilles, actually could you try prototyping (in another PR) an alternative implementation of these functions that doesn't rely on existing mbedtls_asn1 functions (hence does not depend on MBEDTLS_ASN1_xxx_C) but instead re-implements just what it needs from ASN.1 for this particular case (can make assumption on lengths fitting in two bytes, etc)? Just to see if it would result in a lot of code duplication or not that much.

(IMO this doesn't have to be blocking this PR. We can perfectly start by merging a version that depends on MBEDTLS_ASN1_xxx_C and then later change it to a version that doesn't. Incremental improvement and so on.)

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
- Replace 192 case with 256
- Replace 256 case with 512
- Add 521 case

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This is mandatory to have support for the error codes defined
in the asn1write.h header file.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti
Copy link
Contributor Author

[...] could you try prototyping (in another PR) an alternative implementation of these functions that doesn't rely on existing mbedtls_asn1 functions [...]?

Sure! I will start the new PR based on this one

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
There is no PSA equivalent to ASN1 legacy symbols.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This is possible because we know that DER format can have at most
1 leading zero.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Tests with 256 bits curve simply depends on any curve of that size,
but they don't really care about which family is enabled.

Here I replaced PSA_WANT_ECC_SECP_R1_256 with PSA_WANT_ECC_SECP_K1_256
because otherwise there were test disparities in the
"analyze_driver_vs_reference_tfm_config" component of
"analyze_outcomes.py". It looked simpler to change the curve type
in the test suite's data rather than adding proper exceptions
in "analyze_outcomes.py"

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
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 addressing my feedback.

(Still not a complete review, same points left as last time.)

tests/suites/test_suite_psa_crypto_util.data Outdated Show resolved Hide resolved
tests/suites/test_suite_psa_crypto_util.data Show resolved Hide resolved
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti valeriosetti requested a review from mpg January 11, 2024 09:43
@valeriosetti valeriosetti added 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 size-s Estimated task size: small (~2d) and removed needs-ci Needs to pass CI tests labels Jan 11, 2024
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti
Copy link
Contributor Author

Closing this one as agreed on #8696 (comment). This feature will be completed in #8703

Roadmap Board for Mbed TLS automation moved this from In Development to Done Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 priority-high High priority - will be reviewed soon size-s Estimated task size: small (~2d)
Development

Successfully merging this pull request may close these issues.

Conversion function between raw and DER ECDSA signatures
3 participants