corrade-nucleus-nucleons – Blame information for rev 20
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | (function(){ |
2 | |||
3 | var C = (typeof window === 'undefined') ? require('./Crypto').Crypto : window.Crypto; |
||
4 | |||
5 | // Shortcuts
|
||
6 | var util = C.util, |
||
7 | charenc = C.charenc, |
||
8 | UTF8 = charenc.UTF8, |
||
9 | Binary = charenc.Binary; |
||
10 | |||
11 | C.HMAC = function (hasher, message, key, options) { |
||
12 | |||
13 | // Convert to byte arrays
|
||
14 | if (message.constructor == String) message = UTF8.stringToBytes(message); |
||
15 | if (key.constructor == String) key = UTF8.stringToBytes(key); |
||
16 | /* else, assume byte arrays already */ |
||
17 | |||
18 | // Allow arbitrary length keys
|
||
19 | if (key.length > hasher._blocksize * 4) |
||
20 | key = hasher(key, { asBytes: true }); |
||
21 | |||
22 | // XOR keys with pad constants
|
||
23 | var okey = key.slice(0), |
||
24 | ikey = key.slice(0); |
||
25 | for (var i = 0; i < hasher._blocksize * 4; i++) { |
||
26 | okey[i] ^= 0x5C; |
||
27 | ikey[i] ^= 0x36; |
||
28 | } |
||
29 | |||
30 | var hmacbytes = hasher(okey.concat(hasher(ikey.concat(message), { asBytes: true })), { asBytes: true }); |
||
31 | |||
32 | return options && options.asBytes ? hmacbytes : |
||
33 | options && options.asString ? Binary.bytesToString(hmacbytes) : |
||
34 | util.bytesToHex(hmacbytes); |
||
35 | |||
36 | }; |
||
37 | |||
38 | })(); |