diff --git a/loader/goroot.go b/loader/goroot.go index 12b797627..df4ae40cf 100644 --- a/loader/goroot.go +++ b/loader/goroot.go @@ -268,6 +268,16 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool { paths["crypto/internal/boring/sig/"] = false } + if goMinor >= 26 { + // Go 1.26 added a CPU jitter entropy source for FIPS 140-3 that + // allocates a 32 MiB global buffer (ScratchBuffer [1<<25]byte). + // This is fine on systems with virtual memory, but causes RAM + // overflow on microcontrollers. Replace with a zero-size stub + // since TinyGo targets never use FIPS jitter entropy. + paths["crypto/internal/entropy/"] = true + paths["crypto/internal/entropy/v1.0.0/"] = false + } + if needsSyscallPackage { paths["syscall/"] = true // include syscall/js paths["internal/syscall/"] = true diff --git a/src/crypto/internal/entropy/v1.0.0/entropy.go b/src/crypto/internal/entropy/v1.0.0/entropy.go new file mode 100644 index 000000000..eeeaf2158 --- /dev/null +++ b/src/crypto/internal/entropy/v1.0.0/entropy.go @@ -0,0 +1,56 @@ +// 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. + +// Stripped-down version of the entropy package for TinyGo. +// +// The upstream Go 1.26 package allocates a [1<<25]byte (32 MiB) global buffer +// for CPU jitter-based SP 800-90B entropy collection. This is fine on systems +// with virtual memory where BSS pages are lazily backed, but it causes a fatal +// "RAM overflowed" error on microcontrollers and other memory-constrained +// targets. +// +// Because FIPS 140-3 jitter entropy is never used on TinyGo targets (the DRBG +// falls through to sysrand.Read when fips140.Enabled is false), this overlay +// replaces the 32 MiB buffer with a zero-size type. +package entropy + +// Version returns the version of the entropy source. +func Version() string { + return "v1.0.0" +} + +// ScratchBuffer is a large buffer in upstream Go (32 MiB). TinyGo replaces it +// with a zero-size type since the CPU jitter entropy source is not used. +type ScratchBuffer [0]byte + +// Seed returns a 384-bit seed with full entropy. +// On TinyGo targets this is never called because FIPS mode is not enabled. +func Seed(memory *ScratchBuffer) ([48]byte, error) { + panic("entropy: CPU jitter entropy source is not supported on TinyGo targets") +} + +// Samples collects entropy samples. Not supported on TinyGo targets. +func Samples(samples []uint8, memory *ScratchBuffer) error { + panic("entropy: CPU jitter entropy source is not supported on TinyGo targets") +} + +// SHA384 computes SHA-384 over 1024 bytes. Not supported on TinyGo targets. +func SHA384(p *[1024]byte) [48]byte { + panic("entropy: CPU jitter entropy source is not supported on TinyGo targets") +} + +// TestingOnlySHA384 computes SHA-384 over arbitrary bytes. Not supported on TinyGo targets. +func TestingOnlySHA384(p []byte) [48]byte { + panic("entropy: CPU jitter entropy source is not supported on TinyGo targets") +} + +// RepetitionCountTest implements the repetition count test from SP 800-90B. +func RepetitionCountTest(samples []uint8) error { + panic("entropy: CPU jitter entropy source is not supported on TinyGo targets") +} + +// AdaptiveProportionTest implements the adaptive proportion test from SP 800-90B. +func AdaptiveProportionTest(samples []uint8) error { + panic("entropy: CPU jitter entropy source is not supported on TinyGo targets") +}