Source file src/crypto/internal/fips/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/impl"
    11  	"internal/cpu"
    12  )
    13  
    14  var useAVX2 = cpu.X86.HasAVX2 && cpu.X86.HasBMI2
    15  var useSHANI = useAVX2 && cpu.X86.HasSHA
    16  
    17  func init() {
    18  	impl.Register("crypto/sha256", "AVX2", &useAVX2)
    19  	impl.Register("crypto/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