From c96a5ebe1338b5497af5248712261859dec648c6 Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Fri, 27 Mar 2026 20:42:53 +0800 Subject: [PATCH] crypto/rand: return correct count on hardware RNG read error When machine.GetRNG fails mid-read, return the number of bytes already written (i) instead of n, which is still zero at that point. --- src/crypto/rand/rand_baremetal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/rand/rand_baremetal.go b/src/crypto/rand/rand_baremetal.go index 5711f23eb0..a8ff1dc8e7 100644 --- a/src/crypto/rand/rand_baremetal.go +++ b/src/crypto/rand/rand_baremetal.go @@ -26,7 +26,7 @@ func (r *reader) Read(b []byte) (n int, err error) { if i%4 == 0 { randomByte, err = machine.GetRNG() if err != nil { - return n, err + return i, err } } else { randomByte >>= 8