Source File
chacha8.go
Belonging Package
math/rand/v2
// Copyright 2023 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 rand
import
// A ChaCha8 is a ChaCha8-based cryptographically strong
// random number generator.
type ChaCha8 struct {
state chacha8rand.State
}
// NewChaCha8 returns a new ChaCha8 seeded with the given seed.
func ( [32]byte) *ChaCha8 {
:= new(ChaCha8)
.state.Init()
return
}
// Seed resets the ChaCha8 to behave the same way as NewChaCha8(seed).
func ( *ChaCha8) ( [32]byte) {
.state.Init()
}
// Uint64 returns a uniformly distributed random uint64 value.
func ( *ChaCha8) () uint64 {
for {
, := .state.Next()
if {
return
}
.state.Refill()
}
}
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func ( *ChaCha8) ( []byte) error {
return chacha8rand.Unmarshal(&.state, )
}
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func ( *ChaCha8) () ([]byte, error) {
return chacha8rand.Marshal(&.state), nil
}
The pages are generated with Golds v0.6.9-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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |