From 7193cd0df9715eb840c4daa93dfd624469ab08fe Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Wed, 20 Sep 2017 12:12:20 +0200 Subject: [PATCH] Initial Commit (not working) --- .gitignore | 40 +++++++++++++++ HashBase.cs | 15 ++++++ IHash.cs | 9 ++++ Properties/AssemblyInfo.cs | 26 ++++++++++ SHA3/Keccak.cs | 99 ++++++++++++++++++++++++++++++++++++++ sharp.hashing.csproj | 42 ++++++++++++++++ 6 files changed, 231 insertions(+) create mode 100644 .gitignore create mode 100644 HashBase.cs create mode 100644 IHash.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 SHA3/Keccak.cs create mode 100644 sharp.hashing.csproj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e82d27 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# Autosave files +*~ + +# build +[Oo]bj/ +[Bb]in/ +packages/ +TestResults/ + +# globs +Makefile.in +*.DS_Store +*.sln.cache +*.suo +*.cache +*.pidb +*.userprefs +*.usertasks +config.log +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.user +*.tar.gz +tarballs/ +test-results/ +Thumbs.db + +# Mac bundle stuff +*.dmg +*.app + +# resharper +*_Resharper.* +*.Resharper + +# dotCover +*.dotCover diff --git a/HashBase.cs b/HashBase.cs new file mode 100644 index 0000000..ae5f9c3 --- /dev/null +++ b/HashBase.cs @@ -0,0 +1,15 @@ +using System; +using System.Text; +namespace sharp.hashing +{ + public abstract class HashBase : IHash { + + UTF8Encoding utf8 = new UTF8Encoding(); + + public abstract byte[] compute(byte[] data); + public byte[] compute(string data) + { + return compute(utf8.GetBytes(data)); + } + } +} diff --git a/IHash.cs b/IHash.cs new file mode 100644 index 0000000..6863bdc --- /dev/null +++ b/IHash.cs @@ -0,0 +1,9 @@ +using System; +namespace sharp.hashing +{ + public interface IHash + { + byte[] compute(byte[] data); + byte[] compute(string data); + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bf027e4 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("sharp.hashing")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/SHA3/Keccak.cs b/SHA3/Keccak.cs new file mode 100644 index 0000000..8c7deae --- /dev/null +++ b/SHA3/Keccak.cs @@ -0,0 +1,99 @@ +using System; +using System.Threading; +namespace sharp.hashing.SHA3 +{ + public class Keccak : HashBase + { + struct keccak_1600_std { + public readonly int output_size; + public readonly int r, c; + + public keccak_1600_std(int output_size,int r,int c){ + this.output_size = output_size; + this.r = r; + this.c = c; + } + }; + + keccak_1600_std[] std1600 = { + new keccak_1600_std(224,1152,448), + new keccak_1600_std(256,1088,512), + new keccak_1600_std(384,832,768), + new keccak_1600_std(512,576,1024) + }; + + private int output_size,r, c; + + + public Keccak(int size) + { + foreach (keccak_1600_std std in std1600){ + if (std.output_size == size){ + this.r = std.r; + this.c = std.c; + this.output_size = std.output_size; + } + } + + if (this.output_size != size){ + throw new ArgumentException("No Standard Parameters for that Output Size defined!"); + } + + + + } + + public override byte[] compute(byte[] data) + { + byte[] result = null; + + Monitor.Enter(this); + + + + Monitor.Exit(this); + return result; + } + + + + + + private UInt64[] RC = { + 0x0000000000000001, + 0x0000000000008082, + 0x800000000000808A, + 0x8000000080008000, + 0x000000000000808B, + 0x0000000080000001, + 0x8000000080008081, + 0x8000000000008009, + 0x000000000000008A, + 0x0000000000000088, + 0x0000000080008009, + 0x000000008000000A, + 0x000000008000808B, + 0x800000000000008B, + 0x8000000000008089, + 0x8000000000008003, + 0x8000000000008002, + 0x8000000000000080, + 0x000000000000800A, + 0x800000008000000A, + 0x8000000080008081, + 0x8000000000008080, + 0x0000000080000001, + 0x8000000080008008 + }; + + // RO[y][x] + private int[][] RO = { + new int[]{03,10,43,25,39}, + new int[]{36,44,06,55,20}, + new int[]{00,01,62,28,27}, + new int[]{18,02,61,56,14}, + new int[]{41,45,15,21,08} + }; + + } +} diff --git a/sharp.hashing.csproj b/sharp.hashing.csproj new file mode 100644 index 0000000..aaf4795 --- /dev/null +++ b/sharp.hashing.csproj @@ -0,0 +1,42 @@ + + + + Debug + AnyCPU + {CCD7C196-B079-4AA7-98AF-5BECAD089CE4} + Library + sharp.hashing + sharp.hashing + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + true + bin\Release + prompt + 4 + false + + + + + + + + + + + + + + + \ No newline at end of file