Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ultraviolet
GitHub Repository: ultraviolet/bitaddress.org
Path: blob/master/src/cryptojs.hmac.js
248 views
1
/*!
2
* Crypto-JS v2.5.4 HMAC.js
3
* http://code.google.com/p/crypto-js/
4
* Copyright (c) 2009-2013, Jeff Mott. All rights reserved.
5
* http://code.google.com/p/crypto-js/wiki/License
6
*/
7
(function () {
8
9
// Shortcuts
10
var C = Crypto,
11
util = C.util,
12
charenc = C.charenc,
13
UTF8 = charenc.UTF8,
14
Binary = charenc.Binary;
15
16
C.HMAC = function (hasher, message, key, options) {
17
18
// Convert to byte arrays
19
if (message.constructor == String) message = UTF8.stringToBytes(message);
20
if (key.constructor == String) key = UTF8.stringToBytes(key);
21
/* else, assume byte arrays already */
22
23
// Allow arbitrary length keys
24
if (key.length > hasher._blocksize * 4)
25
key = hasher(key, { asBytes: true });
26
27
// XOR keys with pad constants
28
var okey = key.slice(0),
29
ikey = key.slice(0);
30
for (var i = 0; i < hasher._blocksize * 4; i++) {
31
okey[i] ^= 0x5C;
32
ikey[i] ^= 0x36;
33
}
34
35
var hmacbytes = hasher(okey.concat(hasher(ikey.concat(message), { asBytes: true })), { asBytes: true });
36
37
return options && options.asBytes ? hmacbytes :
38
options && options.asString ? Binary.bytesToString(hmacbytes) :
39
util.bytesToHex(hmacbytes);
40
41
};
42
43
})();
44