mirror of
https://github.com/XTLS/REALITY.git
synced 2025-08-22 14:38:35 +00:00
In the process, replace out-of-module imports with their FIPS versions. For #69536 Change-Id: I83e900b7c38ecf760382e5dca7fd0b1eaa5a5589 Reviewed-on: https://go-review.googlesource.com/c/go/+/626879 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Russ Cox <rsc@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Daniel McCarney <daniel@binaryparadox.net> Reviewed-by: Michael Knyszek <mknyszek@google.com>
26 lines
755 B
Go
26 lines
755 B
Go
// Copyright 2018 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 randutil contains internal randomness utilities for various
|
|
// crypto packages.
|
|
package randutil
|
|
|
|
import (
|
|
"io"
|
|
"math/rand/v2"
|
|
)
|
|
|
|
// MaybeReadByte reads a single byte from r with 50% probability. This is used
|
|
// to ensure that callers do not depend on non-guaranteed behaviour, e.g.
|
|
// assuming that rsa.GenerateKey is deterministic w.r.t. a given random stream.
|
|
//
|
|
// This does not affect tests that pass a stream of fixed bytes as the random
|
|
// source (e.g. a zeroReader).
|
|
func MaybeReadByte(r io.Reader) {
|
|
if rand.Uint64()&1 == 1 {
|
|
return
|
|
}
|
|
var buf [1]byte
|
|
r.Read(buf[:])
|
|
} |