Source File
rand.go
Belonging Package
crypto/internal/rand
// Copyright 2025 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package randimport (_)type reader struct {drbg.DefaultReader}func ( reader) ( []byte) ( int, error) {if boring.Enabled {if , := boring.RandReader.Read(); != nil {panic("crypto/rand: boring RandReader failed: " + .Error())}return len(), nil}drbg.Read()return len(), nil}// Reader is an io.Reader that calls [drbg.Read].//// It should be used internally instead of [crypto/rand.Reader], because the// latter can be set by applications outside of tests. These applications then// risk breaking between Go releases, if the way the Reader is used changes.var Reader io.Reader = reader{}// SetTestingReader overrides all calls to [drbg.Read]. The Read method of// r must never return an error or return short.//// SetTestingReader panics when building against Go Cryptographic Module v1.0.0.//// SetTestingReader is pulled by [testing/cryptotest.setGlobalRandom] via go:linkname.////go:linkname SetTestingReader crypto/internal/rand.SetTestingReaderfunc ( io.Reader) {fips140SetTestingReader()}var cryptocustomrand = godebug.New("cryptocustomrand")// CustomReader returns [Reader] or, only if the GODEBUG setting// "cryptocustomrand=1" is set, the provided io.Reader.//// If returning a non-default Reader, it calls [randutil.MaybeReadByte] on it.func ( io.Reader) io.Reader {if cryptocustomrand.Value() == "1" {if !IsDefaultReader() {randutil.MaybeReadByte()cryptocustomrand.IncNonDefault()}return}return Reader}// IsDefaultReader reports whether r is the default [crypto/rand.Reader].//// If true, the Read method of r can be assumed to call [drbg.Read].func ( io.Reader) bool {, := .(drbg.DefaultReader)return}
![]() |
The pages are generated with Golds v0.8.3-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |