Initial FRESH support

master
Lucas Jones 2014-07-07 21:51:55 +01:00
parent 78da3eb9b2
commit ec00b7429b
4 changed files with 84 additions and 1 deletions

View File

@ -23,6 +23,7 @@
"nist5.c",
"sha1.c",
"x15.c",
"fresh.c",
"sha3/sph_hefty1.c",
"sha3/sph_fugue.c",
"sha3/aes_helper.c",
@ -48,7 +49,7 @@
"crypto/c_skein.c",
"crypto/hash.c",
"crypto/aesb.c",
"crypto/wild_keccak.cpp"
"crypto/wild_keccak.cpp",
],
"include_dirs": [
"crypto",

42
fresh.c 100644
View File

@ -0,0 +1,42 @@
#include "fresh.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "sha3/sph_shavite.h"
#include "sha3/sph_simd.h"
#include "sha3/sph_echo.h"
void fresh_hash(const char* input, char* output, uint32_t len)
{
sph_shavite512_context ctx_shavite1;
sph_simd512_context ctx_simd1;
sph_echo512_context ctx_echo1;
//these uint512 in the c++ source of the client are backed by an array of uint32
uint32_t hashA[16], hashB[16];
sph_shavite512_init (&ctx_shavite1);
sph_shavite512 (&ctx_shavite1, input, len);
sph_shavite512_close(&ctx_shavite1, hashA);
sph_simd512_init (&ctx_simd1);
sph_simd512 (&ctx_simd1, hashA, 64);
sph_simd512_close(&ctx_simd1, hashB);
sph_shavite512_init (&ctx_shavite1);
sph_shavite512 (&ctx_shavite1, hashB, 64);
sph_shavite512_close(&ctx_shavite1, hashA);
sph_simd512_init (&ctx_simd1);
sph_simd512 (&ctx_simd1, hashA, 64);
sph_simd512_close(&ctx_simd1, hashB);
sph_echo512_init (&ctx_echo1);
sph_echo512 (&ctx_echo1, hashB, 64);
sph_echo512_close(&ctx_echo1, hashA);
memcpy(output, hashA, 32);
}

16
fresh.h 100644
View File

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

View File

@ -22,6 +22,7 @@ extern "C" {
#include "nist5.h"
#include "sha1.h",
#include "x15.h"
#include "fresh.h"
}
#include "boolberry.h"
@ -551,6 +552,28 @@ Handle<Value> x15(const Arguments& args) {
return scope.Close(buff->handle_);
}
Handle<Value> fresh(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);
fresh_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());
@ -573,6 +596,7 @@ void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("nist5"), FunctionTemplate::New(nist5)->GetFunction());
exports->Set(String::NewSymbol("sha1"), FunctionTemplate::New(sha1)->GetFunction());
exports->Set(String::NewSymbol("x15"), FunctionTemplate::New(x15)->GetFunction());
exports->Set(String::NewSymbol("fresh"), FunctionTemplate::New(fresh)->GetFunction());
}
NODE_MODULE(multihashing, init)