Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make more cross-browser, in case chrome ever gets their shit together
- Loading branch information
1 parent
01f971a
commit 8a5eb26
Showing
16 changed files
with
512 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,49 @@ | ||
crypto.hash.HMAC = function(key, msg, digestmod) { | ||
var hasher = Components.classes["@mozilla.org/security/hmac;1"].createInstance(Components.interfaces.nsICryptoHMAC); | ||
var keyObject = Components.classes["@mozilla.org/security/keyobjectfactory;1"] | ||
.getService(Components.interfaces.nsIKeyObjectFactory) | ||
.keyFromString(Components.interfaces.nsIKeyObject.HMAC, key); | ||
|
||
hasher.init(digestmod, keyObject); | ||
var data = crypto.toByteArray(msg); | ||
hasher.update(data, data.length); | ||
return hasher.finish(false); | ||
} | ||
if (Components) { // Mozilla | ||
crypto.hash.HMAC = function(key, msg, digestmod) { | ||
var hasher = Components.classes["@mozilla.org/security/hmac;1"].createInstance(Components.interfaces.nsICryptoHMAC); | ||
var keyObject = Components.classes["@mozilla.org/security/keyobjectfactory;1"] | ||
.getService(Components.interfaces.nsIKeyObjectFactory) | ||
.keyFromString(Components.interfaces.nsIKeyObject.HMAC, key); | ||
|
||
hasher.init(digestmod, keyObject); | ||
var data = crypto.toByteArray(msg); | ||
hasher.update(data, data.length); | ||
return hasher.finish(false); | ||
}; | ||
|
||
crypto.hash.HMAC_SHA = Components.classes["@mozilla.org/security/hmac;1"].createInstance(Components.interfaces.nsICryptoHMAC).SHA1; | ||
crypto.hash.HMAC_MD5 = Components.classes["@mozilla.org/security/hmac;1"].createInstance(Components.interfaces.nsICryptoHMAC).MD5; | ||
} else { // Chrome | ||
crypto.hash.HMAC = function(key, msg, digestmod) { | ||
var blocksize = 64; | ||
var ipad = 0x36; | ||
var opad = 0x5C; | ||
|
||
var hasher = digestmod == 3 ? crypto.hash.SHA : crypto.hash.MD5; | ||
|
||
var outer = new hasher(); | ||
var inner = new hasher(); | ||
|
||
crypto.hash.HMAC_SHA = Components.classes["@mozilla.org/security/hmac;1"].createInstance(Components.interfaces.nsICryptoHMAC).SHA1; | ||
crypto.hash.HMAC_MD5 = Components.classes["@mozilla.org/security/hmac;1"].createInstance(Components.interfaces.nsICryptoHMAC).MD5; | ||
if (key.length > blocksize) { | ||
key = new hasher(key).digest(); | ||
} | ||
|
||
key = key + new Array(blocksize - key.length + 1).join('\x00'); | ||
|
||
var okey = crypto.toByteArray(key).slice(0); | ||
var ikey = crypto.toByteArray(key).slice(0); | ||
|
||
for (var x = 0; x < blocksize; ++x) { | ||
okey[x] ^= opad; | ||
ikey[x] ^= ipad; | ||
} | ||
|
||
outer.update(okey); | ||
inner.update(ikey); | ||
inner.update(msg); | ||
outer.update(inner.digest()); | ||
return outer.digest(); | ||
}; | ||
crypto.hash.HMAC_SHA = 3; | ||
crypto.hash.HMAC_MD5 = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.