crypto: use and test purego tag consistently

Fixes #58636
Updates #23172

Change-Id: I578a5597f467be45a7d6fb7582b24855b2e6512b
Reviewed-on: https://go-review.googlesource.com/c/go/+/561935
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Filippo Valsorda 2024-02-06 13:32:39 +01:00 committed by Gopher Robot
parent dff3a00cea
commit 8a57cc8e37
81 changed files with 194 additions and 38 deletions

View file

@ -691,6 +691,14 @@ func (t *tester) registerTests() {
})
}
// Check that all crypto packages compile with the purego build tag.
t.registerTest("crypto with tag purego", &goTest{
variant: "purego",
tags: []string{"purego"},
pkg: "crypto/...",
runTests: "^$", // only ensure they compile
})
// Test ios/amd64 for the iOS simulator.
if goos == "darwin" && goarch == "amd64" && t.cgoEnabled {
t.registerTest("GOOS=ios on darwin/amd64",

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build amd64 || arm64
//go:build (amd64 || arm64) && !purego
package aes

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// func encryptBlockAsm(nr int, xk *uint32, dst, src *byte)

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
DATA rotInvSRows<>+0x00(SB)/8, $0x080f0205040b0e01
DATA rotInvSRows<>+0x08(SB)/8, $0x00070a0d0c030609

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ppc64 || ppc64le
//go:build (ppc64 || ppc64le) && !purego
// Based on CRYPTOGAMS code with the following comment:
// # ====================================================================

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// func cryptBlocks(c code, key, dst, src *byte, length int)

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ppc64 || ppc64le
//go:build (ppc64 || ppc64le) && !purego
package aes

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package aes
import (

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build amd64 || arm64 || ppc64 || ppc64le
//go:build (amd64 || arm64 || ppc64 || ppc64le) && !purego
package aes

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !amd64 && !s390x && !ppc64 && !ppc64le && !arm64
//go:build (!amd64 && !s390x && !ppc64 && !ppc64le && !arm64) || purego
package aes

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package aes
import (

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package aes
import (

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
// This is an optimized implementation of AES-GCM using AES-NI and CLMUL-NI
// The implementation uses some optimization as described in:
// [1] Gueron, S., Kounavis, M.E.: Intel® Carry-Less Multiplication

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
#define B0 V0

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ppc64le || ppc64
//go:build (ppc64le || ppc64) && !purego
package aes

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ppc64 || ppc64le
//go:build (ppc64 || ppc64le) && !purego
// Portions based on CRYPTOGAMS code with the following comment:
// # ====================================================================

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package aes
import (

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !s390x
//go:build !s390x || purego
package ecdsa

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package ecdsa
import (

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// func kdsa(fc uint64, params *[4096]byte) (errn uint64)

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build s390x
//go:build s390x && !purego
package ecdsa

View file

@ -17,7 +17,7 @@ import (
func main() {
Package("crypto/internal/edwards25519/field")
ConstraintExpr("amd64,gc,!purego")
ConstraintExpr("!purego")
feMul()
feSquare()
Generate()

View file

@ -1,6 +1,6 @@
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
//go:build amd64 && gc && !purego
//go:build !purego
package field

View file

@ -1,6 +1,6 @@
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
//go:build amd64 && gc && !purego
//go:build !purego
#include "textflag.h"

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !amd64 || !gc || purego
//go:build !amd64 || purego
package field

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build arm64 && gc && !purego
//go:build !purego
package field

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build arm64 && gc && !purego
//go:build !purego
#include "textflag.h"

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !arm64 || !gc || purego
//go:build !arm64 || purego
package field

View file

@ -40,7 +40,7 @@ var curves = []struct {
P: "P256",
Element: "fiat.P256Element",
Params: elliptic.P256().Params(),
BuildTags: "!amd64 && !arm64 && !ppc64le && !s390x",
BuildTags: "(!amd64 && !arm64 && !ppc64le && !s390x) || purego",
},
{
P: "P384",

View file

@ -4,7 +4,7 @@
// Code generated by generate.go. DO NOT EDIT.
//go:build !amd64 && !arm64 && !ppc64le && !s390x
//go:build (!amd64 && !arm64 && !ppc64le && !s390x) || purego
package nistec

View file

@ -10,7 +10,7 @@
// https://link.springer.com/article/10.1007%2Fs13389-014-0090-x
// https://eprint.iacr.org/2013/816.pdf
//go:build amd64 || arm64 || ppc64le || s390x
//go:build (amd64 || arm64 || ppc64le || s390x) && !purego
package nistec

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
// This file contains constant-time, 64-bit assembly implementation of
// P256. The optimizations performed here are described in detail in:
// S.Gueron and V.Krasnov, "Fast prime field elliptic-curve cryptography with

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
// This file contains constant-time, 64-bit assembly implementation of
// P256. The optimizations performed here are described in detail in:
// S.Gueron and V.Krasnov, "Fast prime field elliptic-curve cryptography with

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// This is a port of the s390x asm implementation.

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
#include "go_asm.h"

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build amd64 || arm64 || ppc64le || s390x
//go:build !purego && (amd64 || arm64 || ppc64le || s390x)
package nistec

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build amd64 || arm64
//go:build (amd64 || arm64) && !purego
package nistec

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !amd64 && !arm64
//go:build (!amd64 && !arm64) || purego
package nistec

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build amd64 || arm64
//go:build (amd64 || arm64) && !purego
package nistec_test

View file

@ -6,6 +6,8 @@
// #defines generating 8a assembly, and adjusted for 386,
// by the Go Authors.
//go:build !purego
#include "textflag.h"
// MD5 optimized for AMD64.

View file

@ -5,6 +5,8 @@
// Translated from Perl generating GNU assembly into
// #defines generating 6a assembly by the Go Authors.
//go:build !purego
#include "textflag.h"
// MD5 optimized for AMD64.

View file

@ -4,6 +4,8 @@
//
// ARM version of md5block.go
//go:build !purego
#include "textflag.h"
// Register definitions

View file

@ -5,6 +5,8 @@
// ARM64 version of md5block.go
// derived from crypto/md5/md5block_amd64.s
//go:build !purego
#include "textflag.h"
TEXT ·block(SB),NOSPLIT,$0-32

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build amd64 || 386 || arm || ppc64le || ppc64 || s390x || arm64
//go:build (amd64 || 386 || arm || ppc64le || ppc64 || s390x || arm64) && !purego
package md5

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !amd64 && !386 && !arm && !ppc64le && !ppc64 && !s390x && !arm64
//go:build (!amd64 && !386 && !arm && !ppc64le && !ppc64 && !s390x && !arm64) || purego
package md5

View file

@ -10,7 +10,7 @@
// Licence: I hereby disclaim the copyright on this code and place it
// in the public domain.
//go:build ppc64 || ppc64le
//go:build (ppc64 || ppc64le) && !purego
#include "textflag.h"

View file

@ -10,6 +10,8 @@
// Licence: I hereby disclaim the copyright on this code and place it
// in the public domain.
//go:build !purego
#include "textflag.h"
// func block(dig *digest, p []byte)

67
src/crypto/purego_test.go Normal file
View file

@ -0,0 +1,67 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package crypto_test
import (
"go/build"
"internal/testenv"
"log"
"os"
"os/exec"
"strings"
"testing"
)
// TestPureGoTag checks that when built with the purego build tag, crypto
// packages don't require any assembly. This is used by alternative compilers
// such as TinyGo. See also the "crypto/...:purego" test in cmd/dist, which
// ensures the packages build correctly.
func TestPureGoTag(t *testing.T) {
cmd := exec.Command(testenv.GoToolPath(t), "list", "-e", "crypto/...", "math/big")
cmd.Env = append(cmd.Env, "GOOS=linux")
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
log.Fatalf("loading package list: %v\n%s", err, out)
}
pkgs := strings.Split(strings.TrimSpace(string(out)), "\n")
cmd = exec.Command(testenv.GoToolPath(t), "tool", "dist", "list")
cmd.Stderr = os.Stderr
out, err = cmd.Output()
if err != nil {
log.Fatalf("loading architecture list: %v\n%s", err, out)
}
allGOARCH := make(map[string]bool)
for _, pair := range strings.Split(strings.TrimSpace(string(out)), "\n") {
GOARCH := strings.Split(pair, "/")[1]
allGOARCH[GOARCH] = true
}
for _, pkgName := range pkgs {
if strings.Contains(pkgName, "/boring") {
continue
}
for GOARCH := range allGOARCH {
context := build.Context{
GOOS: "linux", // darwin has custom assembly
GOARCH: GOARCH,
GOROOT: testenv.GOROOT(t),
Compiler: build.Default.Compiler,
BuildTags: []string{"purego", "math_big_pure_go"},
}
pkg, err := context.Import(pkgName, "", 0)
if err != nil {
t.Fatal(err)
}
if len(pkg.SFiles) == 0 {
continue
}
t.Errorf("package %s has purego assembly files on %s: %v", pkgName, GOARCH, pkg.SFiles)
}
}
}

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build s390x
//go:build s390x && !purego
package sha1

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// SHA-1 block routine. See sha1block.go for Go equivalent.

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package sha1
import "internal/cpu"

View file

@ -10,6 +10,7 @@
// Ronen Zohar <ronen.zohar@intel.com>
// Chandramouli Narayanan <mouli@linux.intel.com>
//go:build !purego
#include "textflag.h"

View file

@ -4,6 +4,8 @@
//
// ARM version of md5block.go
//go:build !purego
#include "textflag.h"
// SHA-1 block routine. See sha1block.go for Go equivalent.

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package sha1
import "internal/cpu"

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
#define HASHUPDATECHOOSE \

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build arm || 386 || s390x
//go:build (arm || 386 || s390x) && !purego
package sha1

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !amd64 && !386 && !arm && !s390x && !arm64
//go:build (!amd64 && !386 && !arm && !s390x && !arm64) || purego
package sha1

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package sha1
import "internal/cpu"

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// func block(dig *digest, p []byte)

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build s390x
//go:build s390x && !purego
package sha256

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
// SHA256 block routine. See sha256block.go for Go equivalent.
//
// The algorithm is detailed in FIPS 180-4:

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package sha256
import "internal/cpu"

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// SHA256 block routine. See sha256block.go for Go equivalent.

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package sha256
import "internal/cpu"

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
#define HASHUPDATE \

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build 386 || amd64 || s390x || ppc64le || ppc64
//go:build (386 || amd64 || s390x || ppc64le || ppc64) && !purego
package sha256

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !amd64 && !386 && !s390x && !ppc64le && !ppc64 && !arm64
//go:build (!amd64 && !386 && !s390x && !ppc64le && !ppc64 && !arm64) || purego
package sha256

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ppc64 || ppc64le
//go:build (ppc64 || ppc64le) && !purego
// Based on CRYPTOGAMS code with the following comment:
// # ====================================================================

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package sha256
import "internal/cpu"

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// func block(dig *digest, p []byte)

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build s390x
//go:build s390x && !purego
package sha512

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build amd64
//go:build !purego
package sha512

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// SHA512 block routine. See sha512block.go for Go equivalent.

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package sha512
import "internal/cpu"

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
// Based on the Linux Kernel with the following comment:
// Algorithm based on https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fb87127bcefc17efab757606e1b1e333fd614dd0
// Originally written by Ard Biesheuvel <ard.biesheuvel@linaro.org>

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ppc64le || ppc64 || riscv64 || s390x
//go:build (ppc64le || ppc64 || riscv64 || s390x) && !purego
package sha512

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !amd64 && !arm64 && !ppc64 && !ppc64le && !riscv64 && !s390x
//go:build (!amd64 && !arm64 && !ppc64 && !ppc64le && !riscv64 && !s390x) || purego
package sha512

View file

@ -10,7 +10,7 @@
// # details see http://www.openssl.org/~appro/cryptogams/.
// # ====================================================================
//go:build ppc64 || ppc64le
//go:build (ppc64 || ppc64le) && !purego
#include "textflag.h"

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// SHA512 block routine. See sha512block.go for Go equivalent.

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
package sha512
import "internal/cpu"

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !purego
#include "textflag.h"
// func block(dig *digest, p []byte)