Skip to content

Commit b189052

Browse files
committed
Merge pull request PhearNet#4 from LucasJones/master
Add skein and blake support
2 parents a598ea1 + 7ca648c commit b189052

File tree

17 files changed

+609
-28
lines changed

17 files changed

+609
-28
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ So far this native Node.js addon can do the following hashing algos
2121
```javascript
2222
var multiHashing = require('multi-hashing');
2323

24-
var algorithms = ['quark', 'x11', 'scrypt', 'scryptn', 'scryptjane', 'keccak', 'bcrypt'];
24+
var algorithms = ['quark', 'x11', 'scrypt', 'scryptn', 'scryptjane', 'keccak', 'bcrypt', 'skein', 'blake'];
2525

26-
var data = new Buffer("hash me good bro");
26+
var data = new Buffer("7000000001e980924e4e1109230383e66d62945ff8e749903bea4336755c00000000000051928aff1b4d72416173a8c3948159a09a73ac3bb556aa6bfbcad1a85da7f4c1d13350531e24031b939b9e2b", "hex");
2727

2828
var hashedData = algorithms.map(function(algo){
2929
if (algo === 'scryptjane'){
@@ -33,7 +33,7 @@ var hashedData = algorithms.map(function(algo){
3333
return multiHashing[algo](data, nTime, yaCoinChainStartTime);
3434
}
3535
else{
36-
return return multiHashing[algo](data);
36+
return multiHashing[algo](data);
3737
}
3838
});
3939

@@ -42,7 +42,7 @@ console.log(hashedData);
4242
//<SlowBuffer 0b de 16 ef 2d 92 e4 35 65 c6 6c d8 92 d9 66 b4 3d 65 ..... >
4343

4444
//Another example...
45-
var hashedScryptData = multiHashing.scrypt(new Buffer(32));
45+
var hashedScryptData = multiHashing.scrypt(new Buffer(80));
4646

4747
```
4848

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: 79 additions & 3 deletions
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))
@@ -75,8 +77,10 @@ Handle<Value> quark(const Arguments& args) {
7577

7678
char * input = Buffer::Data(target);
7779
char * output = new char[32];
80+
81+
unsigned int input_len = Buffer::Length(target);
7882

79-
quark_hash(input, output);
83+
quark_hash(input, output, input_len);
8084

8185
Buffer* buff = Buffer::New(output, 32);
8286
return scope.Close(buff->handle_);
@@ -96,7 +100,9 @@ Handle<Value> x11(const Arguments& args) {
96100
char * input = Buffer::Data(target);
97101
char * output = new char[32];
98102

99-
x11_hash(input, output);
103+
unsigned int input_len = Buffer::Length(target);
104+
105+
x11_hash(input, output, input_len);
100106

101107
Buffer* buff = Buffer::New(output, 32);
102108
return scope.Close(buff->handle_);
@@ -197,7 +203,7 @@ Handle<Value> keccak(const Arguments& args) {
197203
char * input = Buffer::Data(target);
198204
char * output = new char[32];
199205

200-
int* dSize = (int*)Buffer::Length(target);
206+
unsigned int dSize = Buffer::Length(target);
201207

202208
keccak_hash(input, output, dSize);
203209

@@ -226,6 +232,73 @@ Handle<Value> bcrypt(const Arguments& args) {
226232
return scope.Close(buff->handle_);
227233
}
228234

235+
Handle<Value> skein(const Arguments& args) {
236+
HandleScope scope;
237+
238+
if (args.Length() < 1)
239+
return except("You must provide one argument.");
240+
241+
Local<Object> target = args[0]->ToObject();
242+
243+
if(!Buffer::HasInstance(target))
244+
return except("Argument should be a buffer object.");
245+
246+
char * input = Buffer::Data(target);
247+
char * output = new char[32];
248+
249+
unsigned int input_len = Buffer::Length(target);
250+
251+
skein_hash(input, output, input_len);
252+
253+
Buffer* buff = Buffer::New(output, 32);
254+
return scope.Close(buff->handle_);
255+
}
256+
257+
258+
Handle<Value> groestl(const Arguments& args) {
259+
HandleScope scope;
260+
261+
if (args.Length() < 1)
262+
return except("You must provide one argument.");
263+
264+
Local<Object> target = args[0]->ToObject();
265+
266+
if(!Buffer::HasInstance(target))
267+
return except("Argument should be a buffer object.");
268+
269+
char * input = Buffer::Data(target);
270+
char * output = new char[32];
271+
272+
unsigned int input_len = Buffer::Length(target);
273+
274+
groestl_hash(input, output, input_len);
275+
276+
Buffer* buff = Buffer::New(output, 32);
277+
return scope.Close(buff->handle_);
278+
}
279+
280+
281+
Handle<Value> blake(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+
blake_hash(input, output, input_len);
298+
299+
Buffer* buff = Buffer::New(output, 32);
300+
return scope.Close(buff->handle_);
301+
}
229302
void init(Handle<Object> exports) {
230303
exports->Set(String::NewSymbol("quark"), FunctionTemplate::New(quark)->GetFunction());
231304
exports->Set(String::NewSymbol("x11"), FunctionTemplate::New(x11)->GetFunction());
@@ -234,6 +307,9 @@ void init(Handle<Object> exports) {
234307
exports->Set(String::NewSymbol("scryptjane"), FunctionTemplate::New(scryptjane)->GetFunction());
235308
exports->Set(String::NewSymbol("keccak"), FunctionTemplate::New(keccak)->GetFunction());
236309
exports->Set(String::NewSymbol("bcrypt"), FunctionTemplate::New(bcrypt)->GetFunction());
310+
exports->Set(String::NewSymbol("skein"), FunctionTemplate::New(skein)->GetFunction());
311+
exports->Set(String::NewSymbol("groestl"), FunctionTemplate::New(groestl)->GetFunction());
312+
exports->Set(String::NewSymbol("blake"), FunctionTemplate::New(blake)->GetFunction());
237313
}
238314

239315
NODE_MODULE(multihashing, init)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "multi-hashing",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"main": "multihashing",
55
"author": {
66
"name": "Matthew Little",
@@ -27,4 +27,4 @@
2727
"shavite",
2828
"fugue"
2929
]
30-
}
30+
}

0 commit comments

Comments
 (0)