Skip to content

Commit cacdbe2

Browse files
committed
Added nist5 hashing
1 parent 0cd36f9 commit cacdbe2

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ node-multi-hashing
77

88
Cryptocurrency hashing functions for node.js.
99

10+
11+
Algorithms
12+
----------
13+
* quark
14+
* x11
15+
* x13
16+
* nist5
17+
* scrypt
18+
* scryptn
19+
* scryptjane
20+
* keccak
21+
* bcrypt
22+
* skein
23+
* groestl
24+
* blake
25+
* fugue
26+
* qubit
27+
* hefty1
28+
* shavite3
29+
* cryptonight
30+
* boolberry
31+
1032
Usage
1133
-----
1234

binding.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"cryptonight.c",
2121
"x13.c",
2222
"boolberry.cc",
23+
"nist5.c",
2324
"sha3/sph_hefty1.c",
2425
"sha3/sph_fugue.c",
2526
"sha3/aes_helper.c",

multihashing.cc

+24
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern "C" {
1919
#include "shavite3.h"
2020
#include "cryptonight.h"
2121
#include "x13.h"
22+
#include "nist5.h"
2223
}
2324

2425
#include "boolberry.h"
@@ -482,6 +483,28 @@ Handle<Value> boolberry(const Arguments& args) {
482483
return scope.Close(buff->handle_);
483484
}
484485

486+
Handle<Value> nist5(const Arguments& args) {
487+
HandleScope scope;
488+
489+
if (args.Length() < 1)
490+
return except("You must provide one argument.");
491+
492+
Local<Object> target = args[0]->ToObject();
493+
494+
if(!Buffer::HasInstance(target))
495+
return except("Argument should be a buffer object.");
496+
497+
char * input = Buffer::Data(target);
498+
char output[32];
499+
500+
uint32_t input_len = Buffer::Length(target);
501+
502+
nist5_hash(input, output, input_len);
503+
504+
Buffer* buff = Buffer::New(output, 32);
505+
return scope.Close(buff->handle_);
506+
}
507+
485508
void init(Handle<Object> exports) {
486509
exports->Set(String::NewSymbol("quark"), FunctionTemplate::New(quark)->GetFunction());
487510
exports->Set(String::NewSymbol("x11"), FunctionTemplate::New(x11)->GetFunction());
@@ -501,6 +524,7 @@ void init(Handle<Object> exports) {
501524
exports->Set(String::NewSymbol("cryptonight"), FunctionTemplate::New(cryptonight)->GetFunction());
502525
exports->Set(String::NewSymbol("x13"), FunctionTemplate::New(x13)->GetFunction());
503526
exports->Set(String::NewSymbol("boolberry"), FunctionTemplate::New(boolberry)->GetFunction());
527+
exports->Set(String::NewSymbol("nist5"), FunctionTemplate::New(nist5)->GetFunction());
504528
}
505529

506530
NODE_MODULE(multihashing, init)

nist5.c

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "nist5.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+
#include "sha3/sph_groestl.h"
9+
#include "sha3/sph_jh.h"
10+
#include "sha3/sph_keccak.h"
11+
#include "sha3/sph_skein.h"
12+
13+
14+
void nist5_hash(const char* input, char* output, uint32_t len)
15+
{
16+
sph_blake512_context ctx_blake;
17+
sph_groestl512_context ctx_groestl;
18+
sph_skein512_context ctx_skein;
19+
sph_jh512_context ctx_jh;
20+
sph_keccak512_context ctx_keccak;
21+
22+
//these uint512 in the c++ source of the client are backed by an array of uint32
23+
uint32_t hash[16];
24+
25+
sph_blake512_init(&ctx_blake);
26+
sph_blake512 (&ctx_blake, input, len);
27+
sph_blake512_close (&ctx_blake, hash);
28+
29+
sph_groestl512_init(&ctx_groestl);
30+
sph_groestl512 (&ctx_groestl, hash, 64);
31+
sph_groestl512_close(&ctx_groestl, hash);
32+
33+
sph_jh512_init(&ctx_jh);
34+
sph_jh512 (&ctx_jh, hash, 64);
35+
sph_jh512_close(&ctx_jh, hash);
36+
37+
sph_keccak512_init(&ctx_keccak);
38+
sph_keccak512 (&ctx_keccak, hash, 64);
39+
sph_keccak512_close(&ctx_keccak, hash);
40+
41+
sph_skein512_init(&ctx_skein);
42+
sph_skein512 (&ctx_skein, hash, 64);
43+
sph_skein512_close (&ctx_skein, hash);
44+
45+
memcpy(output, hash, 32);
46+
}

nist5.h

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

0 commit comments

Comments
 (0)