aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/crypto/aes
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-01-18 19:04:36 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-01-18 19:04:36 +0000
commit4f4a855d82a889cebcfca150a7a43909bcb6a346 (patch)
treef12bae0781920fa34669fe30b6f4615a86d9fb80 /libgo/go/crypto/aes
parent225220d668dafb8262db7012bced688acbe63b33 (diff)
downloadgcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.zip
gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.gz
gcc-4f4a855d82a889cebcfca150a7a43909bcb6a346.tar.bz2
libgo: update to Go1.12beta2
Reviewed-on: https://go-review.googlesource.com/c/158019 gotools/: * Makefile.am (go_cmd_vet_files): Update for Go1.12beta2 release. (GOTOOLS_TEST_TIMEOUT): Increase to 600. (check-runtime): Export LD_LIBRARY_PATH before computing GOARCH and GOOS. (check-vet): Copy golang.org/x/tools into check-vet-dir. * Makefile.in: Regenerate. gcc/testsuite/: * go.go-torture/execute/names-1.go: Stop using debug/xcoff, which is no longer externally visible. From-SVN: r268084
Diffstat (limited to 'libgo/go/crypto/aes')
-rw-r--r--libgo/go/crypto/aes/aes_test.go10
-rw-r--r--libgo/go/crypto/aes/block.go48
-rw-r--r--libgo/go/crypto/aes/ctr_s390x.go14
-rw-r--r--libgo/go/crypto/aes/gcm_s390x.go31
4 files changed, 44 insertions, 59 deletions
diff --git a/libgo/go/crypto/aes/aes_test.go b/libgo/go/crypto/aes/aes_test.go
index bedc2da..1e8bac4 100644
--- a/libgo/go/crypto/aes/aes_test.go
+++ b/libgo/go/crypto/aes/aes_test.go
@@ -231,12 +231,10 @@ L:
continue L
}
}
- if dec != nil {
- for j, v := range dec {
- if v != tt.dec[j] {
- t.Errorf("key %d: dec[%d] = %#x, want %#x", i, j, v, tt.dec[j])
- continue L
- }
+ for j, v := range dec {
+ if v != tt.dec[j] {
+ t.Errorf("key %d: dec[%d] = %#x, want %#x", i, j, v, tt.dec[j])
+ continue L
}
}
}
diff --git a/libgo/go/crypto/aes/block.go b/libgo/go/crypto/aes/block.go
index 8647019..40bd0d3 100644
--- a/libgo/go/crypto/aes/block.go
+++ b/libgo/go/crypto/aes/block.go
@@ -36,14 +36,17 @@
package aes
+import (
+ "encoding/binary"
+)
+
// Encrypt one block from src into dst, using the expanded key xk.
func encryptBlockGo(xk []uint32, dst, src []byte) {
- var s0, s1, s2, s3, t0, t1, t2, t3 uint32
-
- s0 = uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3])
- s1 = uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7])
- s2 = uint32(src[8])<<24 | uint32(src[9])<<16 | uint32(src[10])<<8 | uint32(src[11])
- s3 = uint32(src[12])<<24 | uint32(src[13])<<16 | uint32(src[14])<<8 | uint32(src[15])
+ _ = src[15] // early bounds check
+ s0 := binary.BigEndian.Uint32(src[0:4])
+ s1 := binary.BigEndian.Uint32(src[4:8])
+ s2 := binary.BigEndian.Uint32(src[8:12])
+ s3 := binary.BigEndian.Uint32(src[12:16])
// First round just XORs input with key.
s0 ^= xk[0]
@@ -55,6 +58,7 @@ func encryptBlockGo(xk []uint32, dst, src []byte) {
// Number of rounds is set by length of expanded key.
nr := len(xk)/4 - 2 // - 2: one above, one more below
k := 4
+ var t0, t1, t2, t3 uint32
for r := 0; r < nr; r++ {
t0 = xk[k+0] ^ te0[uint8(s0>>24)] ^ te1[uint8(s1>>16)] ^ te2[uint8(s2>>8)] ^ te3[uint8(s3)]
t1 = xk[k+1] ^ te0[uint8(s1>>24)] ^ te1[uint8(s2>>16)] ^ te2[uint8(s3>>8)] ^ te3[uint8(s0)]
@@ -75,20 +79,20 @@ func encryptBlockGo(xk []uint32, dst, src []byte) {
s2 ^= xk[k+2]
s3 ^= xk[k+3]
- dst[0], dst[1], dst[2], dst[3] = byte(s0>>24), byte(s0>>16), byte(s0>>8), byte(s0)
- dst[4], dst[5], dst[6], dst[7] = byte(s1>>24), byte(s1>>16), byte(s1>>8), byte(s1)
- dst[8], dst[9], dst[10], dst[11] = byte(s2>>24), byte(s2>>16), byte(s2>>8), byte(s2)
- dst[12], dst[13], dst[14], dst[15] = byte(s3>>24), byte(s3>>16), byte(s3>>8), byte(s3)
+ _ = dst[15] // early bounds check
+ binary.BigEndian.PutUint32(dst[0:4], s0)
+ binary.BigEndian.PutUint32(dst[4:8], s1)
+ binary.BigEndian.PutUint32(dst[8:12], s2)
+ binary.BigEndian.PutUint32(dst[12:16], s3)
}
// Decrypt one block from src into dst, using the expanded key xk.
func decryptBlockGo(xk []uint32, dst, src []byte) {
- var s0, s1, s2, s3, t0, t1, t2, t3 uint32
-
- s0 = uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3])
- s1 = uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7])
- s2 = uint32(src[8])<<24 | uint32(src[9])<<16 | uint32(src[10])<<8 | uint32(src[11])
- s3 = uint32(src[12])<<24 | uint32(src[13])<<16 | uint32(src[14])<<8 | uint32(src[15])
+ _ = src[15] // early bounds check
+ s0 := binary.BigEndian.Uint32(src[0:4])
+ s1 := binary.BigEndian.Uint32(src[4:8])
+ s2 := binary.BigEndian.Uint32(src[8:12])
+ s3 := binary.BigEndian.Uint32(src[12:16])
// First round just XORs input with key.
s0 ^= xk[0]
@@ -100,6 +104,7 @@ func decryptBlockGo(xk []uint32, dst, src []byte) {
// Number of rounds is set by length of expanded key.
nr := len(xk)/4 - 2 // - 2: one above, one more below
k := 4
+ var t0, t1, t2, t3 uint32
for r := 0; r < nr; r++ {
t0 = xk[k+0] ^ td0[uint8(s0>>24)] ^ td1[uint8(s3>>16)] ^ td2[uint8(s2>>8)] ^ td3[uint8(s1)]
t1 = xk[k+1] ^ td0[uint8(s1>>24)] ^ td1[uint8(s0>>16)] ^ td2[uint8(s3>>8)] ^ td3[uint8(s2)]
@@ -120,10 +125,11 @@ func decryptBlockGo(xk []uint32, dst, src []byte) {
s2 ^= xk[k+2]
s3 ^= xk[k+3]
- dst[0], dst[1], dst[2], dst[3] = byte(s0>>24), byte(s0>>16), byte(s0>>8), byte(s0)
- dst[4], dst[5], dst[6], dst[7] = byte(s1>>24), byte(s1>>16), byte(s1>>8), byte(s1)
- dst[8], dst[9], dst[10], dst[11] = byte(s2>>24), byte(s2>>16), byte(s2>>8), byte(s2)
- dst[12], dst[13], dst[14], dst[15] = byte(s3>>24), byte(s3>>16), byte(s3>>8), byte(s3)
+ _ = dst[15] // early bounds check
+ binary.BigEndian.PutUint32(dst[0:4], s0)
+ binary.BigEndian.PutUint32(dst[4:8], s1)
+ binary.BigEndian.PutUint32(dst[8:12], s2)
+ binary.BigEndian.PutUint32(dst[12:16], s3)
}
// Apply sbox0 to each byte in w.
@@ -144,7 +150,7 @@ func expandKeyGo(key []byte, enc, dec []uint32) {
var i int
nk := len(key) / 4
for i = 0; i < nk; i++ {
- enc[i] = uint32(key[4*i])<<24 | uint32(key[4*i+1])<<16 | uint32(key[4*i+2])<<8 | uint32(key[4*i+3])
+ enc[i] = binary.BigEndian.Uint32(key[4*i:])
}
for ; i < len(enc); i++ {
t := enc[i-1]
diff --git a/libgo/go/crypto/aes/ctr_s390x.go b/libgo/go/crypto/aes/ctr_s390x.go
index a3c43a3..aed493d 100644
--- a/libgo/go/crypto/aes/ctr_s390x.go
+++ b/libgo/go/crypto/aes/ctr_s390x.go
@@ -9,7 +9,7 @@ package aes
import (
"crypto/cipher"
"crypto/internal/subtle"
- "unsafe"
+ "encoding/binary"
)
// Assert that aesCipherAsm implements the ctrAble interface.
@@ -40,8 +40,8 @@ func (c *aesCipherAsm) NewCTR(iv []byte) cipher.Stream {
}
var ac aesctr
ac.block = c
- ac.ctr[0] = *(*uint64)(unsafe.Pointer((&iv[0]))) // high bits
- ac.ctr[1] = *(*uint64)(unsafe.Pointer((&iv[8]))) // low bits
+ ac.ctr[0] = binary.BigEndian.Uint64(iv[0:]) // high bits
+ ac.ctr[1] = binary.BigEndian.Uint64(iv[8:]) // low bits
ac.buffer = ac.storage[:0]
return &ac
}
@@ -50,10 +50,10 @@ func (c *aesctr) refill() {
// Fill up the buffer with an incrementing count.
c.buffer = c.storage[:streamBufferSize]
c0, c1 := c.ctr[0], c.ctr[1]
- for i := 0; i < streamBufferSize; i += BlockSize {
- b0 := (*uint64)(unsafe.Pointer(&c.buffer[i]))
- b1 := (*uint64)(unsafe.Pointer(&c.buffer[i+BlockSize/2]))
- *b0, *b1 = c0, c1
+ for i := 0; i < streamBufferSize; i += 16 {
+ binary.BigEndian.PutUint64(c.buffer[i+0:], c0)
+ binary.BigEndian.PutUint64(c.buffer[i+8:], c1)
+
// Increment in big endian: c0 is high, c1 is low.
c1++
if c1 == 0 {
diff --git a/libgo/go/crypto/aes/gcm_s390x.go b/libgo/go/crypto/aes/gcm_s390x.go
index 18b0e82..bd1f9a0 100644
--- a/libgo/go/crypto/aes/gcm_s390x.go
+++ b/libgo/go/crypto/aes/gcm_s390x.go
@@ -10,6 +10,7 @@ import (
"crypto/cipher"
subtleoverlap "crypto/internal/subtle"
"crypto/subtle"
+ "encoding/binary"
"errors"
"internal/cpu"
)
@@ -24,35 +25,15 @@ type gcmCount [16]byte
// inc increments the rightmost 32-bits of the count value by 1.
func (x *gcmCount) inc() {
- // The compiler should optimize this to a 32-bit addition.
- n := uint32(x[15]) | uint32(x[14])<<8 | uint32(x[13])<<16 | uint32(x[12])<<24
- n += 1
- x[12] = byte(n >> 24)
- x[13] = byte(n >> 16)
- x[14] = byte(n >> 8)
- x[15] = byte(n)
+ binary.BigEndian.PutUint32(x[len(x)-4:], binary.BigEndian.Uint32(x[len(x)-4:])+1)
}
// gcmLengths writes len0 || len1 as big-endian values to a 16-byte array.
func gcmLengths(len0, len1 uint64) [16]byte {
- return [16]byte{
- byte(len0 >> 56),
- byte(len0 >> 48),
- byte(len0 >> 40),
- byte(len0 >> 32),
- byte(len0 >> 24),
- byte(len0 >> 16),
- byte(len0 >> 8),
- byte(len0),
- byte(len1 >> 56),
- byte(len1 >> 48),
- byte(len1 >> 40),
- byte(len1 >> 32),
- byte(len1 >> 24),
- byte(len1 >> 16),
- byte(len1 >> 8),
- byte(len1),
- }
+ v := [16]byte{}
+ binary.BigEndian.PutUint64(v[0:], len0)
+ binary.BigEndian.PutUint64(v[8:], len1)
+ return v
}
// gcmHashKey represents the 16-byte hash key required by the GHASH algorithm.