Skip to content

Commit d098617

Browse files
committed
Merge pull request PhearNet#5 from LucasJones/master
Add support for more hash algorithms
2 parents b189052 + 08bf937 commit d098617

34 files changed

+2661
-1403
lines changed

binding.gyp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
"bcrypt.c",
1515
"groestl.c",
1616
"blake.c",
17+
"fugue.c",
18+
"qubit.c",
19+
"hefty1.c",
20+
"shavite3.c",
21+
"sha3/sph_hefty1.c",
22+
"sha3/sph_fugue.c",
1723
"sha3/aes_helper.c",
1824
"sha3/sph_blake.c",
1925
"sha3/sph_bmw.c",

blake.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "sha3/sph_blake.h"
88

99

10-
void blake_hash(const char* input, char* output, unsigned int len)
10+
void blake_hash(const char* input, char* output, uint32_t len)
1111
{
1212
sph_blake256_context ctx_blake;
1313
sph_blake256_init(&ctx_blake);

blake.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
extern "C" {
66
#endif
77

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

1012
#ifdef __cplusplus
1113
}

fugue.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "fugue.h"
2+
3+
#include "sha3/sph_fugue.h"
4+
5+
void fugue_hash(const char* input, char* output, uint32_t len)
6+
{
7+
sph_fugue256_context ctx_fugue;
8+
sph_fugue256_init(&ctx_fugue);
9+
sph_fugue256(&ctx_fugue, input, len);
10+
sph_fugue256_close(&ctx_fugue, output);
11+
}
12+

fugue.h

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

groestl.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,36 @@
55
#include <stdio.h>
66

77
#include "sha3/sph_groestl.h"
8+
#include "sha256.h"
89

10+
void groestl_hash(const char* input, char* output, uint32_t len)
11+
{
12+
char hash1[64];
13+
char hash2[64];
14+
15+
sph_groestl512_context ctx_groestl;
16+
sph_groestl512_init(&ctx_groestl);
17+
sph_groestl512(&ctx_groestl, input, len);
18+
sph_groestl512_close(&ctx_groestl, &hash1);
19+
20+
sph_groestl512(&ctx_groestl, hash1, 64);
21+
sph_groestl512_close(&ctx_groestl, &hash2);
22+
23+
memcpy(output, &hash2, 32);
24+
}
925

10-
void groestl_hash(const char* input, char* output, unsigned int len)
26+
void groestl_myriad_hash(const char* input, char* output, uint32_t len)
1127
{
12-
sph_groestl256_context ctx_groestl;
13-
sph_groestl256_init(&ctx_groestl);
14-
sph_groestl256(&ctx_groestl, input, len);
15-
sph_groestl256_close(&ctx_groestl, output);
28+
char temp[64];
29+
30+
sph_groestl512_context ctx_groestl;
31+
sph_groestl512_init(&ctx_groestl);
32+
sph_groestl512(&ctx_groestl, input, len);
33+
sph_groestl512_close(&ctx_groestl, &temp);
34+
35+
SHA256_CTX ctx_sha256;
36+
SHA256_Init(&ctx_sha256);
37+
SHA256_Update(&ctx_sha256, &temp, 64);
38+
SHA256_Final((unsigned char*) output, &ctx_sha256);
1639
}
1740

groestl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
extern "C" {
66
#endif
77

8-
void groestl_hash(const char* input, char* output, unsigned int len);
8+
#include <stdint.h>
9+
10+
void groestl_hash(const char* input, char* output, uint32_t len);
11+
void groestl_myriad_hash(const char* input, char* output, uint32_t len);
912

1013
#ifdef __cplusplus
1114
}

hefty1.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "hefty1.h"
2+
3+
#include "sha3/sph_hefty1.h"
4+
#include "sha3/sph_keccak.h"
5+
#include "sha3/sph_groestl.h"
6+
#include "sha3/sph_blake.h"
7+
#include "sha256.h"
8+
9+
void hefty1_hash(const char* input, char* output, uint32_t len)
10+
{
11+
HEFTY1_CTX ctx_hefty1;
12+
SHA256_CTX ctx_sha256;
13+
sph_keccak512_context ctx_keccak;
14+
sph_groestl512_context ctx_groestl;
15+
sph_blake512_context ctx_blake;
16+
17+
char hash32_1[32];
18+
char hash32_2[32];
19+
char hash64_3[64];
20+
char hash64_4[64];
21+
char hash64_5[64];
22+
23+
HEFTY1_Init(&ctx_hefty1);
24+
HEFTY1_Update(&ctx_hefty1, (const void*) input, len);
25+
HEFTY1_Final((unsigned char*) &hash32_1, &ctx_hefty1); // 1
26+
27+
SHA256_Init(&ctx_sha256);
28+
SHA256_Update(&ctx_sha256, (const void*) input, len);
29+
SHA256_Update(&ctx_sha256, (unsigned char*) &hash32_1, 32); // 1
30+
SHA256_Final((unsigned char*) &hash32_2, &ctx_sha256); // 2
31+
32+
sph_keccak512_init(&ctx_keccak);
33+
sph_keccak512(&ctx_keccak, (const void*) input, len);
34+
sph_keccak512(&ctx_keccak, (unsigned char*) &hash32_1, 32); //1
35+
sph_keccak512_close(&ctx_keccak, (void*) &hash64_3); // 3
36+
37+
sph_groestl512_init(&ctx_groestl);
38+
sph_groestl512(&ctx_groestl, (const void*) input, len);
39+
sph_groestl512(&ctx_groestl, (unsigned char*) &hash32_1, 32); // 1
40+
sph_groestl512_close(&ctx_groestl, (void*) &hash64_4); // 4
41+
42+
sph_blake512_init(&ctx_blake);
43+
sph_blake512(&ctx_blake, (const void*) input, len);
44+
sph_blake512(&ctx_blake, (unsigned char*) &hash32_1, 32); // 1
45+
sph_blake512_close(&ctx_blake, (void*) &hash64_5); // 5
46+
47+
memset(output, 0, 32);
48+
49+
char* hash[4] = { &hash32_2, &hash64_3, &hash64_4, &hash64_5 };
50+
51+
uint32_t i;
52+
uint32_t j;
53+
54+
#define OUTPUT_BIT (i * 4 + j)
55+
56+
for(i = 0; i < 64; i++) {
57+
for(j = 0; j < 4; j++) {
58+
if((*(hash[j] + (i / 8)) & (0x80 >> (i % 8))) != 0)
59+
*(output + (OUTPUT_BIT / 8)) |= 0x80 >> (OUTPUT_BIT % 8);
60+
}
61+
}
62+
}
63+

hefty1.h

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

keccak.c

Lines changed: 1 addition & 5 deletions
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

Lines changed: 3 additions & 1 deletion
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
}

0 commit comments

Comments
 (0)