Initial shavite3 support
parent
5d73e6f45e
commit
4a686c0aba
|
@ -17,6 +17,7 @@
|
||||||
"fugue.c",
|
"fugue.c",
|
||||||
"qubit.c",
|
"qubit.c",
|
||||||
"hefty1.c",
|
"hefty1.c",
|
||||||
|
"shavite3.c",
|
||||||
"sha3/sph_hefty1.c",
|
"sha3/sph_hefty1.c",
|
||||||
"sha3/sph_fugue.c",
|
"sha3/sph_fugue.c",
|
||||||
"sha3/aes_helper.c",
|
"sha3/aes_helper.c",
|
||||||
|
|
6
keccak.c
6
keccak.c
|
@ -1,14 +1,10 @@
|
||||||
#include "keccak.h"
|
#include "keccak.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "sha3/sph_types.h"
|
#include "sha3/sph_types.h"
|
||||||
#include "sha3/sph_keccak.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_context ctx_keccak;
|
||||||
sph_keccak256_init(&ctx_keccak);
|
sph_keccak256_init(&ctx_keccak);
|
||||||
|
|
4
keccak.h
4
keccak.h
|
@ -5,7 +5,9 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ extern "C" {
|
||||||
#include "fugue.h"
|
#include "fugue.h"
|
||||||
#include "qubit.h"
|
#include "qubit.h"
|
||||||
#include "hefty1.h"
|
#include "hefty1.h"
|
||||||
|
#include "shavite3.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace node;
|
using namespace node;
|
||||||
|
@ -360,6 +361,29 @@ Handle<Value> hefty1(const Arguments& args) {
|
||||||
return scope.Close(buff->handle_);
|
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) {
|
void init(Handle<Object> exports) {
|
||||||
exports->Set(String::NewSymbol("quark"), FunctionTemplate::New(quark)->GetFunction());
|
exports->Set(String::NewSymbol("quark"), FunctionTemplate::New(quark)->GetFunction());
|
||||||
exports->Set(String::NewSymbol("x11"), FunctionTemplate::New(x11)->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("fugue"), FunctionTemplate::New(fugue)->GetFunction());
|
||||||
exports->Set(String::NewSymbol("qubit"), FunctionTemplate::New(qubit)->GetFunction());
|
exports->Set(String::NewSymbol("qubit"), FunctionTemplate::New(qubit)->GetFunction());
|
||||||
exports->Set(String::NewSymbol("hefty1"), FunctionTemplate::New(hefty1)->GetFunction());
|
exports->Set(String::NewSymbol("hefty1"), FunctionTemplate::New(hefty1)->GetFunction());
|
||||||
|
exports->Set(String::NewSymbol("shavite3"), FunctionTemplate::New(shavite3)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(multihashing, init)
|
NODE_MODULE(multihashing, init)
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue