aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/golang.org/x/crypto/blake2b
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-07-06 21:18:14 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-07-06 21:18:14 -0700
commit459bb4531f92f8663afb6f36aa9be5b789bd591f (patch)
treef14e6c06b8e5c63612d1ff36f8cab40ae8a99d20 /vendor/golang.org/x/crypto/blake2b
parent34a3fe426b33a63f2d8e02d4a70c88f137fa5410 (diff)
Update vendor dependencies
Diffstat (limited to 'vendor/golang.org/x/crypto/blake2b')
-rw-r--r--vendor/golang.org/x/crypto/blake2b/blake2b.go68
-rw-r--r--vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.go26
-rw-r--r--vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.s12
-rw-r--r--vendor/golang.org/x/crypto/blake2b/blake2b_amd64.go7
-rw-r--r--vendor/golang.org/x/crypto/blake2b/blake2b_amd64.s9
-rw-r--r--vendor/golang.org/x/crypto/blake2b/blake2b_test.go49
6 files changed, 130 insertions, 41 deletions
diff --git a/vendor/golang.org/x/crypto/blake2b/blake2b.go b/vendor/golang.org/x/crypto/blake2b/blake2b.go
index 6dedb89..58ea875 100644
--- a/vendor/golang.org/x/crypto/blake2b/blake2b.go
+++ b/vendor/golang.org/x/crypto/blake2b/blake2b.go
@@ -92,6 +92,8 @@ func New256(key []byte) (hash.Hash, error) { return newDigest(Size256, key) }
// values equal or greater than:
// - 32 if BLAKE2b is used as a hash function (The key is zero bytes long).
// - 16 if BLAKE2b is used as a MAC function (The key is at least 16 bytes long).
+// When the key is nil, the returned hash.Hash implements BinaryMarshaler
+// and BinaryUnmarshaler for state (de)serialization as documented by hash.Hash.
func New(size int, key []byte) (hash.Hash, error) { return newDigest(size, key) }
func newDigest(hashSize int, key []byte) (*digest, error) {
@@ -150,6 +152,50 @@ type digest struct {
keyLen int
}
+const (
+ magic = "b2b"
+ marshaledSize = len(magic) + 8*8 + 2*8 + 1 + BlockSize + 1
+)
+
+func (d *digest) MarshalBinary() ([]byte, error) {
+ if d.keyLen != 0 {
+ return nil, errors.New("crypto/blake2b: cannot marshal MACs")
+ }
+ b := make([]byte, 0, marshaledSize)
+ b = append(b, magic...)
+ for i := 0; i < 8; i++ {
+ b = appendUint64(b, d.h[i])
+ }
+ b = appendUint64(b, d.c[0])
+ b = appendUint64(b, d.c[1])
+ // Maximum value for size is 64
+ b = append(b, byte(d.size))
+ b = append(b, d.block[:]...)
+ b = append(b, byte(d.offset))
+ return b, nil
+}
+
+func (d *digest) UnmarshalBinary(b []byte) error {
+ if len(b) < len(magic) || string(b[:len(magic)]) != magic {
+ return errors.New("crypto/blake2b: invalid hash state identifier")
+ }
+ if len(b) != marshaledSize {
+ return errors.New("crypto/blake2b: invalid hash state size")
+ }
+ b = b[len(magic):]
+ for i := 0; i < 8; i++ {
+ b, d.h[i] = consumeUint64(b)
+ }
+ b, d.c[0] = consumeUint64(b)
+ b, d.c[1] = consumeUint64(b)
+ d.size = int(b[0])
+ b = b[1:]
+ copy(d.block[:], b[:BlockSize])
+ b = b[BlockSize:]
+ d.offset = int(b[0])
+ return nil
+}
+
func (d *digest) BlockSize() int { return BlockSize }
func (d *digest) Size() int { return d.size }
@@ -219,3 +265,25 @@ func (d *digest) finalize(hash *[Size]byte) {
binary.LittleEndian.PutUint64(hash[8*i:], v)
}
}
+
+func appendUint64(b []byte, x uint64) []byte {
+ var a [8]byte
+ binary.BigEndian.PutUint64(a[:], x)
+ return append(b, a[:]...)
+}
+
+func appendUint32(b []byte, x uint32) []byte {
+ var a [4]byte
+ binary.BigEndian.PutUint32(a[:], x)
+ return append(b, a[:]...)
+}
+
+func consumeUint64(b []byte) ([]byte, uint64) {
+ x := binary.BigEndian.Uint64(b)
+ return b[8:], x
+}
+
+func consumeUint32(b []byte) ([]byte, uint32) {
+ x := binary.BigEndian.Uint32(b)
+ return b[4:], x
+}
diff --git a/vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.go b/vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.go
index 8c41cf6..4d31dd0 100644
--- a/vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.go
+++ b/vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.go
@@ -6,22 +6,15 @@
package blake2b
+import "golang.org/x/sys/cpu"
+
func init() {
- useAVX2 = supportsAVX2()
- useAVX = supportsAVX()
- useSSE4 = supportsSSE4()
+ useAVX2 = cpu.X86.HasAVX2
+ useAVX = cpu.X86.HasAVX
+ useSSE4 = cpu.X86.HasSSE41
}
//go:noescape
-func supportsSSE4() bool
-
-//go:noescape
-func supportsAVX() bool
-
-//go:noescape
-func supportsAVX2() bool
-
-//go:noescape
func hashBlocksAVX2(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
//go:noescape
@@ -31,13 +24,14 @@ func hashBlocksAVX(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
- if useAVX2 {
+ switch {
+ case useAVX2:
hashBlocksAVX2(h, c, flag, blocks)
- } else if useAVX {
+ case useAVX:
hashBlocksAVX(h, c, flag, blocks)
- } else if useSSE4 {
+ case useSSE4:
hashBlocksSSE4(h, c, flag, blocks)
- } else {
+ default:
hashBlocksGeneric(h, c, flag, blocks)
}
}
diff --git a/vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.s b/vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.s
index 784bce6..5593b1b 100644
--- a/vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.s
+++ b/vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.s
@@ -748,15 +748,3 @@ noinc:
MOVQ BP, SP
RET
-
-// func supportsAVX2() bool
-TEXT ·supportsAVX2(SB), 4, $0-1
- MOVQ runtime·support_avx2(SB), AX
- MOVB AX, ret+0(FP)
- RET
-
-// func supportsAVX() bool
-TEXT ·supportsAVX(SB), 4, $0-1
- MOVQ runtime·support_avx(SB), AX
- MOVB AX, ret+0(FP)
- RET
diff --git a/vendor/golang.org/x/crypto/blake2b/blake2b_amd64.go b/vendor/golang.org/x/crypto/blake2b/blake2b_amd64.go
index 2ab7c30..30e2fcd 100644
--- a/vendor/golang.org/x/crypto/blake2b/blake2b_amd64.go
+++ b/vendor/golang.org/x/crypto/blake2b/blake2b_amd64.go
@@ -6,14 +6,13 @@
package blake2b
+import "golang.org/x/sys/cpu"
+
func init() {
- useSSE4 = supportsSSE4()
+ useSSE4 = cpu.X86.HasSSE41
}
//go:noescape
-func supportsSSE4() bool
-
-//go:noescape
func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
diff --git a/vendor/golang.org/x/crypto/blake2b/blake2b_amd64.s b/vendor/golang.org/x/crypto/blake2b/blake2b_amd64.s
index 6453074..578e947 100644
--- a/vendor/golang.org/x/crypto/blake2b/blake2b_amd64.s
+++ b/vendor/golang.org/x/crypto/blake2b/blake2b_amd64.s
@@ -279,12 +279,3 @@ noinc:
MOVQ BP, SP
RET
-
-// func supportsSSE4() bool
-TEXT ·supportsSSE4(SB), 4, $0-1
- MOVL $1, AX
- CPUID
- SHRL $19, CX // Bit 19 indicates SSE4 support
- ANDL $1, CX // CX != 0 if support SSE4
- MOVB CX, ret+0(FP)
- RET
diff --git a/vendor/golang.org/x/crypto/blake2b/blake2b_test.go b/vendor/golang.org/x/crypto/blake2b/blake2b_test.go
index 5d68bbf..723327a 100644
--- a/vendor/golang.org/x/crypto/blake2b/blake2b_test.go
+++ b/vendor/golang.org/x/crypto/blake2b/blake2b_test.go
@@ -6,6 +6,7 @@ package blake2b
import (
"bytes"
+ "encoding"
"encoding/hex"
"fmt"
"hash"
@@ -69,6 +70,54 @@ func TestHashes2X(t *testing.T) {
testHashes2X(t)
}
+func TestMarshal(t *testing.T) {
+ input := make([]byte, 255)
+ for i := range input {
+ input[i] = byte(i)
+ }
+ for _, size := range []int{Size, Size256, Size384, 12, 25, 63} {
+ for i := 0; i < 256; i++ {
+ h, err := New(size, nil)
+ if err != nil {
+ t.Fatalf("size=%d, len(input)=%d: error from New(%v, nil): %v", size, i, size, err)
+ }
+ h2, err := New(size, nil)
+ if err != nil {
+ t.Fatalf("size=%d, len(input)=%d: error from New(%v, nil): %v", size, i, size, err)
+ }
+
+ h.Write(input[:i/2])
+ halfstate, err := h.(encoding.BinaryMarshaler).MarshalBinary()
+ if err != nil {
+ t.Fatalf("size=%d, len(input)=%d: could not marshal: %v", size, i, err)
+ }
+ err = h2.(encoding.BinaryUnmarshaler).UnmarshalBinary(halfstate)
+ if err != nil {
+ t.Fatalf("size=%d, len(input)=%d: could not unmarshal: %v", size, i, err)
+ }
+
+ h.Write(input[i/2 : i])
+ sum := h.Sum(nil)
+ h2.Write(input[i/2 : i])
+ sum2 := h2.Sum(nil)
+
+ if !bytes.Equal(sum, sum2) {
+ t.Fatalf("size=%d, len(input)=%d: results do not match; sum = %v, sum2 = %v", size, i, sum, sum2)
+ }
+
+ h3, err := New(size, nil)
+ if err != nil {
+ t.Fatalf("size=%d, len(input)=%d: error from New(%v, nil): %v", size, i, size, err)
+ }
+ h3.Write(input[:i])
+ sum3 := h3.Sum(nil)
+ if !bytes.Equal(sum, sum3) {
+ t.Fatalf("size=%d, len(input)=%d: sum = %v, want %v", size, i, sum, sum3)
+ }
+ }
+ }
+}
+
func testHashes(t *testing.T) {
key, _ := hex.DecodeString("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f")