diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-07-22 18:15:38 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-07-22 18:15:38 +0000 |
commit | 22b955cca564a9a3a5b8c9d9dd1e295b7943c128 (patch) | |
tree | abdbd898676e1f853fca2d7e031d105d7ebcf676 /libgo/go/crypto/cipher | |
parent | 9d04a3af4c6491536badf6bde9707c907e4d196b (diff) | |
download | gcc-22b955cca564a9a3a5b8c9d9dd1e295b7943c128.zip gcc-22b955cca564a9a3a5b8c9d9dd1e295b7943c128.tar.gz gcc-22b955cca564a9a3a5b8c9d9dd1e295b7943c128.tar.bz2 |
libgo: update to go1.7rc3
Reviewed-on: https://go-review.googlesource.com/25150
From-SVN: r238662
Diffstat (limited to 'libgo/go/crypto/cipher')
-rw-r--r-- | libgo/go/crypto/cipher/cbc.go | 22 | ||||
-rw-r--r-- | libgo/go/crypto/cipher/cipher.go | 4 | ||||
-rw-r--r-- | libgo/go/crypto/cipher/cipher_test.go | 2 | ||||
-rw-r--r-- | libgo/go/crypto/cipher/ctr.go | 10 | ||||
-rw-r--r-- | libgo/go/crypto/cipher/example_test.go | 7 | ||||
-rw-r--r-- | libgo/go/crypto/cipher/xor.go | 2 | ||||
-rw-r--r-- | libgo/go/crypto/cipher/xor_test.go | 2 |
7 files changed, 41 insertions, 8 deletions
diff --git a/libgo/go/crypto/cipher/cbc.go b/libgo/go/crypto/cipher/cbc.go index 241e122..0367d59 100644 --- a/libgo/go/crypto/cipher/cbc.go +++ b/libgo/go/crypto/cipher/cbc.go @@ -29,6 +29,14 @@ func newCBC(b Block, iv []byte) *cbc { type cbcEncrypter cbc +// cbcEncAble is an interface implemented by ciphers that have a specific +// optimized implementation of CBC encryption, like crypto/aes. +// NewCBCEncrypter will check for this interface and return the specific +// BlockMode if found. +type cbcEncAble interface { + NewCBCEncrypter(iv []byte) BlockMode +} + // NewCBCEncrypter returns a BlockMode which encrypts in cipher block chaining // mode, using the given Block. The length of iv must be the same as the // Block's block size. @@ -36,6 +44,9 @@ func NewCBCEncrypter(b Block, iv []byte) BlockMode { if len(iv) != b.BlockSize() { panic("cipher.NewCBCEncrypter: IV length must equal block size") } + if cbc, ok := b.(cbcEncAble); ok { + return cbc.NewCBCEncrypter(iv) + } return (*cbcEncrypter)(newCBC(b, iv)) } @@ -75,6 +86,14 @@ func (x *cbcEncrypter) SetIV(iv []byte) { type cbcDecrypter cbc +// cbcDecAble is an interface implemented by ciphers that have a specific +// optimized implementation of CBC decryption, like crypto/aes. +// NewCBCDecrypter will check for this interface and return the specific +// BlockMode if found. +type cbcDecAble interface { + NewCBCDecrypter(iv []byte) BlockMode +} + // NewCBCDecrypter returns a BlockMode which decrypts in cipher block chaining // mode, using the given Block. The length of iv must be the same as the // Block's block size and must match the iv used to encrypt the data. @@ -82,6 +101,9 @@ func NewCBCDecrypter(b Block, iv []byte) BlockMode { if len(iv) != b.BlockSize() { panic("cipher.NewCBCDecrypter: IV length must equal block size") } + if cbc, ok := b.(cbcDecAble); ok { + return cbc.NewCBCDecrypter(iv) + } return (*cbcDecrypter)(newCBC(b, iv)) } diff --git a/libgo/go/crypto/cipher/cipher.go b/libgo/go/crypto/cipher/cipher.go index 7d27fde..531ecad 100644 --- a/libgo/go/crypto/cipher/cipher.go +++ b/libgo/go/crypto/cipher/cipher.go @@ -9,8 +9,8 @@ package cipher // A Block represents an implementation of block cipher -// using a given key. It provides the capability to encrypt -// or decrypt individual blocks. The mode implementations +// using a given key. It provides the capability to encrypt +// or decrypt individual blocks. The mode implementations // extend that capability to streams of blocks. type Block interface { // BlockSize returns the cipher's block size. diff --git a/libgo/go/crypto/cipher/cipher_test.go b/libgo/go/crypto/cipher/cipher_test.go index 8da5bce..1faa7b8 100644 --- a/libgo/go/crypto/cipher/cipher_test.go +++ b/libgo/go/crypto/cipher/cipher_test.go @@ -1,4 +1,4 @@ -// Copyright 2013 The Go Authors. All rights reserved. +// Copyright 2013 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. diff --git a/libgo/go/crypto/cipher/ctr.go b/libgo/go/crypto/cipher/ctr.go index 16baa6d..75f46cf 100644 --- a/libgo/go/crypto/cipher/ctr.go +++ b/libgo/go/crypto/cipher/ctr.go @@ -21,9 +21,19 @@ type ctr struct { const streamBufferSize = 512 +// ctrAble is an interface implemented by ciphers that have a specific optimized +// implementation of CTR, like crypto/aes. NewCTR will check for this interface +// and return the specific Stream if found. +type ctrAble interface { + NewCTR(iv []byte) Stream +} + // NewCTR returns a Stream which encrypts/decrypts using the given Block in // counter mode. The length of iv must be the same as the Block's block size. func NewCTR(block Block, iv []byte) Stream { + if ctr, ok := block.(ctrAble); ok { + return ctr.NewCTR(iv) + } if len(iv) != block.BlockSize() { panic("cipher.NewCTR: IV length must equal block size") } diff --git a/libgo/go/crypto/cipher/example_test.go b/libgo/go/crypto/cipher/example_test.go index f6cc386..9abe782 100644 --- a/libgo/go/crypto/cipher/example_test.go +++ b/libgo/go/crypto/cipher/example_test.go @@ -44,9 +44,9 @@ func ExampleNewGCMDecrypter() { // The key argument should be the AES key, either 16 or 32 bytes // to select AES-128 or AES-256. key := []byte("AES256Key-32Characters1234567890") - ciphertext, _ := hex.DecodeString("f90fbef747e7212ad7410d0eee2d965de7e890471695cddd2a5bc0ef5da1d04ad8147b62141ad6e4914aee8c512f64fba9037603d41de0d50b718bd665f019cdcd") + ciphertext, _ := hex.DecodeString("1019aa66cd7c024f9efd0038899dae1973ee69427f5a6579eba292ffe1b5a260") - nonce, _ := hex.DecodeString("bb8ef84243d2ee95a41c6c57") + nonce, _ := hex.DecodeString("37b8e8a308c354048d245f6d") block, err := aes.NewCipher(key) if err != nil { @@ -63,7 +63,8 @@ func ExampleNewGCMDecrypter() { panic(err.Error()) } - fmt.Printf("%s\n", string(plaintext)) + fmt.Printf("%s\n", plaintext) + // Output: exampleplaintext } func ExampleNewCBCDecrypter() { diff --git a/libgo/go/crypto/cipher/xor.go b/libgo/go/crypto/cipher/xor.go index f88dc89..01ca0a9 100644 --- a/libgo/go/crypto/cipher/xor.go +++ b/libgo/go/crypto/cipher/xor.go @@ -10,7 +10,7 @@ import ( ) const wordSize = int(unsafe.Sizeof(uintptr(0))) -const supportsUnaligned = runtime.GOARCH == "386" || runtime.GOARCH == "amd64" +const supportsUnaligned = runtime.GOARCH == "386" || runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" || runtime.GOARCH == "s390x" // fastXORBytes xors in bulk. It only works on architectures that // support unaligned read/writes. diff --git a/libgo/go/crypto/cipher/xor_test.go b/libgo/go/crypto/cipher/xor_test.go index cc1c9d7..d9187eb 100644 --- a/libgo/go/crypto/cipher/xor_test.go +++ b/libgo/go/crypto/cipher/xor_test.go @@ -19,7 +19,7 @@ func TestXOR(t *testing.T) { d2 := make([]byte, 1024+alignD)[alignD:] xorBytes(d1, p, q) safeXORBytes(d2, p, q) - if bytes.Compare(d1, d2) != 0 { + if !bytes.Equal(d1, d2) { t.Error("not equal") } } |