1 | define(["./_sha-64"], function(sha64){ |
---|
2 | // The 384-bit implementation of SHA-2 |
---|
3 | |
---|
4 | // Note that for 64-bit hashes, we're actually doing high-order, low-order, high-order, low-order. |
---|
5 | // The 64-bit functions will assemble them into actual 64-bit "words". |
---|
6 | var hash = [ |
---|
7 | 0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939, |
---|
8 | 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4 |
---|
9 | ]; |
---|
10 | |
---|
11 | // the exported function |
---|
12 | var SHA384 = function(/* String */data, /* sha64.outputTypes? */outputType){ |
---|
13 | var out = outputType || sha64.outputTypes.Base64; |
---|
14 | data = sha64.stringToUtf8(data); |
---|
15 | var wa = sha64.digest(sha64.toWord(data), data.length * 8, hash, 384); |
---|
16 | switch(out){ |
---|
17 | case sha64.outputTypes.Raw: { |
---|
18 | return wa; |
---|
19 | } |
---|
20 | case sha64.outputTypes.Hex: { |
---|
21 | return sha64.toHex(wa); |
---|
22 | } |
---|
23 | case sha64.outputTypes.String: { |
---|
24 | return sha64._toString(wa); |
---|
25 | } |
---|
26 | default: { |
---|
27 | return sha64.toBase64(wa); |
---|
28 | } |
---|
29 | } |
---|
30 | }; |
---|
31 | SHA384._hmac = function(/* string */data, /* string */key, /* sha64.outputTypes? */outputType){ |
---|
32 | var out = outputType || sha64.outputTypes.Base64; |
---|
33 | data = sha64.stringToUtf8(data); |
---|
34 | key = sha64.stringToUtf8(key); |
---|
35 | |
---|
36 | // prepare the key |
---|
37 | var wa = sha64.toWord(key); |
---|
38 | if(wa.length > 16){ |
---|
39 | wa = sha64.digest(wa, key.length * 8, hash, 384); |
---|
40 | } |
---|
41 | |
---|
42 | // set up the pads |
---|
43 | var ipad = new Array(16), opad = new Array(16); |
---|
44 | for(var i=0; i<16; i++){ |
---|
45 | ipad[i] = wa[i] ^ 0x36363636; |
---|
46 | opad[i] = wa[i] ^ 0x5c5c5c5c; |
---|
47 | } |
---|
48 | |
---|
49 | // make the final digest |
---|
50 | var r1 = sha64.digest(ipad.concat(sha64.toWord(data)), 512 + data.length * 8, hash, 384); |
---|
51 | var r2 = sha64.digest(opad.concat(r1), 512 + 160, hash, 384); |
---|
52 | |
---|
53 | // return the output. |
---|
54 | switch(out){ |
---|
55 | case sha64.outputTypes.Raw: { |
---|
56 | return wa; |
---|
57 | } |
---|
58 | case sha64.outputTypes.Hex: { |
---|
59 | return sha64.toHex(wa); |
---|
60 | } |
---|
61 | case sha64.outputTypes.String: { |
---|
62 | return sha64._toString(wa); |
---|
63 | } |
---|
64 | default: { |
---|
65 | return sha64.toBase64(wa); |
---|
66 | } |
---|
67 | } |
---|
68 | }; |
---|
69 | |
---|
70 | return SHA384; |
---|
71 | }); |
---|