@@ -28,32 +28,18 @@ DocTestSetup = quote
2828end
2929```
3030
31- To start generating random numbers with ChaChaCiphers , create a new keystream
32- with a function like [ ` ChaCha20Stream ` ] ( @ref ) or [ ` ChaCha12Stream ` ] ( @ref ) :
31+ To start generating random numbers, create a new keystream by constructing a
32+ [ ` ChaChaStream ` ] ( @ref ) instance :
3333
3434``` jldoctest
3535julia> using ChaChaCiphers
3636
37- julia> rng = ChaCha20Stream ();
37+ julia> rng = ChaChaStream ();
3838```
3939
4040This will generate a keystream using a key sampled from the operating system's
41- random stream. Alternatively, you can explicitly specify a ` key ` and ` nonce ` as
42- follows:
43-
44- ``` jldoctest
45- julia> key = UInt32.([
46- 0xe2e39848, 0x70bb974d, 0x845f88b4, 0xb30725e4,
47- 0x15c309dc, 0x72d545bb, 0x466e99e3, 0x6a759f91
48- ]);
49-
50- julia> nonce = UInt64(0);
51-
52- julia> rng = ChaCha20Stream(key, nonce);
53- ```
54-
55- After generating a keystream, you can supply it as the ` rng ` parameter to
56- ` Random ` functions like ` rand ` and ` randn ` :
41+ random stream. You can then supply ` rng ` as a parameter to ` Random ` functions,
42+ like ` rand ` and ` randn ` :
5743
5844``` jldoctest
5945julia> using Random
@@ -70,6 +56,23 @@ julia> randn(rng, Float32, 3)
7056
7157Review the API documentation for more details.
7258
59+ ## Advanced usage
60+
61+ In general, we recommend instantiating ` ChaChaStream ` by simply calling
62+ ` ChaChaStream() ` . However, in some cases you may wish to explicitly supply a key
63+ to construct your stream, which you can do as follows:
64+
65+ ``` jldoctest
66+ julia> key = UInt32.([
67+ 0xe2e39848, 0x70bb974d, 0x845f88b4, 0xb30725e4,
68+ 0x15c309dc, 0x72d545bb, 0x466e99e3, 0x6a759f91
69+ ]);
70+
71+ julia> rng = ChaCha20Stream(key);
72+ ```
73+
74+ In this mode, the key will act as a seed for the random number generator.
75+
7376## About ChaCha
7477
7578ChaCha was first introduced as a variant of the Salsa20 stream cipher by Daniel
0 commit comments