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/cipher: BlockMode.CryptBlocks could return an error? #24336

Closed
siadat opened this issue Mar 10, 2018 · 2 comments
Closed

crypto/cipher: BlockMode.CryptBlocks could return an error? #24336

siadat opened this issue Mar 10, 2018 · 2 comments

Comments

@siadat
Copy link
Contributor

siadat commented Mar 10, 2018

It is usually preferred that libraries avoid panicking and return errors and delegate error handling to their client. I was wondering if there is a reason that BlockMode.CryptBlocks does not return an error. Currently both of implementations, i.e., *cbcDecrypter and *cbcEncrypter, have to panic in case there is a problem in their inputs.

@odeke-em
Copy link
Member

Hello @siadat, thank you for the question.

Firstly, I believe that this behavior cannot change due to the Go1.0 compatibility promise.

In regards to panicking on len(dst) < len(src): this is a short write and a user error while encrypting a block and perhaps a security issue as further supported by @rsc's comment in @minux's CL that documented this behavior long after the API was designed https://go-review.googlesource.com/c/go/+/1754#message-1186b2a59679055900246c2dc8c26aa18d16ca8b

2) Claim that this is a security issue, due to being too easy to use incorrectly, and define that len(dst) != len(src) must panic, updating the existing implementations.

/cc @agl for perhaps more words, to explain the API

@andybons
Copy link
Member

Thanks for the report.

@odeke-em is correct that this would break the Go1 compatibility promise.

That said, if you wanted to propose an API change for Go2, I would write a proposal with a bit more detail with real-world, motivating examples to support the change. Then /cc @agl and @FiloSottile for feedback.

Thanks

@golang golang locked and limited conversation to collaborators Mar 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants