Skip to content

Commit 6c78b8a

Browse files
committed
Add Interchained Algorithms
1 parent 79e0b95 commit 6c78b8a

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Miningcore.Contracts;
2+
using Miningcore.Native;
3+
4+
namespace Miningcore.Crypto.Hashing.Algorithms;
5+
6+
[Identifier("interchained")]
7+
public unsafe class Interchained : IHashAlgorithm
8+
{
9+
public void Digest(ReadOnlySpan<byte> data, Span<byte> result, params object[] extra)
10+
{
11+
Contract.Requires<ArgumentException>(result.Length >= 32);
12+
13+
fixed (byte* input = data)
14+
{
15+
fixed (byte* output = result)
16+
{
17+
Multihash.interchained(input, output, (uint) data.Length);
18+
}
19+
}
20+
}
21+
}

src/Miningcore/Native/Multihash.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ public static unsafe class Multihash
226226
[DllImport("libmultihash", EntryPoint = "power2b_export", CallingConvention = CallingConvention.Cdecl)]
227227
public static extern void power2b(byte* input, void* output, uint inputLength);
228228

229+
[DllImport("libmultihash", EntryPoint = "interchained_export", CallingConvention = CallingConvention.Cdecl)]
230+
public static extern void interchained(byte* input, void* output, uint inputLength);
231+
229232
[DllImport("libmultihash", EntryPoint = "yespower_export", CallingConvention = CallingConvention.Cdecl)]
230233
public static extern void yespower(byte* input, void* output, uint inputLength);
231234

src/Native/libmultihash/exports.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ extern "C" MODULE_API void power2b_export(const char *input, char *output, uint3
443443
power2b_hash(input, output, input_len);
444444
}
445445

446+
extern "C" MODULE_API void interchained_export(const char *input, char *output, uint32_t input_len)
447+
{
448+
interchained_hash(input, output, input_len);
449+
}
446450
extern "C" MODULE_API void yespower_export(const char *input, char *output, uint32_t input_len)
447451
{
448452
yespower_hash(input, output, input_len);

src/Native/libmultihash/yespower/yespower-combined.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,3 +1337,15 @@ void yespowerEQPAY_hash(const char* input, char* output, uint32_t len)
13371337
yespower_tls(input, len, &yespower_1_0_EQPAY, (yespower_binary_t *)output);
13381338
}
13391339

1340+
void interchained_hash(const char* input, char* output, uint32_t len)
1341+
{
1342+
yespower_params_t yespower_1_0_interchained = {
1343+
.version = YESPOWER_1_0,
1344+
.N = 1024,
1345+
.r = 8,
1346+
.pers = NULL,
1347+
.perslen = 0
1348+
};
1349+
yespower_tls( input, len, &yespower_1_0_interchained, (yespower_binary_t *)output);
1350+
}
1351+

src/Native/libmultihash/yespower/yespower.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ void yespowerMGPC_hash(const char* input, char* output, uint32_t len);
146146
void yespowerARWN_hash(const char* input, char* output, uint32_t len);
147147
void yespowerADVC_hash(const char* input, char* output, uint32_t len);
148148
void yespowerEQPAY_hash(const char* input, char* output, uint32_t len);
149+
void interchained_hash(const char* input, char* output, uint32_t len);
149150

150151
#ifdef __cplusplus
151152
}

0 commit comments

Comments
 (0)