crypto/cipher: Add ECB support #5597

Closed
gopherbot opened this Issue May 30, 2013 · 3 comments

Comments

Projects
None yet
3 participants
@gopherbot

by hebipp1:

ECB support would be nice. There was also a patch already which was not pulled because
of the Go 1.1 feature freeze: https://golang.org/cl/7860047/
@rsc

This comment has been minimized.

Show comment
Hide comment
@rsc

rsc May 31, 2013

Contributor

Comment 1:

Why? We left ECB out intentionally: it's insecure, and if needed it's
trivial to implement.
Contributor

rsc commented May 31, 2013

Comment 1:

Why? We left ECB out intentionally: it's insecure, and if needed it's
trivial to implement.
@gopherbot

This comment has been minimized.

Show comment
Hide comment
@gopherbot

gopherbot May 31, 2013

Comment 2 by hebipp1:

Well, I need it to implement a protocol (to encrypt the IV that's sended before the
actual content) and I don't know much about cryptography, so I'm a bit cautious to
implement it myself.

Comment 2 by hebipp1:

Well, I need it to implement a protocol (to encrypt the IV that's sended before the
actual content) and I don't know much about cryptography, so I'm a bit cautious to
implement it myself.
@agl

This comment has been minimized.

Show comment
Hide comment
@agl

agl May 31, 2013

Contributor

Comment 3:

IV are supposed to be public and shouldn't be encrypted, but anyway...
ECB is essentially "no mode" and while it isn't supported in a named fashion,
crypto/cipher.Block.Encrypt and Decrypt implement it on a block by block basis. You just
need to feed in a multiple of the blocksize:
bs := block.BlockSize()
if len(plaintext) % bs != 0 {
  panic("Need a multiple of the blocksize")
}
ciphertext := make([]byte, len(plaintext))
for len(plaintext) > 0 {
  block.Encrypt(ciphertext, plaintext)
  plaintext = plaintext[bs:]
  ciphertext = ciphertext[bs:]
}
[1] http://golang.org/pkg/crypto/cipher/#Block

Status changed to WontFix.

Contributor

agl commented May 31, 2013

Comment 3:

IV are supposed to be public and shouldn't be encrypted, but anyway...
ECB is essentially "no mode" and while it isn't supported in a named fashion,
crypto/cipher.Block.Encrypt and Decrypt implement it on a block by block basis. You just
need to feed in a multiple of the blocksize:
bs := block.BlockSize()
if len(plaintext) % bs != 0 {
  panic("Need a multiple of the blocksize")
}
ciphertext := make([]byte, len(plaintext))
for len(plaintext) > 0 {
  block.Encrypt(ciphertext, plaintext)
  plaintext = plaintext[bs:]
  ciphertext = ciphertext[bs:]
}
[1] http://golang.org/pkg/crypto/cipher/#Block

Status changed to WontFix.

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.