Source file src/crypto/internal/fips140/sha256/sha256block_amd64.go

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !purego
     6  
     7  package sha256
     8  
     9  import (
    10  	"crypto/internal/fips140deps/cpu"
    11  	"crypto/internal/impl"
    12  )
    13  
    14  var useAVX2 = cpu.X86HasAVX && cpu.X86HasAVX2 && cpu.X86HasBMI2
    15  var useSHANI = cpu.X86HasAVX && cpu.X86HasSHA && cpu.X86HasSSE41 && cpu.X86HasSSSE3
    16  
    17  func init() {
    18  	impl.Register("sha256", "AVX2", &useAVX2)
    19  	impl.Register("sha256", "SHA-NI", &useSHANI)
    20  }
    21  
    22  //go:noescape
    23  func blockAMD64(dig *Digest, p []byte)
    24  
    25  //go:noescape
    26  func blockAVX2(dig *Digest, p []byte)
    27  
    28  //go:noescape
    29  func blockSHANI(dig *Digest, p []byte)
    30  
    31  func block(dig *Digest, p []byte) {
    32  	if useSHANI {
    33  		blockSHANI(dig, p)
    34  	} else if useAVX2 {
    35  		blockAVX2(dig, p)
    36  	} else {
    37  		blockAMD64(dig, p)
    38  	}
    39  }
    40  

View as plain text