|
4 | 4 | [](https://kernelmethod.github.io/ChaChaCiphers.jl/dev)
|
5 | 5 | [](https://github.com/kernelmethod/ChaChaCiphers.jl/actions/workflows/CI.yml?query=branch%3Amain)
|
6 | 6 | [](https://codecov.io/gh/kernelmethod/ChaChaCiphers.jl)
|
| 7 | + |
| 8 | +`ChaChaCiphers` is a Julia package that provides a CUDA-compatible |
| 9 | +implementation of the ChaCha stream cipher family, and implements the |
| 10 | +`Random.AbstractDevice` interface to use ChaCha for cryptographically secure |
| 11 | +random number generation (CRNG). |
| 12 | + |
| 13 | +This package seeks to accomplish the following goals: |
| 14 | + |
| 15 | +- Provide performant and reproducible CRNG for CPU and GPU computations |
| 16 | +- Implement basic cryptographic primitives that can be used as a building block |
| 17 | + in higher-level cryptographic code (e.g. for building ChaCha20-Poly1305). |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +You can start using ChaChaCiphers.jl for random number generation by creating a |
| 22 | +`ChaChaStream` instance: |
| 23 | + |
| 24 | +```julia |
| 25 | +julia> using ChaChaCiphers |
| 26 | + |
| 27 | +julia> rng = ChaChaStream(); |
| 28 | +``` |
| 29 | + |
| 30 | +This will create a `ChaChaStream` with a randomly-generated key. Alternatively, |
| 31 | +you can specify a key and pass it in to `ChaChaStream` to create a reproducible |
| 32 | +random number stream |
| 33 | + |
| 34 | +```julia |
| 35 | +julia> key = UInt32.([ |
| 36 | + 0xe2e39848, 0x70bb974d, 0x845f88b4, 0xb30725e4, |
| 37 | + 0x15c309dc, 0x72d545bb, 0x466e99e3, 0x6a759f91 |
| 38 | + ]); |
| 39 | + |
| 40 | +julia> rng = ChaChaStream(key); |
| 41 | +``` |
| 42 | + |
| 43 | +You can then pass `rng` into random number generation functions like `rand` or |
| 44 | +`randn`: |
| 45 | + |
| 46 | +```julia |
| 47 | +julia> rand(rng, UInt8) |
| 48 | +0x18 |
| 49 | + |
| 50 | +julia> rand(rng, 1:10, 3) |
| 51 | +3-element Vector{Int64}: |
| 52 | + 8 |
| 53 | + 4 |
| 54 | + 3 |
| 55 | + |
| 56 | +julia> randn(rng, 3) |
| 57 | +3-element Vector{Float64}: |
| 58 | + 0.4899558093907058 |
| 59 | + -0.4164526650672216 |
| 60 | + -0.864497576500388 |
| 61 | +``` |
| 62 | + |
0 commit comments