go.mod: github.com/minio/sha256-simd v1.0.1
https://github.com/minio/sha256-simd/compare/v1.0.0...v1.0.1 Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
		
							
								
								
									
										6
									
								
								vendor/github.com/minio/sha256-simd/cpuid_other.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								vendor/github.com/minio/sha256-simd/cpuid_other.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -23,6 +23,11 @@ import (
 | 
			
		||||
	"github.com/klauspost/cpuid/v2"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	hasIntelSha = runtime.GOARCH == "amd64" && cpuid.CPU.Supports(cpuid.SHA, cpuid.SSSE3, cpuid.SSE4)
 | 
			
		||||
	hasAvx512   = cpuid.CPU.Supports(cpuid.AVX512F, cpuid.AVX512DQ, cpuid.AVX512BW, cpuid.AVX512VL)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func hasArmSha2() bool {
 | 
			
		||||
	if cpuid.CPU.Has(cpuid.SHA2) {
 | 
			
		||||
		return true
 | 
			
		||||
@@ -42,5 +47,4 @@ func hasArmSha2() bool {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	return bytes.Contains(cpuInfo, []byte(sha256Feature))
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										131
									
								
								vendor/github.com/minio/sha256-simd/sha256.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										131
									
								
								vendor/github.com/minio/sha256-simd/sha256.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -19,10 +19,8 @@ package sha256
 | 
			
		||||
import (
 | 
			
		||||
	"crypto/sha256"
 | 
			
		||||
	"encoding/binary"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"hash"
 | 
			
		||||
	"runtime"
 | 
			
		||||
 | 
			
		||||
	"github.com/klauspost/cpuid/v2"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Size - The size of a SHA256 checksum in bytes.
 | 
			
		||||
@@ -68,42 +66,34 @@ func (d *digest) Reset() {
 | 
			
		||||
type blockfuncType int
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	blockfuncGeneric blockfuncType = iota
 | 
			
		||||
	blockfuncSha     blockfuncType = iota
 | 
			
		||||
	blockfuncArm     blockfuncType = iota
 | 
			
		||||
	blockfuncStdlib blockfuncType = iota
 | 
			
		||||
	blockfuncIntelSha
 | 
			
		||||
	blockfuncArmSha2
 | 
			
		||||
	blockfuncForceGeneric = -1
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var blockfunc blockfuncType
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	blockfunc = blockfuncGeneric
 | 
			
		||||
	switch {
 | 
			
		||||
	case hasSHAExtensions():
 | 
			
		||||
		blockfunc = blockfuncSha
 | 
			
		||||
	case hasIntelSha:
 | 
			
		||||
		blockfunc = blockfuncIntelSha
 | 
			
		||||
	case hasArmSha2():
 | 
			
		||||
		blockfunc = blockfuncArm
 | 
			
		||||
	default:
 | 
			
		||||
		blockfunc = blockfuncGeneric
 | 
			
		||||
		blockfunc = blockfuncArmSha2
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var avx512 = cpuid.CPU.Supports(cpuid.AVX512F, cpuid.AVX512DQ, cpuid.AVX512BW, cpuid.AVX512VL)
 | 
			
		||||
 | 
			
		||||
// hasSHAExtensions return  whether the cpu supports SHA extensions.
 | 
			
		||||
func hasSHAExtensions() bool {
 | 
			
		||||
	return cpuid.CPU.Supports(cpuid.SHA, cpuid.SSSE3, cpuid.SSE4) && runtime.GOARCH == "amd64"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// New returns a new hash.Hash computing the SHA256 checksum.
 | 
			
		||||
func New() hash.Hash {
 | 
			
		||||
	if blockfunc != blockfuncGeneric {
 | 
			
		||||
		d := new(digest)
 | 
			
		||||
		d.Reset()
 | 
			
		||||
		return d
 | 
			
		||||
	if blockfunc == blockfuncStdlib {
 | 
			
		||||
		// Fallback to the standard golang implementation
 | 
			
		||||
		// if no features were found.
 | 
			
		||||
		return sha256.New()
 | 
			
		||||
	}
 | 
			
		||||
	// Fallback to the standard golang implementation
 | 
			
		||||
	// if no features were found.
 | 
			
		||||
	return sha256.New()
 | 
			
		||||
 | 
			
		||||
	d := new(digest)
 | 
			
		||||
	d.Reset()
 | 
			
		||||
	return d
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Sum256 - single caller sha256 helper
 | 
			
		||||
@@ -272,11 +262,11 @@ func (d *digest) checkSum() (digest [Size]byte) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func block(dig *digest, p []byte) {
 | 
			
		||||
	if blockfunc == blockfuncSha {
 | 
			
		||||
		blockShaGo(dig, p)
 | 
			
		||||
	} else if blockfunc == blockfuncArm {
 | 
			
		||||
		blockArmGo(dig, p)
 | 
			
		||||
	} else if blockfunc == blockfuncGeneric {
 | 
			
		||||
	if blockfunc == blockfuncIntelSha {
 | 
			
		||||
		blockIntelShaGo(dig, p)
 | 
			
		||||
	} else if blockfunc == blockfuncArmSha2 {
 | 
			
		||||
		blockArmSha2Go(dig, p)
 | 
			
		||||
	} else {
 | 
			
		||||
		blockGeneric(dig, p)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -397,3 +387,82 @@ var _K = []uint32{
 | 
			
		||||
	0xbef9a3f7,
 | 
			
		||||
	0xc67178f2,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	magic256      = "sha\x03"
 | 
			
		||||
	marshaledSize = len(magic256) + 8*4 + chunk + 8
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func (d *digest) MarshalBinary() ([]byte, error) {
 | 
			
		||||
	b := make([]byte, 0, marshaledSize)
 | 
			
		||||
	b = append(b, magic256...)
 | 
			
		||||
	b = appendUint32(b, d.h[0])
 | 
			
		||||
	b = appendUint32(b, d.h[1])
 | 
			
		||||
	b = appendUint32(b, d.h[2])
 | 
			
		||||
	b = appendUint32(b, d.h[3])
 | 
			
		||||
	b = appendUint32(b, d.h[4])
 | 
			
		||||
	b = appendUint32(b, d.h[5])
 | 
			
		||||
	b = appendUint32(b, d.h[6])
 | 
			
		||||
	b = appendUint32(b, d.h[7])
 | 
			
		||||
	b = append(b, d.x[:d.nx]...)
 | 
			
		||||
	b = b[:len(b)+len(d.x)-d.nx] // already zero
 | 
			
		||||
	b = appendUint64(b, d.len)
 | 
			
		||||
	return b, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *digest) UnmarshalBinary(b []byte) error {
 | 
			
		||||
	if len(b) < len(magic256) || string(b[:len(magic256)]) != magic256 {
 | 
			
		||||
		return errors.New("crypto/sha256: invalid hash state identifier")
 | 
			
		||||
	}
 | 
			
		||||
	if len(b) != marshaledSize {
 | 
			
		||||
		return errors.New("crypto/sha256: invalid hash state size")
 | 
			
		||||
	}
 | 
			
		||||
	b = b[len(magic256):]
 | 
			
		||||
	b, d.h[0] = consumeUint32(b)
 | 
			
		||||
	b, d.h[1] = consumeUint32(b)
 | 
			
		||||
	b, d.h[2] = consumeUint32(b)
 | 
			
		||||
	b, d.h[3] = consumeUint32(b)
 | 
			
		||||
	b, d.h[4] = consumeUint32(b)
 | 
			
		||||
	b, d.h[5] = consumeUint32(b)
 | 
			
		||||
	b, d.h[6] = consumeUint32(b)
 | 
			
		||||
	b, d.h[7] = consumeUint32(b)
 | 
			
		||||
	b = b[copy(d.x[:], b):]
 | 
			
		||||
	b, d.len = consumeUint64(b)
 | 
			
		||||
	d.nx = int(d.len % chunk)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func appendUint32(b []byte, v uint32) []byte {
 | 
			
		||||
	return append(b,
 | 
			
		||||
		byte(v>>24),
 | 
			
		||||
		byte(v>>16),
 | 
			
		||||
		byte(v>>8),
 | 
			
		||||
		byte(v),
 | 
			
		||||
	)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func appendUint64(b []byte, v uint64) []byte {
 | 
			
		||||
	return append(b,
 | 
			
		||||
		byte(v>>56),
 | 
			
		||||
		byte(v>>48),
 | 
			
		||||
		byte(v>>40),
 | 
			
		||||
		byte(v>>32),
 | 
			
		||||
		byte(v>>24),
 | 
			
		||||
		byte(v>>16),
 | 
			
		||||
		byte(v>>8),
 | 
			
		||||
		byte(v),
 | 
			
		||||
	)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func consumeUint64(b []byte) ([]byte, uint64) {
 | 
			
		||||
	_ = b[7]
 | 
			
		||||
	x := uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
 | 
			
		||||
		uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
 | 
			
		||||
	return b[8:], x
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func consumeUint32(b []byte) ([]byte, uint32) {
 | 
			
		||||
	_ = b[3]
 | 
			
		||||
	x := uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
 | 
			
		||||
	return b[4:], x
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								vendor/github.com/minio/sha256-simd/sha256blockAvx512_amd64.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								vendor/github.com/minio/sha256-simd/sha256blockAvx512_amd64.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,5 @@
 | 
			
		||||
//+build !noasm,!appengine,gc
 | 
			
		||||
//go:build !noasm && !appengine && gc
 | 
			
		||||
// +build !noasm,!appengine,gc
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Minio Cloud Storage, (C) 2017 Minio, Inc.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/github.com/minio/sha256-simd/sha256blockAvx512_amd64.s
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/minio/sha256-simd/sha256blockAvx512_amd64.s
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
//+build !noasm,!appengine
 | 
			
		||||
//+build !noasm,!appengine,gc
 | 
			
		||||
 | 
			
		||||
TEXT ·sha256X16Avx512(SB), 7, $0
 | 
			
		||||
	MOVQ  digests+0(FP), DI
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								vendor/github.com/minio/sha256-simd/sha256blockSha_amd64.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								vendor/github.com/minio/sha256-simd/sha256blockSha_amd64.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,6 +0,0 @@
 | 
			
		||||
//+build !noasm,!appengine,gc
 | 
			
		||||
 | 
			
		||||
package sha256
 | 
			
		||||
 | 
			
		||||
//go:noescape
 | 
			
		||||
func blockSha(h *[8]uint32, message []uint8)
 | 
			
		||||
							
								
								
									
										14
									
								
								vendor/github.com/minio/sha256-simd/sha256block_amd64.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								vendor/github.com/minio/sha256-simd/sha256block_amd64.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,5 @@
 | 
			
		||||
//+build !noasm,!appengine,gc
 | 
			
		||||
//go:build !noasm && !appengine && gc
 | 
			
		||||
// +build !noasm,!appengine,gc
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Minio Cloud Storage, (C) 2016 Minio, Inc.
 | 
			
		||||
@@ -18,10 +19,13 @@
 | 
			
		||||
 | 
			
		||||
package sha256
 | 
			
		||||
 | 
			
		||||
func blockArmGo(dig *digest, p []byte) {
 | 
			
		||||
	panic("blockArmGo called unexpectedly")
 | 
			
		||||
func blockArmSha2Go(dig *digest, p []byte) {
 | 
			
		||||
	panic("blockArmSha2Go called unexpectedly")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func blockShaGo(dig *digest, p []byte) {
 | 
			
		||||
	blockSha(&dig.h, p)
 | 
			
		||||
//go:noescape
 | 
			
		||||
func blockIntelSha(h *[8]uint32, message []uint8)
 | 
			
		||||
 | 
			
		||||
func blockIntelShaGo(dig *digest, p []byte) {
 | 
			
		||||
	blockIntelSha(&dig.h, p)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
//+build !noasm,!appengine
 | 
			
		||||
//+build !noasm,!appengine,gc
 | 
			
		||||
 | 
			
		||||
// SHA intrinsic version of SHA256
 | 
			
		||||
 | 
			
		||||
@@ -106,7 +106,7 @@ GLOBL SHUF_MASK<>(SB), RODATA|NOPTR, $16
 | 
			
		||||
// X13 saved hash state // CDGH
 | 
			
		||||
// X15 data shuffle mask (constant)
 | 
			
		||||
 | 
			
		||||
TEXT ·blockSha(SB), NOSPLIT, $0-32
 | 
			
		||||
TEXT ·blockIntelSha(SB), NOSPLIT, $0-32
 | 
			
		||||
	MOVQ      h+0(FP), DX
 | 
			
		||||
	MOVQ      message_base+8(FP), SI
 | 
			
		||||
	MOVQ      message_len+16(FP), DI
 | 
			
		||||
							
								
								
									
										13
									
								
								vendor/github.com/minio/sha256-simd/sha256block_arm64.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								vendor/github.com/minio/sha256-simd/sha256block_arm64.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,5 @@
 | 
			
		||||
//+build !noasm,!appengine,gc
 | 
			
		||||
//go:build !noasm && !appengine && gc
 | 
			
		||||
// +build !noasm,!appengine,gc
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Minio Cloud Storage, (C) 2016 Minio, Inc.
 | 
			
		||||
@@ -18,18 +19,18 @@
 | 
			
		||||
 | 
			
		||||
package sha256
 | 
			
		||||
 | 
			
		||||
func blockShaGo(dig *digest, p []byte) {
 | 
			
		||||
	panic("blockShaGoc called unexpectedly")
 | 
			
		||||
func blockIntelShaGo(dig *digest, p []byte) {
 | 
			
		||||
	panic("blockIntelShaGo called unexpectedly")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//go:noescape
 | 
			
		||||
func blockArm(h []uint32, message []uint8)
 | 
			
		||||
func blockArmSha2(h []uint32, message []uint8)
 | 
			
		||||
 | 
			
		||||
func blockArmGo(dig *digest, p []byte) {
 | 
			
		||||
func blockArmSha2Go(dig *digest, p []byte) {
 | 
			
		||||
 | 
			
		||||
	h := []uint32{dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7]}
 | 
			
		||||
 | 
			
		||||
	blockArm(h[:], p[:])
 | 
			
		||||
	blockArmSha2(h[:], p[:])
 | 
			
		||||
 | 
			
		||||
	dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7] = h[0], h[1], h[2], h[3], h[4],
 | 
			
		||||
		h[5], h[6], h[7]
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								vendor/github.com/minio/sha256-simd/sha256block_arm64.s
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								vendor/github.com/minio/sha256-simd/sha256block_arm64.s
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
//+build !noasm,!appengine
 | 
			
		||||
//+build !noasm,!appengine,gc
 | 
			
		||||
 | 
			
		||||
// ARM64 version of SHA256
 | 
			
		||||
 | 
			
		||||
@@ -25,7 +25,7 @@
 | 
			
		||||
// their Plan9 equivalents
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
TEXT ·blockArm(SB), 7, $0
 | 
			
		||||
TEXT ·blockArmSha2(SB), 7, $0
 | 
			
		||||
	MOVD h+0(FP), R0
 | 
			
		||||
	MOVD message+24(FP), R1
 | 
			
		||||
	MOVD message_len+32(FP), R2 // length of message
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								vendor/github.com/minio/sha256-simd/sha256block_other.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								vendor/github.com/minio/sha256-simd/sha256block_other.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,5 @@
 | 
			
		||||
//+build appengine noasm !amd64,!arm64 !gc
 | 
			
		||||
//go:build appengine || noasm || (!amd64 && !arm64) || !gc
 | 
			
		||||
// +build appengine noasm !amd64,!arm64 !gc
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Minio Cloud Storage, (C) 2019 Minio, Inc.
 | 
			
		||||
@@ -18,11 +19,11 @@
 | 
			
		||||
 | 
			
		||||
package sha256
 | 
			
		||||
 | 
			
		||||
func blockShaGo(dig *digest, p []byte) {
 | 
			
		||||
	panic("blockShaGo called unexpectedly")
 | 
			
		||||
func blockIntelShaGo(dig *digest, p []byte) {
 | 
			
		||||
	panic("blockIntelShaGo called unexpectedly")
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func blockArmGo(dig *digest, p []byte) {
 | 
			
		||||
	panic("blockArmGo called unexpectedly")
 | 
			
		||||
func blockArmSha2Go(dig *digest, p []byte) {
 | 
			
		||||
	panic("blockArmSha2Go called unexpectedly")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user