@brix-crypto/crypto-js 0.0.1-security → 4.2.6
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.
Potentially problematic release.
This version of @brix-crypto/crypto-js might be problematic. Click here for more details.
- package/.jshintrc +33 -0
- package/.travis.yml +15 -0
- package/CONTRIBUTING.md +28 -0
- package/LICENSE +24 -0
- package/README.md +273 -3
- package/aes.js +234 -0
- package/blowfish.js +471 -0
- package/bower.json +39 -0
- package/cipher-core.js +895 -0
- package/core.js +819 -0
- package/crypto-js.js +6657 -0
- package/docs/QuickStartGuide.wiki +470 -0
- package/enc-base64.js +140 -0
- package/enc-base64url.js +148 -0
- package/enc-hex.js +18 -0
- package/enc-latin1.js +18 -0
- package/enc-utf16.js +149 -0
- package/enc-utf8.js +18 -0
- package/evpkdf.js +134 -0
- package/format-hex.js +66 -0
- package/format-openssl.js +18 -0
- package/hmac-md5.js +18 -0
- package/hmac-ripemd160.js +18 -0
- package/hmac-sha1.js +18 -0
- package/hmac-sha224.js +18 -0
- package/hmac-sha256.js +18 -0
- package/hmac-sha3.js +18 -0
- package/hmac-sha384.js +18 -0
- package/hmac-sha512.js +18 -0
- package/hmac.js +143 -0
- package/index.js +18 -0
- package/lib-typedarrays.js +76 -0
- package/md5.js +268 -0
- package/mode-cfb.js +80 -0
- package/mode-ctr-gladman.js +116 -0
- package/mode-ctr.js +58 -0
- package/mode-ecb.js +40 -0
- package/mode-ofb.js +54 -0
- package/package.json +45 -3
- package/pad-ansix923.js +49 -0
- package/pad-iso10126.js +44 -0
- package/pad-iso97971.js +40 -0
- package/pad-nopadding.js +30 -0
- package/pad-pkcs7.js +18 -0
- package/pad-zeropadding.js +47 -0
- package/pbkdf2.js +145 -0
- package/rabbit-legacy.js +190 -0
- package/rabbit.js +192 -0
- package/rc4.js +139 -0
- package/ripemd160.js +267 -0
- package/sha1.js +150 -0
- package/sha224.js +80 -0
- package/sha256.js +199 -0
- package/sha3.js +326 -0
- package/sha384.js +83 -0
- package/sha512.js +326 -0
- package/test/aes-profile.js +31 -0
- package/test/aes-test.js +80 -0
- package/test/blowfish-test.js +33 -0
- package/test/cipher-test.js +522 -0
- package/test/config-test.js +51 -0
- package/test/des-profile.js +31 -0
- package/test/des-test.js +104 -0
- package/test/enc-base64-test.js +71 -0
- package/test/enc-hex-test.js +15 -0
- package/test/enc-latin1-test.js +15 -0
- package/test/enc-utf16-test.js +55 -0
- package/test/enc-utf8-test.js +39 -0
- package/test/evpkdf-profile.js +11 -0
- package/test/evpkdf-test.js +32 -0
- package/test/format-openssl-test.js +37 -0
- package/test/hmac-md5-profile.js +30 -0
- package/test/hmac-md5-test.js +59 -0
- package/test/hmac-sha224-test.js +59 -0
- package/test/hmac-sha256-test.js +59 -0
- package/test/hmac-sha384-test.js +59 -0
- package/test/hmac-sha512-test.js +59 -0
- package/test/kdf-openssl-test.js +15 -0
- package/test/lib-base-test.js +92 -0
- package/test/lib-cipherparams-test.js +59 -0
- package/test/lib-passwordbasedcipher-test.js +25 -0
- package/test/lib-serializablecipher-test.js +51 -0
- package/test/lib-typedarrays-test.js +57 -0
- package/test/lib-wordarray-test.js +85 -0
- package/test/md5-profile.js +24 -0
- package/test/md5-test.js +70 -0
- package/test/mode-cbc-test.js +49 -0
- package/test/mode-cfb-test.js +51 -0
- package/test/mode-ctr-test.js +55 -0
- package/test/mode-ecb-test.js +38 -0
- package/test/mode-ofb-test.js +50 -0
- package/test/pad-ansix923-test.js +28 -0
- package/test/pad-iso10126-test.js +50 -0
- package/test/pad-iso97971-test.js +35 -0
- package/test/pad-pkcs7-test.js +28 -0
- package/test/pad-zeropadding-test.js +28 -0
- package/test/pbkdf2-profile.js +11 -0
- package/test/pbkdf2-test.js +80 -0
- package/test/profile.html +281 -0
- package/test/rabbit-legacy-test.js +80 -0
- package/test/rabbit-profile.js +30 -0
- package/test/rabbit-test.js +84 -0
- package/test/rc4-profile.js +30 -0
- package/test/rc4-test.js +68 -0
- package/test/ripemd160-test.js +19 -0
- package/test/sha1-profile.js +24 -0
- package/test/sha1-test.js +70 -0
- package/test/sha224-test.js +19 -0
- package/test/sha256-profile.js +24 -0
- package/test/sha256-test.js +70 -0
- package/test/sha3-profile.js +24 -0
- package/test/sha3-test.js +69 -0
- package/test/sha384-test.js +54 -0
- package/test/sha512-profile.js +24 -0
- package/test/sha512-test.js +54 -0
- package/test/test-build.html +105 -0
- package/test/test.html +138 -0
- package/test/test1.html +63 -0
- package/test/tripledes-profile.js +31 -0
- package/test/tripledes-test.js +121 -0
- package/test/x64-word-test.js +99 -0
- package/test/x64-wordarray-test.js +38 -0
- package/tripledes.js +779 -0
- package/x64-core.js +304 -0
package/enc-base64url.js
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
;(function (root, factory) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
(function () {
|
17
|
+
// Shortcuts
|
18
|
+
var C = CryptoJS;
|
19
|
+
var C_lib = C.lib;
|
20
|
+
var WordArray = C_lib.WordArray;
|
21
|
+
var C_enc = C.enc;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Base64url encoding strategy.
|
25
|
+
*/
|
26
|
+
var Base64url = C_enc.Base64url = {
|
27
|
+
/**
|
28
|
+
* Converts a word array to a Base64url string.
|
29
|
+
*
|
30
|
+
* @param {WordArray} wordArray The word array.
|
31
|
+
*
|
32
|
+
* @param {boolean} urlSafe Whether to use url safe
|
33
|
+
*
|
34
|
+
* @return {string} The Base64url string.
|
35
|
+
*
|
36
|
+
* @static
|
37
|
+
*
|
38
|
+
* @example
|
39
|
+
*
|
40
|
+
* var base64String = CryptoJS.enc.Base64url.stringify(wordArray);
|
41
|
+
*/
|
42
|
+
stringify: function (wordArray, urlSafe) {
|
43
|
+
if (urlSafe === undefined) {
|
44
|
+
urlSafe = true
|
45
|
+
}
|
46
|
+
// Shortcuts
|
47
|
+
var words = wordArray.words;
|
48
|
+
var sigBytes = wordArray.sigBytes;
|
49
|
+
var map = urlSafe ? this._safe_map : this._map;
|
50
|
+
|
51
|
+
// Clamp excess bits
|
52
|
+
wordArray.clamp();
|
53
|
+
|
54
|
+
// Convert
|
55
|
+
var base64Chars = [];
|
56
|
+
for (var i = 0; i < sigBytes; i += 3) {
|
57
|
+
var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
58
|
+
var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
|
59
|
+
var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
|
60
|
+
|
61
|
+
var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
|
62
|
+
|
63
|
+
for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
|
64
|
+
base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
// Add padding
|
69
|
+
var paddingChar = map.charAt(64);
|
70
|
+
if (paddingChar) {
|
71
|
+
while (base64Chars.length % 4) {
|
72
|
+
base64Chars.push(paddingChar);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
return base64Chars.join('');
|
77
|
+
},
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Converts a Base64url string to a word array.
|
81
|
+
*
|
82
|
+
* @param {string} base64Str The Base64url string.
|
83
|
+
*
|
84
|
+
* @param {boolean} urlSafe Whether to use url safe
|
85
|
+
*
|
86
|
+
* @return {WordArray} The word array.
|
87
|
+
*
|
88
|
+
* @static
|
89
|
+
*
|
90
|
+
* @example
|
91
|
+
*
|
92
|
+
* var wordArray = CryptoJS.enc.Base64url.parse(base64String);
|
93
|
+
*/
|
94
|
+
parse: function (base64Str, urlSafe) {
|
95
|
+
if (urlSafe === undefined) {
|
96
|
+
urlSafe = true
|
97
|
+
}
|
98
|
+
|
99
|
+
// Shortcuts
|
100
|
+
var base64StrLength = base64Str.length;
|
101
|
+
var map = urlSafe ? this._safe_map : this._map;
|
102
|
+
var reverseMap = this._reverseMap;
|
103
|
+
|
104
|
+
if (!reverseMap) {
|
105
|
+
reverseMap = this._reverseMap = [];
|
106
|
+
for (var j = 0; j < map.length; j++) {
|
107
|
+
reverseMap[map.charCodeAt(j)] = j;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
// Ignore padding
|
112
|
+
var paddingChar = map.charAt(64);
|
113
|
+
if (paddingChar) {
|
114
|
+
var paddingIndex = base64Str.indexOf(paddingChar);
|
115
|
+
if (paddingIndex !== -1) {
|
116
|
+
base64StrLength = paddingIndex;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
// Convert
|
121
|
+
return parseLoop(base64Str, base64StrLength, reverseMap);
|
122
|
+
|
123
|
+
},
|
124
|
+
|
125
|
+
_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
|
126
|
+
_safe_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
|
127
|
+
};
|
128
|
+
|
129
|
+
function parseLoop(base64Str, base64StrLength, reverseMap) {
|
130
|
+
var words = [];
|
131
|
+
var nBytes = 0;
|
132
|
+
for (var i = 0; i < base64StrLength; i++) {
|
133
|
+
if (i % 4) {
|
134
|
+
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
|
135
|
+
var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
|
136
|
+
var bitsCombined = bits1 | bits2;
|
137
|
+
words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
|
138
|
+
nBytes++;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
return WordArray.create(words, nBytes);
|
142
|
+
}
|
143
|
+
}());
|
144
|
+
|
145
|
+
|
146
|
+
return CryptoJS.enc.Base64url;
|
147
|
+
|
148
|
+
}));
|
package/enc-hex.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.enc.Hex;
|
17
|
+
|
18
|
+
}));
|
package/enc-latin1.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.enc.Latin1;
|
17
|
+
|
18
|
+
}));
|
package/enc-utf16.js
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
;(function (root, factory) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
(function () {
|
17
|
+
// Shortcuts
|
18
|
+
var C = CryptoJS;
|
19
|
+
var C_lib = C.lib;
|
20
|
+
var WordArray = C_lib.WordArray;
|
21
|
+
var C_enc = C.enc;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* UTF-16 BE encoding strategy.
|
25
|
+
*/
|
26
|
+
var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
|
27
|
+
/**
|
28
|
+
* Converts a word array to a UTF-16 BE string.
|
29
|
+
*
|
30
|
+
* @param {WordArray} wordArray The word array.
|
31
|
+
*
|
32
|
+
* @return {string} The UTF-16 BE string.
|
33
|
+
*
|
34
|
+
* @static
|
35
|
+
*
|
36
|
+
* @example
|
37
|
+
*
|
38
|
+
* var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
|
39
|
+
*/
|
40
|
+
stringify: function (wordArray) {
|
41
|
+
// Shortcuts
|
42
|
+
var words = wordArray.words;
|
43
|
+
var sigBytes = wordArray.sigBytes;
|
44
|
+
|
45
|
+
// Convert
|
46
|
+
var utf16Chars = [];
|
47
|
+
for (var i = 0; i < sigBytes; i += 2) {
|
48
|
+
var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
|
49
|
+
utf16Chars.push(String.fromCharCode(codePoint));
|
50
|
+
}
|
51
|
+
|
52
|
+
return utf16Chars.join('');
|
53
|
+
},
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Converts a UTF-16 BE string to a word array.
|
57
|
+
*
|
58
|
+
* @param {string} utf16Str The UTF-16 BE string.
|
59
|
+
*
|
60
|
+
* @return {WordArray} The word array.
|
61
|
+
*
|
62
|
+
* @static
|
63
|
+
*
|
64
|
+
* @example
|
65
|
+
*
|
66
|
+
* var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
|
67
|
+
*/
|
68
|
+
parse: function (utf16Str) {
|
69
|
+
// Shortcut
|
70
|
+
var utf16StrLength = utf16Str.length;
|
71
|
+
|
72
|
+
// Convert
|
73
|
+
var words = [];
|
74
|
+
for (var i = 0; i < utf16StrLength; i++) {
|
75
|
+
words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
|
76
|
+
}
|
77
|
+
|
78
|
+
return WordArray.create(words, utf16StrLength * 2);
|
79
|
+
}
|
80
|
+
};
|
81
|
+
|
82
|
+
/**
|
83
|
+
* UTF-16 LE encoding strategy.
|
84
|
+
*/
|
85
|
+
C_enc.Utf16LE = {
|
86
|
+
/**
|
87
|
+
* Converts a word array to a UTF-16 LE string.
|
88
|
+
*
|
89
|
+
* @param {WordArray} wordArray The word array.
|
90
|
+
*
|
91
|
+
* @return {string} The UTF-16 LE string.
|
92
|
+
*
|
93
|
+
* @static
|
94
|
+
*
|
95
|
+
* @example
|
96
|
+
*
|
97
|
+
* var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
|
98
|
+
*/
|
99
|
+
stringify: function (wordArray) {
|
100
|
+
// Shortcuts
|
101
|
+
var words = wordArray.words;
|
102
|
+
var sigBytes = wordArray.sigBytes;
|
103
|
+
|
104
|
+
// Convert
|
105
|
+
var utf16Chars = [];
|
106
|
+
for (var i = 0; i < sigBytes; i += 2) {
|
107
|
+
var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
|
108
|
+
utf16Chars.push(String.fromCharCode(codePoint));
|
109
|
+
}
|
110
|
+
|
111
|
+
return utf16Chars.join('');
|
112
|
+
},
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Converts a UTF-16 LE string to a word array.
|
116
|
+
*
|
117
|
+
* @param {string} utf16Str The UTF-16 LE string.
|
118
|
+
*
|
119
|
+
* @return {WordArray} The word array.
|
120
|
+
*
|
121
|
+
* @static
|
122
|
+
*
|
123
|
+
* @example
|
124
|
+
*
|
125
|
+
* var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
|
126
|
+
*/
|
127
|
+
parse: function (utf16Str) {
|
128
|
+
// Shortcut
|
129
|
+
var utf16StrLength = utf16Str.length;
|
130
|
+
|
131
|
+
// Convert
|
132
|
+
var words = [];
|
133
|
+
for (var i = 0; i < utf16StrLength; i++) {
|
134
|
+
words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
|
135
|
+
}
|
136
|
+
|
137
|
+
return WordArray.create(words, utf16StrLength * 2);
|
138
|
+
}
|
139
|
+
};
|
140
|
+
|
141
|
+
function swapEndian(word) {
|
142
|
+
return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
|
143
|
+
}
|
144
|
+
}());
|
145
|
+
|
146
|
+
|
147
|
+
return CryptoJS.enc.Utf16;
|
148
|
+
|
149
|
+
}));
|
package/enc-utf8.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.enc.Utf8;
|
17
|
+
|
18
|
+
}));
|
package/evpkdf.js
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./sha1", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
(function () {
|
17
|
+
// Shortcuts
|
18
|
+
var C = CryptoJS;
|
19
|
+
var C_lib = C.lib;
|
20
|
+
var Base = C_lib.Base;
|
21
|
+
var WordArray = C_lib.WordArray;
|
22
|
+
var C_algo = C.algo;
|
23
|
+
var MD5 = C_algo.MD5;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* This key derivation function is meant to conform with EVP_BytesToKey.
|
27
|
+
* www.openssl.org/docs/crypto/EVP_BytesToKey.html
|
28
|
+
*/
|
29
|
+
var EvpKDF = C_algo.EvpKDF = Base.extend({
|
30
|
+
/**
|
31
|
+
* Configuration options.
|
32
|
+
*
|
33
|
+
* @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
|
34
|
+
* @property {Hasher} hasher The hash algorithm to use. Default: MD5
|
35
|
+
* @property {number} iterations The number of iterations to perform. Default: 1
|
36
|
+
*/
|
37
|
+
cfg: Base.extend({
|
38
|
+
keySize: 128/32,
|
39
|
+
hasher: MD5,
|
40
|
+
iterations: 1
|
41
|
+
}),
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Initializes a newly created key derivation function.
|
45
|
+
*
|
46
|
+
* @param {Object} cfg (Optional) The configuration options to use for the derivation.
|
47
|
+
*
|
48
|
+
* @example
|
49
|
+
*
|
50
|
+
* var kdf = CryptoJS.algo.EvpKDF.create();
|
51
|
+
* var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
|
52
|
+
* var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
|
53
|
+
*/
|
54
|
+
init: function (cfg) {
|
55
|
+
this.cfg = this.cfg.extend(cfg);
|
56
|
+
},
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Derives a key from a password.
|
60
|
+
*
|
61
|
+
* @param {WordArray|string} password The password.
|
62
|
+
* @param {WordArray|string} salt A salt.
|
63
|
+
*
|
64
|
+
* @return {WordArray} The derived key.
|
65
|
+
*
|
66
|
+
* @example
|
67
|
+
*
|
68
|
+
* var key = kdf.compute(password, salt);
|
69
|
+
*/
|
70
|
+
compute: function (password, salt) {
|
71
|
+
var block;
|
72
|
+
|
73
|
+
// Shortcut
|
74
|
+
var cfg = this.cfg;
|
75
|
+
|
76
|
+
// Init hasher
|
77
|
+
var hasher = cfg.hasher.create();
|
78
|
+
|
79
|
+
// Initial values
|
80
|
+
var derivedKey = WordArray.create();
|
81
|
+
|
82
|
+
// Shortcuts
|
83
|
+
var derivedKeyWords = derivedKey.words;
|
84
|
+
var keySize = cfg.keySize;
|
85
|
+
var iterations = cfg.iterations;
|
86
|
+
|
87
|
+
// Generate key
|
88
|
+
while (derivedKeyWords.length < keySize) {
|
89
|
+
if (block) {
|
90
|
+
hasher.update(block);
|
91
|
+
}
|
92
|
+
block = hasher.update(password).finalize(salt);
|
93
|
+
hasher.reset();
|
94
|
+
|
95
|
+
// Iterations
|
96
|
+
for (var i = 1; i < iterations; i++) {
|
97
|
+
block = hasher.finalize(block);
|
98
|
+
hasher.reset();
|
99
|
+
}
|
100
|
+
|
101
|
+
derivedKey.concat(block);
|
102
|
+
}
|
103
|
+
derivedKey.sigBytes = keySize * 4;
|
104
|
+
|
105
|
+
return derivedKey;
|
106
|
+
}
|
107
|
+
});
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Derives a key from a password.
|
111
|
+
*
|
112
|
+
* @param {WordArray|string} password The password.
|
113
|
+
* @param {WordArray|string} salt A salt.
|
114
|
+
* @param {Object} cfg (Optional) The configuration options to use for this computation.
|
115
|
+
*
|
116
|
+
* @return {WordArray} The derived key.
|
117
|
+
*
|
118
|
+
* @static
|
119
|
+
*
|
120
|
+
* @example
|
121
|
+
*
|
122
|
+
* var key = CryptoJS.EvpKDF(password, salt);
|
123
|
+
* var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
|
124
|
+
* var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
|
125
|
+
*/
|
126
|
+
C.EvpKDF = function (password, salt, cfg) {
|
127
|
+
return EvpKDF.create(cfg).compute(password, salt);
|
128
|
+
};
|
129
|
+
}());
|
130
|
+
|
131
|
+
|
132
|
+
return CryptoJS.EvpKDF;
|
133
|
+
|
134
|
+
}));
|
package/format-hex.js
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
(function (undefined) {
|
17
|
+
// Shortcuts
|
18
|
+
var C = CryptoJS;
|
19
|
+
var C_lib = C.lib;
|
20
|
+
var CipherParams = C_lib.CipherParams;
|
21
|
+
var C_enc = C.enc;
|
22
|
+
var Hex = C_enc.Hex;
|
23
|
+
var C_format = C.format;
|
24
|
+
|
25
|
+
var HexFormatter = C_format.Hex = {
|
26
|
+
/**
|
27
|
+
* Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
|
28
|
+
*
|
29
|
+
* @param {CipherParams} cipherParams The cipher params object.
|
30
|
+
*
|
31
|
+
* @return {string} The hexadecimally encoded string.
|
32
|
+
*
|
33
|
+
* @static
|
34
|
+
*
|
35
|
+
* @example
|
36
|
+
*
|
37
|
+
* var hexString = CryptoJS.format.Hex.stringify(cipherParams);
|
38
|
+
*/
|
39
|
+
stringify: function (cipherParams) {
|
40
|
+
return cipherParams.ciphertext.toString(Hex);
|
41
|
+
},
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Converts a hexadecimally encoded ciphertext string to a cipher params object.
|
45
|
+
*
|
46
|
+
* @param {string} input The hexadecimally encoded string.
|
47
|
+
*
|
48
|
+
* @return {CipherParams} The cipher params object.
|
49
|
+
*
|
50
|
+
* @static
|
51
|
+
*
|
52
|
+
* @example
|
53
|
+
*
|
54
|
+
* var cipherParams = CryptoJS.format.Hex.parse(hexString);
|
55
|
+
*/
|
56
|
+
parse: function (input) {
|
57
|
+
var ciphertext = Hex.parse(input);
|
58
|
+
return CipherParams.create({ ciphertext: ciphertext });
|
59
|
+
}
|
60
|
+
};
|
61
|
+
}());
|
62
|
+
|
63
|
+
|
64
|
+
return CryptoJS.format.Hex;
|
65
|
+
|
66
|
+
}));
|
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.format.OpenSSL;
|
17
|
+
|
18
|
+
}));
|
package/hmac-md5.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./md5"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./md5", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.HmacMD5;
|
17
|
+
|
18
|
+
}));
|
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./ripemd160"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./ripemd160", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.HmacRIPEMD160;
|
17
|
+
|
18
|
+
}));
|
package/hmac-sha1.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./sha1", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.HmacSHA1;
|
17
|
+
|
18
|
+
}));
|
package/hmac-sha224.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./sha256"), require("./sha224"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./sha256", "./sha224", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.HmacSHA224;
|
17
|
+
|
18
|
+
}));
|
package/hmac-sha256.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./sha256"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./sha256", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.HmacSHA256;
|
17
|
+
|
18
|
+
}));
|
package/hmac-sha3.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha3"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./x64-core", "./sha3", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.HmacSHA3;
|
17
|
+
|
18
|
+
}));
|