feat: argon2 benchmarks
This commit is contained in:
parent
a547d6ebbf
commit
b2547d25a3
2 changed files with 130 additions and 0 deletions
128
Benchmarks/Argon2Benchmarks.cs
Normal file
128
Benchmarks/Argon2Benchmarks.cs
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
||||||
|
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using BenchmarkDotNet.Order;
|
||||||
|
using Isopoh.Cryptography.Argon2;
|
||||||
|
using Konscious.Security.Cryptography;
|
||||||
|
using Argon2 = Isopoh.Cryptography.Argon2.Argon2;
|
||||||
|
|
||||||
|
namespace Benchmarks;
|
||||||
|
|
||||||
|
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
|
||||||
|
[Config(typeof(GenericConfig))]
|
||||||
|
public class Argon2Benchmarks
|
||||||
|
{
|
||||||
|
[Params(2, 4)] public int _iterations;
|
||||||
|
[Params(16, 32)] public int _memory;
|
||||||
|
[Params(1, 2)] public int _parallelism;
|
||||||
|
private byte[] _salt = null!;
|
||||||
|
private byte[] _additionalData = null!;
|
||||||
|
[Params(16)] public int _length;
|
||||||
|
|
||||||
|
private byte[] _password = null!;
|
||||||
|
|
||||||
|
[GlobalSetup]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_salt = RandomNumberGenerator.GetBytes(16);
|
||||||
|
_additionalData = RandomNumberGenerator.GetBytes(16);
|
||||||
|
_password = RandomNumberGenerator.GetBytes(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public byte[] Argon2i()
|
||||||
|
{
|
||||||
|
return new Argon2i(_password)
|
||||||
|
{
|
||||||
|
Iterations = _iterations,
|
||||||
|
MemorySize = 1024 * _memory,
|
||||||
|
DegreeOfParallelism = _parallelism,
|
||||||
|
AssociatedData = _additionalData,
|
||||||
|
Salt = _salt,
|
||||||
|
}.GetBytes(_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public byte[] Argon2d()
|
||||||
|
{
|
||||||
|
return new Argon2d(_password)
|
||||||
|
{
|
||||||
|
Iterations = _iterations,
|
||||||
|
MemorySize = 1024 * _memory,
|
||||||
|
DegreeOfParallelism = _parallelism,
|
||||||
|
AssociatedData = _additionalData,
|
||||||
|
Salt = _salt,
|
||||||
|
}.GetBytes(_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public byte[] Argon2id()
|
||||||
|
{
|
||||||
|
return new Argon2id(_password)
|
||||||
|
{
|
||||||
|
Iterations = _iterations,
|
||||||
|
MemorySize = 1024 * _memory,
|
||||||
|
DegreeOfParallelism = _parallelism,
|
||||||
|
AssociatedData = _additionalData,
|
||||||
|
Salt = _salt,
|
||||||
|
}.GetBytes(_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public byte[] IsopohArgon2DD()
|
||||||
|
{
|
||||||
|
var config = new Argon2Config
|
||||||
|
{
|
||||||
|
Type = Argon2Type.DataDependentAddressing,
|
||||||
|
Version = Argon2Version.Nineteen,
|
||||||
|
MemoryCost = 1024 * _memory,
|
||||||
|
TimeCost = _iterations,
|
||||||
|
Lanes = _parallelism,
|
||||||
|
HashLength = _length,
|
||||||
|
Salt = _salt,
|
||||||
|
AssociatedData = _additionalData,
|
||||||
|
Password = _password,
|
||||||
|
};
|
||||||
|
var argon2 = new Argon2(config);
|
||||||
|
return argon2.Hash().Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public byte[] IsopohArgon2DI()
|
||||||
|
{
|
||||||
|
var config = new Argon2Config
|
||||||
|
{
|
||||||
|
Type = Argon2Type.DataIndependentAddressing,
|
||||||
|
Version = Argon2Version.Nineteen,
|
||||||
|
MemoryCost = 1024 * _memory,
|
||||||
|
TimeCost = _iterations,
|
||||||
|
Lanes = _parallelism,
|
||||||
|
HashLength = _length,
|
||||||
|
Salt = _salt,
|
||||||
|
AssociatedData = _additionalData,
|
||||||
|
Password = _password,
|
||||||
|
};
|
||||||
|
var argon2 = new Argon2(config);
|
||||||
|
return argon2.Hash().Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public byte[] IsopohArgon2Hybrid()
|
||||||
|
{
|
||||||
|
var config = new Argon2Config
|
||||||
|
{
|
||||||
|
Type = Argon2Type.HybridAddressing,
|
||||||
|
Version = Argon2Version.Nineteen,
|
||||||
|
MemoryCost = 1024 * _memory,
|
||||||
|
TimeCost = _iterations,
|
||||||
|
Lanes = _parallelism,
|
||||||
|
HashLength = _length,
|
||||||
|
Salt = _salt,
|
||||||
|
AssociatedData = _additionalData,
|
||||||
|
Password = _password,
|
||||||
|
};
|
||||||
|
var argon2 = new Argon2(config);
|
||||||
|
return argon2.Hash().Buffer;
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,8 @@
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="BenchmarkDotNet" Version="0.13.10"/>
|
<PackageReference Include="BenchmarkDotNet" Version="0.13.10"/>
|
||||||
|
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
|
||||||
|
<PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.0" />
|
||||||
<PackageReference Include="Meziantou.Analyzer" Version="2.0.110">
|
<PackageReference Include="Meziantou.Analyzer" Version="2.0.110">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|
Loading…
Reference in a new issue