@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,59 @@
1
+ YUI.add('algo-hmac-sha512-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'HMAC SHA512',
6
+
7
+ testVector1: function () {
8
+ Y.Assert.areEqual('7641c48a3b4aa8f887c07b3e83f96affb89c978fed8c96fcbbf4ad596eebfe496f9f16da6cd080ba393c6f365ad72b50d15c71bfb1d6b81f66a911786c6ce932', C.HmacSHA512('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString());
9
+ },
10
+
11
+ testVector2: function () {
12
+ Y.Assert.areEqual('164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737', C.HmacSHA512('what do ya want for nothing?', 'Jefe').toString());
13
+ },
14
+
15
+ testVector3: function () {
16
+ Y.Assert.areEqual('ad9b5c7de72693737cd5e9d9f41170d18841fec1201c1c1b02e05cae116718009f771cad9946ddbf7e3cde3e818d9ae85d91b2badae94172d096a44a79c91e86', C.HmacSHA512(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString());
17
+ },
18
+
19
+ testVector4: function () {
20
+ Y.Assert.areEqual('a303979f7c94bb39a8ab6ce05cdbe28f0255da8bb305263e3478ef7e855f0242729bf1d2be55398f14da8e63f0302465a8a3f76c297bd584ad028d18ed7f0195', C.HmacSHA512('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A').toString());
21
+ },
22
+
23
+ testVector5: function () {
24
+ Y.Assert.areEqual('8c2d56f7628325e62124c0a870ad98d101327fc42696899a06ce0d7121454022fae597e42c25ac3a4c380fd514f553702a5b0afaa9b5a22050902f024368e9d9', C.HmacSHA512('abcdefghijklmnopqrstuvwxyz', 'A').toString());
25
+ },
26
+
27
+ testUpdate: function () {
28
+ var hmac = C.algo.HMAC.create(C.algo.SHA512, C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'));
29
+ hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddd'));
30
+ hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd'));
31
+ hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd'));
32
+
33
+ Y.Assert.areEqual(C.HmacSHA512(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString(), hmac.finalize().toString());
34
+ },
35
+
36
+ testInputIntegrity: function () {
37
+ var message = C.lib.WordArray.create([0x12345678]);
38
+ var key = C.lib.WordArray.create([0x12345678]);
39
+
40
+ var expectedMessage = message.toString();
41
+ var expectedKey = key.toString();
42
+
43
+ C.HmacSHA512(message, key);
44
+
45
+ Y.Assert.areEqual(expectedMessage, message.toString());
46
+ Y.Assert.areEqual(expectedKey, key.toString());
47
+ },
48
+
49
+ testRespectKeySigBytes: function () {
50
+ var key = C.lib.WordArray.random(8);
51
+ key.sigBytes = 4;
52
+
53
+ var keyClamped = key.clone();
54
+ keyClamped.clamp();
55
+
56
+ Y.Assert.areEqual(CryptoJS.HmacSHA512("Message", keyClamped).toString(), CryptoJS.HmacSHA512("Message", key).toString());
57
+ }
58
+ }));
59
+ }, '$Rev$');
@@ -0,0 +1,15 @@
1
+ YUI.add('kdf-openssl-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'OpenSSLKdf',
6
+
7
+ testVector: function () {
8
+ var derivedParams = C.kdf.OpenSSL.execute('password', 256/32, 128/32, C.enc.Hex.parse('0a9d8620cf7219f1'));
9
+
10
+ Y.Assert.areEqual('50f32e0ec9408e02ff42364a52aac95c3694fc027256c6f488bf84b8e60effcd', derivedParams.key.toString());
11
+ Y.Assert.areEqual('81381e39b94fd692dff7e2239a298cb6', derivedParams.iv.toString());
12
+ Y.Assert.areEqual('0a9d8620cf7219f1', derivedParams.salt.toString());
13
+ }
14
+ }));
15
+ }, '$Rev$');
@@ -0,0 +1,92 @@
1
+ YUI.add('lib-base-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'Base',
6
+
7
+ setUp: function () {
8
+ this.data = {};
9
+
10
+ this.data.overrides = {
11
+ init: function (arg) {
12
+ this.initFired = true;
13
+ this.initArg = arg;
14
+ },
15
+
16
+ toString: function () {
17
+ }
18
+ };
19
+
20
+ this.data.mixins = {
21
+ mixinMethod: function () {
22
+ }
23
+ };
24
+
25
+ this.data.Obj = C.lib.Base.extend(this.data.overrides);
26
+
27
+ this.data.Obj.mixIn(this.data.mixins);
28
+
29
+ this.data.obj = this.data.Obj.create('argValue');
30
+
31
+ this.data.objClone = this.data.obj.clone();
32
+ },
33
+
34
+ testExtendInheritance: function () {
35
+ Y.Assert.areEqual(C.lib.Base.extend, this.data.Obj.extend);
36
+ Y.Assert.isFalse(this.data.Obj.hasOwnProperty('extend'));
37
+ },
38
+
39
+ testExtendSuper: function () {
40
+ Y.Assert.areEqual(C.lib.Base, this.data.Obj.$super);
41
+ },
42
+
43
+ testExtendOverrideInit: function () {
44
+ Y.Assert.areEqual(this.data.overrides.init, this.data.Obj.init);
45
+ Y.Assert.isTrue(this.data.Obj.hasOwnProperty('init'));
46
+ },
47
+
48
+ testExtendOverrideToString: function () {
49
+ Y.Assert.areEqual(this.data.overrides.toString, this.data.Obj.toString);
50
+ Y.Assert.isTrue(this.data.Obj.hasOwnProperty('toString'));
51
+ },
52
+
53
+ testCreateInheritanceFromBase: function () {
54
+ Y.Assert.areEqual(C.lib.Base.extend, this.data.obj.extend);
55
+ Y.Assert.isFalse(this.data.obj.hasOwnProperty('extend'));
56
+ },
57
+
58
+ testCreateSuper: function () {
59
+ Y.Assert.areEqual(this.data.Obj, this.data.obj.$super);
60
+ },
61
+
62
+ testCreateInit: function () {
63
+ Y.Assert.isTrue(this.data.obj.initFired);
64
+ Y.Assert.areEqual('argValue', this.data.obj.initArg);
65
+ },
66
+
67
+ testMixIn: function () {
68
+ Y.Assert.areEqual(this.data.mixins.mixinMethod, this.data.Obj.mixinMethod);
69
+ Y.Assert.isTrue(this.data.Obj.hasOwnProperty('mixinMethod'));
70
+ },
71
+
72
+ testCloneDistinct: function () {
73
+ Y.Assert.areNotEqual(this.data.obj, this.data.objClone);
74
+ },
75
+
76
+ testCloneCopy: function () {
77
+ Y.Assert.areEqual(this.data.obj.initArg, this.data.objClone.initArg);
78
+ },
79
+
80
+ testCloneIndependent: function () {
81
+ this.data.obj.initArg = 'newValue';
82
+
83
+ Y.Assert.areNotEqual(this.data.obj.initArg, this.data.objClone.initArg);
84
+ },
85
+
86
+ testCloneLeavesOriginalInitPrototypeUnchanged: function() {
87
+ Y.Assert.areEqual(this.data.obj, this.data.obj.init.prototype);
88
+ Y.Assert.areEqual(this.data.objClone, this.data.objClone.init.prototype);
89
+ Y.Assert.areNotEqual(this.data.obj.init.prototype, this.data.objClone.init.prototype);
90
+ }
91
+ }));
92
+ }, '$Rev$');
@@ -0,0 +1,59 @@
1
+ YUI.add('lib-cipherparams-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'CipherParams',
6
+
7
+ setUp: function () {
8
+ this.data = {};
9
+
10
+ this.data.ciphertext = C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f');
11
+ this.data.key = C.enc.Hex.parse('101112131415161718191a1b1c1d1e1f');
12
+ this.data.iv = C.enc.Hex.parse('202122232425262728292a2b2c2d2e2f');
13
+ this.data.salt = C.enc.Hex.parse('0123456789abcdef');
14
+ this.data.algorithm = C.algo.AES;
15
+ this.data.mode = C.mode.CBC;
16
+ this.data.padding = C.pad.PKCS7;
17
+ this.data.blockSize = this.data.algorithm.blockSize;
18
+ this.data.formatter = C.format.OpenSSL;
19
+
20
+ this.data.cipherParams = C.lib.CipherParams.create({
21
+ ciphertext: this.data.ciphertext,
22
+ key: this.data.key,
23
+ iv: this.data.iv,
24
+ salt: this.data.salt,
25
+ algorithm: this.data.algorithm,
26
+ mode: this.data.mode,
27
+ padding: this.data.padding,
28
+ blockSize: this.data.blockSize,
29
+ formatter: this.data.formatter
30
+ });
31
+ },
32
+
33
+ testInit: function () {
34
+ Y.Assert.areEqual(this.data.ciphertext, this.data.cipherParams.ciphertext);
35
+ Y.Assert.areEqual(this.data.key, this.data.cipherParams.key);
36
+ Y.Assert.areEqual(this.data.iv, this.data.cipherParams.iv);
37
+ Y.Assert.areEqual(this.data.salt, this.data.cipherParams.salt);
38
+ Y.Assert.areEqual(this.data.algorithm, this.data.cipherParams.algorithm);
39
+ Y.Assert.areEqual(this.data.mode, this.data.cipherParams.mode);
40
+ Y.Assert.areEqual(this.data.padding, this.data.cipherParams.padding);
41
+ Y.Assert.areEqual(this.data.blockSize, this.data.cipherParams.blockSize);
42
+ Y.Assert.areEqual(this.data.formatter, this.data.cipherParams.formatter);
43
+ },
44
+
45
+ testToString0: function () {
46
+ Y.Assert.areEqual(C.format.OpenSSL.stringify(this.data.cipherParams), this.data.cipherParams.toString());
47
+ },
48
+
49
+ testToString1: function () {
50
+ var JsonFormatter = {
51
+ stringify: function (cipherParams) {
52
+ return '{ ct: ' + cipherParams.ciphertext + ', iv: ' + cipherParams.iv + ' }';
53
+ }
54
+ };
55
+
56
+ Y.Assert.areEqual(JsonFormatter.stringify(this.data.cipherParams), this.data.cipherParams.toString(JsonFormatter));
57
+ }
58
+ }));
59
+ }, '$Rev$');
@@ -0,0 +1,25 @@
1
+ YUI.add('lib-passwordbasedcipher-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'PasswordBasedCipher',
6
+
7
+ testEncrypt: function () {
8
+ // Compute actual
9
+ var actual = C.lib.PasswordBasedCipher.encrypt(C.algo.AES, 'Hello, World!', 'password');
10
+
11
+ // Compute expected
12
+ var aes = C.algo.AES.createEncryptor(actual.key, { iv: actual.iv });
13
+ var expected = aes.finalize('Hello, World!');
14
+
15
+ Y.Assert.areEqual(expected.toString(), actual.ciphertext.toString());
16
+ },
17
+
18
+ testDecrypt: function () {
19
+ var ciphertext = C.lib.PasswordBasedCipher.encrypt(C.algo.AES, 'Hello, World!', 'password');
20
+ var plaintext = C.lib.PasswordBasedCipher.decrypt(C.algo.AES, ciphertext, 'password');
21
+
22
+ Y.Assert.areEqual('Hello, World!', plaintext.toString(C.enc.Utf8));
23
+ }
24
+ }));
25
+ }, '$Rev$');
@@ -0,0 +1,51 @@
1
+ YUI.add('lib-serializablecipher-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'SerializableCipher',
6
+
7
+ setUp: function () {
8
+ this.data = {};
9
+
10
+ this.data.message = C.lib.WordArray.create([0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f]);
11
+ this.data.key = C.lib.WordArray.create([0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f]);
12
+ this.data.iv = C.lib.WordArray.create([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]);
13
+ },
14
+
15
+ testEncrypt: function () {
16
+ // Compute expected
17
+ var aes = C.algo.AES.createEncryptor(this.data.key, { iv: this.data.iv });
18
+ var ciphertext = aes.finalize(this.data.message);
19
+ var expected = C.lib.CipherParams.create({
20
+ ciphertext: ciphertext,
21
+ key: this.data.key,
22
+ iv: this.data.iv,
23
+ algorithm: C.algo.AES,
24
+ mode: aes.cfg.mode,
25
+ padding: aes.cfg.padding,
26
+ blockSize: aes.blockSize,
27
+ formatter: C.format.OpenSSL
28
+ });
29
+
30
+ // Compute actual
31
+ var actual = C.lib.SerializableCipher.encrypt(C.algo.AES, this.data.message, this.data.key, { iv: this.data.iv });
32
+
33
+ // Test
34
+ Y.Assert.areEqual(expected.toString(), actual.toString());
35
+ Y.Assert.areEqual(expected.ciphertext.toString(), actual.ciphertext.toString());
36
+ Y.Assert.areEqual(expected.key.toString(), actual.key.toString());
37
+ Y.Assert.areEqual(expected.iv.toString(), actual.iv.toString());
38
+ Y.Assert.areEqual(expected.algorithm, actual.algorithm);
39
+ Y.Assert.areEqual(expected.mode, actual.mode);
40
+ Y.Assert.areEqual(expected.padding, actual.padding);
41
+ Y.Assert.areEqual(expected.blockSize, actual.blockSize);
42
+ },
43
+
44
+ testDecrypt: function () {
45
+ var encrypted = C.lib.SerializableCipher.encrypt(C.algo.AES, this.data.message, this.data.key, { iv: this.data.iv }) + '';
46
+ var decrypted = C.lib.SerializableCipher.decrypt(C.algo.AES, encrypted, this.data.key, { iv: this.data.iv });
47
+
48
+ Y.Assert.areEqual(this.data.message.toString(), decrypted.toString());
49
+ }
50
+ }));
51
+ }, '$Rev$');
@@ -0,0 +1,57 @@
1
+ YUI.add('lib-wordarray-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ if (typeof ArrayBuffer != 'undefined') {
5
+ Y.Test.Runner.add(new Y.Test.Case({
6
+ name: 'TypedArrays',
7
+
8
+ setUp: function () {
9
+ this.data = {};
10
+
11
+ this.data.buffer = new ArrayBuffer(8);
12
+
13
+ var uint8View = new Uint8Array(this.data.buffer);
14
+ uint8View[0] = 0x01;
15
+ uint8View[1] = 0x23;
16
+ uint8View[2] = 0x45;
17
+ uint8View[3] = 0x67;
18
+ uint8View[4] = 0x89;
19
+ uint8View[5] = 0xab;
20
+ uint8View[6] = 0xcd;
21
+ uint8View[7] = 0xef;
22
+ },
23
+
24
+ testInt8Array: function () {
25
+ Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Int8Array(this.data.buffer)).toString());
26
+ },
27
+
28
+ testUint8Array: function () {
29
+ Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Uint8Array(this.data.buffer)).toString());
30
+ },
31
+
32
+ testUint8ClampedArray: function () {
33
+ Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Uint8ClampedArray(this.data.buffer)).toString());
34
+ },
35
+
36
+ testInt16Array: function () {
37
+ Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Int16Array(this.data.buffer)).toString());
38
+ },
39
+
40
+ testUint16Array: function () {
41
+ Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Uint16Array(this.data.buffer)).toString());
42
+ },
43
+
44
+ testInt32Array: function () {
45
+ Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Int32Array(this.data.buffer)).toString());
46
+ },
47
+
48
+ testUint32Array: function () {
49
+ Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Uint32Array(this.data.buffer)).toString());
50
+ },
51
+
52
+ testPartialView: function () {
53
+ Y.Assert.areEqual('456789ab', C.lib.WordArray.create(new Int16Array(this.data.buffer, 2, 2)).toString());
54
+ }
55
+ }));
56
+ }
57
+ }, '$Rev$');
@@ -0,0 +1,85 @@
1
+ YUI.add('lib-wordarray-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'WordArray',
6
+
7
+ testInit0: function () {
8
+ Y.Assert.areEqual('', C.lib.WordArray.create().toString());
9
+ },
10
+
11
+ testInit1: function () {
12
+ Y.Assert.areEqual('12345678', C.lib.WordArray.create([0x12345678]).toString());
13
+ },
14
+
15
+ testInit2: function () {
16
+ Y.Assert.areEqual('1234', C.lib.WordArray.create([0x12345678], 2).toString());
17
+ },
18
+
19
+ testToStringPassedEncoder: function () {
20
+ Y.Assert.areEqual('\x12\x34\x56\x78', C.lib.WordArray.create([0x12345678]).toString(C.enc.Latin1));
21
+ },
22
+
23
+ testToStringDefaultEncoder: function () {
24
+ Y.Assert.areEqual('12345678', C.lib.WordArray.create([0x12345678]).toString());
25
+ },
26
+
27
+ testConcat3: function () {
28
+ var wordArray1 = C.lib.WordArray.create([0x12345678], 3);
29
+ var wordArray2 = C.lib.WordArray.create([0x12345678], 3);
30
+
31
+ Y.Assert.areEqual('123456123456', wordArray1.concat(wordArray2).toString());
32
+ Y.Assert.areEqual('123456123456', wordArray1.toString());
33
+ },
34
+
35
+ testConcat4: function () {
36
+ var wordArray1 = C.lib.WordArray.create([0x12345678], 4);
37
+ var wordArray2 = C.lib.WordArray.create([0x12345678], 3);
38
+
39
+ Y.Assert.areEqual('12345678123456', wordArray1.concat(wordArray2).toString());
40
+ Y.Assert.areEqual('12345678123456', wordArray1.toString());
41
+ },
42
+
43
+ testConcat5: function () {
44
+ var wordArray1 = C.lib.WordArray.create([0x12345678], 5);
45
+ var wordArray2 = C.lib.WordArray.create([0x12345678], 3);
46
+
47
+ Y.Assert.areEqual('1234567800123456', wordArray1.concat(wordArray2).toString());
48
+ Y.Assert.areEqual('1234567800123456', wordArray1.toString());
49
+ },
50
+
51
+ testConcatLong: function () {
52
+ var wordArray1 = C.lib.WordArray.create();
53
+
54
+ var wordArray2 = C.lib.WordArray.create();
55
+ var wordArray3 = C.lib.WordArray.create();
56
+ for (var i = 0; i < 500000; i++) {
57
+ wordArray2.words[i] = i;
58
+ wordArray3.words[i] = i;
59
+ }
60
+ wordArray2.sigBytes = wordArray3.sigBytes = 500000;
61
+
62
+ Y.Assert.areEqual(wordArray2.toString() + wordArray3.toString(), wordArray1.concat(wordArray2.concat(wordArray3)).toString());
63
+ },
64
+
65
+ testClamp: function () {
66
+ var wordArray = C.lib.WordArray.create([0x12345678, 0x12345678], 3);
67
+ wordArray.clamp();
68
+
69
+ Y.Assert.areEqual([0x12345600].toString(), wordArray.words.toString());
70
+ },
71
+
72
+ testClone: function () {
73
+ var wordArray = C.lib.WordArray.create([0x12345678]);
74
+ var clone = wordArray.clone();
75
+ clone.words[0] = 0;
76
+
77
+ Y.Assert.areNotEqual(wordArray.toString(), clone.toString());
78
+ },
79
+
80
+ testRandom: function () {
81
+ Y.Assert.areNotEqual(C.lib.WordArray.random(8).toString(), C.lib.WordArray.random(8).toString());
82
+ Y.Assert.areEqual(8, C.lib.WordArray.random(8).sigBytes);
83
+ }
84
+ }));
85
+ }, '$Rev$');
@@ -0,0 +1,24 @@
1
+ YUI.add('algo-md5-profile', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Profiler.add({
5
+ name: 'MD5',
6
+
7
+ profileSinglePartMessage: function () {
8
+ var singlePartMessage = '';
9
+ for (var i = 0; i < 500; i++) {
10
+ singlePartMessage += '12345678901234567890123456789012345678901234567890';
11
+ }
12
+
13
+ C.algo.MD5.create().finalize(singlePartMessage) + '';
14
+ },
15
+
16
+ profileMultiPartMessage: function () {
17
+ var md5 = C.algo.MD5.create();
18
+ for (var i = 0; i < 500; i++) {
19
+ md5.update('12345678901234567890123456789012345678901234567890');
20
+ }
21
+ md5.finalize() + '';
22
+ }
23
+ });
24
+ }, '$Rev$');
@@ -0,0 +1,70 @@
1
+ YUI.add('algo-md5-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'MD5',
6
+
7
+ testVector1: function () {
8
+ Y.Assert.areEqual('d41d8cd98f00b204e9800998ecf8427e', C.MD5('').toString());
9
+ },
10
+
11
+ testVector2: function () {
12
+ Y.Assert.areEqual('0cc175b9c0f1b6a831c399e269772661', C.MD5('a').toString());
13
+ },
14
+
15
+ testVector3: function () {
16
+ Y.Assert.areEqual('900150983cd24fb0d6963f7d28e17f72', C.MD5('abc').toString());
17
+ },
18
+
19
+ testVector4: function () {
20
+ Y.Assert.areEqual('f96b697d7cb7938d525a2f31aaf161d0', C.MD5('message digest').toString());
21
+ },
22
+
23
+ testVector5: function () {
24
+ Y.Assert.areEqual('c3fcd3d76192e4007dfb496cca67e13b', C.MD5('abcdefghijklmnopqrstuvwxyz').toString());
25
+ },
26
+
27
+ testVector6: function () {
28
+ Y.Assert.areEqual('d174ab98d277d9f5a5611c2c9f419d9f', C.MD5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789').toString());
29
+ },
30
+
31
+ testVector7: function () {
32
+ Y.Assert.areEqual('57edf4a22be3c955ac49da2e2107b67a', C.MD5('12345678901234567890123456789012345678901234567890123456789012345678901234567890').toString());
33
+ },
34
+
35
+ testUpdateAndLongMessage: function () {
36
+ var md5 = C.algo.MD5.create();
37
+ for (var i = 0; i < 100; i++) {
38
+ md5.update('12345678901234567890123456789012345678901234567890');
39
+ }
40
+
41
+ Y.Assert.areEqual('7d017545e0268a6a12f2b507871d0429', md5.finalize().toString());
42
+ },
43
+
44
+ testClone: function () {
45
+ var md5 = C.algo.MD5.create();
46
+
47
+ Y.Assert.areEqual(C.MD5('a').toString(), md5.update('a').clone().finalize().toString());
48
+ Y.Assert.areEqual(C.MD5('ab').toString(), md5.update('b').clone().finalize().toString());
49
+ Y.Assert.areEqual(C.MD5('abc').toString(), md5.update('c').clone().finalize().toString());
50
+ },
51
+
52
+ testInputIntegrity: function () {
53
+ var message = C.lib.WordArray.create([0x12345678]);
54
+
55
+ var expected = message.toString();
56
+
57
+ C.MD5(message);
58
+
59
+ Y.Assert.areEqual(expected, message.toString());
60
+ },
61
+
62
+ testHelper: function () {
63
+ Y.Assert.areEqual(C.algo.MD5.create().finalize('').toString(), C.MD5('').toString());
64
+ },
65
+
66
+ testHmacHelper: function () {
67
+ Y.Assert.areEqual(C.algo.HMAC.create(C.algo.MD5, C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).finalize('Hi There').toString(), C.HmacMD5('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString());
68
+ }
69
+ }));
70
+ }, '$Rev$');
@@ -0,0 +1,49 @@
1
+ YUI.add('mode-cbc-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'CBC',
6
+
7
+ setUp: function () {
8
+ this.data = {};
9
+
10
+ this.data.message = C.lib.WordArray.create([
11
+ 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
12
+ 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f
13
+ ]);
14
+ this.data.key = C.lib.WordArray.create([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]);
15
+ this.data.iv = C.lib.WordArray.create([0x30313233, 0x34353637, 0x38393a3b, 0x3c3d3e3f]);
16
+ },
17
+
18
+ testEncryptor: function () {
19
+ // Compute expected
20
+ var expected = this.data.message.clone();
21
+ var aes = C.algo.AES.createEncryptor(this.data.key);
22
+
23
+ // First block XORed with IV, then encrypted
24
+ for (var i = 0; i < 4; i++) {
25
+ expected.words[i] ^= this.data.iv.words[i];
26
+ }
27
+ aes.encryptBlock(expected.words, 0);
28
+
29
+ // Subsequent blocks XORed with previous crypted block, then encrypted
30
+ for (var i = 4; i < 8; i++) {
31
+ expected.words[i] ^= expected.words[i - 4];
32
+ }
33
+ aes.encryptBlock(expected.words, 4);
34
+
35
+ // Compute actual
36
+ var actual = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CBC, padding: C.pad.NoPadding }).ciphertext;
37
+
38
+ // Test
39
+ Y.Assert.areEqual(expected.toString(), actual.toString());
40
+ },
41
+
42
+ testDecryptor: function () {
43
+ var encrypted = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CBC, padding: C.pad.NoPadding });
44
+ var decrypted = C.AES.decrypt(encrypted, this.data.key, { iv: this.data.iv, mode: C.mode.CBC, padding: C.pad.NoPadding });
45
+
46
+ Y.Assert.areEqual(this.data.message.toString(), decrypted.toString());
47
+ }
48
+ }));
49
+ }, '$Rev$');
@@ -0,0 +1,51 @@
1
+ YUI.add('mode-cfb-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'CFB',
6
+
7
+ setUp: function () {
8
+ this.data = {};
9
+
10
+ this.data.message = C.lib.WordArray.create([
11
+ 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
12
+ 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f
13
+ ]);
14
+ this.data.key = C.lib.WordArray.create([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]);
15
+ this.data.iv = C.lib.WordArray.create([0x30313233, 0x34353637, 0x38393a3b, 0x3c3d3e3f]);
16
+ },
17
+
18
+ testEncryptor: function () {
19
+ // Compute expected
20
+ var expected = this.data.message.clone();
21
+ var aes = C.algo.AES.createEncryptor(this.data.key);
22
+
23
+ // First block XORed with encrypted IV
24
+ var keystream = this.data.iv.words.slice(0);
25
+ aes.encryptBlock(keystream, 0);
26
+ for (var i = 0; i < 4; i++) {
27
+ expected.words[i] ^= keystream[i];
28
+ }
29
+
30
+ // Subsequent blocks XORed with encrypted previous crypted block
31
+ var keystream = expected.words.slice(0, 4);
32
+ aes.encryptBlock(keystream, 0);
33
+ for (var i = 4; i < 8; i++) {
34
+ expected.words[i] ^= keystream[i % 4];
35
+ }
36
+
37
+ // Compute actual
38
+ var actual = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CFB, padding: C.pad.NoPadding }).ciphertext;
39
+
40
+ // Test
41
+ Y.Assert.areEqual(expected.toString(), actual.toString());
42
+ },
43
+
44
+ testDecryptor: function () {
45
+ var encrypted = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CFB, padding: C.pad.NoPadding });
46
+ var decrypted = C.AES.decrypt(encrypted, this.data.key, { iv: this.data.iv, mode: C.mode.CFB, padding: C.pad.NoPadding });
47
+
48
+ Y.Assert.areEqual(this.data.message.toString(), decrypted.toString());
49
+ }
50
+ }));
51
+ }, '$Rev$');