-
Notifications
You must be signed in to change notification settings - Fork 18k
crypto: Equal(PublicKey) bool methods leak to PrivateKey implementations #38190
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
Comments
I ran into the same issue with #33564 where I created a MarshalText method on ecdsa.PublicKey, which then leaked to ecdsa.PrivateKey because it embedded PublicKey. That's unfortunate. @FiloSottile how do you want to proceed here? Make an Equal on the PrivateKey types too? |
Nice bug. If a particular PrivateKey embeds PublicKey, then any time you implement PublicKey.M you should also implement PrivateKey.M to do the private key-specific behavior, whatever that is. Probably there should be a (non-doc) comment in the sources anywhere we do this, alerting people to the gotcha. Embedding the PublicKey instead of calling the field Public was probably a mistake, but too late now. |
Yeah, using embedding was probably a mistake in hindsight, even if I see how it made sense since the PublicKey fields are arguably PrivateKey fields as well. Question about Equal semantics: would you expect two equivalent PrivateKeys to return true or false if one has Precomputed set and the other doesn't? I think false? (I was hoping to avoid the question by not implementing Equal on the private keys, but yes, too late.) |
Naively I'd assume (It could be somewhat confusing to consider it given ECDSA and EdDSA have no analog.) |
@rsc what do you think? |
I would personally expect Equal to be semantic rather than picky about the exact representation. But if you can make an argument for being picky, that's OK with me too. |
@rsc pointed out IP.Equal and Time.Equal as precedents of Equal meaning equivalent, so let's implement it by ignoring Precomputed. |
Change https://golang.org/cl/231417 mentions this issue: |
Fixes golang#38190 Change-Id: I10766068ee18974e81b3bd78ee0b4d83cc9d1a8c Reviewed-on: https://go-review.googlesource.com/c/go/+/231417 Run-TryBot: Filippo Valsorda <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Katie Hockman <[email protected]>
Since golang.org/cl/225460 (#21704), the following code compiles but prints an unexpected result:
This is due to PrivateKey embedding
PublicKey
without having its ownEqual
method to maskPublicKey
’s.This causes difficult to debug issues with tools like go-cmp, as it looks for an
Equal
method on each type recursively and finds one in this case for the concrete private key types. The diff printed by the following code will be non-empty, but the values are identical:/cc @FiloSottile @katiehockman
The text was updated successfully, but these errors were encountered: