nebulae.dotChaCha20
0.1.8
See the version list below for details.
dotnet add package nebulae.dotChaCha20 --version 0.1.8
NuGet\Install-Package nebulae.dotChaCha20 -Version 0.1.8
<PackageReference Include="nebulae.dotChaCha20" Version="0.1.8" />
<PackageVersion Include="nebulae.dotChaCha20" Version="0.1.8" />
<PackageReference Include="nebulae.dotChaCha20" />
paket add nebulae.dotChaCha20 --version 0.1.8
#r "nuget: nebulae.dotChaCha20, 0.1.8"
#:package nebulae.dotChaCha20@0.1.8
#addin nuget:?package=nebulae.dotChaCha20&version=0.1.8
#tool nuget:?package=nebulae.dotChaCha20&version=0.1.8
dotChaCha20
A minimal, fast, cross-platform ChaCha20 wrapper for .NET applications.
This library provides access to the ChaCha20 stream cipher, which is known for its speed and security. It is designed to be easy to use and integrates seamlessly with .NET applications. Binaries are provided for Windows x64, Linux x64 and macOS (x64 & Apple Silicon).
The underlying optimized implementation is taken verbatim from BoringSSL maintained by Google, ensuring that it is both efficient and secure.
Tests are included and available in the Github repo.
Features
- Cross-platform: Works on Windows, Linux, and macOS (x64 & Apple Silicon).
- High performance: Optimized for speed, leveraging AVX2 on x64 & neon on Apple Silicon.
- Easy to use: Simple API for encryption and decryption.
- Secure: Based on the ChaCha20 cipher, which is widely recognized for its security.
- Minimal dependencies: No external dependencies required (all are included), making it lightweight and easy to integrate.
Requirements
- .NET 8.0 or later
- Advanced SIMD capable CPU (AVX2 support for x64 on any OS or neon on Apple Silicon M-Series)
- Windows x64, Linux x64, or macOS (x64 / M-series arm64)
Usage
For those that are unaware, ChaCha20 is a stream ciper that is used for encrypting data in a way that is both fast and secure. It operates on 64-byte blocks and uses a 256-bit key. The encrypt function called with the key & nonce will encrypt the plaintext (the message), and re-running the encrypt function with the same key & nonce on the encrypted message will yield the original plaintext.
using System;
using nebulae.dotChaCha20;
public class Example
{
public static void Main()
{
// Be sure to call Init() to load the native library
ChaCha20.Init();
// ------------------------
// Example 1: byte[] API
// ------------------------
byte[] key1 = new byte[32];
byte[] nonce1 = new byte[12];
byte[] plaintext1 = new byte[32];
new Random(1).NextBytes(plaintext1); // fill with random data
byte[] ciphertext1 = new byte[32];
byte[] decrypted1 = new byte[32];
ChaCha20.Encrypt(key1, nonce1, counter: 1, plaintext1, ciphertext1);
ChaCha20.Encrypt(key1, nonce1, counter: 1, ciphertext1, decrypted1);
Console.WriteLine("Byte[] round-trip success: " + plaintext1.AsSpan().SequenceEqual(decrypted1));
// ------------------------------
// Example 2: Span<byte> API
// ------------------------------
Span<byte> key2 = stackalloc byte[32];
Span<byte> nonce2 = stackalloc byte[12];
Span<byte> plaintext2 = stackalloc byte[32];
Span<byte> ciphertext2 = stackalloc byte[32];
Span<byte> decrypted2 = stackalloc byte[32];
new Random(2).NextBytes(plaintext2);
ChaCha20.Encrypt(key2, nonce2, counter: 1, plaintext2, ciphertext2);
ChaCha20.Encrypt(key2, nonce2, counter: 1, ciphertext2, decrypted2);
Console.WriteLine("Span<byte> round-trip success: " + plaintext2.SequenceEqual(decrypted2));
}
}
Installation
You can install the package via NuGet:
$ dotnet add package nebulae.dotChaCha20
Or via git:
$ git clone https://github.com/nebulaeonline/dotChaCha20.git
$ cd dotChaCha20
$ dotnet build
License
MIT
Roadmap
Unless there are vulnerabilities found in the ChaCha20 cipher, there are no plans to add any new features.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.