@brix-crypto/crypto-js 0.0.1-security → 4.2.1

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.

Files changed (108) hide show
  1. package/.jshintrc +33 -0
  2. package/.travis.yml +15 -0
  3. package/CONTRIBUTING.md +28 -0
  4. package/LICENSE +24 -0
  5. package/README.md +273 -3
  6. package/docs/QuickStartGuide.wiki +470 -0
  7. package/package.json +45 -3
  8. package/src/aes.js +214 -0
  9. package/src/blowfish.js +451 -0
  10. package/src/cipher-core.js +877 -0
  11. package/src/core.js +796 -0
  12. package/src/enc-base64.js +116 -0
  13. package/src/enc-base64url.js +128 -0
  14. package/src/enc-utf16.js +129 -0
  15. package/src/evpkdf.js +114 -0
  16. package/src/format-hex.js +46 -0
  17. package/src/hmac.js +125 -0
  18. package/src/lib-typedarrays.js +56 -0
  19. package/src/md5.js +248 -0
  20. package/src/mode-cfb.js +60 -0
  21. package/src/mode-ctr-gladman.js +96 -0
  22. package/src/mode-ctr.js +38 -0
  23. package/src/mode-ecb.js +20 -0
  24. package/src/mode-ofb.js +34 -0
  25. package/src/pad-ansix923.js +29 -0
  26. package/src/pad-iso10126.js +24 -0
  27. package/src/pad-iso97971.js +20 -0
  28. package/src/pad-nopadding.js +10 -0
  29. package/src/pad-zeropadding.js +27 -0
  30. package/src/pbkdf2.js +125 -0
  31. package/src/rabbit-legacy.js +170 -0
  32. package/src/rabbit.js +172 -0
  33. package/src/rc4.js +119 -0
  34. package/src/ripemd160.js +247 -0
  35. package/src/sha1.js +130 -0
  36. package/src/sha224.js +60 -0
  37. package/src/sha256.js +179 -0
  38. package/src/sha3.js +306 -0
  39. package/src/sha384.js +63 -0
  40. package/src/sha512.js +306 -0
  41. package/src/tripledes.js +759 -0
  42. package/src/x64-core.js +284 -0
  43. package/test/aes-profile.js +31 -0
  44. package/test/aes-test.js +80 -0
  45. package/test/blowfish-test.js +33 -0
  46. package/test/cipher-test.js +522 -0
  47. package/test/config-test.js +51 -0
  48. package/test/des-profile.js +31 -0
  49. package/test/des-test.js +104 -0
  50. package/test/enc-base64-test.js +71 -0
  51. package/test/enc-hex-test.js +15 -0
  52. package/test/enc-latin1-test.js +15 -0
  53. package/test/enc-utf16-test.js +55 -0
  54. package/test/enc-utf8-test.js +39 -0
  55. package/test/evpkdf-profile.js +11 -0
  56. package/test/evpkdf-test.js +32 -0
  57. package/test/format-openssl-test.js +37 -0
  58. package/test/hmac-md5-profile.js +30 -0
  59. package/test/hmac-md5-test.js +59 -0
  60. package/test/hmac-sha224-test.js +59 -0
  61. package/test/hmac-sha256-test.js +59 -0
  62. package/test/hmac-sha384-test.js +59 -0
  63. package/test/hmac-sha512-test.js +59 -0
  64. package/test/kdf-openssl-test.js +15 -0
  65. package/test/lib-base-test.js +92 -0
  66. package/test/lib-cipherparams-test.js +59 -0
  67. package/test/lib-passwordbasedcipher-test.js +25 -0
  68. package/test/lib-serializablecipher-test.js +51 -0
  69. package/test/lib-typedarrays-test.js +57 -0
  70. package/test/lib-wordarray-test.js +85 -0
  71. package/test/md5-profile.js +24 -0
  72. package/test/md5-test.js +70 -0
  73. package/test/mode-cbc-test.js +49 -0
  74. package/test/mode-cfb-test.js +51 -0
  75. package/test/mode-ctr-test.js +55 -0
  76. package/test/mode-ecb-test.js +38 -0
  77. package/test/mode-ofb-test.js +50 -0
  78. package/test/pad-ansix923-test.js +28 -0
  79. package/test/pad-iso10126-test.js +50 -0
  80. package/test/pad-iso97971-test.js +35 -0
  81. package/test/pad-pkcs7-test.js +28 -0
  82. package/test/pad-zeropadding-test.js +28 -0
  83. package/test/pbkdf2-profile.js +11 -0
  84. package/test/pbkdf2-test.js +80 -0
  85. package/test/profile.html +281 -0
  86. package/test/rabbit-legacy-test.js +80 -0
  87. package/test/rabbit-profile.js +30 -0
  88. package/test/rabbit-test.js +84 -0
  89. package/test/rc4-profile.js +30 -0
  90. package/test/rc4-test.js +68 -0
  91. package/test/ripemd160-test.js +19 -0
  92. package/test/sha1-profile.js +24 -0
  93. package/test/sha1-test.js +70 -0
  94. package/test/sha224-test.js +19 -0
  95. package/test/sha256-profile.js +24 -0
  96. package/test/sha256-test.js +70 -0
  97. package/test/sha3-profile.js +24 -0
  98. package/test/sha3-test.js +69 -0
  99. package/test/sha384-test.js +54 -0
  100. package/test/sha512-profile.js +24 -0
  101. package/test/sha512-test.js +54 -0
  102. package/test/test-build.html +105 -0
  103. package/test/test.html +138 -0
  104. package/test/test1.html +63 -0
  105. package/test/tripledes-profile.js +31 -0
  106. package/test/tripledes-test.js +121 -0
  107. package/test/x64-word-test.js +99 -0
  108. package/test/x64-wordarray-test.js +38 -0
@@ -0,0 +1,284 @@
1
+ (function (undefined) {
2
+ // Shortcuts
3
+ var C = CryptoJS;
4
+ var C_lib = C.lib;
5
+ var Base = C_lib.Base;
6
+ var X32WordArray = C_lib.WordArray;
7
+
8
+ /**
9
+ * x64 namespace.
10
+ */
11
+ var C_x64 = C.x64 = {};
12
+
13
+ /**
14
+ * A 64-bit word.
15
+ */
16
+ var X64Word = C_x64.Word = Base.extend({
17
+ /**
18
+ * Initializes a newly created 64-bit word.
19
+ *
20
+ * @param {number} high The high 32 bits.
21
+ * @param {number} low The low 32 bits.
22
+ *
23
+ * @example
24
+ *
25
+ * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
26
+ */
27
+ init: function (high, low) {
28
+ this.high = high;
29
+ this.low = low;
30
+ }
31
+
32
+ /**
33
+ * Bitwise NOTs this word.
34
+ *
35
+ * @return {X64Word} A new x64-Word object after negating.
36
+ *
37
+ * @example
38
+ *
39
+ * var negated = x64Word.not();
40
+ */
41
+ // not: function () {
42
+ // var high = ~this.high;
43
+ // var low = ~this.low;
44
+
45
+ // return X64Word.create(high, low);
46
+ // },
47
+
48
+ /**
49
+ * Bitwise ANDs this word with the passed word.
50
+ *
51
+ * @param {X64Word} word The x64-Word to AND with this word.
52
+ *
53
+ * @return {X64Word} A new x64-Word object after ANDing.
54
+ *
55
+ * @example
56
+ *
57
+ * var anded = x64Word.and(anotherX64Word);
58
+ */
59
+ // and: function (word) {
60
+ // var high = this.high & word.high;
61
+ // var low = this.low & word.low;
62
+
63
+ // return X64Word.create(high, low);
64
+ // },
65
+
66
+ /**
67
+ * Bitwise ORs this word with the passed word.
68
+ *
69
+ * @param {X64Word} word The x64-Word to OR with this word.
70
+ *
71
+ * @return {X64Word} A new x64-Word object after ORing.
72
+ *
73
+ * @example
74
+ *
75
+ * var ored = x64Word.or(anotherX64Word);
76
+ */
77
+ // or: function (word) {
78
+ // var high = this.high | word.high;
79
+ // var low = this.low | word.low;
80
+
81
+ // return X64Word.create(high, low);
82
+ // },
83
+
84
+ /**
85
+ * Bitwise XORs this word with the passed word.
86
+ *
87
+ * @param {X64Word} word The x64-Word to XOR with this word.
88
+ *
89
+ * @return {X64Word} A new x64-Word object after XORing.
90
+ *
91
+ * @example
92
+ *
93
+ * var xored = x64Word.xor(anotherX64Word);
94
+ */
95
+ // xor: function (word) {
96
+ // var high = this.high ^ word.high;
97
+ // var low = this.low ^ word.low;
98
+
99
+ // return X64Word.create(high, low);
100
+ // },
101
+
102
+ /**
103
+ * Shifts this word n bits to the left.
104
+ *
105
+ * @param {number} n The number of bits to shift.
106
+ *
107
+ * @return {X64Word} A new x64-Word object after shifting.
108
+ *
109
+ * @example
110
+ *
111
+ * var shifted = x64Word.shiftL(25);
112
+ */
113
+ // shiftL: function (n) {
114
+ // if (n < 32) {
115
+ // var high = (this.high << n) | (this.low >>> (32 - n));
116
+ // var low = this.low << n;
117
+ // } else {
118
+ // var high = this.low << (n - 32);
119
+ // var low = 0;
120
+ // }
121
+
122
+ // return X64Word.create(high, low);
123
+ // },
124
+
125
+ /**
126
+ * Shifts this word n bits to the right.
127
+ *
128
+ * @param {number} n The number of bits to shift.
129
+ *
130
+ * @return {X64Word} A new x64-Word object after shifting.
131
+ *
132
+ * @example
133
+ *
134
+ * var shifted = x64Word.shiftR(7);
135
+ */
136
+ // shiftR: function (n) {
137
+ // if (n < 32) {
138
+ // var low = (this.low >>> n) | (this.high << (32 - n));
139
+ // var high = this.high >>> n;
140
+ // } else {
141
+ // var low = this.high >>> (n - 32);
142
+ // var high = 0;
143
+ // }
144
+
145
+ // return X64Word.create(high, low);
146
+ // },
147
+
148
+ /**
149
+ * Rotates this word n bits to the left.
150
+ *
151
+ * @param {number} n The number of bits to rotate.
152
+ *
153
+ * @return {X64Word} A new x64-Word object after rotating.
154
+ *
155
+ * @example
156
+ *
157
+ * var rotated = x64Word.rotL(25);
158
+ */
159
+ // rotL: function (n) {
160
+ // return this.shiftL(n).or(this.shiftR(64 - n));
161
+ // },
162
+
163
+ /**
164
+ * Rotates this word n bits to the right.
165
+ *
166
+ * @param {number} n The number of bits to rotate.
167
+ *
168
+ * @return {X64Word} A new x64-Word object after rotating.
169
+ *
170
+ * @example
171
+ *
172
+ * var rotated = x64Word.rotR(7);
173
+ */
174
+ // rotR: function (n) {
175
+ // return this.shiftR(n).or(this.shiftL(64 - n));
176
+ // },
177
+
178
+ /**
179
+ * Adds this word with the passed word.
180
+ *
181
+ * @param {X64Word} word The x64-Word to add with this word.
182
+ *
183
+ * @return {X64Word} A new x64-Word object after adding.
184
+ *
185
+ * @example
186
+ *
187
+ * var added = x64Word.add(anotherX64Word);
188
+ */
189
+ // add: function (word) {
190
+ // var low = (this.low + word.low) | 0;
191
+ // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
192
+ // var high = (this.high + word.high + carry) | 0;
193
+
194
+ // return X64Word.create(high, low);
195
+ // }
196
+ });
197
+
198
+ /**
199
+ * An array of 64-bit words.
200
+ *
201
+ * @property {Array} words The array of CryptoJS.x64.Word objects.
202
+ * @property {number} sigBytes The number of significant bytes in this word array.
203
+ */
204
+ var X64WordArray = C_x64.WordArray = Base.extend({
205
+ /**
206
+ * Initializes a newly created word array.
207
+ *
208
+ * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
209
+ * @param {number} sigBytes (Optional) The number of significant bytes in the words.
210
+ *
211
+ * @example
212
+ *
213
+ * var wordArray = CryptoJS.x64.WordArray.create();
214
+ *
215
+ * var wordArray = CryptoJS.x64.WordArray.create([
216
+ * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
217
+ * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
218
+ * ]);
219
+ *
220
+ * var wordArray = CryptoJS.x64.WordArray.create([
221
+ * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
222
+ * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
223
+ * ], 10);
224
+ */
225
+ init: function (words, sigBytes) {
226
+ words = this.words = words || [];
227
+
228
+ if (sigBytes != undefined) {
229
+ this.sigBytes = sigBytes;
230
+ } else {
231
+ this.sigBytes = words.length * 8;
232
+ }
233
+ },
234
+
235
+ /**
236
+ * Converts this 64-bit word array to a 32-bit word array.
237
+ *
238
+ * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
239
+ *
240
+ * @example
241
+ *
242
+ * var x32WordArray = x64WordArray.toX32();
243
+ */
244
+ toX32: function () {
245
+ // Shortcuts
246
+ var x64Words = this.words;
247
+ var x64WordsLength = x64Words.length;
248
+
249
+ // Convert
250
+ var x32Words = [];
251
+ for (var i = 0; i < x64WordsLength; i++) {
252
+ var x64Word = x64Words[i];
253
+ x32Words.push(x64Word.high);
254
+ x32Words.push(x64Word.low);
255
+ }
256
+
257
+ return X32WordArray.create(x32Words, this.sigBytes);
258
+ },
259
+
260
+ /**
261
+ * Creates a copy of this word array.
262
+ *
263
+ * @return {X64WordArray} The clone.
264
+ *
265
+ * @example
266
+ *
267
+ * var clone = x64WordArray.clone();
268
+ */
269
+ clone: function () {
270
+ var clone = Base.clone.call(this);
271
+
272
+ // Clone "words" array
273
+ var words = clone.words = this.words.slice(0);
274
+
275
+ // Clone each X64Word object
276
+ var wordsLength = words.length;
277
+ for (var i = 0; i < wordsLength; i++) {
278
+ words[i] = words[i].clone();
279
+ }
280
+
281
+ return clone;
282
+ }
283
+ });
284
+ }());
@@ -0,0 +1,31 @@
1
+ YUI.add('algo-aes-profile', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Profiler.add({
5
+ name: 'AES',
6
+
7
+ setUp: function () {
8
+ this.data = {
9
+ key: C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'),
10
+ iv: C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f')
11
+ };
12
+ },
13
+
14
+ profileSinglePartMessage: function () {
15
+ var singlePartMessage = '';
16
+ for (var i = 0; i < 500; i++) {
17
+ singlePartMessage += '12345678901234567890123456789012345678901234567890';
18
+ }
19
+
20
+ C.algo.AES.createEncryptor(this.data.key, { iv: this.data.iv }).finalize(singlePartMessage) + '';
21
+ },
22
+
23
+ profileMultiPartMessage: function () {
24
+ var aes = C.algo.AES.createEncryptor(this.data.key, { iv: this.data.iv });
25
+ for (var i = 0; i < 500; i++) {
26
+ aes.process('12345678901234567890123456789012345678901234567890') + '';
27
+ }
28
+ aes.finalize() + '';
29
+ }
30
+ });
31
+ }, '$Rev$');
@@ -0,0 +1,80 @@
1
+ YUI.add('algo-aes-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'AES',
6
+
7
+ testEncryptKeySize128: function () {
8
+ Y.Assert.areEqual('69c4e0d86a7b0430d8cdb78070b4c55a', C.AES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
9
+ },
10
+
11
+ testEncryptKeySize192: function () {
12
+ Y.Assert.areEqual('dda97ca4864cdfe06eaf70a0ec0d7191', C.AES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f1011121314151617'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
13
+ },
14
+
15
+ testEncryptKeySize256: function () {
16
+ Y.Assert.areEqual('8ea2b7ca516745bfeafc49904b496089', C.AES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
17
+ },
18
+
19
+ testDecryptKeySize128: function () {
20
+ Y.Assert.areEqual('00112233445566778899aabbccddeeff', C.AES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('69c4e0d86a7b0430d8cdb78070b4c55a') }), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
21
+ },
22
+
23
+ testDecryptKeySize192: function () {
24
+ Y.Assert.areEqual('00112233445566778899aabbccddeeff', C.AES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('dda97ca4864cdfe06eaf70a0ec0d7191') }), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f1011121314151617'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
25
+ },
26
+
27
+ testDecryptKeySize256: function () {
28
+ Y.Assert.areEqual('00112233445566778899aabbccddeeff', C.AES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('8ea2b7ca516745bfeafc49904b496089') }), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
29
+ },
30
+
31
+ testMultiPart: function () {
32
+ var aes = C.algo.AES.createEncryptor(C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f'), { mode: C.mode.ECB, padding: C.pad.NoPadding });
33
+ var ciphertext1 = aes.process(C.enc.Hex.parse('001122334455'));
34
+ var ciphertext2 = aes.process(C.enc.Hex.parse('66778899aa'));
35
+ var ciphertext3 = aes.process(C.enc.Hex.parse('bbccddeeff'));
36
+ var ciphertext4 = aes.finalize();
37
+
38
+ Y.Assert.areEqual('69c4e0d86a7b0430d8cdb78070b4c55a', ciphertext1.concat(ciphertext2).concat(ciphertext3).concat(ciphertext4).toString());
39
+ },
40
+
41
+ testInputIntegrity: function () {
42
+ var message = C.enc.Hex.parse('00112233445566778899aabbccddeeff');
43
+ var key = C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f');
44
+ var iv = C.enc.Hex.parse('101112131415161718191a1b1c1d1e1f');
45
+
46
+ var expectedMessage = message.toString();
47
+ var expectedKey = key.toString();
48
+ var expectedIv = iv.toString();
49
+
50
+ C.AES.encrypt(message, key, { iv: iv });
51
+
52
+ Y.Assert.areEqual(expectedMessage, message.toString());
53
+ Y.Assert.areEqual(expectedKey, key.toString());
54
+ Y.Assert.areEqual(expectedIv, iv.toString());
55
+ },
56
+
57
+ testHelper: function () {
58
+ // Save original random method
59
+ var random = C.lib.WordArray.random;
60
+
61
+ // Replace random method with one that returns a predictable value
62
+ C.lib.WordArray.random = function (nBytes) {
63
+ var words = [];
64
+ for (var i = 0; i < nBytes; i += 4) {
65
+ words.push([0x11223344]);
66
+ }
67
+
68
+ return C.lib.WordArray.create(words, nBytes);
69
+ };
70
+
71
+ // Test
72
+ Y.Assert.areEqual(C.algo.AES.createEncryptor(C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).finalize('Hi There').toString(), C.AES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
73
+ Y.Assert.areEqual(C.lib.SerializableCipher.encrypt(C.algo.AES, 'Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.AES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
74
+ Y.Assert.areEqual(C.lib.PasswordBasedCipher.encrypt(C.algo.AES, 'Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.AES.encrypt('Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
75
+
76
+ // Restore random method
77
+ C.lib.WordArray.random = random;
78
+ }
79
+ }));
80
+ }, '$Rev$');
@@ -0,0 +1,33 @@
1
+ YUI.add('algo-aes-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'Blowfish',
6
+
7
+ setUp: function () {
8
+ this.data = {
9
+ saltA: CryptoJS.enc.Hex.parse('AA00000000000000')
10
+ };
11
+ },
12
+
13
+ testEncrypt: function () {
14
+ let encryptedA = C.Blowfish.encrypt('Test',
15
+ 'pass',
16
+ {
17
+ salt: this.data.saltA,
18
+ hasher: CryptoJS.algo.SHA256
19
+ }).toString();
20
+ Y.Assert.areEqual('U2FsdGVkX1+qAAAAAAAAAKTIU8MPrBdH', encryptedA);
21
+ },
22
+
23
+ testDecrypt: function () {
24
+ let encryptedA = C.Blowfish.encrypt('Test',
25
+ 'pass',
26
+ {
27
+ salt: this.data.saltA,
28
+ hasher: CryptoJS.algo.SHA256
29
+ }).toString();
30
+ Y.Assert.areEqual('Test', C.Blowfish.decrypt(encryptedA, 'pass', {hasher: CryptoJS.algo.SHA256}).toString(C.enc.Utf8));
31
+ }
32
+ }));
33
+ }, '$Rev$');