From 8dbabd5cb602980e8f3405cc6107ba378ed2ef9e Mon Sep 17 00:00:00 2001 From: evanvosberg Date: Wed, 1 Apr 2015 15:21:11 +0200 Subject: [PATCH 1/7] Fix readme html code block. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5ead0a0..40834e2 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ require(["crypto-js"], function (CryptoJS) { var encrypted = CryptoJS.AES(...); var encrypted = CryptoJS.SHA256(...); +``` ## API From 428a3e486d2f2487ba254433151395a8c15a8bde Mon Sep 17 00:00:00 2001 From: evanvosberg Date: Thu, 9 Apr 2015 03:52:29 +0200 Subject: [PATCH 2/7] Update origin location and description. --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9f9be52..f60047a 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,19 @@ { "name": "crypto-js", "title": "crypto-js", - "description": "Modularized port of googlecode project crypto-js.", + "description": "JavaScript library of crypto standards.", "version": "3.1.4", - "homepage": "http://github.com/evanvosberg/crypto-js", + "homepage": "http://github.com/brix/crypto-js", "author": { "name": "Evan Vosberg", "url": "http://github.com/evanvosberg" }, "repository": { "type": "git", - "url": "http://github.com/evanvosberg/crypto-js.git" + "url": "http://github.com/brix/crypto-js.git" }, "bugs": { - "url": "http://github.com/evanvosberg/crypto-js/issues" + "url": "http://github.com/brix/crypto-js/issues" }, "licenses": [ { From 359cb15e40697438b7d57512f348df458dff0709 Mon Sep 17 00:00:00 2001 From: evanvosberg Date: Thu, 9 Apr 2015 03:54:08 +0200 Subject: [PATCH 3/7] Update description in readme as well. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 40834e2..376d8af 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # crypto-js -Modularized port of googlecode project crypto-js. +JavaScript library of crypto standards. ## Node.js (Install) From 27c414fac0462cc9f48d99ca31217fc3b1eae11d Mon Sep 17 00:00:00 2001 From: Christopher Hall Date: Wed, 15 Apr 2015 17:37:53 +0800 Subject: [PATCH 4/7] expand HMAC tests to cover the SHA2 series of hashes Currently HMAC-SHA224 and HMAC-SHA384 will fail these tests Signed-off-by: Christopher Hall --- test/{hmac-profile.js => hmac-md5-profile.js} | 4 +- test/{hmac-test.js => hmac-md5-test.js} | 12 +++- test/hmac-sha224-test.js | 59 +++++++++++++++++++ test/hmac-sha256-test.js | 59 +++++++++++++++++++ test/hmac-sha384-test.js | 59 +++++++++++++++++++ test/hmac-sha512-test.js | 59 +++++++++++++++++++ test/test.html | 8 ++- 7 files changed, 254 insertions(+), 6 deletions(-) rename test/{hmac-profile.js => hmac-md5-profile.js} (89%) rename test/{hmac-test.js => hmac-md5-test.js} (83%) create mode 100644 test/hmac-sha224-test.js create mode 100644 test/hmac-sha256-test.js create mode 100644 test/hmac-sha384-test.js create mode 100644 test/hmac-sha512-test.js diff --git a/test/hmac-profile.js b/test/hmac-md5-profile.js similarity index 89% rename from test/hmac-profile.js rename to test/hmac-md5-profile.js index eec56ed..b628240 100644 --- a/test/hmac-profile.js +++ b/test/hmac-md5-profile.js @@ -1,8 +1,8 @@ -YUI.add('algo-hmac-profile', function (Y) { +YUI.add('algo-hmac-md5-profile', function (Y) { var C = CryptoJS; Y.Profiler.add({ - name: 'HMAC', + name: 'HMAC MD5', setUp: function () { this.data = { diff --git a/test/hmac-test.js b/test/hmac-md5-test.js similarity index 83% rename from test/hmac-test.js rename to test/hmac-md5-test.js index 919865b..b50bb04 100644 --- a/test/hmac-test.js +++ b/test/hmac-md5-test.js @@ -1,8 +1,8 @@ -YUI.add('algo-hmac-test', function (Y) { +YUI.add('algo-hmac-md5-test', function (Y) { var C = CryptoJS; Y.Test.Runner.add(new Y.Test.Case({ - name: 'HMAC', + name: 'HMAC MD5', testVector1: function () { Y.Assert.areEqual('9294727a3638bb1c13f48ef8158bfc9d', C.HmacMD5('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); @@ -16,6 +16,14 @@ YUI.add('algo-hmac-test', function (Y) { Y.Assert.areEqual('56be34521d144c88dbb8c733f0e8b3f6', C.HmacMD5(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString()); }, + testVector4: function () { + Y.Assert.areEqual('7ee2a3cc979ab19865704644ce13355c', C.HmacMD5('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A')); + }, + + testVector5: function () { + Y.Assert.areEqual('0e1bd89c43e3e6e3b3f8cf1d5ba4f77a', C.HmacMD5('abcdefghijklmnopqrstuvwxyz', 'A')); + }, + testUpdate: function () { var hmac = C.algo.HMAC.create(C.algo.MD5, C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')); hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddd')); diff --git a/test/hmac-sha224-test.js b/test/hmac-sha224-test.js new file mode 100644 index 0000000..77b1788 --- /dev/null +++ b/test/hmac-sha224-test.js @@ -0,0 +1,59 @@ +YUI.add('algo-hmac-sha224-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'HMAC SHA224', + + testVector1: function () { + Y.Assert.areEqual('4e841ce7a4ae83fbcf71e3cd64bfbf277f73a14680aae8c518ac7861', C.HmacSHA224('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44', C.HmacSHA224('what do ya want for nothing?', 'Jefe').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('cbff7c2716bbaa7c77bed4f491d3e8456cb6c574e92f672b291acf5b', C.HmacSHA224(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('61bf669da4fdcd8e5c3bd09ebbb4a986d3d1b298d3ca05c511f7aeff', C.HmacSHA224('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A')); + }, + + testVector5: function () { + Y.Assert.areEqual('16fc69ada3c3edc1fe9144d6b98d93393833ae442bedf681110a1176', C.HmacSHA224('abcdefghijklmnopqrstuvwxyz', 'A')); + }, + + testUpdate: function () { + var hmac = C.algo.HMAC.create(C.algo.SHA224, C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + + Y.Assert.areEqual(C.HmacSHA224(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString(), hmac.finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + var key = C.lib.WordArray.create([0x12345678]); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + + C.HmacSHA224(message, key); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + }, + + testRespectKeySigBytes: function () { + var key = C.lib.WordArray.random(8); + key.sigBytes = 4; + + var keyClamped = key.clone(); + keyClamped.clamp(); + + Y.Assert.areEqual(CryptoJS.HmacSHA224("Message", keyClamped).toString(), CryptoJS.HmacSHA224("Message", key).toString()); + } + })); +}, '$Rev$'); diff --git a/test/hmac-sha256-test.js b/test/hmac-sha256-test.js new file mode 100644 index 0000000..e8c3b1f --- /dev/null +++ b/test/hmac-sha256-test.js @@ -0,0 +1,59 @@ +YUI.add('algo-hmac-sha256-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'HMAC SHA256', + + testVector1: function () { + Y.Assert.areEqual('492ce020fe2534a5789dc3848806c78f4f6711397f08e7e7a12ca5a4483c8aa6', C.HmacSHA256('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843', C.HmacSHA256('what do ya want for nothing?', 'Jefe').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('7dda3cc169743a6484649f94f0eda0f9f2ff496a9733fb796ed5adb40a44c3c1', C.HmacSHA256(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('a89dc8178c1184a62df87adaa77bf86e93064863d93c5131140b0ae98b866687', C.HmacSHA256('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A')); + }, + + testVector5: function () { + Y.Assert.areEqual('d8cb78419c02fe20b90f8b77427dd9f81817a751d74c2e484e0ac5fc4e6ca986', C.HmacSHA256('abcdefghijklmnopqrstuvwxyz', 'A')); + }, + + testUpdate: function () { + var hmac = C.algo.HMAC.create(C.algo.SHA256, C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + + Y.Assert.areEqual(C.HmacSHA256(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString(), hmac.finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + var key = C.lib.WordArray.create([0x12345678]); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + + C.HmacSHA256(message, key); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + }, + + testRespectKeySigBytes: function () { + var key = C.lib.WordArray.random(8); + key.sigBytes = 4; + + var keyClamped = key.clone(); + keyClamped.clamp(); + + Y.Assert.areEqual(CryptoJS.HmacSHA256("Message", keyClamped).toString(), CryptoJS.HmacSHA256("Message", key).toString()); + } + })); +}, '$Rev$'); diff --git a/test/hmac-sha384-test.js b/test/hmac-sha384-test.js new file mode 100644 index 0000000..aa89455 --- /dev/null +++ b/test/hmac-sha384-test.js @@ -0,0 +1,59 @@ +YUI.add('algo-hmac-sha384-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'HMAC SHA384', + + testVector1: function () { + Y.Assert.areEqual('7afaa633e20d379b02395915fbc385ff8dc27dcd3885e1068ab942eeab52ec1f20ad382a92370d8b2e0ac8b83c4d53bf', C.HmacSHA384('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649', C.HmacSHA384('what do ya want for nothing?', 'Jefe').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('1383e82e28286b91f4cc7afbd13d5b5c6f887c05e7c4542484043a37a5fe45802a9470fb663bd7b6570fe2f503fc92f5', C.HmacSHA384(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('365dfb271adb8e30fe6c74220b75df1b38c2d19b9d37f2e5a0ec2f3f22bd0406bf5b786e98d81b82c36d3d8a1be6cd07', C.HmacSHA384('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A')); + }, + + testVector5: function () { + Y.Assert.areEqual('a8357d5e84da64140e41545562ae0782e2a58e39c6cd98939fad8d9080e774c84b7eaca4ba07f6dbf0f12eab912c5285', C.HmacSHA384('abcdefghijklmnopqrstuvwxyz', 'A')); + }, + + testUpdate: function () { + var hmac = C.algo.HMAC.create(C.algo.SHA384, C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + + Y.Assert.areEqual(C.HmacSHA384(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString(), hmac.finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + var key = C.lib.WordArray.create([0x12345678]); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + + C.HmacSHA384(message, key); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + }, + + testRespectKeySigBytes: function () { + var key = C.lib.WordArray.random(8); + key.sigBytes = 4; + + var keyClamped = key.clone(); + keyClamped.clamp(); + + Y.Assert.areEqual(CryptoJS.HmacSHA384("Message", keyClamped).toString(), CryptoJS.HmacSHA384("Message", key).toString()); + } + })); +}, '$Rev$'); diff --git a/test/hmac-sha512-test.js b/test/hmac-sha512-test.js new file mode 100644 index 0000000..ceb2c7d --- /dev/null +++ b/test/hmac-sha512-test.js @@ -0,0 +1,59 @@ +YUI.add('algo-hmac-sha512-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'HMAC SHA512', + + testVector1: function () { + Y.Assert.areEqual('7641c48a3b4aa8f887c07b3e83f96affb89c978fed8c96fcbbf4ad596eebfe496f9f16da6cd080ba393c6f365ad72b50d15c71bfb1d6b81f66a911786c6ce932', C.HmacSHA512('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737', C.HmacSHA512('what do ya want for nothing?', 'Jefe').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('ad9b5c7de72693737cd5e9d9f41170d18841fec1201c1c1b02e05cae116718009f771cad9946ddbf7e3cde3e818d9ae85d91b2badae94172d096a44a79c91e86', C.HmacSHA512(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('a303979f7c94bb39a8ab6ce05cdbe28f0255da8bb305263e3478ef7e855f0242729bf1d2be55398f14da8e63f0302465a8a3f76c297bd584ad028d18ed7f0195', C.HmacSHA512('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'A')); + }, + + testVector5: function () { + Y.Assert.areEqual('8c2d56f7628325e62124c0a870ad98d101327fc42696899a06ce0d7121454022fae597e42c25ac3a4c380fd514f553702a5b0afaa9b5a22050902f024368e9d9', C.HmacSHA512('abcdefghijklmnopqrstuvwxyz', 'A')); + }, + + testUpdate: function () { + var hmac = C.algo.HMAC.create(C.algo.SHA512, C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + + Y.Assert.areEqual(C.HmacSHA512(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString(), hmac.finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + var key = C.lib.WordArray.create([0x12345678]); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + + C.HmacSHA512(message, key); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + }, + + testRespectKeySigBytes: function () { + var key = C.lib.WordArray.random(8); + key.sigBytes = 4; + + var keyClamped = key.clone(); + keyClamped.clamp(); + + Y.Assert.areEqual(CryptoJS.HmacSHA512("Message", keyClamped).toString(), CryptoJS.HmacSHA512("Message", key).toString()); + } + })); +}, '$Rev$'); diff --git a/test/test.html b/test/test.html index 04d17b4..6a05ea6 100644 --- a/test/test.html +++ b/test/test.html @@ -1,4 +1,4 @@ - + @@ -59,7 +59,11 @@ - + + + + + From f50b05140188ff981f8f2879271e77a27bd0ffb7 Mon Sep 17 00:00:00 2001 From: Christopher Hall Date: Wed, 15 Apr 2015 17:41:06 +0800 Subject: [PATCH 5/7] Fix bug that breaks HMAC routines Some references: (until googlecode shuts down) https://code.google.com/p/crypto-js/issues/detail?id=84 https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js Signed-off-by: Christopher Hall --- src/core.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core.js b/src/core.js index 9869ac6..22711eb 100644 --- a/src/core.js +++ b/src/core.js @@ -210,14 +210,11 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); } - } else if (thatWords.length > 0xffff) { + } else { // Copy one word at a time for (var i = 0; i < thatSigBytes; i += 4) { thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; } - } else { - // Copy all words at once - thisWords.push.apply(thisWords, thatWords); } this.sigBytes += thatSigBytes; From 790b8ef7380cd39d678d280540fe6b8003465113 Mon Sep 17 00:00:00 2001 From: evanvosberg Date: Thu, 28 May 2015 22:00:19 +0200 Subject: [PATCH 6/7] Update license attribute see: https://docs.npmjs.com/files/package.json#license; thanks to @pdehaan. --- package.json | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/package.json b/package.json index f60047a..70c0aec 100644 --- a/package.json +++ b/package.json @@ -15,12 +15,7 @@ "bugs": { "url": "http://github.com/brix/crypto-js/issues" }, - "licenses": [ - { - "type": "MIT", - "url": "http://opensource.org/licenses/MIT" - } - ], + "license": "MIT", "scripts": { "build": "grunt build", "check": "grunt default" From 6398d9cbf592c20d30d32a85d9ee8fa72277b6d1 Mon Sep 17 00:00:00 2001 From: evanvosberg Date: Thu, 28 May 2015 22:13:17 +0200 Subject: [PATCH 7/7] Bump version. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 70c0aec..fcf2d13 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "crypto-js", "title": "crypto-js", "description": "JavaScript library of crypto standards.", - "version": "3.1.4", + "version": "3.1.5", "homepage": "http://github.com/brix/crypto-js", "author": { "name": "Evan Vosberg",