})
}
+ // 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",
// 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
// 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)
// 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
// 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:
// # ====================================================================
// 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)
// 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
// 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 (
// 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
// 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
// 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 (
// 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 (
// 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
// 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
// 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
// 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:
// # ====================================================================
// 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 (
// 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
// 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 (
// 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)
// 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
func main() {
Package("crypto/internal/edwards25519/field")
- ConstraintExpr("amd64,gc,!purego")
+ ConstraintExpr("!purego")
feMul()
feSquare()
Generate()
// 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
// 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"
// 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
// 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
// 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"
// 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
P: "P256",
Element: "fiat.P256Element",
Params: elliptic.P256().Params(),
- BuildTags: "!amd64 && !arm64 && !ppc64le && !s390x",
+ BuildTags: "(!amd64 && !arm64 && !ppc64le && !s390x) || purego",
},
{
P: "P384",
// Code generated by generate.go. DO NOT EDIT.
-//go:build !amd64 && !arm64 && !ppc64le && !s390x
+//go:build (!amd64 && !arm64 && !ppc64le && !s390x) || purego
package nistec
// 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
// 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
// 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
// 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.
// 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"
// 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
// 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
// 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
// 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
// #defines generating 8a assembly, and adjusted for 386,
// by the Go Authors.
+//go:build !purego
+
#include "textflag.h"
// MD5 optimized for AMD64.
// 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.
//
// ARM version of md5block.go
+//go:build !purego
+
#include "textflag.h"
// Register definitions
// ARM64 version of md5block.go
// derived from crypto/md5/md5block_amd64.s
+//go:build !purego
+
#include "textflag.h"
TEXT ·block(SB),NOSPLIT,$0-32
// 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
// 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
// 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"
// 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)
--- /dev/null
+// 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)
+ }
+ }
+}
// 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
// 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.
// 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"
// Ronen Zohar <ronen.zohar@intel.com>
// Chandramouli Narayanan <mouli@linux.intel.com>
+//go:build !purego
#include "textflag.h"
//
// ARM version of md5block.go
+//go:build !purego
+
#include "textflag.h"
// SHA-1 block routine. See sha1block.go for Go equivalent.
// 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"
// 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 \
// 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
// 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
// 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"
// 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)
// 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
// 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:
// 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"
// 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.
// 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"
// 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 \
// 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
// 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
// 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:
// # ====================================================================
// 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"
// 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)
// 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
// 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
// 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.
// 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"
// 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>
// 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
// 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
// # details see http://www.openssl.org/~appro/cryptogams/.
// # ====================================================================
-//go:build ppc64 || ppc64le
+//go:build (ppc64 || ppc64le) && !purego
#include "textflag.h"
// 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.
// 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"
// 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)