go.internal.chacha8rand 1.23.1.3

dotnet add package go.internal.chacha8rand --version 1.23.1.3
                    
NuGet\Install-Package go.internal.chacha8rand -Version 1.23.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="go.internal.chacha8rand" Version="1.23.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="go.internal.chacha8rand" Version="1.23.1.3" />
                    
Directory.Packages.props
<PackageReference Include="go.internal.chacha8rand" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add go.internal.chacha8rand --version 1.23.1.3
                    
#r "nuget: go.internal.chacha8rand, 1.23.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package go.internal.chacha8rand@1.23.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=go.internal.chacha8rand&version=1.23.1.3
                    
Install as a Cake Addin
#tool nuget:?package=go.internal.chacha8rand&version=1.23.1.3
                    
Install as a Cake Tool

go.internal.chacha8rand

C# package converted from the Go standard library by go2cs. Go version: 1.23.1

Tests

Package chacha8rand implements a pseudorandom generator based on ChaCha8. It is used by both runtime and math/rand/v2 and must have minimal dependencies.

ChaCha8 is ChaCha with 8 rounds. See https://cr.yp.to/chacha/chacha-20080128.pdf.

ChaCha8 operates on a 4x4 matrix of uint32 values, initially set to:

const1 const2 const3 const4
seed   seed   seed   seed
seed   seed   seed   seed
counter64     0      0

We use the same constants as ChaCha20 does, a random seed, and a counter. Running ChaCha8 on this input produces a 4x4 matrix of pseudo-random values with as much entropy as the seed.

Given SIMD registers that can hold N uint32s, it is possible to run N ChaCha8 block transformations in parallel by filling the first register with the N copies of const1, the second with N copies of const2, and so on, and then running the operations.

Each iteration of ChaCha8Rand operates over 32 bytes of input and produces 992 bytes of RNG output, plus 32 bytes of input for the next iteration.

The 32 bytes of input are used as a ChaCha8 key, with a zero nonce, to produce 1024 bytes of output (16 blocks, with counters 0 to 15). First, for each block, the values 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 are subtracted from the 32-bit little-endian words at position 0, 1, 2, and 3 respectively, and an increasing counter starting at zero is subtracted from each word at position 12. Then, this stream is permuted such that for each sequence of four blocks, first we output the first four bytes of each block, then the next four bytes of each block, and so on. Finally, the last 32 bytes of output are used as the input of the next iteration, and the remaining 992 bytes are the RNG output.

See https://c2sp.org/chacha8rand for additional details.

Normal ChaCha20 implementations for encryption use this same parallelism but then have to deinterlace the results so that it appears the blocks were generated separately. For the purposes of generating random numbers, the interlacing is fine. We are simply locked in to preserving the 4-way interlacing in any future optimizations.


Part of the go2cs converted Go standard library. See the repository for usage and details.

Copyright 2009 The Go Authors. All rights reserved. This C# package is converted from Go standard library source; use of that source is governed by a BSD-style license that can be found in the LICENSE file. The go2cs conversion itself is distributed under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on go.internal.chacha8rand:

Package Downloads
go.runtime

runtime (net9.0 - Release) -- C# project converted from Go source

go.math.rand.v2

math.rand.v2 (net9.0 - Release) -- C# project converted from Go source

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.23.1.3 1,529 8/4/2026
1.23.1.2 3,541 7/27/2026
1.23.1.1 3,527 7/14/2026