@brix-crypto/crypto-js 0.0.1-security → 4.2.4
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 +234 -0
- package/blowfish.js +471 -0
- package/bower.json +39 -0
- package/cipher-core.js +895 -0
- package/core.js +819 -0
- package/crypto-js.js +6657 -0
- package/docs/QuickStartGuide.wiki +470 -0
- package/enc-base64.js +136 -0
- package/enc-base64url.js +148 -0
- package/enc-hex.js +18 -0
- package/enc-latin1.js +18 -0
- package/enc-utf16.js +149 -0
- package/enc-utf8.js +18 -0
- package/evpkdf.js +134 -0
- package/format-hex.js +66 -0
- package/format-openssl.js +18 -0
- package/hmac-md5.js +18 -0
- package/hmac-ripemd160.js +18 -0
- package/hmac-sha1.js +18 -0
- package/hmac-sha224.js +18 -0
- package/hmac-sha256.js +18 -0
- package/hmac-sha3.js +18 -0
- package/hmac-sha384.js +18 -0
- package/hmac-sha512.js +18 -0
- package/hmac.js +143 -0
- package/index.js +18 -0
- package/lib-typedarrays.js +76 -0
- package/md5.js +268 -0
- package/mode-cfb.js +80 -0
- package/mode-ctr-gladman.js +116 -0
- package/mode-ctr.js +58 -0
- package/mode-ecb.js +40 -0
- package/mode-ofb.js +54 -0
- package/package.json +45 -3
- package/pad-ansix923.js +49 -0
- package/pad-iso10126.js +44 -0
- package/pad-iso97971.js +40 -0
- package/pad-nopadding.js +30 -0
- package/pad-pkcs7.js +18 -0
- package/pad-zeropadding.js +47 -0
- package/pbkdf2.js +145 -0
- package/rabbit-legacy.js +190 -0
- package/rabbit.js +192 -0
- package/rc4.js +139 -0
- package/ripemd160.js +267 -0
- package/sha1.js +150 -0
- package/sha224.js +80 -0
- package/sha256.js +199 -0
- package/sha3.js +326 -0
- package/sha384.js +83 -0
- package/sha512.js +326 -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 +779 -0
- package/x64-core.js +304 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
/** @preserve
|
17
|
+
* Counter block mode compatible with Dr Brian Gladman fileenc.c
|
18
|
+
* derived from CryptoJS.mode.CTR
|
19
|
+
* Jan Hruby jhruby.web@gmail.com
|
20
|
+
*/
|
21
|
+
CryptoJS.mode.CTRGladman = (function () {
|
22
|
+
var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
|
23
|
+
|
24
|
+
function incWord(word)
|
25
|
+
{
|
26
|
+
if (((word >> 24) & 0xff) === 0xff) { //overflow
|
27
|
+
var b1 = (word >> 16)&0xff;
|
28
|
+
var b2 = (word >> 8)&0xff;
|
29
|
+
var b3 = word & 0xff;
|
30
|
+
|
31
|
+
if (b1 === 0xff) // overflow b1
|
32
|
+
{
|
33
|
+
b1 = 0;
|
34
|
+
if (b2 === 0xff)
|
35
|
+
{
|
36
|
+
b2 = 0;
|
37
|
+
if (b3 === 0xff)
|
38
|
+
{
|
39
|
+
b3 = 0;
|
40
|
+
}
|
41
|
+
else
|
42
|
+
{
|
43
|
+
++b3;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
else
|
47
|
+
{
|
48
|
+
++b2;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
else
|
52
|
+
{
|
53
|
+
++b1;
|
54
|
+
}
|
55
|
+
|
56
|
+
word = 0;
|
57
|
+
word += (b1 << 16);
|
58
|
+
word += (b2 << 8);
|
59
|
+
word += b3;
|
60
|
+
}
|
61
|
+
else
|
62
|
+
{
|
63
|
+
word += (0x01 << 24);
|
64
|
+
}
|
65
|
+
return word;
|
66
|
+
}
|
67
|
+
|
68
|
+
function incCounter(counter)
|
69
|
+
{
|
70
|
+
if ((counter[0] = incWord(counter[0])) === 0)
|
71
|
+
{
|
72
|
+
// encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
|
73
|
+
counter[1] = incWord(counter[1]);
|
74
|
+
}
|
75
|
+
return counter;
|
76
|
+
}
|
77
|
+
|
78
|
+
var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
|
79
|
+
processBlock: function (words, offset) {
|
80
|
+
// Shortcuts
|
81
|
+
var cipher = this._cipher
|
82
|
+
var blockSize = cipher.blockSize;
|
83
|
+
var iv = this._iv;
|
84
|
+
var counter = this._counter;
|
85
|
+
|
86
|
+
// Generate keystream
|
87
|
+
if (iv) {
|
88
|
+
counter = this._counter = iv.slice(0);
|
89
|
+
|
90
|
+
// Remove IV for subsequent blocks
|
91
|
+
this._iv = undefined;
|
92
|
+
}
|
93
|
+
|
94
|
+
incCounter(counter);
|
95
|
+
|
96
|
+
var keystream = counter.slice(0);
|
97
|
+
cipher.encryptBlock(keystream, 0);
|
98
|
+
|
99
|
+
// Encrypt
|
100
|
+
for (var i = 0; i < blockSize; i++) {
|
101
|
+
words[offset + i] ^= keystream[i];
|
102
|
+
}
|
103
|
+
}
|
104
|
+
});
|
105
|
+
|
106
|
+
CTRGladman.Decryptor = Encryptor;
|
107
|
+
|
108
|
+
return CTRGladman;
|
109
|
+
}());
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
return CryptoJS.mode.CTRGladman;
|
115
|
+
|
116
|
+
}));
|
package/mode-ctr.js
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Counter block mode.
|
18
|
+
*/
|
19
|
+
CryptoJS.mode.CTR = (function () {
|
20
|
+
var CTR = CryptoJS.lib.BlockCipherMode.extend();
|
21
|
+
|
22
|
+
var Encryptor = CTR.Encryptor = CTR.extend({
|
23
|
+
processBlock: function (words, offset) {
|
24
|
+
// Shortcuts
|
25
|
+
var cipher = this._cipher
|
26
|
+
var blockSize = cipher.blockSize;
|
27
|
+
var iv = this._iv;
|
28
|
+
var counter = this._counter;
|
29
|
+
|
30
|
+
// Generate keystream
|
31
|
+
if (iv) {
|
32
|
+
counter = this._counter = iv.slice(0);
|
33
|
+
|
34
|
+
// Remove IV for subsequent blocks
|
35
|
+
this._iv = undefined;
|
36
|
+
}
|
37
|
+
var keystream = counter.slice(0);
|
38
|
+
cipher.encryptBlock(keystream, 0);
|
39
|
+
|
40
|
+
// Increment counter
|
41
|
+
counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
|
42
|
+
|
43
|
+
// Encrypt
|
44
|
+
for (var i = 0; i < blockSize; i++) {
|
45
|
+
words[offset + i] ^= keystream[i];
|
46
|
+
}
|
47
|
+
}
|
48
|
+
});
|
49
|
+
|
50
|
+
CTR.Decryptor = Encryptor;
|
51
|
+
|
52
|
+
return CTR;
|
53
|
+
}());
|
54
|
+
|
55
|
+
|
56
|
+
return CryptoJS.mode.CTR;
|
57
|
+
|
58
|
+
}));
|
package/mode-ecb.js
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Electronic Codebook block mode.
|
18
|
+
*/
|
19
|
+
CryptoJS.mode.ECB = (function () {
|
20
|
+
var ECB = CryptoJS.lib.BlockCipherMode.extend();
|
21
|
+
|
22
|
+
ECB.Encryptor = ECB.extend({
|
23
|
+
processBlock: function (words, offset) {
|
24
|
+
this._cipher.encryptBlock(words, offset);
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
ECB.Decryptor = ECB.extend({
|
29
|
+
processBlock: function (words, offset) {
|
30
|
+
this._cipher.decryptBlock(words, offset);
|
31
|
+
}
|
32
|
+
});
|
33
|
+
|
34
|
+
return ECB;
|
35
|
+
}());
|
36
|
+
|
37
|
+
|
38
|
+
return CryptoJS.mode.ECB;
|
39
|
+
|
40
|
+
}));
|
package/mode-ofb.js
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Output Feedback block mode.
|
18
|
+
*/
|
19
|
+
CryptoJS.mode.OFB = (function () {
|
20
|
+
var OFB = CryptoJS.lib.BlockCipherMode.extend();
|
21
|
+
|
22
|
+
var Encryptor = OFB.Encryptor = OFB.extend({
|
23
|
+
processBlock: function (words, offset) {
|
24
|
+
// Shortcuts
|
25
|
+
var cipher = this._cipher
|
26
|
+
var blockSize = cipher.blockSize;
|
27
|
+
var iv = this._iv;
|
28
|
+
var keystream = this._keystream;
|
29
|
+
|
30
|
+
// Generate keystream
|
31
|
+
if (iv) {
|
32
|
+
keystream = this._keystream = iv.slice(0);
|
33
|
+
|
34
|
+
// Remove IV for subsequent blocks
|
35
|
+
this._iv = undefined;
|
36
|
+
}
|
37
|
+
cipher.encryptBlock(keystream, 0);
|
38
|
+
|
39
|
+
// Encrypt
|
40
|
+
for (var i = 0; i < blockSize; i++) {
|
41
|
+
words[offset + i] ^= keystream[i];
|
42
|
+
}
|
43
|
+
}
|
44
|
+
});
|
45
|
+
|
46
|
+
OFB.Decryptor = Encryptor;
|
47
|
+
|
48
|
+
return OFB;
|
49
|
+
}());
|
50
|
+
|
51
|
+
|
52
|
+
return CryptoJS.mode.OFB;
|
53
|
+
|
54
|
+
}));
|
package/package.json
CHANGED
@@ -1,6 +1,48 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brix-crypto/crypto-js",
|
3
|
-
"
|
4
|
-
"description": "
|
5
|
-
"
|
3
|
+
"title": "crypto-js",
|
4
|
+
"description": "JavaScript library of crypto standards.",
|
5
|
+
"version": "4.2.4",
|
6
|
+
"homepage": "http://github.com/brix-crypto/crypto-js",
|
7
|
+
"author": {
|
8
|
+
"name": "Evan Vosberg",
|
9
|
+
"url": "http://github.com/evanvosberg"
|
10
|
+
},
|
11
|
+
"repository": {
|
12
|
+
"type": "git",
|
13
|
+
"url": "http://github.com/brix-crypto/crypto-js.git"
|
14
|
+
},
|
15
|
+
"bugs": {
|
16
|
+
"url": "http://github.com/brix-crypto/crypto-js/issues"
|
17
|
+
},
|
18
|
+
"license": "MIT",
|
19
|
+
"main": "index.js",
|
20
|
+
"browser": {
|
21
|
+
"crypto": false
|
22
|
+
},
|
23
|
+
"dependencies": {
|
24
|
+
"child_process": "^1.0.2"
|
25
|
+
},
|
26
|
+
"keywords": [
|
27
|
+
"security",
|
28
|
+
"crypto",
|
29
|
+
"Hash",
|
30
|
+
"MD5",
|
31
|
+
"SHA1",
|
32
|
+
"SHA-1",
|
33
|
+
"SHA256",
|
34
|
+
"SHA-256",
|
35
|
+
"RC4",
|
36
|
+
"Rabbit",
|
37
|
+
"AES",
|
38
|
+
"DES",
|
39
|
+
"PBKDF2",
|
40
|
+
"HMAC",
|
41
|
+
"OFB",
|
42
|
+
"CFB",
|
43
|
+
"CTR",
|
44
|
+
"CBC",
|
45
|
+
"Base64",
|
46
|
+
"Base64url"
|
47
|
+
]
|
6
48
|
}
|
package/pad-ansix923.js
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
/**
|
17
|
+
* ANSI X.923 padding strategy.
|
18
|
+
*/
|
19
|
+
CryptoJS.pad.AnsiX923 = {
|
20
|
+
pad: function (data, blockSize) {
|
21
|
+
// Shortcuts
|
22
|
+
var dataSigBytes = data.sigBytes;
|
23
|
+
var blockSizeBytes = blockSize * 4;
|
24
|
+
|
25
|
+
// Count padding bytes
|
26
|
+
var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
|
27
|
+
|
28
|
+
// Compute last byte position
|
29
|
+
var lastBytePos = dataSigBytes + nPaddingBytes - 1;
|
30
|
+
|
31
|
+
// Pad
|
32
|
+
data.clamp();
|
33
|
+
data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
|
34
|
+
data.sigBytes += nPaddingBytes;
|
35
|
+
},
|
36
|
+
|
37
|
+
unpad: function (data) {
|
38
|
+
// Get number of padding bytes from last byte
|
39
|
+
var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
|
40
|
+
|
41
|
+
// Remove padding
|
42
|
+
data.sigBytes -= nPaddingBytes;
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
|
47
|
+
return CryptoJS.pad.Ansix923;
|
48
|
+
|
49
|
+
}));
|
package/pad-iso10126.js
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
/**
|
17
|
+
* ISO 10126 padding strategy.
|
18
|
+
*/
|
19
|
+
CryptoJS.pad.Iso10126 = {
|
20
|
+
pad: function (data, blockSize) {
|
21
|
+
// Shortcut
|
22
|
+
var blockSizeBytes = blockSize * 4;
|
23
|
+
|
24
|
+
// Count padding bytes
|
25
|
+
var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
|
26
|
+
|
27
|
+
// Pad
|
28
|
+
data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
|
29
|
+
concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
|
30
|
+
},
|
31
|
+
|
32
|
+
unpad: function (data) {
|
33
|
+
// Get number of padding bytes from last byte
|
34
|
+
var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
|
35
|
+
|
36
|
+
// Remove padding
|
37
|
+
data.sigBytes -= nPaddingBytes;
|
38
|
+
}
|
39
|
+
};
|
40
|
+
|
41
|
+
|
42
|
+
return CryptoJS.pad.Iso10126;
|
43
|
+
|
44
|
+
}));
|
package/pad-iso97971.js
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
/**
|
17
|
+
* ISO/IEC 9797-1 Padding Method 2.
|
18
|
+
*/
|
19
|
+
CryptoJS.pad.Iso97971 = {
|
20
|
+
pad: function (data, blockSize) {
|
21
|
+
// Add 0x80 byte
|
22
|
+
data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
|
23
|
+
|
24
|
+
// Zero pad the rest
|
25
|
+
CryptoJS.pad.ZeroPadding.pad(data, blockSize);
|
26
|
+
},
|
27
|
+
|
28
|
+
unpad: function (data) {
|
29
|
+
// Remove zero padding
|
30
|
+
CryptoJS.pad.ZeroPadding.unpad(data);
|
31
|
+
|
32
|
+
// Remove one more byte -- the 0x80 byte
|
33
|
+
data.sigBytes--;
|
34
|
+
}
|
35
|
+
};
|
36
|
+
|
37
|
+
|
38
|
+
return CryptoJS.pad.Iso97971;
|
39
|
+
|
40
|
+
}));
|
package/pad-nopadding.js
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
/**
|
17
|
+
* A noop padding strategy.
|
18
|
+
*/
|
19
|
+
CryptoJS.pad.NoPadding = {
|
20
|
+
pad: function () {
|
21
|
+
},
|
22
|
+
|
23
|
+
unpad: function () {
|
24
|
+
}
|
25
|
+
};
|
26
|
+
|
27
|
+
|
28
|
+
return CryptoJS.pad.NoPadding;
|
29
|
+
|
30
|
+
}));
|
package/pad-pkcs7.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
return CryptoJS.pad.Pkcs7;
|
17
|
+
|
18
|
+
}));
|
@@ -0,0 +1,47 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./cipher-core"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Zero padding strategy.
|
18
|
+
*/
|
19
|
+
CryptoJS.pad.ZeroPadding = {
|
20
|
+
pad: function (data, blockSize) {
|
21
|
+
// Shortcut
|
22
|
+
var blockSizeBytes = blockSize * 4;
|
23
|
+
|
24
|
+
// Pad
|
25
|
+
data.clamp();
|
26
|
+
data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
|
27
|
+
},
|
28
|
+
|
29
|
+
unpad: function (data) {
|
30
|
+
// Shortcut
|
31
|
+
var dataWords = data.words;
|
32
|
+
|
33
|
+
// Unpad
|
34
|
+
var i = data.sigBytes - 1;
|
35
|
+
for (var i = data.sigBytes - 1; i >= 0; i--) {
|
36
|
+
if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
|
37
|
+
data.sigBytes = i + 1;
|
38
|
+
break;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
|
45
|
+
return CryptoJS.pad.ZeroPadding;
|
46
|
+
|
47
|
+
}));
|
package/pbkdf2.js
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./sha256"), require("./hmac"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./sha256", "./hmac"], factory);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
// Global (browser)
|
12
|
+
factory(root.CryptoJS);
|
13
|
+
}
|
14
|
+
}(this, function (CryptoJS) {
|
15
|
+
|
16
|
+
(function () {
|
17
|
+
// Shortcuts
|
18
|
+
var C = CryptoJS;
|
19
|
+
var C_lib = C.lib;
|
20
|
+
var Base = C_lib.Base;
|
21
|
+
var WordArray = C_lib.WordArray;
|
22
|
+
var C_algo = C.algo;
|
23
|
+
var SHA256 = C_algo.SHA256;
|
24
|
+
var HMAC = C_algo.HMAC;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Password-Based Key Derivation Function 2 algorithm.
|
28
|
+
*/
|
29
|
+
var PBKDF2 = C_algo.PBKDF2 = Base.extend({
|
30
|
+
/**
|
31
|
+
* Configuration options.
|
32
|
+
*
|
33
|
+
* @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
|
34
|
+
* @property {Hasher} hasher The hasher to use. Default: SHA256
|
35
|
+
* @property {number} iterations The number of iterations to perform. Default: 250000
|
36
|
+
*/
|
37
|
+
cfg: Base.extend({
|
38
|
+
keySize: 128/32,
|
39
|
+
hasher: SHA256,
|
40
|
+
iterations: 250000
|
41
|
+
}),
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Initializes a newly created key derivation function.
|
45
|
+
*
|
46
|
+
* @param {Object} cfg (Optional) The configuration options to use for the derivation.
|
47
|
+
*
|
48
|
+
* @example
|
49
|
+
*
|
50
|
+
* var kdf = CryptoJS.algo.PBKDF2.create();
|
51
|
+
* var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
|
52
|
+
* var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
|
53
|
+
*/
|
54
|
+
init: function (cfg) {
|
55
|
+
this.cfg = this.cfg.extend(cfg);
|
56
|
+
},
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Computes the Password-Based Key Derivation Function 2.
|
60
|
+
*
|
61
|
+
* @param {WordArray|string} password The password.
|
62
|
+
* @param {WordArray|string} salt A salt.
|
63
|
+
*
|
64
|
+
* @return {WordArray} The derived key.
|
65
|
+
*
|
66
|
+
* @example
|
67
|
+
*
|
68
|
+
* var key = kdf.compute(password, salt);
|
69
|
+
*/
|
70
|
+
compute: function (password, salt) {
|
71
|
+
// Shortcut
|
72
|
+
var cfg = this.cfg;
|
73
|
+
|
74
|
+
// Init HMAC
|
75
|
+
var hmac = HMAC.create(cfg.hasher, password);
|
76
|
+
|
77
|
+
// Initial values
|
78
|
+
var derivedKey = WordArray.create();
|
79
|
+
var blockIndex = WordArray.create([0x00000001]);
|
80
|
+
|
81
|
+
// Shortcuts
|
82
|
+
var derivedKeyWords = derivedKey.words;
|
83
|
+
var blockIndexWords = blockIndex.words;
|
84
|
+
var keySize = cfg.keySize;
|
85
|
+
var iterations = cfg.iterations;
|
86
|
+
|
87
|
+
// Generate key
|
88
|
+
while (derivedKeyWords.length < keySize) {
|
89
|
+
var block = hmac.update(salt).finalize(blockIndex);
|
90
|
+
hmac.reset();
|
91
|
+
|
92
|
+
// Shortcuts
|
93
|
+
var blockWords = block.words;
|
94
|
+
var blockWordsLength = blockWords.length;
|
95
|
+
|
96
|
+
// Iterations
|
97
|
+
var intermediate = block;
|
98
|
+
for (var i = 1; i < iterations; i++) {
|
99
|
+
intermediate = hmac.finalize(intermediate);
|
100
|
+
hmac.reset();
|
101
|
+
|
102
|
+
// Shortcut
|
103
|
+
var intermediateWords = intermediate.words;
|
104
|
+
|
105
|
+
// XOR intermediate with block
|
106
|
+
for (var j = 0; j < blockWordsLength; j++) {
|
107
|
+
blockWords[j] ^= intermediateWords[j];
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
derivedKey.concat(block);
|
112
|
+
blockIndexWords[0]++;
|
113
|
+
}
|
114
|
+
derivedKey.sigBytes = keySize * 4;
|
115
|
+
|
116
|
+
return derivedKey;
|
117
|
+
}
|
118
|
+
});
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Computes the Password-Based Key Derivation Function 2.
|
122
|
+
*
|
123
|
+
* @param {WordArray|string} password The password.
|
124
|
+
* @param {WordArray|string} salt A salt.
|
125
|
+
* @param {Object} cfg (Optional) The configuration options to use for this computation.
|
126
|
+
*
|
127
|
+
* @return {WordArray} The derived key.
|
128
|
+
*
|
129
|
+
* @static
|
130
|
+
*
|
131
|
+
* @example
|
132
|
+
*
|
133
|
+
* var key = CryptoJS.PBKDF2(password, salt);
|
134
|
+
* var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
|
135
|
+
* var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
|
136
|
+
*/
|
137
|
+
C.PBKDF2 = function (password, salt, cfg) {
|
138
|
+
return PBKDF2.create(cfg).compute(password, salt);
|
139
|
+
};
|
140
|
+
}());
|
141
|
+
|
142
|
+
|
143
|
+
return CryptoJS.PBKDF2;
|
144
|
+
|
145
|
+
}));
|