New upstream version 5.2.5188

This commit is contained in:
geos_one
2025-08-08 12:40:03 +02:00
parent b1e9cf955b
commit e8b2c75644
5730 changed files with 1430965 additions and 238433 deletions

View File

@@ -0,0 +1,72 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
namespace Blake2Sharp
{
public static class Blake2B
{
public static Hasher Create()
{
return Create(new Blake2BConfig());
}
public static Hasher Create(Blake2BConfig config)
{
return new Blake2BHasher(config);
}
/*public static Hasher CreateParallel(int parallelism = 4)
{
return CreateParallel(null, parallelism);
}
public static Hasher CreateParallel(Blake2Config config, int parallelism = 4)
{
if (parallelism < 2)
throw new ArgumentOutOfRangeException("parallelism", "parallism must be at least 2");
throw new NotImplementedException();
}
public static Hasher CreateTreeHasher(Blake2BConfig config, Blake2TreeConfig treeConfig)
{
}
public static NodeHasher CreateNodeHasher(Blake2BConfig config, Blake2TreeConfig treeConfig)
{
}*/
public static byte[] ComputeHash(byte[] data, int start, int count)
{
return ComputeHash(data, start, count, null);
}
public static byte[] ComputeHash(byte[] data)
{
return ComputeHash(data, 0, data.Length, null);
}
public static byte[] ComputeHash(byte[] data, Blake2BConfig config)
{
return ComputeHash(data, 0, data.Length, config);
}
public static byte[] ComputeHash(byte[] data, int start, int count, Blake2BConfig config)
{
var hasher = Create(config);
hasher.Update(data, start, count);
return hasher.Finish();
}
//public static byte[] ComputeParallelHash(byte[] data);
//public static byte[] ComputeParallelHash(byte[] data, Blake2Config config);
}
}

View File

@@ -0,0 +1,57 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
using System.Text;
namespace Blake2Sharp
{
public sealed class Blake2BConfig : ICloneable
{
public byte[] Personalization { get; set; }
public byte[] Salt { get; set; }
public byte[] Key { get; set; }
public int OutputSizeInBytes { get; set; }
public int OutputSizeInBits
{
get { return OutputSizeInBytes * 8; }
set
{
if (value % 8 != 0)
throw new ArgumentException("Output size must be a multiple of 8 bits");
OutputSizeInBytes = value / 8;
}
}
public Blake2BConfig()
{
OutputSizeInBytes = 64;
}
public Blake2BConfig Clone()
{
var result = new Blake2BConfig();
result.OutputSizeInBytes = OutputSizeInBytes;
if (Key != null)
result.Key = (byte[])Key.Clone();
if (Personalization != null)
result.Personalization = (byte[])Personalization.Clone();
if (Salt != null)
result.Salt = (byte[])Salt.Clone();
return result;
}
object ICloneable.Clone()
{
return Clone();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,177 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
namespace Blake2Sharp
{
#if false
public sealed partial class Blake2BCore
{
partial void Compress(byte[] block, int start)
{
var h = _h;
var m = _m;
if (BitConverter.IsLittleEndian)
{
Buffer.BlockCopy(block, start, m, 0, BlockSizeInBytes);
}
else
{
for (int i = 0; i < 16; ++i)
m[i] = BytesToUInt64(block, start + (i << 3));
}
var v0 = h[0];
var v1 = h[1];
var v2 = h[2];
var v3 = h[3];
var v4 = h[4];
var v5 = h[5];
var v6 = h[6];
var v7 = h[7];
var v8 = IV0;
var v9 = IV1;
var v10 = IV2;
var v11 = IV3;
var v12 = IV4 ^ _counter0;
var v13 = IV5 ^ _counter1;
var v14 = IV6 ^ _finaliziationFlag0;
var v15 = IV7 ^ _finaliziationFlag1;
for (int r = 0; r < NumberOfRounds; ++r)
{
// G(r,0,v0,v4,v8,v12)
v0 = v0 + v4 + m[Sigma[16 * r + 2 * 0 + 0]];
v12 ^= v0;
v12 = ((v12 >> 32) | (v12 << (64 - 32)));
v8 = v8 + v12;
v4 ^= v8;
v4 = ((v4 >> 24) | (v4 << (64 - 24)));
v0 = v0 + v4 + m[Sigma[16 * r + 2 * 0 + 1]];
v12 ^= v0;
v12 = ((v12 >> 16) | (v12 << (64 - 16)));
v8 = v8 + v12;
v4 ^= v8;
v4 = ((v4 >> 63) | (v4 << (64 - 63)));
// G(r,1,v1,v5,v9,v13)
v1 = v1 + v5 + m[Sigma[16 * r + 2 * 1 + 0]];
v13 ^= v1;
v13 = ((v13 >> 32) | (v13 << (64 - 32)));
v9 = v9 + v13;
v5 ^= v9;
v5 = ((v5 >> 24) | (v5 << (64 - 24)));
v1 = v1 + v5 + m[Sigma[16 * r + 2 * 1 + 1]];
v13 ^= v1;
v13 = ((v13 >> 16) | (v13 << (64 - 16)));
v9 = v9 + v13;
v5 ^= v9;
v5 = ((v5 >> 63) | (v5 << (64 - 63)));
// G(r,2,v2,v6,v10,v14)
v2 = v2 + v6 + m[Sigma[16 * r + 2 * 2 + 0]];
v14 ^= v2;
v14 = ((v14 >> 32) | (v14 << (64 - 32)));
v10 = v10 + v14;
v6 ^= v10;
v6 = ((v6 >> 24) | (v6 << (64 - 24)));
v2 = v2 + v6 + m[Sigma[16 * r + 2 * 2 + 1]];
v14 ^= v2;
v14 = ((v14 >> 16) | (v14 << (64 - 16)));
v10 = v10 + v14;
v6 ^= v10;
v6 = ((v6 >> 63) | (v6 << (64 - 63)));
// G(r,3,v3,v7,v11,v15)
v3 = v3 + v7 + m[Sigma[16 * r + 2 * 3 + 0]];
v15 ^= v3;
v15 = ((v15 >> 32) | (v15 << (64 - 32)));
v11 = v11 + v15;
v7 ^= v11;
v7 = ((v7 >> 24) | (v7 << (64 - 24)));
v3 = v3 + v7 + m[Sigma[16 * r + 2 * 3 + 1]];
v15 ^= v3;
v15 = ((v15 >> 16) | (v15 << (64 - 16)));
v11 = v11 + v15;
v7 ^= v11;
v7 = ((v7 >> 63) | (v7 << (64 - 63)));
// G(r,4,v0,v5,v10,v15)
v0 = v0 + v5 + m[Sigma[16 * r + 2 * 4 + 0]];
v15 ^= v0;
v15 = ((v15 >> 32) | (v15 << (64 - 32)));
v10 = v10 + v15;
v5 ^= v10;
v5 = ((v5 >> 24) | (v5 << (64 - 24)));
v0 = v0 + v5 + m[Sigma[16 * r + 2 * 4 + 1]];
v15 ^= v0;
v15 = ((v15 >> 16) | (v15 << (64 - 16)));
v10 = v10 + v15;
v5 ^= v10;
v5 = ((v5 >> 63) | (v5 << (64 - 63)));
// G(r,5,v1,v6,v11,v12)
v1 = v1 + v6 + m[Sigma[16 * r + 2 * 5 + 0]];
v12 ^= v1;
v12 = ((v12 >> 32) | (v12 << (64 - 32)));
v11 = v11 + v12;
v6 ^= v11;
v6 = ((v6 >> 24) | (v6 << (64 - 24)));
v1 = v1 + v6 + m[Sigma[16 * r + 2 * 5 + 1]];
v12 ^= v1;
v12 = ((v12 >> 16) | (v12 << (64 - 16)));
v11 = v11 + v12;
v6 ^= v11;
v6 = ((v6 >> 63) | (v6 << (64 - 63)));
// G(r,6,v2,v7,v8,v13)
v2 = v2 + v7 + m[Sigma[16 * r + 2 * 6 + 0]];
v13 ^= v2;
v13 = ((v13 >> 32) | (v13 << (64 - 32)));
v8 = v8 + v13;
v7 ^= v8;
v7 = ((v7 >> 24) | (v7 << (64 - 24)));
v2 = v2 + v7 + m[Sigma[16 * r + 2 * 6 + 1]];
v13 ^= v2;
v13 = ((v13 >> 16) | (v13 << (64 - 16)));
v8 = v8 + v13;
v7 ^= v8;
v7 = ((v7 >> 63) | (v7 << (64 - 63)));
// G(r,7,v3,v4,v9,v14)
v3 = v3 + v4 + m[Sigma[16 * r + 2 * 7 + 0]];
v14 ^= v3;
v14 = ((v14 >> 32) | (v14 << (64 - 32)));
v9 = v9 + v14;
v4 ^= v9;
v4 = ((v4 >> 24) | (v4 << (64 - 24)));
v3 = v3 + v4 + m[Sigma[16 * r + 2 * 7 + 1]];
v14 ^= v3;
v14 = ((v14 >> 16) | (v14 << (64 - 16)));
v9 = v9 + v14;
v4 ^= v9;
v4 = ((v4 >> 63) | (v4 << (64 - 63)));
}
h[0] ^= v0 ^ v8;
h[1] ^= v1 ^ v9;
h[2] ^= v2 ^ v10;
h[3] ^= v3 ^ v11;
h[4] ^= v4 ^ v12;
h[5] ^= v5 ^ v13;
h[6] ^= v6 ^ v14;
h[7] ^= v7 ^ v15;
}
}
#endif
}

View File

@@ -0,0 +1,88 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
namespace Blake2Sharp
{
#if false
public sealed partial class Blake2BCore
{
private ulong[] _v = new ulong[16];
private static ulong RotateRight(ulong value, int nBits)
{
return (value >> nBits) | (value << (64 - nBits));
}
private void G(int a, int b, int c, int d, int r, int i)
{
int p = (r << 4) + i;
int p0 = Sigma[p];
int p1 = Sigma[p + 1];
var v = _v;
var m = _m;
v[a] += v[b] + m[p0];
v[d] = RotateRight(v[d] ^ v[a], 32);
v[c] += v[d];
v[b] = RotateRight(v[b] ^ v[c], 24);
v[a] += v[b] + m[p1];
v[d] = RotateRight(v[d] ^ v[a], 16);
v[c] += v[d];
v[b] = RotateRight(v[b] ^ v[c], 63);
}
partial void Compress(byte[] block, int start)
{
var v = _v;
var h = _h;
var m = _m;
for (int i = 0; i < 16; ++i)
m[i] = BytesToUInt64(block, start + (i << 3));
v[0] = h[0];
v[1] = h[1];
v[2] = h[2];
v[3] = h[3];
v[4] = h[4];
v[5] = h[5];
v[6] = h[6];
v[7] = h[7];
v[8] = IV0;
v[9] = IV1;
v[10] = IV2;
v[11] = IV3;
v[12] = IV4 ^ _counter0;
v[13] = IV5 ^ _counter1;
v[14] = IV6 ^ _finaliziationFlag0;
v[15] = IV7 ^ _finaliziationFlag1;
for (int r = 0; r < NumberOfRounds; ++r)
{
G(0, 4, 8, 12, r, 0);
G(1, 5, 9, 13, r, 2);
G(2, 6, 10, 14, r, 4);
G(3, 7, 11, 15, r, 6);
G(3, 4, 9, 14, r, 14);
G(2, 7, 8, 13, r, 12);
G(0, 5, 10, 15, r, 8);
G(1, 6, 11, 12, r, 10);
}
for (int i = 0; i < 8; ++i)
h[i] ^= v[i] ^ v[i + 8];
}
}
#endif
}

View File

@@ -0,0 +1,198 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
//
/*
Based on BlakeSharp
by Dominik Reichl <dominik.reichl@t-online.de>
Web: http://www.dominik-reichl.de/
If you're using this class, it would be nice if you'd mention
me somewhere in the documentation of your program, but it's
not required.
BLAKE was designed by Jean-Philippe Aumasson, Luca Henzen,
Willi Meier and Raphael C.-W. Phan.
BlakeSharp was derived from the reference C implementation.
*/
using System;
namespace Blake2Sharp
{
public sealed partial class Blake2BCore
{
private bool _isInitialized = false;
private int _bufferFilled;
private byte[] _buf = new byte[128];
private ulong[] _m = new ulong[16];
private ulong[] _h = new ulong[8];
private ulong _counter0;
private ulong _counter1;
private ulong _finalizationFlag0;
private ulong _finalizationFlag1;
private const int NumberOfRounds = 12;
private const int BlockSizeInBytes = 128;
const ulong IV0 = 0x6A09E667F3BCC908UL;
const ulong IV1 = 0xBB67AE8584CAA73BUL;
const ulong IV2 = 0x3C6EF372FE94F82BUL;
const ulong IV3 = 0xA54FF53A5F1D36F1UL;
const ulong IV4 = 0x510E527FADE682D1UL;
const ulong IV5 = 0x9B05688C2B3E6C1FUL;
const ulong IV6 = 0x1F83D9ABFB41BD6BUL;
const ulong IV7 = 0x5BE0CD19137E2179UL;
private static readonly int[] Sigma = new int[NumberOfRounds * 16] {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
};
internal static ulong BytesToUInt64(byte[] buf, int offset)
{
return
((ulong)buf[offset + 7] << 7 * 8 |
((ulong)buf[offset + 6] << 6 * 8) |
((ulong)buf[offset + 5] << 5 * 8) |
((ulong)buf[offset + 4] << 4 * 8) |
((ulong)buf[offset + 3] << 3 * 8) |
((ulong)buf[offset + 2] << 2 * 8) |
((ulong)buf[offset + 1] << 1 * 8) |
((ulong)buf[offset]));
}
private static void UInt64ToBytes(ulong value, byte[] buf, int offset)
{
buf[offset + 7] = (byte)(value >> 7 * 8);
buf[offset + 6] = (byte)(value >> 6 * 8);
buf[offset + 5] = (byte)(value >> 5 * 8);
buf[offset + 4] = (byte)(value >> 4 * 8);
buf[offset + 3] = (byte)(value >> 3 * 8);
buf[offset + 2] = (byte)(value >> 2 * 8);
buf[offset + 1] = (byte)(value >> 1 * 8);
buf[offset] = (byte)value;
}
partial void Compress(byte[] block, int start);
public void Initialize(ulong[] config)
{
if (config == null)
throw new ArgumentNullException("config");
if (config.Length != 8)
throw new ArgumentException("config length must be 8 words");
_isInitialized = true;
_h[0] = IV0;
_h[1] = IV1;
_h[2] = IV2;
_h[3] = IV3;
_h[4] = IV4;
_h[5] = IV5;
_h[6] = IV6;
_h[7] = IV7;
_counter0 = 0;
_counter1 = 0;
_finalizationFlag0 = 0;
_finalizationFlag1 = 0;
_bufferFilled = 0;
Array.Clear(_buf, 0, _buf.Length);
for (int i = 0; i < 8; i++)
_h[i] ^= config[i];
}
public void HashCore(byte[] array, int start, int count)
{
if (!_isInitialized)
throw new InvalidOperationException("Not initialized");
if (array == null)
throw new ArgumentNullException("array");
if (start < 0)
throw new ArgumentOutOfRangeException("start");
if (count < 0)
throw new ArgumentOutOfRangeException("count");
if ((long)start + (long)count > array.Length)
throw new ArgumentOutOfRangeException("start+count");
int offset = start;
int bufferRemaining = BlockSizeInBytes - _bufferFilled;
if ((_bufferFilled > 0) && (count > bufferRemaining))
{
Array.Copy(array, offset, _buf, _bufferFilled, bufferRemaining);
_counter0 += BlockSizeInBytes;
if (_counter0 == 0)
_counter1++;
Compress(_buf, 0);
offset += bufferRemaining;
count -= bufferRemaining;
_bufferFilled = 0;
}
while (count > BlockSizeInBytes)
{
_counter0 += BlockSizeInBytes;
if (_counter0 == 0)
_counter1++;
Compress(array, offset);
offset += BlockSizeInBytes;
count -= BlockSizeInBytes;
}
if (count > 0)
{
Array.Copy(array, offset, _buf, _bufferFilled, count);
_bufferFilled += count;
}
}
public byte[] HashFinal()
{
return HashFinal(false);
}
public byte[] HashFinal(bool isEndOfLayer)
{
if (!_isInitialized)
throw new InvalidOperationException("Not initialized");
_isInitialized = false;
//Last compression
_counter0 += (uint)_bufferFilled;
_finalizationFlag0 = ulong.MaxValue;
if (isEndOfLayer)
_finalizationFlag1 = ulong.MaxValue;
for (int i = _bufferFilled; i < _buf.Length; i++)
_buf[i] = 0;
Compress(_buf, 0);
//Output
byte[] hash = new byte[64];
for (int i = 0; i < 8; ++i)
UInt64ToBytes(_h[i], hash, i << 3);
return hash;
}
}
}

View File

@@ -0,0 +1,66 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
using System.Collections.Generic;
using System.Text;
namespace Blake2Sharp
{
internal class Blake2BHasher : Hasher
{
private readonly Blake2BCore core = new Blake2BCore();
private readonly ulong[] rawConfig;
private readonly byte[] key;
private readonly int outputSizeInBytes;
private static readonly Blake2BConfig DefaultConfig = new Blake2BConfig();
public override void Init()
{
core.Initialize(rawConfig);
if (key != null)
{
core.HashCore(key, 0, key.Length);
}
}
public override byte[] Finish()
{
var fullResult = core.HashFinal();
if (outputSizeInBytes != fullResult.Length)
{
var result = new byte[outputSizeInBytes];
Array.Copy(fullResult, result, result.Length);
return result;
}
else return fullResult;
}
public Blake2BHasher(Blake2BConfig config)
{
if (config == null)
config = DefaultConfig;
rawConfig = Blake2IvBuilder.ConfigB(config, null);
if (config.Key != null && config.Key.Length != 0)
{
key = new byte[128];
Array.Copy(config.Key, key, config.Key.Length);
}
outputSizeInBytes = config.OutputSizeInBytes;
Init();
}
public override void Update(byte[] data, int start, int count)
{
core.HashCore(data, start, count);
}
}
}

View File

@@ -0,0 +1,52 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
using System.Collections.Generic;
using System.Text;
namespace Blake2Sharp
{
/*public class Blake2BNodeHasher : NodeHasher
{
ulong[] rawConfig;
byte[] key;
Blake2BCore core = new Blake2BCore();
public override void Init(int depth, long nodeOffset)
{
throw new NotImplementedException();
}
public override byte[] Finish(bool isEndOfLayer)
{
throw new NotImplementedException();
}
public override void Update(byte[] data, int start, int count)
{
throw new NotImplementedException();
}
public Blake2BNodeHasher(Blake2BConfig config, Blake2BTreeConfig treeConfig)
{
if (config == null)
config = DefaultConfig;
rawConfig = Blake2IvBuilder.ConfigB(config, null);
if (config.Key != null && config.Key.Length != 0)
{
key = new byte[128];
Array.Copy(config.Key, key, config.Key.Length);
}
Init(0, 0);
}
}*/
}

View File

@@ -0,0 +1,52 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
namespace Blake2Sharp
{
public sealed class Blake2BTreeConfig : ICloneable
{
public int IntermediateHashSize { get; set; }
public int MaxHeight { get; set; }
public long LeafSize { get; set; }
public int FanOut { get; set; }
public Blake2BTreeConfig()
{
IntermediateHashSize = 64;
}
public Blake2BTreeConfig Clone()
{
var result = new Blake2BTreeConfig();
result.IntermediateHashSize = IntermediateHashSize;
result.MaxHeight = MaxHeight;
result.LeafSize = LeafSize;
result.FanOut = FanOut;
return result;
}
public static Blake2BTreeConfig CreateInterleaved(int parallelism)
{
var result = new Blake2BTreeConfig();
result.FanOut = parallelism;
result.MaxHeight = 2;
result.IntermediateHashSize = 64;
return result;
}
object ICloneable.Clone()
{
return Clone();
}
}
}

View File

@@ -0,0 +1,76 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
namespace Blake2Sharp
{
internal static class Blake2IvBuilder
{
private static readonly Blake2BTreeConfig SequentialTreeConfig = new Blake2BTreeConfig() { IntermediateHashSize = 0, LeafSize = 0, FanOut = 1, MaxHeight = 1 };
public static ulong[] ConfigB(Blake2BConfig config, Blake2BTreeConfig treeConfig)
{
bool isSequential = treeConfig == null;
if (isSequential)
treeConfig = SequentialTreeConfig;
var rawConfig = new ulong[8];
var result = new ulong[8];
//digest length
if (config.OutputSizeInBytes <= 0 | config.OutputSizeInBytes > 64)
throw new ArgumentOutOfRangeException("config.OutputSize");
rawConfig[0] |= (ulong)(uint)config.OutputSizeInBytes;
//Key length
if (config.Key != null)
{
if (config.Key.Length > 64)
throw new ArgumentException("config.Key", "Key too long");
rawConfig[0] |= (ulong)((uint)config.Key.Length << 8);
}
// FanOut
rawConfig[0] |= (uint)treeConfig.FanOut << 16;
// Depth
rawConfig[0] |= (uint)treeConfig.MaxHeight << 24;
// Leaf length
rawConfig[0] |= ((ulong)(uint)treeConfig.LeafSize) << 32;
// Inner length
if (!isSequential && (treeConfig.IntermediateHashSize <= 0 || treeConfig.IntermediateHashSize > 64))
throw new ArgumentOutOfRangeException("treeConfig.TreeIntermediateHashSize");
rawConfig[2] |= (uint)treeConfig.IntermediateHashSize << 8;
// Salt
if (config.Salt != null)
{
if (config.Salt.Length != 16)
throw new ArgumentException("config.Salt has invalid length");
rawConfig[4] = Blake2BCore.BytesToUInt64(config.Salt, 0);
rawConfig[5] = Blake2BCore.BytesToUInt64(config.Salt, 8);
}
// Personalization
if (config.Personalization != null)
{
if (config.Personalization.Length != 16)
throw new ArgumentException("config.Personalization has invalid length");
rawConfig[6] = Blake2BCore.BytesToUInt64(config.Personalization, 0);
rawConfig[7] = Blake2BCore.BytesToUInt64(config.Personalization, 8);
}
return rawConfig;
}
public static void ConfigBSetNode(ulong[] rawConfig, byte depth, ulong nodeOffset)
{
rawConfig[1] = nodeOffset;
rawConfig[2] = (rawConfig[2] & ~0xFFul) | depth;
}
}
}

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E21AB364-9130-4F14-ABE1-18FA0C089130}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Blake2Sharp</RootNamespace>
<AssemblyName>Blake2Sharp</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Blake2B.cs" />
<Compile Include="Blake2BCore.cs" />
<Compile Include="Blake2BNodeHasher.cs" />
<Compile Include="Blake2BConfig.cs" />
<Compile Include="Blake2BCore-FullyUnrolled.cs" />
<Compile Include="Blake2IvBuilder.cs" />
<Compile Include="Blake2BTreeConfig.cs" />
<Compile Include="Blake2BCore-Simple.cs" />
<Compile Include="Blake2BCore-Inline.cs" />
<Compile Include="Blake2BHasher.cs" />
<Compile Include="NodeHasher.cs" />
<Compile Include="Hasher.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TreeHasher.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,60 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
namespace Blake2Sharp
{
public abstract class Hasher
{
public abstract void Init();
public abstract byte[] Finish();
public abstract void Update(byte[] data, int start, int count);
public void Update(byte[] data)
{
Update(data, 0, data.Length);
}
public HashAlgorithm AsHashAlgorithm()
{
return new HashAlgorithmAdapter(this);
}
internal class HashAlgorithmAdapter : HashAlgorithm
{
private readonly Hasher _hasher;
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
_hasher.Update(array, ibStart, cbSize);
}
protected override byte[] HashFinal()
{
return _hasher.Finish();
}
public override void Initialize()
{
_hasher.Init();
}
public HashAlgorithmAdapter(Hasher hasher)
{
_hasher = hasher;
}
}
}
}

View File

@@ -0,0 +1,30 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
namespace Blake2Sharp
{
public abstract class NodeHasher
{
public abstract void Init(int depth, long nodeOffset);
public abstract byte[] Finish(bool isEndOfLayer);
public abstract void Update(byte[] data, int start, int count);
public void Update(byte[] data)
{
Update(data, 0, data.Length);
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Blake2Sharp")]
[assembly: AssemblyDescription("Blake2 Hashfunction")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("CodesInChaos")]
[assembly: AssemblyProduct("Blake2Sharp")]
[assembly: AssemblyCopyright("Public Domain")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b7361e6c-1a16-4653-9afb-134066503c8f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,77 @@
// BLAKE2 reference source code package - C# implementation
// Written in 2012 by Christian Winnerlein <codesinchaos@gmail.com>
// To the extent possible under law, the author(s) have dedicated all copyright
// and related and neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
using System;
using System.Collections.Generic;
using System.Text;
namespace Blake2Sharp
{
/*public class TreeHasher : Hasher
{
NodeHasher nodeHasher;
int maxDepth;
int maxLeafSize;
int currentLeafSize;
int fanOut;
List<byte[]>[] intermediateHashes;
long[] counts;
public override void Init()
{
intermediateHashes = new List<byte[]>[maxDepth];
counts = new long[maxDepth];
}
public override byte[] Finish()
{
for (int layer = 0; layer < intermediateHashes.Length; layer++)
{
if (intermediateHashes[layer].Count > 0)
{
nodeHasher.Init(layer, counts[layer]);
foreach (var hash in intermediateHashes[layer])
nodeHasher.Update(hash);
}
}
intermediateHashes = null;
}
public override void Update(byte[] data, int start, int count)
{
while (count > 0)
{
int toHash = Math.Min(maxLeafSize - currentLeafSize, count);
nodeHasher.Update(data, start, toHash);
start += toHash;
count -= toHash;
if (count > 0)
{
intermediateHashes[0].Add(nodeHasher.Finish(false));
for (int layer = 0; layer < intermediateHashes.Length; layer++)
{
if ((layer + 1 < maxDepth) && (intermediateHashes[layer].Count == fanOut))
{
nodeHasher.Init(layer, counts[layer]);
foreach (var hash in intermediateHashes[layer])
nodeHasher.Update(hash);
intermediateHashes[layer + 1].Add(nodeHasher.Finish);
intermediateHashes[layer].Clear();
counts[layer + 1]++;
}
}
counts[0]++;
nodeHasher.Init(0, counts[0]);
}
}
}
}*/
}

View File

@@ -0,0 +1,26 @@
#define ROT(x, y)\
((x >> y)|(x << (64-y)))
#define G(r,i,a,b,c,d) \
YY G(r,i,a,b,c,d) XXX\
a = a + b + m[Sigma[16*r+2*i+0]]; XXX\
d ^= a; XXX\
d = ROT(d, 32); XXX\
c = c + d; XXX\
b ^= c; XXX\
b = ROT(b, 24); XXX\
a = a + b + m[Sigma[16*r+2*i+1]]; XXX\
d ^= a; XXX\
d = ROT(d, 16); XXX\
c = c + d; XXX\
b ^= c; XXX\
b = ROT(b, 63); XXX
G( r, 0, v0, v4, v8, v12 )
G( r, 1, v1, v5, v9, v13 )
G( r, 2, v2, v6, v10, v14 )
G( r, 3, v3, v7, v11, v15 )
G( r, 4, v0, v5, v10, v15 )
G( r, 5, v1, v6, v11, v12 )
G( r, 6, v2, v7, v8, v13 )
G( r, 7, v3, v4, v9, v14 )