Initial shavite3 support

master
Lucas Jones 2014-04-19 22:33:45 +01:00
parent 5d73e6f45e
commit 4a686c0aba
7 changed files with 72 additions and 6 deletions

View File

@ -17,6 +17,7 @@
"fugue.c",
"qubit.c",
"hefty1.c",
"shavite3.c",
"sha3/sph_hefty1.c",
"sha3/sph_fugue.c",
"sha3/aes_helper.c",

View File

@ -1,14 +1,10 @@
#include "keccak.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "sha3/sph_types.h"
#include "sha3/sph_keccak.h"
void keccak_hash(const char* input, char* output, unsigned int size)
void keccak_hash(const char* input, char* output, uint32_t size)
{
sph_keccak256_context ctx_keccak;
sph_keccak256_init(&ctx_keccak);

View File

@ -5,7 +5,9 @@
extern "C" {
#endif
void keccak_hash(const char* input, char* output, unsigned int size);
#include <stdint.h>
void keccak_hash(const char* input, char* output, uint32_t size);
#ifdef __cplusplus
}

View File

@ -17,6 +17,7 @@ extern "C" {
#include "fugue.h"
#include "qubit.h"
#include "hefty1.h"
#include "shavite3.h"
}
using namespace node;
@ -360,6 +361,29 @@ Handle<Value> hefty1(const Arguments& args) {
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());
@ -375,6 +399,7 @@ void init(Handle<Object> exports) {
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)

24
shavite3.c 100644
View File

@ -0,0 +1,24 @@
#include "shavite3.h"
#include "sha3/sph_shavite.h"
void shavite3_hash(const char* input, char* output, uint32_t len)
{
char* hash1 = (char*) malloc(64);
char* hash2 = (char*) malloc(64);
sph_shavite512_context ctx_shavite;
sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx_shavite, (const void*) input, len);
sph_shavite512_close(&ctx_shavite, (void*) hash1);
sph_shavite512(&ctx_shavite, (const void*) hash1, 64);
sph_shavite512_close(&ctx_shavite, (void*) hash2);
memcpy(output, hash2, 32);
free(hash1);
free(hash2);
}

16
shavite3.h 100644
View File

@ -0,0 +1,16 @@
#ifndef SHAVITE_H
#define SHAVITE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
void shavite3_hash(const char* input, char* output, uint32_t len);
#ifdef __cplusplus
}
#endif
#endif

2
x11.h
View File

@ -5,6 +5,8 @@
extern "C" {
#endif
#include <stdint.h>
void x11_hash(const char* input, char* output, uint32_t len);
#ifdef __cplusplus