Skip to content

Commit 1feaf0e

Browse files
committed
Initial support for skein, blake and groestl
1 parent a598ea1 commit 1feaf0e

File tree

10 files changed

+142
-9
lines changed

10 files changed

+142
-9
lines changed

binding.gyp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"x11.c",
1313
"quark.c",
1414
"bcrypt.c",
15+
"groestl.c",
16+
"blake.c",
1517
"sha3/aes_helper.c",
1618
"sha3/sph_blake.c",
1719
"sha3/sph_bmw.c",

blake.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "blake.h"
2+
#include <stdlib.h>
3+
#include <stdint.h>
4+
#include <string.h>
5+
#include <stdio.h>
6+
7+
#include "sha3/sph_blake.h"
8+
9+
10+
void blake_hash(const char* input, char* output, unsigned int len)
11+
{
12+
sph_blake256_context ctx_blake;
13+
sph_blake256_init(&ctx_blake);
14+
sph_blake256(&ctx_blake, input, len);
15+
sph_blake256_close(&ctx_blake, output);
16+
}
17+

blake.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef BLAKE_H
2+
#define BLAKE_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
void blake_hash(const char* input, char* output, unsigned int len);
9+
10+
#ifdef __cplusplus
11+
}
12+
#endif
13+
14+
#endif

groestl.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "groestl.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+
9+
10+
void groestl_hash(const char* input, char* output, unsigned int len)
11+
{
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);
16+
}
17+

groestl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef GROESTL_H
2+
#define GROESTL_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
void groestl_hash(const char* input, char* output, unsigned int len);
9+
10+
#ifdef __cplusplus
11+
}
12+
#endif
13+
14+
#endif

keccak.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "sha3/sph_keccak.h"
99

1010

11-
void keccak_hash(const char* input, char* output, int * size)
11+
void keccak_hash(const char* input, char* output, unsigned int size)
1212
{
1313
sph_keccak256_context ctx_keccak;
1414
sph_keccak256_init(&ctx_keccak);

keccak.h

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

8-
void keccak_hash(const char* input, char* output, int * size);
8+
void keccak_hash(const char* input, char* output, unsigned int size);
99

1010
#ifdef __cplusplus
1111
}

multihashing.cc

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ extern "C" {
1111
#include "scryptn.h"
1212
#include "skein.h"
1313
#include "x11.h"
14+
#include "groestl.h"
15+
#include "blake.h"
1416

1517

1618
#define max(a,b) (((a) > (b)) ? (a) : (b))
@@ -197,7 +199,7 @@ Handle<Value> keccak(const Arguments& args) {
197199
char * input = Buffer::Data(target);
198200
char * output = new char[32];
199201

200-
int* dSize = (int*)Buffer::Length(target);
202+
unsigned int dSize = Buffer::Length(target);
201203

202204
keccak_hash(input, output, dSize);
203205

@@ -226,6 +228,70 @@ Handle<Value> bcrypt(const Arguments& args) {
226228
return scope.Close(buff->handle_);
227229
}
228230

231+
Handle<Value> skein(const Arguments& args) {
232+
HandleScope scope;
233+
234+
if (args.Length() < 1)
235+
return except("You must provide one argument.");
236+
237+
Local<Object> target = args[0]->ToObject();
238+
239+
if(!Buffer::HasInstance(target))
240+
return except("Argument should be a buffer object.");
241+
242+
char * input = Buffer::Data(target);
243+
unsigned int input_len = Buffer::Length(target);
244+
char * output = new char[32];
245+
246+
skein_hash(input, output, input_len);
247+
248+
Buffer* buff = Buffer::New(output, 32);
249+
return scope.Close(buff->handle_);
250+
}
251+
252+
253+
Handle<Value> groestl(const Arguments& args) {
254+
HandleScope scope;
255+
256+
if (args.Length() < 1)
257+
return except("You must provide one argument.");
258+
259+
Local<Object> target = args[0]->ToObject();
260+
261+
if(!Buffer::HasInstance(target))
262+
return except("Argument should be a buffer object.");
263+
264+
char * input = Buffer::Data(target);
265+
unsigned int input_len = Buffer::Length(target);
266+
char * output = new char[32];
267+
268+
groestl_hash(input, output, input_len);
269+
270+
Buffer* buff = Buffer::New(output, 32);
271+
return scope.Close(buff->handle_);
272+
}
273+
274+
275+
Handle<Value> blake(const Arguments& args) {
276+
HandleScope scope;
277+
278+
if (args.Length() < 1)
279+
return except("You must provide one argument.");
280+
281+
Local<Object> target = args[0]->ToObject();
282+
283+
if(!Buffer::HasInstance(target))
284+
return except("Argument should be a buffer object.");
285+
286+
char * input = Buffer::Data(target);
287+
unsigned int input_len = Buffer::Length(target);
288+
char * output = new char[32];
289+
290+
blake_hash(input, output, input_len);
291+
292+
Buffer* buff = Buffer::New(output, 32);
293+
return scope.Close(buff->handle_);
294+
}
229295
void init(Handle<Object> exports) {
230296
exports->Set(String::NewSymbol("quark"), FunctionTemplate::New(quark)->GetFunction());
231297
exports->Set(String::NewSymbol("x11"), FunctionTemplate::New(x11)->GetFunction());
@@ -234,6 +300,9 @@ void init(Handle<Object> exports) {
234300
exports->Set(String::NewSymbol("scryptjane"), FunctionTemplate::New(scryptjane)->GetFunction());
235301
exports->Set(String::NewSymbol("keccak"), FunctionTemplate::New(keccak)->GetFunction());
236302
exports->Set(String::NewSymbol("bcrypt"), FunctionTemplate::New(bcrypt)->GetFunction());
303+
exports->Set(String::NewSymbol("skein"), FunctionTemplate::New(skein)->GetFunction());
304+
exports->Set(String::NewSymbol("groestl"), FunctionTemplate::New(groestl)->GetFunction());
305+
exports->Set(String::NewSymbol("blake"), FunctionTemplate::New(blake)->GetFunction());
237306
}
238307

239308
NODE_MODULE(multihashing, init)

skein.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#include "sha3/sph_skein.h"
88

99

10-
void skein_hash(const char* input, char* output)
10+
void skein_hash(const char* input, char* output, unsigned int len)
1111
{
12-
sph_skein512_context ctx_skien;
13-
sph_skein512_init(&ctx_skien);
14-
sph_skein512(&ctx_skien, input, 64);
15-
sph_skein512_close(&ctx_skien, output);
12+
sph_skein256_context ctx_skien;
13+
sph_skein256_init(&ctx_skien);
14+
sph_skein256(&ctx_skien, input, len);
15+
sph_skein256_close(&ctx_skien, output);
1616
}
1717

skein.h

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

8-
void skein_hash(const char* input, char* output);
8+
void skein_hash(const char* input, char* output, unsigned int len);
99

1010
#ifdef __cplusplus
1111
}

0 commit comments

Comments
 (0)