Skip to content

Commit

Permalink
Add MegaBTX Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolin1579 committed Jul 3, 2024
1 parent ceb09ab commit 670a340
Show file tree
Hide file tree
Showing 7 changed files with 423 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/Miningcore/Crypto/Hashing/Algorithms/MegaBTX.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("megabtx")]
public unsafe class MegaBTX : 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.megabtx(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 @@ -196,6 +196,9 @@ public static unsafe class Multihash
[DllImport("libmultihash", EntryPoint = "aurum_export", CallingConvention = CallingConvention.Cdecl)]
public static extern void aurum(byte* input, void* output, uint inputLength);

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/Native/libmultihash/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LDFLAGS = -shared
LDLIBS = -lsodium
TARGET = libmultihash.so

OBJECTS = allium.o aurum.o bcrypt.o blake.o c11.o dcrypt.o fresh.o lane.o memehash.o \
OBJECTS = allium.o aurum.o bcrypt.o blake.o c11.o dcrypt.o fresh.o lane.o megabtx.o memehash.o \
fugue.o groestl.o hefty1.o jh.o keccak.o neoscrypt.o exports.o nist5.o quark.o qubit.o s3.o scryptn.o \
sha256csm.o hmq17.o phi.o \
sha3/aes_helper.o sha3/hamsi.o sha3/hamsi_helper.o sha3/sph_blake.o sha3/sph_bmw.o sha3/sph_cubehash.o \
Expand Down
6 changes: 6 additions & 0 deletions src/Native/libmultihash/exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "shake/cshake.h"
#include "shake/shake.h"
#include "memehash.h"
#include "megabtx.h"

#ifdef _WIN32
#include "blake2/ref/blake2.h"
Expand Down Expand Up @@ -451,3 +452,8 @@ extern "C" MODULE_API void memehash_export(const char *input, char *output, uint
meme_hash(input, output, input_len);
}

extern "C" MODULE_API void megabtx_export(const char *input, char *output, uint32_t input_len)
{
megabtx_hash(input, output, input_len);
}

2 changes: 2 additions & 0 deletions src/Native/libmultihash/libmultihash.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<ClInclude Include="lane.h" />
<ClInclude Include="Lyra2.h" />
<ClInclude Include="Lyra2RE.h" />
<ClInclude Include="megabtx.h" />
<ClInclude Include="memehash.h" />
<ClInclude Include="neoscrypt.h" />
<ClInclude Include="nist5.h" />
Expand Down Expand Up @@ -336,6 +337,7 @@
<ClCompile Include="lane.c" />
<ClCompile Include="Lyra2.c" />
<ClCompile Include="Lyra2RE.c" />
<ClCompile Include="megabtx.c" />
<ClCompile Include="memehash.c" />
<ClCompile Include="neoscrypt.c" />
<ClCompile Include="exports.cpp" />
Expand Down
Loading

0 comments on commit 670a340

Please sign in to comment.