Add sha1coin support
parent
880da0eac5
commit
4e99791cc2
|
@ -17,6 +17,7 @@
|
|||
"qubit.c",
|
||||
"hefty1.c",
|
||||
"shavite3.c",
|
||||
"sha1coin.c",
|
||||
"sha3/sph_hefty1.c",
|
||||
"sha3/sph_fugue.c",
|
||||
"sha3/aes_helper.c",
|
||||
|
|
|
@ -17,6 +17,7 @@ extern "C" {
|
|||
#include "qubit.h"
|
||||
#include "hefty1.h"
|
||||
#include "shavite3.h"
|
||||
#include "sha1coin.h"
|
||||
}
|
||||
|
||||
using namespace node;
|
||||
|
@ -388,6 +389,28 @@ Handle<Value> shavite3(const Arguments& args) {
|
|||
return scope.Close(buff->handle_);
|
||||
}
|
||||
|
||||
Handle<Value> sha1coin(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[32];
|
||||
|
||||
uint32_t input_len = Buffer::Length(target);
|
||||
|
||||
sha1coin_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());
|
||||
|
@ -404,6 +427,7 @@ void init(Handle<Object> exports) {
|
|||
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());
|
||||
exports->Set(String::NewSymbol("sha1coin"), FunctionTemplate::New(sha1coin)->GetFunction());
|
||||
}
|
||||
|
||||
NODE_MODULE(multihashing, init)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"keccak",
|
||||
"blake",
|
||||
"shavite",
|
||||
"fugue"
|
||||
"fugue",
|
||||
"sha1coin"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
#include "sha1coin.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
inline void encodeb64(const unsigned char* pch, char* buff)
|
||||
{
|
||||
const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
int mode = 0, left = 0;
|
||||
const int len = 20;
|
||||
const unsigned char *pchEnd = pch + len;
|
||||
while (pch < pchEnd) {
|
||||
int enc = *(pch++);
|
||||
if (mode == 0) {
|
||||
*buff++ = pbase64[enc >> 2];
|
||||
left = (enc & 3) << 4;
|
||||
mode = 1;
|
||||
}
|
||||
else if (mode == 1) {
|
||||
*buff++ = pbase64[left | (enc >> 4)];
|
||||
left = (enc & 15) << 2;
|
||||
mode = 2;
|
||||
}
|
||||
else {
|
||||
*buff++ = pbase64[left | (enc >> 6)];
|
||||
*buff++ = pbase64[enc & 63];
|
||||
mode = 0;
|
||||
}
|
||||
}
|
||||
*buff = pbase64[left];
|
||||
*(buff + 1) = 0;
|
||||
}
|
||||
|
||||
void sha1coin_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
char str[38] __attribute__((aligned(32))); // 26 + 11 + 1
|
||||
uint32_t prehash[5] __attribute__((aligned(32)));
|
||||
uint32_t hash[5] __attribute__((aligned(32))) = { 0 };
|
||||
int i = 0;
|
||||
SHA1((void *)input, len, (void *)prehash);
|
||||
encodeb64((const unsigned char *)prehash, str);
|
||||
memcpy(&str[26], str, 11);
|
||||
str[37] = 0;
|
||||
for (i = 0; i < 26; i++) {
|
||||
SHA1((const unsigned char*)&str[i], 12, (unsigned char *)prehash);
|
||||
hash[0] ^= prehash[0];
|
||||
hash[1] ^= prehash[1];
|
||||
hash[2] ^= prehash[2];
|
||||
hash[3] ^= prehash[3];
|
||||
hash[4] ^= prehash[4];
|
||||
}
|
||||
memset(output, 0, 32 - 20);
|
||||
memcpy(&output[32 - 20], hash, 20);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef SHA1COIN_H
|
||||
#define SHA1COIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void sha1coin_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue