Skip to content

Commit edd4fa7

Browse files
committed
cn_fast_hash support
1 parent 1505af5 commit edd4fa7

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

cryptonight.c

+6
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,9 @@ void cryptonight_hash(const char* input, char* output, uint32_t len) {
169169
extra_hashes[state.hs.b[0] & 3](&state, 200, output);
170170
oaes_free(&aes_ctx);
171171
}
172+
173+
void cryptonight_fast_hash(const char* input, char* output, uint32_t len) {
174+
union hash_state state;
175+
hash_process(&state, input, len);
176+
memcpy(output, &state, HASH_SIZE);
177+
}

cryptonight.h

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern "C" {
88
#include <stdint.h>
99

1010
void cryptonight_hash(const char* input, char* output, uint32_t len);
11+
void cryptonight_fast_hash(const char* input, char* output, uint32_t len);
1112

1213
#ifdef __cplusplus
1314
}

multihashing.cc

+12-1
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,16 @@ Handle<Value> shavite3(const Arguments& args) {
392392
Handle<Value> cryptonight(const Arguments& args) {
393393
HandleScope scope;
394394

395+
bool fast = false;
396+
395397
if (args.Length() < 1)
396398
return except("You must provide one argument.");
399+
400+
if (args.Length() >= 2) {
401+
if(!args[1]->IsBoolean())
402+
return except("Argument 2 should be a boolean");
403+
fast = args[1]->ToBoolean()->BooleanValue();
404+
}
397405

398406
Local<Object> target = args[0]->ToObject();
399407

@@ -405,7 +413,10 @@ Handle<Value> cryptonight(const Arguments& args) {
405413

406414
uint32_t input_len = Buffer::Length(target);
407415

408-
cryptonight_hash(input, output, input_len);
416+
if(fast)
417+
cryptonight_fast_hash(input, output, input_len);
418+
else
419+
cryptonight_hash(input, output, input_len);
409420

410421
Buffer* buff = Buffer::New(output, 32);
411422
return scope.Close(buff->handle_);

0 commit comments

Comments
 (0)