Skip to content

Commit dbc35af

Browse files
committed
Initial support for qubit
1 parent e0d291b commit dbc35af

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"groestl.c",
1616
"blake.c",
1717
"fugue.c",
18+
"qubit.c",
1819
"sha3/sph_fugue.c",
1920
"sha3/aes_helper.c",
2021
"sha3/sph_blake.c",

multihashing.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern "C" {
1515
#include "groestl.h"
1616
#include "blake.h"
1717
#include "fugue.h"
18+
#include "qubit.h"
1819
}
1920

2021
using namespace node;
@@ -312,6 +313,29 @@ Handle<Value> fugue(const Arguments& args) {
312313
return scope.Close(buff->handle_);
313314
}
314315

316+
317+
Handle<Value> qubit(const Arguments& args) {
318+
HandleScope scope;
319+
320+
if (args.Length() < 1)
321+
return except("You must provide one argument.");
322+
323+
Local<Object> target = args[0]->ToObject();
324+
325+
if(!Buffer::HasInstance(target))
326+
return except("Argument should be a buffer object.");
327+
328+
char * input = Buffer::Data(target);
329+
char * output = new char[32];
330+
331+
uint32_t input_len = Buffer::Length(target);
332+
333+
qubit_hash(input, output, input_len);
334+
335+
Buffer* buff = Buffer::New(output, 32);
336+
return scope.Close(buff->handle_);
337+
}
338+
315339
void init(Handle<Object> exports) {
316340
exports->Set(String::NewSymbol("quark"), FunctionTemplate::New(quark)->GetFunction());
317341
exports->Set(String::NewSymbol("x11"), FunctionTemplate::New(x11)->GetFunction());
@@ -325,6 +349,7 @@ void init(Handle<Object> exports) {
325349
exports->Set(String::NewSymbol("groestl_myriad"), FunctionTemplate::New(groestl_myriad)->GetFunction());
326350
exports->Set(String::NewSymbol("blake"), FunctionTemplate::New(blake)->GetFunction());
327351
exports->Set(String::NewSymbol("fugue"), FunctionTemplate::New(fugue)->GetFunction());
352+
exports->Set(String::NewSymbol("qubit"), FunctionTemplate::New(qubit)->GetFunction());
328353
}
329354

330355
NODE_MODULE(multihashing, init)

qubit.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "qubit.h"
2+
3+
#include "sha3/sph_cubehash.h"
4+
#include "sha3/sph_luffa.h"
5+
#include "sha3/sph_shavite.h"
6+
#include "sha3/sph_simd.h"
7+
#include "sha3/sph_echo.h"
8+
9+
void qubit_hash(const char* input, char* output, uint32_t len)
10+
{
11+
sph_luffa512_context ctx_luffa;
12+
sph_cubehash512_context ctx_cubehash;
13+
sph_shavite512_context ctx_shavite;
14+
sph_simd512_context ctx_simd;
15+
sph_echo512_context ctx_echo;
16+
17+
char* hash1 = (char*) malloc(64);
18+
char* hash2 = (char*) malloc(64);
19+
20+
sph_luffa512_init(&ctx_luffa);
21+
sph_luffa512(&ctx_luffa, (const void*) input, len);
22+
sph_luffa512_close(&ctx_luffa, (void*) hash1); //1
23+
24+
sph_cubehash512_init(&ctx_cubehash);
25+
sph_cubehash512(&ctx_cubehash, (const void*) hash1, 64); // 1
26+
sph_cubehash512_close(&ctx_cubehash, (void*) hash2); // 2
27+
28+
sph_shavite512_init(&ctx_shavite);
29+
sph_shavite512(&ctx_shavite, (const void*) hash2, 64); // 3
30+
sph_shavite512_close(&ctx_shavite, (void*) hash1); // 4
31+
32+
sph_simd512_init(&ctx_simd);
33+
sph_simd512(&ctx_simd, (const void*) hash1, 64); // 4
34+
sph_simd512_close(&ctx_simd, (void*) hash2); // 5
35+
36+
sph_echo512_init(&ctx_echo);
37+
sph_echo512(&ctx_echo, (const void*) hash2, 64); // 5
38+
sph_echo512_close(&ctx_echo, (void*) hash1); // 6
39+
40+
memcpy(output, hash1, 32);
41+
42+
free(hash1);
43+
free(hash2);
44+
}
45+

qubit.h

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

0 commit comments

Comments
 (0)