Skip to content

Commit

Permalink
Add support for blake3 algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolin1579 committed Dec 10, 2023
1 parent 259f37f commit 15b7f2b
Show file tree
Hide file tree
Showing 26 changed files with 23,588 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Miningcore/Crypto/Hashing/Algorithms/Blake3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Miningcore.Contracts;
using Miningcore.Native;

namespace Miningcore.Crypto.Hashing.Algorithms;

[Identifier("blake3")]
public unsafe class Blake3 : IHashAlgorithm
{
public void Digest(ReadOnlySpan<byte> data, Span<byte> result, params object[] extra)
{
Contract.Requires<ArgumentException>(result.Length >= 32);

fixed (byte* input = data)
{
fixed (byte* output = result)
{
Multihash.blake3(input, output, (uint) data.Length);
}
}
}
}
3 changes: 3 additions & 0 deletions src/Miningcore/Native/Multihash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public static unsafe class Multihash
[DllImport("libmultihash", EntryPoint = "blake2b_export", CallingConvention = CallingConvention.Cdecl)]
public static extern void blake2b(byte* input, void* output, uint inputLength, int outputLength);

[DllImport("libmultihash", EntryPoint = "blake3_export", CallingConvention = CallingConvention.Cdecl)]
public static extern void blake3(byte* input, void* output, uint inputLength);

[DllImport("libmultihash", EntryPoint = "dcrypt_export", CallingConvention = CallingConvention.Cdecl)]
public static extern void dcrypt(byte* input, void* output, uint inputLength);

Expand Down
2 changes: 2 additions & 0 deletions src/Native/libmultihash/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ OBJECTS = allium.o bcrypt.o blake.o c11.o dcrypt.o fresh.o lane.o \
sha3/extra.o sha3/gost_streebog.o sha3/sph_tiger.o sha3/SWIFFTX.o KeccakP-800-reference.o \
shavite3.o skein.o skein2.o x11.o x11gost.o x13.o x15.o x17.o x16r.o x16rt.o x16rv2.o x16s.o x20r.o x21s.o x22i.o \
blake2/sse/blake2s.o blake2/sse/blake2b.o \
blake3/blake3.o blake3/blake3_dispatch.o blake3/blake3_portable.o \
blake3/blake3_sse41_x86-64_unix.o blake3/blake3_avx2_x86-64_unix.o blake3/blake3_avx512_x86-64_unix.o \
Lyra2.o Lyra2RE.o Sponge.o geek.o minotaurx.o memehash.o rwahash.o \
heavyhash/heavyhash.o heavyhash/keccak_tiny.o \
verthash/tiny_sha3/sha3.o verthash/h2.o \
Expand Down
Loading

0 comments on commit 15b7f2b

Please sign in to comment.