DZen.Adiantum 1.0.0

dotnet add package DZen.Adiantum --version 1.0.0
                    
NuGet\Install-Package DZen.Adiantum -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DZen.Adiantum" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DZen.Adiantum" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DZen.Adiantum" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DZen.Adiantum --version 1.0.0
                    
#r "nuget: DZen.Adiantum, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DZen.Adiantum@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DZen.Adiantum&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DZen.Adiantum&version=1.0.0
                    
Install as a Cake Tool

DZen.Adiantum

A pure managed C# implementation of Adiantum, Google's length-preserving, tweakable encryption construction for data such as storage sectors. It uses XChaCha12, AES-256, NH, and Poly1305, with a portable scalar path and SSE2, AVX2, and AVX-512F acceleration for NH on supported x86/x64 processors.

NuGet License: MIT .NET 10


What it does

Adiantum is a wide-block encryption construction: it transforms an entire input as one unit while preserving its length. It combines a tweakable hash with AES-256 and XChaCha12 in the HBSH construction. The result is suitable for length-preserving encryption use cases where conventional authenticated encryption would add bytes.

The implementation provides:

  • In-place encryption and decryption over Span<byte>.
  • A caller-supplied tweak, with no nonce or metadata added to the data.
  • Managed NH, Poly1305, and XChaCha12 implementations.
  • AES-256 single-block operations through the .NET cryptography API.
  • Published known-answer-vector coverage for NH, Poly1305, XChaCha12, and Adiantum.

The current SIMD work targets NH on x86/x64. ARM64 AdvSimd/NEON support is deferred; all platforms retain a scalar NH fallback.


Hardware acceleration

NH uses runtime CPU detection to process multiple 32-bit message words in parallel. It selects AVX-512F, AVX2, or SSE2 when supported, then falls back to scalar code. The SIMD implementations use safe .NET intrinsics. Poly1305 and XChaCha12 remain scalar in this release. ARM64 AdvSimd/NEON is deferred.

Run the console-only microbenchmark with:

dotnet run --project test/Benchmark -c Release

It reports scalar and supported x86 NH paths at several input lengths, plus end-to-end Adiantum timings. It does not write benchmark results to files.

Example results

Measured on an AMD Ryzen 9 9950X3D, Windows x64, and .NET 10.0.12, using a Release build of the library at commit 64f3f44. These are single-threaded, in-process Stopwatch measurements, not BenchmarkDotNet results. Each value is the median of five samples of at least 250 ms, after a 300 ms warm-up. Two independent runs produced similar results; the second run is shown below.

Adiantum data size Average time per operation Throughput
512 B 3.08 us 158.3 MiB/s
4 KiB 18.47 us 211.5 MiB/s
16 KiB 71.10 us 219.8 MiB/s

Each measurement repeatedly encrypts and decrypts the same buffer with a reused cipher and a 16-byte tweak. Time per operation is half the pair's elapsed time; throughput is calculated from that average. It includes the library's temporary buffer allocation and clearing, but excludes cipher construction.

NH message size Scalar SSE2 AVX2 AVX-512F
64 B 40.4 ns 32.2 ns 29.9 ns 29.5 ns
256 B 128.3 ns 63.5 ns 45.0 ns 39.6 ns
512 B 245.5 ns 109.8 ns 65.9 ns 52.5 ns
1024 B 481.6 ns 206.9 ns 106.9 ns 79.2 ns

NH timings call each implementation directly and are not end-to-end encryption results. Performance varies with hardware, runtime, input size, and system load.


Installation

The NuGet package ID is DZen.Adiantum. Once the package is available from NuGet, install it with:

dotnet add package DZen.Adiantum

The library targets .NET 10.0. It has no third-party runtime dependencies.


API

namespace DZen.Adiantum;

public sealed class Adiantum : IDisposable
{
    public const int KeySize = 32;
    public const int MinimumMessageSize = 16;

    public Adiantum(ReadOnlySpan<byte> key);
    public void Encrypt(Span<byte> data, ReadOnlySpan<byte> tweak);
    public void Decrypt(Span<byte> data, ReadOnlySpan<byte> tweak);
    public void Dispose();
}

The key must be exactly 32 bytes. Data must contain at least 16 bytes. Encryption and decryption operate in place and preserve the input length. Tweak bytes are supplied by the caller and are not serialized into the output. If processing throws, the data buffer is left unchanged. To provide this guarantee, each operation temporarily allocates a buffer the size of the data.


Usage

using System.Security.Cryptography;
using DZen.Adiantum;

byte[] key = RandomNumberGenerator.GetBytes(Adiantum.KeySize);
byte[] tweak = GetStableTweakForThisData();
byte[] data = ReadData();

using var cipher = new Adiantum(key);
cipher.Encrypt(data, tweak);

// Store or transmit the ciphertext and retain the tweak separately.
// To recover the original data, use the same key and tweak:
cipher.Decrypt(data, tweak);

Keep the key secret and use a consistent, unambiguous tweak scheme for the encrypted data. A common use is to derive a tweak from a stable data-unit identifier. Tweak design and uniqueness are the caller's responsibility.


Security considerations

Adiantum provides confidentiality only. It does not authenticate data or detect modification. Do not treat it as an AEAD or rely on it for integrity; use a separate, appropriate integrity/authentication mechanism when required.

This implementation has not received an independent security audit or formal verification. Poly1305 uses fixed-width arithmetic without secret-dependent branches, but the managed runtime and JIT do not guarantee constant-time execution. Key clearing is best effort; runtime and cryptography-provider copies may remain in memory. Do not assume it is suitable for threat models requiring constant-time secret arithmetic or guaranteed key erasure. Published-vector and round-trip tests demonstrate interoperability and functional behavior, not a security certification.


Building from source

git clone https://github.com/jdluzen/adiantum
cd adiantum
dotnet build -c Release

Run the published scalar known-answer vectors with:

dotnet run --project test/DZen.Adiantum.Test

The existing NH and Poly1305 test projects can be run with:

dotnet test test/NH.Test
dotnet test test/Poly1305.Test

References


License

Project code is licensed under the MIT License; see LICENSE. Third-party attribution is listed in THIRD-PARTY-NOTICES.md.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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.

Version Downloads Last Updated
1.0.0 0 11/23/2026