github.com/icodeface/tls@v0.0.0-20230910023335-34df9250cd12/internal/x/crypto/poly1305/sum_s390x.go (about)

     1  // Copyright 2018 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  // +build s390x,go1.11,!gccgo,!appengine
     6  
     7  package poly1305
     8  
     9  // hasVectorFacility reports whether the machine supports
    10  // the vector facility (vx).
    11  func hasVectorFacility() bool
    12  
    13  // hasVMSLFacility reports whether the machine supports
    14  // Vector Multiply Sum Logical (VMSL).
    15  func hasVMSLFacility() bool
    16  
    17  var hasVX = hasVectorFacility()
    18  var hasVMSL = hasVMSLFacility()
    19  
    20  // poly1305vx is an assembly implementation of Poly1305 that uses vector
    21  // instructions. It must only be called if the vector facility (vx) is
    22  // available.
    23  //go:noescape
    24  func poly1305vx(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
    25  
    26  // poly1305vmsl is an assembly implementation of Poly1305 that uses vector
    27  // instructions, including VMSL. It must only be called if the vector facility (vx) is
    28  // available and if VMSL is supported.
    29  //go:noescape
    30  func poly1305vmsl(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
    31  
    32  // Sum generates an authenticator for m using a one-time key and puts the
    33  // 16-byte result into out. Authenticating two different messages with the same
    34  // key allows an attacker to forge messages at will.
    35  func Sum(out *[16]byte, m []byte, key *[32]byte) {
    36  	if hasVX {
    37  		var mPtr *byte
    38  		if len(m) > 0 {
    39  			mPtr = &m[0]
    40  		}
    41  		if hasVMSL && len(m) > 256 {
    42  			poly1305vmsl(out, mPtr, uint64(len(m)), key)
    43  		} else {
    44  			poly1305vx(out, mPtr, uint64(len(m)), key)
    45  		}
    46  	} else {
    47  		sumGeneric(out, m, key)
    48  	}
    49  }