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

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 (109) 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/aes.js +214 -0
  7. package/blowfish.js +451 -0
  8. package/cipher-core.js +877 -0
  9. package/core.js +796 -0
  10. package/docs/QuickStartGuide.wiki +470 -0
  11. package/enc-base64.js +116 -0
  12. package/enc-base64url.js +128 -0
  13. package/enc-utf16.js +129 -0
  14. package/evpkdf.js +114 -0
  15. package/format-hex.js +46 -0
  16. package/hmac.js +125 -0
  17. package/index.js +18 -0
  18. package/lib-typedarrays.js +56 -0
  19. package/md5.js +248 -0
  20. package/mode-cfb.js +60 -0
  21. package/mode-ctr-gladman.js +96 -0
  22. package/mode-ctr.js +38 -0
  23. package/mode-ecb.js +20 -0
  24. package/mode-ofb.js +34 -0
  25. package/package.json +45 -3
  26. package/pad-ansix923.js +29 -0
  27. package/pad-iso10126.js +24 -0
  28. package/pad-iso97971.js +20 -0
  29. package/pad-nopadding.js +10 -0
  30. package/pad-zeropadding.js +27 -0
  31. package/pbkdf2.js +125 -0
  32. package/rabbit-legacy.js +170 -0
  33. package/rabbit.js +172 -0
  34. package/rc4.js +119 -0
  35. package/ripemd160.js +247 -0
  36. package/sha1.js +130 -0
  37. package/sha224.js +60 -0
  38. package/sha256.js +179 -0
  39. package/sha3.js +306 -0
  40. package/sha384.js +63 -0
  41. package/sha512.js +306 -0
  42. package/test/aes-profile.js +31 -0
  43. package/test/aes-test.js +80 -0
  44. package/test/blowfish-test.js +33 -0
  45. package/test/cipher-test.js +522 -0
  46. package/test/config-test.js +51 -0
  47. package/test/des-profile.js +31 -0
  48. package/test/des-test.js +104 -0
  49. package/test/enc-base64-test.js +71 -0
  50. package/test/enc-hex-test.js +15 -0
  51. package/test/enc-latin1-test.js +15 -0
  52. package/test/enc-utf16-test.js +55 -0
  53. package/test/enc-utf8-test.js +39 -0
  54. package/test/evpkdf-profile.js +11 -0
  55. package/test/evpkdf-test.js +32 -0
  56. package/test/format-openssl-test.js +37 -0
  57. package/test/hmac-md5-profile.js +30 -0
  58. package/test/hmac-md5-test.js +59 -0
  59. package/test/hmac-sha224-test.js +59 -0
  60. package/test/hmac-sha256-test.js +59 -0
  61. package/test/hmac-sha384-test.js +59 -0
  62. package/test/hmac-sha512-test.js +59 -0
  63. package/test/kdf-openssl-test.js +15 -0
  64. package/test/lib-base-test.js +92 -0
  65. package/test/lib-cipherparams-test.js +59 -0
  66. package/test/lib-passwordbasedcipher-test.js +25 -0
  67. package/test/lib-serializablecipher-test.js +51 -0
  68. package/test/lib-typedarrays-test.js +57 -0
  69. package/test/lib-wordarray-test.js +85 -0
  70. package/test/md5-profile.js +24 -0
  71. package/test/md5-test.js +70 -0
  72. package/test/mode-cbc-test.js +49 -0
  73. package/test/mode-cfb-test.js +51 -0
  74. package/test/mode-ctr-test.js +55 -0
  75. package/test/mode-ecb-test.js +38 -0
  76. package/test/mode-ofb-test.js +50 -0
  77. package/test/pad-ansix923-test.js +28 -0
  78. package/test/pad-iso10126-test.js +50 -0
  79. package/test/pad-iso97971-test.js +35 -0
  80. package/test/pad-pkcs7-test.js +28 -0
  81. package/test/pad-zeropadding-test.js +28 -0
  82. package/test/pbkdf2-profile.js +11 -0
  83. package/test/pbkdf2-test.js +80 -0
  84. package/test/profile.html +281 -0
  85. package/test/rabbit-legacy-test.js +80 -0
  86. package/test/rabbit-profile.js +30 -0
  87. package/test/rabbit-test.js +84 -0
  88. package/test/rc4-profile.js +30 -0
  89. package/test/rc4-test.js +68 -0
  90. package/test/ripemd160-test.js +19 -0
  91. package/test/sha1-profile.js +24 -0
  92. package/test/sha1-test.js +70 -0
  93. package/test/sha224-test.js +19 -0
  94. package/test/sha256-profile.js +24 -0
  95. package/test/sha256-test.js +70 -0
  96. package/test/sha3-profile.js +24 -0
  97. package/test/sha3-test.js +69 -0
  98. package/test/sha384-test.js +54 -0
  99. package/test/sha512-profile.js +24 -0
  100. package/test/sha512-test.js +54 -0
  101. package/test/test-build.html +105 -0
  102. package/test/test.html +138 -0
  103. package/test/test1.html +63 -0
  104. package/test/tripledes-profile.js +31 -0
  105. package/test/tripledes-test.js +121 -0
  106. package/test/x64-word-test.js +99 -0
  107. package/test/x64-wordarray-test.js +38 -0
  108. package/tripledes.js +759 -0
  109. package/x64-core.js +284 -0
@@ -0,0 +1,51 @@
1
+ YUI.add('config-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'Config',
6
+
7
+ setUp: function () {
8
+ this.data = {
9
+ saltA: CryptoJS.enc.Hex.parse('AA00000000000000'),
10
+ saltB: CryptoJS.enc.Hex.parse('BB00000000000000')
11
+ };
12
+ },
13
+
14
+ testEncrypt: function () {
15
+ Y.Assert.areEqual(C.AES.encrypt('Test', 'Pass', { salt: this.data.saltA }).toString(), C.AES.encrypt('Test', 'Pass', { salt: this.data.saltA }).toString());
16
+ Y.Assert.areNotEqual(C.AES.encrypt('Test', 'Pass', { salt: this.data.saltA }).toString(), C.AES.encrypt('Test', 'Pass', { salt: this.data.saltB }).toString());
17
+ },
18
+
19
+ testDecrypt: function () {
20
+ var encryptedA = C.AES.encrypt('Test', 'Pass', { salt: this.data.saltA });
21
+ var encryptedB = C.AES.encrypt('Test', 'Pass', { salt: this.data.saltB });
22
+ Y.Assert.areEqual('Test', C.AES.decrypt(encryptedA, 'Pass').toString(C.enc.Utf8));
23
+ Y.Assert.areEqual('Test', C.AES.decrypt(encryptedB, 'Pass').toString(C.enc.Utf8));
24
+ },
25
+
26
+ testCustomKDFHasher: function () {
27
+ //SHA1
28
+ let encryptedSHA1 = C.AES.encrypt('Test', 'Pass', { salt: this.data.saltA, hasher: C.algo.SHA1}).toString();
29
+ Y.Assert.areEqual('Test', C.AES.decrypt(encryptedSHA1, 'Pass', { hasher: C.algo.SHA1}).toString(C.enc.Utf8));
30
+
31
+ //SHA256
32
+ let encryptedSHA256 = C.AES.encrypt('Test', 'Pass', { salt: this.data.saltA, hasher: C.algo.SHA256}).toString();
33
+ Y.Assert.areEqual('Test', C.AES.decrypt(encryptedSHA256, 'Pass', { hasher: C.algo.SHA256}).toString(C.enc.Utf8));
34
+
35
+ //SHA512
36
+ let encryptedSHA512 = C.AES.encrypt('Test', 'Pass', { salt: this.data.saltA, hasher: C.algo.SHA512}).toString();
37
+ Y.Assert.areEqual('Test', C.AES.decrypt(encryptedSHA512, 'Pass', { hasher: C.algo.SHA512}).toString(C.enc.Utf8));
38
+
39
+ //Default: MD5
40
+ let encryptedDefault = C.AES.encrypt('Test', 'Pass', { salt: this.data.saltA }).toString();
41
+ let encryptedMD5 = C.AES.encrypt('Test', 'Pass', { salt: this.data.saltA, hasher: C.algo.MD5}).toString();
42
+ Y.Assert.areEqual('Test', C.AES.decrypt(encryptedMD5, 'Pass', { hasher: C.algo.MD5}).toString(C.enc.Utf8));
43
+ Y.Assert.areEqual(encryptedDefault, encryptedMD5);
44
+
45
+ //Different KDFHasher
46
+ Y.Assert.areNotEqual(encryptedDefault, encryptedSHA1);
47
+ Y.Assert.areNotEqual(encryptedDefault, encryptedSHA256);
48
+ Y.Assert.areNotEqual(encryptedDefault, encryptedSHA512);
49
+ }
50
+ }));
51
+ }, '$Rev$');
@@ -0,0 +1,31 @@
1
+ YUI.add('algo-des-profile', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Profiler.add({
5
+ name: 'DES',
6
+
7
+ setUp: function () {
8
+ this.data = {
9
+ key: C.enc.Hex.parse('0001020304050607'),
10
+ iv: C.enc.Hex.parse('08090a0b0c0d0e0f')
11
+ };
12
+ },
13
+
14
+ profileSinglePartMessage: function () {
15
+ var singlePartMessage = '';
16
+ for (var i = 0; i < 100; i++) {
17
+ singlePartMessage += '12345678901234567890123456789012345678901234567890';
18
+ }
19
+
20
+ C.algo.DES.createEncryptor(this.data.key, { iv: this.data.iv }).finalize(singlePartMessage) + '';
21
+ },
22
+
23
+ profileMultiPartMessage: function () {
24
+ var des = C.algo.DES.createEncryptor(this.data.key, { iv: this.data.iv });
25
+ for (var i = 0; i < 100; i++) {
26
+ des.process('12345678901234567890123456789012345678901234567890') + '';
27
+ }
28
+ des.finalize() + '';
29
+ }
30
+ });
31
+ }, '$Rev$');
@@ -0,0 +1,104 @@
1
+ YUI.add('algo-des-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'DES',
6
+
7
+ testEncrypt1: function () {
8
+ Y.Assert.areEqual('95a8d72813daa94d', C.DES.encrypt(C.enc.Hex.parse('0000000000000000'), C.enc.Hex.parse('8000000000000000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
9
+ },
10
+
11
+ testEncrypt2: function () {
12
+ Y.Assert.areEqual('1de5279dae3bed6f', C.DES.encrypt(C.enc.Hex.parse('0000000000000000'), C.enc.Hex.parse('0000000000002000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
13
+ },
14
+
15
+ testEncrypt3: function () {
16
+ Y.Assert.areEqual('1d1ca853ae7c0c5f', C.DES.encrypt(C.enc.Hex.parse('0000000000002000'), C.enc.Hex.parse('0000000000000000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
17
+ },
18
+
19
+ testEncrypt4: function () {
20
+ Y.Assert.areEqual('ac978c247863388f', C.DES.encrypt(C.enc.Hex.parse('3232323232323232'), C.enc.Hex.parse('3232323232323232'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
21
+ },
22
+
23
+ testEncrypt5: function () {
24
+ Y.Assert.areEqual('3af1703d76442789', C.DES.encrypt(C.enc.Hex.parse('6464646464646464'), C.enc.Hex.parse('6464646464646464'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
25
+ },
26
+
27
+ testEncrypt6: function () {
28
+ Y.Assert.areEqual('a020003c5554f34c', C.DES.encrypt(C.enc.Hex.parse('9696969696969696'), C.enc.Hex.parse('9696969696969696'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
29
+ },
30
+
31
+ testDecrypt1: function () {
32
+ Y.Assert.areEqual('0000000000000000', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('95a8d72813daa94d') }), C.enc.Hex.parse('8000000000000000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
33
+ },
34
+
35
+ testDecrypt2: function () {
36
+ Y.Assert.areEqual('0000000000000000', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('1de5279dae3bed6f') }), C.enc.Hex.parse('0000000000002000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
37
+ },
38
+
39
+ testDecrypt3: function () {
40
+ Y.Assert.areEqual('0000000000002000', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('1d1ca853ae7c0c5f') }), C.enc.Hex.parse('0000000000000000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
41
+ },
42
+
43
+ testDecrypt4: function () {
44
+ Y.Assert.areEqual('3232323232323232', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('ac978c247863388f') }), C.enc.Hex.parse('3232323232323232'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
45
+ },
46
+
47
+ testDecrypt5: function () {
48
+ Y.Assert.areEqual('6464646464646464', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('3af1703d76442789') }), C.enc.Hex.parse('6464646464646464'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
49
+ },
50
+
51
+ testDecrypt6: function () {
52
+ Y.Assert.areEqual('9696969696969696', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('a020003c5554f34c') }), C.enc.Hex.parse('9696969696969696'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
53
+ },
54
+
55
+ testMultiPart: function () {
56
+ var des = C.algo.DES.createEncryptor(C.enc.Hex.parse('0123456789abcdef'), { mode: C.mode.ECB, padding: C.pad.NoPadding });
57
+ var ciphertext1 = des.process(C.enc.Hex.parse('001122334455'));
58
+ var ciphertext2 = des.process(C.enc.Hex.parse('66778899aa'));
59
+ var ciphertext3 = des.process(C.enc.Hex.parse('bbccddeeff'));
60
+ var ciphertext4 = des.finalize();
61
+
62
+ Y.Assert.areEqual(C.DES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('0123456789abcdef'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString(), ciphertext1.concat(ciphertext2).concat(ciphertext3).concat(ciphertext4).toString());
63
+ },
64
+
65
+ testInputIntegrity: function () {
66
+ var message = C.enc.Hex.parse('00112233445566778899aabbccddeeff');
67
+ var key = C.enc.Hex.parse('0001020304050607');
68
+ var iv = C.enc.Hex.parse('08090a0b0c0d0e0f');
69
+
70
+ var expectedMessage = message.toString();
71
+ var expectedKey = key.toString();
72
+ var expectedIv = iv.toString();
73
+
74
+ C.DES.encrypt(message, key, { iv: iv });
75
+
76
+ Y.Assert.areEqual(expectedMessage, message.toString());
77
+ Y.Assert.areEqual(expectedKey, key.toString());
78
+ Y.Assert.areEqual(expectedIv, iv.toString());
79
+ },
80
+
81
+ testHelper: function () {
82
+ // Save original random method
83
+ var random = C.lib.WordArray.random;
84
+
85
+ // Replace random method with one that returns a predictable value
86
+ C.lib.WordArray.random = function (nBytes) {
87
+ var words = [];
88
+ for (var i = 0; i < nBytes; i += 4) {
89
+ words.push([0x11223344]);
90
+ }
91
+
92
+ return C.lib.WordArray.create(words, nBytes);
93
+ };
94
+
95
+ // Test
96
+ Y.Assert.areEqual(C.algo.DES.createEncryptor(C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).finalize('Hi There').toString(), C.DES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString());
97
+ Y.Assert.areEqual(C.lib.SerializableCipher.encrypt(C.algo.DES, 'Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.DES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
98
+ Y.Assert.areEqual(C.lib.PasswordBasedCipher.encrypt(C.algo.DES, 'Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.DES.encrypt('Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString());
99
+
100
+ // Restore random method
101
+ C.lib.WordArray.random = random;
102
+ }
103
+ }));
104
+ }, '$Rev$');
@@ -0,0 +1,71 @@
1
+ YUI.add('enc-base64-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'Base64',
6
+
7
+ testStringify0: function () {
8
+ Y.Assert.areEqual('', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 0)));
9
+ },
10
+
11
+ testStringify1: function () {
12
+ Y.Assert.areEqual('Zg==', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 1)));
13
+ },
14
+
15
+ testStringify2: function () {
16
+ Y.Assert.areEqual('Zm8=', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 2)));
17
+ },
18
+
19
+ testStringify3: function () {
20
+ Y.Assert.areEqual('Zm9v', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 3)));
21
+ },
22
+
23
+ testStringify4: function () {
24
+ Y.Assert.areEqual('Zm9vYg==', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 4)));
25
+ },
26
+
27
+ testStringify5: function () {
28
+ Y.Assert.areEqual('Zm9vYmE=', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 5)));
29
+ },
30
+
31
+ testStringify6: function () {
32
+ Y.Assert.areEqual('Zm9vYmFy', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 6)));
33
+ },
34
+
35
+ testStringify15: function () {
36
+ Y.Assert.areEqual('Pj4+Pz8/Pj4+Pz8/PS8r', C.enc.Base64.stringify(C.lib.WordArray.create([0x3e3e3e3f, 0x3f3f3e3e, 0x3e3f3f3f, 0x3d2f2b00], 15)));
37
+ },
38
+
39
+ testParse0: function () {
40
+ Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 0).toString(), C.enc.Base64.parse('').toString());
41
+ },
42
+
43
+ testParse1: function () {
44
+ Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 1).toString(), C.enc.Base64.parse('Zg==').toString());
45
+ },
46
+
47
+ testParse2: function () {
48
+ Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 2).toString(), C.enc.Base64.parse('Zm8=').toString());
49
+ },
50
+
51
+ testParse3: function () {
52
+ Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 3).toString(), C.enc.Base64.parse('Zm9v').toString());
53
+ },
54
+
55
+ testParse4: function () {
56
+ Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 4).toString(), C.enc.Base64.parse('Zm9vYg==').toString());
57
+ },
58
+
59
+ testParse5: function () {
60
+ Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 5).toString(), C.enc.Base64.parse('Zm9vYmE=').toString());
61
+ },
62
+
63
+ testParse6: function () {
64
+ Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 6).toString(), C.enc.Base64.parse('Zm9vYmFy').toString());
65
+ },
66
+
67
+ testParse15: function () {
68
+ Y.Assert.areEqual(C.lib.WordArray.create([0x3e3e3e3f, 0x3f3f3e3e, 0x3e3f3f3f, 0x3d2f2b00], 15).toString(), C.enc.Base64.parse('Pj4+Pz8/Pj4+Pz8/PS8r').toString());
69
+ }
70
+ }));
71
+ }, '$Rev$');
@@ -0,0 +1,15 @@
1
+ YUI.add('enc-hex-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'Hex',
6
+
7
+ testStringify: function () {
8
+ Y.Assert.areEqual('12345678', C.enc.Hex.stringify(C.lib.WordArray.create([0x12345678])));
9
+ },
10
+
11
+ testParse: function () {
12
+ Y.Assert.areEqual(C.lib.WordArray.create([0x12345678]).toString(), C.enc.Hex.parse('12345678').toString());
13
+ }
14
+ }));
15
+ }, '$Rev$');
@@ -0,0 +1,15 @@
1
+ YUI.add('enc-latin1-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'Latin1',
6
+
7
+ testStringify: function () {
8
+ Y.Assert.areEqual('\x12\x34\x56\x78', C.enc.Latin1.stringify(C.lib.WordArray.create([0x12345678])));
9
+ },
10
+
11
+ testParse: function () {
12
+ Y.Assert.areEqual(C.lib.WordArray.create([0x12345678]).toString(), C.enc.Latin1.parse('\x12\x34\x56\x78').toString());
13
+ }
14
+ }));
15
+ }, '$Rev$');
@@ -0,0 +1,55 @@
1
+ YUI.add('enc-utf16-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'Utf16',
6
+
7
+ testStringify1: function () {
8
+ Y.Assert.areEqual('z', C.enc.Utf16.stringify(C.lib.WordArray.create([0x007a0000], 2)));
9
+ },
10
+
11
+ testStringify2: function () {
12
+ Y.Assert.areEqual('水', C.enc.Utf16.stringify(C.lib.WordArray.create([0x6c340000], 2)));
13
+ },
14
+
15
+ testStringify3: function () {
16
+ Y.Assert.areEqual('𐀀', C.enc.Utf16.stringify(C.lib.WordArray.create([0xd800dc00], 4)));
17
+ },
18
+
19
+ testStringify4: function () {
20
+ Y.Assert.areEqual('𝄞', C.enc.Utf16.stringify(C.lib.WordArray.create([0xd834dd1e], 4)));
21
+ },
22
+
23
+ testStringify5: function () {
24
+ Y.Assert.areEqual('􏿽', C.enc.Utf16.stringify(C.lib.WordArray.create([0xdbffdffd], 4)));
25
+ },
26
+
27
+ testStringifyLE: function () {
28
+ Y.Assert.areEqual('􏿽', C.enc.Utf16LE.stringify(C.lib.WordArray.create([0xffdbfddf], 4)));
29
+ },
30
+
31
+ testParse1: function () {
32
+ Y.Assert.areEqual(C.lib.WordArray.create([0x007a0000], 2).toString(), C.enc.Utf16.parse('z').toString());
33
+ },
34
+
35
+ testParse2: function () {
36
+ Y.Assert.areEqual(C.lib.WordArray.create([0x6c340000], 2).toString(), C.enc.Utf16.parse('水').toString());
37
+ },
38
+
39
+ testParse3: function () {
40
+ Y.Assert.areEqual(C.lib.WordArray.create([0xd800dc00], 4).toString(), C.enc.Utf16.parse('𐀀').toString());
41
+ },
42
+
43
+ testParse4: function () {
44
+ Y.Assert.areEqual(C.lib.WordArray.create([0xd834dd1e], 4).toString(), C.enc.Utf16.parse('𝄞').toString());
45
+ },
46
+
47
+ testParse5: function () {
48
+ Y.Assert.areEqual(C.lib.WordArray.create([0xdbffdffd], 4).toString(), C.enc.Utf16.parse('􏿽').toString());
49
+ },
50
+
51
+ testParseLE: function () {
52
+ Y.Assert.areEqual(C.lib.WordArray.create([0xffdbfddf], 4).toString(), C.enc.Utf16LE.parse('􏿽').toString());
53
+ }
54
+ }));
55
+ }, '$Rev$');
@@ -0,0 +1,39 @@
1
+ YUI.add('enc-utf8-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'Utf8',
6
+
7
+ testStringify1: function () {
8
+ Y.Assert.areEqual('$', C.enc.Utf8.stringify(C.lib.WordArray.create([0x24000000], 1)));
9
+ },
10
+
11
+ testStringify2: function () {
12
+ Y.Assert.areEqual('¢', C.enc.Utf8.stringify(C.lib.WordArray.create([0xc2a20000], 2)));
13
+ },
14
+
15
+ testStringify3: function () {
16
+ Y.Assert.areEqual('€', C.enc.Utf8.stringify(C.lib.WordArray.create([0xe282ac00], 3)));
17
+ },
18
+
19
+ testStringify4: function () {
20
+ Y.Assert.areEqual('𤭢', C.enc.Utf8.stringify(C.lib.WordArray.create([0xf0a4ada2], 4)));
21
+ },
22
+
23
+ testParse1: function () {
24
+ Y.Assert.areEqual(C.lib.WordArray.create([0x24000000], 1).toString(), C.enc.Utf8.parse('$').toString());
25
+ },
26
+
27
+ testParse2: function () {
28
+ Y.Assert.areEqual(C.lib.WordArray.create([0xc2a20000], 2).toString(), C.enc.Utf8.parse('¢').toString());
29
+ },
30
+
31
+ testParse3: function () {
32
+ Y.Assert.areEqual(C.lib.WordArray.create([0xe282ac00], 3).toString(), C.enc.Utf8.parse('€').toString());
33
+ },
34
+
35
+ testParse4: function () {
36
+ Y.Assert.areEqual(C.lib.WordArray.create([0xf0a4ada2], 4).toString(), C.enc.Utf8.parse('𤭢').toString());
37
+ }
38
+ }));
39
+ }, '$Rev$');
@@ -0,0 +1,11 @@
1
+ YUI.add('algo-evpkdf-profile', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Profiler.add({
5
+ name: 'EvpKDF',
6
+
7
+ profileKeySize256Iterations20: function () {
8
+ C.algo.EvpKDF.create({ keySize: 256/32, iterations: 20 }).compute('password', 'ATHENA.MIT.EDUraeburn');
9
+ }
10
+ });
11
+ }, '$Rev$');
@@ -0,0 +1,32 @@
1
+ YUI.add('algo-evpkdf-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'EvpKDF',
6
+
7
+ testVector: function () {
8
+ Y.Assert.areEqual('fdbdf3419fff98bdb0241390f62a9db35f4aba29d77566377997314ebfc709f20b5ca7b1081f94b1ac12e3c8ba87d05a', C.EvpKDF('password', 'saltsalt', { keySize: (256+128)/32 }).toString());
9
+ },
10
+
11
+ // There are no official test vectors that I could find, and the EVP implementation is short on comments.
12
+ // Need to use the C code to generate more test vectors.
13
+ // The iteration count in particular needs to be tested.
14
+
15
+ testInputIntegrity: function () {
16
+ var password = C.lib.WordArray.create([0x12345678]);
17
+ var salt = C.lib.WordArray.create([0x12345678]);
18
+
19
+ var expectedPassword = password.toString();
20
+ var expectedSalt = salt.toString();
21
+
22
+ C.EvpKDF(password, salt);
23
+
24
+ Y.Assert.areEqual(expectedPassword, password.toString());
25
+ Y.Assert.areEqual(expectedSalt, salt.toString());
26
+ },
27
+
28
+ testHelper: function () {
29
+ Y.Assert.areEqual(C.algo.EvpKDF.create({ keySize: (256+128)/32 }).compute('password', 'saltsalt').toString(), C.EvpKDF('password', 'saltsalt', { keySize: (256+128)/32 }).toString());
30
+ }
31
+ }));
32
+ }, '$Rev$');
@@ -0,0 +1,37 @@
1
+ YUI.add('format-openssl-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'OpenSSLFormatter',
6
+
7
+ setUp: function () {
8
+ this.data = {};
9
+
10
+ this.data.ciphertext = C.lib.WordArray.create([0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f]);
11
+ this.data.salt = C.lib.WordArray.create([0x01234567, 0x89abcdef]);
12
+ },
13
+
14
+ testSaltedToString: function () {
15
+ Y.Assert.areEqual(C.enc.Latin1.parse('Salted__').concat(this.data.salt).concat(this.data.ciphertext).toString(C.enc.Base64), C.format.OpenSSL.stringify(C.lib.CipherParams.create({ ciphertext: this.data.ciphertext, salt: this.data.salt })));
16
+ },
17
+
18
+ testUnsaltedToString: function () {
19
+ Y.Assert.areEqual(this.data.ciphertext.toString(C.enc.Base64), C.format.OpenSSL.stringify(C.lib.CipherParams.create({ ciphertext: this.data.ciphertext })));
20
+ },
21
+
22
+ testSaltedFromString: function () {
23
+ var openSSLStr = C.format.OpenSSL.stringify(C.lib.CipherParams.create({ ciphertext: this.data.ciphertext, salt: this.data.salt }));
24
+ var cipherParams = C.format.OpenSSL.parse(openSSLStr);
25
+
26
+ Y.Assert.areEqual(this.data.ciphertext.toString(), cipherParams.ciphertext.toString());
27
+ Y.Assert.areEqual(this.data.salt.toString(), cipherParams.salt.toString());
28
+ },
29
+
30
+ testUnsaltedFromString: function () {
31
+ var openSSLStr = C.format.OpenSSL.stringify(C.lib.CipherParams.create({ ciphertext: this.data.ciphertext }));
32
+ var cipherParams = C.format.OpenSSL.parse(openSSLStr);
33
+
34
+ Y.Assert.areEqual(this.data.ciphertext.toString(), cipherParams.ciphertext.toString());
35
+ }
36
+ }));
37
+ }, '$Rev$');
@@ -0,0 +1,30 @@
1
+ YUI.add('algo-hmac-md5-profile', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Profiler.add({
5
+ name: 'HMAC MD5',
6
+
7
+ setUp: function () {
8
+ this.data = {
9
+ key: C.lib.WordArray.random(128/8)
10
+ };
11
+ },
12
+
13
+ profileSinglePartMessage: function () {
14
+ var singlePartMessage = '';
15
+ for (var i = 0; i < 500; i++) {
16
+ singlePartMessage += '12345678901234567890123456789012345678901234567890';
17
+ }
18
+
19
+ C.algo.HMAC.create(C.algo.MD5, this.data.key).finalize(singlePartMessage) + '';
20
+ },
21
+
22
+ profileMultiPartMessage: function () {
23
+ var hmac = C.algo.HMAC.create(C.algo.MD5, this.data.key);
24
+ for (var i = 0; i < 500; i++) {
25
+ hmac.update('12345678901234567890123456789012345678901234567890');
26
+ }
27
+ hmac.finalize() + '';
28
+ }
29
+ });
30
+ }, '$Rev$');
@@ -0,0 +1,59 @@
1
+ YUI.add('algo-hmac-md5-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'HMAC MD5',
6
+
7
+ testVector1: function () {
8
+ Y.Assert.areEqual('9294727a3638bb1c13f48ef8158bfc9d', C.HmacMD5('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString());
9
+ },
10
+
11
+ testVector2: function () {
12
+ Y.Assert.areEqual('750c783e6ab0b503eaa86e310a5db738', C.HmacMD5('what do ya want for nothing?', 'Jefe').toString());
13
+ },
14
+
15
+ testVector3: function () {
16
+ Y.Assert.areEqual('56be34521d144c88dbb8c733f0e8b3f6', C.HmacMD5(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString());
17
+ },
18
+
19
+ testVector4: function () {
20
+ Y.Assert.areEqual('7ee2a3cc979ab19865704644ce13355c', C.HmacMD5('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A').toString());
21
+ },
22
+
23
+ testVector5: function () {
24
+ Y.Assert.areEqual('0e1bd89c43e3e6e3b3f8cf1d5ba4f77a', C.HmacMD5('abcdefghijklmnopqrstuvwxyz', 'A').toString());
25
+ },
26
+
27
+ testUpdate: function () {
28
+ var hmac = C.algo.HMAC.create(C.algo.MD5, 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.HmacMD5(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.HmacMD5(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.HmacSHA256("Message", keyClamped).toString(), CryptoJS.HmacSHA256("Message", key).toString());
57
+ }
58
+ }));
59
+ }, '$Rev$');
@@ -0,0 +1,59 @@
1
+ YUI.add('algo-hmac-sha224-test', function (Y) {
2
+ var C = CryptoJS;
3
+
4
+ Y.Test.Runner.add(new Y.Test.Case({
5
+ name: 'HMAC SHA224',
6
+
7
+ testVector1: function () {
8
+ Y.Assert.areEqual('4e841ce7a4ae83fbcf71e3cd64bfbf277f73a14680aae8c518ac7861', C.HmacSHA224('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString());
9
+ },
10
+
11
+ testVector2: function () {
12
+ Y.Assert.areEqual('a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44', C.HmacSHA224('what do ya want for nothing?', 'Jefe').toString());
13
+ },
14
+
15
+ testVector3: function () {
16
+ Y.Assert.areEqual('cbff7c2716bbaa7c77bed4f491d3e8456cb6c574e92f672b291acf5b', C.HmacSHA224(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString());
17
+ },
18
+
19
+ testVector4: function () {
20
+ Y.Assert.areEqual('61bf669da4fdcd8e5c3bd09ebbb4a986d3d1b298d3ca05c511f7aeff', C.HmacSHA224('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A').toString());
21
+ },
22
+
23
+ testVector5: function () {
24
+ Y.Assert.areEqual('16fc69ada3c3edc1fe9144d6b98d93393833ae442bedf681110a1176', C.HmacSHA224('abcdefghijklmnopqrstuvwxyz', 'A').toString());
25
+ },
26
+
27
+ testUpdate: function () {
28
+ var hmac = C.algo.HMAC.create(C.algo.SHA224, 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.HmacSHA224(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.HmacSHA224(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.HmacSHA224("Message", keyClamped).toString(), CryptoJS.HmacSHA224("Message", key).toString());
57
+ }
58
+ }));
59
+ }, '$Rev$');