Skip to content

Conversation

@daxpedda
Copy link
Contributor

@daxpedda daxpedda commented Oct 1, 2021

This enabled GroupEncoding::to_bytes() and GroupEncoding::from_bytes() for AffinePoint and ProjectivePoint for p256 and k256 to handle the identity point.

See #443.

@daxpedda daxpedda changed the title Fix related functions tp Fix related functions to #443 Oct 1, 2021
@daxpedda daxpedda changed the title Fix related functions to #443 Handle identity point in GroupEncoding Oct 1, 2021
@codecov-commenter
Copy link

Codecov Report

Merging #444 (ca45ba1) into master (9a93c97) will increase coverage by 0.88%.
The diff coverage is 84.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #444      +/-   ##
==========================================
+ Coverage   64.51%   65.39%   +0.88%     
==========================================
  Files          28       28              
  Lines        3590     3624      +34     
==========================================
+ Hits         2316     2370      +54     
+ Misses       1274     1254      -20     
Impacted Files Coverage Δ
k256/src/arithmetic/projective.rs 78.49% <77.77%> (+1.44%) ⬆️
k256/src/arithmetic/affine.rs 85.34% <84.61%> (+9.38%) ⬆️
p256/src/arithmetic/affine.rs 91.13% <84.61%> (+6.20%) ⬆️
p256/src/arithmetic/projective.rs 77.81% <100.00%> (+0.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a93c97...ca45ba1. Read the comment docs.

Comment on lines +174 to +179
.or_else(|| {
CtOption::new(
AffinePoint::identity(),
tag.ct_eq(&sec1::Tag::Identity.into()),
)
})
Copy link
Contributor Author

@daxpedda daxpedda Oct 1, 2021

Choose a reason for hiding this comment

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

This seemed to me to be the cleanest solution, but not entirely correct because it doesn't check if the rest of the bytes are also 0s.

I think the best approach if this is desired is to change DecompressPoint::decompress() to handle the identity point, which would require a breaking change.
Just realized what I said here is nonsense, I guess we could do the check right there.

Copy link
Member

Choose a reason for hiding this comment

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

This would accept a 0-tagged value with garbage bytes. Not sure that's a good idea. It should probably check all of them.

This is a lot of logic to repeat on a per-crate basis. It seems like it might be worth hoisting into the elliptic-curve crate in some form. It could probably be composed in terms of FromDecodedPoint.

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 unsure what you mean, FromDecodedPoint::from_encoded_point() requires an EncodedPoint and doesn't do the check we want. Do you mean adding a new method to FromDecodedPoint?

Copy link
Member

Choose a reason for hiding this comment

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

No, I mean something which uses FromDecodedPoint to do the decoding, possibly after changing its result to a CtOption, and offloading the SEC1 tag handling there

Copy link
Contributor Author

@daxpedda daxpedda Oct 1, 2021

Choose a reason for hiding this comment

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

I just realized, I thought you meant FromEncodedPoint, I can't find FromDecodedPoint. Did you mean creating a new trait called FromDecodedPoint?

Copy link
Member

Choose a reason for hiding this comment

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

Err yes sorry (responding on my phone here)

tarcieri added a commit that referenced this pull request Oct 2, 2021
`GroupEncoding` uses a fixed-width `Repr` whereas SEC1 is variable-width
with respect to compressed points versus the identity.

This change allows 33-bytes of zeroes to be used as the identity.
Technically that's not a valid SEC1 encoding: the SEC1 encoding for the
identity is 1-byte: 0x00. However, this is the best we can do with a
fixed-width encoding.

See also: #443 and #444
@tarcieri
Copy link
Member

tarcieri commented Oct 2, 2021

I've opened a PR with a slight variation on this:

#446

It's able to leverage a now CtOption return value from the FromEncodedPoint trait introduced in #445.

tarcieri added a commit that referenced this pull request Oct 2, 2021
`GroupEncoding` uses a fixed-width `Repr` whereas SEC1 is variable-width
with respect to compressed points versus the identity.

This change allows 33-bytes of zeroes to be used as the identity.
Technically that's not a valid SEC1 encoding: the SEC1 encoding for the
identity is 1-byte: 0x00. However, this is the best we can do with a
fixed-width encoding.

See also: #443 and #444
@tarcieri
Copy link
Member

tarcieri commented Oct 2, 2021

Closing in favor of #446

@tarcieri tarcieri closed this Oct 2, 2021
@daxpedda daxpedda deleted the group-encoding-to-from-bytes branch October 3, 2021 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants