Initial fugue support

master
Lucas Jones 2014-04-19 20:28:17 +01:00
parent 1190307989
commit e0d291b318
6 changed files with 1345 additions and 0 deletions

View File

@ -14,6 +14,8 @@
"bcrypt.c",
"groestl.c",
"blake.c",
"fugue.c",
"sha3/sph_fugue.c",
"sha3/aes_helper.c",
"sha3/sph_blake.c",
"sha3/sph_bmw.c",

12
fugue.c 100644
View File

@ -0,0 +1,12 @@
#include "fugue.h"
#include "sha3/sph_fugue.h"
void fugue_hash(const char* input, char* output, uint32_t len)
{
sph_fugue256_context ctx_fugue;
sph_fugue256_init(&ctx_fugue);
sph_fugue256(&ctx_fugue, input, len);
sph_fugue256_close(&ctx_fugue, output);
}

16
fugue.h 100644
View File

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

View File

@ -14,6 +14,7 @@ extern "C" {
#include "x11.h"
#include "groestl.h"
#include "blake.h"
#include "fugue.h"
}
using namespace node;
@ -287,6 +288,30 @@ Handle<Value> blake(const Arguments& args) {
Buffer* buff = Buffer::New(output, 32);
return scope.Close(buff->handle_);
}
Handle<Value> fugue(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);
fugue_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());
@ -299,6 +324,7 @@ void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("groestl"), FunctionTemplate::New(groestl)->GetFunction());
exports->Set(String::NewSymbol("groestl_myriad"), FunctionTemplate::New(groestl_myriad)->GetFunction());
exports->Set(String::NewSymbol("blake"), FunctionTemplate::New(blake)->GetFunction());
exports->Set(String::NewSymbol("fugue"), FunctionTemplate::New(fugue)->GetFunction());
}
NODE_MODULE(multihashing, init)

1208
sha3/sph_fugue.c 100644

File diff suppressed because it is too large Load Diff

81
sha3/sph_fugue.h 100644
View File

@ -0,0 +1,81 @@
#ifndef SPH_FUGUE_H__
#define SPH_FUGUE_H__
#include <stddef.h>
#include "sph_types.h"
#ifdef __cplusplus
extern "C"{
#endif
#define SPH_SIZE_fugue224 224
#define SPH_SIZE_fugue256 256
#define SPH_SIZE_fugue384 384
#define SPH_SIZE_fugue512 512
typedef struct {
#ifndef DOXYGEN_IGNORE
sph_u32 partial;
unsigned partial_len;
unsigned round_shift;
sph_u32 S[36];
#if SPH_64
sph_u64 bit_count;
#else
sph_u32 bit_count_high, bit_count_low;
#endif
#endif
} sph_fugue_context;
typedef sph_fugue_context sph_fugue224_context;
typedef sph_fugue_context sph_fugue256_context;
typedef sph_fugue_context sph_fugue384_context;
typedef sph_fugue_context sph_fugue512_context;
void sph_fugue224_init(void *cc);
void sph_fugue224(void *cc, const void *data, size_t len);
void sph_fugue224_close(void *cc, void *dst);
void sph_fugue224_addbits_and_close(
void *cc, unsigned ub, unsigned n, void *dst);
void sph_fugue256_init(void *cc);
void sph_fugue256(void *cc, const void *data, size_t len);
void sph_fugue256_close(void *cc, void *dst);
void sph_fugue256_addbits_and_close(
void *cc, unsigned ub, unsigned n, void *dst);
void sph_fugue384_init(void *cc);
void sph_fugue384(void *cc, const void *data, size_t len);
void sph_fugue384_close(void *cc, void *dst);
void sph_fugue384_addbits_and_close(
void *cc, unsigned ub, unsigned n, void *dst);
void sph_fugue512_init(void *cc);
void sph_fugue512(void *cc, const void *data, size_t len);
void sph_fugue512_close(void *cc, void *dst);
void sph_fugue512_addbits_and_close(
void *cc, unsigned ub, unsigned n, void *dst);
#ifdef __cplusplus
}
#endif
#endif