@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.
- 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 +214 -0
- package/blowfish.js +451 -0
- package/cipher-core.js +877 -0
- package/core.js +796 -0
- package/docs/QuickStartGuide.wiki +470 -0
- package/enc-base64.js +116 -0
- package/enc-base64url.js +128 -0
- package/enc-utf16.js +129 -0
- package/evpkdf.js +114 -0
- package/format-hex.js +46 -0
- package/hmac.js +125 -0
- package/index.js +18 -0
- package/lib-typedarrays.js +56 -0
- package/md5.js +248 -0
- package/mode-cfb.js +60 -0
- package/mode-ctr-gladman.js +96 -0
- package/mode-ctr.js +38 -0
- package/mode-ecb.js +20 -0
- package/mode-ofb.js +34 -0
- package/package.json +45 -3
- package/pad-ansix923.js +29 -0
- package/pad-iso10126.js +24 -0
- package/pad-iso97971.js +20 -0
- package/pad-nopadding.js +10 -0
- package/pad-zeropadding.js +27 -0
- package/pbkdf2.js +125 -0
- package/rabbit-legacy.js +170 -0
- package/rabbit.js +172 -0
- package/rc4.js +119 -0
- package/ripemd160.js +247 -0
- package/sha1.js +130 -0
- package/sha224.js +60 -0
- package/sha256.js +179 -0
- package/sha3.js +306 -0
- package/sha384.js +63 -0
- package/sha512.js +306 -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 +759 -0
- package/x64-core.js +284 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
YUI.add('algo-hmac-sha256-test', function (Y) {
|
2
|
+
var C = CryptoJS;
|
3
|
+
|
4
|
+
Y.Test.Runner.add(new Y.Test.Case({
|
5
|
+
name: 'HMAC SHA256',
|
6
|
+
|
7
|
+
testVector1: function () {
|
8
|
+
Y.Assert.areEqual('492ce020fe2534a5789dc3848806c78f4f6711397f08e7e7a12ca5a4483c8aa6', C.HmacSHA256('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString());
|
9
|
+
},
|
10
|
+
|
11
|
+
testVector2: function () {
|
12
|
+
Y.Assert.areEqual('5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843', C.HmacSHA256('what do ya want for nothing?', 'Jefe').toString());
|
13
|
+
},
|
14
|
+
|
15
|
+
testVector3: function () {
|
16
|
+
Y.Assert.areEqual('7dda3cc169743a6484649f94f0eda0f9f2ff496a9733fb796ed5adb40a44c3c1', C.HmacSHA256(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString());
|
17
|
+
},
|
18
|
+
|
19
|
+
testVector4: function () {
|
20
|
+
Y.Assert.areEqual('a89dc8178c1184a62df87adaa77bf86e93064863d93c5131140b0ae98b866687', C.HmacSHA256('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A').toString());
|
21
|
+
},
|
22
|
+
|
23
|
+
testVector5: function () {
|
24
|
+
Y.Assert.areEqual('d8cb78419c02fe20b90f8b77427dd9f81817a751d74c2e484e0ac5fc4e6ca986', C.HmacSHA256('abcdefghijklmnopqrstuvwxyz', 'A').toString());
|
25
|
+
},
|
26
|
+
|
27
|
+
testUpdate: function () {
|
28
|
+
var hmac = C.algo.HMAC.create(C.algo.SHA256, 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.HmacSHA256(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.HmacSHA256(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-sha384-test', function (Y) {
|
2
|
+
var C = CryptoJS;
|
3
|
+
|
4
|
+
Y.Test.Runner.add(new Y.Test.Case({
|
5
|
+
name: 'HMAC SHA384',
|
6
|
+
|
7
|
+
testVector1: function () {
|
8
|
+
Y.Assert.areEqual('7afaa633e20d379b02395915fbc385ff8dc27dcd3885e1068ab942eeab52ec1f20ad382a92370d8b2e0ac8b83c4d53bf', C.HmacSHA384('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString());
|
9
|
+
},
|
10
|
+
|
11
|
+
testVector2: function () {
|
12
|
+
Y.Assert.areEqual('af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649', C.HmacSHA384('what do ya want for nothing?', 'Jefe').toString());
|
13
|
+
},
|
14
|
+
|
15
|
+
testVector3: function () {
|
16
|
+
Y.Assert.areEqual('1383e82e28286b91f4cc7afbd13d5b5c6f887c05e7c4542484043a37a5fe45802a9470fb663bd7b6570fe2f503fc92f5', C.HmacSHA384(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString());
|
17
|
+
},
|
18
|
+
|
19
|
+
testVector4: function () {
|
20
|
+
Y.Assert.areEqual('365dfb271adb8e30fe6c74220b75df1b38c2d19b9d37f2e5a0ec2f3f22bd0406bf5b786e98d81b82c36d3d8a1be6cd07', C.HmacSHA384('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A').toString());
|
21
|
+
},
|
22
|
+
|
23
|
+
testVector5: function () {
|
24
|
+
Y.Assert.areEqual('a8357d5e84da64140e41545562ae0782e2a58e39c6cd98939fad8d9080e774c84b7eaca4ba07f6dbf0f12eab912c5285', C.HmacSHA384('abcdefghijklmnopqrstuvwxyz', 'A').toString());
|
25
|
+
},
|
26
|
+
|
27
|
+
testUpdate: function () {
|
28
|
+
var hmac = C.algo.HMAC.create(C.algo.SHA384, 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.HmacSHA384(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.HmacSHA384(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.HmacSHA384("Message", keyClamped).toString(), CryptoJS.HmacSHA384("Message", key).toString());
|
57
|
+
}
|
58
|
+
}));
|
59
|
+
}, '$Rev$');
|
@@ -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$');
|
package/test/md5-test.js
ADDED
@@ -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$');
|