https://github.com/kernelmethod/ChaChaCiphers.jl
GPU-compatible implementations of the ChaCha stream cipher family
https://github.com/kernelmethod/ChaChaCiphers.jl
cryptography rng
Last synced: 2 months ago
JSON representation
GPU-compatible implementations of the ChaCha stream cipher family
- Host: GitHub
- URL: https://github.com/kernelmethod/ChaChaCiphers.jl
- Owner: kernelmethod
- License: bsd-2-clause
- Created: 2022-05-08T19:41:57.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-15T08:32:09.000Z (about 2 years ago)
- Last Synced: 2026-02-27T03:58:53.665Z (4 months ago)
- Topics: cryptography, rng
- Language: Julia
- Homepage:
- Size: 156 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-julia-security - ChaChaCiphers.jl - GPU-compatible implementations of the ChaCha stream cipher family. (Cryptography / Symmetric Encryption)
README
# ChaChaCiphers
[](https://kernelmethod.github.io/ChaChaCiphers.jl/stable)
[](https://kernelmethod.github.io/ChaChaCiphers.jl/dev)
[](https://github.com/kernelmethod/ChaChaCiphers.jl/actions/workflows/CI.yml?query=branch%3Amain)
[](https://codecov.io/gh/kernelmethod/ChaChaCiphers.jl)
[ChaChaCiphers](https://github.com/kernelmethod/ChaChaCiphers.jl) is a
CUDA-compatible, pure-Julia implementation of the ChaCha family of stream
ciphers. This package provides:
- fast, cryptographically-secure, and reproducible random number generators
implementing Julia's `AbstractRNG` interface for both CPU and GPU, and
- implementations of ChaCha stream ciphers such as ChaCha20 that can be used as
building blocks for other cryptographic primitives, such as the
ChaCha20-Poly1305 AEAD algorithm.
The default stream cipher provided by this package follows [Daniel Bernstein's
original implementation](https://cr.yp.to/chacha.html) (using a 64-bit counter
and 64-bit nonce), which allows you to generate 1 ZiB of random data before the
nonce must be recycled.
## Installation
You can install ChaChaCiphers.jl with `julia> ] add ChaChaCiphers` in the Julia
REPL, or with `using Pkg; Pkg.add("ChaChaCiphers");`.
## Usage
You can start using ChaChaCiphers.jl for random number generation by creating a
`ChaChaStream` instance:
```julia
julia> using ChaChaCiphers
julia> rng = ChaChaStream();
```
This will create a `ChaChaStream` with a randomly-generated key. Alternatively,
you can specify a key and pass it in to `ChaChaStream` to create a reproducible
random number stream
```julia
julia> key = UInt32.([
0xe2e39848, 0x70bb974d, 0x845f88b4, 0xb30725e4,
0x15c309dc, 0x72d545bb, 0x466e99e3, 0x6a759f91
]);
julia> rng = ChaChaStream(key);
```
You can then pass `rng` into random number generation functions like `rand` or
`randn`:
```julia
julia> rand(rng, UInt8)
0x18
julia> rand(rng, 1:10, 3)
3-element Vector{Int64}:
8
4
3
julia> randn(rng, 3)
3-element Vector{Float64}:
0.4899558093907058
-0.4164526650672216
-0.864497576500388
```