@@ -21,7 +21,7 @@ extern "C" {
2121 #include " cryptonight.h"
2222 #include " x13.h"
2323 #include " nist5.h"
24- #include " sha1.h" ,
24+ #include " sha1.h"
2525 #include " x15.h"
2626 #include " fresh.h"
2727}
@@ -49,7 +49,7 @@ NAN_METHOD(quark) {
4949 char * input = node::Buffer::Data (target);
5050 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
5151 char * output = node::Buffer::Data (dest.ToLocalChecked ());
52-
52+
5353 uint32_t input_len = node::Buffer::Length (target);
5454
5555 quark_hash (input, output, input_len);
@@ -86,18 +86,18 @@ NAN_METHOD(scrypt) {
8686
8787 if (!node::Buffer::HasInstance (target))
8888 return except (" Argument should be a buffer object." );
89-
89+
9090 Local<Number> numn = info[1 ]->ToNumber ();
9191 unsigned int nValue = numn->Value ();
9292 Local<Number> numr = info[2 ]->ToNumber ();
9393 unsigned int rValue = numr->Value ();
94-
94+
9595 char * input = node::Buffer::Data (target);
9696 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
9797 char * output = node::Buffer::Data (dest.ToLocalChecked ());
9898
9999 uint32_t input_len = node::Buffer::Length (target);
100-
100+
101101 scrypt_N_R_1_256 (input, output, nValue, rValue, input_len);
102102
103103 info.GetReturnValue ().Set (dest.ToLocalChecked ());
@@ -216,7 +216,7 @@ NAN_METHOD(skein) {
216216 char * output = node::Buffer::Data (dest.ToLocalChecked ());
217217
218218 uint32_t input_len = node::Buffer::Length (target);
219-
219+
220220 skein_hash (input, output, input_len);
221221
222222 info.GetReturnValue ().Set (dest.ToLocalChecked ());
@@ -235,7 +235,7 @@ NAN_METHOD(groestl) {
235235 char * input = node::Buffer::Data (target);
236236 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
237237 char * output = node::Buffer::Data (dest.ToLocalChecked ());
238-
238+
239239 uint32_t input_len = node::Buffer::Length (target);
240240
241241 groestl_hash (input, output, input_len);
@@ -256,7 +256,7 @@ NAN_METHOD(groestlmyriad) {
256256 char * input = node::Buffer::Data (target);
257257 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
258258 char * output = node::Buffer::Data (dest.ToLocalChecked ());
259-
259+
260260 uint32_t input_len = node::Buffer::Length (target);
261261
262262 groestlmyriad_hash (input, output, input_len);
@@ -277,7 +277,7 @@ NAN_METHOD(blake) {
277277 char * input = node::Buffer::Data (target);
278278 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
279279 char * output = node::Buffer::Data (dest.ToLocalChecked ());
280-
280+
281281 uint32_t input_len = node::Buffer::Length (target);
282282
283283 blake_hash (input, output, input_len);
@@ -298,7 +298,7 @@ NAN_METHOD(fugue) {
298298 char * input = node::Buffer::Data (target);
299299 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
300300 char * output = node::Buffer::Data (dest.ToLocalChecked ());
301-
301+
302302 uint32_t input_len = node::Buffer::Length (target);
303303
304304 fugue_hash (input, output, input_len);
@@ -319,7 +319,7 @@ NAN_METHOD(qubit) {
319319 char * input = node::Buffer::Data (target);
320320 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
321321 char * output = node::Buffer::Data (dest.ToLocalChecked ());
322-
322+
323323 uint32_t input_len = node::Buffer::Length (target);
324324
325325 qubit_hash (input, output, input_len);
@@ -340,7 +340,7 @@ NAN_METHOD(hefty1) {
340340 char * input = node::Buffer::Data (target);
341341 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
342342 char * output = node::Buffer::Data (dest.ToLocalChecked ());
343-
343+
344344 uint32_t input_len = node::Buffer::Length (target);
345345
346346 hefty1_hash (input, output, input_len);
@@ -361,7 +361,7 @@ NAN_METHOD(shavite3) {
361361 char * input = node::Buffer::Data (target);
362362 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
363363 char * output = node::Buffer::Data (dest.ToLocalChecked ());
364-
364+
365365 uint32_t input_len = node::Buffer::Length (target);
366366
367367 shavite3_hash (input, output, input_len);
@@ -371,14 +371,60 @@ NAN_METHOD(shavite3) {
371371
372372NAN_METHOD (cryptonight) {
373373 bool fast = false ;
374+ uint32_t cn_variant = 0 ;
375+
376+ if (info.Length () < 1 )
377+ return except (" You must provide one argument." );
378+
379+ if (info.Length () >= 2 ) {
380+ if (info.Length () >= 2 ) {
381+ if (info[1 ]->IsBoolean ())
382+ fast = info[1 ]->ToBoolean ()->BooleanValue ();
383+ else if (info[1 ]->IsUint32 ())
384+ cn_variant = info[1 ]->ToUint32 ()->Uint32Value ();
385+ else
386+ return except (" Argument 2 should be a boolean or uint32_t" );
387+ }
388+ }
389+
390+ Local<Object> target = info[0 ]->ToObject ();
391+
392+ if (!node::Buffer::HasInstance (target))
393+ return except (" Argument should be a buffer object." );
394+
395+ char * input = node::Buffer::Data (target);
396+ Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
397+ char * output = node::Buffer::Data (dest.ToLocalChecked ());
398+
399+ uint32_t input_len = node::Buffer::Length (target);
400+
401+ if (fast)
402+ cryptonight_fast_hash (input, output, input_len);
403+ else {
404+ if (cn_variant > 0 && input_len < 43 )
405+ return except (" Argument must be 43 bytes for monero variant 1+" );
406+ cryptonight_hash (input, output, input_len, cn_variant, 0 );
407+ }
408+
409+ info.GetReturnValue ().Set (dest.ToLocalChecked ());
410+ }
411+
412+ NAN_METHOD (cryptonightlite) {
413+ bool fast = false ;
414+ uint32_t cn_variant = 0 ;
374415
375416 if (info.Length () < 1 )
376417 return except (" You must provide one argument." );
377-
418+
378419 if (info.Length () >= 2 ) {
379- if (!info[1 ]->IsBoolean ())
380- return except (" Argument 2 should be a boolean" );
381- fast = info[1 ]->ToBoolean ()->BooleanValue ();
420+ if (info.Length () >= 2 ) {
421+ if (info[1 ]->IsBoolean ())
422+ fast = info[1 ]->ToBoolean ()->BooleanValue ();
423+ else if (info[1 ]->IsUint32 ())
424+ cn_variant = info[1 ]->ToUint32 ()->Uint32Value ();
425+ else
426+ return except (" Argument 2 should be a boolean or uint32_t" );
427+ }
382428 }
383429
384430 Local<Object> target = info[0 ]->ToObject ();
@@ -389,13 +435,16 @@ NAN_METHOD(cryptonight) {
389435 char * input = node::Buffer::Data (target);
390436 Nan::MaybeLocal<v8::Object> dest = Nan::NewBuffer (32 );
391437 char * output = node::Buffer::Data (dest.ToLocalChecked ());
392-
438+
393439 uint32_t input_len = node::Buffer::Length (target);
394440
395441 if (fast)
396442 cryptonight_fast_hash (input, output, input_len);
397- else
398- cryptonight_hash (input, output, input_len);
443+ else {
444+ if (cn_variant > 0 && input_len < 43 )
445+ return except (" Argument must be 43 bytes for aeon variant 1+" );
446+ cryptonight_hash (input, output, input_len, cn_variant, 1 );
447+ }
399448
400449 info.GetReturnValue ().Set (dest.ToLocalChecked ());
401450}
@@ -566,6 +615,8 @@ NAN_MODULE_INIT(Init) {
566615 GetFunction (New<FunctionTemplate>(shavite3)).ToLocalChecked ());
567616 Nan::Set (target, New<String>(" cryptonight" ).ToLocalChecked (),
568617 GetFunction (New<FunctionTemplate>(cryptonight)).ToLocalChecked ());
618+ Nan::Set (target, New<String>(" cryptonight-lite" ).ToLocalChecked (),
619+ GetFunction (New<FunctionTemplate>(cryptonightlite)).ToLocalChecked ());
569620 Nan::Set (target, New<String>(" x13" ).ToLocalChecked (),
570621 GetFunction (New<FunctionTemplate>(x13)).ToLocalChecked ());
571622 Nan::Set (target, New<String>(" boolberry" ).ToLocalChecked (),
@@ -581,4 +632,4 @@ NAN_MODULE_INIT(Init) {
581632}
582633
583634NODE_MODULE (multihashing, Init)
584- }
635+ }
0 commit comments