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

x/crypto/xts: bad length check in Decrypt #19881

Closed
aead opened this issue Apr 7, 2017 · 1 comment
Closed

x/crypto/xts: bad length check in Decrypt #19881

aead opened this issue Apr 7, 2017 · 1 comment

Comments

@aead
Copy link
Contributor

aead commented Apr 7, 2017

What version of Go are you using (go version)?

go version go1.8 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/andreas/go/"
GORACE=""
GOROOT="/home/andreas/.go/root"
GOTOOLDIR="/home/andreas/.go/root/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build198035070=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

package main

import (
    "fmt"
    "bytes"
    "crypto/aes"
    "golang.org/x/crypto/xts"
)

func main() {
    c, err := xts.NewCipher(aes.NewCipher, make([]byte, 32))
	if err != nil {
		panic(fmt.Sprintf("NewCipher failed: %s", err))
	}

	plaintext := make([]byte, 32)
	ciphertext := make([]byte, 32)
	plaintext2 := make([]byte, 48)

	c.Encrypt(ciphertext, plaintext, 0)
	c.Decrypt(plaintext2, ciphertext, 0)

	if !bytes.Equal(plaintext, plaintext2[:32]) {
		panic("encryption - decryption is not inverse")
	}
}

The decryption panics because the Decrypt iterates over the plaintext argument (plaintext2).
That's probably a copy-paste error - the logic looks like copied from Encrypt.

What did you expect to see?

No panic

What did you see instead?

panic: runtime error: index out of range [recovered]
        panic: runtime error: index out of range
@gopherbot
Copy link

CL https://golang.org/cl/39954 mentions this issue.

@gopherbot gopherbot added this to the Unreleased milestone Apr 8, 2017
@golang golang locked and limited conversation to collaborators Jun 1, 2018
c-expert-zigbee pushed a commit to c-expert-zigbee/crypto_go that referenced this issue Mar 28, 2022
This change does two things:
 1. Fix a length checking bug in the Decrypt function.
 2. Use binary.LittleEndian for byte conversions.

Fixes golang/go#19881

Change-Id: I9d33b92f2bd7e6ca8f69308388f1e8a5c6df2be8
Reviewed-on: https://go-review.googlesource.com/39954
Reviewed-by: Adam Langley <agl@golang.org>
c-expert-zigbee pushed a commit to c-expert-zigbee/crypto_go that referenced this issue Mar 29, 2022
This change does two things:
 1. Fix a length checking bug in the Decrypt function.
 2. Use binary.LittleEndian for byte conversions.

Fixes golang/go#19881

Change-Id: I9d33b92f2bd7e6ca8f69308388f1e8a5c6df2be8
Reviewed-on: https://go-review.googlesource.com/39954
Reviewed-by: Adam Langley <agl@golang.org>
LewiGoddard pushed a commit to LewiGoddard/crypto that referenced this issue Feb 16, 2023
This change does two things:
 1. Fix a length checking bug in the Decrypt function.
 2. Use binary.LittleEndian for byte conversions.

Fixes golang/go#19881

Change-Id: I9d33b92f2bd7e6ca8f69308388f1e8a5c6df2be8
Reviewed-on: https://go-review.googlesource.com/39954
Reviewed-by: Adam Langley <agl@golang.org>
BiiChris pushed a commit to BiiChris/crypto that referenced this issue Sep 15, 2023
This change does two things:
 1. Fix a length checking bug in the Decrypt function.
 2. Use binary.LittleEndian for byte conversions.

Fixes golang/go#19881

Change-Id: I9d33b92f2bd7e6ca8f69308388f1e8a5c6df2be8
Reviewed-on: https://go-review.googlesource.com/39954
Reviewed-by: Adam Langley <agl@golang.org>
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

2 participants