Skip to content

Commit b2f7a21

Browse files
FiloSottilegopherbot
authored andcommitted
crypto/fips140: new package
This package holds only the Enabled() function. Updates #70123 Change-Id: If0e731724d9997001fa52002fa6ae72df4eb16ff Reviewed-on: https://go-review.googlesource.com/c/go/+/631017 Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Daniel McCarney <[email protected]>
1 parent 918765b commit b2f7a21

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

api/next/70123.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pkg crypto/fips140, func Enabled() bool #70123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- FIPS 140 will be covered in its own section. -->

src/crypto/fips140/fips140.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package fips140
6+
7+
import (
8+
"crypto/internal/fips140"
9+
"crypto/internal/fips140/check"
10+
"internal/godebug"
11+
)
12+
13+
var fips140GODEBUG = godebug.New("#fips140")
14+
15+
// Enabled reports whether the cryptography libraries are operating in FIPS
16+
// 140-3 mode.
17+
//
18+
// It can be controlled at runtime using the GODEBUG setting "fips140". If set
19+
// to "on", FIPS 140-3 mode is enabled. If set to "only", non-approved
20+
// cryptography functions will additionally return errors or panic.
21+
//
22+
// This can't be changed after the program has started.
23+
func Enabled() bool {
24+
godebug := fips140GODEBUG.Value()
25+
currentlyEnabled := godebug == "on" || godebug == "only" || godebug == "debug"
26+
if currentlyEnabled != fips140.Enabled {
27+
panic("crypto/fips140: GODEBUG setting changed after program start")
28+
}
29+
if fips140.Enabled && !check.Enabled() {
30+
panic("crypto/fips140: FIPS 140-3 mode enabled, but integrity check didn't pass")
31+
}
32+
return fips140.Enabled
33+
}

src/go/build/deps_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ var depsRules = `
491491
492492
FIPS, sync/atomic < crypto/tls/internal/fips140tls;
493493
494+
FIPS, internal/godebug < crypto/fips140;
495+
494496
NONE < crypto/internal/boring/sig, crypto/internal/boring/syso;
495497
sync/atomic < crypto/internal/boring/bcache, crypto/internal/boring/fips140tls;
496498
crypto/internal/boring/sig, crypto/tls/internal/fips140tls < crypto/tls/fipsonly;

0 commit comments

Comments
 (0)