Skip to content

Commit

Permalink
Use keccak package
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Apr 8, 2017
1 parent 720ff7e commit 5c03042
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 198 deletions.
16 changes: 10 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ var crypto = require("crypto");
var sjcl = require("sjcl");
var uuid = require("uuid");
var secp256k1 = require("secp256k1/elliptic");
var keccak = require("./lib/keccak");
var createKeccakHash = require("keccak/js");
var scrypt = require("./lib/scrypt");

function isFunction(f) {
return typeof f === "function";
}

function keccak256(buffer) {
return createKeccakHash("keccak256").update(buffer).digest();
}

module.exports = {

browser: typeof process === "undefined" || !process.nextTick || Boolean(process.browser),
Expand Down Expand Up @@ -163,7 +167,7 @@ module.exports = {
]);
}
publicKey = secp256k1.publicKeyCreate(privateKeyBuffer, false).slice(1);
return "0x" + keccak(this.hex2utf16le(publicKey.toString("hex"))).slice(-40);
return "0x" + keccak256(publicKey).slice(-20).toString("hex");
},

/**
Expand All @@ -177,9 +181,9 @@ module.exports = {
*/
getMAC: function (derivedKey, ciphertext) {
if (derivedKey !== undefined && derivedKey !== null && ciphertext !== undefined && ciphertext !== null) {
if (Buffer.isBuffer(derivedKey)) derivedKey = derivedKey.toString("hex");
if (Buffer.isBuffer(ciphertext)) ciphertext = ciphertext.toString("hex");
return keccak(this.hex2utf16le(derivedKey.slice(32, 64) + ciphertext));
derivedKey = this.str2buf(derivedKey);
ciphertext = this.str2buf(ciphertext);
return keccak256(Buffer.concat([derivedKey.slice(16, 32), ciphertext])).toString("hex");
}
},

Expand Down Expand Up @@ -417,7 +421,7 @@ module.exports = {
throw new Error("message authentication code mismatch");
}
if (keyObject.version === "1") {
key = Buffer.from(keccak(self.hex2utf16le(derivedKey.toString("hex").slice(0, 32))), "hex").slice(0, 16);
key = keccak256(derivedKey.slice(0, 16)).slice(0, 16);
} else {
key = derivedKey.slice(0, 16);
}
Expand Down
192 changes: 0 additions & 192 deletions lib/keccak.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"homepage": "https://github.com/ethereumjs/keythereum#readme",
"dependencies": {
"keccak": "1.2.0",
"secp256k1": "3.2.5",
"sjcl": "1.0.6",
"uuid": "3.0.0"
Expand Down

0 comments on commit 5c03042

Please sign in to comment.