diff --git a/README.md b/README.md index 17ecd04..0bba0bf 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,28 @@ node-multi-hashing Cryptocurrency hashing functions for node.js. + +Algorithms +---------- +* quark +* x11 +* x13 +* nist5 +* scrypt +* scryptn +* scryptjane +* keccak +* bcrypt +* skein +* groestl +* blake +* fugue +* qubit +* hefty1 +* shavite3 +* cryptonight +* boolberry + Usage ----- diff --git a/binding.gyp b/binding.gyp index 81e8009..a26a6e6 100644 --- a/binding.gyp +++ b/binding.gyp @@ -20,6 +20,7 @@ "cryptonight.c", "x13.c", "boolberry.cc", + "nist5.c", "sha3/sph_hefty1.c", "sha3/sph_fugue.c", "sha3/aes_helper.c", diff --git a/multihashing.cc b/multihashing.cc index 4aadff0..c7ad467 100644 --- a/multihashing.cc +++ b/multihashing.cc @@ -19,6 +19,7 @@ extern "C" { #include "shavite3.h" #include "cryptonight.h" #include "x13.h" + #include "nist5.h" } #include "boolberry.h" @@ -482,6 +483,28 @@ Handle boolberry(const Arguments& args) { return scope.Close(buff->handle_); } +Handle nist5(const Arguments& args) { + HandleScope scope; + + if (args.Length() < 1) + return except("You must provide one argument."); + + Local target = args[0]->ToObject(); + + if(!Buffer::HasInstance(target)) + return except("Argument should be a buffer object."); + + char * input = Buffer::Data(target); + char output[32]; + + uint32_t input_len = Buffer::Length(target); + + nist5_hash(input, output, input_len); + + Buffer* buff = Buffer::New(output, 32); + return scope.Close(buff->handle_); +} + void init(Handle exports) { exports->Set(String::NewSymbol("quark"), FunctionTemplate::New(quark)->GetFunction()); exports->Set(String::NewSymbol("x11"), FunctionTemplate::New(x11)->GetFunction()); @@ -501,6 +524,7 @@ void init(Handle exports) { exports->Set(String::NewSymbol("cryptonight"), FunctionTemplate::New(cryptonight)->GetFunction()); exports->Set(String::NewSymbol("x13"), FunctionTemplate::New(x13)->GetFunction()); exports->Set(String::NewSymbol("boolberry"), FunctionTemplate::New(boolberry)->GetFunction()); + exports->Set(String::NewSymbol("nist5"), FunctionTemplate::New(nist5)->GetFunction()); } NODE_MODULE(multihashing, init) diff --git a/nist5.c b/nist5.c new file mode 100644 index 0000000..f74b27a --- /dev/null +++ b/nist5.c @@ -0,0 +1,46 @@ +#include "nist5.h" +#include +#include +#include +#include + +#include "sha3/sph_blake.h" +#include "sha3/sph_groestl.h" +#include "sha3/sph_jh.h" +#include "sha3/sph_keccak.h" +#include "sha3/sph_skein.h" + + +void nist5_hash(const char* input, char* output, uint32_t len) +{ + sph_blake512_context ctx_blake; + sph_groestl512_context ctx_groestl; + sph_skein512_context ctx_skein; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + + //these uint512 in the c++ source of the client are backed by an array of uint32 + uint32_t hash[16]; + + sph_blake512_init(&ctx_blake); + sph_blake512 (&ctx_blake, input, len); + sph_blake512_close (&ctx_blake, hash); + + sph_groestl512_init(&ctx_groestl); + sph_groestl512 (&ctx_groestl, hash, 64); + sph_groestl512_close(&ctx_groestl, hash); + + sph_jh512_init(&ctx_jh); + sph_jh512 (&ctx_jh, hash, 64); + sph_jh512_close(&ctx_jh, hash); + + sph_keccak512_init(&ctx_keccak); + sph_keccak512 (&ctx_keccak, hash, 64); + sph_keccak512_close(&ctx_keccak, hash); + + sph_skein512_init(&ctx_skein); + sph_skein512 (&ctx_skein, hash, 64); + sph_skein512_close (&ctx_skein, hash); + + memcpy(output, hash, 32); +} \ No newline at end of file diff --git a/nist5.h b/nist5.h new file mode 100644 index 0000000..bf7407e --- /dev/null +++ b/nist5.h @@ -0,0 +1,16 @@ +#ifndef NIST5_H +#define NIST5_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void nist5_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file