diff --git a/binding.gyp b/binding.gyp index 665bb9e..4c0ea53 100644 --- a/binding.gyp +++ b/binding.gyp @@ -15,6 +15,7 @@ "groestl.c", "blake.c", "fugue.c", + "qubit.c", "sha3/sph_fugue.c", "sha3/aes_helper.c", "sha3/sph_blake.c", diff --git a/multihashing.cc b/multihashing.cc index 8cc5cb8..642b6ef 100644 --- a/multihashing.cc +++ b/multihashing.cc @@ -15,6 +15,7 @@ extern "C" { #include "groestl.h" #include "blake.h" #include "fugue.h" + #include "qubit.h" } using namespace node; @@ -312,6 +313,29 @@ Handle fugue(const Arguments& args) { return scope.Close(buff->handle_); } + +Handle qubit(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 = new char[32]; + + uint32_t input_len = Buffer::Length(target); + + qubit_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()); @@ -325,6 +349,7 @@ void init(Handle exports) { exports->Set(String::NewSymbol("groestl_myriad"), FunctionTemplate::New(groestl_myriad)->GetFunction()); exports->Set(String::NewSymbol("blake"), FunctionTemplate::New(blake)->GetFunction()); exports->Set(String::NewSymbol("fugue"), FunctionTemplate::New(fugue)->GetFunction()); + exports->Set(String::NewSymbol("qubit"), FunctionTemplate::New(qubit)->GetFunction()); } NODE_MODULE(multihashing, init) diff --git a/qubit.c b/qubit.c new file mode 100644 index 0000000..e38d02f --- /dev/null +++ b/qubit.c @@ -0,0 +1,45 @@ +#include "qubit.h" + +#include "sha3/sph_cubehash.h" +#include "sha3/sph_luffa.h" +#include "sha3/sph_shavite.h" +#include "sha3/sph_simd.h" +#include "sha3/sph_echo.h" + +void qubit_hash(const char* input, char* output, uint32_t len) +{ + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + + char* hash1 = (char*) malloc(64); + char* hash2 = (char*) malloc(64); + + sph_luffa512_init(&ctx_luffa); + sph_luffa512(&ctx_luffa, (const void*) input, len); + sph_luffa512_close(&ctx_luffa, (void*) hash1); //1 + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, (const void*) hash1, 64); // 1 + sph_cubehash512_close(&ctx_cubehash, (void*) hash2); // 2 + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, (const void*) hash2, 64); // 3 + sph_shavite512_close(&ctx_shavite, (void*) hash1); // 4 + + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, (const void*) hash1, 64); // 4 + sph_simd512_close(&ctx_simd, (void*) hash2); // 5 + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, (const void*) hash2, 64); // 5 + sph_echo512_close(&ctx_echo, (void*) hash1); // 6 + + memcpy(output, hash1, 32); + + free(hash1); + free(hash2); +} + diff --git a/qubit.h b/qubit.h new file mode 100644 index 0000000..1055a5e --- /dev/null +++ b/qubit.h @@ -0,0 +1,16 @@ +#ifndef QUBIT_H +#define QUBIT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void qubit_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif