SHA3 1.1.0
dotnet add package SHA3 --version 1.1.0
NuGet\Install-Package SHA3 -Version 1.1.0
<PackageReference Include="SHA3" Version="1.1.0" />
<PackageVersion Include="SHA3" Version="1.1.0" />
<PackageReference Include="SHA3" />
paket add SHA3 --version 1.1.0
#r "nuget: SHA3, 1.1.0"
#:package SHA3@1.1.0
#addin nuget:?package=SHA3&version=1.1.0
#tool nuget:?package=SHA3&version=1.1.0
SHA3
A pure managed C# implementation of the SHA-3 family and SHAKE128/SHAKE256 extendable-output functions, using the Keccak-f[1600] permutation.
What it does
- SHA3-224, SHA3-256, SHA3-384, and SHA3-512 through
HashAlgorithm. - The legacy Keccak padding variant through the
UseKeccakPaddingproperty. - Stateful SHAKE128 and SHAKE256 absorption and output squeezing, including caller-selected output lengths.
- Shared Keccak-f[1600] permutation code for SHA-3 and SHAKE.
- NIST CAVP known-answer vectors and streaming tests.
The library targets .NET Standard 1.3, 2.0, and 2.1, plus .NET 8. Span-based
APIs are available across these targets; .NET Standard 1.3 and 2.0 use the
System.Memory package for span support.
This package provides hash and extendable-output functions, not cSHAKE, KMAC, or a higher-level protocol.
Hardware acceleration
The .NET 8 asset uses runtime-dispatched x64 AVX-512F, AVX2, AVX, or SSE2 instructions for XORing full lanes during absorption, with narrower paths for remaining lanes. AVX without AVX2 uses AVX bitwise operations. The Keccak-f permutation remains scalar; output copying may be optimized by the runtime. The .NET Standard assets use the scalar implementation, as do runtimes without the supported x64 instructions. There are no explicit ARM64 SIMD paths.
Timing
Illustrative local measurements on Windows 11 x64 (build 26300), AMD Ryzen 9 9950X3D, .NET 8.0.31, Release, with tiered compilation disabled. Values are median nanoseconds per operation across five samples after warm-up; smaller is better. SHA3 hashes the input; SHAKE256 absorbs the input and squeezes an equal number of bytes. Each sample has 100,000 iterations for 32-byte inputs, 2,048 for 4 KiB, and 16 for 1 MiB.
| Workload | Pre-change scalar code | Current scalar fallback | Current AVX-512F |
|---|---|---|---|
| SHA3-256, 32 B | 356.2 | 298.9 | 295.1 |
| SHAKE256, 32 B | 264.8 | 221.1 | 198.9 |
| SHA3-256, 4 KiB | 8,768.8 | 7,171.2 | 6,522.8 |
| SHAKE256, 4 KiB | 21,032.9 | 12,122.0 | 10,602.8 |
| SHA3-256, 1 MiB | 2,119,443.8 | 1,689,756.2 | 1,537,106.2 |
| SHAKE256, 1 MiB | 4,621,043.8 | 3,056,231.2 | 2,677,950.0 |
The pre-change numbers use the previous .NET Standard 2.1 asset on .NET 8; they were measured from an uncommitted source snapshot, not an existing commit. The other columns use the .NET 8 asset. Scalar fallback also includes the new lane-at-a-time SHAKE I/O, so the difference from pre-change is not solely SIMD. Disabling intrinsics is runtime-wide and can affect JIT code outside the XOR path; CPU frequency and other activity can also affect these results. These are not guarantees of speedup.
Reproduce the current SIMD and scalar-fallback measurements from the repository root:
$env:DOTNET_TieredCompilation = '0'
dotnet run --project .\test\SHA3.SpeedTest\SHA3.SpeedTest.csproj -c Release
$env:DOTNET_EnableHWIntrinsic = '0'
dotnet run --project .\test\SHA3.SpeedTest\SHA3.SpeedTest.csproj -c Release
Remove-Item Env:\DOTNET_EnableHWIntrinsic
Remove-Item Env:\DOTNET_TieredCompilation
For path testing, DOTNET_EnableAVX512F=0 selects AVX2,
DOTNET_EnableAVX2=0 selects AVX, and DOTNET_EnableAVX=0 selects SSE2 on a
machine that supports them. These switches restrict the runtime's available
instructions; they do not emulate hardware. Tests exercised all four paths on
the CPU above, not on separate machines with each ISA as their highest feature.
Experimental single-state SSE2 and AVX2 permutations
Experimental .NET 8 single-state SSE2 and AVX2 permutations are available only
in builds made with ExperimentalAvx2Permutation=true and are selected only
by the benchmark harness. Normal builds retain the scalar permutation without
the experimental dispatch.
A longer comparison on the same Ryzen 9 9950X3D, Windows 11 x64 build 26300, and .NET 8.0.31 used the same experimental Release build for all three paths. Each workload had at least three seconds of warm-up and five samples of at least two seconds each. Values are median ns/op. Each 1 MiB sample completed 80 vector SHAKE operations or 144-160 vector SHA3 operations, versus 736-752 scalar SHAKE or 1,312-1,328 scalar SHA3 operations. Smaller workloads performed at least 18,000 operations per sample. ReadyToRun was disabled; the six processes ran sequentially, each taking at least 78 seconds.
| Workload | Scalar | SSE2 | AVX2 | Scalar + PGO | SSE2 + PGO | AVX2 + PGO |
|---|---|---|---|---|---|---|
| SHA3-256, 32 B | 267.7 | 1,738.2 | 1,823.4 | 269.4 | 1,744.4 | 1,845.3 |
| SHAKE256, 32 B | 192.1 | 1,657.8 | 1,746.4 | 188.6 | 1,653.7 | 1,782.2 |
| SHA3-256, 4 KiB | 6,150.5 | 51,358.8 | 53,775.1 | 6,204.9 | 51,569.6 | 54,812.8 |
| SHAKE256, 4 KiB | 10,635.3 | 99,418.2 | 104,201.1 | 10,640.5 | 100,186.4 | 106,048.1 |
| SHA3-256, 1 MiB | 1,510,185.3 | 12,697,373.7 | 13,342,341.2 | 1,516,386.5 | 12,802,760.0 | 13,620,468.8 |
| SHAKE256, 1 MiB | 2,680,400.5 | 25,109,357.5 | 26,601,563.8 | 2,686,519.4 | 25,350,670.0 | 27,022,017.5 |
SSE2 was modestly faster than this AVX2 prototype, but both remained roughly 6-10 times slower than scalar; neither is enabled by default. Tiered compilation with dynamic PGO did not close the gap. This result applies to these implementations and this machine, not all SIMD Keccak implementations. The benchmark runs existing single-stream APIs with identical input/output handling.
Full-optimization JIT disassembly confirmed that the scalar run compiled
PermuteScalar, the AVX2 run compiled KeccakAvx2.Permute, and the SSE2 run
compiled KeccakSse2.Permute with 128-bit vpxor and vpandn instructions.
AVX was available during these measurements, so the JIT used VEX-encoded
instructions for SSE2 intrinsics. The prototypes reconstruct and extract
vectors, use indexed loops, modulo calculations, dynamic rotations and bounds
checks; the scalar permutation is largely unrolled. These are plausible
sources of overhead, not a measured attribution.
To reproduce and test the comparison from the repository root:
dotnet build .\test\SHA3.SpeedTest\SHA3.SpeedTest.csproj -c Release -p:ExperimentalAvx2Permutation=true
$env:DOTNET_ReadyToRun = '0'
$env:DOTNET_TieredCompilation = '0'
$env:DOTNET_TieredPGO = '0'
dotnet .\test\SHA3.SpeedTest\bin\Release\net8.0\SHA3.SpeedTest.dll --long
dotnet .\test\SHA3.SpeedTest\bin\Release\net8.0\SHA3.SpeedTest.dll --long --sse2-permutation
dotnet .\test\SHA3.SpeedTest\bin\Release\net8.0\SHA3.SpeedTest.dll --long --avx2-permutation
$env:DOTNET_TieredCompilation = '1'
$env:DOTNET_TieredPGO = '1'
dotnet .\test\SHA3.SpeedTest\bin\Release\net8.0\SHA3.SpeedTest.dll --long
dotnet .\test\SHA3.SpeedTest\bin\Release\net8.0\SHA3.SpeedTest.dll --long --sse2-permutation
dotnet .\test\SHA3.SpeedTest\bin\Release\net8.0\SHA3.SpeedTest.dll --long --avx2-permutation
dotnet test .\test\SHA3.Tests\SHA3.Tests.csproj -c Release -f net8.0 -p:ExperimentalAvx2Permutation=true --filter "FullyQualifiedName~KeccakAvx2Tests|FullyQualifiedName~KeccakSse2Tests"
Remove-Item Env:\DOTNET_ReadyToRun
Remove-Item Env:\DOTNET_TieredCompilation
Remove-Item Env:\DOTNET_TieredPGO
The experimental paths were checked against scalar random states, SHA3/Keccak and SHAKE vectors and streaming boundaries on the listed CPU. SSE2 was also tested with AVX disabled, and each path falls back to scalar when its required ISA is disabled. No other x64 CPU or ARM64 hardware was tested.
Installation
dotnet add package SHA3
The published package may not include the SHAKE APIs documented in this README.
To use the current source-tree implementation, build and reference
src\SHA3\SHA3.csproj.
API
All types are in namespace DZen.Security.Cryptography.
| Type | Operations |
|---|---|
SHA3 |
Create() and Create(string) select a SHA-3 implementation |
SHA3224Managed, SHA3256Managed, SHA3384Managed, SHA3512Managed |
HashAlgorithm implementations for the corresponding digest sizes |
SHA3Managed |
Shared managed SHA-3 implementation; set UseKeccakPadding to select legacy Keccak padding |
Shake128, Shake256 |
Incremental AppendData/Absorb, Squeeze/GetBytes, Reset, Clone, and HashData |
SHA-3 and Keccak use the same digest sizes but different padding. SHA-3 padding
is used by default; set UseKeccakPadding = true when a caller specifically
requires the legacy Keccak variant.
Usage
SHA-3
using DZen.Security.Cryptography;
using SHA3 sha3 = SHA3.Create("SHA3-256");
byte[] digest = sha3.ComputeHash(message);
To use Keccak padding instead:
using SHA3 keccak = SHA3.Create("SHA3-256");
keccak.UseKeccakPadding = true;
byte[] digest = keccak.ComputeHash(message);
SHAKE
using DZen.Security.Cryptography;
using var shake = new Shake128();
shake.AppendData(message);
byte[] first = shake.GetBytes(32);
Span<byte> more = stackalloc byte[64];
shake.Squeeze(more);
Input can be supplied incrementally with AppendData or Absorb, using
byte[] or ReadOnlySpan<byte>. Once the first Squeeze or GetBytes call
starts output (even for an empty destination), no more input can be absorbed.
Squeezing is stateful and can continue across calls and rate-block boundaries.
Use Reset to clear and reuse an instance, or Clone to copy its current
absorption or squeezing state.
For one-shot output, use Shake128.HashData(source, outputLength) or
Shake256.HashData(source, outputLength). Span overloads write directly to a
caller-provided destination.
Security considerations
Automated review only; no independent cryptographic audit. No formal verification, generated-code timing analysis, or independent human cryptographic audit has been performed. This library makes no constant-time guarantee for the .NET runtime, JIT, or any particular processor.
NIST known-answer vectors and .NET differential tests check functional
compatibility; they are not a security certification or guarantee. Shake
implements IDisposable and clears its sponge state on Dispose and Reset,
but this is best-effort clearing, not guaranteed erasure of copies, runtime
buffers, registers, or caller-owned input and output.
Building from source
From the repository root:
dotnet build .\src\SHA3\SHA3.csproj -c Release
dotnet test .\test\SHA3.Tests\SHA3.Tests.csproj -c Release
dotnet pack .\src\SHA3\SHA3.csproj -c Release -o .\artifacts
The library builds for .NET Standard 1.3, 2.0, and 2.1, and .NET 8. Tests run
on .NET 7 and .NET 8; the .NET 8 tests also compare SHAKE results against the
platform System.Security.Cryptography.Shake128 and Shake256
implementations.
Release library builds enable the SDK's ContinuousIntegrationBuild setting
to normalize source paths in deterministic assemblies and portable PDBs.
SourceLink maps those paths to the repository revision; build from a clean Git
checkout so the linked source matches. For reproducible results, use the same
SDK, dependencies, configuration, and inputs. The SDK is not pinned in this
repository. Debug builds retain local source paths unless
ContinuousIntegrationBuild=true is supplied explicitly.
This setting does not guarantee byte-identical NuGet packages: package ZIP metadata can differ between builds even when their assemblies and PDBs match.
References
- FIPS 202: SHA-3 and SHAKE specifications.
- NIST CAVP Secure Hashing: SHA-3 and SHAKE test-vector archives.
License
Project code is licensed under Apache-2.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
| .NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
| Universal Windows Platform | uap was computed. uap10.0 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- System.Memory (>= 4.5.0)
-
.NETStandard 2.0
- System.Memory (>= 4.5.0)
-
.NETStandard 2.1
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (5)
Showing the top 5 NuGet packages that depend on SHA3:
| Package | Downloads |
|---|---|
|
Sonolib
Sono crypto library |
|
|
VBCommonUtility
Package Description |
|
|
VBGenericUtility
Package Description |
|
|
GNodeUtils
Package Description |
|
|
DZen.MLDsa
Managed implementation of FIPS 204 ML-DSA signatures with scalar and optional x86 SIMD polynomial arithmetic. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Adds streaming SHAKE128 and SHAKE256, corrects SHA-3 lane encoding on big-endian systems, and adds accelerated x64 absorption on .NET 8.