#include #include #include #include extern "C" { #include "bcrypt.h" #include "keccak.h" #include "quark.h" #include "scrypt.h" #include "scryptjane.h" #include "scryptn.h" #include "skein.h" #include "x11.h" #include "groestl.h" #include "blake.h" #include "fugue.h" #include "qubit.h" #include "hefty1.h" } using namespace node; using namespace v8; Handle except(const char* msg) { return ThrowException(Exception::Error(String::New(msg))); } Handle quark(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); quark_hash(input, output, input_len); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle x11(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); x11_hash(input, output, input_len); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle scrypt(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); scrypt_1024_1_1_256(input, output, input_len); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle scryptn(const Arguments& args) { HandleScope scope; if (args.Length() < 2) return except("You must provide buffer to hash and N factor."); Local target = args[0]->ToObject(); if(!Buffer::HasInstance(target)) return except("Argument should be a buffer object."); Local num = args[1]->ToNumber(); unsigned int nFactor = num->Value(); char * input = Buffer::Data(target); char * output = new char[32]; uint32_t input_len = Buffer::Length(target); //unsigned int N = 1 << (getNfactor(input) + 1); unsigned int N = 1 << nFactor; scrypt_N_1_1_256(input, output, N, input_len); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle scryptjane(const Arguments& args) { HandleScope scope; if (args.Length() < 5) return except("You must provide two argument: buffer, timestamp as number, and nChainStarTime as number, nMin, and nMax"); Local target = args[0]->ToObject(); if(!Buffer::HasInstance(target)) return except("First should be a buffer object."); Local num = args[1]->ToNumber(); int timestamp = num->Value(); Local num2 = args[2]->ToNumber(); int nChainStartTime = num2->Value(); Local num3 = args[3]->ToNumber(); int nMin = num3->Value(); Local num4 = args[4]->ToNumber(); int nMax = num4->Value(); char * input = Buffer::Data(target); char * output = new char[32]; uint32_t input_len = Buffer::Length(target); scryptjane_hash(input, input_len, (uint32_t *)output, GetNfactorJane(timestamp, nChainStartTime, nMin, nMax)); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle keccak(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]; unsigned int dSize = Buffer::Length(target); keccak_hash(input, output, dSize); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle bcrypt(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]; bcrypt_hash(input, output); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle skein(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); skein_hash(input, output, input_len); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle groestl(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); groestl_hash(input, output, input_len); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle groestl_myriad(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); groestl_myriad_hash(input, output, input_len); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle blake(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); blake_hash(input, output, input_len); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_); } Handle fugue(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); fugue_hash(input, output, input_len); Buffer* buff = Buffer::New(output, 32); 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_); } Handle hefty1(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); hefty1_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()); exports->Set(String::NewSymbol("scrypt"), FunctionTemplate::New(scrypt)->GetFunction()); exports->Set(String::NewSymbol("scryptn"), FunctionTemplate::New(scryptn)->GetFunction()); exports->Set(String::NewSymbol("scryptjane"), FunctionTemplate::New(scryptjane)->GetFunction()); exports->Set(String::NewSymbol("keccak"), FunctionTemplate::New(keccak)->GetFunction()); exports->Set(String::NewSymbol("bcrypt"), FunctionTemplate::New(bcrypt)->GetFunction()); exports->Set(String::NewSymbol("skein"), FunctionTemplate::New(skein)->GetFunction()); exports->Set(String::NewSymbol("groestl"), FunctionTemplate::New(groestl)->GetFunction()); 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()); exports->Set(String::NewSymbol("hefty1"), FunctionTemplate::New(hefty1)->GetFunction()); } NODE_MODULE(multihashing, init)