What version of Go are you using (go version)?
$ go version
1.14.2
Does this issue reproduce with the latest release?
yes, but bug is in x/ not the stdlib, anyway.
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/elagergren/gopath/bin"
GOCACHE="/Users/elagergren/Library/Caches/go-build"
GOENV="/Users/elagergren/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/elagergren/gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/elagergren/.local/share/gopath/src/golang.org/x/crypto/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2b/74fz3jhd4wz4vnbf4z7ywzww0000gp/T/go-build588172469=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Was running project Wychefproof test vectors and marshaling (r, s) into a signature failed: https://play.golang.org/p/aiuFIKDTUIj
What did you expect to see?
Same output as asn1.Marshal.
What did you see instead?
A runtime panic.
The existing code in encoding/asn1 correctly handles the case where the integer is -1 by checking the length of math/big.(*Int).Bytes, which may be zero if n-1 == 0:
|
if len(bytes) == 0 || bytes[0]&0x80 == 0 { |
However, x/crypto/cryptobyte does not: https://github.com/golang/crypto/blob/0848c9571904fcbcb24543358ca8b5a7dbfde875/cryptobyte/asn1.go#L84
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
yes, but bug is in x/ not the stdlib, anyway.
What operating system and processor architecture are you using (
go env)?go envOutputWhat did you do?
Was running project Wychefproof test vectors and marshaling (r, s) into a signature failed: https://play.golang.org/p/aiuFIKDTUIj
What did you expect to see?
Same output as
asn1.Marshal.What did you see instead?
A runtime panic.
The existing code in
encoding/asn1correctly handles the case where the integer is -1 by checking the length ofmath/big.(*Int).Bytes, which may be zero ifn-1 == 0:go/src/encoding/asn1/marshal.go
Line 169 in b0da26a
However,
x/crypto/cryptobytedoes not: https://github.com/golang/crypto/blob/0848c9571904fcbcb24543358ca8b5a7dbfde875/cryptobyte/asn1.go#L84