go/api/next
Filippo Valsorda 2b8dbb35b0 crypto,testing/cryptotest: ignore random io.Reader params, add SetGlobalRandom
First, we centralize all random bytes generation through drbg.Read. The
rest of the FIPS 140-3 module can't use external functions anyway, so
drbg.Read needs to have all the logic.

Then, make sure that the crypto/... tree uses drbg.Read (or the new
crypto/internal/rand.Reader wrapper) instead of crypto/rand, so it is
unaffected by applications setting crypto/rand.Reader.

Next, pass all unspecified random io.Reader parameters through the new
crypto/internal/rand.CustomReader, which just redirects to drbg.Read
unless GODEBUG=cryptocustomrand=1 is set. Move all the calls to
MaybeReadByte there, since it's only needed for these custom Readers.

Finally, add testing/cryptotest.SetGlobalRandom which sets
crypto/rand.Reader to a locked deterministic source and overrides
drbg.Read. This way SetGlobalRandom should affect all cryptographic
randomness in the standard library.

Fixes #70942

Co-authored-by: qiulaidongfeng <2645477756@qq.com>
Change-Id: I6a6a69641311d9fac318abcc6d79677f0e406100
Reviewed-on: https://go-review.googlesource.com/c/go/+/724480
Reviewed-by: Nicholas Husin <nsh@golang.org>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-26 16:01:17 -08:00
..
49097.txt net: context aware Dialer.Dial functions 2025-08-11 14:26:10 -07:00
51945.txt errors: add AsType 2025-09-30 10:22:08 -07:00
56866.txt crypto/x509: add ExtKeyUsage.String and KeyUsage.String methods 2025-11-24 16:19:47 -08:00
61642.txt net/netip: export Prefix.Compare, fix ordering 2025-09-03 15:10:15 -07:00
63963.txt crypto/ecdsa: deprecate direct use of big.Int fields in keys 2025-09-09 12:20:39 -07:00
65716.txt crypto/rsa: add EncryptOAEPWithOptions 2025-11-25 08:22:22 -08:00
65954.txt log/slog: add multiple handlers support for logger 2025-09-04 11:07:44 -07:00
66631.txt reflect: add iterator equivalents for NumField, NumIn, NumOut and NumMethod 2025-11-25 09:18:42 -08:00
67546.txt database/sql: allow drivers to override Scan behavior 2025-08-11 14:27:36 -07:00
67813.txt net/http: add HTTP2Config.StrictMaxConcurrentRequests 2025-09-26 16:14:14 -07:00
68021.txt go/ast: add ParseDirective for parsing directive comments 2025-10-21 14:49:10 -07:00
70352.txt os: add (*Process).WithHandle 2025-09-15 12:17:42 -07:00
70942.txt crypto,testing/cryptotest: ignore random io.Reader params, add SetGlobalRandom 2025-11-26 16:01:17 -08:00
71206.txt crypto/tls: add SecP256r1/SecP384r1MLKEM1024 hybrid post-quantum key exchanges 2025-11-25 17:25:00 -08:00
71287.txt cmd/go, testing: add TB.ArtifactDir and -artifacts flag 2025-10-07 14:39:32 -07:00
73161.txt net/http/httputil: deprecate ReverseProxy.Director 2025-10-02 12:53:31 -07:00
73627.txt crypto/mlkem/mlkemtest: add derandomized Encapsulate768/1024 2025-11-17 09:54:06 -08:00
73794.txt bytes: add Buffer.Peek 2025-11-03 09:39:00 -08:00
74425.txt crypto/tls: expose HelloRetryRequest state 2025-11-25 07:40:46 -08:00
74630.txt crypto/fips140: add WithoutEnforcement 2025-11-26 14:26:06 -08:00
75108.txt crypto/tls: add QUICErrorEvent 2025-11-20 15:39:14 -08:00
75300.txt crypto/hpke: expose crypto/internal/hpke 2025-11-25 10:35:07 -08:00
75301.txt crypto/fips140: add Version 2025-11-24 23:09:27 -08:00
75302.txt crypto/rsa: deprecate PKCS#1 v1.5 encryption 2025-11-15 15:41:23 -08:00
75325.txt crypto/x509: add ExtKeyUsage.OID method 2025-11-26 14:21:13 -08:00
75562.txt debug/elf: sync new loong64 relocation types up to LoongArch ELF psABI v20250521 2025-11-17 17:00:42 -08:00
75772.txt net/http: add Transport.NewClientConn 2025-11-24 17:26:36 -08:00
75849.txt go/token: add (*File).End method 2025-11-17 09:47:47 -08:00
76031.txt go/ast: fix BasicLit.End position for raw strings containing \r 2025-11-17 10:52:48 -08:00