From 07c7eff3c37d46ac86808df5839dc6d76df67ee5 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 18 Feb 2025 14:19:46 +0100 Subject: [PATCH] runtime: add FIPS helper functions Not entirely sure what they're for, but the Go runtime also stores this information per goroutine so let's go with that. --- src/internal/task/task.go | 3 +++ src/runtime/panic.go | 5 +++++ src/runtime/scheduler.go | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/internal/task/task.go b/src/internal/task/task.go index 546f5ba11..58c02fe84 100644 --- a/src/internal/task/task.go +++ b/src/internal/task/task.go @@ -21,6 +21,9 @@ type Task struct { // state is the underlying running state of the task. state state + // This is needed for some crypto packages. + FipsIndicator uint8 + // DeferFrame stores a pointer to the (stack allocated) defer frame of the // goroutine that is used for the recover builtin. DeferFrame unsafe.Pointer diff --git a/src/runtime/panic.go b/src/runtime/panic.go index ec33a4469..9ae1f982b 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -226,3 +226,8 @@ func divideByZeroPanic() { func blockingPanic() { runtimePanicAt(returnAddress(0), "trying to do blocking operation in exported function") } + +//go:linkname fips_fatal crypto/internal/fips140.fatal +func fips_fatal(msg string) { + runtimePanic(msg) +} diff --git a/src/runtime/scheduler.go b/src/runtime/scheduler.go index 727c7f5f2..40740da31 100644 --- a/src/runtime/scheduler.go +++ b/src/runtime/scheduler.go @@ -31,3 +31,14 @@ func scheduleLogChan(msg string, ch *channel, t *task.Task) { func Goexit() { panicOrGoexit(nil, panicGoexit) } + +//go:linkname fips_getIndicator crypto/internal/fips140.getIndicator +func fips_getIndicator() uint8 { + return task.Current().FipsIndicator +} + +//go:linkname fips_setIndicator crypto/internal/fips140.setIndicator +func fips_setIndicator(indicator uint8) { + // This indicator is stored per goroutine. + task.Current().FipsIndicator = indicator +}