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: io.Reader/Writer implementations for BlockMode #28153

Open
WillSewell opened this issue Oct 11, 2018 · 1 comment

Comments

@WillSewell
Copy link

commented Oct 11, 2018

The cipher.Stream interface can be wrapped in a cipher.StreamReader or cipher.StreamWriter for io.Reader/io.Writer implementations. It was be nice to have the same interface for cipher.BlockMode.

The challenge with cipher.BlockMode is that CryptBlocks must be run on byte slices whose lengths are multiples of the block size. I don't see this being a fundamental problem, but it will complicate the implementation. For the Reade, I imagine it would consist of two internal buffers as the state: encrypted to store encrypted bytes read from the underlying reader, and decrypted to store decrypted bytes to by copy out whenever Read is called. It would operate in two phases: If len(decrypted) == 0, then call Read on the underlying Reader until there is at least BlockSize bytes in encrypted. Then we can decrypt as many blocks as possible from encrypted into decrypted, and return these whenever Read is called until len(decrypted) == 0 again.

I haven't though as much about the Writer, but I suspect it will operate in a similar way.

The implementation is just a rough idea at the moment. I'm creating this issue mainly to see whether there is interest in the idea. If there is, I am happy to write a prototype.

@bcmills

This comment has been minimized.

Copy link
Member

commented Oct 23, 2018

@bcmills bcmills changed the title Lack of Reader/Writer implementations for cipher.BlockMode crypto/cipher: io.Reader/Writer implementations for BlockMode Oct 23, 2018

@bcmills bcmills added this to the Unplanned milestone Oct 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.