SauceControl.Blake2Fast
0.1.0
See the version list below for details.
Install-Package SauceControl.Blake2Fast -Version 0.1.0
dotnet add package SauceControl.Blake2Fast --version 0.1.0
<PackageReference Include="SauceControl.Blake2Fast" Version="0.1.0" />
paket add SauceControl.Blake2Fast --version 0.1.0
#r "nuget: SauceControl.Blake2Fast, 0.1.0"
// Install SauceControl.Blake2Fast as a Cake Addin
#addin nuget:?package=SauceControl.Blake2Fast&version=0.1.0
// Install SauceControl.Blake2Fast as a Cake Tool
#tool nuget:?package=SauceControl.Blake2Fast&version=0.1.0
These RFC 7693-compliant BLAKE2 implementations have been tuned for high speed and low memory usage. The .NET Core 2.1 build supports the new X86 SIMD Intrinsics for even greater speed and Span{T}
for even lower memory usage.
Usage
All-at-Once Hashing
The simplest and lightest-weight way to calculate a hash is the all-at-once ComputeHash
method.
Blake2b.ComputeHash(data);
BLAKE2 supports variable digest lengths from 1 to 32 bytes for Blake2s
or 1 to 64 bytes for Blake2b
.
Blake2b.ComputeHash(42, data);
BLAKE2 also natively supports keyed hashing.
Blake2b.ComputeHash(key, data);
Incremental Hashing
BLAKE2 hashes can be incrementally updated if you do not have the data available all at once.
async Task<byte[]> CalculateHashAsync(Stream data)
{
var incHash = Blake2b.CreateIncrementalHasher();
var buffer = new byte[4096];
int bytesRead;
while ((bytesRead = await data.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
// Use Span<T> for .NET Core 2.1 or ArraySegment<T> for others
incHash.Update(new ArraySegment<byte>(buffer, 0, bytesRead));
}
return incHash.Finish();
}
System.Security.Cryptography Interop
For interoperating with code that uses System.Security.Cryptography
primitives, Blake2Fast can create a HashAlgorithm
wrapper. The wrapper inherits from HMAC
in case keyed hashing is required.
HashAlgorithm
is less efficient than the above methods, so use it only when necessary for compatibility.
byte[] WriteDataAndCalculateHash(byte[] data)
{
using (var hashAlg = Blake2b.CreateHashAlgorithm())
using (var fileStream = new FileStream(@"c:\data\output.bin", FileMode.Create))
using (var cryptoStream = new CryptoStream(fileStream, hashAlg, CryptoStreamMode.Write))
{
cryptoStream.Write(data, 0, data.Length);
cryptoStream.FlushFinalBlock();
return hashAlg.Hash;
}
}
SIMD Intrinsics Warning
The X86 SIMD Intrinsics used in the .NET Core 2.1 build are not officially supported by Microsoft. Although the specific SSE Intrinsics used by Blake2Fast have been well-tested, the JIT support for the X86 Intrinsics in general is experimental in .NET Core 2.1. Please test with your specific hardware and report any issues here or in the CoreCLR repo as appropriate.
If you are uncomfortable using unsupported functionality, you can make a custom build of Blake2Fast by removing the USE_INTRINSICS
define constant in the project file. This applies only to .NET Core 2.1; the older build targets use only the scalar code.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows |
.NET Core | netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1 |
.NET Framework | net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen30 tizen40 tizen60 |
Universal Windows Platform | uap uap10.0 |
Windows Phone | wp8 wp81 wpa81 |
Windows Store | netcore netcore45 netcore451 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETCoreApp 2.0
- System.Runtime.CompilerServices.Unsafe (>= 4.5.0)
-
.NETCoreApp 2.1
- System.Runtime.CompilerServices.Unsafe (>= 4.5.0)
- System.Runtime.Intrinsics.Experimental (>= 4.5.0-rc1)
-
.NETFramework 4.5
- System.Runtime.CompilerServices.Unsafe (>= 4.5.0)
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
- System.Runtime.CompilerServices.Unsafe (>= 4.5.0)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- System.Runtime.CompilerServices.Unsafe (>= 4.5.0)
-
.NETStandard 2.0
- System.Runtime.CompilerServices.Unsafe (>= 4.5.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on SauceControl.Blake2Fast:
Package | Downloads |
---|---|
CardanoSharp.Wallet
Package Description |
|
DigitalRuby.SimpleCache
Simple and powerful caching for .NET using three layers: RAM, file and redis. |
|
Centr.NetCS
Third Party Library for implementing Credits Blockchain in .NET |
|
PoseidonSharp
This is a Poseidon Hashing Library built for use with Loopring |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on SauceControl.Blake2Fast:
Repository | Stars |
---|---|
baking-bad/tzkt
😼 Awesome Tezos blockchain indexer and API
|