From edd4fa7b5ccde0431778752a2d57ba9e0139515c Mon Sep 17 00:00:00 2001 From: lucas Date: Wed, 14 May 2014 16:56:17 +0100 Subject: [PATCH] cn_fast_hash support --- cryptonight.c | 6 ++++++ cryptonight.h | 1 + multihashing.cc | 13 ++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cryptonight.c b/cryptonight.c index f889577..d68a820 100644 --- a/cryptonight.c +++ b/cryptonight.c @@ -169,3 +169,9 @@ void cryptonight_hash(const char* input, char* output, uint32_t len) { extra_hashes[state.hs.b[0] & 3](&state, 200, output); oaes_free(&aes_ctx); } + +void cryptonight_fast_hash(const char* input, char* output, uint32_t len) { + union hash_state state; + hash_process(&state, input, len); + memcpy(output, &state, HASH_SIZE); +} diff --git a/cryptonight.h b/cryptonight.h index d02099e..86fedca 100644 --- a/cryptonight.h +++ b/cryptonight.h @@ -8,6 +8,7 @@ extern "C" { #include void cryptonight_hash(const char* input, char* output, uint32_t len); +void cryptonight_fast_hash(const char* input, char* output, uint32_t len); #ifdef __cplusplus } diff --git a/multihashing.cc b/multihashing.cc index 01d34c9..c02ef5c 100644 --- a/multihashing.cc +++ b/multihashing.cc @@ -392,8 +392,16 @@ Handle shavite3(const Arguments& args) { Handle cryptonight(const Arguments& args) { HandleScope scope; + bool fast = false; + if (args.Length() < 1) return except("You must provide one argument."); + + if (args.Length() >= 2) { + if(!args[1]->IsBoolean()) + return except("Argument 2 should be a boolean"); + fast = args[1]->ToBoolean()->BooleanValue(); + } Local target = args[0]->ToObject(); @@ -405,7 +413,10 @@ Handle cryptonight(const Arguments& args) { uint32_t input_len = Buffer::Length(target); - cryptonight_hash(input, output, input_len); + if(fast) + cryptonight_fast_hash(input, output, input_len); + else + cryptonight_hash(input, output, input_len); Buffer* buff = Buffer::New(output, 32); return scope.Close(buff->handle_);