Skip to content

Commit e9d7760

Browse files
HashUnlimitedzone117x
authored andcommitted
Add C11 Algo support (zone117x#57)
1 parent 4b77e4a commit e9d7760

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

c11.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include "c11.h"
2+
#include <stdlib.h>
3+
#include <stdint.h>
4+
#include <string.h>
5+
#include <stdio.h>
6+
7+
#include "sha3/sph_blake.h"
8+
#include "sha3/sph_bmw.h"
9+
#include "sha3/sph_groestl.h"
10+
#include "sha3/sph_jh.h"
11+
#include "sha3/sph_keccak.h"
12+
#include "sha3/sph_skein.h"
13+
#include "sha3/sph_luffa.h"
14+
#include "sha3/sph_cubehash.h"
15+
#include "sha3/sph_shavite.h"
16+
#include "sha3/sph_simd.h"
17+
#include "sha3/sph_echo.h"
18+
19+
20+
void c11_hash(const char* input, char* output, uint32_t len)
21+
{
22+
sph_blake512_context ctx_blake;
23+
sph_bmw512_context ctx_bmw;
24+
sph_groestl512_context ctx_groestl;
25+
sph_skein512_context ctx_skein;
26+
sph_jh512_context ctx_jh;
27+
sph_keccak512_context ctx_keccak;
28+
29+
sph_luffa512_context ctx_luffa1;
30+
sph_cubehash512_context ctx_cubehash1;
31+
sph_shavite512_context ctx_shavite1;
32+
sph_simd512_context ctx_simd1;
33+
sph_echo512_context ctx_echo1;
34+
35+
//these uint512 in the c++ source of the client are backed by an array of uint32
36+
uint32_t hashA[16], hashB[16];
37+
38+
sph_blake512_init(&ctx_blake);
39+
sph_blake512 (&ctx_blake, input, 80);
40+
sph_blake512_close (&ctx_blake, hashA);
41+
42+
sph_bmw512_init(&ctx_bmw);
43+
sph_bmw512 (&ctx_bmw, hashA, 64);
44+
sph_bmw512_close(&ctx_bmw, hashB);
45+
46+
sph_groestl512_init(&ctx_groestl);
47+
sph_groestl512 (&ctx_groestl, hashB, 64);
48+
sph_groestl512_close(&ctx_groestl, hashA);
49+
50+
sph_jh512_init(&ctx_jh);
51+
sph_jh512 (&ctx_jh, hashA, 64);
52+
sph_jh512_close(&ctx_jh, hashB);
53+
54+
sph_keccak512_init(&ctx_keccak);
55+
sph_keccak512 (&ctx_keccak, hashB, 64);
56+
sph_keccak512_close(&ctx_keccak, hashA);
57+
58+
sph_skein512_init(&ctx_skein);
59+
sph_skein512 (&ctx_skein, hashA, 64);
60+
sph_skein512_close (&ctx_skein, hashB);
61+
62+
sph_luffa512_init (&ctx_luffa1);
63+
sph_luffa512 (&ctx_luffa1, hashB, 64);
64+
sph_luffa512_close (&ctx_luffa1, hashA);
65+
66+
sph_cubehash512_init (&ctx_cubehash1);
67+
sph_cubehash512 (&ctx_cubehash1, hashA, 64);
68+
sph_cubehash512_close(&ctx_cubehash1, hashB);
69+
70+
sph_shavite512_init (&ctx_shavite1);
71+
sph_shavite512 (&ctx_shavite1, hashB, 64);
72+
sph_shavite512_close(&ctx_shavite1, hashA);
73+
74+
sph_simd512_init (&ctx_simd1);
75+
sph_simd512 (&ctx_simd1, hashA, 64);
76+
sph_simd512_close(&ctx_simd1, hashB);
77+
78+
sph_echo512_init (&ctx_echo1);
79+
sph_echo512 (&ctx_echo1, hashB, 64);
80+
sph_echo512_close(&ctx_echo1, hashA);
81+
82+
memcpy(output, hashA, 32);
83+
84+
}
85+

c11.h

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

multihashing.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
extern "C" {
77
#include "bcrypt.h"
88
#include "blake.h"
9+
#include "c11.h"
910
#include "cryptonight.h"
1011
#include "fresh.h"
1112
#include "fugue.h"
@@ -102,6 +103,7 @@ using namespace v8;
102103

103104
DECLARE_CALLBACK(bcrypt, bcrypt_hash, 32);
104105
DECLARE_CALLBACK(blake, blake_hash, 32);
106+
DECLARE_CALLBACK(c11, c11_hash, 32);
105107
DECLARE_CALLBACK(fresh, fresh_hash, 32);
106108
DECLARE_CALLBACK(fugue, fugue_hash, 32);
107109
DECLARE_CALLBACK(groestl, groestl_hash, 32);
@@ -272,6 +274,7 @@ DECLARE_INIT(init) {
272274
NODE_SET_METHOD(exports, "bcrypt", bcrypt);
273275
NODE_SET_METHOD(exports, "blake", blake);
274276
NODE_SET_METHOD(exports, "boolberry", boolberry);
277+
NODE_SET_METHOD(exports, "c11", c11);
275278
NODE_SET_METHOD(exports, "cryptonight", cryptonight);
276279
NODE_SET_METHOD(exports, "fresh", fresh);
277280
NODE_SET_METHOD(exports, "fugue", fugue);

0 commit comments

Comments
 (0)