Source file src/crypto/internal/fips140/sha3/sha3_arm64.go

     1  // Copyright 2025 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 sha3
     8  
     9  import (
    10  	"crypto/internal/fips140deps/cpu"
    11  	"crypto/internal/impl"
    12  	"runtime"
    13  )
    14  
    15  // On non-Apple ARM64, the SHA-3 instructions are apparently slower than the
    16  // pure Go implementation. Checking GOOS is a bit blunt, as it also excludes
    17  // Asahi Linux; we might consider checking the MIDR model in the future.
    18  var useSHA3 = cpu.ARM64HasSHA3 && runtime.GOOS == "darwin"
    19  
    20  func init() {
    21  	impl.Register("sha3", "Armv8.2", &useSHA3)
    22  }
    23  
    24  //go:noescape
    25  func keccakF1600NEON(a *[200]byte)
    26  
    27  func keccakF1600(a *[200]byte) {
    28  	if useSHA3 {
    29  		keccakF1600NEON(a)
    30  	} else {
    31  		keccakF1600Generic(a)
    32  	}
    33  }
    34  
    35  func (d *Digest) write(p []byte) (n int, err error) {
    36  	return d.writeGeneric(p)
    37  }
    38  func (d *Digest) read(out []byte) (n int, err error) {
    39  	return d.readGeneric(out)
    40  }
    41  func (d *Digest) sum(b []byte) []byte {
    42  	return d.sumGeneric(b)
    43  }
    44  

View as plain text