1a2f01efa6
Update the Go library to the 1.10beta1 release. Requires a few changes to the compiler for modifications to the map runtime code, and to handle some nowritebarrier cases in the runtime. Reviewed-on: https://go-review.googlesource.com/86455 gotools/: * Makefile.am (go_cmd_vet_files): New variable. (go_cmd_buildid_files, go_cmd_test2json_files): New variables. (s-zdefaultcc): Change from constants to functions. (noinst_PROGRAMS): Add vet, buildid, and test2json. (cgo$(EXEEXT)): Link against $(LIBGOTOOL). (vet$(EXEEXT)): New target. (buildid$(EXEEXT)): New target. (test2json$(EXEEXT)): New target. (install-exec-local): Install all $(noinst_PROGRAMS). (uninstall-local): Uninstasll all $(noinst_PROGRAMS). (check-go-tool): Depend on $(noinst_PROGRAMS). Copy down objabi.go. (check-runtime): Depend on $(noinst_PROGRAMS). (check-cgo-test, check-carchive-test): Likewise. (check-vet): New target. (check): Depend on check-vet. Look at cmd_vet-testlog. (.PHONY): Add check-vet. * Makefile.in: Rebuild. From-SVN: r256365
62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
// Copyright 2017 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package crypto
|
|
|
|
import (
|
|
"crypto/aes"
|
|
"crypto/cipher"
|
|
"crypto/rc4"
|
|
"testing"
|
|
)
|
|
|
|
func TestRC4OutOfBoundsWrite(t *testing.T) {
|
|
// This cipherText is encrypted "0123456789"
|
|
cipherText := []byte{238, 41, 187, 114, 151, 2, 107, 13, 178, 63}
|
|
cipher, err := rc4.NewCipher([]byte{0})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
test(t, "RC4", cipherText, cipher.XORKeyStream)
|
|
}
|
|
func TestCTROutOfBoundsWrite(t *testing.T) {
|
|
testBlock(t, "CTR", cipher.NewCTR)
|
|
}
|
|
func TestOFBOutOfBoundsWrite(t *testing.T) {
|
|
testBlock(t, "OFB", cipher.NewOFB)
|
|
}
|
|
func TestCFBEncryptOutOfBoundsWrite(t *testing.T) {
|
|
testBlock(t, "CFB Encrypt", cipher.NewCFBEncrypter)
|
|
}
|
|
func TestCFBDecryptOutOfBoundsWrite(t *testing.T) {
|
|
testBlock(t, "CFB Decrypt", cipher.NewCFBDecrypter)
|
|
}
|
|
func testBlock(t *testing.T, name string, newCipher func(cipher.Block, []byte) cipher.Stream) {
|
|
// This cipherText is encrypted "0123456789"
|
|
cipherText := []byte{86, 216, 121, 231, 219, 191, 26, 12, 176, 117}
|
|
var iv, key [16]byte
|
|
block, err := aes.NewCipher(key[:])
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
stream := newCipher(block, iv[:])
|
|
test(t, name, cipherText, stream.XORKeyStream)
|
|
}
|
|
func test(t *testing.T, name string, cipherText []byte, xor func([]byte, []byte)) {
|
|
want := "abcdefghij"
|
|
plainText := []byte(want)
|
|
shorterLen := len(cipherText) / 2
|
|
defer func() {
|
|
err := recover()
|
|
if err == nil {
|
|
t.Errorf("%v XORKeyStream expected to panic on len(dst) < len(src), but didn't", name)
|
|
}
|
|
const plain = "0123456789"
|
|
if plainText[shorterLen] == plain[shorterLen] {
|
|
t.Errorf("%v XORKeyStream did out of bounds write, want %v, got %v", name, want, string(plainText))
|
|
}
|
|
}()
|
|
xor(plainText[:shorterLen], cipherText)
|
|
}
|