diff --git a/binding.gyp b/binding.gyp index 59324d7..79e8fb3 100644 --- a/binding.gyp +++ b/binding.gyp @@ -17,6 +17,7 @@ "fugue.c", "qubit.c", "hefty1.c", + "shavite3.c", "sha3/sph_hefty1.c", "sha3/sph_fugue.c", "sha3/aes_helper.c", diff --git a/keccak.c b/keccak.c index a4316be..7116777 100644 --- a/keccak.c +++ b/keccak.c @@ -1,14 +1,10 @@ #include "keccak.h" -#include -#include -#include -#include #include "sha3/sph_types.h" #include "sha3/sph_keccak.h" -void keccak_hash(const char* input, char* output, unsigned int size) +void keccak_hash(const char* input, char* output, uint32_t size) { sph_keccak256_context ctx_keccak; sph_keccak256_init(&ctx_keccak); diff --git a/keccak.h b/keccak.h index 8d61989..0998c51 100644 --- a/keccak.h +++ b/keccak.h @@ -5,7 +5,9 @@ extern "C" { #endif -void keccak_hash(const char* input, char* output, unsigned int size); +#include + +void keccak_hash(const char* input, char* output, uint32_t size); #ifdef __cplusplus } diff --git a/multihashing.cc b/multihashing.cc index c9bc41e..4ab7ca3 100644 --- a/multihashing.cc +++ b/multihashing.cc @@ -17,6 +17,7 @@ extern "C" { #include "fugue.h" #include "qubit.h" #include "hefty1.h" + #include "shavite3.h" } using namespace node; @@ -360,6 +361,29 @@ Handle hefty1(const Arguments& args) { return scope.Close(buff->handle_); } + +Handle shavite3(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); + + shavite3_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()); @@ -375,6 +399,7 @@ void init(Handle exports) { exports->Set(String::NewSymbol("fugue"), FunctionTemplate::New(fugue)->GetFunction()); exports->Set(String::NewSymbol("qubit"), FunctionTemplate::New(qubit)->GetFunction()); exports->Set(String::NewSymbol("hefty1"), FunctionTemplate::New(hefty1)->GetFunction()); + exports->Set(String::NewSymbol("shavite3"), FunctionTemplate::New(shavite3)->GetFunction()); } NODE_MODULE(multihashing, init) diff --git a/shavite3.c b/shavite3.c new file mode 100644 index 0000000..494ea3b --- /dev/null +++ b/shavite3.c @@ -0,0 +1,24 @@ +#include "shavite3.h" + +#include "sha3/sph_shavite.h" + +void shavite3_hash(const char* input, char* output, uint32_t len) +{ + char* hash1 = (char*) malloc(64); + char* hash2 = (char*) malloc(64); + + sph_shavite512_context ctx_shavite; + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, (const void*) input, len); + sph_shavite512_close(&ctx_shavite, (void*) hash1); + + sph_shavite512(&ctx_shavite, (const void*) hash1, 64); + sph_shavite512_close(&ctx_shavite, (void*) hash2); + + memcpy(output, hash2, 32); + + free(hash1); + free(hash2); +} + diff --git a/shavite3.h b/shavite3.h new file mode 100644 index 0000000..add9fa6 --- /dev/null +++ b/shavite3.h @@ -0,0 +1,16 @@ +#ifndef SHAVITE_H +#define SHAVITE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void shavite3_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/x11.h b/x11.h index 1622f13..fc9cdad 100644 --- a/x11.h +++ b/x11.h @@ -5,6 +5,8 @@ extern "C" { #endif +#include + void x11_hash(const char* input, char* output, uint32_t len); #ifdef __cplusplus