| 1 |
// Copyright 2025 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build goexperiment.runtimesecret && (arm64 || amd64) |
| 6 |
|
| 7 |
// testing stubs, these are implemented in assembly in |
| 8 |
// asm_$GOARCH.s |
| 9 |
// |
| 10 |
// Note that this file is also used as a template to build a |
| 11 |
// crashing binary that tries to leave secrets in places where |
| 12 |
// they are supposed to be erased. see crash_test.go for more info |
| 13 |
|
| 14 |
package secret |
| 15 |
|
| 16 |
import "unsafe" |
| 17 |
|
| 18 |
// Load data from p into test registers. |
| 19 |
// |
| 20 |
//go:noescape |
| 21 |
func loadRegisters(p unsafe.Pointer) |
| 22 |
|
| 23 |
// Spill data from test registers into p. |
| 24 |
// Returns the amount of space filled in. |
| 25 |
// |
| 26 |
//go:noescape |
| 27 |
func spillRegisters(p unsafe.Pointer) uintptr |
| 28 |
|
| 29 |
// Load secret into all registers. |
| 30 |
// |
| 31 |
//go:noescape |
| 32 |
func useSecret(secret []byte) |
| 33 |
|
| 34 |
// callback from assembly |
| 35 |
func delay() { |
| 36 |
sleep(1_000_000) |
| 37 |
} |
| 38 |
|
| 39 |
// linknamed to avoid package importing time |
| 40 |
// for just testing code |
| 41 |
// |
| 42 |
//go:linkname sleep time.Sleep |
| 43 |
func sleep(int64) |