runtime: use rand_hwrng hardwareRand for RP2040/RP2350 (#5135)

* runtime: use rand_hwrng hardwareRand for RP2040/RP2350

* add a comment

* insert 'implementations'
This commit is contained in:
MakKi (makki_d)
2025-12-19 04:52:12 +09:00
committed by GitHub
parent 8d9c9a16e3
commit f7fd5cf2d8
2 changed files with 6 additions and 21 deletions
+6 -1
View File
@@ -1,7 +1,12 @@
//go:build baremetal && (nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey || (tinygo.riscv32 && virt))
//go:build baremetal && (nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey || (tinygo.riscv32 && virt) || rp2040 || rp2350)
// If you update the above build constraint, you'll probably also need to update
// src/crypto/rand/rand_baremetal.go.
//
// The rp2040 and rp2350 implementations are not included in src/crypto/rand/rand_baremetal.go
// due to not being sufficiently random for the Go crypto libs.
// However since the randomness here does not provide those same guarantees,
// they are included in the list for hardwareRand() implementations.
package runtime
-20
View File
@@ -1,20 +0,0 @@
//go:build rp2040 || rp2350
package runtime
import "machine"
var hardwareRandValue uint64
func hardwareRand() (n uint64, ok bool) {
if hardwareRandValue == 0 {
n1, _ := machine.GetRNG()
n2, _ := machine.GetRNG()
hardwareRandValue = uint64(n1)<<32 | uint64(n2)
}
// Return ok=false to keep using fastrand64(),
// with hardwareRandVal used only as its initial random state.
return hardwareRandValue, false
}