From 7f70ca872677bb1b2a9c2cbdcbf632f6c9b9069e Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Thu, 4 Sep 2025 22:19:18 -0400 Subject: [PATCH] crypto/internal/cryptotest: add MustSupportFIPS140 Change-Id: Iccb3ffdb7c1e15f8f0d889fdc4a27e62870cd58e Reviewed-on: https://go-review.googlesource.com/c/go/+/702776 LUCI-TryBot-Result: Go LUCI Reviewed-by: Daniel McCarney Reviewed-by: Mark Freeman Auto-Submit: Filippo Valsorda Reviewed-by: Michael Knyszek --- src/crypto/internal/cryptotest/fips140.go | 17 +++++++++++++++++ src/crypto/internal/fips140test/check_test.go | 14 ++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 src/crypto/internal/cryptotest/fips140.go diff --git a/src/crypto/internal/cryptotest/fips140.go b/src/crypto/internal/cryptotest/fips140.go new file mode 100644 index 0000000000..c24622ce5a --- /dev/null +++ b/src/crypto/internal/cryptotest/fips140.go @@ -0,0 +1,17 @@ +// 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. + +package cryptotest + +import ( + "crypto/internal/fips140" + "testing" +) + +func MustSupportFIPS140(t *testing.T) { + t.Helper() + if err := fips140.Supported(); err != nil { + t.Skipf("test requires FIPS 140 mode: %v", err) + } +} diff --git a/src/crypto/internal/fips140test/check_test.go b/src/crypto/internal/fips140test/check_test.go index c4f6a95e3e..2ceef6dd88 100644 --- a/src/crypto/internal/fips140test/check_test.go +++ b/src/crypto/internal/fips140test/check_test.go @@ -6,7 +6,7 @@ package fipstest import ( "bytes" - "crypto/internal/fips140" + "crypto/internal/cryptotest" . "crypto/internal/fips140/check" "crypto/internal/fips140/check/checktest" "fmt" @@ -31,9 +31,7 @@ func TestIntegrityCheck(t *testing.T) { t.Fatalf("GODEBUG=fips140=on but verification did not run") } - if err := fips140.Supported(); err != nil { - t.Skipf("skipping: %v", err) - } + cryptotest.MustSupportFIPS140(t) cmd := testenv.Command(t, testenv.Executable(t), "-test.v", "-test.run=^TestIntegrityCheck$") cmd.Env = append(cmd.Environ(), "GODEBUG=fips140=on") @@ -47,9 +45,7 @@ func TestIntegrityCheck(t *testing.T) { func TestIntegrityCheckFailure(t *testing.T) { moduleStatus(t) testenv.MustHaveExec(t) - if err := fips140.Supported(); err != nil { - t.Skipf("skipping: %v", err) - } + cryptotest.MustSupportFIPS140(t) bin, err := os.ReadFile(os.Args[0]) if err != nil { @@ -90,9 +86,7 @@ func TestIntegrityCheckFailure(t *testing.T) { } func TestIntegrityCheckInfo(t *testing.T) { - if err := fips140.Supported(); err != nil { - t.Skipf("skipping: %v", err) - } + cryptotest.MustSupportFIPS140(t) // Check that the checktest symbols are initialized properly. if checktest.NOPTRDATA != 1 { -- 2.52.0