diff --git a/src/crypto/hash/index.js b/src/crypto/hash/index.js index e8a54954..9ade2a5a 100644 --- a/src/crypto/hash/index.js +++ b/src/crypto/hash/index.js @@ -4,13 +4,18 @@ */ var sha = require('./sha.js'), forge_sha256 = require('./forge_sha256.js'), + rusha = require('./rusha.js'), util = require('../../util.js'); module.exports = { /** @see module:crypto/hash/md5 */ md5: require('./md5.js'), /** @see module:crypto/hash/sha.sha1 */ - sha1: sha.sha1, + //sha1: sha.sha1, + sha1: function (data) { + var r = new rusha(); + return util.str2Uint8Array(util.hex2bin(r.digest(data))); + }, /** @see module:crypto/hash/sha.sha224 */ sha224: sha.sha224, /** @see module:crypto/hash/sha.sha256 */ @@ -35,13 +40,16 @@ module.exports = { return this.md5(data); case 2: // - SHA-1 [FIPS180] - return this.sha1(data); + // return this.sha1(data); + var r = new rusha(); + return util.str2Uint8Array(util.hex2bin(r.digest(data))); case 3: // - RIPE-MD/160 [HAC] return this.ripemd(data); case 8: // - SHA256 [FIPS180] //return this.sha256(data); + var sha256 = forge_sha256.create(); sha256.update(util.Uint8Array2str(data)); return util.str2Uint8Array(sha256.digest().getBytes()); diff --git a/src/crypto/public_key/dsa.js b/src/crypto/public_key/dsa.js index ae612f67..d9138c33 100644 --- a/src/crypto/public_key/dsa.js +++ b/src/crypto/public_key/dsa.js @@ -40,7 +40,7 @@ function DSA() { // of leftmost bits equal to the number of bits of q. This (possibly // truncated) hash function result is treated as a number and used // directly in the DSA signature algorithm. - var hashed_data = util.getLeftNBits(hashModule.digest(hashalgo, m), q.bitLength()); + var hashed_data = util.getLeftNBits(util.Uint8Array2str(hashModule.digest(hashalgo, util.str2Uint8Array(m))), q.bitLength()); var hash = new BigInteger(util.hexstrdump(hashed_data), 16); // FIPS-186-4, section 4.6: // The values of r and s shall be checked to determine if r = 0 or s = 0. @@ -100,7 +100,7 @@ function DSA() { this.select_hash_algorithm = select_hash_algorithm; function verify(hashalgo, s1, s2, m, p, q, g, y) { - var hashed_data = util.getLeftNBits(hashModule.digest(hashalgo, m), q.bitLength()); + var hashed_data = util.getLeftNBits(util.Uint8Array2str(hashModule.digest(hashalgo, util.str2Uint8Array(m))), q.bitLength()); var hash = new BigInteger(util.hexstrdump(hashed_data), 16); if (BigInteger.ZERO.compareTo(s1) >= 0 || s1.compareTo(q) >= 0 || diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index 909227d1..1331d6e4 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -83,10 +83,6 @@ function parse_cleartext_mpi(hash_algorithm, cleartext, algorithm) { var hash = util.Uint8Array2str(hashfn(cleartext)); - console.log(hash); - console.log(hashtext); - console.log(hash_algorithm); - if (hash != hashtext) return new Error("Hash mismatch."); @@ -245,7 +241,6 @@ SecretKey.prototype.decrypt = function (passphrase) { key = crypto.hash.md5(passphrase); } - // - [Optional] If secret data is encrypted (string-to-key usage octet // not zero), an Initial Vector (IV) of the same length as the // cipher's block size. diff --git a/src/type/s2k.js b/src/type/s2k.js index 10e9e7ec..a84f6fad 100644 --- a/src/type/s2k.js +++ b/src/type/s2k.js @@ -179,13 +179,14 @@ S2K.prototype.produce_key = function (passphrase, numBytes) { } var arr = [], - i = 0, rlength = 0, + prefix = ''; prefix = new Uint8Array(numBytes); for(var i = 0; i