diff options
| author | Russ Cox <rsc@golang.org> | 2024-11-20 09:03:35 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-11-20 20:28:34 +0000 |
| commit | 4a3cef2036097d323b6cc0bbe90fc4d8c7588660 (patch) | |
| tree | 781c49601ff4013959343f2b1fa13d1a4147c9f3 /src/cmd/internal | |
| parent | 5254e989425648ff62faa270948bb927b6568ff3 (diff) | |
| download | go-4a3cef2036097d323b6cc0bbe90fc4d8c7588660.tar.xz | |
all: rename crypto/internal/fips to crypto/internal/fips140
Sometimes we've used the 140 suffix (GOFIPS140, crypto/fips140)
and sometimes not (crypto/internal/fips, cmd/go/internal/fips).
Use it always, to avoid having to remember which is which.
Also, there are other FIPS standards, like AES (FIPS 197), SHA-2 (FIPS 180),
and so on, which have nothing to do with FIPS 140. Best to be clear.
For #70123.
Change-Id: I33b29dabd9e8b2703d2af25e428f88bc81c7c307
Reviewed-on: https://go-review.googlesource.com/c/go/+/630115
Reviewed-by: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Diffstat (limited to 'src/cmd/internal')
| -rw-r--r-- | src/cmd/internal/obj/fips140.go (renamed from src/cmd/internal/obj/fips.go) | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/cmd/internal/obj/fips.go b/src/cmd/internal/obj/fips140.go index 978028f70a..326301aa87 100644 --- a/src/cmd/internal/obj/fips.go +++ b/src/cmd/internal/obj/fips140.go @@ -26,14 +26,14 @@ restrict those to the actual cryptographic packages. Since we're not hashing the whole binary, we need to record the parts of the binary that contain FIPS code, specifically the part of the -binary corresponding to the crypto/internal/fips package subtree. +binary corresponding to the crypto/internal/fips140 package subtree. To do that, we create special symbol types STEXTFIPS, SRODATAFIPS, SNOPTRDATAFIPS, and SDATAFIPS, which those packages use instead of STEXT, SRODATA, SNOPTRDATA, and SDATA. The linker groups symbols by their type, so that naturally makes the FIPS parts contiguous within a given type. The linker then writes out in a special symbol the start and end of each of these FIPS-specific sections, alongside the -expected HMAC-SHA256 of them. At startup, the crypto/internal/fips/check +expected HMAC-SHA256 of them. At startup, the crypto/internal/fips140/check package has an init function that recomputes the hash and checks it against the recorded expectation. @@ -74,11 +74,11 @@ A similar issue happens with: The compiler invents an anonymous array and then treats the code as in the first example. In both cases, a load-time relocation applied -before the crypto/internal/fips/check init function would invalidate +before the crypto/internal/fips140/check init function would invalidate the hash. Instead, we disable the “link time initialization” optimizations in the compiler (package staticinit) for the fips packages. That way, the slice initialization is deferred to its own init function. -As long as the package in question imports crypto/internal/fips/check, +As long as the package in question imports crypto/internal/fips140/check, the hash check will happen before the package's own init function runs, and so the hash check will see the slice header written by the linker, with a slice base pointer predictably nil instead of the @@ -95,11 +95,11 @@ for every new relocation in a symbol in a FIPS package (as reported by The cryptographic code+data must be included in the hash-verified data. In general we accomplish that by putting all symbols from -crypto/internal/fips/... packages into the hash-verified data. +crypto/internal/fips140/... packages into the hash-verified data. But not all. Note that wrapper code that layers a Go API atop the cryptographic -core is unverified. For example, crypto/internal/fips/sha256 is part of +core is unverified. For example, crypto/internal/fips140/sha256 is part of the FIPS module and verified but the crypto/sha256 package that wraps it is outside the module and unverified. Also, runtime support like the implementation of malloc and garbage collection is outside the @@ -146,7 +146,7 @@ import ( const enableFIPS = true -// IsFIPS reports whether we are compiling one of the crypto/internal/fips/... packages. +// IsFIPS reports whether we are compiling one of the crypto/internal/fips140/... packages. func (ctxt *Link) IsFIPS() bool { if strings.HasSuffix(ctxt.Pkgpath, "_test") { // External test packages are outside the FIPS hash scope. @@ -154,7 +154,7 @@ func (ctxt *Link) IsFIPS() bool { // emit absolute relocations in the global data. return false } - return ctxt.Pkgpath == "crypto/internal/fips" || strings.HasPrefix(ctxt.Pkgpath, "crypto/internal/fips/") + return ctxt.Pkgpath == "crypto/internal/fips140" || strings.HasPrefix(ctxt.Pkgpath, "crypto/internal/fips140/") } // bisectFIPS controls bisect-based debugging of FIPS symbol assignment. @@ -191,7 +191,7 @@ func EnableFIPS() bool { // It should instead pass -shared to the compiler to get true // position-independent code, at which point FIPS verification // would work fine. FIPS verification does work fine on -buildmode=exe, - // but -buildmode=pie is the default, so crypto/internal/fips/check + // but -buildmode=pie is the default, so crypto/internal/fips140/check // would fail during all.bash if we enabled FIPS here. // Perhaps the default should be changed back to -buildmode=exe, // after which we could remove this case, but until then, @@ -221,11 +221,11 @@ func (s *LSym) setFIPSType(ctxt *Link) { return } - // Name must begin with crypto/internal/fips, then dot or slash. + // Name must begin with crypto/internal/fips140, then dot or slash. // The quick check for 'c' before the string compare is probably overkill, // but this function is called a fair amount, and we don't want to // slow down all the non-FIPS compilations. - const prefix = "crypto/internal/fips" + const prefix = "crypto/internal/fips140" name := s.Name if len(name) <= len(prefix) || (name[len(prefix)] != '.' && name[len(prefix)] != '/') || name[0] != 'c' || name[:len(prefix)] != prefix { return @@ -239,7 +239,7 @@ func (s *LSym) setFIPSType(ctxt *Link) { // Now we're at least handling a FIPS symbol. // It's okay to be slower now, since this code only runs when compiling a few packages. - // Even in the crypto/internal/fips packages, + // Even in the crypto/internal/fips140 packages, // we exclude various Go runtime metadata, // so that it can be allowed to contain data relocations. if strings.Contains(name, ".init") || @@ -257,7 +257,7 @@ func (s *LSym) setFIPSType(ctxt *Link) { // This symbol is linknamed to go:fipsinfo, // so we shouldn't see it, but skip it just in case. - if s.Name == "crypto/internal/fips/check.linkinfo" { + if s.Name == "crypto/internal/fips140/check.linkinfo" { return } @@ -289,7 +289,7 @@ func (s *LSym) setFIPSType(ctxt *Link) { // checkFIPSReloc should be called for every relocation applied to s. // It rejects absolute (non-PC-relative) address relocations when building // with go build -buildmode=pie (which triggers the compiler's -shared flag), -// because those relocations will be applied before crypto/internal/fips/check +// because those relocations will be applied before crypto/internal/fips140/check // can hash-verify the FIPS code+data, which will make the verification fail. func (s *LSym) checkFIPSReloc(ctxt *Link, rel Reloc) { if !ctxt.Flag_shared { |
