ChaChaCiphers.jl

GPU-compatible implementations of the ChaCha stream cipher family
Author kernelmethod
Popularity
3 Stars
Updated Last
6 Months Ago
Started In
May 2022

ChaChaCiphers

Stable Dev Build Status Coverage

ChaChaCiphers 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 (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> 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> 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> 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

Used By Packages

No packages found.