-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
WordArray.js
47 lines (37 loc) · 1.1 KB
/
WordArray.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
ES6 compatible port of CryptoJS - WordArray for PBKDF2 password key generation
Source: https://github.com/brix/crypto-js
LICENSE: MIT
*/
let CryptoJSWordArray = {
random: function (nBytes) {
let words = [];
let r = function (mw) {
let mz = 0x3ade68b1;
let mask = 0xffffffff;
return function () {
mz = (0x9069 * (mz & 0xffff) + (mz >> 0x10)) & mask;
mw = (0x4650 * (mw & 0xffff) + (mw >> 0x10)) & mask;
let result = ((mz << 0x10) + mw) & mask;
result /= 0x100000000;
result += 0.5;
return result * (Math.random() > 0.5 ? 1 : -1);
};
};
for (let i = 0, rcache; i < nBytes; i += 4) {
let _r = r((rcache || Math.random()) * 0x100000000);
rcache = _r() * 0x3ade67b7;
words.push((_r() * 0x100000000) | 0);
}
return new CryptoJSWordArray.Set(words, nBytes);
},
Set: function (words, sigBytes) {
words = this.words = words || [];
if (sigBytes !== undefined) {
this.sigBytes = sigBytes;
} else {
this.sigBytes = words.length * 8;
}
},
};
export default CryptoJSWordArray;