Skip to content

Commit 814d47a

Browse files
committed
Fix groestl hashing, and add support for myriadcoin groestl
1 parent 7ca648c commit 814d47a

File tree

6 files changed

+501
-871
lines changed

6 files changed

+501
-871
lines changed

groestl.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,42 @@
55
#include <stdio.h>
66

77
#include "sha3/sph_groestl.h"
8-
8+
#include "sha256.h"
99

1010
void groestl_hash(const char* input, char* output, unsigned int len)
1111
{
12-
sph_groestl256_context ctx_groestl;
13-
sph_groestl256_init(&ctx_groestl);
14-
sph_groestl256(&ctx_groestl, input, len);
15-
sph_groestl256_close(&ctx_groestl, output);
12+
char* hash1 = (char*) malloc(64);
13+
char* hash2 = (char*) malloc(64);
14+
15+
sph_groestl512_context ctx_groestl;
16+
sph_groestl512_init(&ctx_groestl);
17+
sph_groestl512(&ctx_groestl, input, len);
18+
sph_groestl512_close(&ctx_groestl, hash1);
19+
20+
sph_groestl512_init(&ctx_groestl);
21+
sph_groestl512(&ctx_groestl, hash1, 64);
22+
sph_groestl512_close(&ctx_groestl, hash2);
23+
24+
memcpy(output, hash2, 32);
25+
26+
free(hash1);
27+
free(hash2);
28+
}
29+
30+
void groestl_myriad_hash(const char* input, char* output, unsigned int len)
31+
{
32+
char* temp = (char*) malloc(64);
33+
34+
sph_groestl512_context ctx_groestl;
35+
sph_groestl512_init(&ctx_groestl);
36+
sph_groestl512(&ctx_groestl, input, len);
37+
sph_groestl512_close(&ctx_groestl, temp);
38+
39+
SHA256_CTX ctx_sha256;
40+
SHA256_Init(&ctx_sha256);
41+
SHA256_Update(&ctx_sha256, temp, 64);
42+
SHA256_Final(output, &ctx_sha256);
43+
44+
free(temp);
1645
}
1746

groestl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern "C" {
66
#endif
77

88
void groestl_hash(const char* input, char* output, unsigned int len);
9+
void groestl_myriad_hash(const char* input, char* output, unsigned int len);
910

1011
#ifdef __cplusplus
1112
}

multihashing.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,29 @@ Handle<Value> groestl(const Arguments& args) {
278278
}
279279

280280

281+
Handle<Value> groestl_myriad(const Arguments& args) {
282+
HandleScope scope;
283+
284+
if (args.Length() < 1)
285+
return except("You must provide one argument.");
286+
287+
Local<Object> target = args[0]->ToObject();
288+
289+
if(!Buffer::HasInstance(target))
290+
return except("Argument should be a buffer object.");
291+
292+
char * input = Buffer::Data(target);
293+
char * output = new char[32];
294+
295+
unsigned int input_len = Buffer::Length(target);
296+
297+
groestl_myriad_hash(input, output, input_len);
298+
299+
Buffer* buff = Buffer::New(output, 32);
300+
return scope.Close(buff->handle_);
301+
}
302+
303+
281304
Handle<Value> blake(const Arguments& args) {
282305
HandleScope scope;
283306

@@ -309,6 +332,7 @@ void init(Handle<Object> exports) {
309332
exports->Set(String::NewSymbol("bcrypt"), FunctionTemplate::New(bcrypt)->GetFunction());
310333
exports->Set(String::NewSymbol("skein"), FunctionTemplate::New(skein)->GetFunction());
311334
exports->Set(String::NewSymbol("groestl"), FunctionTemplate::New(groestl)->GetFunction());
335+
exports->Set(String::NewSymbol("groestl_myriad"), FunctionTemplate::New(groestl_myriad)->GetFunction());
312336
exports->Set(String::NewSymbol("blake"), FunctionTemplate::New(blake)->GetFunction());
313337
}
314338

0 commit comments

Comments
 (0)