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: input not full blocks #24402

Closed
sukidesuaoi opened this issue Mar 15, 2018 · 3 comments
Closed

crypto/cipher: input not full blocks #24402

sukidesuaoi opened this issue Mar 15, 2018 · 3 comments

Comments

@sukidesuaoi
Copy link

Good day,

I am trying out the crypto/cipher and I am hitting an error when performing CryptBlocks.
It works when the password I am encrypting is within the 16 bytes but, I have encountered a password with more than that, so I tried to change the aeskey to 24 bytes instead.

mode := cipher.NewCBCEncrypter(block, iv)
mode.CryptBlocks(cipherText[aes.BlockSize:], plainTextBytes)

When I run the code and it comes to this point, I am getting an error in CryptBlocks. I tried looking at the code, and it seems that is comparing the size of the text-to-be-encrypted against the aes.BlockSize is which is declared a constant in the ./aes/cipher.go.

// The AES block size in bytes.
const BlockSize = 16

I assumed that by resizing the aeskey will also make the block size follow.
If that is not the case, will someone help/enlighten me?

Thank you in advance.

go1.9.3
GOARCH="amd64"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"

@ALTree
Copy link
Member

ALTree commented Mar 15, 2018

I suspect you are making the same mistake as the OP in issue #9559 (please see Minux comment). The initialization vector (IV) is not the key, and it needs to have length 16.

@sukidesuaoi
Copy link
Author

Hi @ALTree Thank you for your reply.

I can confirm that the IV is in 16 bytes and that it is different from the aeskey.
I am not sure why it encounters error here:

func (x *cbcEncrypter) CryptBlocks(dst, src []byte) {
	if len(src)%x.blockSize != 0 {
		panic("crypto/cipher: input not full blocks")
	}

@ALTree
Copy link
Member

ALTree commented Mar 15, 2018

That panic will trigger when the length of the source (src) is not divisible by the value of blockSize.

I suspect you are simply using the package incorrectly, but it's hard to say because you didn't provide a full, auto-contained code snippet that shows what you're doing and can be actually compiled and run.

In general, we only use the Github issue tracker for confirmed Go bugs. The Questions wiki page has a list of good places for asking questions. My suggestion is to ask for help in one of the places linked there. Remember to show them a full code snippet that can be run and triggers the error you are seeing. Ask if you're using the package correctly.

I'm closing this issue, but if it turns out that this is actually a bug, comment here and we'll re-open. Thanks.

@ALTree ALTree closed this as completed Mar 15, 2018
@golang golang locked and limited conversation to collaborators Mar 15, 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

3 participants