]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go,crypto/internal/fips140: prevent using FIPS 140-3 mode with purego tag
authorFilippo Valsorda <filippo@golang.org>
Thu, 11 Sep 2025 22:19:55 +0000 (00:19 +0200)
committerGopher Robot <gobot@golang.org>
Tue, 16 Sep 2025 00:13:32 +0000 (17:13 -0700)
Change-Id: I6a6a696414f8d5d9dc77c65b0ac9edfc982c2798
Reviewed-on: https://go-review.googlesource.com/c/go/+/703095
Auto-Submit: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/dist/test.go
src/cmd/go/internal/fips140/fips140.go
src/crypto/internal/fips140/fips140.go
src/crypto/internal/fips140/notpurego.go [new file with mode: 0644]
src/crypto/internal/fips140/purego.go [new file with mode: 0644]

index ec4ff649b3815dcf9b4c0d4afe95b323efe9944a..7c26d001bce4e16b877041145d7911f02464800b 100644 (file)
@@ -1823,6 +1823,8 @@ func isEnvSet(evar string) bool {
 func (t *tester) fipsSupported() bool {
        // Keep this in sync with [crypto/internal/fips140.Supported].
 
+       // We don't test with the purego tag, so no need to check it.
+
        // Use GOFIPS140 or GOEXPERIMENT=boringcrypto, but not both.
        if strings.Contains(goexperiment, "boringcrypto") {
                return false
index 7ca0cde5880eeda6faa46774cef092b8d6379a51..4194f0ff6aa99743e256b720d3631d5c581a2289 100644 (file)
@@ -94,6 +94,7 @@ import (
        "os"
        "path"
        "path/filepath"
+       "slices"
        "strings"
 
        "golang.org/x/mod/module"
@@ -121,6 +122,9 @@ func Init() {
        if cfg.ExperimentErr == nil && cfg.Experiment.BoringCrypto && Enabled() {
                base.Fatalf("go: cannot use GOFIPS140 with GOEXPERIMENT=boringcrypto")
        }
+       if slices.Contains(cfg.BuildContext.BuildTags, "purego") && Enabled() {
+               base.Fatalf("go: cannot use GOFIPS140 with the purego build tag")
+       }
 }
 
 var initDone bool
index fd265718e026c5436176e10ef2d67d4d21ea8f51..ca96c88442c6ff0f3001419c15f694cbe8360b46 100644 (file)
@@ -33,6 +33,12 @@ func init() {
 func Supported() error {
        // Keep this in sync with fipsSupported in cmd/dist/test.go.
 
+       // The purego tag changes too much of the implementation to claim the
+       // validation still applies.
+       if puregoEnabled {
+               return errors.New("FIPS 140-3 mode is incompatible with the purego build tag")
+       }
+
        // ASAN disapproves of reading swaths of global memory in fips140/check.
        // One option would be to expose runtime.asanunpoison through
        // crypto/internal/fips140deps and then call it to unpoison the range
diff --git a/src/crypto/internal/fips140/notpurego.go b/src/crypto/internal/fips140/notpurego.go
new file mode 100644 (file)
index 0000000..7d1ec4b
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2025 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.
+
+//go:build !purego
+
+package fips140
+
+const puregoEnabled = false
diff --git a/src/crypto/internal/fips140/purego.go b/src/crypto/internal/fips140/purego.go
new file mode 100644 (file)
index 0000000..335977e
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2025 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.
+
+//go:build purego
+
+package fips140
+
+const puregoEnabled = true