Skip to content

Commit 8539691

Browse files
FiloSottilegopherbot
authored andcommitted
crypto/internal/fips140/entropy: move to crypto/internal/entropy/v1.0.0
The lab confirmed the that entropy source doesn't have to be inside the module boundary, although changing the entropy source of a module does require recertification. Move the v1.0.0 entropy source out of crypto/internal/fips140, to a versioned path that lets us keep multiple versions (which would be used by different modules) if we wish to. Change-Id: I6a6a69647e9dfca1c375650a0869bdc001d65173 Reviewed-on: https://go-review.googlesource.com/c/go/+/710057 Reviewed-by: Daniel McCarney <daniel@binaryparadox.net> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
1 parent 99cf4d6 commit 8539691

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

src/crypto/internal/entropy/entropy.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
// Package entropy provides the passive entropy source for the FIPS 140-3
66
// module. It is only used in FIPS mode by [crypto/internal/fips140/drbg.Read]
7-
// from the FIPS 140-3 Go Cryptographic Module v1.0.0. Later versions of the
8-
// module have an internal CPU jitter-based entropy source.
7+
// from the FIPS 140-3 Go Cryptographic Module v1.0.0.
8+
//
9+
// Later versions of the module use the CPU jitter-based entropy source in the
10+
// crypto/internal/entropy/v1.0.0 sub-package.
911
//
1012
// This complied with IG 9.3.A, Additional Comment 12, which until January 1,
1113
// 2026 allows new modules to meet an [earlier version] of Resolution 2(b):

src/crypto/internal/fips140/drbg/rand.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
package drbg
1010

1111
import (
12+
entropy "crypto/internal/entropy/v1.0.0"
1213
"crypto/internal/fips140"
13-
"crypto/internal/fips140/entropy"
1414
"crypto/internal/randutil"
1515
"crypto/internal/sysrand"
1616
"io"

src/crypto/internal/fips140deps/fipsdeps_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import (
1616
//
1717
// DO NOT add new packages here just to make the tests pass.
1818
var AllowedInternalPackages = map[string]bool{
19-
// entropy.Depleted is the external passive entropy source, and sysrand.Read
19+
// entropy.Depleted/Seed is the entropy source, and sysrand.Read
2020
// is the actual (but uncredited!) random bytes source.
21-
"crypto/internal/entropy": true,
22-
"crypto/internal/sysrand": true,
21+
"crypto/internal/entropy": true,
22+
"crypto/internal/entropy/v1.0.0": true,
23+
"crypto/internal/sysrand": true,
2324

2425
// impl.Register is how the packages expose their alternative
2526
// implementations to tests outside the module.
@@ -88,8 +89,7 @@ func TestImports(t *testing.T) {
8889
}
8990
}
9091

91-
// Ensure that all packages except check, check's dependencies, and the
92-
// entropy source (which is used only from .../fips140/drbg) import check.
92+
// Ensure that all packages except check and check's dependencies import check.
9393
for pkg := range allPackages {
9494
switch pkg {
9595
case "crypto/internal/fips140/check":
@@ -100,7 +100,6 @@ func TestImports(t *testing.T) {
100100
case "crypto/internal/fips140/sha3":
101101
case "crypto/internal/fips140/sha256":
102102
case "crypto/internal/fips140/sha512":
103-
case "crypto/internal/fips140/entropy":
104103
default:
105104
if !importCheck[pkg] {
106105
t.Errorf("package %s does not import crypto/internal/fips140/check", pkg)

src/crypto/internal/fips140test/entropy_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ package fipstest
99
import (
1010
"bytes"
1111
"crypto/internal/cryptotest"
12+
entropy "crypto/internal/entropy/v1.0.0"
1213
"crypto/internal/fips140/drbg"
13-
"crypto/internal/fips140/entropy"
1414
"crypto/rand"
1515
"crypto/sha256"
1616
"crypto/sha512"
@@ -217,7 +217,7 @@ func TestEntropyUnchanged(t *testing.T) {
217217
testenv.MustHaveSource(t)
218218

219219
h := sha256.New()
220-
root := os.DirFS("../fips140/entropy")
220+
root := os.DirFS("../entropy/v1.0.0")
221221
if err := fs.WalkDir(root, ".", func(path string, d fs.DirEntry, err error) error {
222222
if err != nil {
223223
return err
@@ -237,13 +237,13 @@ func TestEntropyUnchanged(t *testing.T) {
237237
t.Fatalf("WalkDir: %v", err)
238238
}
239239

240-
// The crypto/internal/fips140/entropy package is certified as a FIPS 140-3
240+
// The crypto/internal/entropy/v1.0.0 package is certified as a FIPS 140-3
241241
// entropy source through the Entropy Source Validation program,
242242
// independently of the FIPS 140-3 module. It must not change even across
243243
// FIPS 140-3 module versions, in order to reuse the ESV certificate.
244244
exp := "2541273241ae8aafe55026328354ed3799df1e2fb308b2097833203a42911b53"
245245
if got := hex.EncodeToString(h.Sum(nil)); got != exp {
246-
t.Errorf("hash of crypto/internal/fips140/entropy = %s, want %s", got, exp)
246+
t.Errorf("hash of crypto/internal/entropy/v1.0.0 = %s, want %s", got, exp)
247247
}
248248
}
249249

src/go/build/deps_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,13 @@ var depsRules = `
490490
time, internal/syscall/windows < crypto/internal/fips140deps/time;
491491
492492
crypto/internal/fips140deps/time, errors, math/bits, sync/atomic, unsafe
493-
< crypto/internal/fips140/entropy;
493+
< crypto/internal/entropy/v1.0.0;
494494
495495
STR, hash,
496496
crypto/internal/impl,
497497
crypto/internal/entropy,
498498
crypto/internal/randutil,
499-
crypto/internal/fips140/entropy,
499+
crypto/internal/entropy/v1.0.0,
500500
crypto/internal/fips140deps/byteorder,
501501
crypto/internal/fips140deps/cpu,
502502
crypto/internal/fips140deps/godebug

0 commit comments

Comments
 (0)