@brix-crypto/crypto-js 0.0.1-security → 4.2.5
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/hmac-sha384.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("./sha512"), require("./sha384"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./x64-core", "./sha512", "./sha384", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.HmacSHA384;
|
17
|
+
|
18
|
+
}));
|
package/hmac-sha512.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("./sha512"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./x64-core", "./sha512", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.HmacSHA512;
|
17
|
+
|
18
|
+
}));
|
package/hmac.js
ADDED
@@ -0,0 +1,143 @@
|
|
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 Base = C_lib.Base;
|
21
|
+
var C_enc = C.enc;
|
22
|
+
var Utf8 = C_enc.Utf8;
|
23
|
+
var C_algo = C.algo;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* HMAC algorithm.
|
27
|
+
*/
|
28
|
+
var HMAC = C_algo.HMAC = Base.extend({
|
29
|
+
/**
|
30
|
+
* Initializes a newly created HMAC.
|
31
|
+
*
|
32
|
+
* @param {Hasher} hasher The hash algorithm to use.
|
33
|
+
* @param {WordArray|string} key The secret key.
|
34
|
+
*
|
35
|
+
* @example
|
36
|
+
*
|
37
|
+
* var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
|
38
|
+
*/
|
39
|
+
init: function (hasher, key) {
|
40
|
+
// Init hasher
|
41
|
+
hasher = this._hasher = new hasher.init();
|
42
|
+
|
43
|
+
// Convert string to WordArray, else assume WordArray already
|
44
|
+
if (typeof key == 'string') {
|
45
|
+
key = Utf8.parse(key);
|
46
|
+
}
|
47
|
+
|
48
|
+
// Shortcuts
|
49
|
+
var hasherBlockSize = hasher.blockSize;
|
50
|
+
var hasherBlockSizeBytes = hasherBlockSize * 4;
|
51
|
+
|
52
|
+
// Allow arbitrary length keys
|
53
|
+
if (key.sigBytes > hasherBlockSizeBytes) {
|
54
|
+
key = hasher.finalize(key);
|
55
|
+
}
|
56
|
+
|
57
|
+
// Clamp excess bits
|
58
|
+
key.clamp();
|
59
|
+
|
60
|
+
// Clone key for inner and outer pads
|
61
|
+
var oKey = this._oKey = key.clone();
|
62
|
+
var iKey = this._iKey = key.clone();
|
63
|
+
|
64
|
+
// Shortcuts
|
65
|
+
var oKeyWords = oKey.words;
|
66
|
+
var iKeyWords = iKey.words;
|
67
|
+
|
68
|
+
// XOR keys with pad constants
|
69
|
+
for (var i = 0; i < hasherBlockSize; i++) {
|
70
|
+
oKeyWords[i] ^= 0x5c5c5c5c;
|
71
|
+
iKeyWords[i] ^= 0x36363636;
|
72
|
+
}
|
73
|
+
oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
|
74
|
+
|
75
|
+
// Set initial values
|
76
|
+
this.reset();
|
77
|
+
},
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Resets this HMAC to its initial state.
|
81
|
+
*
|
82
|
+
* @example
|
83
|
+
*
|
84
|
+
* hmacHasher.reset();
|
85
|
+
*/
|
86
|
+
reset: function () {
|
87
|
+
// Shortcut
|
88
|
+
var hasher = this._hasher;
|
89
|
+
|
90
|
+
// Reset
|
91
|
+
hasher.reset();
|
92
|
+
hasher.update(this._iKey);
|
93
|
+
},
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Updates this HMAC with a message.
|
97
|
+
*
|
98
|
+
* @param {WordArray|string} messageUpdate The message to append.
|
99
|
+
*
|
100
|
+
* @return {HMAC} This HMAC instance.
|
101
|
+
*
|
102
|
+
* @example
|
103
|
+
*
|
104
|
+
* hmacHasher.update('message');
|
105
|
+
* hmacHasher.update(wordArray);
|
106
|
+
*/
|
107
|
+
update: function (messageUpdate) {
|
108
|
+
this._hasher.update(messageUpdate);
|
109
|
+
|
110
|
+
// Chainable
|
111
|
+
return this;
|
112
|
+
},
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Finalizes the HMAC computation.
|
116
|
+
* Note that the finalize operation is effectively a destructive, read-once operation.
|
117
|
+
*
|
118
|
+
* @param {WordArray|string} messageUpdate (Optional) A final message update.
|
119
|
+
*
|
120
|
+
* @return {WordArray} The HMAC.
|
121
|
+
*
|
122
|
+
* @example
|
123
|
+
*
|
124
|
+
* var hmac = hmacHasher.finalize();
|
125
|
+
* var hmac = hmacHasher.finalize('message');
|
126
|
+
* var hmac = hmacHasher.finalize(wordArray);
|
127
|
+
*/
|
128
|
+
finalize: function (messageUpdate) {
|
129
|
+
// Shortcut
|
130
|
+
var hasher = this._hasher;
|
131
|
+
|
132
|
+
// Compute HMAC
|
133
|
+
var innerHash = hasher.finalize(messageUpdate);
|
134
|
+
hasher.reset();
|
135
|
+
var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
|
136
|
+
|
137
|
+
return hmac;
|
138
|
+
}
|
139
|
+
});
|
140
|
+
}());
|
141
|
+
|
142
|
+
|
143
|
+
}));
|
package/index.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("./lib-typedarrays"), require("./enc-utf16"), require("./enc-base64"), require("./enc-base64url"), require("./md5"), require("./sha1"), require("./sha256"), require("./sha224"), require("./sha512"), require("./sha384"), require("./sha3"), require("./ripemd160"), require("./hmac"), require("./pbkdf2"), require("./evpkdf"), require("./cipher-core"), require("./mode-cfb"), require("./mode-ctr"), require("./mode-ctr-gladman"), require("./mode-ofb"), require("./mode-ecb"), require("./pad-ansix923"), require("./pad-iso10126"), require("./pad-iso97971"), require("./pad-zeropadding"), require("./pad-nopadding"), require("./format-hex"), require("./aes"), require("./tripledes"), require("./rc4"), require("./rabbit"), require("./rabbit-legacy"), require("./blowfish"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./x64-core", "./lib-typedarrays", "./enc-utf16", "./enc-base64", "./enc-base64url", "./md5", "./sha1", "./sha256", "./sha224", "./sha512", "./sha384", "./sha3", "./ripemd160", "./hmac", "./pbkdf2", "./evpkdf", "./cipher-core", "./mode-cfb", "./mode-ctr", "./mode-ctr-gladman", "./mode-ofb", "./mode-ecb", "./pad-ansix923", "./pad-iso10126", "./pad-iso97971", "./pad-zeropadding", "./pad-nopadding", "./format-hex", "./aes", "./tripledes", "./rc4", "./rabbit", "./rabbit-legacy", "./blowfish"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
root.CryptoJS = factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS;
|
17
|
+
|
18
|
+
}));
|
@@ -0,0 +1,76 @@
|
|
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
|
+
// Check if typed arrays are supported
|
18
|
+
if (typeof ArrayBuffer != 'function') {
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
|
22
|
+
// Shortcuts
|
23
|
+
var C = CryptoJS;
|
24
|
+
var C_lib = C.lib;
|
25
|
+
var WordArray = C_lib.WordArray;
|
26
|
+
|
27
|
+
// Reference original init
|
28
|
+
var superInit = WordArray.init;
|
29
|
+
|
30
|
+
// Augment WordArray.init to handle typed arrays
|
31
|
+
var subInit = WordArray.init = function (typedArray) {
|
32
|
+
// Convert buffers to uint8
|
33
|
+
if (typedArray instanceof ArrayBuffer) {
|
34
|
+
typedArray = new Uint8Array(typedArray);
|
35
|
+
}
|
36
|
+
|
37
|
+
// Convert other array views to uint8
|
38
|
+
if (
|
39
|
+
typedArray instanceof Int8Array ||
|
40
|
+
(typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
|
41
|
+
typedArray instanceof Int16Array ||
|
42
|
+
typedArray instanceof Uint16Array ||
|
43
|
+
typedArray instanceof Int32Array ||
|
44
|
+
typedArray instanceof Uint32Array ||
|
45
|
+
typedArray instanceof Float32Array ||
|
46
|
+
typedArray instanceof Float64Array
|
47
|
+
) {
|
48
|
+
typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
|
49
|
+
}
|
50
|
+
|
51
|
+
// Handle Uint8Array
|
52
|
+
if (typedArray instanceof Uint8Array) {
|
53
|
+
// Shortcut
|
54
|
+
var typedArrayByteLength = typedArray.byteLength;
|
55
|
+
|
56
|
+
// Extract bytes
|
57
|
+
var words = [];
|
58
|
+
for (var i = 0; i < typedArrayByteLength; i++) {
|
59
|
+
words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
|
60
|
+
}
|
61
|
+
|
62
|
+
// Initialize this word array
|
63
|
+
superInit.call(this, words, typedArrayByteLength);
|
64
|
+
} else {
|
65
|
+
// Else call normal init
|
66
|
+
superInit.apply(this, arguments);
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
subInit.prototype = WordArray;
|
71
|
+
}());
|
72
|
+
|
73
|
+
|
74
|
+
return CryptoJS.lib.WordArray;
|
75
|
+
|
76
|
+
}));
|
package/md5.js
ADDED
@@ -0,0 +1,268 @@
|
|
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 (Math) {
|
17
|
+
// Shortcuts
|
18
|
+
var C = CryptoJS;
|
19
|
+
var C_lib = C.lib;
|
20
|
+
var WordArray = C_lib.WordArray;
|
21
|
+
var Hasher = C_lib.Hasher;
|
22
|
+
var C_algo = C.algo;
|
23
|
+
|
24
|
+
// Constants table
|
25
|
+
var T = [];
|
26
|
+
|
27
|
+
// Compute constants
|
28
|
+
(function () {
|
29
|
+
for (var i = 0; i < 64; i++) {
|
30
|
+
T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
|
31
|
+
}
|
32
|
+
}());
|
33
|
+
|
34
|
+
/**
|
35
|
+
* MD5 hash algorithm.
|
36
|
+
*/
|
37
|
+
var MD5 = C_algo.MD5 = Hasher.extend({
|
38
|
+
_doReset: function () {
|
39
|
+
this._hash = new WordArray.init([
|
40
|
+
0x67452301, 0xefcdab89,
|
41
|
+
0x98badcfe, 0x10325476
|
42
|
+
]);
|
43
|
+
},
|
44
|
+
|
45
|
+
_doProcessBlock: function (M, offset) {
|
46
|
+
// Swap endian
|
47
|
+
for (var i = 0; i < 16; i++) {
|
48
|
+
// Shortcuts
|
49
|
+
var offset_i = offset + i;
|
50
|
+
var M_offset_i = M[offset_i];
|
51
|
+
|
52
|
+
M[offset_i] = (
|
53
|
+
(((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
|
54
|
+
(((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
|
55
|
+
);
|
56
|
+
}
|
57
|
+
|
58
|
+
// Shortcuts
|
59
|
+
var H = this._hash.words;
|
60
|
+
|
61
|
+
var M_offset_0 = M[offset + 0];
|
62
|
+
var M_offset_1 = M[offset + 1];
|
63
|
+
var M_offset_2 = M[offset + 2];
|
64
|
+
var M_offset_3 = M[offset + 3];
|
65
|
+
var M_offset_4 = M[offset + 4];
|
66
|
+
var M_offset_5 = M[offset + 5];
|
67
|
+
var M_offset_6 = M[offset + 6];
|
68
|
+
var M_offset_7 = M[offset + 7];
|
69
|
+
var M_offset_8 = M[offset + 8];
|
70
|
+
var M_offset_9 = M[offset + 9];
|
71
|
+
var M_offset_10 = M[offset + 10];
|
72
|
+
var M_offset_11 = M[offset + 11];
|
73
|
+
var M_offset_12 = M[offset + 12];
|
74
|
+
var M_offset_13 = M[offset + 13];
|
75
|
+
var M_offset_14 = M[offset + 14];
|
76
|
+
var M_offset_15 = M[offset + 15];
|
77
|
+
|
78
|
+
// Working variables
|
79
|
+
var a = H[0];
|
80
|
+
var b = H[1];
|
81
|
+
var c = H[2];
|
82
|
+
var d = H[3];
|
83
|
+
|
84
|
+
// Computation
|
85
|
+
a = FF(a, b, c, d, M_offset_0, 7, T[0]);
|
86
|
+
d = FF(d, a, b, c, M_offset_1, 12, T[1]);
|
87
|
+
c = FF(c, d, a, b, M_offset_2, 17, T[2]);
|
88
|
+
b = FF(b, c, d, a, M_offset_3, 22, T[3]);
|
89
|
+
a = FF(a, b, c, d, M_offset_4, 7, T[4]);
|
90
|
+
d = FF(d, a, b, c, M_offset_5, 12, T[5]);
|
91
|
+
c = FF(c, d, a, b, M_offset_6, 17, T[6]);
|
92
|
+
b = FF(b, c, d, a, M_offset_7, 22, T[7]);
|
93
|
+
a = FF(a, b, c, d, M_offset_8, 7, T[8]);
|
94
|
+
d = FF(d, a, b, c, M_offset_9, 12, T[9]);
|
95
|
+
c = FF(c, d, a, b, M_offset_10, 17, T[10]);
|
96
|
+
b = FF(b, c, d, a, M_offset_11, 22, T[11]);
|
97
|
+
a = FF(a, b, c, d, M_offset_12, 7, T[12]);
|
98
|
+
d = FF(d, a, b, c, M_offset_13, 12, T[13]);
|
99
|
+
c = FF(c, d, a, b, M_offset_14, 17, T[14]);
|
100
|
+
b = FF(b, c, d, a, M_offset_15, 22, T[15]);
|
101
|
+
|
102
|
+
a = GG(a, b, c, d, M_offset_1, 5, T[16]);
|
103
|
+
d = GG(d, a, b, c, M_offset_6, 9, T[17]);
|
104
|
+
c = GG(c, d, a, b, M_offset_11, 14, T[18]);
|
105
|
+
b = GG(b, c, d, a, M_offset_0, 20, T[19]);
|
106
|
+
a = GG(a, b, c, d, M_offset_5, 5, T[20]);
|
107
|
+
d = GG(d, a, b, c, M_offset_10, 9, T[21]);
|
108
|
+
c = GG(c, d, a, b, M_offset_15, 14, T[22]);
|
109
|
+
b = GG(b, c, d, a, M_offset_4, 20, T[23]);
|
110
|
+
a = GG(a, b, c, d, M_offset_9, 5, T[24]);
|
111
|
+
d = GG(d, a, b, c, M_offset_14, 9, T[25]);
|
112
|
+
c = GG(c, d, a, b, M_offset_3, 14, T[26]);
|
113
|
+
b = GG(b, c, d, a, M_offset_8, 20, T[27]);
|
114
|
+
a = GG(a, b, c, d, M_offset_13, 5, T[28]);
|
115
|
+
d = GG(d, a, b, c, M_offset_2, 9, T[29]);
|
116
|
+
c = GG(c, d, a, b, M_offset_7, 14, T[30]);
|
117
|
+
b = GG(b, c, d, a, M_offset_12, 20, T[31]);
|
118
|
+
|
119
|
+
a = HH(a, b, c, d, M_offset_5, 4, T[32]);
|
120
|
+
d = HH(d, a, b, c, M_offset_8, 11, T[33]);
|
121
|
+
c = HH(c, d, a, b, M_offset_11, 16, T[34]);
|
122
|
+
b = HH(b, c, d, a, M_offset_14, 23, T[35]);
|
123
|
+
a = HH(a, b, c, d, M_offset_1, 4, T[36]);
|
124
|
+
d = HH(d, a, b, c, M_offset_4, 11, T[37]);
|
125
|
+
c = HH(c, d, a, b, M_offset_7, 16, T[38]);
|
126
|
+
b = HH(b, c, d, a, M_offset_10, 23, T[39]);
|
127
|
+
a = HH(a, b, c, d, M_offset_13, 4, T[40]);
|
128
|
+
d = HH(d, a, b, c, M_offset_0, 11, T[41]);
|
129
|
+
c = HH(c, d, a, b, M_offset_3, 16, T[42]);
|
130
|
+
b = HH(b, c, d, a, M_offset_6, 23, T[43]);
|
131
|
+
a = HH(a, b, c, d, M_offset_9, 4, T[44]);
|
132
|
+
d = HH(d, a, b, c, M_offset_12, 11, T[45]);
|
133
|
+
c = HH(c, d, a, b, M_offset_15, 16, T[46]);
|
134
|
+
b = HH(b, c, d, a, M_offset_2, 23, T[47]);
|
135
|
+
|
136
|
+
a = II(a, b, c, d, M_offset_0, 6, T[48]);
|
137
|
+
d = II(d, a, b, c, M_offset_7, 10, T[49]);
|
138
|
+
c = II(c, d, a, b, M_offset_14, 15, T[50]);
|
139
|
+
b = II(b, c, d, a, M_offset_5, 21, T[51]);
|
140
|
+
a = II(a, b, c, d, M_offset_12, 6, T[52]);
|
141
|
+
d = II(d, a, b, c, M_offset_3, 10, T[53]);
|
142
|
+
c = II(c, d, a, b, M_offset_10, 15, T[54]);
|
143
|
+
b = II(b, c, d, a, M_offset_1, 21, T[55]);
|
144
|
+
a = II(a, b, c, d, M_offset_8, 6, T[56]);
|
145
|
+
d = II(d, a, b, c, M_offset_15, 10, T[57]);
|
146
|
+
c = II(c, d, a, b, M_offset_6, 15, T[58]);
|
147
|
+
b = II(b, c, d, a, M_offset_13, 21, T[59]);
|
148
|
+
a = II(a, b, c, d, M_offset_4, 6, T[60]);
|
149
|
+
d = II(d, a, b, c, M_offset_11, 10, T[61]);
|
150
|
+
c = II(c, d, a, b, M_offset_2, 15, T[62]);
|
151
|
+
b = II(b, c, d, a, M_offset_9, 21, T[63]);
|
152
|
+
|
153
|
+
// Intermediate hash value
|
154
|
+
H[0] = (H[0] + a) | 0;
|
155
|
+
H[1] = (H[1] + b) | 0;
|
156
|
+
H[2] = (H[2] + c) | 0;
|
157
|
+
H[3] = (H[3] + d) | 0;
|
158
|
+
},
|
159
|
+
|
160
|
+
_doFinalize: function () {
|
161
|
+
// Shortcuts
|
162
|
+
var data = this._data;
|
163
|
+
var dataWords = data.words;
|
164
|
+
|
165
|
+
var nBitsTotal = this._nDataBytes * 8;
|
166
|
+
var nBitsLeft = data.sigBytes * 8;
|
167
|
+
|
168
|
+
// Add padding
|
169
|
+
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
170
|
+
|
171
|
+
var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
|
172
|
+
var nBitsTotalL = nBitsTotal;
|
173
|
+
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
|
174
|
+
(((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
|
175
|
+
(((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
|
176
|
+
);
|
177
|
+
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
|
178
|
+
(((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
|
179
|
+
(((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
|
180
|
+
);
|
181
|
+
|
182
|
+
data.sigBytes = (dataWords.length + 1) * 4;
|
183
|
+
|
184
|
+
// Hash final blocks
|
185
|
+
this._process();
|
186
|
+
|
187
|
+
// Shortcuts
|
188
|
+
var hash = this._hash;
|
189
|
+
var H = hash.words;
|
190
|
+
|
191
|
+
// Swap endian
|
192
|
+
for (var i = 0; i < 4; i++) {
|
193
|
+
// Shortcut
|
194
|
+
var H_i = H[i];
|
195
|
+
|
196
|
+
H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
|
197
|
+
(((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
|
198
|
+
}
|
199
|
+
|
200
|
+
// Return final computed hash
|
201
|
+
return hash;
|
202
|
+
},
|
203
|
+
|
204
|
+
clone: function () {
|
205
|
+
var clone = Hasher.clone.call(this);
|
206
|
+
clone._hash = this._hash.clone();
|
207
|
+
|
208
|
+
return clone;
|
209
|
+
}
|
210
|
+
});
|
211
|
+
|
212
|
+
function FF(a, b, c, d, x, s, t) {
|
213
|
+
var n = a + ((b & c) | (~b & d)) + x + t;
|
214
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
215
|
+
}
|
216
|
+
|
217
|
+
function GG(a, b, c, d, x, s, t) {
|
218
|
+
var n = a + ((b & d) | (c & ~d)) + x + t;
|
219
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
220
|
+
}
|
221
|
+
|
222
|
+
function HH(a, b, c, d, x, s, t) {
|
223
|
+
var n = a + (b ^ c ^ d) + x + t;
|
224
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
225
|
+
}
|
226
|
+
|
227
|
+
function II(a, b, c, d, x, s, t) {
|
228
|
+
var n = a + (c ^ (b | ~d)) + x + t;
|
229
|
+
return ((n << s) | (n >>> (32 - s))) + b;
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Shortcut function to the hasher's object interface.
|
234
|
+
*
|
235
|
+
* @param {WordArray|string} message The message to hash.
|
236
|
+
*
|
237
|
+
* @return {WordArray} The hash.
|
238
|
+
*
|
239
|
+
* @static
|
240
|
+
*
|
241
|
+
* @example
|
242
|
+
*
|
243
|
+
* var hash = CryptoJS.MD5('message');
|
244
|
+
* var hash = CryptoJS.MD5(wordArray);
|
245
|
+
*/
|
246
|
+
C.MD5 = Hasher._createHelper(MD5);
|
247
|
+
|
248
|
+
/**
|
249
|
+
* Shortcut function to the HMAC's object interface.
|
250
|
+
*
|
251
|
+
* @param {WordArray|string} message The message to hash.
|
252
|
+
* @param {WordArray|string} key The secret key.
|
253
|
+
*
|
254
|
+
* @return {WordArray} The HMAC.
|
255
|
+
*
|
256
|
+
* @static
|
257
|
+
*
|
258
|
+
* @example
|
259
|
+
*
|
260
|
+
* var hmac = CryptoJS.HmacMD5(message, key);
|
261
|
+
*/
|
262
|
+
C.HmacMD5 = Hasher._createHmacHelper(MD5);
|
263
|
+
}(Math));
|
264
|
+
|
265
|
+
|
266
|
+
return CryptoJS.MD5;
|
267
|
+
|
268
|
+
}));
|
package/mode-cfb.js
ADDED
@@ -0,0 +1,80 @@
|
|
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
|
+
/**
|
17
|
+
* Cipher Feedback block mode.
|
18
|
+
*/
|
19
|
+
CryptoJS.mode.CFB = (function () {
|
20
|
+
var CFB = CryptoJS.lib.BlockCipherMode.extend();
|
21
|
+
|
22
|
+
CFB.Encryptor = CFB.extend({
|
23
|
+
processBlock: function (words, offset) {
|
24
|
+
// Shortcuts
|
25
|
+
var cipher = this._cipher;
|
26
|
+
var blockSize = cipher.blockSize;
|
27
|
+
|
28
|
+
generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
|
29
|
+
|
30
|
+
// Remember this block to use with next block
|
31
|
+
this._prevBlock = words.slice(offset, offset + blockSize);
|
32
|
+
}
|
33
|
+
});
|
34
|
+
|
35
|
+
CFB.Decryptor = CFB.extend({
|
36
|
+
processBlock: function (words, offset) {
|
37
|
+
// Shortcuts
|
38
|
+
var cipher = this._cipher;
|
39
|
+
var blockSize = cipher.blockSize;
|
40
|
+
|
41
|
+
// Remember this block to use with next block
|
42
|
+
var thisBlock = words.slice(offset, offset + blockSize);
|
43
|
+
|
44
|
+
generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
|
45
|
+
|
46
|
+
// This block becomes the previous block
|
47
|
+
this._prevBlock = thisBlock;
|
48
|
+
}
|
49
|
+
});
|
50
|
+
|
51
|
+
function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
|
52
|
+
var keystream;
|
53
|
+
|
54
|
+
// Shortcut
|
55
|
+
var iv = this._iv;
|
56
|
+
|
57
|
+
// Generate keystream
|
58
|
+
if (iv) {
|
59
|
+
keystream = iv.slice(0);
|
60
|
+
|
61
|
+
// Remove IV for subsequent blocks
|
62
|
+
this._iv = undefined;
|
63
|
+
} else {
|
64
|
+
keystream = this._prevBlock;
|
65
|
+
}
|
66
|
+
cipher.encryptBlock(keystream, 0);
|
67
|
+
|
68
|
+
// Encrypt
|
69
|
+
for (var i = 0; i < blockSize; i++) {
|
70
|
+
words[offset + i] ^= keystream[i];
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
return CFB;
|
75
|
+
}());
|
76
|
+
|
77
|
+
|
78
|
+
return CryptoJS.mode.CFB;
|
79
|
+
|
80
|
+
}));
|