Skip to content

Commit a598ea1

Browse files
committed
Updated keccak hashing to allow variable size, required for maxcoin and its clones.
1 parent 2b058ac commit a598ea1

File tree

3 files changed

+7
-35
lines changed

3 files changed

+7
-35
lines changed

keccak.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
#include <string.h>
55
#include <stdio.h>
66

7+
#include "sha3/sph_types.h"
78
#include "sha3/sph_keccak.h"
89

910

10-
void keccak_hash(const char* input, char* output)
11+
void keccak_hash(const char* input, char* output, int * size)
1112
{
1213
sph_keccak256_context ctx_keccak;
1314
sph_keccak256_init(&ctx_keccak);
14-
sph_keccak256 (&ctx_keccak, input, 80);
15+
sph_keccak256 (&ctx_keccak, input, size);//80);
1516
sph_keccak256_close(&ctx_keccak, output);
1617
}
1718

keccak.h

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

8-
void keccak_hash(const char* input, char* output);
8+
void keccak_hash(const char* input, char* output, int * size);
99

1010
#ifdef __cplusplus
1111
}

multihashing.cc

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,6 @@ extern "C" {
1313
#include "x11.h"
1414

1515

16-
/*static unsigned char getNfactor(char* blockheader) {
17-
int n,l = 0;
18-
unsigned long nTimestamp = *(unsigned int*)(&blockheader[68]);
19-
unsigned char minNfactor = 10;
20-
unsigned char maxNfactor = 30;
21-
unsigned char N;
22-
uint64_t s;
23-
24-
if (nTimestamp <= 1389306217) {
25-
return minNfactor;
26-
}
27-
28-
s = nTimestamp - 1389306217;
29-
while ((s >> 1) > 3) {
30-
l += 1;
31-
s >>= 1;
32-
}
33-
34-
s &= 3;
35-
36-
n = (l * 158 + s * 28 - 2670) / 100;
37-
38-
if (n < 0) n = 0;
39-
40-
N = (unsigned char) n;
41-
n = N > minNfactor ? N : minNfactor;
42-
N = n < maxNfactor ? n : maxNfactor;
43-
44-
return N;
45-
}*/
46-
4716
#define max(a,b) (((a) > (b)) ? (a) : (b))
4817
#define min(a,b) (((a) < (b)) ? (a) : (b))
4918
unsigned char GetNfactorJane(int nTimestamp, int nChainStartTime, int nMin, int nMax) {
@@ -228,7 +197,9 @@ Handle<Value> keccak(const Arguments& args) {
228197
char * input = Buffer::Data(target);
229198
char * output = new char[32];
230199

231-
keccak_hash(input, output);
200+
int* dSize = (int*)Buffer::Length(target);
201+
202+
keccak_hash(input, output, dSize);
232203

233204
Buffer* buff = Buffer::New(output, 32);
234205
return scope.Close(buff->handle_);

0 commit comments

Comments
 (0)