From 5cfb47c470c2fd057f6ff066b21a4d9307fbd1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Thu, 22 Jan 2015 21:50:07 +0100 Subject: [PATCH] Use wrappers for get and set prefs Fix some syntax issues in hmac.js --- firefox_addon/lib/hmac.js | 32 +++++++++++++++++--------------- firefox_addon/lib/main.js | 22 ++++++++++++++++------ firefox_addon/lib/pkdbf2.js | 8 ++++---- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/firefox_addon/lib/hmac.js b/firefox_addon/lib/hmac.js index a70525d..257c39a 100644 --- a/firefox_addon/lib/hmac.js +++ b/firefox_addon/lib/hmac.js @@ -22,19 +22,21 @@ var {Cc, Ci} = require("chrome"); var hmac = Cc["@mozilla.org/security/hmac;1"] .createInstance(Ci.nsICryptoHMAC); -function hmac_init(key) { - var keyObject = Cc["@mozilla.org/security/keyobjectfactory;1"] - .getService(Ci.nsIKeyObjectFactory) - .keyFromString(Ci.nsIKeyObject.HMAC, key); - hmac.init(hmac.SHA256, keyObject); -} +exports.hmac = { + hmac_init : function (key) { + var keyObject = Cc["@mozilla.org/security/keyobjectfactory;1"] + .getService(Ci.nsIKeyObjectFactory) + .keyFromString(Ci.nsIKeyObject.HMAC, key); + hmac.init(hmac.SHA256, keyObject); + }, -function hmac_digest(message) { - var data = new Uint8Array(message.length); - for(i=0; i. */ -require("hmac.js"); +var hmac = require("hmac.js").hmac; exports.pkdbf2 = { @@ -28,10 +28,10 @@ exports.pkdbf2 = { var temp_res = ""; var temp_res2 = ""; - hmac_init(password); + hmac.hmac_init(password); for (i=1; result.length < outlen; i++) { - temp = hmac_digest(salt + + temp = hmac.hmac_digest(salt + String.fromCharCode((i & 0xff000000) >> 24) + String.fromCharCode((i & 0x00ff0000) >> 16) + String.fromCharCode((i & 0x0000ff00) >> 8) + @@ -41,7 +41,7 @@ exports.pkdbf2 = { for(a=1; a