Skip to content

Commit 9805bde

Browse files
authored
Merge pull request #119 from jrnewell/hash_parameters_fix
hash/hashSync functions don't take the params object correctly
2 parents 68e2698 + 4961d6c commit 9805bde

5 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/node-boilerplate/scrypt_hash_async.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ using namespace v8;
3838
// Scrypt Hash Function
3939
//
4040
void ScryptHashAsyncWorker::Execute() {
41-
result = ScryptHashFunction(key_ptr, key_size, salt_ptr, salt_size, params.N, params.r, params.p, hash_ptr, hash_size);
41+
result = Hash(key_ptr, key_size, salt_ptr, salt_size, params.N, params.r, params.p, hash_ptr, hash_size);
4242
}
4343

4444
void ScryptHashAsyncWorker::HandleOKCallback() {

src/node-boilerplate/scrypt_hash_sync.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ NAN_METHOD(hashSync) {
3535
//
3636
// Scrypt key derivation function
3737
//
38-
const unsigned int result = ScryptHashFunction(key_ptr, key_size, salt_ptr, salt_size, params.N, params.r, params.p, hash_ptr, hash_size);
38+
const unsigned int result = Hash(key_ptr, key_size, salt_ptr, salt_size, params.N, params.r, params.p, hash_ptr, hash_size);
3939

4040
//
4141
// Error handling

src/scryptwrapper/hash.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ Barry Steyn barry.steyn@gmail.com
3030
#include <errno.h>
3131
#include "crypto_scrypt.h"
3232
#include "pickparams.h"
33+
#include "hash.h"
34+
35+
//
36+
// This is the function that the hash and hashSync api functions use.
37+
// Does final modifications to parameters
38+
//
39+
unsigned int
40+
Hash(const uint8_t* key, size_t keylen, const uint8_t *salt, size_t saltlen, uint64_t logN, uint32_t r, uint32_t p, uint8_t *buf, size_t buflen) {
41+
uint64_t N=1;
42+
43+
N <<= logN;
44+
return (ScryptHashFunction(key, keylen, salt, saltlen, N, r, p, buf, buflen));
45+
}
3346

3447
//
3548
// This is the actual key derivation function.

src/scryptwrapper/inc/hash.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Barry Steyn barry.steyn@gmail.com
2525
#ifndef _KEYDERIVATION_H_
2626
#define _KEYDERIVATION_H_
2727

28+
unsigned int
29+
Hash(const uint8_t*, size_t, const uint8_t*, size_t, uint64_t, uint32_t, uint32_t, uint8_t*, size_t);
30+
2831
unsigned int
2932
ScryptHashFunction(const uint8_t*, size_t, const uint8_t*, size_t, uint64_t, uint32_t, uint32_t, uint8_t*, size_t);
3033

tests/scrypt-tests.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,26 +611,26 @@ describe("Scrypt Node Module Tests", function() {
611611
describe("Test vectors", function() {
612612
describe("Synchronous", function() {
613613
it("Vector 1: Will produce an identical vector to scrypt paper", function() {
614-
var result = scrypt.hashSync("", {"N":16,"r":1,"p":1}, 64, "");
614+
var result = scrypt.hashSync("", {"N":4,"r":1,"p":1}, 64, "");
615615
expect(result.toString("hex"))
616616
.to.equal("77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906");
617617
})
618618

619619
it("Vector 2: Will produce an identical vector to scrypt paper", function() {
620-
var result = scrypt.hashSync("password",{"N":1024,"r":8,"p":16},64, new Buffer("NaCl"));
620+
var result = scrypt.hashSync("password",{"N":10,"r":8,"p":16},64, new Buffer("NaCl"));
621621
expect(result.toString("hex"))
622622
.to.equal("fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640");
623623
})
624624

625625
it("Vector 3: Will produce an identical vector to scrypt paper", function() {
626-
var result = scrypt.hashSync(new Buffer("pleaseletmein"),{"N":16384,"r":8,"p":1},64, "SodiumChloride");
626+
var result = scrypt.hashSync(new Buffer("pleaseletmein"),{"N":14,"r":8,"p":1},64, "SodiumChloride");
627627
expect(result.toString("hex"))
628628
.to.equal("7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887");
629629
})
630630
});
631631
describe("Aynchronous", function() {
632632
it("Vector 1: Will produce an identical vector to scrypt paper", function(done) {
633-
scrypt.hash("", {"N":16,"r":1,"p":1}, 64, "", function(err, result) {
633+
scrypt.hash("", {"N":4,"r":1,"p":1}, 64, "", function(err, result) {
634634
expect(result.toString("hex"))
635635
.to.equal("77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906");
636636
expect(err)
@@ -640,7 +640,7 @@ describe("Scrypt Node Module Tests", function() {
640640
});
641641

642642
it("Vector 2: Will produce an identical vector to scrypt paper", function(done) {
643-
scrypt.hash(new Buffer("password"),{"N":1024,"r":8,"p":16},64, new Buffer("NaCl"), function(err, result) {
643+
scrypt.hash(new Buffer("password"),{"N":10,"r":8,"p":16},64, new Buffer("NaCl"), function(err, result) {
644644
expect(result.toString("hex"))
645645
.to.equal("fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640");
646646
expect(err)
@@ -650,7 +650,7 @@ describe("Scrypt Node Module Tests", function() {
650650
});
651651

652652
it("Vector 3: Will produce an identical vector to scrypt paper", function(done) {
653-
scrypt.hash("pleaseletmein",{"N":16384,"r":8,"p":1},64, "SodiumChloride", function(err, result) {
653+
scrypt.hash("pleaseletmein",{"N":14,"r":8,"p":1},64, "SodiumChloride", function(err, result) {
654654
expect(result.toString("hex"))
655655
.to.equal("7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887");
656656
expect(err)

0 commit comments

Comments
 (0)