Skip to content

Commit ec00b74

Browse files
committed
Initial FRESH support
1 parent 78da3eb commit ec00b74

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

binding.gyp

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"nist5.c",
2424
"sha1.c",
2525
"x15.c",
26+
"fresh.c",
2627
"sha3/sph_hefty1.c",
2728
"sha3/sph_fugue.c",
2829
"sha3/aes_helper.c",
@@ -48,7 +49,7 @@
4849
"crypto/c_skein.c",
4950
"crypto/hash.c",
5051
"crypto/aesb.c",
51-
"crypto/wild_keccak.cpp"
52+
"crypto/wild_keccak.cpp",
5253
],
5354
"include_dirs": [
5455
"crypto",

fresh.c

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include "fresh.h"
2+
#include <stdlib.h>
3+
#include <stdint.h>
4+
#include <string.h>
5+
#include <stdio.h>
6+
7+
#include "sha3/sph_shavite.h"
8+
#include "sha3/sph_simd.h"
9+
#include "sha3/sph_echo.h"
10+
11+
void fresh_hash(const char* input, char* output, uint32_t len)
12+
{
13+
sph_shavite512_context ctx_shavite1;
14+
sph_simd512_context ctx_simd1;
15+
sph_echo512_context ctx_echo1;
16+
17+
//these uint512 in the c++ source of the client are backed by an array of uint32
18+
uint32_t hashA[16], hashB[16];
19+
20+
sph_shavite512_init (&ctx_shavite1);
21+
sph_shavite512 (&ctx_shavite1, input, len);
22+
sph_shavite512_close(&ctx_shavite1, hashA);
23+
24+
sph_simd512_init (&ctx_simd1);
25+
sph_simd512 (&ctx_simd1, hashA, 64);
26+
sph_simd512_close(&ctx_simd1, hashB);
27+
28+
sph_shavite512_init (&ctx_shavite1);
29+
sph_shavite512 (&ctx_shavite1, hashB, 64);
30+
sph_shavite512_close(&ctx_shavite1, hashA);
31+
32+
sph_simd512_init (&ctx_simd1);
33+
sph_simd512 (&ctx_simd1, hashA, 64);
34+
sph_simd512_close(&ctx_simd1, hashB);
35+
36+
sph_echo512_init (&ctx_echo1);
37+
sph_echo512 (&ctx_echo1, hashB, 64);
38+
sph_echo512_close(&ctx_echo1, hashA);
39+
40+
memcpy(output, hashA, 32);
41+
42+
}

fresh.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef FRESH_H
2+
#define FRESH_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include <stdint.h>
9+
10+
void fresh_hash(const char* input, char* output, uint32_t len);
11+
12+
#ifdef __cplusplus
13+
}
14+
#endif
15+
16+
#endif

multihashing.cc

+24
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern "C" {
2222
#include "nist5.h"
2323
#include "sha1.h",
2424
#include "x15.h"
25+
#include "fresh.h"
2526
}
2627

2728
#include "boolberry.h"
@@ -551,6 +552,28 @@ Handle<Value> x15(const Arguments& args) {
551552
return scope.Close(buff->handle_);
552553
}
553554

555+
Handle<Value> fresh(const Arguments& args) {
556+
HandleScope scope;
557+
558+
if (args.Length() < 1)
559+
return except("You must provide one argument.");
560+
561+
Local<Object> target = args[0]->ToObject();
562+
563+
if(!Buffer::HasInstance(target))
564+
return except("Argument should be a buffer object.");
565+
566+
char * input = Buffer::Data(target);
567+
char output[32];
568+
569+
uint32_t input_len = Buffer::Length(target);
570+
571+
fresh_hash(input, output, input_len);
572+
573+
Buffer* buff = Buffer::New(output, 32);
574+
return scope.Close(buff->handle_);
575+
}
576+
554577
void init(Handle<Object> exports) {
555578
exports->Set(String::NewSymbol("quark"), FunctionTemplate::New(quark)->GetFunction());
556579
exports->Set(String::NewSymbol("x11"), FunctionTemplate::New(x11)->GetFunction());
@@ -573,6 +596,7 @@ void init(Handle<Object> exports) {
573596
exports->Set(String::NewSymbol("nist5"), FunctionTemplate::New(nist5)->GetFunction());
574597
exports->Set(String::NewSymbol("sha1"), FunctionTemplate::New(sha1)->GetFunction());
575598
exports->Set(String::NewSymbol("x15"), FunctionTemplate::New(x15)->GetFunction());
599+
exports->Set(String::NewSymbol("fresh"), FunctionTemplate::New(fresh)->GetFunction());
576600
}
577601

578602
NODE_MODULE(multihashing, init)

0 commit comments

Comments
 (0)