ChaCha is a CSPRING, a cryptographically secure pseudorandom number generator. When used in cryptography, ChaCha typically carries out 20 rounds of its internal scrambling process. Google’s Adiantum encryption system uses ChaCha with 12 rounds.
The runtime for ChaCha is proportional to the number of rounds, so you don’t want to do more rounds than necessary if you’re concerned with speed. Adiantum was developed for mobile devices and so Google wanted to reduce the number of rounds while maintaining a margin of cryptographic safety.
Cryptographer Jean-Philippe Aumasson suggests 8 rounds of ChaCha is plenty. He reports that there is a known attack on ChaCha with 6 rounds that requires on the order of 2116 operations, but that ChaCha with 5 rounds is definitely breakable, requiring on the order of only 216 operations.
Three rounds of ChaCha are not enough , but four rounds are enough to satisfy DIEHARDER, PractRand, and TestU01 . This illustrates the gap between adequate statistical quality and adequate cryptographic quality: Four rounds of ChaCha are apparently enough to produce the former but five rounds are not enough to produce the latter.
There doesn’t seem to be any reason to use ChaCha with four rounds. If you don’t need cryptographic security, then there are faster RNGs you could use. If you do need security, four rounds are not enough.
ChaCha with six rounds seems like a good compromise if you want an RNG that is fast enough for general use and that that also has reasonably good cryptographic quality. If you want more safety margin for cryptographic quality, you might want to go up to eight rounds.
What a difference one round makes
One thing I find interesting about random number generation and block encryption is that a single round of obfuscation can make a huge difference. ChaCha(3) fails statistical tests but ChaCha(4) is fine. ChaCha(5) is easily broken but ChaCha(6) is not.
Often random number generators are either good or bad; they pass the standard test suites or they clearly fail. ChaCha(3) is interesting in that it is somewhere in between. As the results in the footnotes show, ChaCha(3) is an intermediate case. DIEHARDER hints at problems, but small crush thinks everything is fine. The full crush battery however does find problems.
The decisive failure of the Fourier tests is understandable: low-quality generators often fail spectral tests. But the results of the simple poker test are harder to understand. What is it about simulating poker that makes ChaCha(3) fail spectacularly? And in both cases, one more round of ChaCha fixes the problems.
 ChaCha(3) passes DIEHARDER, though five of the tests passed with a “weak” pass. Passes TestU01 small crush but fails full crush:
========= Summary results of Crush ========= Version: TestU01 1.2.3 Generator: 32-bit stdin Number of statistics: 144 Total CPU time: 00:39:05.05 The following tests gave p-values outside [0.001, 0.9990]: (eps means a value < 1.0e-300): (eps1 means a value < 1.0e-15): Test p-value ---------------------------------------------- 25 SimpPoker, d = 64 eps 26 SimpPoker, d = 64 eps 27 CouponCollector, d = 4 7.7e-4 28 CouponCollector, d = 4 7.4e-4 29 CouponCollector, d = 16 eps 33 Gap, r = 0 2.7e-8 51 WeightDistrib, r = 0 eps 52 WeightDistrib, r = 8 5.2e-15 53 WeightDistrib, r = 16 2.1e-5 55 SumCollector eps 69 RandomWalk1 H (L = 10000) 1.1e-4 74 Fourier3, r = 0 1.3e-144 75 Fourier3, r = 20 6.9e-44 80 HammingWeight2, r = 0 2.8e-6 83 HammingCorr, L = 300 3.2e-10 84 HammingCorr, L = 1200 6.1e-13 ---------------------------------------------- All other tests were passed
ChaCha(3) also fails PractRand decisively.
RNG_test using PractRand version 0.94 RNG = chacha(3), seed = 0x7221236f test set = core, folding = standard (32 bit) rng=chacha(3), seed=0x7221236f length= 128 megabytes (2^27 bytes), time= 2.0 seconds Test Name Raw Processed Evaluation [Low1/32]BCFN(2+0,13-6,T) R= +31.0 p = 4.7e-11 VERY SUSPICIOUS [Low1/32]BCFN(2+1,13-6,T) R= +27.4 p = 8.3e-10 VERY SUSPICIOUS [Low1/32]BCFN(2+2,13-6,T) R= +52.7 p = 1.8e-18 FAIL ! [Low1/32]BCFN(2+3,13-6,T) R= +47.6 p = 9.5e-17 FAIL ! [Low1/32]BCFN(2+4,13-7,T) R= +26.1 p = 1.7e-8 very suspicious [Low1/32]DC6-9x1Bytes-1 R= +26.3 p = 1.3e-14 FAIL ! [Low1/32]FPF-14+6/16:all R= +8.6 p = 2.2e-7 very suspicious ...and 147 test result(s) without anomalies
 ChaCha(4) passed TestU01 small crush and full crush. It passed PractRand using up to 512 GB.
2 thoughts on “ChaCha RNG with fewer rounds”
Honestly surprised that 3 rounds of ChaCha does not pass PractRand, considering the much simpler/faster SFC64 and JSF64 don’t even do multiple rounds and yet pass PractRand.
zikey, if I recall correctly, AES also fails PractRand’s BCFN tests with such a small number of rounds. A version of AES using a 16×16 MDS matrix (which provides full diffusion every round) might stand a chance of passing with three rounds. Because of the design constraints for Salsa/ChaCha, they’re unable to diffuse very quickly, so it fails these tests despite the fact that it has 512 bits of state. Even an LCG with 128 bits of state passes tests that 3 rounds of ChaCha doesn’t. However, if you tried to encrypt a data stream with such an LCG, it’s going to be broken significantly quicker than 3 rounds of ChaCha.