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

crypto: add SignatureLength constant and use it everywhere #18264

Closed
wants to merge 2 commits into from

Conversation

jpeletier
Copy link
Contributor

Also added PubkeyLength and DigestLength and RecoveryIDOffset, to avoid harcoded numbers

Copy link
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

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

LGTM for the Whisper part.

@karalabe
Copy link
Member

I don't really agree with this change. The 65 bytes is not something that's configurable or makes sense to separate out into a global constant. It's essentially defined by the cryptographic primitive of secp256k1, so hard coding 64 might make the code cleaner to read really.

Anyway, @fjl @holiman please chip in your thoughts.

@holiman
Copy link
Contributor

holiman commented Dec 10, 2018

I agree, this is not a 'parameter' which can be configured, so I don't see the reason to modify this.

@karalabe karalabe closed this Dec 10, 2018
@jpeletier
Copy link
Contributor Author

@holiman @karalabe I agree this is not a configurable parameter, but rather is about all the code around that sizes up slices with 65 (x:= make([]byte, 65) and really is a way of expressing you are making room for a ECDSA signature from the crypto package and avoid making mistakes. For veterans this is straightforward, not so for newcomers that want to understand the code.

sig:=make([]byte, 65) means dude is creating a 65 byte slice named "sig". Maybe a signature but what?
sig:=make([]byte, crypto.SignatureLength) means dude is making some space for a signature coming from the crypto package. Let's go to that package to see what that is about.

math.Pi is even less configurable than a signature length, but people don't put 3.1415 all over the place.

I would ask you to reconsider, please don't close the issue without allowing some comments from the contributor. In my work for the feeds module in Swarm I had to define my own constant so I don't have to put 65: crypto.SignatureLength clearly expresses I am making some space for an Ethereum signature. I know their size won't change in 100 years, but it is about making it understandable for people who are not so familiar.

Perhaps some parts can be tweaked in the PR so not everything is as I put it. Can we find some middle ground?

Thanks

@karalabe karalabe reopened this Dec 10, 2018
@nolash
Copy link
Contributor

nolash commented Dec 10, 2018

The 65 bytes is not something that's configurable

Doesn't that then reinforce the argument that other packages operating on signatures shouldn't seem to have arbitrarily chosen a number, but instead rely on a truth value chaperoned by the package that provides the functionality?

@jpeletier
Copy link
Contributor Author

@holiman @karalabe can we reconsider? Thanks.

Copy link
Contributor

@fjl fjl 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 a nice change, but unfortunately breaks the nocgo build. Please define the constants in package crypto instead of crypto/secp256k1.

@jpeletier
Copy link
Contributor Author

@fjl modified this to leave crypto/secp256k1 untouched. Please let me know

@jpeletier jpeletier changed the title crypto/secp256k1: Created SignatureLength constant + refactor throughout crypto: Created SignatureLength constant + refactor throughout Dec 20, 2018
@holiman
Copy link
Contributor

holiman commented Aug 1, 2019

I'm not a fan, it adds a level of indirection making it more difficult for a programmer to see explicitly what the lengths and offsets are.

@jpeletier
Copy link
Contributor Author

magic number 65 in the middle of a code file does not make sense for a newcomer. crypto.SignatureLength is kind of self-explanatory and helps document the code. Any IDE will give you the actual value if you hover over a constant if you want to know the value. In any case, a programmer should not care about the actual value of the constant, just use it.

@fjl fjl force-pushed the signaturelength branch from b765384 to 4125cfb Compare August 22, 2019 11:42
@fjl
Copy link
Contributor

fjl commented Aug 22, 2019

Rebased on master

@fjl fjl changed the title crypto: Created SignatureLength constant + refactor throughout crypto: add SignatureLength constant and use it everywhere Aug 22, 2019
@fjl fjl force-pushed the signaturelength branch from 4125cfb to 5c3d38f Compare August 22, 2019 12:29
@fjl fjl force-pushed the signaturelength branch from 5c3d38f to d50acbd Compare August 22, 2019 12:30
@fjl
Copy link
Contributor

fjl commented Aug 22, 2019

Not really sure what happened here, but GitHub can't merge this PR anymore. Will reopen this as a new PR.

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.

7 participants