Skip to content
This repository
Browse code

Updating cryptojs to 3.1.2 from https://code.google.com/p/crypto-js/

  • Loading branch information...
commit 46af2dc3a48c0c765dbbb89f918cd77cb4f50252 1 parent 19aec7c
Brian Graham authored March 06, 2013

Showing 88 changed files with 6,922 additions and 0 deletions. Show diff stats Hide diff stats

  1. 10  cryptojs/components/aes-min.js
  2. 213  cryptojs/components/aes.js
  3. 14  cryptojs/components/cipher-core-min.js
  4. 863  cryptojs/components/cipher-core.js
  5. 13  cryptojs/components/core-min.js
  6. 712  cryptojs/components/core.js
  7. 8  cryptojs/components/enc-base64-min.js
  8. 109  cryptojs/components/enc-base64.js
  9. 8  cryptojs/components/enc-utf16-min.js
  10. 135  cryptojs/components/enc-utf16.js
  11. 8  cryptojs/components/evpkdf-min.js
  12. 118  cryptojs/components/evpkdf.js
  13. 7  cryptojs/components/format-hex-min.js
  14. 52  cryptojs/components/format-hex.js
  15. 8  cryptojs/components/hmac-min.js
  16. 131  cryptojs/components/hmac.js
  17. 8  cryptojs/components/lib-typedarrays-min.js
  18. 62  cryptojs/components/lib-typedarrays.js
  19. 12  cryptojs/components/md5-min.js
  20. 254  cryptojs/components/md5.js
  21. 7  cryptojs/components/mode-cfb-min.js
  22. 64  cryptojs/components/mode-cfb.js
  23. 14  cryptojs/components/mode-ctr-gladman-min.js
  24. 102  cryptojs/components/mode-ctr-gladman.js
  25. 7  cryptojs/components/mode-ctr-min.js
  26. 44  cryptojs/components/mode-ctr.js
  27. 7  cryptojs/components/mode-ecb-min.js
  28. 26  cryptojs/components/mode-ecb.js
  29. 7  cryptojs/components/mode-ofb-min.js
  30. 40  cryptojs/components/mode-ofb.js
  31. 7  cryptojs/components/pad-ansix923-min.js
  32. 35  cryptojs/components/pad-ansix923.js
  33. 7  cryptojs/components/pad-iso10126-min.js
  34. 30  cryptojs/components/pad-iso10126.js
  35. 7  cryptojs/components/pad-iso97971-min.js
  36. 26  cryptojs/components/pad-iso97971.js
  37. 7  cryptojs/components/pad-nopadding-min.js
  38. 16  cryptojs/components/pad-nopadding.js
  39. 7  cryptojs/components/pad-zeropadding-min.js
  40. 31  cryptojs/components/pad-zeropadding.js
  41. 8  cryptojs/components/pbkdf2-min.js
  42. 131  cryptojs/components/pbkdf2.js
  43. 11  cryptojs/components/rabbit-legacy-min.js
  44. 176  cryptojs/components/rabbit-legacy.js
  45. 11  cryptojs/components/rabbit-min.js
  46. 178  cryptojs/components/rabbit.js
  47. 8  cryptojs/components/rc4-min.js
  48. 125  cryptojs/components/rc4.js
  49. 22  cryptojs/components/ripemd160-min.js
  50. 253  cryptojs/components/ripemd160.js
  51. 8  cryptojs/components/sha1-min.js
  52. 136  cryptojs/components/sha1.js
  53. 7  cryptojs/components/sha224-min.js
  54. 66  cryptojs/components/sha224.js
  55. 9  cryptojs/components/sha256-min.js
  56. 185  cryptojs/components/sha256.js
  57. 11  cryptojs/components/sha3-min.js
  58. 309  cryptojs/components/sha3.js
  59. 8  cryptojs/components/sha384-min.js
  60. 69  cryptojs/components/sha384.js
  61. 15  cryptojs/components/sha512-min.js
  62. 309  cryptojs/components/sha512.js
  63. 26  cryptojs/components/tripledes-min.js
  64. 756  cryptojs/components/tripledes.js
  65. 7  cryptojs/components/x64-core-min.js
  66. 290  cryptojs/components/x64-core.js
  67. 35  cryptojs/rollups/aes.js
  68. 21  cryptojs/rollups/hmac-md5.js
  69. 31  cryptojs/rollups/hmac-ripemd160.js
  70. 17  cryptojs/rollups/hmac-sha1.js
  71. 19  cryptojs/rollups/hmac-sha224.js
  72. 18  cryptojs/rollups/hmac-sha256.js
  73. 21  cryptojs/rollups/hmac-sha3.js
  74. 27  cryptojs/rollups/hmac-sha384.js
  75. 25  cryptojs/rollups/hmac-sha512.js
  76. 19  cryptojs/rollups/md5.js
  77. 19  cryptojs/rollups/pbkdf2.js
  78. 36  cryptojs/rollups/rabbit-legacy.js
  79. 36  cryptojs/rollups/rabbit.js
  80. 33  cryptojs/rollups/rc4.js
  81. 29  cryptojs/rollups/ripemd160.js
  82. 15  cryptojs/rollups/sha1.js
  83. 17  cryptojs/rollups/sha224.js
  84. 16  cryptojs/rollups/sha256.js
  85. 19  cryptojs/rollups/sha3.js
  86. 25  cryptojs/rollups/sha384.js
  87. 23  cryptojs/rollups/sha512.js
  88. 51  cryptojs/rollups/tripledes.js
10  cryptojs/components/aes-min.js
... ...
@@ -0,0 +1,10 @@
  1
+/*
  2
+CryptoJS v3.1.2
  3
+code.google.com/p/crypto-js
  4
+(c) 2009-2013 by Jeff Mott. All rights reserved.
  5
+code.google.com/p/crypto-js/wiki/License
  6
+*/
  7
+(function(){for(var q=CryptoJS,x=q.lib.BlockCipher,r=q.algo,j=[],y=[],z=[],A=[],B=[],C=[],s=[],u=[],v=[],w=[],g=[],k=0;256>k;k++)g[k]=128>k?k<<1:k<<1^283;for(var n=0,l=0,k=0;256>k;k++){var f=l^l<<1^l<<2^l<<3^l<<4,f=f>>>8^f&255^99;j[n]=f;y[f]=n;var t=g[n],D=g[t],E=g[D],b=257*g[f]^16843008*f;z[n]=b<<24|b>>>8;A[n]=b<<16|b>>>16;B[n]=b<<8|b>>>24;C[n]=b;b=16843009*E^65537*D^257*t^16843008*n;s[f]=b<<24|b>>>8;u[f]=b<<16|b>>>16;v[f]=b<<8|b>>>24;w[f]=b;n?(n=t^g[g[g[E^t]]],l^=g[g[l]]):n=l=1}var F=[0,1,2,4,8,
  8
+16,32,64,128,27,54],r=r.AES=x.extend({_doReset:function(){for(var c=this._key,e=c.words,a=c.sigBytes/4,c=4*((this._nRounds=a+6)+1),b=this._keySchedule=[],h=0;h<c;h++)if(h<a)b[h]=e[h];else{var d=b[h-1];h%a?6<a&&4==h%a&&(d=j[d>>>24]<<24|j[d>>>16&255]<<16|j[d>>>8&255]<<8|j[d&255]):(d=d<<8|d>>>24,d=j[d>>>24]<<24|j[d>>>16&255]<<16|j[d>>>8&255]<<8|j[d&255],d^=F[h/a|0]<<24);b[h]=b[h-a]^d}e=this._invKeySchedule=[];for(a=0;a<c;a++)h=c-a,d=a%4?b[h]:b[h-4],e[a]=4>a||4>=h?d:s[j[d>>>24]]^u[j[d>>>16&255]]^v[j[d>>>
  9
+8&255]]^w[j[d&255]]},encryptBlock:function(c,e){this._doCryptBlock(c,e,this._keySchedule,z,A,B,C,j)},decryptBlock:function(c,e){var a=c[e+1];c[e+1]=c[e+3];c[e+3]=a;this._doCryptBlock(c,e,this._invKeySchedule,s,u,v,w,y);a=c[e+1];c[e+1]=c[e+3];c[e+3]=a},_doCryptBlock:function(c,e,a,b,h,d,j,m){for(var n=this._nRounds,f=c[e]^a[0],g=c[e+1]^a[1],k=c[e+2]^a[2],p=c[e+3]^a[3],l=4,t=1;t<n;t++)var q=b[f>>>24]^h[g>>>16&255]^d[k>>>8&255]^j[p&255]^a[l++],r=b[g>>>24]^h[k>>>16&255]^d[p>>>8&255]^j[f&255]^a[l++],s=
  10
+b[k>>>24]^h[p>>>16&255]^d[f>>>8&255]^j[g&255]^a[l++],p=b[p>>>24]^h[f>>>16&255]^d[g>>>8&255]^j[k&255]^a[l++],f=q,g=r,k=s;q=(m[f>>>24]<<24|m[g>>>16&255]<<16|m[k>>>8&255]<<8|m[p&255])^a[l++];r=(m[g>>>24]<<24|m[k>>>16&255]<<16|m[p>>>8&255]<<8|m[f&255])^a[l++];s=(m[k>>>24]<<24|m[p>>>16&255]<<16|m[f>>>8&255]<<8|m[g&255])^a[l++];p=(m[p>>>24]<<24|m[f>>>16&255]<<16|m[g>>>8&255]<<8|m[k&255])^a[l++];c[e]=q;c[e+1]=r;c[e+2]=s;c[e+3]=p},keySize:8});q.AES=x._createHelper(r)})();
213  cryptojs/components/aes.js
... ...
@@ -0,0 +1,213 @@
  1
+/*
  2
+CryptoJS v3.1.2
  3
+code.google.com/p/crypto-js
  4
+(c) 2009-2013 by Jeff Mott. All rights reserved.
  5
+code.google.com/p/crypto-js/wiki/License
  6
+*/
  7
+(function () {
  8
+    // Shortcuts
  9
+    var C = CryptoJS;
  10
+    var C_lib = C.lib;
  11
+    var BlockCipher = C_lib.BlockCipher;
  12
+    var C_algo = C.algo;
  13
+
  14
+    // Lookup tables
  15
+    var SBOX = [];
  16
+    var INV_SBOX = [];
  17
+    var SUB_MIX_0 = [];
  18
+    var SUB_MIX_1 = [];
  19
+    var SUB_MIX_2 = [];
  20
+    var SUB_MIX_3 = [];
  21
+    var INV_SUB_MIX_0 = [];
  22
+    var INV_SUB_MIX_1 = [];
  23
+    var INV_SUB_MIX_2 = [];
  24
+    var INV_SUB_MIX_3 = [];
  25
+
  26
+    // Compute lookup tables
  27
+    (function () {
  28
+        // Compute double table
  29
+        var d = [];
  30
+        for (var i = 0; i < 256; i++) {
  31
+            if (i < 128) {
  32
+                d[i] = i << 1;
  33
+            } else {
  34
+                d[i] = (i << 1) ^ 0x11b;
  35
+            }
  36
+        }
  37
+
  38
+        // Walk GF(2^8)
  39
+        var x = 0;
  40
+        var xi = 0;
  41
+        for (var i = 0; i < 256; i++) {
  42
+            // Compute sbox
  43
+            var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  44
+            sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  45
+            SBOX[x] = sx;
  46
+            INV_SBOX[sx] = x;
  47
+
  48
+            // Compute multiplication
  49
+            var x2 = d[x];
  50
+            var x4 = d[x2];
  51
+            var x8 = d[x4];
  52
+
  53
+            // Compute sub bytes, mix columns tables
  54
+            var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  55
+            SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  56
+            SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  57
+            SUB_MIX_2[x] = (t << 8)  | (t >>> 24);
  58
+            SUB_MIX_3[x] = t;
  59
+
  60
+            // Compute inv sub bytes, inv mix columns tables
  61
+            var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  62
+            INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  63
+            INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  64
+            INV_SUB_MIX_2[sx] = (t << 8)  | (t >>> 24);
  65
+            INV_SUB_MIX_3[sx] = t;
  66
+
  67
+            // Compute next counter
  68
+            if (!x) {
  69
+                x = xi = 1;
  70
+            } else {
  71
+                x = x2 ^ d[d[d[x8 ^ x2]]];
  72
+                xi ^= d[d[xi]];
  73
+            }
  74
+        }
  75
+    }());
  76
+
  77
+    // Precomputed Rcon lookup
  78
+    var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  79
+
  80
+    /**
  81
+     * AES block cipher algorithm.
  82
+     */
  83
+    var AES = C_algo.AES = BlockCipher.extend({
  84
+        _doReset: function () {
  85
+            // Shortcuts
  86
+            var key = this._key;
  87
+            var keyWords = key.words;
  88
+            var keySize = key.sigBytes / 4;
  89
+
  90
+            // Compute number of rounds
  91
+            var nRounds = this._nRounds = keySize + 6
  92
+
  93
+            // Compute number of key schedule rows
  94
+            var ksRows = (nRounds + 1) * 4;
  95
+
  96
+            // Compute key schedule
  97
+            var keySchedule = this._keySchedule = [];
  98
+            for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  99
+                if (ksRow < keySize) {
  100
+                    keySchedule[ksRow] = keyWords[ksRow];
  101
+                } else {
  102
+                    var t = keySchedule[ksRow - 1];
  103
+
  104
+                    if (!(ksRow % keySize)) {
  105
+                        // Rot word
  106
+                        t = (t << 8) | (t >>> 24);
  107
+
  108
+                        // Sub word
  109
+                        t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  110
+
  111
+                        // Mix Rcon
  112
+                        t ^= RCON[(ksRow / keySize) | 0] << 24;
  113
+                    } else if (keySize > 6 && ksRow % keySize == 4) {
  114
+                        // Sub word
  115
+                        t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  116
+                    }
  117
+
  118
+                    keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  119
+                }
  120
+            }
  121
+
  122
+            // Compute inv key schedule
  123
+            var invKeySchedule = this._invKeySchedule = [];
  124
+            for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  125
+                var ksRow = ksRows - invKsRow;
  126
+
  127
+                if (invKsRow % 4) {
  128
+                    var t = keySchedule[ksRow];
  129
+                } else {
  130
+                    var t = keySchedule[ksRow - 4];
  131
+                }
  132
+
  133
+                if (invKsRow < 4 || ksRow <= 4) {
  134
+                    invKeySchedule[invKsRow] = t;
  135
+                } else {
  136
+                    invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
  137
+                                               INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
  138
+                }
  139
+            }
  140
+        },
  141
+
  142
+        encryptBlock: function (M, offset) {
  143
+            this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
  144
+        },
  145
+
  146
+        decryptBlock: function (M, offset) {
  147
+            // Swap 2nd and 4th rows
  148
+            var t = M[offset + 1];
  149
+            M[offset + 1] = M[offset + 3];
  150
+            M[offset + 3] = t;
  151
+
  152
+            this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
  153
+
  154
+            // Inv swap 2nd and 4th rows
  155
+            var t = M[offset + 1];
  156
+            M[offset + 1] = M[offset + 3];
  157
+            M[offset + 3] = t;
  158
+        },
  159
+
  160
+        _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
  161
+            // Shortcut
  162
+            var nRounds = this._nRounds;
  163
+
  164
+            // Get input, add round key
  165
+            var s0 = M[offset]     ^ keySchedule[0];
  166
+            var s1 = M[offset + 1] ^ keySchedule[1];
  167
+            var s2 = M[offset + 2] ^ keySchedule[2];
  168
+            var s3 = M[offset + 3] ^ keySchedule[3];
  169
+
  170
+            // Key schedule row counter
  171
+            var ksRow = 4;
  172
+
  173
+            // Rounds
  174
+            for (var round = 1; round < nRounds; round++) {
  175
+                // Shift rows, sub bytes, mix columns, add round key
  176
+                var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
  177
+                var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
  178
+                var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
  179
+                var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
  180
+
  181
+                // Update state
  182
+                s0 = t0;
  183
+                s1 = t1;
  184
+                s2 = t2;
  185
+                s3 = t3;
  186
+            }
  187
+
  188
+            // Shift rows, sub bytes, add round key
  189
+            var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  190
+            var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  191
+            var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  192
+            var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  193
+
  194
+            // Set output
  195
+            M[offset]     = t0;
  196
+            M[offset + 1] = t1;
  197
+            M[offset + 2] = t2;
  198
+            M[offset + 3] = t3;
  199
+        },
  200
+
  201
+        keySize: 256/32
  202
+    });
  203
+
  204
+    /**
  205
+     * Shortcut functions to the cipher's object interface.
  206
+     *
  207
+     * @example
  208
+     *
  209
+     *     var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  210
+     *     var plaintext  = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  211
+     */
  212
+    C.AES = BlockCipher._createHelper(AES);
  213
+}());
14  cryptojs/components/cipher-core-min.js
... ...
@@ -0,0 +1,14 @@
  1
+/*
  2
+CryptoJS v3.1.2
  3
+code.google.com/p/crypto-js
  4
+(c) 2009-2013 by Jeff Mott. All rights reserved.
  5
+code.google.com/p/crypto-js/wiki/License
  6
+*/
  7
+CryptoJS.lib.Cipher||function(u){var g=CryptoJS,f=g.lib,k=f.Base,l=f.WordArray,q=f.BufferedBlockAlgorithm,r=g.enc.Base64,v=g.algo.EvpKDF,n=f.Cipher=q.extend({cfg:k.extend(),createEncryptor:function(a,b){return this.create(this._ENC_XFORM_MODE,a,b)},createDecryptor:function(a,b){return this.create(this._DEC_XFORM_MODE,a,b)},init:function(a,b,c){this.cfg=this.cfg.extend(c);this._xformMode=a;this._key=b;this.reset()},reset:function(){q.reset.call(this);this._doReset()},process:function(a){this._append(a);
  8
+return this._process()},finalize:function(a){a&&this._append(a);return this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(a){return{encrypt:function(b,c,d){return("string"==typeof c?s:j).encrypt(a,b,c,d)},decrypt:function(b,c,d){return("string"==typeof c?s:j).decrypt(a,b,c,d)}}}});f.StreamCipher=n.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var m=g.mode={},t=function(a,b,c){var d=this._iv;d?this._iv=u:d=this._prevBlock;for(var e=
  9
+0;e<c;e++)a[b+e]^=d[e]},h=(f.BlockCipherMode=k.extend({createEncryptor:function(a,b){return this.Encryptor.create(a,b)},createDecryptor:function(a,b){return this.Decryptor.create(a,b)},init:function(a,b){this._cipher=a;this._iv=b}})).extend();h.Encryptor=h.extend({processBlock:function(a,b){var c=this._cipher,d=c.blockSize;t.call(this,a,b,d);c.encryptBlock(a,b);this._prevBlock=a.slice(b,b+d)}});h.Decryptor=h.extend({processBlock:function(a,b){var c=this._cipher,d=c.blockSize,e=a.slice(b,b+d);c.decryptBlock(a,
  10
+b);t.call(this,a,b,d);this._prevBlock=e}});m=m.CBC=h;h=(g.pad={}).Pkcs7={pad:function(a,b){for(var c=4*b,c=c-a.sigBytes%c,d=c<<24|c<<16|c<<8|c,e=[],f=0;f<c;f+=4)e.push(d);c=l.create(e,c);a.concat(c)},unpad:function(a){a.sigBytes-=a.words[a.sigBytes-1>>>2]&255}};f.BlockCipher=n.extend({cfg:n.cfg.extend({mode:m,padding:h}),reset:function(){n.reset.call(this);var a=this.cfg,b=a.iv,a=a.mode;if(this._xformMode==this._ENC_XFORM_MODE)var c=a.createEncryptor;else c=a.createDecryptor,this._minBufferSize=1;
  11
+this._mode=c.call(a,this,b&&b.words)},_doProcessBlock:function(a,b){this._mode.processBlock(a,b)},_doFinalize:function(){var a=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){a.pad(this._data,this.blockSize);var b=this._process(!0)}else b=this._process(!0),a.unpad(b);return b},blockSize:4});var p=f.CipherParams=k.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}}),m=(g.format={}).OpenSSL={stringify:function(a){var b=a.ciphertext;a=a.salt;
  12
+return(a?l.create([1398893684,1701076831]).concat(a).concat(b):b).toString(r)},parse:function(a){a=r.parse(a);var b=a.words;if(1398893684==b[0]&&1701076831==b[1]){var c=l.create(b.slice(2,4));b.splice(0,4);a.sigBytes-=16}return p.create({ciphertext:a,salt:c})}},j=f.SerializableCipher=k.extend({cfg:k.extend({format:m}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);var e=a.createEncryptor(c,d);b=e.finalize(b);e=e.cfg;return p.create({ciphertext:b,key:c,iv:e.iv,algorithm:a,mode:e.mode,padding:e.padding,
  13
+blockSize:a.blockSize,formatter:d.format})},decrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);return a.createDecryptor(c,d).finalize(b.ciphertext)},_parse:function(a,b){return"string"==typeof a?b.parse(a,this):a}}),g=(g.kdf={}).OpenSSL={execute:function(a,b,c,d){d||(d=l.random(8));a=v.create({keySize:b+c}).compute(a,d);c=l.create(a.words.slice(b),4*c);a.sigBytes=4*b;return p.create({key:a,iv:c,salt:d})}},s=f.PasswordBasedCipher=j.extend({cfg:j.cfg.extend({kdf:g}),encrypt:function(a,
  14
+b,c,d){d=this.cfg.extend(d);c=d.kdf.execute(c,a.keySize,a.ivSize);d.iv=c.iv;a=j.encrypt.call(this,a,b,c.key,d);a.mixIn(c);return a},decrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);c=d.kdf.execute(c,a.keySize,a.ivSize,b.salt);d.iv=c.iv;return j.decrypt.call(this,a,b,c.key,d)}})}();
863  cryptojs/components/cipher-core.js
... ...
@@ -0,0 +1,863 @@
  1
+/*
  2
+CryptoJS v3.1.2
  3
+code.google.com/p/crypto-js
  4
+(c) 2009-2013 by Jeff Mott. All rights reserved.
  5
+code.google.com/p/crypto-js/wiki/License
  6
+*/
  7
+/**
  8
+ * Cipher core components.
  9
+ */
  10
+CryptoJS.lib.Cipher || (function (undefined) {
  11
+    // Shortcuts
  12
+    var C = CryptoJS;
  13
+    var C_lib = C.lib;
  14
+    var Base = C_lib.Base;
  15
+    var WordArray = C_lib.WordArray;
  16
+    var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  17
+    var C_enc = C.enc;
  18
+    var Utf8 = C_enc.Utf8;
  19
+    var Base64 = C_enc.Base64;
  20
+    var C_algo = C.algo;
  21
+    var EvpKDF = C_algo.EvpKDF;
  22
+
  23
+    /**
  24
+     * Abstract base cipher template.
  25
+     *
  26
+     * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
  27
+     * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
  28
+     * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
  29
+     * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
  30
+     */
  31
+    var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
  32
+        /**
  33
+         * Configuration options.
  34
+         *
  35
+         * @property {WordArray} iv The IV to use for this operation.
  36
+         */
  37
+        cfg: Base.extend(),
  38
+
  39
+        /**
  40
+         * Creates this cipher in encryption mode.
  41
+         *
  42
+         * @param {WordArray} key The key.
  43
+         * @param {Object} cfg (Optional) The configuration options to use for this operation.
  44
+         *
  45
+         * @return {Cipher} A cipher instance.
  46
+         *
  47
+         * @static
  48
+         *
  49
+         * @example
  50
+         *
  51
+         *     var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  52
+         */
  53
+        createEncryptor: function (key, cfg) {
  54
+            return this.create(this._ENC_XFORM_MODE, key, cfg);
  55
+        },
  56
+
  57
+        /**
  58
+         * Creates this cipher in decryption mode.
  59
+         *
  60
+         * @param {WordArray} key The key.
  61
+         * @param {Object} cfg (Optional) The configuration options to use for this operation.
  62
+         *
  63
+         * @return {Cipher} A cipher instance.
  64
+         *
  65
+         * @static
  66
+         *
  67
+         * @example
  68
+         *
  69
+         *     var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  70
+         */
  71
+        createDecryptor: function (key, cfg) {
  72
+            return this.create(this._DEC_XFORM_MODE, key, cfg);
  73
+        },
  74
+
  75
+        /**
  76
+         * Initializes a newly created cipher.
  77
+         *
  78
+         * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  79
+         * @param {WordArray} key The key.
  80
+         * @param {Object} cfg (Optional) The configuration options to use for this operation.
  81
+         *
  82
+         * @example
  83
+         *
  84
+         *     var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  85
+         */
  86
+        init: function (xformMode, key, cfg) {
  87
+            // Apply config defaults
  88
+            this.cfg = this.cfg.extend(cfg);
  89
+
  90
+            // Store transform mode and key
  91
+            this._xformMode = xformMode;
  92
+            this._key = key;
  93
+
  94
+            // Set initial values
  95
+            this.reset();
  96
+        },
  97
+
  98
+        /**
  99
+         * Resets this cipher to its initial state.
  100
+         *
  101
+         * @example
  102
+         *
  103
+         *     cipher.reset();
  104
+         */
  105
+        reset: function () {
  106
+            // Reset data buffer
  107
+            BufferedBlockAlgorithm.reset.call(this);
  108
+
  109
+            // Perform concrete-cipher logic
  110
+            this._doReset();
  111
+        },
  112
+
  113
+        /**
  114
+         * Adds data to be encrypted or decrypted.
  115
+         *
  116
+         * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  117
+         *
  118
+         * @return {WordArray} The data after processing.
  119
+         *
  120
+         * @example
  121
+         *
  122
+         *     var encrypted = cipher.process('data');
  123
+         *     var encrypted = cipher.process(wordArray);
  124
+         */
  125
+        process: function (dataUpdate) {
  126
+            // Append
  127
+            this._append(dataUpdate);
  128
+
  129
+            // Process available blocks
  130
+            return this._process();
  131
+        },
  132
+
  133
+        /**
  134
+         * Finalizes the encryption or decryption process.
  135
+         * Note that the finalize operation is effectively a destructive, read-once operation.
  136
+         *
  137
+         * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  138
+         *
  139
+         * @return {WordArray} The data after final processing.
  140
+         *
  141
+         * @example
  142
+         *
  143
+         *     var encrypted = cipher.finalize();
  144
+         *     var encrypted = cipher.finalize('data');
  145
+         *     var encrypted = cipher.finalize(wordArray);
  146
+         */
  147
+        finalize: function (dataUpdate) {
  148
+            // Final data update
  149
+            if (dataUpdate) {
  150
+                this._append(dataUpdate);
  151
+            }
  152
+
  153
+            // Perform concrete-cipher logic
  154
+            var finalProcessedData = this._doFinalize();
  155
+
  156
+            return finalProcessedData;
  157
+        },
  158
+
  159
+        keySize: 128/32,
  160
+
  161
+        ivSize: 128/32,
  162
+
  163
+        _ENC_XFORM_MODE: 1,
  164
+
  165
+        _DEC_XFORM_MODE: 2,
  166
+
  167
+        /**
  168
+         * Creates shortcut functions to a cipher's object interface.
  169
+         *
  170
+         * @param {Cipher} cipher The cipher to create a helper for.
  171
+         *
  172
+         * @return {Object} An object with encrypt and decrypt shortcut functions.
  173
+         *
  174
+         * @static
  175
+         *
  176
+         * @example
  177
+         *
  178
+         *     var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  179
+         */
  180
+        _createHelper: (function () {
  181
+            function selectCipherStrategy(key) {
  182
+                if (typeof key == 'string') {
  183
+                    return PasswordBasedCipher;
  184
+                } else {
  185
+                    return SerializableCipher;
  186
+                }
  187
+            }
  188
+
  189
+            return function (cipher) {
  190
+                return {
  191
+                    encrypt: function (message, key, cfg) {
  192
+                        return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
  193
+                    },
  194
+
  195
+                    decrypt: function (ciphertext, key, cfg) {
  196
+                        return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
  197
+                    }
  198
+                };
  199
+            };
  200
+        }())
  201
+    });
  202
+
  203
+    /**
  204
+     * Abstract base stream cipher template.
  205
+     *
  206
+     * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
  207
+     */
  208
+    var StreamCipher = C_lib.StreamCipher = Cipher.extend({
  209
+        _doFinalize: function () {
  210
+            // Process partial blocks
  211
+            var finalProcessedBlocks = this._process(!!'flush');
  212
+
  213
+            return finalProcessedBlocks;
  214
+        },
  215
+
  216
+        blockSize: 1
  217
+    });
  218
+
  219
+    /**
  220
+     * Mode namespace.
  221
+     */
  222
+    var C_mode = C.mode = {};
  223
+
  224
+    /**
  225
+     * Abstract base block cipher mode template.
  226
+     */
  227
+    var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
  228
+        /**
  229
+         * Creates this mode for encryption.
  230
+         *
  231
+         * @param {Cipher} cipher A block cipher instance.
  232
+         * @param {Array} iv The IV words.
  233
+         *
  234
+         * @static
  235
+         *
  236
+         * @example
  237
+         *
  238
+         *     var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  239
+         */
  240
+        createEncryptor: function (cipher, iv) {
  241
+            return this.Encryptor.create(cipher, iv);
  242
+        },
  243
+
  244
+        /**
  245
+         * Creates this mode for decryption.
  246
+         *
  247
+         * @param {Cipher} cipher A block cipher instance.
  248
+         * @param {Array} iv The IV words.
  249
+         *
  250
+         * @static
  251
+         *
  252
+         * @example
  253
+         *
  254
+         *     var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  255
+         */
  256
+        createDecryptor: function (cipher, iv) {
  257
+            return this.Decryptor.create(cipher, iv);
  258
+        },
  259
+
  260
+        /**
  261
+         * Initializes a newly created mode.
  262
+         *
  263
+         * @param {Cipher} cipher A block cipher instance.
  264
+         * @param {Array} iv The IV words.
  265
+         *
  266
+         * @example
  267
+         *
  268
+         *     var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  269
+         */
  270
+        init: function (cipher, iv) {
  271
+            this._cipher = cipher;
  272
+            this._iv = iv;
  273
+        }
  274
+    });
  275
+
  276
+    /**
  277
+     * Cipher Block Chaining mode.
  278
+     */
  279
+    var CBC = C_mode.CBC = (function () {
  280
+        /**
  281
+         * Abstract base CBC mode.
  282
+         */
  283
+        var CBC = BlockCipherMode.extend();
  284
+
  285
+        /**
  286
+         * CBC encryptor.
  287
+         */
  288
+        CBC.Encryptor = CBC.extend({
  289
+            /**
  290
+             * Processes the data block at offset.
  291
+             *
  292
+             * @param {Array} words The data words to operate on.
  293
+             * @param {number} offset The offset where the block starts.
  294
+             *
  295
+             * @example
  296
+             *
  297
+             *     mode.processBlock(data.words, offset);
  298
+             */
  299
+            processBlock: function (words, offset) {
  300
+                // Shortcuts
  301
+                var cipher = this._cipher;
  302
+                var blockSize = cipher.blockSize;
  303
+
  304
+                // XOR and encrypt
  305
+                xorBlock.call(this, words, offset, blockSize);
  306
+                cipher.encryptBlock(words, offset);
  307
+
  308
+                // Remember this block to use with next block
  309
+                this._prevBlock = words.slice(offset, offset + blockSize);
  310
+            }
  311
+        });
  312
+
  313
+        /**
  314
+         * CBC decryptor.
  315
+         */
  316
+        CBC.Decryptor = CBC.extend({
  317
+            /**
  318
+             * Processes the data block at offset.
  319
+             *
  320
+             * @param {Array} words The data words to operate on.
  321
+             * @param {number} offset The offset where the block starts.
  322
+             *
  323
+             * @example
  324
+             *
  325
+             *     mode.processBlock(data.words, offset);
  326
+             */
  327
+            processBlock: function (words, offset) {
  328
+                // Shortcuts
  329
+                var cipher = this._cipher;
  330
+                var blockSize = cipher.blockSize;
  331
+
  332
+                // Remember this block to use with next block
  333
+                var thisBlock = words.slice(offset, offset + blockSize);
  334
+
  335
+                // Decrypt and XOR
  336
+                cipher.decryptBlock(words, offset);
  337
+                xorBlock.call(this, words, offset, blockSize);
  338
+
  339
+                // This block becomes the previous block
  340
+                this._prevBlock = thisBlock;
  341
+            }
  342
+        });
  343
+
  344
+        function xorBlock(words, offset, blockSize) {
  345
+            // Shortcut
  346
+            var iv = this._iv;
  347
+
  348
+            // Choose mixing block
  349
+            if (iv) {
  350
+                var block = iv;
  351
+
  352
+                // Remove IV for subsequent blocks
  353
+                this._iv = undefined;
  354
+            } else {
  355
+                var block = this._prevBlock;
  356
+            }
  357
+
  358
+            // XOR blocks
  359
+            for (var i = 0; i < blockSize; i++) {
  360
+                words[offset + i] ^= block[i];
  361
+            }
  362
+        }
  363
+
  364
+        return CBC;
  365
+    }());
  366
+
  367
+    /**
  368
+     * Padding namespace.
  369
+     */
  370
+    var C_pad = C.pad = {};
  371
+
  372
+    /**
  373
+     * PKCS #5/7 padding strategy.
  374
+     */
  375
+    var Pkcs7 = C_pad.Pkcs7 = {
  376
+        /**
  377
+         * Pads data using the algorithm defined in PKCS #5/7.
  378
+         *
  379
+         * @param {WordArray} data The data to pad.
  380
+         * @param {number} blockSize The multiple that the data should be padded to.
  381
+         *
  382
+         * @static
  383
+         *
  384
+         * @example
  385
+         *
  386
+         *     CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  387
+         */
  388
+        pad: function (data, blockSize) {
  389
+            // Shortcut
  390
+            var blockSizeBytes = blockSize * 4;
  391
+
  392
+            // Count padding bytes
  393
+            var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  394
+
  395
+            // Create padding word
  396
+            var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
  397
+
  398
+            // Create padding
  399
+            var paddingWords = [];
  400
+            for (var i = 0; i < nPaddingBytes; i += 4) {
  401
+                paddingWords.push(paddingWord);
  402
+            }
  403
+            var padding = WordArray.create(paddingWords, nPaddingBytes);
  404
+
  405
+            // Add padding
  406
+            data.concat(padding);
  407
+        },
  408
+
  409
+        /**
  410
+         * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  411
+         *
  412
+         * @param {WordArray} data The data to unpad.
  413
+         *
  414
+         * @static
  415
+         *
  416
+         * @example
  417
+         *
  418
+         *     CryptoJS.pad.Pkcs7.unpad(wordArray);
  419
+         */
  420
+        unpad: function (data) {
  421
+            // Get number of padding bytes from last byte
  422
+            var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  423
+
  424
+            // Remove padding
  425
+            data.sigBytes -= nPaddingBytes;
  426
+        }
  427
+    };
  428
+
  429
+    /**
  430
+     * Abstract base block cipher template.
  431
+     *
  432
+     * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
  433
+     */
  434
+    var BlockCipher = C_lib.BlockCipher = Cipher.extend({
  435
+        /**
  436
+         * Configuration options.
  437
+         *
  438
+         * @property {Mode} mode The block mode to use. Default: CBC
  439
+         * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  440
+         */
  441
+        cfg: Cipher.cfg.extend({
  442
+            mode: CBC,
  443
+            padding: Pkcs7
  444
+        }),
  445
+
  446
+        reset: function () {
  447
+            // Reset cipher
  448
+            Cipher.reset.call(this);
  449
+
  450
+            // Shortcuts
  451
+            var cfg = this.cfg;
  452
+            var iv = cfg.iv;
  453
+            var mode = cfg.mode;
  454
+
  455
+            // Reset block mode
  456
+            if (this._xformMode == this._ENC_XFORM_MODE) {
  457
+                var modeCreator = mode.createEncryptor;
  458
+            } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  459
+                var modeCreator = mode.createDecryptor;
  460
+
  461
+                // Keep at least one block in the buffer for unpadding
  462
+                this._minBufferSize = 1;
  463
+            }
  464
+            this._mode = modeCreator.call(mode, this, iv && iv.words);
  465
+        },
  466
+
  467
+        _doProcessBlock: function (words, offset) {
  468
+            this._mode.processBlock(words, offset);
  469
+        },
  470
+
  471
+        _doFinalize: function () {
  472
+            // Shortcut
  473
+            var padding = this.cfg.padding;
  474
+
  475
+            // Finalize
  476
+            if (this._xformMode == this._ENC_XFORM_MODE) {
  477
+                // Pad data
  478
+                padding.pad(this._data, this.blockSize);
  479
+
  480
+                // Process final blocks
  481
+                var finalProcessedBlocks = this._process(!!'flush');
  482
+            } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  483
+                // Process final blocks
  484
+                var finalProcessedBlocks = this._process(!!'flush');
  485
+
  486
+                // Unpad data
  487
+                padding.unpad(finalProcessedBlocks);
  488
+            }
  489
+
  490
+            return finalProcessedBlocks;
  491
+        },
  492
+
  493
+        blockSize: 128/32
  494
+    });
  495
+
  496
+    /**
  497
+     * A collection of cipher parameters.
  498
+     *
  499
+     * @property {WordArray} ciphertext The raw ciphertext.
  500
+     * @property {WordArray} key The key to this ciphertext.
  501
+     * @property {WordArray} iv The IV used in the ciphering operation.
  502
+     * @property {WordArray} salt The salt used with a key derivation function.
  503
+     * @property {Cipher} algorithm The cipher algorithm.
  504
+     * @property {Mode} mode The block mode used in the ciphering operation.
  505
+     * @property {Padding} padding The padding scheme used in the ciphering operation.
  506
+     * @property {number} blockSize The block size of the cipher.
  507
+     * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
  508
+     */
  509
+    var CipherParams = C_lib.CipherParams = Base.extend({
  510
+        /**
  511
+         * Initializes a newly created cipher params object.
  512
+         *
  513
+         * @param {Object} cipherParams An object with any of the possible cipher parameters.
  514
+         *
  515
+         * @example
  516
+         *
  517
+         *     var cipherParams = CryptoJS.lib.CipherParams.create({
  518
+         *         ciphertext: ciphertextWordArray,
  519
+         *         key: keyWordArray,
  520
+         *         iv: ivWordArray,
  521
+         *         salt: saltWordArray,
  522
+         *         algorithm: CryptoJS.algo.AES,
  523
+         *         mode: CryptoJS.mode.CBC,
  524
+         *         padding: CryptoJS.pad.PKCS7,
  525
+         *         blockSize: 4,
  526
+         *         formatter: CryptoJS.format.OpenSSL
  527
+         *     });
  528
+         */
  529
+        init: function (cipherParams) {
  530
+            this.mixIn(cipherParams);
  531
+        },
  532
+
  533
+        /**
  534
+         * Converts this cipher params object to a string.
  535
+         *
  536
+         * @param {Format} formatter (Optional) The formatting strategy to use.
  537
+         *
  538
+         * @return {string} The stringified cipher params.
  539
+         *
  540
+         * @throws Error If neither the formatter nor the default formatter is set.
  541
+         *
  542
+         * @example
  543
+         *
  544
+         *     var string = cipherParams + '';
  545
+         *     var string = cipherParams.toString();
  546
+         *     var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  547
+         */
  548
+        toString: function (formatter) {
  549
+            return (formatter || this.formatter).stringify(this);
  550
+        }
  551
+    });
  552
+
  553
+    /**
  554
+     * Format namespace.
  555
+     */
  556
+    var C_format = C.format = {};
  557
+
  558
+    /**
  559
+     * OpenSSL formatting strategy.
  560
+     */
  561
+    var OpenSSLFormatter = C_format.OpenSSL = {
  562
+        /**
  563
+         * Converts a cipher params object to an OpenSSL-compatible string.
  564
+         *
  565
+         * @param {CipherParams} cipherParams The cipher params object.
  566
+         *
  567
+         * @return {string} The OpenSSL-compatible string.
  568
+         *
  569
+         * @static
  570
+         *
  571
+         * @example
  572
+         *
  573
+         *     var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  574
+         */
  575
+        stringify: function (cipherParams) {
  576
+            // Shortcuts
  577
+            var ciphertext = cipherParams.ciphertext;
  578
+            var salt = cipherParams.salt;
  579
+
  580
+            // Format
  581
+            if (salt) {
  582
+                var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
  583
+            } else {
  584
+                var wordArray = ciphertext;
  585
+            }
  586
+
  587
+            return wordArray.toString(Base64);
  588
+        },
  589
+
  590
+        /**
  591
+         * Converts an OpenSSL-compatible string to a cipher params object.
  592
+         *
  593
+         * @param {string} openSSLStr The OpenSSL-compatible string.
  594
+         *
  595
+         * @return {CipherParams} The cipher params object.
  596
+         *
  597
+         * @static
  598
+         *
  599
+         * @example
  600
+         *
  601
+         *     var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  602
+         */
  603
+        parse: function (openSSLStr) {
  604
+            // Parse base64
  605
+            var ciphertext = Base64.parse(openSSLStr);
  606
+
  607
+            // Shortcut
  608
+            var ciphertextWords = ciphertext.words;
  609
+
  610
+            // Test for salt
  611
+            if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
  612
+                // Extract salt
  613
+                var salt = WordArray.create(ciphertextWords.slice(2, 4));
  614
+
  615
+                // Remove salt from ciphertext
  616
+                ciphertextWords.splice(0, 4);
  617
+                ciphertext.sigBytes -= 16;
  618
+            }
  619
+
  620
+            return CipherParams.create({ ciphertext: ciphertext, salt: salt });
  621
+        }
  622
+    };
  623
+
  624
+    /**
  625
+     * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  626
+     */
  627
+    var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  628
+        /**
  629
+         * Configuration options.
  630
+         *
  631
+         * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  632
+         */
  633
+        cfg: Base.extend({
  634
+            format: OpenSSLFormatter
  635
+        }),
  636
+
  637
+        /**
  638
+         * Encrypts a message.
  639
+         *
  640
+         * @param {Cipher} cipher The cipher algorithm to use.
  641
+         * @param {WordArray|string} message The message to encrypt.
  642
+         * @param {WordArray} key The key.
  643
+         * @param {Object} cfg (Optional) The configuration options to use for this operation.
  644
+         *
  645
+         * @return {CipherParams} A cipher params object.
  646
+         *
  647
+         * @static
  648
+         *
  649
+         * @example
  650
+         *
  651
+         *     var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  652
+         *     var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  653
+         *     var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  654
+         */
  655
+        encrypt: function (cipher, message, key, cfg) {
  656
+            // Apply config defaults
  657
+            cfg = this.cfg.extend(cfg);
  658
+
  659
+            // Encrypt
  660
+            var encryptor = cipher.createEncryptor(key, cfg);
  661
+            var ciphertext = encryptor.finalize(message);
  662
+
  663
+            // Shortcut
  664
+            var cipherCfg = encryptor.cfg;
  665
+
  666
+            // Create and return serializable cipher params
  667
+            return CipherParams.create({
  668
+                ciphertext: ciphertext,
  669
+                key: key,
  670
+                iv: cipherCfg.iv,
  671
+                algorithm: cipher,
  672
+                mode: cipherCfg.mode,
  673
+                padding: cipherCfg.padding,
  674
+                blockSize: cipher.blockSize,
  675
+                formatter: cfg.format
  676
+            });
  677
+        },
  678
+
  679
+        /**
  680
+         * Decrypts serialized ciphertext.
  681
+         *
  682
+         * @param {Cipher} cipher The cipher algorithm to use.
  683
+         * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  684
+         * @param {WordArray} key The key.
  685
+         * @param {Object} cfg (Optional) The configuration options to use for this operation.
  686
+         *
  687
+         * @return {WordArray} The plaintext.
  688
+         *
  689
+         * @static
  690
+         *
  691
+         * @example
  692
+         *
  693
+         *     var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  694
+         *     var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  695
+         */
  696
+        decrypt: function (cipher, ciphertext, key, cfg) {
  697
+            // Apply config defaults
  698
+            cfg = this.cfg.extend(cfg);
  699
+
  700
+            // Convert string to CipherParams
  701
+            ciphertext = this._parse(ciphertext, cfg.format);
  702
+
  703
+            // Decrypt
  704
+            var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  705
+
  706
+            return plaintext;
  707
+        },
  708
+
  709
+        /**
  710
+         * Converts serialized ciphertext to CipherParams,
  711
+         * else assumed CipherParams already and returns ciphertext unchanged.
  712
+         *
  713
+         * @param {CipherParams|string} ciphertext The ciphertext.
  714
+         * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  715
+         *
  716
+         * @return {CipherParams} The unserialized ciphertext.
  717
+         *
  718
+         * @static
  719
+         *
  720
+         * @example
  721
+         *
  722
+         *     var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  723
+         */
  724
+        _parse: function (ciphertext, format) {
  725
+            if (typeof ciphertext == 'string') {
  726
+                return format.parse(ciphertext, this);
  727
+            } else {
  728
+                return ciphertext;
  729
+            }
  730
+        }
  731
+    });
  732
+
  733
+    /**
  734
+     * Key derivation function namespace.
  735
+     */
  736
+    var C_kdf = C.kdf = {};
  737
+
  738
+    /**
  739
+     * OpenSSL key derivation function.
  740
+     */
  741
+    var OpenSSLKdf = C_kdf.OpenSSL = {
  742
+        /**
  743
+         * Derives a key and IV from a password.
  744
+         *
  745
+         * @param {string} password The password to derive from.
  746
+         * @param {number} keySize The size in words of the key to generate.
  747
+         * @param {number} ivSize The size in words of the IV to generate.
  748
+         * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  749
+         *
  750
+         * @return {CipherParams} A cipher params object with the key, IV, and salt.
  751
+         *
  752
+         * @static
  753
+         *
  754
+         * @example
  755
+         *
  756
+         *     var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  757
+         *     var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  758
+         */
  759
+        execute: function (password, keySize, ivSize, salt) {
  760
+            // Generate random salt
  761
+            if (!salt) {
  762
+                salt = WordArray.random(64/8);
  763
+            }
  764
+
  765
+            // Derive key and IV
  766
+            var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
  767
+
  768
+            // Separate key and IV
  769
+            var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  770
+            key.sigBytes = keySize * 4;
  771
+
  772
+            // Return params
  773
+            return CipherParams.create({ key: key, iv: iv, salt: salt });
  774
+        }
  775
+    };
  776
+
  777
+    /**
  778
+     * A serializable cipher wrapper that derives the key from a password,
  779
+     * and returns ciphertext as a serializable cipher params object.
  780
+     */
  781
+    var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  782
+        /**
  783
+         * Configuration options.
  784
+         *
  785
+         * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  786
+         */
  787
+        cfg: SerializableCipher.cfg.extend({
  788
+            kdf: OpenSSLKdf
  789
+        }),
  790
+
  791
+        /**
  792
+         * Encrypts a message using a password.
  793
+         *
  794
+         * @param {Cipher} cipher The cipher algorithm to use.
  795
+         * @param {WordArray|string} message The message to encrypt.
  796
+         * @param {string} password The password.
  797
+         * @param {Object} cfg (Optional) The configuration options to use for this operation.
  798
+         *
  799
+         * @return {CipherParams} A cipher params object.
  800
+         *
  801
+         * @static
  802
+         *
  803
+         * @example
  804
+         *
  805
+         *     var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  806
+         *     var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  807
+         */
  808
+        encrypt: function (cipher, message, password, cfg) {
  809
+            // Apply config defaults
  810
+            cfg = this.cfg.extend(cfg);
  811
+
  812
+            // Derive key and other params
  813
+            var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
  814
+
  815
+            // Add IV to config
  816
+            cfg.iv = derivedParams.iv;
  817
+
  818
+            // Encrypt
  819
+            var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  820
+
  821
+            // Mix in derived params
  822
+            ciphertext.mixIn(derivedParams);
  823
+
  824
+            return ciphertext;
  825
+        },
  826
+
  827
+        /**
  828
+         * Decrypts serialized ciphertext using a password.
  829
+         *
  830
+         * @param {Cipher} cipher The cipher algorithm to use.
  831
+         * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  832
+         * @param {string} password The password.
  833
+         * @param {Object} cfg (Optional) The configuration options to use for this operation.
  834
+         *
  835
+         * @return {WordArray} The plaintext.
  836
+         *
  837
+         * @static
  838
+         *
  839
+         * @example
  840
+         *
  841
+         *     var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  842
+         *     var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  843
+         */
  844
+        decrypt: function (cipher, ciphertext, password, cfg) {
  845
+            // Apply config defaults
  846
+            cfg = this.cfg.extend(cfg);
  847
+
  848
+            // Convert string to CipherParams
  849
+            ciphertext = this._parse(ciphertext, cfg.format);
  850
+
  851
+            // Derive key and other params