406 lines
11 KiB
C++
406 lines
11 KiB
C++
#include <node.h>
|
|
#include <node_buffer.h>
|
|
#include <v8.h>
|
|
#include <stdint.h>
|
|
|
|
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"
|
|
#include "shavite3.h"
|
|
}
|
|
|
|
using namespace node;
|
|
using namespace v8;
|
|
|
|
Handle<Value> except(const char* msg) {
|
|
return ThrowException(Exception::Error(String::New(msg)));
|
|
}
|
|
|
|
Handle<Value> quark(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> x11(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> scrypt(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> scryptn(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 2)
|
|
return except("You must provide buffer to hash and N factor.");
|
|
|
|
Local<Object> target = args[0]->ToObject();
|
|
|
|
if(!Buffer::HasInstance(target))
|
|
return except("Argument should be a buffer object.");
|
|
|
|
Local<Number> 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<Value> 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<Object> target = args[0]->ToObject();
|
|
|
|
if(!Buffer::HasInstance(target))
|
|
return except("First should be a buffer object.");
|
|
|
|
Local<Number> num = args[1]->ToNumber();
|
|
int timestamp = num->Value();
|
|
|
|
Local<Number> num2 = args[2]->ToNumber();
|
|
int nChainStartTime = num2->Value();
|
|
|
|
Local<Number> num3 = args[3]->ToNumber();
|
|
int nMin = num3->Value();
|
|
|
|
Local<Number> 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<Value> keccak(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> bcrypt(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> skein(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> groestl(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> groestl_myriad(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> blake(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> fugue(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> qubit(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Value> hefty1(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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_);
|
|
}
|
|
|
|
|
|
Handle<Value> shavite3(const Arguments& args) {
|
|
HandleScope scope;
|
|
|
|
if (args.Length() < 1)
|
|
return except("You must provide one argument.");
|
|
|
|
Local<Object> 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<Object> 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());
|
|
exports->Set(String::NewSymbol("shavite3"), FunctionTemplate::New(shavite3)->GetFunction());
|
|
}
|
|
|
|
NODE_MODULE(multihashing, init)
|