Skip to content

Commit 4a686c0

Browse files
committed
Initial shavite3 support
1 parent 5d73e6f commit 4a686c0

File tree

7 files changed

+72
-6
lines changed

7 files changed

+72
-6
lines changed

binding.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"fugue.c",
1818
"qubit.c",
1919
"hefty1.c",
20+
"shavite3.c",
2021
"sha3/sph_hefty1.c",
2122
"sha3/sph_fugue.c",
2223
"sha3/aes_helper.c",

keccak.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#include "keccak.h"
2-
#include <stdlib.h>
3-
#include <stdint.h>
4-
#include <string.h>
5-
#include <stdio.h>
62

73
#include "sha3/sph_types.h"
84
#include "sha3/sph_keccak.h"
95

106

11-
void keccak_hash(const char* input, char* output, unsigned int size)
7+
void keccak_hash(const char* input, char* output, uint32_t size)
128
{
139
sph_keccak256_context ctx_keccak;
1410
sph_keccak256_init(&ctx_keccak);

keccak.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
extern "C" {
66
#endif
77

8-
void keccak_hash(const char* input, char* output, unsigned int size);
8+
#include <stdint.h>
9+
10+
void keccak_hash(const char* input, char* output, uint32_t size);
911

1012
#ifdef __cplusplus
1113
}

multihashing.cc

+25
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern "C" {
1717
#include "fugue.h"
1818
#include "qubit.h"
1919
#include "hefty1.h"
20+
#include "shavite3.h"
2021
}
2122

2223
using namespace node;
@@ -360,6 +361,29 @@ Handle<Value> hefty1(const Arguments& args) {
360361
return scope.Close(buff->handle_);
361362
}
362363

364+
365+
Handle<Value> shavite3(const Arguments& args) {
366+
HandleScope scope;
367+
368+
if (args.Length() < 1)
369+
return except("You must provide one argument.");
370+
371+
Local<Object> target = args[0]->ToObject();
372+
373+
if(!Buffer::HasInstance(target))
374+
return except("Argument should be a buffer object.");
375+
376+
char * input = Buffer::Data(target);
377+
char * output = new char[32];
378+
379+
uint32_t input_len = Buffer::Length(target);
380+
381+
shavite3_hash(input, output, input_len);
382+
383+
Buffer* buff = Buffer::New(output, 32);
384+
return scope.Close(buff->handle_);
385+
}
386+
363387
void init(Handle<Object> exports) {
364388
exports->Set(String::NewSymbol("quark"), FunctionTemplate::New(quark)->GetFunction());
365389
exports->Set(String::NewSymbol("x11"), FunctionTemplate::New(x11)->GetFunction());
@@ -375,6 +399,7 @@ void init(Handle<Object> exports) {
375399
exports->Set(String::NewSymbol("fugue"), FunctionTemplate::New(fugue)->GetFunction());
376400
exports->Set(String::NewSymbol("qubit"), FunctionTemplate::New(qubit)->GetFunction());
377401
exports->Set(String::NewSymbol("hefty1"), FunctionTemplate::New(hefty1)->GetFunction());
402+
exports->Set(String::NewSymbol("shavite3"), FunctionTemplate::New(shavite3)->GetFunction());
378403
}
379404

380405
NODE_MODULE(multihashing, init)

shavite3.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "shavite3.h"
2+
3+
#include "sha3/sph_shavite.h"
4+
5+
void shavite3_hash(const char* input, char* output, uint32_t len)
6+
{
7+
char* hash1 = (char*) malloc(64);
8+
char* hash2 = (char*) malloc(64);
9+
10+
sph_shavite512_context ctx_shavite;
11+
12+
sph_shavite512_init(&ctx_shavite);
13+
sph_shavite512(&ctx_shavite, (const void*) input, len);
14+
sph_shavite512_close(&ctx_shavite, (void*) hash1);
15+
16+
sph_shavite512(&ctx_shavite, (const void*) hash1, 64);
17+
sph_shavite512_close(&ctx_shavite, (void*) hash2);
18+
19+
memcpy(output, hash2, 32);
20+
21+
free(hash1);
22+
free(hash2);
23+
}
24+

shavite3.h

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

x11.h

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
extern "C" {
66
#endif
77

8+
#include <stdint.h>
9+
810
void x11_hash(const char* input, char* output, uint32_t len);
911

1012
#ifdef __cplusplus

0 commit comments

Comments
 (0)