@@ -28,32 +28,18 @@ DocTestSetup = quote
28
28
end
29
29
```
30
30
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 :
33
33
34
34
``` jldoctest
35
35
julia> using ChaChaCiphers
36
36
37
- julia> rng = ChaCha20Stream ();
37
+ julia> rng = ChaChaStream ();
38
38
```
39
39
40
40
This 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 ` :
57
43
58
44
``` jldoctest
59
45
julia> using Random
@@ -70,6 +56,23 @@ julia> randn(rng, Float32, 3)
70
56
71
57
Review the API documentation for more details.
72
58
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
+
73
76
## About ChaCha
74
77
75
78
ChaCha was first introduced as a variant of the Salsa20 stream cipher by Daniel
0 commit comments