Skip to content

Commit

Permalink
stream cipher benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
JayArrowz committed May 16, 2019
0 parents commit 97b552b
Show file tree
Hide file tree
Showing 17 changed files with 5,488 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.vscode
/obj
/bin
/out
BenchmarkDotNet.Artifacts/*.log
BenchmarkDotNet.Artifacts/results/*.csv
BenchmarkDotNet.Artifacts/results/*.html
*.lock
*.ide
.vs/benchmarks/v16/.suo
.vs/benchmarks/DesignTimeBuild/.dtbcache
.vs/benchmarks/v16/Server/sqlite3/storage.ide-shm
.vs/benchmarks/v16/Server/sqlite3/storage.ide-wal
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# crypto-benchmarking
Benchmarker for various crypto libraries

## Setup
build:
```shell
dotnet publish -c Release -o out
```

## Run benchmarks

To run all benchmarks and collate them into a single table:
```shell
out/benchmarks.dll -f '*' --join
```

To run single point of comparison eg benchmark the verification method of all libraries:
```shell
dotnet out/benchmarks.dll --anyCategories=verify —-join
```

To compare just ed25519 methods (or secp256k1)
```shell
dotnet out/benchmarks.dll --anyCategories=ed25519 --join
```
To get info about memory allocation add ```-m``` to the console arguments

To run tests for a single library
```shell
dotnet out/benchmarks.dll
```
to get console options



## Reports

Reports can be found in the BenchmarkDotNet.Artifacts/results folder.

[Report 4/1/19](BenchmarkDotNet.Artifacts/results/BenchmarkRun-joined-2019-01-04-01-35-42-report-github.md)

18 changes: 18 additions & 0 deletions benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.4" />
<PackageReference Include="Secp256k1.Net" Version="0.1.52" />
<PackageReference Include="NSec.Cryptography" Version="18.6.0" />
<Content Include="src\Program.cs" />
<Content Include="benchmarks.sln" />
</ItemGroup>
<ItemGroup>
<Folder Include="BenchmarkDotNet.Artifacts\results\" />
</ItemGroup>
</Project>
34 changes: 34 additions & 0 deletions benchmarks.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "benchmarks", "benchmarks.csproj", "{D56023AD-346D-4353-8689-A6495CFF34D5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D56023AD-346D-4353-8689-A6495CFF34D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Debug|x64.ActiveCfg = Debug|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Debug|x64.Build.0 = Debug|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Debug|x86.ActiveCfg = Debug|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Debug|x86.Build.0 = Debug|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Release|Any CPU.Build.0 = Release|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Release|x64.ActiveCfg = Release|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Release|x64.Build.0 = Release|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Release|x86.ActiveCfg = Release|Any CPU
{D56023AD-346D-4353-8689-A6495CFF34D5}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions benchmarks.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="https://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Int64 x:Key="/Default/CodeStyle/Naming/CSharpAutoNaming/AutoNamingCompletedVersion/@EntryValue">2</s:Int64></wpf:ResourceDictionary>
24 changes: 24 additions & 0 deletions src/ChaCha20Benchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Linq;
using benchmark.utils;
using BenchmarkDotNet.Attributes;

namespace benchmarks
{
public class Isaac
{
[Benchmark]
[BenchmarkCategory("PRNG")]
public void GenerateRandom()
{
byte[] rngBytes = new byte[Program.RNG_COUNT * Program.INT_SIZE];
ChaCha20 chaCha20 = new ChaCha20 { IsParallel = false };
var keyParam = new KeyParams(Guid.NewGuid().ToByteArray(),
Guid.NewGuid().ToByteArray().Take(8).ToArray());
chaCha20.Initialize(keyParam);
chaCha20.Transform(rngBytes, rngBytes);

chaCha20.Dispose();
}
}
}
20 changes: 20 additions & 0 deletions src/IsaacBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using benchmark.utils;
using BenchmarkDotNet.Attributes;

namespace benchmarks
{
public class IsaacBenchmark
{
[Benchmark]
[BenchmarkCategory("PRNG")]
public void GenerateRandom()
{
IsaacRandom random = new IsaacRandom(Guid.NewGuid().ToString());
for (int i = 0; i < Program.RNG_COUNT; i++)
{
random.NextInt();
}
}
}
}
17 changes: 17 additions & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using BenchmarkDotNet.Running;

namespace benchmarks
{
public class Program
{
public static int RNG_COUNT = 100000;
public static int INT_SIZE = 4;

public static void Main(string[] args)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}

}
}

31 changes: 31 additions & 0 deletions src/Salsa20Benchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using benchmark.utils;
using BenchmarkDotNet.Attributes;

namespace benchmarks
{
public class Salsa20Benchmark
{
[Benchmark]
[BenchmarkCategory("PRNG")]
public void GenerateRandom()
{

for (int v = 0; v < 10; v++)
{
byte[] rng = new byte[Program.RNG_COUNT * Program.INT_SIZE];
using (SymmetricAlgorithm salsa20 = new Salsa20())
using (ICryptoTransform encrypt = salsa20.CreateEncryptor(Guid.NewGuid().ToByteArray(),
Guid.NewGuid().ToByteArray().Take(8).ToArray()))
using (MemoryStream streamInput = new MemoryStream(rng, false))
using (CryptoStream streamEncrypted = new CryptoStream(streamInput, encrypt, CryptoStreamMode.Read))
{
streamEncrypted.ReadAsync(rng).GetAwaiter().GetResult();
}
}
}
}
}
Loading

0 comments on commit 97b552b

Please sign in to comment.