Skip to content

Commit 9625004

Browse files
committed
Change scrypt so that N and R values can be specified
Remove scrypt.c in the name of removing code duplication
1 parent 2be90f2 commit 9625004

File tree

6 files changed

+8
-278
lines changed

6 files changed

+8
-278
lines changed

binding.gyp

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"target_name": "multihashing",
55
"sources": [
66
"multihashing.cc",
7-
"scrypt.c",
87
"scryptjane.c",
98
"scryptn.c",
109
"keccak.c",

multihashing.cc

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ extern "C" {
77
#include "bcrypt.h"
88
#include "keccak.h"
99
#include "quark.h"
10-
#include "scrypt.h"
1110
#include "scryptjane.h"
1211
#include "scryptn.h"
1312
#include "skein.h"

scrypt.c

-258
This file was deleted.

scrypt.h

-10
This file was deleted.

scryptn.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ smix(uint8_t * B, size_t r, uint64_t N, uint32_t * V, uint32_t * XY)
217217
/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
218218
scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes
219219
*/
220-
void scrypt_N_1_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t len)
220+
void scrypt_N_R_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t R, uint32_t len)
221221
{
222222
uint8_t * B;
223223
uint32_t * V;
224224
uint32_t * XY;
225225
uint32_t i;
226226

227227
//const uint32_t N = 1024;
228-
const uint32_t r = 1;
228+
uint32_t r=R;
229229
const uint32_t p = 1;
230230

231231
B = (uint8_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));
@@ -245,14 +245,14 @@ void scrypt_N_1_1_256_sp(const char* input, char* output, char* scratchpad, uint
245245
PBKDF2_SHA256((const uint8_t*)input, len, B, p * 128 * r, 1, (uint8_t*)output, 32);
246246
}
247247

248-
void scrypt_N_1_1_256(const char* input, char* output, uint32_t N, uint32_t len)
248+
void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len)
249249
{
250250
//char scratchpad[131583];
251251
char *scratchpad;
252252

253253
// align on 4 byte boundary
254-
scratchpad = (char*)malloc(128*N + 512);
255-
scrypt_N_1_1_256_sp(input, output, scratchpad, N, len);
254+
scratchpad = (char*)malloc(128*N*R + (128*R)+(256*R)+64+64);
255+
scrypt_N_R_1_256_sp(input, output, scratchpad, N, R, len);
256256
free(scratchpad);
257257
}
258258

scryptn.h

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

8-
void scrypt_N_1_1_256(const char* input, char* output, uint32_t N, uint32_t len);
9-
void scrypt_N_1_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t len);
8+
void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len);
9+
void scrypt_N_R_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t R, uint32_t len);
1010
//const int scrypt_scratchpad_size = 131583;
1111

1212
#ifdef __cplusplus
1313
}
1414
#endif
1515

16-
#endif
16+
#endif

0 commit comments

Comments
 (0)