]> Cypherpunks repositories - gostls13.git/commitdiff
crypto: use and test purego tag consistently
authorFilippo Valsorda <filippo@golang.org>
Tue, 6 Feb 2024 12:32:39 +0000 (13:32 +0100)
committerGopher Robot <gobot@golang.org>
Mon, 4 Mar 2024 17:29:44 +0000 (17:29 +0000)
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>

81 files changed:
src/cmd/dist/test.go
src/crypto/aes/aes_gcm.go
src/crypto/aes/asm_amd64.s
src/crypto/aes/asm_arm64.s
src/crypto/aes/asm_ppc64x.s
src/crypto/aes/asm_s390x.s
src/crypto/aes/cbc_ppc64x.go
src/crypto/aes/cbc_s390x.go
src/crypto/aes/cipher_asm.go
src/crypto/aes/cipher_generic.go
src/crypto/aes/cipher_s390x.go
src/crypto/aes/ctr_s390x.go
src/crypto/aes/gcm_amd64.s
src/crypto/aes/gcm_arm64.s
src/crypto/aes/gcm_ppc64x.go
src/crypto/aes/gcm_ppc64x.s
src/crypto/aes/gcm_s390x.go
src/crypto/ecdsa/ecdsa_noasm.go
src/crypto/ecdsa/ecdsa_s390x.go
src/crypto/ecdsa/ecdsa_s390x.s
src/crypto/ecdsa/ecdsa_s390x_test.go
src/crypto/internal/edwards25519/field/_asm/fe_amd64_asm.go
src/crypto/internal/edwards25519/field/fe_amd64.go
src/crypto/internal/edwards25519/field/fe_amd64.s
src/crypto/internal/edwards25519/field/fe_amd64_noasm.go
src/crypto/internal/edwards25519/field/fe_arm64.go
src/crypto/internal/edwards25519/field/fe_arm64.s
src/crypto/internal/edwards25519/field/fe_arm64_noasm.go
src/crypto/internal/nistec/generate.go
src/crypto/internal/nistec/p256.go
src/crypto/internal/nistec/p256_asm.go
src/crypto/internal/nistec/p256_asm_amd64.s
src/crypto/internal/nistec/p256_asm_arm64.s
src/crypto/internal/nistec/p256_asm_ppc64le.s
src/crypto/internal/nistec/p256_asm_s390x.s
src/crypto/internal/nistec/p256_asm_table_test.go
src/crypto/internal/nistec/p256_ordinv.go
src/crypto/internal/nistec/p256_ordinv_noasm.go
src/crypto/internal/nistec/p256_ordinv_test.go
src/crypto/md5/md5block_386.s
src/crypto/md5/md5block_amd64.s
src/crypto/md5/md5block_arm.s
src/crypto/md5/md5block_arm64.s
src/crypto/md5/md5block_decl.go
src/crypto/md5/md5block_generic.go
src/crypto/md5/md5block_ppc64x.s
src/crypto/md5/md5block_s390x.s
src/crypto/purego_test.go [new file with mode: 0644]
src/crypto/sha1/fallback_test.go
src/crypto/sha1/sha1block_386.s
src/crypto/sha1/sha1block_amd64.go
src/crypto/sha1/sha1block_amd64.s
src/crypto/sha1/sha1block_arm.s
src/crypto/sha1/sha1block_arm64.go
src/crypto/sha1/sha1block_arm64.s
src/crypto/sha1/sha1block_decl.go
src/crypto/sha1/sha1block_generic.go
src/crypto/sha1/sha1block_s390x.go
src/crypto/sha1/sha1block_s390x.s
src/crypto/sha256/fallback_test.go
src/crypto/sha256/sha256block_386.s
src/crypto/sha256/sha256block_amd64.go
src/crypto/sha256/sha256block_amd64.s
src/crypto/sha256/sha256block_arm64.go
src/crypto/sha256/sha256block_arm64.s
src/crypto/sha256/sha256block_decl.go
src/crypto/sha256/sha256block_generic.go
src/crypto/sha256/sha256block_ppc64x.s
src/crypto/sha256/sha256block_s390x.go
src/crypto/sha256/sha256block_s390x.s
src/crypto/sha512/fallback_test.go
src/crypto/sha512/sha512block_amd64.go
src/crypto/sha512/sha512block_amd64.s
src/crypto/sha512/sha512block_arm64.go
src/crypto/sha512/sha512block_arm64.s
src/crypto/sha512/sha512block_decl.go
src/crypto/sha512/sha512block_generic.go
src/crypto/sha512/sha512block_ppc64x.s
src/crypto/sha512/sha512block_riscv64.s
src/crypto/sha512/sha512block_s390x.go
src/crypto/sha512/sha512block_s390x.s

index 80a134becdf8796be9d95c5c6b646916d37d548f..aed59db9d5608094f63135f68e411afd1b2968a0 100644 (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",
index 036705fecaac6e102dc76362c6fbf7d5ce3f92c1..b95796970c86ad589fa04f564d457a7dff56f36d 100644 (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
 
index ed831bf47ff2a9d41c9bdf98750e341e16c7fd82..d5e17401ea0ef65a9cdc0c525931e996d1fbec3d 100644 (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)
index 4a02e943ce3168591b63497218f48b0664a7a793..2bf5bee2b59fb2eff53fa4327d1151a6ac0f3b86 100644 (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
index 288f7256c7c5bf4b1113470e87ee313193855fad..859cffa3eef233fff20f4a43c5e1d31e97847852 100644 (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:
 // # ====================================================================
index a233714fb8e3b50c7e69ce8ffd52ae19c94958d3..5da0d8bf9cb3f13f381d23c7bfb8cbf0f80476f5 100644 (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)
index c23c37156e517909e87b9b3fbe41d13248283ef2..2cb9606e5864b4281249f2f27b42e5775d5c8093 100644 (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
 
index eaa21f8a65f2ccab64434597f4775eb907f96eca..09c19ff394793a0a520cd109672816f8b1403fe2 100644 (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 (
index 90031c5e2c58e6b0ef43060c45423ad948252bba..5451fa60d38677bedf2342671ba14b356b139eb1 100644 (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
 
index 8a8a3fff384400c4c17191cd7527fba6da503ac1..7c7d89aa873d0d3305e5d8b434a5007881e2cfe2 100644 (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
 
index 8dd3d8f0537fd3b86229449168204a473a4ea4f8..1541890deab7fa2ccffdf587333935640dd0d255 100644 (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 (
index 921421533a4490ec772d5c24ca4bca163f578a5b..e5249d1842216bd4d3f7823482b9e0cc68b87108 100644 (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 (
index e6eedf326400a59b5fb491767a77ce2696d08b3f..f787e6fd6bbe94216dc282669b071f674e735db9 100644 (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
index c3501024c9f932deef458378c812de1c08cd00d4..23ce1890e4e5d0224b4a5f872047c48e3d3d7727 100644 (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
index 2a7f898dc4be422fbaa4b797892d58aba3bbf83f..04fac72459cbe253bf8f8833e0688dccc69a2bff 100644 (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
 
index f661b2764279c9215d114fab6d4293e1c877161a..987f4e718e124ce9524bc0fed7b90e64d3446347 100644 (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:
 // # ====================================================================
index cf0e28af695bdae7359fa504004199fad052de7c..01504e1815a0314c5db353172e5b1273679aa89a 100644 (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 (
index a72aa4b04ef52f5fe87dee2d3f89ce22750e3cd7..e2fa8082f68d4c802609d0036dfdaebfabb6effb 100644 (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
 
index 49f645a4892761a304a59d4af0b707b5d9750dc4..8ebf15a525fbfdbbd16176b9fe10306ae5783e71 100644 (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 (
index ea1f4469e9918ca7d730344073caaa0ed2f2754b..2aae59c291d15cb31c8f283d368f8eb991a8b8ff 100644 (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)
index fd1dc7c0605a5d94cf0aff5e632cc82f95c35f4f..ba8f810fab0e864491ae4bf0e3d2c96080162e45 100644 (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
 
index 411399cb1e83d392f8030915cb30d3d90bad2ef1..6765a688f455ec91f634944638ff496a497e0cc0 100644 (file)
@@ -17,7 +17,7 @@ import (
 
 func main() {
        Package("crypto/internal/edwards25519/field")
-       ConstraintExpr("amd64,gc,!purego")
+       ConstraintExpr("!purego")
        feMul()
        feSquare()
        Generate()
index 70c541692c3a3ab6bc88c726e53e18cd7e55aaba..00bf8f4479225b29048dec9f1d899c242f6bfef9 100644 (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
 
index 60817acc4131a0958030224e2c88e7ea1a559591..657851c85ed199c61f77fefd022291f39377bbb7 100644 (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"
 
index 9da280d1d887d01790b1a4c936a77b9eaefa20e7..4b81f25d1d0f5336d8c4af79fe6e7b2c063d9740 100644 (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
 
index 075fe9b925742e031a45f7f398fbe3ffea18d3e0..05c7cedd4e9c74cd6adfae38302cab3e283b78d9 100644 (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
 
index 3126a434191c0c638a4b1b5181b8a0ce6700f671..ae207dae43e8fc743b5428be227e2e3f4b2dbb10 100644 (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"
 
index fc029ac12dae057c74925b3e5336c0367b73f831..6b9e06a6e8266c458df4cd8ee102ce67e750e2aa 100644 (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
 
index 0e84cefb3657dcf83e431a152d9d074a1973d871..27e8d13943b2430f19135937a82b908c4bdad91b 100644 (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",
index 3cfa5fb37179c68661fbb3356710ceec3d9792ef..f2dfbbb1ee9b43cd92621804aca3c51e487e92f8 100644 (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
 
index 99a22b833f028c846e07191573530aa6efaa4eb4..1a523cc13c14495bd55aca9c94ac4c7df90a4df2 100644 (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
 
index 84e4cee9039ccc5fb8da1c487c47099739a9557a..f5c008319bd7f0251f457e9e43b35240cb3d4adf 100644 (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
index 1ba5df381b3a96c0afb14fbb1e5fd5e148463d96..d00a54db1adc417c872780f3d841c42686604165 100644 (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
index 6b787609b9994e4a5b12b48de3e93e9e829ec7ab..1475dfb1d90e4b3d48018a33cb4bb8bbc70f4e15 100644 (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.
index 8da4f3f5b89d08d4dd7b8a6ac034995c9ce4d10e..77c9f63349a047e31d8e1804ed0cb453d98af34b 100644 (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"
 
index 5b7246ba1274becdf96bb511ed96c943f4a78e6e..cba455d32db965dc2a61cd2bcb1aafaa1b818c40 100644 (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
 
index 1274fb7fd3f5ccf55113fae7905c5f8d8a36ed3f..156a873188c3aeb66e8646855c6d6f708d88c9d5 100644 (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
 
index 213875ce76165c58e7b27df7f7ecde8201e134a2..9cbb1a89dbaf1867fa62f4e5f9657fd18109713e 100644 (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
 
index 72de6bd487d06e59cae4b2af21206f45539b35f0..ca323a3ae294f9d5f53a039292a2d03719958e32 100644 (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
 
index 30d4209a62407f15a4c2c08352d44a6f8ad09ee2..b6c6509d3b529c6a11f0820193518bcd4919d4ad 100644 (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.
index 75c8074b37ebb4679339f1b9190bf4f12f26fb81..652506ae27fbc18d89e70948aefbe0c74bfe316d 100644 (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.
index 54d02b743a6a2b293b2e5de72d9cc0aedadc4291..13fdc5c3beb515717ef97d6a5ed28f5a516a05cc 100644 (file)
@@ -4,6 +4,8 @@
 //
 // ARM version of md5block.go
 
+//go:build !purego
+
 #include "textflag.h"
 
 // Register definitions
index 39b9851d1fe1c24aefc6e523a85af600170a82cc..5942218f76fb928798df5c43f7a4ec2b1c45e016 100644 (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
index f1fb34c3d7fb85e56399c8a19879bf3f0f8f2c99..3664542fb92048bdd1b344051837b660418d6c76 100644 (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
 
index c929c2b84aca519cece6c9508c792b52ee60030c..43cfebd38a9094f01b39c80b324c010b7827c114 100644 (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
 
index 69a20e7cad3399abf864bf13dcaf976897657ab0..f607040d02e664abee31e60748407d95ed7900a7 100644 (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"
 
index 68f501cfea83d34fa033deb5a66c03d0b7a43d11..2d18d28f2514d5996e869ad98dd332ef3cbd89d0 100644 (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)
diff --git a/src/crypto/purego_test.go b/src/crypto/purego_test.go
new file mode 100644 (file)
index 0000000..62be347
--- /dev/null
@@ -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)
+               }
+       }
+}
index aa1d413f2f063f31a72e079fbd3c094e3f3f0b76..b869a939f601fb9528dfbcf385fdf3ff88fd0fee 100644 (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
 
index 34d023d424c0ff30e58b462a9161f8f5c73a9c73..33d3f1e9973fd39985b21fd4d1326145f5f828e5 100644 (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.
index 039813d7dc3fea7cc224a28fbc6e71c10efc02a7..92fa7a6fbc0d1401461755ddc84dfd1a5d0b136b 100644 (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"
index 9bdf24cf49f24e5b9b59fe3e1920ca50a6e3ee3a..6508612d890099180c1645503e0317f14b17c118 100644 (file)
@@ -10,6 +10,7 @@
 // Ronen Zohar <ronen.zohar@intel.com>
 // Chandramouli Narayanan <mouli@linux.intel.com>
 
+//go:build !purego
 
 #include "textflag.h"
 
index 2236533ab4d9ef19a589c9624e5961ef3de2982a..209b1d89ae349af8791b4e8c0abbc7e799116fbf 100644 (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.
index 08d3df0000e686157952b2ffe20b2e3e87432a4f..e6d96a9080a8c56044df96d42df60b4da19702e1 100644 (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"
index d56838464ddba30ac75cd0844e3721aa61d5d097..d0ff0986b8b5abc97903aa737943b62fb3eb9df6 100644 (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 \
index 8e20401c14c406b55f01ed6657b47ebbec0f7fbb..3edf5a43606d417e55b100f3b7aae7d410006fd5 100644 (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
 
index ba35155d0b92ef4d4c801f8dea8d70d5ec36775d..4c6f74d99d8f23eb273530277a3dd880a15448d9 100644 (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
 
index 446bf5d36e5943a74dd9430abe1d5c35f79796f0..f8b0d8ba31007bb9aec40548f4ad06b1b2b70321 100644 (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"
index 0fb7aef28371fcd38feb70443a8877610a7ab7fa..7a2f4e39c4013ffd872ba15d64bd44a7f2b51a62 100644 (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)
index 3f561aadd65ee62154795788d5aed97d165372ac..ceef3cc9222fcd7cfe9d085c0fc095dc5c2c52b6 100644 (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
 
index 086a0ab25c88c68bcd819b9a68cccd51663a911e..0e27fa02d7e708cb9ba3ac4a8cf20e32fd39ffd0 100644 (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:
index b5d2c9b574a2a4451aa96425ee6a8f8269b6cdad..fdd75a3f3e7e048bb4dc69a1bb7b1e5633c5e2ce 100644 (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"
index bbde6285d1789ee3fa3ce05276bdae4dd8d266c8..2559f659a200770c6f53928cb94c97411bed44fe 100644 (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.
index e5da5663631556e8cc36c2adb024c406705d40d4..434b6f253d41c96ca60307f9c4b9c862971f6ce3 100644 (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"
index d5c1eb0b2e15ac92045fb80e973f9bb7b5dac19f..6757310c34e34c4bfc57cbe3913856bbb9755f45 100644 (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 \
index 7d68cd95fe440fb5834ae649e89879bb302368af..85374cbdbb59bbd6037819706c98009be33828de 100644 (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
 
index fd098bec894be5215b803627d39861984765391f..2964255f99cc55b1feb3a8a5d09f535eaf15ec11 100644 (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
 
index b229ef619a35bcb729967492c31ed4c27b506a1e..ba8fa623c11f020d289396b50de6baa75db7ce30 100644 (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:
 // # ====================================================================
index 1a376c5f93531897c5b2f5c9a65855e16b5e3356..0a1dc5785d2e447d02010d2639403d0680c31c8b 100644 (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"
index 9c30136b31ef51e7730e7dccfae9928322c37d3d..757d62f5125aa1c3717f0e38dfa9dbe230e9f4c5 100644 (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)
index ac0c2c3c76f712d38637444c557669f578513f59..b55a4a56fa9d03a379f058640632299fdfef6a29 100644 (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
 
index 8da3e1473f6c45289a690dd6af8783c85d63beab..fd1baecb32d83a8b3138a0b2a9231cd83f690ff3 100644 (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
 
index 0fa0df2f60e8b733f1875d754643e60945a2a876..bd4e3e6669f8861aa26cc7aeff210ea5a14783a5 100644 (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.
index 243eb5c1d63b6f085bd484992858003f58fdff01..4e2793100a3199062f8421d68735208b48e1d1f8 100644 (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"
index dfc35d69c3880256163f02971ef9ecf8050735cb..25f3dbfe43d5e617d5e7cbba6158f259831d3d95 100644 (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>
index d5d03d0f3c01536400169d3944b9f2ac66a4e676..324659e62ca28981f16bbe4bbfd3fe198fd75998 100644 (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
 
index f11c0980bd60e95732c92389c0020170ee49ca12..9177722be12b00fbd042b445bd9fa8d9373de61f 100644 (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
 
index 90dbf0f02b64bf7593edbab2e1e805fd11005870..87aab80903c9b8beb7a9f4a4debbf69cd011d06b 100644 (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"
 
index 361aafe49d75bbb8ed26ea083ff99d1aedbd42c8..6fbd524a31deec0f7ef07f51302ec662fa8d2d47 100644 (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.
index 7df29fd29828c4461a4709e3fe9d8daba677f65d..d0f09ea9edb07289b653c53ad89dcadf8b722e10 100644 (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"
index 9fdf3439007ae039cf6c30da42422e010b9ba79b..230bd414d38bd07703cf8a0d357df50930066f8b 100644 (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)