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

[3.0] Honor OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT as set and default to UNCOMPRESSED #19901

Closed

Conversation

romen
Copy link
Member

@romen romen commented Dec 14, 2022

This is a backport of #19681 to openssl-3.0 as per openssl/technical-policies#60.

  • Cherry-pick was mostly clean, only CHANGES.md required manual intervention, as expected.
  • To ease review, I collected the changes in the documentation as a fixup commit in a9c2d1e

Fixes #16595

Checklist
  • documentation is added or updated
  • tests are added or updated

…o UNCOMPRESSED

Originally the code to im/export the EC pubkey was meant to be consumed
only by the im/export functions when crossing the provider boundary.
Having our providers exporting to a COMPRESSED format octet string made
sense to avoid memory waste, as it wasn't exposed outside the provider
API, and providers had all tools available to convert across the three
formats.

Later on, with openssl#13139 deprecating the `EC_KEY_*` functions, more state
was added among the params imported/exported on an EC provider-native
key (including `OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT`, although it
did not affect the format used to export `OSSL_PKEY_PARAM_PUB_KEY`).

Finally, in openssl#14800, `EVP_PKEY_todata()` was introduced and prominently
exposed directly to users outside the provider API, and the choice of
COMPRESSED over UNCOMPRESSED as the default became less sensible in
light of usability, given the latter is more often needed by
applications and protocols.

This commit fixes it, by using `EC_KEY_get_conv_form()` to get the
point format from the internal state (an `EC_KEY` under the hood) of the
provider-side object, and using it on
`EVP_PKEY_export()`/`EVP_PKEY_todata()` to format
`OSSL_PKEY_PARAM_PUB_KEY`.
The default for an `EC_KEY` was already UNCOMPRESSED, and it is altered
if the user sets `OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT` via
`EVP_PKEY_fromdata()`, `EVP_PKEY_set_params()`, or one of the
more specialized methods.

For symmetry, this commit also alters `ec_pkey_export_to()` in
`crypto/ec/ec_ameth.c`, part of the `EVP_PKEY_ASN1_METHOD` for legacy EC
keys: it exclusively used COMPRESSED format, and now it honors the
conversion format specified in the EC_KEY object being exported to a
provider when this function is called.

Expand documentation about `OSSL_PKEY_PARAM_PUB_KEY` and mention the
change in behavior for our providers.

Fixes openssl#16595

(cherry picked from commit 926db47)
@romen romen added approval: review pending This pull request needs review by a committer approval: otc review pending This pull request needs review by an OTC member triaged: bug The issue/pr is/fixes a bug branch: 3.0 Merge to openssl-3.0 branch tests: present The PR has suitable tests present labels Dec 14, 2022
@romen romen requested review from hlandau and t8m December 14, 2022 00:07
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Dec 14, 2022
@romen
Copy link
Member Author

romen commented Dec 14, 2022

Notice that once this PR is merged, the changes in a9c2d1e will be applied to openssl-3.1 and master as well.

Presumably, 3.1.0-beta1 and maybe even the final 3.1.0 might be issued before 3.0.8 is properly released, making it so that the shipped documentation in those releases will mention a change introduced in a yet-to-be-released 3.0.8.

Do we consider that a problem?
If so, would you suggest amendments to a9c2d1e for this PR?

@t8m
Copy link
Member

t8m commented Dec 14, 2022

I do not think this is a problem for 3.1 beta1. It would be better resolved before the 3.1.0 final though.

@t8m
Copy link
Member

t8m commented Dec 14, 2022

IMO 3.0.8 should be done before 3.1.0 final.

@t8m t8m removed the approval: otc review pending This pull request needs review by an OTC member label Dec 14, 2022
@hlandau hlandau added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Dec 14, 2022
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Dec 15, 2022
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@t8m
Copy link
Member

t8m commented Dec 22, 2022

Merged to 3.0 branch. Thank you.

@romen Could you please create a fixup PR against master branch to correct the documentation and resync the CHANGES.md?

@t8m t8m closed this Dec 22, 2022
openssl-machine pushed a commit that referenced this pull request Dec 22, 2022
…o UNCOMPRESSED

Originally the code to im/export the EC pubkey was meant to be consumed
only by the im/export functions when crossing the provider boundary.
Having our providers exporting to a COMPRESSED format octet string made
sense to avoid memory waste, as it wasn't exposed outside the provider
API, and providers had all tools available to convert across the three
formats.

Later on, with #13139 deprecating the `EC_KEY_*` functions, more state
was added among the params imported/exported on an EC provider-native
key (including `OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT`, although it
did not affect the format used to export `OSSL_PKEY_PARAM_PUB_KEY`).

Finally, in #14800, `EVP_PKEY_todata()` was introduced and prominently
exposed directly to users outside the provider API, and the choice of
COMPRESSED over UNCOMPRESSED as the default became less sensible in
light of usability, given the latter is more often needed by
applications and protocols.

This commit fixes it, by using `EC_KEY_get_conv_form()` to get the
point format from the internal state (an `EC_KEY` under the hood) of the
provider-side object, and using it on
`EVP_PKEY_export()`/`EVP_PKEY_todata()` to format
`OSSL_PKEY_PARAM_PUB_KEY`.
The default for an `EC_KEY` was already UNCOMPRESSED, and it is altered
if the user sets `OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT` via
`EVP_PKEY_fromdata()`, `EVP_PKEY_set_params()`, or one of the
more specialized methods.

For symmetry, this commit also alters `ec_pkey_export_to()` in
`crypto/ec/ec_ameth.c`, part of the `EVP_PKEY_ASN1_METHOD` for legacy EC
keys: it exclusively used COMPRESSED format, and now it honors the
conversion format specified in the EC_KEY object being exported to a
provider when this function is called.

Expand documentation about `OSSL_PKEY_PARAM_PUB_KEY` and mention the
change in behavior for our providers.

Fixes #16595

(cherry picked from commit 926db47)

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #19901)
openssl-machine pushed a commit that referenced this pull request Dec 22, 2022
(cherry picked from commit d656efb)

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #19901)
romen added a commit to romen/openssl that referenced this pull request Jan 6, 2023
…_CONVERSION_FORMAT

openssl#19901 backported the
"Honor OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT as set and default to
UNCOMPRESSED" changeset to 3.0.

This commit updates:

- the HISTORY notes of the relevant documentation to mark the change
  happened since 3.0.8.
@romen
Copy link
Member Author

romen commented Jan 6, 2023

Merged to 3.0 branch. Thank you.

@romen Could you please create a fixup PR against master branch to correct the documentation and resync the CHANGES.md?

@t8m see #20003

openssl-machine pushed a commit that referenced this pull request Jan 31, 2023
…_CONVERSION_FORMAT

#19901 backported the
"Honor OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT as set and default to
UNCOMPRESSED" changeset to 3.0.

This commit updates:

- the HISTORY notes of the relevant documentation to mark the change
  happened since 3.0.8.

- the `CHANGES.md file` to sync up with the tip of the `openssl-3.0`
  branch

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #20003)

(cherry picked from commit f66c127)
openssl-machine pushed a commit that referenced this pull request Jan 31, 2023
…_CONVERSION_FORMAT

#19901 backported the
"Honor OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT as set and default to
UNCOMPRESSED" changeset to 3.0.

This commit updates:

- the HISTORY notes of the relevant documentation to mark the change
  happened since 3.0.8.

- the `CHANGES.md file` to sync up with the tip of the `openssl-3.0`
  branch

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #20003)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: 3.0 Merge to openssl-3.0 branch severity: fips change The pull request changes FIPS provider sources tests: present The PR has suitable tests present triaged: bug The issue/pr is/fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants