Skip to content

Commit c97a439

Browse files
committed
Add EvoHash Algorithms
1 parent 9cb6551 commit c97a439

File tree

6 files changed

+231
-1
lines changed

6 files changed

+231
-1
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("evohash")]
7+
public unsafe class EvoHash : 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.evohash(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
@@ -253,6 +253,9 @@ public static unsafe class Multihash
253253
[DllImport("libmultihash", EntryPoint = "x11gost_export", CallingConvention = CallingConvention.Cdecl)]
254254
public static extern void x11gost(byte* input, void* output, uint inputLength);
255255

256+
[DllImport("libmultihash", EntryPoint = "evohash_export", CallingConvention = CallingConvention.Cdecl)]
257+
public static extern void evohash(byte* input, void* output, uint inputLength);
258+
256259
[DllImport("libmultihash", EntryPoint = "fishhash_get_context", CallingConvention = CallingConvention.Cdecl)]
257260
public static extern IntPtr fishhashGetContext(bool fullContext = false);
258261

src/Native/libmultihash/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LDFLAGS = -shared
44
LDLIBS = -lsodium
55
TARGET = libmultihash.so
66

7-
OBJECTS = allium.o aurum.o bcrypt.o blake.o c11.o dcrypt.o fresh.o lane.o megabtx.o memehash.o \
7+
OBJECTS = allium.o aurum.o bcrypt.o blake.o c11.o dcrypt.o evohash.o fresh.o lane.o megabtx.o memehash.o \
88
fugue.o groestl.o hefty1.o jh.o keccak.o neoscrypt.o exports.o nist5.o quark.o qubit.o s3.o scryptn.o \
99
sha256csm.o hmq17.o phi.o phi2.o \
1010
sha3/aes_helper.o sha3/hamsi.o sha3/hamsi_helper.o sha3/sph_blake.o sha3/sph_bmw.o sha3/sph_cubehash.o \

src/Native/libmultihash/evohash.c

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#include "evohash.h"
2+
#include <stdlib.h>
3+
#include <stdint.h>
4+
#include <string.h>
5+
#include <stdio.h>
6+
7+
#include "sha3/sph_groestl.h"
8+
#include "sha3/sph_keccak.h"
9+
#include "sha3/sph_jh.h"
10+
#include "sha3/sph_bmw.h"
11+
#include "sha3/sph_skein.h"
12+
#include "sha3/sph_cubehash.h"
13+
#include "sha3/sph_luffa.h"
14+
#include "sha3/sph_shavite.h"
15+
#include "sha3/sph_simd.h"
16+
#include "sha3/sph_echo.h"
17+
#include "sha3/sph_hamsi.h"
18+
#include "sha3/sph_fugue.h"
19+
#include "sha3/sph_whirlpool.h"
20+
#include "sha3/sph_shabal.h"
21+
#include "Lyra2.h"
22+
23+
#define _ALIGN(x) __attribute__ ((aligned(x)))
24+
25+
void evohash_hash(const char* input, char* output, uint32_t len)
26+
{
27+
sph_groestl512_context ctx_groestl;
28+
sph_keccak512_context ctx_keccak;
29+
sph_cubehash512_context ctx_cubehash;
30+
sph_luffa512_context ctx_luffa;
31+
sph_echo512_context ctx_echo;
32+
sph_simd512_context ctx_simd;
33+
sph_shavite512_context ctx_shavite;
34+
sph_hamsi512_context ctx_hamsi;
35+
sph_fugue512_context ctx_fugue;
36+
sph_whirlpool_context ctx_whirlpool;
37+
sph_skein512_context ctx_skein;
38+
sph_shabal512_context ctx_shabal;
39+
sph_bmw512_context ctx_bmw;
40+
sph_jh512_context ctx_jh;
41+
42+
unsigned char hash[128] = { 0 };
43+
unsigned char hashA[64] = { 0 };
44+
unsigned char hashB[64] = { 0 };
45+
46+
sph_cubehash512_init(&ctx_cubehash);
47+
sph_cubehash512(&ctx_cubehash, input, len);
48+
sph_cubehash512_close(&ctx_cubehash, (void*)hash);
49+
50+
sph_bmw512_init(&ctx_bmw);
51+
sph_bmw512(&ctx_bmw, (const void*) hash, 64);
52+
sph_bmw512_close(&ctx_bmw, hashB);
53+
54+
LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8);
55+
LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8);
56+
57+
sph_groestl512_init(&ctx_groestl);
58+
sph_groestl512 (&ctx_groestl, hashA, 64);
59+
sph_groestl512_close(&ctx_groestl, hash);
60+
61+
sph_hamsi512_init(&ctx_hamsi);
62+
sph_hamsi512(&ctx_hamsi, (const void*) hash, 64);
63+
sph_hamsi512_close(&ctx_hamsi, hashB);
64+
65+
LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8);
66+
LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8);
67+
//print_hash("lyra2re_2", hashA, 32);
68+
//printf("Hashing complete.\n");
69+
70+
sph_fugue512_init(&ctx_fugue);
71+
sph_fugue512(&ctx_fugue, (const void*) hashA, 64);
72+
sph_fugue512_close(&ctx_fugue, hash);
73+
//print_hash("fugue512", hash, 16);
74+
//printf("Hashing complete.\n");
75+
76+
sph_simd512_init(&ctx_simd);
77+
sph_simd512(&ctx_simd, (const void*) hash, 64);
78+
sph_simd512_close(&ctx_simd, hashB);
79+
//print_hash("simd512", hashB, 16);
80+
//printf("Hashing complete.\n");
81+
82+
LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8);
83+
LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8);
84+
//print_hash("lyra2re_3", hashA, 32);
85+
//printf("Hashing complete.\n");
86+
87+
sph_echo512_init(&ctx_echo);
88+
sph_echo512(&ctx_echo, (const void*) hashA, 64);
89+
sph_echo512_close(&ctx_echo, hash);
90+
//print_hash("echo512", hash, 16);
91+
//printf("Hashing complete.\n");
92+
93+
sph_cubehash512_init(&ctx_cubehash);
94+
sph_cubehash512(&ctx_cubehash, (const void*) hash, 64);
95+
sph_cubehash512_close(&ctx_cubehash, hashB);
96+
//print_hash("cubehash512_2", hashB, 16);
97+
//printf("Hashing complete.\n");
98+
99+
LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8);
100+
LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8);
101+
//print_hash("lyra2re_4", hashA, 32);
102+
//printf("Hashing complete.\n");
103+
104+
sph_shavite512_init(&ctx_shavite);
105+
sph_shavite512(&ctx_shavite, (const void*) hashA, 64);
106+
sph_shavite512_close(&ctx_shavite, hash);
107+
//print_hash("shavite512_1", hash, 16);
108+
//printf("Hashing complete.\n");
109+
110+
sph_luffa512_init(&ctx_luffa);
111+
sph_luffa512(&ctx_luffa, (const void*) hash, 64);
112+
sph_luffa512_close (&ctx_luffa, hashB);
113+
//print_hash("luffa512_1", hashB, 16);
114+
//printf("Hashing complete.\n");
115+
116+
LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8);
117+
LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8);
118+
//print_hash("lyra2re_5", hashA, 32);
119+
//printf("Hashing complete.\n");
120+
121+
sph_shavite512_init(&ctx_shavite);
122+
sph_shavite512(&ctx_shavite, (const void*) hashA, 64);
123+
sph_shavite512_close(&ctx_shavite, hash);
124+
//print_hash("shavite512_2", hash, 16);
125+
//printf("Hashing complete.\n");
126+
127+
sph_luffa512_init(&ctx_luffa);
128+
sph_luffa512(&ctx_luffa, (const void*) hash, 64);
129+
sph_luffa512_close (&ctx_luffa, hashB);
130+
//print_hash("luffa512_2", hashB, 16);
131+
//printf("Hashing complete.\n");
132+
133+
LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8);
134+
LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8);
135+
//print_hash("lyra2re_6", hashA, 32);
136+
//printf("Hashing complete.\n");
137+
138+
sph_whirlpool_init(&ctx_whirlpool);
139+
sph_whirlpool (&ctx_whirlpool, (const void*) hashA, 64);
140+
sph_whirlpool_close(&ctx_whirlpool, hash);
141+
//print_hash("whirlpool", hash, 16);
142+
//printf("Hashing complete.\n");
143+
144+
sph_shabal512_init(&ctx_shabal);
145+
sph_shabal512(&ctx_shabal, (const void*) hash, 64);
146+
sph_shabal512_close(&ctx_shabal, hashB);
147+
//print_hash("shabal512", hashB, 16);
148+
//printf("Hashing complete.\n");
149+
150+
LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8);
151+
LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8);
152+
//print_hash("lyra2re_7", hashA, 32);
153+
//printf("Hashing complete.\n");
154+
155+
sph_jh512_init(&ctx_jh);
156+
sph_jh512(&ctx_jh, (const void*) hashA, 64);
157+
sph_jh512_close(&ctx_jh, hash);
158+
//print_hash("jh512", hash, 16);
159+
//printf("Hashing complete.\n");
160+
161+
sph_keccak512_init(&ctx_keccak);
162+
sph_keccak512 (&ctx_keccak, hash, 64);
163+
sph_keccak512_close(&ctx_keccak, hashB);
164+
//print_hash("keccak512", hashB, 16);
165+
//printf("Hashing complete.\n");
166+
167+
LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8);
168+
LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8);
169+
//print_hash("lyra2re_8", hashA, 32);
170+
//printf("Hashing complete.\n");
171+
172+
sph_skein512_init(&ctx_skein);
173+
sph_skein512(&ctx_skein, (const void*)hashA, 64);
174+
sph_skein512_close(&ctx_skein, (void*)hash);
175+
//print_hash("skein512", hash, 16);
176+
//printf("Hashing complete.\n");
177+
178+
for (int i=0; i<32; i++)
179+
hash[i] ^= hash[i+32];
180+
181+
memcpy(output, hash, 32);
182+
//printf("Hashing complete.\n");
183+
//getchar();
184+
}

src/Native/libmultihash/evohash.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef EVOHASH_H
2+
#define EVOHASH_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include <stdint.h>
9+
10+
void evohash_hash(const char* input, char* output, uint32_t len);
11+
12+
#ifdef __cplusplus
13+
}
14+
#endif
15+
16+
#endif

src/Native/libmultihash/exports.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7272
#include "xelisv2.h"
7373
#include "x11kvs.h"
7474
#include "argon2d.h"
75+
#include "evohash.h"
7576

7677
#ifdef _WIN32
7778
#include "blake2/ref/blake2.h"
@@ -521,3 +522,8 @@ extern "C" MODULE_API void argon2d16000_export(const char* input, char* output,
521522
{
522523
argon2d16000_hash(input, output, input_len);
523524
}
525+
526+
extern "C" MODULE_API void evohash_export(const char* input, char* output, uint32_t input_len)
527+
{
528+
evohash_hash(input, output, input_len);
529+
}

0 commit comments

Comments
 (0)