{"record":{"id":"6ebe350106be2893","repo":"golang/go","slug":"sha-256-hash-of-s-is-s-want-s-from-s","errorCode":null,"errorMessage":"SHA-256 hash of %s is %s, want %s (from %s)","messagePattern":"SHA-256 hash of (.+?) is (.+?), want (.+?) \\(from (.+?)\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/cmd/go/internal/fips140/fips140.go","lineNumber":286,"sourceCode":"\t\tif n == name {\n\t\t\twant = strings.TrimSpace(h)\n\t\t\tbreak\n\t\t}\n\t}\n\tif want == \"\" {\n\t\treturn fmt.Errorf(\"no SHA-256 hash for %s in %s\", name, sumfile)\n\t}\n\tf, err := os.Open(zipfile)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\th := sha256.New()\n\tif _, err := io.Copy(h, f); err != nil {\n\t\treturn err\n\t}\n\tif got := fmt.Sprintf(\"%x\", h.Sum(nil)); got != want {\n\t\treturn fmt.Errorf(\"SHA-256 hash of %s is %s, want %s (from %s)\", name, got, want, sumfile)\n\t}\n\treturn nil\n}\n\n// ResolveImport resolves the import path imp.\n// If it is of the form crypto/internal/fips140/foo\n// (not crypto/internal/fips140/v1.2.3/foo)\n// and we are using a snapshot, then LookupImport\n// rewrites the path to crypto/internal/fips140/v1.2.3/foo\n// and returns that path and its location in the unpacked\n// FIPS snapshot.\nfunc ResolveImport(imp string) (newPath, dir string, ok bool) {\n\tcheckInit()\n\tconst fips = \"crypto/internal/fips140\"\n\tif !Snapshot() || !str.HasPathPrefix(imp, fips) {\n\t\treturn \"\", \"\", false\n\t}\n\tfipsv := path.Join(fips, version)","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/fips140/fips140.go#L268-L304","documentation":"Returned by verifyZipSum when the FIPS 140 snapshot zip's actual SHA-256 hash does not equal the hash recorded for its basename in GOROOT/lib/fips140/fips140.sum. The mismatch indicates corruption, a partial download, or tampering — verification intentionally refuses to proceed.","triggerScenarios":"Any of: the zip in the module cache is truncated/corrupted; the zip was replaced with a different file; the fips140.sum file was edited and now disagrees with the zip; a partially-written download.","commonSituations":"Interrupted downloads leaving a truncated zip; cache corruption on disk; manual edits to fips140.sum; copying zips between machines with different snapshots.","solutions":["Clean the module cache entry for the FIPS snapshot (`go clean -modcache` for the affected module) and let the go command re-fetch/re-unpack.","Reinstall/upgrade the Go toolchain to restore a pristine GOROOT/lib/fips140/fips140.sum and bundled snapshots.","If the sum file was edited, restore it from the toolchain distribution.","Verify disk health if corruption recurs — intermittent bit-rot produces the same symptom."],"exampleFix":"# before — corrupted cache zip\n$ GOFIPS140=v1.2.3 go build ./...\nerror: SHA-256 hash of fips140-v1.2.3.zip is <got>, want <want>\n# after — purge and rebuild\n$ go clean -modcache && GOFIPS140=v1.2.3 go build ./...","handlingStrategy":"try-catch","validationCode":"// Pre-verify the snapshot zip's SHA-256 against the recorded hash to give\n// a clear, actionable message before the go command fails.\nfunc preVerify(zipfile, sumfile string) error {\n    want, err := recordedHash(sumfile, filepath.Base(zipfile))\n    if err != nil { return err }\n    f, err := os.Open(zipfile)\n    if err != nil { return err }\n    defer f.Close()\n    h := sha256.New()\n    if _, err := io.Copy(h, f); err != nil { return err }\n    if fmt.Sprintf(\"%x\", h.Sum(nil)) != want {\n        return fmt.Errorf(\"snapshot %s corrupted — run `go clean -modcache`\", zipfile)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Treat integrity failures as recoverable by clearing the cache and retrying once.\nerr = runBuild()\nif isHashMismatch(err) {\n    _ = runGo(\"clean\", \"-modcache\")\n    err = runBuild()\n}\nif err != nil { return err }","preventionTips":["Run `go clean -modcache` after interrupted downloads.","Keep toolchain distributions pristine — do not edit bundled files.","Monitor disks for bit-rot when caches are long-lived."],"tags":["security","fips140","verification","integrity","tampering","go-command"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}