@ivujs/i-utils 1.1.14 → 1.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ID-card/index.cjs +87 -0
- package/dist/cjs/array/index.cjs +470 -0
- package/dist/cjs/clipboard/index.cjs +128 -0
- package/dist/cjs/color/index.cjs +193 -0
- package/dist/cjs/constants/date.cjs +178 -0
- package/dist/cjs/constants/id-card.cjs +52 -0
- package/dist/cjs/constants/keycode.cjs +117 -0
- package/dist/cjs/constants/lang.cjs +13 -0
- package/dist/cjs/constants/math.cjs +13 -0
- package/dist/cjs/constants/regexp.cjs +53 -0
- package/dist/cjs/constants/sort.cjs +15 -0
- package/dist/cjs/cookie/index.cjs +70 -0
- package/dist/cjs/crypto/aes/aes.cjs +480 -0
- package/dist/cjs/crypto/aes/index.cjs +27 -0
- package/dist/cjs/crypto/base32/base32.cjs +357 -0
- package/dist/cjs/crypto/base32/index.cjs +41 -0
- package/dist/cjs/crypto/base64/base64.cjs +348 -0
- package/dist/cjs/crypto/base64/index.cjs +59 -0
- package/dist/cjs/crypto/des/des.cjs +257 -0
- package/dist/cjs/crypto/des/index.cjs +28 -0
- package/dist/cjs/crypto/md5/index.cjs +24 -0
- package/dist/cjs/crypto/md5/md5.cjs +897 -0
- package/dist/cjs/crypto/sha/sha1/index.cjs +24 -0
- package/dist/cjs/crypto/sha/sha1/sha1.cjs +529 -0
- package/dist/cjs/crypto/sha/sha256/index.cjs +43 -0
- package/dist/cjs/crypto/sha/sha256/sha256.cjs +595 -0
- package/dist/cjs/crypto/sha/sha3/index.cjs +41 -0
- package/dist/cjs/crypto/sha/sha3/sha3.cjs +624 -0
- package/dist/cjs/crypto/sha/sha512/index.cjs +81 -0
- package/dist/cjs/crypto/sha/sha512/sha512.cjs +950 -0
- package/dist/cjs/crypto/sm/lib/asn1.cjs +149 -0
- package/dist/cjs/crypto/sm/lib/ec.cjs +315 -0
- package/dist/cjs/crypto/sm/lib/jsbn.cjs +1608 -0
- package/dist/cjs/crypto/sm/lib/sm3.cjs +158 -0
- package/dist/cjs/crypto/sm/lib/utils.cjs +170 -0
- package/dist/cjs/crypto/sm/sm2/index.cjs +112 -0
- package/dist/cjs/crypto/sm/sm2/sm2.cjs +231 -0
- package/dist/cjs/crypto/sm/sm3/index.cjs +15 -0
- package/dist/cjs/crypto/sm/sm3/sm3.cjs +93 -0
- package/dist/cjs/crypto/sm/sm4/index.cjs +27 -0
- package/dist/cjs/crypto/sm/sm4/sm4.cjs +327 -0
- package/dist/cjs/crypto/tea/index.cjs +25 -0
- package/dist/cjs/crypto/tea/tea.cjs +187 -0
- package/dist/cjs/date/index.cjs +1266 -0
- package/dist/cjs/desensitized/index.cjs +75 -0
- package/dist/cjs/device/index.cjs +151 -0
- package/dist/cjs/dom/index.cjs +129 -0
- package/dist/cjs/file/index.cjs +333 -0
- package/dist/cjs/function/index.cjs +69 -0
- package/dist/cjs/id/index.cjs +1 -1
- package/dist/cjs/index.cjs +398 -47
- package/dist/cjs/keycode/index.cjs +33 -0
- package/dist/cjs/math/index.cjs +278 -0
- package/dist/cjs/number/index.cjs +31 -0
- package/dist/cjs/object/index.cjs +272 -0
- package/dist/cjs/pagination/index.cjs +131 -0
- package/dist/cjs/random/index.cjs +24 -0
- package/dist/cjs/regexp/index.cjs +100 -0
- package/dist/cjs/storage/index.cjs +11 -0
- package/dist/cjs/storage/localStorage.cjs +37 -0
- package/dist/cjs/storage/sessionStorage.cjs +37 -0
- package/dist/cjs/string/index.cjs +358 -0
- package/dist/cjs/url/index.cjs +258 -0
- package/dist/cjs/validate/index.cjs +468 -0
- package/dist/cjs/weapp/index.cjs +142 -0
- package/dist/es/ID-card/index.d.ts +31 -0
- package/dist/es/ID-card/index.mjs +81 -0
- package/dist/es/array/index.d.ts +203 -0
- package/dist/es/array/index.mjs +441 -0
- package/dist/es/clipboard/index.d.ts +29 -0
- package/dist/es/clipboard/index.mjs +122 -0
- package/dist/es/color/index.d.ts +52 -0
- package/dist/es/color/index.mjs +183 -0
- package/dist/es/constants/date.d.ts +174 -0
- package/dist/es/constants/date.mjs +176 -0
- package/dist/es/constants/id-card.d.ts +43 -0
- package/dist/es/constants/id-card.mjs +50 -0
- package/dist/es/constants/index.d.ts +7 -0
- package/dist/es/constants/keycode.d.ts +103 -0
- package/dist/es/constants/keycode.mjs +115 -0
- package/dist/es/constants/lang.d.ts +4 -0
- package/dist/es/constants/lang.mjs +11 -0
- package/dist/es/constants/math.d.ts +4 -0
- package/dist/es/constants/math.mjs +11 -0
- package/dist/es/constants/regexp.d.ts +24 -0
- package/dist/es/constants/regexp.mjs +51 -0
- package/dist/es/constants/sort.d.ts +5 -0
- package/dist/es/constants/sort.mjs +13 -0
- package/dist/es/cookie/index.d.ts +29 -0
- package/dist/es/cookie/index.mjs +64 -0
- package/dist/es/crypto/aes/aes.d.ts +156 -0
- package/dist/es/crypto/aes/aes.mjs +478 -0
- package/dist/es/crypto/aes/index.d.ts +16 -0
- package/dist/es/crypto/aes/index.mjs +24 -0
- package/dist/es/crypto/base32/base32.d.ts +3 -0
- package/dist/es/crypto/base32/base32.mjs +353 -0
- package/dist/es/crypto/base32/index.d.ts +24 -0
- package/dist/es/crypto/base32/index.mjs +36 -0
- package/dist/es/crypto/base64/base64.d.ts +5 -0
- package/dist/es/crypto/base64/base64.mjs +342 -0
- package/dist/es/crypto/base64/index.d.ts +36 -0
- package/dist/es/crypto/base64/index.mjs +52 -0
- package/dist/es/crypto/des/des.d.ts +52 -0
- package/dist/es/crypto/des/des.mjs +255 -0
- package/dist/es/crypto/des/index.d.ts +14 -0
- package/dist/es/crypto/des/index.mjs +25 -0
- package/dist/es/crypto/index.d.ts +8 -0
- package/dist/es/crypto/md5/index.d.ts +13 -0
- package/dist/es/crypto/md5/index.mjs +21 -0
- package/dist/es/crypto/md5/md5.d.ts +144 -0
- package/dist/es/crypto/md5/md5.mjs +894 -0
- package/dist/es/crypto/sha/index.d.ts +4 -0
- package/dist/es/crypto/sha/sha1/index.d.ts +13 -0
- package/dist/es/crypto/sha/sha1/index.mjs +21 -0
- package/dist/es/crypto/sha/sha1/sha1.d.ts +2 -0
- package/dist/es/crypto/sha/sha1/sha1.mjs +526 -0
- package/dist/es/crypto/sha/sha256/index.d.ts +26 -0
- package/dist/es/crypto/sha/sha256/index.mjs +38 -0
- package/dist/es/crypto/sha/sha256/sha256.d.ts +4 -0
- package/dist/es/crypto/sha/sha256/sha256.mjs +590 -0
- package/dist/es/crypto/sha/sha3/index.d.ts +24 -0
- package/dist/es/crypto/sha/sha3/index.mjs +36 -0
- package/dist/es/crypto/sha/sha3/sha3.d.ts +4 -0
- package/dist/es/crypto/sha/sha3/sha3.mjs +619 -0
- package/dist/es/crypto/sha/sha512/index.d.ts +52 -0
- package/dist/es/crypto/sha/sha512/index.mjs +72 -0
- package/dist/es/crypto/sha/sha512/sha512.d.ts +8 -0
- package/dist/es/crypto/sha/sha512/sha512.mjs +941 -0
- package/dist/es/crypto/sm/index.d.ts +3 -0
- package/dist/es/crypto/sm/lib/asn1.d.ts +12 -0
- package/dist/es/crypto/sm/lib/asn1.mjs +146 -0
- package/dist/es/crypto/sm/lib/ec.d.ts +126 -0
- package/dist/es/crypto/sm/lib/ec.mjs +312 -0
- package/dist/es/crypto/sm/lib/jsbn.d.ts +198 -0
- package/dist/es/crypto/sm/lib/jsbn.mjs +1605 -0
- package/dist/es/crypto/sm/lib/sm3.d.ts +5 -0
- package/dist/es/crypto/sm/lib/sm3.mjs +155 -0
- package/dist/es/crypto/sm/lib/utils.d.ts +53 -0
- package/dist/es/crypto/sm/lib/utils.mjs +158 -0
- package/dist/es/crypto/sm/sm2/index.d.ts +71 -0
- package/dist/es/crypto/sm/sm2/index.mjs +101 -0
- package/dist/es/crypto/sm/sm2/sm2.d.ts +34 -0
- package/dist/es/crypto/sm/sm2/sm2.mjs +220 -0
- package/dist/es/crypto/sm/sm3/index.d.ts +7 -0
- package/dist/es/crypto/sm/sm3/index.mjs +13 -0
- package/dist/es/crypto/sm/sm3/sm3.d.ts +1 -0
- package/dist/es/crypto/sm/sm3/sm3.mjs +91 -0
- package/dist/es/crypto/sm/sm4/index.d.ts +16 -0
- package/dist/es/crypto/sm/sm4/index.mjs +24 -0
- package/dist/es/crypto/sm/sm4/sm4.d.ts +2 -0
- package/dist/es/crypto/sm/sm4/sm4.mjs +324 -0
- package/dist/es/crypto/tea/index.d.ts +14 -0
- package/dist/es/crypto/tea/index.mjs +22 -0
- package/dist/es/crypto/tea/tea.d.ts +69 -0
- package/dist/es/crypto/tea/tea.mjs +185 -0
- package/dist/es/date/index.d.ts +547 -0
- package/dist/es/date/index.mjs +1179 -0
- package/dist/es/desensitized/index.d.ts +38 -0
- package/dist/es/desensitized/index.mjs +69 -0
- package/dist/es/device/index.d.ts +67 -0
- package/dist/es/device/index.mjs +137 -0
- package/dist/es/dom/index.d.ts +57 -0
- package/dist/es/dom/index.mjs +119 -0
- package/dist/es/file/index.d.ts +93 -0
- package/dist/es/file/index.mjs +317 -0
- package/dist/es/function/index.d.ts +23 -0
- package/dist/es/function/index.mjs +65 -0
- package/dist/es/id/index.mjs +1 -1
- package/dist/es/index.d.ts +25 -42
- package/dist/es/index.mjs +54 -40
- package/dist/es/keycode/index.d.ts +12 -0
- package/dist/es/keycode/index.mjs +30 -0
- package/dist/es/math/index.d.ts +66 -0
- package/dist/es/math/index.mjs +268 -0
- package/dist/es/number/index.d.ts +14 -0
- package/dist/es/number/index.mjs +28 -0
- package/dist/es/object/index.d.ts +83 -0
- package/dist/es/object/index.mjs +259 -0
- package/dist/es/pagination/index.d.ts +34 -0
- package/dist/es/pagination/index.mjs +125 -0
- package/dist/es/random/index.d.ts +15 -0
- package/dist/es/random/index.mjs +21 -0
- package/dist/es/regexp/index.d.ts +63 -0
- package/dist/es/regexp/index.mjs +89 -0
- package/dist/es/storage/index.d.ts +7 -0
- package/dist/es/storage/index.mjs +9 -0
- package/dist/es/storage/localStorage.d.ts +21 -0
- package/dist/es/storage/localStorage.mjs +32 -0
- package/dist/es/storage/sessionStorage.d.ts +21 -0
- package/dist/es/storage/sessionStorage.mjs +32 -0
- package/dist/es/string/index.d.ts +121 -0
- package/dist/es/string/index.mjs +339 -0
- package/dist/es/url/index.d.ts +118 -0
- package/dist/es/url/index.mjs +240 -0
- package/dist/es/validate/index.d.ts +228 -0
- package/dist/es/validate/index.mjs +431 -0
- package/dist/es/weapp/index.d.ts +57 -0
- package/dist/es/weapp/index.mjs +131 -0
- package/dist/index.d.ts +2850 -53
- package/dist/lib/index.full.cjs.js +14230 -67
- package/dist/lib/index.full.cjs.min.js +64 -2
- package/dist/lib/index.full.cjs.min.js.map +1 -1
- package/dist/lib/index.full.esm.js +13881 -63
- package/dist/lib/index.full.esm.min.js +59 -2
- package/dist/lib/index.full.esm.min.js.map +1 -1
- package/dist/lib/index.full.umd.js +14230 -67
- package/dist/lib/index.full.umd.min.js +64 -2
- package/dist/lib/index.full.umd.min.js.map +1 -1
- package/dist/resolver/auto-imports.cjs +337 -11
- package/dist/resolver/auto-imports.mjs +337 -11
- package/dist/resolver/index.cjs +1 -1
- package/dist/resolver/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,941 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* [js-sha512]{@link https://github.com/emn178/js-sha512}
|
|
3
|
+
*
|
|
4
|
+
* @version 0.9.0
|
|
5
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
|
+
* @copyright Chen, Yi-Cyuan 2014-2024
|
|
7
|
+
* @license MIT
|
|
8
|
+
*/
|
|
9
|
+
/* jslint bitwise: true */
|
|
10
|
+
var INPUT_ERROR = "input is invalid type";
|
|
11
|
+
var FINALIZE_ERROR = "finalize already called";
|
|
12
|
+
var WINDOW = typeof window === "object";
|
|
13
|
+
var root = WINDOW ? window : {};
|
|
14
|
+
if (root.JS_SHA512_NO_WINDOW) {
|
|
15
|
+
WINDOW = false;
|
|
16
|
+
}
|
|
17
|
+
var WEB_WORKER = !WINDOW && typeof self === "object";
|
|
18
|
+
var NODE_JS = !root.JS_SHA512_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node;
|
|
19
|
+
if (NODE_JS) {
|
|
20
|
+
root = global;
|
|
21
|
+
}
|
|
22
|
+
else if (WEB_WORKER) {
|
|
23
|
+
root = self;
|
|
24
|
+
}
|
|
25
|
+
var ARRAY_BUFFER = !root.JS_SHA512_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined";
|
|
26
|
+
var HEX_CHARS = "0123456789abcdef".split("");
|
|
27
|
+
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
|
28
|
+
var SHIFT = [24, 16, 8, 0];
|
|
29
|
+
var K = [
|
|
30
|
+
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, 0x3956c25b,
|
|
31
|
+
0xf348b538, 0x59f111f1, 0xb605d019, 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242,
|
|
32
|
+
0x12835b01, 0x45706fbe, 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, 0x72be5d74, 0xf27b896f, 0x80deb1fe,
|
|
33
|
+
0x3b1696b1, 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
34
|
+
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, 0x5cb0a9dc,
|
|
35
|
+
0xbd41fbd4, 0x76f988da, 0x831153b5, 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, 0xb00327c8, 0x98fb213f,
|
|
36
|
+
0xbf597fc7, 0xbeef0ee4, 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, 0x06ca6351, 0xe003826f, 0x14292967,
|
|
37
|
+
0x0a0e6e70, 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
38
|
+
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, 0xa2bfe8a1,
|
|
39
|
+
0x4cf10364, 0xa81a664b, 0xbc423001, 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, 0xd192e819, 0xd6ef5218,
|
|
40
|
+
0xd6990624, 0x5565a910, 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, 0x19a4c116, 0xb8d2d0c8, 0x1e376c08,
|
|
41
|
+
0x5141ab53, 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
42
|
+
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, 0x84c87814,
|
|
43
|
+
0xa1f0ab72, 0x8cc70208, 0x1a6439ec, 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, 0xbef9a3f7, 0xb2c67915,
|
|
44
|
+
0xc67178f2, 0xe372532b, 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f,
|
|
45
|
+
0xee6ed178, 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
46
|
+
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, 0x4cc5d4be,
|
|
47
|
+
0xcb3e42b6, 0x597f299c, 0xfc657e2a, 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817,
|
|
48
|
+
];
|
|
49
|
+
var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"];
|
|
50
|
+
var blocks = [];
|
|
51
|
+
var isArray = Array.isArray;
|
|
52
|
+
if (root.JS_SHA512_NO_NODE_JS || !isArray) {
|
|
53
|
+
isArray = function (obj) {
|
|
54
|
+
return Object.prototype.toString.call(obj) === "[object Array]";
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
var isView = ArrayBuffer.isView;
|
|
58
|
+
if (ARRAY_BUFFER && (root.JS_SHA512_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
|
|
59
|
+
isView = function (obj) {
|
|
60
|
+
return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// [message: string, isString: bool]
|
|
64
|
+
var formatMessage = function (message) {
|
|
65
|
+
var type = typeof message;
|
|
66
|
+
if (type === "string") {
|
|
67
|
+
return [message, true];
|
|
68
|
+
}
|
|
69
|
+
if (type !== "object" || message === null) {
|
|
70
|
+
throw new Error(INPUT_ERROR);
|
|
71
|
+
}
|
|
72
|
+
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
73
|
+
return [new Uint8Array(message), false];
|
|
74
|
+
}
|
|
75
|
+
if (!isArray(message) && !isView(message)) {
|
|
76
|
+
throw new Error(INPUT_ERROR);
|
|
77
|
+
}
|
|
78
|
+
return [message, false];
|
|
79
|
+
};
|
|
80
|
+
var createOutputMethod = function (outputType, bits) {
|
|
81
|
+
return function (message) {
|
|
82
|
+
return new Sha512(bits, true).update(message)[outputType]();
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
var createMethod = function (bits) {
|
|
86
|
+
var method = createOutputMethod("hex", bits);
|
|
87
|
+
method.create = function () {
|
|
88
|
+
return new Sha512(bits);
|
|
89
|
+
};
|
|
90
|
+
method.update = function (message) {
|
|
91
|
+
return method.create().update(message);
|
|
92
|
+
};
|
|
93
|
+
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
94
|
+
var type = OUTPUT_TYPES[i];
|
|
95
|
+
method[type] = createOutputMethod(type, bits);
|
|
96
|
+
}
|
|
97
|
+
return method;
|
|
98
|
+
};
|
|
99
|
+
var createHmacOutputMethod = function (outputType, bits) {
|
|
100
|
+
return function (key, message) {
|
|
101
|
+
return new HmacSha512(key, bits, true).update(message)[outputType]();
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
var createHmacMethod = function (bits) {
|
|
105
|
+
var method = createHmacOutputMethod("hex", bits);
|
|
106
|
+
method.create = function (key) {
|
|
107
|
+
return new HmacSha512(key, bits);
|
|
108
|
+
};
|
|
109
|
+
method.update = function (key, message) {
|
|
110
|
+
return method.create(key).update(message);
|
|
111
|
+
};
|
|
112
|
+
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
113
|
+
var type = OUTPUT_TYPES[i];
|
|
114
|
+
method[type] = createHmacOutputMethod(type, bits);
|
|
115
|
+
}
|
|
116
|
+
return method;
|
|
117
|
+
};
|
|
118
|
+
function Sha512(bits, sharedMemory) {
|
|
119
|
+
if (sharedMemory) {
|
|
120
|
+
blocks[0] =
|
|
121
|
+
blocks[1] =
|
|
122
|
+
blocks[2] =
|
|
123
|
+
blocks[3] =
|
|
124
|
+
blocks[4] =
|
|
125
|
+
blocks[5] =
|
|
126
|
+
blocks[6] =
|
|
127
|
+
blocks[7] =
|
|
128
|
+
blocks[8] =
|
|
129
|
+
blocks[9] =
|
|
130
|
+
blocks[10] =
|
|
131
|
+
blocks[11] =
|
|
132
|
+
blocks[12] =
|
|
133
|
+
blocks[13] =
|
|
134
|
+
blocks[14] =
|
|
135
|
+
blocks[15] =
|
|
136
|
+
blocks[16] =
|
|
137
|
+
blocks[17] =
|
|
138
|
+
blocks[18] =
|
|
139
|
+
blocks[19] =
|
|
140
|
+
blocks[20] =
|
|
141
|
+
blocks[21] =
|
|
142
|
+
blocks[22] =
|
|
143
|
+
blocks[23] =
|
|
144
|
+
blocks[24] =
|
|
145
|
+
blocks[25] =
|
|
146
|
+
blocks[26] =
|
|
147
|
+
blocks[27] =
|
|
148
|
+
blocks[28] =
|
|
149
|
+
blocks[29] =
|
|
150
|
+
blocks[30] =
|
|
151
|
+
blocks[31] =
|
|
152
|
+
blocks[32] =
|
|
153
|
+
0;
|
|
154
|
+
this.blocks = blocks;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
this.blocks = [
|
|
158
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
if (bits == 384) {
|
|
162
|
+
this.h0h = 0xcbbb9d5d;
|
|
163
|
+
this.h0l = 0xc1059ed8;
|
|
164
|
+
this.h1h = 0x629a292a;
|
|
165
|
+
this.h1l = 0x367cd507;
|
|
166
|
+
this.h2h = 0x9159015a;
|
|
167
|
+
this.h2l = 0x3070dd17;
|
|
168
|
+
this.h3h = 0x152fecd8;
|
|
169
|
+
this.h3l = 0xf70e5939;
|
|
170
|
+
this.h4h = 0x67332667;
|
|
171
|
+
this.h4l = 0xffc00b31;
|
|
172
|
+
this.h5h = 0x8eb44a87;
|
|
173
|
+
this.h5l = 0x68581511;
|
|
174
|
+
this.h6h = 0xdb0c2e0d;
|
|
175
|
+
this.h6l = 0x64f98fa7;
|
|
176
|
+
this.h7h = 0x47b5481d;
|
|
177
|
+
this.h7l = 0xbefa4fa4;
|
|
178
|
+
}
|
|
179
|
+
else if (bits == 256) {
|
|
180
|
+
this.h0h = 0x22312194;
|
|
181
|
+
this.h0l = 0xfc2bf72c;
|
|
182
|
+
this.h1h = 0x9f555fa3;
|
|
183
|
+
this.h1l = 0xc84c64c2;
|
|
184
|
+
this.h2h = 0x2393b86b;
|
|
185
|
+
this.h2l = 0x6f53b151;
|
|
186
|
+
this.h3h = 0x96387719;
|
|
187
|
+
this.h3l = 0x5940eabd;
|
|
188
|
+
this.h4h = 0x96283ee2;
|
|
189
|
+
this.h4l = 0xa88effe3;
|
|
190
|
+
this.h5h = 0xbe5e1e25;
|
|
191
|
+
this.h5l = 0x53863992;
|
|
192
|
+
this.h6h = 0x2b0199fc;
|
|
193
|
+
this.h6l = 0x2c85b8aa;
|
|
194
|
+
this.h7h = 0x0eb72ddc;
|
|
195
|
+
this.h7l = 0x81c52ca2;
|
|
196
|
+
}
|
|
197
|
+
else if (bits == 224) {
|
|
198
|
+
this.h0h = 0x8c3d37c8;
|
|
199
|
+
this.h0l = 0x19544da2;
|
|
200
|
+
this.h1h = 0x73e19966;
|
|
201
|
+
this.h1l = 0x89dcd4d6;
|
|
202
|
+
this.h2h = 0x1dfab7ae;
|
|
203
|
+
this.h2l = 0x32ff9c82;
|
|
204
|
+
this.h3h = 0x679dd514;
|
|
205
|
+
this.h3l = 0x582f9fcf;
|
|
206
|
+
this.h4h = 0x0f6d2b69;
|
|
207
|
+
this.h4l = 0x7bd44da8;
|
|
208
|
+
this.h5h = 0x77e36f73;
|
|
209
|
+
this.h5l = 0x04c48942;
|
|
210
|
+
this.h6h = 0x3f9d85a8;
|
|
211
|
+
this.h6l = 0x6a1d36c8;
|
|
212
|
+
this.h7h = 0x1112e6ad;
|
|
213
|
+
this.h7l = 0x91d692a1;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
// 512
|
|
217
|
+
this.h0h = 0x6a09e667;
|
|
218
|
+
this.h0l = 0xf3bcc908;
|
|
219
|
+
this.h1h = 0xbb67ae85;
|
|
220
|
+
this.h1l = 0x84caa73b;
|
|
221
|
+
this.h2h = 0x3c6ef372;
|
|
222
|
+
this.h2l = 0xfe94f82b;
|
|
223
|
+
this.h3h = 0xa54ff53a;
|
|
224
|
+
this.h3l = 0x5f1d36f1;
|
|
225
|
+
this.h4h = 0x510e527f;
|
|
226
|
+
this.h4l = 0xade682d1;
|
|
227
|
+
this.h5h = 0x9b05688c;
|
|
228
|
+
this.h5l = 0x2b3e6c1f;
|
|
229
|
+
this.h6h = 0x1f83d9ab;
|
|
230
|
+
this.h6l = 0xfb41bd6b;
|
|
231
|
+
this.h7h = 0x5be0cd19;
|
|
232
|
+
this.h7l = 0x137e2179;
|
|
233
|
+
}
|
|
234
|
+
this.bits = bits;
|
|
235
|
+
this.block = this.start = this.bytes = this.hBytes = 0;
|
|
236
|
+
this.finalized = this.hashed = false;
|
|
237
|
+
}
|
|
238
|
+
Sha512.prototype.update = function (message) {
|
|
239
|
+
if (this.finalized) {
|
|
240
|
+
throw new Error(FINALIZE_ERROR);
|
|
241
|
+
}
|
|
242
|
+
var result = formatMessage(message);
|
|
243
|
+
message = result[0];
|
|
244
|
+
var isString = result[1];
|
|
245
|
+
var code, index = 0, i, length = message.length, blocks = this.blocks;
|
|
246
|
+
while (index < length) {
|
|
247
|
+
if (this.hashed) {
|
|
248
|
+
this.hashed = false;
|
|
249
|
+
blocks[0] = this.block;
|
|
250
|
+
this.block =
|
|
251
|
+
blocks[1] =
|
|
252
|
+
blocks[2] =
|
|
253
|
+
blocks[3] =
|
|
254
|
+
blocks[4] =
|
|
255
|
+
blocks[5] =
|
|
256
|
+
blocks[6] =
|
|
257
|
+
blocks[7] =
|
|
258
|
+
blocks[8] =
|
|
259
|
+
blocks[9] =
|
|
260
|
+
blocks[10] =
|
|
261
|
+
blocks[11] =
|
|
262
|
+
blocks[12] =
|
|
263
|
+
blocks[13] =
|
|
264
|
+
blocks[14] =
|
|
265
|
+
blocks[15] =
|
|
266
|
+
blocks[16] =
|
|
267
|
+
blocks[17] =
|
|
268
|
+
blocks[18] =
|
|
269
|
+
blocks[19] =
|
|
270
|
+
blocks[20] =
|
|
271
|
+
blocks[21] =
|
|
272
|
+
blocks[22] =
|
|
273
|
+
blocks[23] =
|
|
274
|
+
blocks[24] =
|
|
275
|
+
blocks[25] =
|
|
276
|
+
blocks[26] =
|
|
277
|
+
blocks[27] =
|
|
278
|
+
blocks[28] =
|
|
279
|
+
blocks[29] =
|
|
280
|
+
blocks[30] =
|
|
281
|
+
blocks[31] =
|
|
282
|
+
blocks[32] =
|
|
283
|
+
0;
|
|
284
|
+
}
|
|
285
|
+
if (isString) {
|
|
286
|
+
for (i = this.start; index < length && i < 128; ++index) {
|
|
287
|
+
code = message.charCodeAt(index);
|
|
288
|
+
if (code < 0x80) {
|
|
289
|
+
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
|
|
290
|
+
}
|
|
291
|
+
else if (code < 0x800) {
|
|
292
|
+
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
|
|
293
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
294
|
+
}
|
|
295
|
+
else if (code < 0xd800 || code >= 0xe000) {
|
|
296
|
+
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
|
|
297
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
298
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
302
|
+
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
|
|
303
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
304
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
305
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
for (i = this.start; index < length && i < 128; ++index) {
|
|
311
|
+
blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
this.lastByteIndex = i;
|
|
315
|
+
this.bytes += i - this.start;
|
|
316
|
+
if (i >= 128) {
|
|
317
|
+
this.block = blocks[32];
|
|
318
|
+
this.start = i - 128;
|
|
319
|
+
this.hash();
|
|
320
|
+
this.hashed = true;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
this.start = i;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (this.bytes > 4294967295) {
|
|
327
|
+
this.hBytes += (this.bytes / 4294967296) << 0;
|
|
328
|
+
this.bytes = this.bytes % 4294967296;
|
|
329
|
+
}
|
|
330
|
+
return this;
|
|
331
|
+
};
|
|
332
|
+
Sha512.prototype.finalize = function () {
|
|
333
|
+
if (this.finalized) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
this.finalized = true;
|
|
337
|
+
var blocks = this.blocks, i = this.lastByteIndex;
|
|
338
|
+
blocks[32] = this.block;
|
|
339
|
+
blocks[i >>> 2] |= EXTRA[i & 3];
|
|
340
|
+
this.block = blocks[32];
|
|
341
|
+
if (i >= 112) {
|
|
342
|
+
if (!this.hashed) {
|
|
343
|
+
this.hash();
|
|
344
|
+
}
|
|
345
|
+
blocks[0] = this.block;
|
|
346
|
+
blocks[1] =
|
|
347
|
+
blocks[2] =
|
|
348
|
+
blocks[3] =
|
|
349
|
+
blocks[4] =
|
|
350
|
+
blocks[5] =
|
|
351
|
+
blocks[6] =
|
|
352
|
+
blocks[7] =
|
|
353
|
+
blocks[8] =
|
|
354
|
+
blocks[9] =
|
|
355
|
+
blocks[10] =
|
|
356
|
+
blocks[11] =
|
|
357
|
+
blocks[12] =
|
|
358
|
+
blocks[13] =
|
|
359
|
+
blocks[14] =
|
|
360
|
+
blocks[15] =
|
|
361
|
+
blocks[16] =
|
|
362
|
+
blocks[17] =
|
|
363
|
+
blocks[18] =
|
|
364
|
+
blocks[19] =
|
|
365
|
+
blocks[20] =
|
|
366
|
+
blocks[21] =
|
|
367
|
+
blocks[22] =
|
|
368
|
+
blocks[23] =
|
|
369
|
+
blocks[24] =
|
|
370
|
+
blocks[25] =
|
|
371
|
+
blocks[26] =
|
|
372
|
+
blocks[27] =
|
|
373
|
+
blocks[28] =
|
|
374
|
+
blocks[29] =
|
|
375
|
+
blocks[30] =
|
|
376
|
+
blocks[31] =
|
|
377
|
+
blocks[32] =
|
|
378
|
+
0;
|
|
379
|
+
}
|
|
380
|
+
blocks[30] = (this.hBytes << 3) | (this.bytes >>> 29);
|
|
381
|
+
blocks[31] = this.bytes << 3;
|
|
382
|
+
this.hash();
|
|
383
|
+
};
|
|
384
|
+
Sha512.prototype.hash = function () {
|
|
385
|
+
var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l, h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l, h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l, blocks = this.blocks, j, s0h, s0l, s1h, s1l, c1, c2, c3, c4, abh, abl, dah, dal, cdh, cdl, bch, bcl, majh, majl, t1h, t1l, t2h, t2l, chh, chl;
|
|
386
|
+
for (j = 32; j < 160; j += 2) {
|
|
387
|
+
t1h = blocks[j - 30];
|
|
388
|
+
t1l = blocks[j - 29];
|
|
389
|
+
s0h = ((t1h >>> 1) | (t1l << 31)) ^ ((t1h >>> 8) | (t1l << 24)) ^ (t1h >>> 7);
|
|
390
|
+
s0l = ((t1l >>> 1) | (t1h << 31)) ^ ((t1l >>> 8) | (t1h << 24)) ^ ((t1l >>> 7) | (t1h << 25));
|
|
391
|
+
t1h = blocks[j - 4];
|
|
392
|
+
t1l = blocks[j - 3];
|
|
393
|
+
s1h = ((t1h >>> 19) | (t1l << 13)) ^ ((t1l >>> 29) | (t1h << 3)) ^ (t1h >>> 6);
|
|
394
|
+
s1l = ((t1l >>> 19) | (t1h << 13)) ^ ((t1h >>> 29) | (t1l << 3)) ^ ((t1l >>> 6) | (t1h << 26));
|
|
395
|
+
t1h = blocks[j - 32];
|
|
396
|
+
t1l = blocks[j - 31];
|
|
397
|
+
t2h = blocks[j - 14];
|
|
398
|
+
t2l = blocks[j - 13];
|
|
399
|
+
c1 = (t2l & 0xffff) + (t1l & 0xffff) + (s0l & 0xffff) + (s1l & 0xffff);
|
|
400
|
+
c2 = (t2l >>> 16) + (t1l >>> 16) + (s0l >>> 16) + (s1l >>> 16) + (c1 >>> 16);
|
|
401
|
+
c3 = (t2h & 0xffff) + (t1h & 0xffff) + (s0h & 0xffff) + (s1h & 0xffff) + (c2 >>> 16);
|
|
402
|
+
c4 = (t2h >>> 16) + (t1h >>> 16) + (s0h >>> 16) + (s1h >>> 16) + (c3 >>> 16);
|
|
403
|
+
blocks[j] = (c4 << 16) | (c3 & 0xffff);
|
|
404
|
+
blocks[j + 1] = (c2 << 16) | (c1 & 0xffff);
|
|
405
|
+
}
|
|
406
|
+
var ah = h0h, al = h0l, bh = h1h, bl = h1l, ch = h2h, cl = h2l, dh = h3h, dl = h3l, eh = h4h, el = h4l, fh = h5h, fl = h5l, gh = h6h, gl = h6l, hh = h7h, hl = h7l;
|
|
407
|
+
bch = bh & ch;
|
|
408
|
+
bcl = bl & cl;
|
|
409
|
+
for (j = 0; j < 160; j += 8) {
|
|
410
|
+
s0h = ((ah >>> 28) | (al << 4)) ^ ((al >>> 2) | (ah << 30)) ^ ((al >>> 7) | (ah << 25));
|
|
411
|
+
s0l = ((al >>> 28) | (ah << 4)) ^ ((ah >>> 2) | (al << 30)) ^ ((ah >>> 7) | (al << 25));
|
|
412
|
+
s1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((el >>> 9) | (eh << 23));
|
|
413
|
+
s1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((eh >>> 9) | (el << 23));
|
|
414
|
+
abh = ah & bh;
|
|
415
|
+
abl = al & bl;
|
|
416
|
+
majh = abh ^ (ah & ch) ^ bch;
|
|
417
|
+
majl = abl ^ (al & cl) ^ bcl;
|
|
418
|
+
chh = (eh & fh) ^ (~eh & gh);
|
|
419
|
+
chl = (el & fl) ^ (~el & gl);
|
|
420
|
+
t1h = blocks[j];
|
|
421
|
+
t1l = blocks[j + 1];
|
|
422
|
+
t2h = K[j];
|
|
423
|
+
t2l = K[j + 1];
|
|
424
|
+
c1 = (t2l & 0xffff) + (t1l & 0xffff) + (chl & 0xffff) + (s1l & 0xffff) + (hl & 0xffff);
|
|
425
|
+
c2 = (t2l >>> 16) + (t1l >>> 16) + (chl >>> 16) + (s1l >>> 16) + (hl >>> 16) + (c1 >>> 16);
|
|
426
|
+
c3 = (t2h & 0xffff) + (t1h & 0xffff) + (chh & 0xffff) + (s1h & 0xffff) + (hh & 0xffff) + (c2 >>> 16);
|
|
427
|
+
c4 = (t2h >>> 16) + (t1h >>> 16) + (chh >>> 16) + (s1h >>> 16) + (hh >>> 16) + (c3 >>> 16);
|
|
428
|
+
t1h = (c4 << 16) | (c3 & 0xffff);
|
|
429
|
+
t1l = (c2 << 16) | (c1 & 0xffff);
|
|
430
|
+
c1 = (majl & 0xffff) + (s0l & 0xffff);
|
|
431
|
+
c2 = (majl >>> 16) + (s0l >>> 16) + (c1 >>> 16);
|
|
432
|
+
c3 = (majh & 0xffff) + (s0h & 0xffff) + (c2 >>> 16);
|
|
433
|
+
c4 = (majh >>> 16) + (s0h >>> 16) + (c3 >>> 16);
|
|
434
|
+
t2h = (c4 << 16) | (c3 & 0xffff);
|
|
435
|
+
t2l = (c2 << 16) | (c1 & 0xffff);
|
|
436
|
+
c1 = (dl & 0xffff) + (t1l & 0xffff);
|
|
437
|
+
c2 = (dl >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
|
438
|
+
c3 = (dh & 0xffff) + (t1h & 0xffff) + (c2 >>> 16);
|
|
439
|
+
c4 = (dh >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
|
440
|
+
hh = (c4 << 16) | (c3 & 0xffff);
|
|
441
|
+
hl = (c2 << 16) | (c1 & 0xffff);
|
|
442
|
+
c1 = (t2l & 0xffff) + (t1l & 0xffff);
|
|
443
|
+
c2 = (t2l >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
|
444
|
+
c3 = (t2h & 0xffff) + (t1h & 0xffff) + (c2 >>> 16);
|
|
445
|
+
c4 = (t2h >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
|
446
|
+
dh = (c4 << 16) | (c3 & 0xffff);
|
|
447
|
+
dl = (c2 << 16) | (c1 & 0xffff);
|
|
448
|
+
s0h = ((dh >>> 28) | (dl << 4)) ^ ((dl >>> 2) | (dh << 30)) ^ ((dl >>> 7) | (dh << 25));
|
|
449
|
+
s0l = ((dl >>> 28) | (dh << 4)) ^ ((dh >>> 2) | (dl << 30)) ^ ((dh >>> 7) | (dl << 25));
|
|
450
|
+
s1h = ((hh >>> 14) | (hl << 18)) ^ ((hh >>> 18) | (hl << 14)) ^ ((hl >>> 9) | (hh << 23));
|
|
451
|
+
s1l = ((hl >>> 14) | (hh << 18)) ^ ((hl >>> 18) | (hh << 14)) ^ ((hh >>> 9) | (hl << 23));
|
|
452
|
+
dah = dh & ah;
|
|
453
|
+
dal = dl & al;
|
|
454
|
+
majh = dah ^ (dh & bh) ^ abh;
|
|
455
|
+
majl = dal ^ (dl & bl) ^ abl;
|
|
456
|
+
chh = (hh & eh) ^ (~hh & fh);
|
|
457
|
+
chl = (hl & el) ^ (~hl & fl);
|
|
458
|
+
t1h = blocks[j + 2];
|
|
459
|
+
t1l = blocks[j + 3];
|
|
460
|
+
t2h = K[j + 2];
|
|
461
|
+
t2l = K[j + 3];
|
|
462
|
+
c1 = (t2l & 0xffff) + (t1l & 0xffff) + (chl & 0xffff) + (s1l & 0xffff) + (gl & 0xffff);
|
|
463
|
+
c2 = (t2l >>> 16) + (t1l >>> 16) + (chl >>> 16) + (s1l >>> 16) + (gl >>> 16) + (c1 >>> 16);
|
|
464
|
+
c3 = (t2h & 0xffff) + (t1h & 0xffff) + (chh & 0xffff) + (s1h & 0xffff) + (gh & 0xffff) + (c2 >>> 16);
|
|
465
|
+
c4 = (t2h >>> 16) + (t1h >>> 16) + (chh >>> 16) + (s1h >>> 16) + (gh >>> 16) + (c3 >>> 16);
|
|
466
|
+
t1h = (c4 << 16) | (c3 & 0xffff);
|
|
467
|
+
t1l = (c2 << 16) | (c1 & 0xffff);
|
|
468
|
+
c1 = (majl & 0xffff) + (s0l & 0xffff);
|
|
469
|
+
c2 = (majl >>> 16) + (s0l >>> 16) + (c1 >>> 16);
|
|
470
|
+
c3 = (majh & 0xffff) + (s0h & 0xffff) + (c2 >>> 16);
|
|
471
|
+
c4 = (majh >>> 16) + (s0h >>> 16) + (c3 >>> 16);
|
|
472
|
+
t2h = (c4 << 16) | (c3 & 0xffff);
|
|
473
|
+
t2l = (c2 << 16) | (c1 & 0xffff);
|
|
474
|
+
c1 = (cl & 0xffff) + (t1l & 0xffff);
|
|
475
|
+
c2 = (cl >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
|
476
|
+
c3 = (ch & 0xffff) + (t1h & 0xffff) + (c2 >>> 16);
|
|
477
|
+
c4 = (ch >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
|
478
|
+
gh = (c4 << 16) | (c3 & 0xffff);
|
|
479
|
+
gl = (c2 << 16) | (c1 & 0xffff);
|
|
480
|
+
c1 = (t2l & 0xffff) + (t1l & 0xffff);
|
|
481
|
+
c2 = (t2l >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
|
482
|
+
c3 = (t2h & 0xffff) + (t1h & 0xffff) + (c2 >>> 16);
|
|
483
|
+
c4 = (t2h >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
|
484
|
+
ch = (c4 << 16) | (c3 & 0xffff);
|
|
485
|
+
cl = (c2 << 16) | (c1 & 0xffff);
|
|
486
|
+
s0h = ((ch >>> 28) | (cl << 4)) ^ ((cl >>> 2) | (ch << 30)) ^ ((cl >>> 7) | (ch << 25));
|
|
487
|
+
s0l = ((cl >>> 28) | (ch << 4)) ^ ((ch >>> 2) | (cl << 30)) ^ ((ch >>> 7) | (cl << 25));
|
|
488
|
+
s1h = ((gh >>> 14) | (gl << 18)) ^ ((gh >>> 18) | (gl << 14)) ^ ((gl >>> 9) | (gh << 23));
|
|
489
|
+
s1l = ((gl >>> 14) | (gh << 18)) ^ ((gl >>> 18) | (gh << 14)) ^ ((gh >>> 9) | (gl << 23));
|
|
490
|
+
cdh = ch & dh;
|
|
491
|
+
cdl = cl & dl;
|
|
492
|
+
majh = cdh ^ (ch & ah) ^ dah;
|
|
493
|
+
majl = cdl ^ (cl & al) ^ dal;
|
|
494
|
+
chh = (gh & hh) ^ (~gh & eh);
|
|
495
|
+
chl = (gl & hl) ^ (~gl & el);
|
|
496
|
+
t1h = blocks[j + 4];
|
|
497
|
+
t1l = blocks[j + 5];
|
|
498
|
+
t2h = K[j + 4];
|
|
499
|
+
t2l = K[j + 5];
|
|
500
|
+
c1 = (t2l & 0xffff) + (t1l & 0xffff) + (chl & 0xffff) + (s1l & 0xffff) + (fl & 0xffff);
|
|
501
|
+
c2 = (t2l >>> 16) + (t1l >>> 16) + (chl >>> 16) + (s1l >>> 16) + (fl >>> 16) + (c1 >>> 16);
|
|
502
|
+
c3 = (t2h & 0xffff) + (t1h & 0xffff) + (chh & 0xffff) + (s1h & 0xffff) + (fh & 0xffff) + (c2 >>> 16);
|
|
503
|
+
c4 = (t2h >>> 16) + (t1h >>> 16) + (chh >>> 16) + (s1h >>> 16) + (fh >>> 16) + (c3 >>> 16);
|
|
504
|
+
t1h = (c4 << 16) | (c3 & 0xffff);
|
|
505
|
+
t1l = (c2 << 16) | (c1 & 0xffff);
|
|
506
|
+
c1 = (majl & 0xffff) + (s0l & 0xffff);
|
|
507
|
+
c2 = (majl >>> 16) + (s0l >>> 16) + (c1 >>> 16);
|
|
508
|
+
c3 = (majh & 0xffff) + (s0h & 0xffff) + (c2 >>> 16);
|
|
509
|
+
c4 = (majh >>> 16) + (s0h >>> 16) + (c3 >>> 16);
|
|
510
|
+
t2h = (c4 << 16) | (c3 & 0xffff);
|
|
511
|
+
t2l = (c2 << 16) | (c1 & 0xffff);
|
|
512
|
+
c1 = (bl & 0xffff) + (t1l & 0xffff);
|
|
513
|
+
c2 = (bl >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
|
514
|
+
c3 = (bh & 0xffff) + (t1h & 0xffff) + (c2 >>> 16);
|
|
515
|
+
c4 = (bh >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
|
516
|
+
fh = (c4 << 16) | (c3 & 0xffff);
|
|
517
|
+
fl = (c2 << 16) | (c1 & 0xffff);
|
|
518
|
+
c1 = (t2l & 0xffff) + (t1l & 0xffff);
|
|
519
|
+
c2 = (t2l >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
|
520
|
+
c3 = (t2h & 0xffff) + (t1h & 0xffff) + (c2 >>> 16);
|
|
521
|
+
c4 = (t2h >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
|
522
|
+
bh = (c4 << 16) | (c3 & 0xffff);
|
|
523
|
+
bl = (c2 << 16) | (c1 & 0xffff);
|
|
524
|
+
s0h = ((bh >>> 28) | (bl << 4)) ^ ((bl >>> 2) | (bh << 30)) ^ ((bl >>> 7) | (bh << 25));
|
|
525
|
+
s0l = ((bl >>> 28) | (bh << 4)) ^ ((bh >>> 2) | (bl << 30)) ^ ((bh >>> 7) | (bl << 25));
|
|
526
|
+
s1h = ((fh >>> 14) | (fl << 18)) ^ ((fh >>> 18) | (fl << 14)) ^ ((fl >>> 9) | (fh << 23));
|
|
527
|
+
s1l = ((fl >>> 14) | (fh << 18)) ^ ((fl >>> 18) | (fh << 14)) ^ ((fh >>> 9) | (fl << 23));
|
|
528
|
+
bch = bh & ch;
|
|
529
|
+
bcl = bl & cl;
|
|
530
|
+
majh = bch ^ (bh & dh) ^ cdh;
|
|
531
|
+
majl = bcl ^ (bl & dl) ^ cdl;
|
|
532
|
+
chh = (fh & gh) ^ (~fh & hh);
|
|
533
|
+
chl = (fl & gl) ^ (~fl & hl);
|
|
534
|
+
t1h = blocks[j + 6];
|
|
535
|
+
t1l = blocks[j + 7];
|
|
536
|
+
t2h = K[j + 6];
|
|
537
|
+
t2l = K[j + 7];
|
|
538
|
+
c1 = (t2l & 0xffff) + (t1l & 0xffff) + (chl & 0xffff) + (s1l & 0xffff) + (el & 0xffff);
|
|
539
|
+
c2 = (t2l >>> 16) + (t1l >>> 16) + (chl >>> 16) + (s1l >>> 16) + (el >>> 16) + (c1 >>> 16);
|
|
540
|
+
c3 = (t2h & 0xffff) + (t1h & 0xffff) + (chh & 0xffff) + (s1h & 0xffff) + (eh & 0xffff) + (c2 >>> 16);
|
|
541
|
+
c4 = (t2h >>> 16) + (t1h >>> 16) + (chh >>> 16) + (s1h >>> 16) + (eh >>> 16) + (c3 >>> 16);
|
|
542
|
+
t1h = (c4 << 16) | (c3 & 0xffff);
|
|
543
|
+
t1l = (c2 << 16) | (c1 & 0xffff);
|
|
544
|
+
c1 = (majl & 0xffff) + (s0l & 0xffff);
|
|
545
|
+
c2 = (majl >>> 16) + (s0l >>> 16) + (c1 >>> 16);
|
|
546
|
+
c3 = (majh & 0xffff) + (s0h & 0xffff) + (c2 >>> 16);
|
|
547
|
+
c4 = (majh >>> 16) + (s0h >>> 16) + (c3 >>> 16);
|
|
548
|
+
t2h = (c4 << 16) | (c3 & 0xffff);
|
|
549
|
+
t2l = (c2 << 16) | (c1 & 0xffff);
|
|
550
|
+
c1 = (al & 0xffff) + (t1l & 0xffff);
|
|
551
|
+
c2 = (al >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
|
552
|
+
c3 = (ah & 0xffff) + (t1h & 0xffff) + (c2 >>> 16);
|
|
553
|
+
c4 = (ah >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
|
554
|
+
eh = (c4 << 16) | (c3 & 0xffff);
|
|
555
|
+
el = (c2 << 16) | (c1 & 0xffff);
|
|
556
|
+
c1 = (t2l & 0xffff) + (t1l & 0xffff);
|
|
557
|
+
c2 = (t2l >>> 16) + (t1l >>> 16) + (c1 >>> 16);
|
|
558
|
+
c3 = (t2h & 0xffff) + (t1h & 0xffff) + (c2 >>> 16);
|
|
559
|
+
c4 = (t2h >>> 16) + (t1h >>> 16) + (c3 >>> 16);
|
|
560
|
+
ah = (c4 << 16) | (c3 & 0xffff);
|
|
561
|
+
al = (c2 << 16) | (c1 & 0xffff);
|
|
562
|
+
}
|
|
563
|
+
c1 = (h0l & 0xffff) + (al & 0xffff);
|
|
564
|
+
c2 = (h0l >>> 16) + (al >>> 16) + (c1 >>> 16);
|
|
565
|
+
c3 = (h0h & 0xffff) + (ah & 0xffff) + (c2 >>> 16);
|
|
566
|
+
c4 = (h0h >>> 16) + (ah >>> 16) + (c3 >>> 16);
|
|
567
|
+
this.h0h = (c4 << 16) | (c3 & 0xffff);
|
|
568
|
+
this.h0l = (c2 << 16) | (c1 & 0xffff);
|
|
569
|
+
c1 = (h1l & 0xffff) + (bl & 0xffff);
|
|
570
|
+
c2 = (h1l >>> 16) + (bl >>> 16) + (c1 >>> 16);
|
|
571
|
+
c3 = (h1h & 0xffff) + (bh & 0xffff) + (c2 >>> 16);
|
|
572
|
+
c4 = (h1h >>> 16) + (bh >>> 16) + (c3 >>> 16);
|
|
573
|
+
this.h1h = (c4 << 16) | (c3 & 0xffff);
|
|
574
|
+
this.h1l = (c2 << 16) | (c1 & 0xffff);
|
|
575
|
+
c1 = (h2l & 0xffff) + (cl & 0xffff);
|
|
576
|
+
c2 = (h2l >>> 16) + (cl >>> 16) + (c1 >>> 16);
|
|
577
|
+
c3 = (h2h & 0xffff) + (ch & 0xffff) + (c2 >>> 16);
|
|
578
|
+
c4 = (h2h >>> 16) + (ch >>> 16) + (c3 >>> 16);
|
|
579
|
+
this.h2h = (c4 << 16) | (c3 & 0xffff);
|
|
580
|
+
this.h2l = (c2 << 16) | (c1 & 0xffff);
|
|
581
|
+
c1 = (h3l & 0xffff) + (dl & 0xffff);
|
|
582
|
+
c2 = (h3l >>> 16) + (dl >>> 16) + (c1 >>> 16);
|
|
583
|
+
c3 = (h3h & 0xffff) + (dh & 0xffff) + (c2 >>> 16);
|
|
584
|
+
c4 = (h3h >>> 16) + (dh >>> 16) + (c3 >>> 16);
|
|
585
|
+
this.h3h = (c4 << 16) | (c3 & 0xffff);
|
|
586
|
+
this.h3l = (c2 << 16) | (c1 & 0xffff);
|
|
587
|
+
c1 = (h4l & 0xffff) + (el & 0xffff);
|
|
588
|
+
c2 = (h4l >>> 16) + (el >>> 16) + (c1 >>> 16);
|
|
589
|
+
c3 = (h4h & 0xffff) + (eh & 0xffff) + (c2 >>> 16);
|
|
590
|
+
c4 = (h4h >>> 16) + (eh >>> 16) + (c3 >>> 16);
|
|
591
|
+
this.h4h = (c4 << 16) | (c3 & 0xffff);
|
|
592
|
+
this.h4l = (c2 << 16) | (c1 & 0xffff);
|
|
593
|
+
c1 = (h5l & 0xffff) + (fl & 0xffff);
|
|
594
|
+
c2 = (h5l >>> 16) + (fl >>> 16) + (c1 >>> 16);
|
|
595
|
+
c3 = (h5h & 0xffff) + (fh & 0xffff) + (c2 >>> 16);
|
|
596
|
+
c4 = (h5h >>> 16) + (fh >>> 16) + (c3 >>> 16);
|
|
597
|
+
this.h5h = (c4 << 16) | (c3 & 0xffff);
|
|
598
|
+
this.h5l = (c2 << 16) | (c1 & 0xffff);
|
|
599
|
+
c1 = (h6l & 0xffff) + (gl & 0xffff);
|
|
600
|
+
c2 = (h6l >>> 16) + (gl >>> 16) + (c1 >>> 16);
|
|
601
|
+
c3 = (h6h & 0xffff) + (gh & 0xffff) + (c2 >>> 16);
|
|
602
|
+
c4 = (h6h >>> 16) + (gh >>> 16) + (c3 >>> 16);
|
|
603
|
+
this.h6h = (c4 << 16) | (c3 & 0xffff);
|
|
604
|
+
this.h6l = (c2 << 16) | (c1 & 0xffff);
|
|
605
|
+
c1 = (h7l & 0xffff) + (hl & 0xffff);
|
|
606
|
+
c2 = (h7l >>> 16) + (hl >>> 16) + (c1 >>> 16);
|
|
607
|
+
c3 = (h7h & 0xffff) + (hh & 0xffff) + (c2 >>> 16);
|
|
608
|
+
c4 = (h7h >>> 16) + (hh >>> 16) + (c3 >>> 16);
|
|
609
|
+
this.h7h = (c4 << 16) | (c3 & 0xffff);
|
|
610
|
+
this.h7l = (c2 << 16) | (c1 & 0xffff);
|
|
611
|
+
};
|
|
612
|
+
Sha512.prototype.hex = function () {
|
|
613
|
+
this.finalize();
|
|
614
|
+
var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l, h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l, h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l, bits = this.bits;
|
|
615
|
+
var hex = HEX_CHARS[(h0h >>> 28) & 0x0f] +
|
|
616
|
+
HEX_CHARS[(h0h >>> 24) & 0x0f] +
|
|
617
|
+
HEX_CHARS[(h0h >>> 20) & 0x0f] +
|
|
618
|
+
HEX_CHARS[(h0h >>> 16) & 0x0f] +
|
|
619
|
+
HEX_CHARS[(h0h >>> 12) & 0x0f] +
|
|
620
|
+
HEX_CHARS[(h0h >>> 8) & 0x0f] +
|
|
621
|
+
HEX_CHARS[(h0h >>> 4) & 0x0f] +
|
|
622
|
+
HEX_CHARS[h0h & 0x0f] +
|
|
623
|
+
HEX_CHARS[(h0l >>> 28) & 0x0f] +
|
|
624
|
+
HEX_CHARS[(h0l >>> 24) & 0x0f] +
|
|
625
|
+
HEX_CHARS[(h0l >>> 20) & 0x0f] +
|
|
626
|
+
HEX_CHARS[(h0l >>> 16) & 0x0f] +
|
|
627
|
+
HEX_CHARS[(h0l >>> 12) & 0x0f] +
|
|
628
|
+
HEX_CHARS[(h0l >>> 8) & 0x0f] +
|
|
629
|
+
HEX_CHARS[(h0l >>> 4) & 0x0f] +
|
|
630
|
+
HEX_CHARS[h0l & 0x0f] +
|
|
631
|
+
HEX_CHARS[(h1h >>> 28) & 0x0f] +
|
|
632
|
+
HEX_CHARS[(h1h >>> 24) & 0x0f] +
|
|
633
|
+
HEX_CHARS[(h1h >>> 20) & 0x0f] +
|
|
634
|
+
HEX_CHARS[(h1h >>> 16) & 0x0f] +
|
|
635
|
+
HEX_CHARS[(h1h >>> 12) & 0x0f] +
|
|
636
|
+
HEX_CHARS[(h1h >>> 8) & 0x0f] +
|
|
637
|
+
HEX_CHARS[(h1h >>> 4) & 0x0f] +
|
|
638
|
+
HEX_CHARS[h1h & 0x0f] +
|
|
639
|
+
HEX_CHARS[(h1l >>> 28) & 0x0f] +
|
|
640
|
+
HEX_CHARS[(h1l >>> 24) & 0x0f] +
|
|
641
|
+
HEX_CHARS[(h1l >>> 20) & 0x0f] +
|
|
642
|
+
HEX_CHARS[(h1l >>> 16) & 0x0f] +
|
|
643
|
+
HEX_CHARS[(h1l >>> 12) & 0x0f] +
|
|
644
|
+
HEX_CHARS[(h1l >>> 8) & 0x0f] +
|
|
645
|
+
HEX_CHARS[(h1l >>> 4) & 0x0f] +
|
|
646
|
+
HEX_CHARS[h1l & 0x0f] +
|
|
647
|
+
HEX_CHARS[(h2h >>> 28) & 0x0f] +
|
|
648
|
+
HEX_CHARS[(h2h >>> 24) & 0x0f] +
|
|
649
|
+
HEX_CHARS[(h2h >>> 20) & 0x0f] +
|
|
650
|
+
HEX_CHARS[(h2h >>> 16) & 0x0f] +
|
|
651
|
+
HEX_CHARS[(h2h >>> 12) & 0x0f] +
|
|
652
|
+
HEX_CHARS[(h2h >>> 8) & 0x0f] +
|
|
653
|
+
HEX_CHARS[(h2h >>> 4) & 0x0f] +
|
|
654
|
+
HEX_CHARS[h2h & 0x0f] +
|
|
655
|
+
HEX_CHARS[(h2l >>> 28) & 0x0f] +
|
|
656
|
+
HEX_CHARS[(h2l >>> 24) & 0x0f] +
|
|
657
|
+
HEX_CHARS[(h2l >>> 20) & 0x0f] +
|
|
658
|
+
HEX_CHARS[(h2l >>> 16) & 0x0f] +
|
|
659
|
+
HEX_CHARS[(h2l >>> 12) & 0x0f] +
|
|
660
|
+
HEX_CHARS[(h2l >>> 8) & 0x0f] +
|
|
661
|
+
HEX_CHARS[(h2l >>> 4) & 0x0f] +
|
|
662
|
+
HEX_CHARS[h2l & 0x0f] +
|
|
663
|
+
HEX_CHARS[(h3h >>> 28) & 0x0f] +
|
|
664
|
+
HEX_CHARS[(h3h >>> 24) & 0x0f] +
|
|
665
|
+
HEX_CHARS[(h3h >>> 20) & 0x0f] +
|
|
666
|
+
HEX_CHARS[(h3h >>> 16) & 0x0f] +
|
|
667
|
+
HEX_CHARS[(h3h >>> 12) & 0x0f] +
|
|
668
|
+
HEX_CHARS[(h3h >>> 8) & 0x0f] +
|
|
669
|
+
HEX_CHARS[(h3h >>> 4) & 0x0f] +
|
|
670
|
+
HEX_CHARS[h3h & 0x0f];
|
|
671
|
+
if (bits >= 256) {
|
|
672
|
+
hex +=
|
|
673
|
+
HEX_CHARS[(h3l >>> 28) & 0x0f] +
|
|
674
|
+
HEX_CHARS[(h3l >>> 24) & 0x0f] +
|
|
675
|
+
HEX_CHARS[(h3l >>> 20) & 0x0f] +
|
|
676
|
+
HEX_CHARS[(h3l >>> 16) & 0x0f] +
|
|
677
|
+
HEX_CHARS[(h3l >>> 12) & 0x0f] +
|
|
678
|
+
HEX_CHARS[(h3l >>> 8) & 0x0f] +
|
|
679
|
+
HEX_CHARS[(h3l >>> 4) & 0x0f] +
|
|
680
|
+
HEX_CHARS[h3l & 0x0f];
|
|
681
|
+
}
|
|
682
|
+
if (bits >= 384) {
|
|
683
|
+
hex +=
|
|
684
|
+
HEX_CHARS[(h4h >>> 28) & 0x0f] +
|
|
685
|
+
HEX_CHARS[(h4h >>> 24) & 0x0f] +
|
|
686
|
+
HEX_CHARS[(h4h >>> 20) & 0x0f] +
|
|
687
|
+
HEX_CHARS[(h4h >>> 16) & 0x0f] +
|
|
688
|
+
HEX_CHARS[(h4h >>> 12) & 0x0f] +
|
|
689
|
+
HEX_CHARS[(h4h >>> 8) & 0x0f] +
|
|
690
|
+
HEX_CHARS[(h4h >>> 4) & 0x0f] +
|
|
691
|
+
HEX_CHARS[h4h & 0x0f] +
|
|
692
|
+
HEX_CHARS[(h4l >>> 28) & 0x0f] +
|
|
693
|
+
HEX_CHARS[(h4l >>> 24) & 0x0f] +
|
|
694
|
+
HEX_CHARS[(h4l >>> 20) & 0x0f] +
|
|
695
|
+
HEX_CHARS[(h4l >>> 16) & 0x0f] +
|
|
696
|
+
HEX_CHARS[(h4l >>> 12) & 0x0f] +
|
|
697
|
+
HEX_CHARS[(h4l >>> 8) & 0x0f] +
|
|
698
|
+
HEX_CHARS[(h4l >>> 4) & 0x0f] +
|
|
699
|
+
HEX_CHARS[h4l & 0x0f] +
|
|
700
|
+
HEX_CHARS[(h5h >>> 28) & 0x0f] +
|
|
701
|
+
HEX_CHARS[(h5h >>> 24) & 0x0f] +
|
|
702
|
+
HEX_CHARS[(h5h >>> 20) & 0x0f] +
|
|
703
|
+
HEX_CHARS[(h5h >>> 16) & 0x0f] +
|
|
704
|
+
HEX_CHARS[(h5h >>> 12) & 0x0f] +
|
|
705
|
+
HEX_CHARS[(h5h >>> 8) & 0x0f] +
|
|
706
|
+
HEX_CHARS[(h5h >>> 4) & 0x0f] +
|
|
707
|
+
HEX_CHARS[h5h & 0x0f] +
|
|
708
|
+
HEX_CHARS[(h5l >>> 28) & 0x0f] +
|
|
709
|
+
HEX_CHARS[(h5l >>> 24) & 0x0f] +
|
|
710
|
+
HEX_CHARS[(h5l >>> 20) & 0x0f] +
|
|
711
|
+
HEX_CHARS[(h5l >>> 16) & 0x0f] +
|
|
712
|
+
HEX_CHARS[(h5l >>> 12) & 0x0f] +
|
|
713
|
+
HEX_CHARS[(h5l >>> 8) & 0x0f] +
|
|
714
|
+
HEX_CHARS[(h5l >>> 4) & 0x0f] +
|
|
715
|
+
HEX_CHARS[h5l & 0x0f];
|
|
716
|
+
}
|
|
717
|
+
if (bits == 512) {
|
|
718
|
+
hex +=
|
|
719
|
+
HEX_CHARS[(h6h >>> 28) & 0x0f] +
|
|
720
|
+
HEX_CHARS[(h6h >>> 24) & 0x0f] +
|
|
721
|
+
HEX_CHARS[(h6h >>> 20) & 0x0f] +
|
|
722
|
+
HEX_CHARS[(h6h >>> 16) & 0x0f] +
|
|
723
|
+
HEX_CHARS[(h6h >>> 12) & 0x0f] +
|
|
724
|
+
HEX_CHARS[(h6h >>> 8) & 0x0f] +
|
|
725
|
+
HEX_CHARS[(h6h >>> 4) & 0x0f] +
|
|
726
|
+
HEX_CHARS[h6h & 0x0f] +
|
|
727
|
+
HEX_CHARS[(h6l >>> 28) & 0x0f] +
|
|
728
|
+
HEX_CHARS[(h6l >>> 24) & 0x0f] +
|
|
729
|
+
HEX_CHARS[(h6l >>> 20) & 0x0f] +
|
|
730
|
+
HEX_CHARS[(h6l >>> 16) & 0x0f] +
|
|
731
|
+
HEX_CHARS[(h6l >>> 12) & 0x0f] +
|
|
732
|
+
HEX_CHARS[(h6l >>> 8) & 0x0f] +
|
|
733
|
+
HEX_CHARS[(h6l >>> 4) & 0x0f] +
|
|
734
|
+
HEX_CHARS[h6l & 0x0f] +
|
|
735
|
+
HEX_CHARS[(h7h >>> 28) & 0x0f] +
|
|
736
|
+
HEX_CHARS[(h7h >>> 24) & 0x0f] +
|
|
737
|
+
HEX_CHARS[(h7h >>> 20) & 0x0f] +
|
|
738
|
+
HEX_CHARS[(h7h >>> 16) & 0x0f] +
|
|
739
|
+
HEX_CHARS[(h7h >>> 12) & 0x0f] +
|
|
740
|
+
HEX_CHARS[(h7h >>> 8) & 0x0f] +
|
|
741
|
+
HEX_CHARS[(h7h >>> 4) & 0x0f] +
|
|
742
|
+
HEX_CHARS[h7h & 0x0f] +
|
|
743
|
+
HEX_CHARS[(h7l >>> 28) & 0x0f] +
|
|
744
|
+
HEX_CHARS[(h7l >>> 24) & 0x0f] +
|
|
745
|
+
HEX_CHARS[(h7l >>> 20) & 0x0f] +
|
|
746
|
+
HEX_CHARS[(h7l >>> 16) & 0x0f] +
|
|
747
|
+
HEX_CHARS[(h7l >>> 12) & 0x0f] +
|
|
748
|
+
HEX_CHARS[(h7l >>> 8) & 0x0f] +
|
|
749
|
+
HEX_CHARS[(h7l >>> 4) & 0x0f] +
|
|
750
|
+
HEX_CHARS[h7l & 0x0f];
|
|
751
|
+
}
|
|
752
|
+
return hex;
|
|
753
|
+
};
|
|
754
|
+
Sha512.prototype.toString = Sha512.prototype.hex;
|
|
755
|
+
Sha512.prototype.digest = function () {
|
|
756
|
+
this.finalize();
|
|
757
|
+
var h0h = this.h0h, h0l = this.h0l, h1h = this.h1h, h1l = this.h1l, h2h = this.h2h, h2l = this.h2l, h3h = this.h3h, h3l = this.h3l, h4h = this.h4h, h4l = this.h4l, h5h = this.h5h, h5l = this.h5l, h6h = this.h6h, h6l = this.h6l, h7h = this.h7h, h7l = this.h7l, bits = this.bits;
|
|
758
|
+
var arr = [
|
|
759
|
+
(h0h >>> 24) & 0xff,
|
|
760
|
+
(h0h >>> 16) & 0xff,
|
|
761
|
+
(h0h >>> 8) & 0xff,
|
|
762
|
+
h0h & 0xff,
|
|
763
|
+
(h0l >>> 24) & 0xff,
|
|
764
|
+
(h0l >>> 16) & 0xff,
|
|
765
|
+
(h0l >>> 8) & 0xff,
|
|
766
|
+
h0l & 0xff,
|
|
767
|
+
(h1h >>> 24) & 0xff,
|
|
768
|
+
(h1h >>> 16) & 0xff,
|
|
769
|
+
(h1h >>> 8) & 0xff,
|
|
770
|
+
h1h & 0xff,
|
|
771
|
+
(h1l >>> 24) & 0xff,
|
|
772
|
+
(h1l >>> 16) & 0xff,
|
|
773
|
+
(h1l >>> 8) & 0xff,
|
|
774
|
+
h1l & 0xff,
|
|
775
|
+
(h2h >>> 24) & 0xff,
|
|
776
|
+
(h2h >>> 16) & 0xff,
|
|
777
|
+
(h2h >>> 8) & 0xff,
|
|
778
|
+
h2h & 0xff,
|
|
779
|
+
(h2l >>> 24) & 0xff,
|
|
780
|
+
(h2l >>> 16) & 0xff,
|
|
781
|
+
(h2l >>> 8) & 0xff,
|
|
782
|
+
h2l & 0xff,
|
|
783
|
+
(h3h >>> 24) & 0xff,
|
|
784
|
+
(h3h >>> 16) & 0xff,
|
|
785
|
+
(h3h >>> 8) & 0xff,
|
|
786
|
+
h3h & 0xff,
|
|
787
|
+
];
|
|
788
|
+
if (bits >= 256) {
|
|
789
|
+
arr.push((h3l >>> 24) & 0xff, (h3l >>> 16) & 0xff, (h3l >>> 8) & 0xff, h3l & 0xff);
|
|
790
|
+
}
|
|
791
|
+
if (bits >= 384) {
|
|
792
|
+
arr.push((h4h >>> 24) & 0xff, (h4h >>> 16) & 0xff, (h4h >>> 8) & 0xff, h4h & 0xff, (h4l >>> 24) & 0xff, (h4l >>> 16) & 0xff, (h4l >>> 8) & 0xff, h4l & 0xff, (h5h >>> 24) & 0xff, (h5h >>> 16) & 0xff, (h5h >>> 8) & 0xff, h5h & 0xff, (h5l >>> 24) & 0xff, (h5l >>> 16) & 0xff, (h5l >>> 8) & 0xff, h5l & 0xff);
|
|
793
|
+
}
|
|
794
|
+
if (bits == 512) {
|
|
795
|
+
arr.push((h6h >>> 24) & 0xff, (h6h >>> 16) & 0xff, (h6h >>> 8) & 0xff, h6h & 0xff, (h6l >>> 24) & 0xff, (h6l >>> 16) & 0xff, (h6l >>> 8) & 0xff, h6l & 0xff, (h7h >>> 24) & 0xff, (h7h >>> 16) & 0xff, (h7h >>> 8) & 0xff, h7h & 0xff, (h7l >>> 24) & 0xff, (h7l >>> 16) & 0xff, (h7l >>> 8) & 0xff, h7l & 0xff);
|
|
796
|
+
}
|
|
797
|
+
return arr;
|
|
798
|
+
};
|
|
799
|
+
Sha512.prototype.array = Sha512.prototype.digest;
|
|
800
|
+
Sha512.prototype.arrayBuffer = function () {
|
|
801
|
+
this.finalize();
|
|
802
|
+
var bits = this.bits;
|
|
803
|
+
var buffer = new ArrayBuffer(bits / 8);
|
|
804
|
+
var dataView = new DataView(buffer);
|
|
805
|
+
dataView.setUint32(0, this.h0h);
|
|
806
|
+
dataView.setUint32(4, this.h0l);
|
|
807
|
+
dataView.setUint32(8, this.h1h);
|
|
808
|
+
dataView.setUint32(12, this.h1l);
|
|
809
|
+
dataView.setUint32(16, this.h2h);
|
|
810
|
+
dataView.setUint32(20, this.h2l);
|
|
811
|
+
dataView.setUint32(24, this.h3h);
|
|
812
|
+
if (bits >= 256) {
|
|
813
|
+
dataView.setUint32(28, this.h3l);
|
|
814
|
+
}
|
|
815
|
+
if (bits >= 384) {
|
|
816
|
+
dataView.setUint32(32, this.h4h);
|
|
817
|
+
dataView.setUint32(36, this.h4l);
|
|
818
|
+
dataView.setUint32(40, this.h5h);
|
|
819
|
+
dataView.setUint32(44, this.h5l);
|
|
820
|
+
}
|
|
821
|
+
if (bits == 512) {
|
|
822
|
+
dataView.setUint32(48, this.h6h);
|
|
823
|
+
dataView.setUint32(52, this.h6l);
|
|
824
|
+
dataView.setUint32(56, this.h7h);
|
|
825
|
+
dataView.setUint32(60, this.h7l);
|
|
826
|
+
}
|
|
827
|
+
return buffer;
|
|
828
|
+
};
|
|
829
|
+
Sha512.prototype.clone = function () {
|
|
830
|
+
var hash = new Sha512(this.bits, false);
|
|
831
|
+
this.copyTo(hash);
|
|
832
|
+
return hash;
|
|
833
|
+
};
|
|
834
|
+
Sha512.prototype.copyTo = function (hash) {
|
|
835
|
+
var i = 0, attrs = [
|
|
836
|
+
"h0h",
|
|
837
|
+
"h0l",
|
|
838
|
+
"h1h",
|
|
839
|
+
"h1l",
|
|
840
|
+
"h2h",
|
|
841
|
+
"h2l",
|
|
842
|
+
"h3h",
|
|
843
|
+
"h3l",
|
|
844
|
+
"h4h",
|
|
845
|
+
"h4l",
|
|
846
|
+
"h5h",
|
|
847
|
+
"h5l",
|
|
848
|
+
"h6h",
|
|
849
|
+
"h6l",
|
|
850
|
+
"h7h",
|
|
851
|
+
"h7l",
|
|
852
|
+
"start",
|
|
853
|
+
"bytes",
|
|
854
|
+
"hBytes",
|
|
855
|
+
"finalized",
|
|
856
|
+
"hashed",
|
|
857
|
+
"lastByteIndex",
|
|
858
|
+
];
|
|
859
|
+
for (i = 0; i < attrs.length; ++i) {
|
|
860
|
+
hash[attrs[i]] = this[attrs[i]];
|
|
861
|
+
}
|
|
862
|
+
for (i = 0; i < this.blocks.length; ++i) {
|
|
863
|
+
hash.blocks[i] = this.blocks[i];
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
function HmacSha512(key, bits, sharedMemory) {
|
|
867
|
+
var i, result = formatMessage(key);
|
|
868
|
+
key = result[0];
|
|
869
|
+
if (result[1]) {
|
|
870
|
+
var bytes = [], length = key.length, index = 0, code;
|
|
871
|
+
for (var i = 0; i < length; ++i) {
|
|
872
|
+
code = key.charCodeAt(i);
|
|
873
|
+
if (code < 0x80) {
|
|
874
|
+
bytes[index++] = code;
|
|
875
|
+
}
|
|
876
|
+
else if (code < 0x800) {
|
|
877
|
+
bytes[index++] = 0xc0 | (code >>> 6);
|
|
878
|
+
bytes[index++] = 0x80 | (code & 0x3f);
|
|
879
|
+
}
|
|
880
|
+
else if (code < 0xd800 || code >= 0xe000) {
|
|
881
|
+
bytes[index++] = 0xe0 | (code >>> 12);
|
|
882
|
+
bytes[index++] = 0x80 | ((code >>> 6) & 0x3f);
|
|
883
|
+
bytes[index++] = 0x80 | (code & 0x3f);
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
|
|
887
|
+
bytes[index++] = 0xf0 | (code >>> 18);
|
|
888
|
+
bytes[index++] = 0x80 | ((code >>> 12) & 0x3f);
|
|
889
|
+
bytes[index++] = 0x80 | ((code >>> 6) & 0x3f);
|
|
890
|
+
bytes[index++] = 0x80 | (code & 0x3f);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
key = bytes;
|
|
894
|
+
}
|
|
895
|
+
if (key.length > 128) {
|
|
896
|
+
key = new Sha512(bits, true).update(key).array();
|
|
897
|
+
}
|
|
898
|
+
var oKeyPad = [], iKeyPad = [];
|
|
899
|
+
for (var i = 0; i < 128; ++i) {
|
|
900
|
+
var b = key[i] || 0;
|
|
901
|
+
oKeyPad[i] = 0x5c ^ b;
|
|
902
|
+
iKeyPad[i] = 0x36 ^ b;
|
|
903
|
+
}
|
|
904
|
+
Sha512.call(this, bits, sharedMemory);
|
|
905
|
+
this.update(iKeyPad);
|
|
906
|
+
this.oKeyPad = oKeyPad;
|
|
907
|
+
this.inner = true;
|
|
908
|
+
this.sharedMemory = sharedMemory;
|
|
909
|
+
}
|
|
910
|
+
HmacSha512.prototype = new Sha512();
|
|
911
|
+
HmacSha512.prototype.finalize = function () {
|
|
912
|
+
Sha512.prototype.finalize.call(this);
|
|
913
|
+
if (this.inner) {
|
|
914
|
+
this.inner = false;
|
|
915
|
+
var innerHash = this.array();
|
|
916
|
+
Sha512.call(this, this.bits, this.sharedMemory);
|
|
917
|
+
this.update(this.oKeyPad);
|
|
918
|
+
this.update(innerHash);
|
|
919
|
+
Sha512.prototype.finalize.call(this);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
HmacSha512.prototype.clone = function () {
|
|
923
|
+
var hash = new HmacSha512([], this.bits, false);
|
|
924
|
+
this.copyTo(hash);
|
|
925
|
+
hash.inner = this.inner;
|
|
926
|
+
for (var i = 0; i < this.oKeyPad.length; ++i) {
|
|
927
|
+
hash.oKeyPad[i] = this.oKeyPad[i];
|
|
928
|
+
}
|
|
929
|
+
return hash;
|
|
930
|
+
};
|
|
931
|
+
/* 以下是内部实现需要的es模块化导出方法 */
|
|
932
|
+
const sha512 = createMethod(512);
|
|
933
|
+
const sha384 = createMethod(384);
|
|
934
|
+
const sha512_256 = createMethod(256);
|
|
935
|
+
const sha512_224 = createMethod(224);
|
|
936
|
+
const sha512_hmac = createHmacMethod(512);
|
|
937
|
+
const sha384_hmac = createHmacMethod(384);
|
|
938
|
+
const sha512_256_hmac = createHmacMethod(256);
|
|
939
|
+
const sha512_224_hmac = createHmacMethod(224);
|
|
940
|
+
|
|
941
|
+
export { sha384, sha384_hmac, sha512, sha512_224, sha512_224_hmac, sha512_256, sha512_256_hmac, sha512_hmac };
|