r/RNG • u/Gilgamesch61 • 1d ago
ChaCha20GF512: ChaCha20 + exact 512-wise independence over the Galois field GF(2^64)
I've been working on an experimental PRNG that combines ChaCha20 with a classical k-wise independent construction over a Galois field.
GF stands for Galois field, also called a finite field. In this case GF(2^64) has 2^64 elements that can be represented by 64-bit words; addition in the field is simply XOR. I'll just use GF below.
For 64-bit output position i, the construction is basically
R(i) = ChaCha20(K, i) XOR P(i)
where P is a random degree-511 polynomial over GF(2^64).
With the full 4096-byte GF coefficient seed sampled uniformly, any selection of up to 512 distinct 64-bit output positions is exactly jointly uniform.
There is a fairly sharp contrast with ChaCha20 alone: with a fixed/public stream ID, ChaCha20 has a 256-bit key space, so exact 5-wise independence of 64-bit output words is already information-theoretically impossible. Five 64-bit words have 2^320 possible joint values, while there are only 2^256 keyed ChaCha20 streams.
So the point isn't that the output is somehow "more random than ChaCha20". The idea is to add an exact finite distribution property that ChaCha20 cannot have, while retaining ChaCha20 as the computational pseudorandom component.
The GF part is deliberately algebraic. Beyond 512 output words there are linear relations, and with enough unmasked evaluations the polynomial can be reconstructed. The exact guarantee stops there; beyond that, the construction relies on the usual computational assumption about ChaCha20.
The implementation is C++17. I initially used Horner evaluation, which was far too slow, but the 512 evaluation points have enough structure to use a 9-stage additive FFT. The resulting generator also supports random access and parallel generation of different ranges of the same logical stream.
For example, on a Ryzen 9 5900X with GCC:
ChaCha20: 99.6 M uint64/s
ChaCha20GF512 single: 43.8 M uint64/s
ChaCha20GF512 4 threads: 140.9 M uint64/s
Source, implementation details, benchmarks and the exact claims are here:
https://github.com/tzipproth/ChaCha20GF512
I should also mention that I used AI tools quite extensively during development, for coding assistance, optimization, review and discussing the design. The construction and claims are laid out in the README so they can hopefully be checked independently rather than taken on trust.
I'd be very interested in criticism, especially if I've stated something too strongly, missed an assumption, or overlooked closely related prior work.