@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
package/.jshintrc
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"bitwise": false, // Prohibits the use of bitwise operators (not confuse & with &&)
|
3
|
+
"curly": true, // Requires to always put curly braces around blocks in loops and conditionals
|
4
|
+
"eqeqeq": false, // Prohibits the use of == and != in favor of === and !==
|
5
|
+
"eqnull": true, // Suppresses warnings about == null comparisons
|
6
|
+
"immed": true, // Requires immediate invocations to be wrapped in parens e.g. `(function () { } ());`
|
7
|
+
"latedef": false, // Prohibits the use of a variable before it was defined
|
8
|
+
"newcap": false, // Requires to capitalize names of constructor functions
|
9
|
+
"noarg": true, // Prohibits the use of arguments.caller and arguments.callee
|
10
|
+
"strict": false, // Requires all functions to run in ECMAScript 5's strict mode
|
11
|
+
"undef": true, // Require non-global variables to be declared (prevents global leaks)
|
12
|
+
"asi": true, // Suppresses warnings about missing semicolons
|
13
|
+
"funcscope": false,
|
14
|
+
"shadow": true,
|
15
|
+
"expr": true,
|
16
|
+
"-W041": true,
|
17
|
+
"-W018": true,
|
18
|
+
"globals": {
|
19
|
+
"CryptoJS": true,
|
20
|
+
"escape": true,
|
21
|
+
"unescape": true,
|
22
|
+
"Int8Array": true,
|
23
|
+
"Int16Array": true,
|
24
|
+
"Int32Array": true,
|
25
|
+
"Uint8Array": true,
|
26
|
+
"Uint16Array": true,
|
27
|
+
"Uint32Array": true,
|
28
|
+
"Uint8ClampedArray": true,
|
29
|
+
"ArrayBuffer": true,
|
30
|
+
"Float32Array": true,
|
31
|
+
"Float64Array": true
|
32
|
+
}
|
33
|
+
}
|
package/.travis.yml
ADDED
package/CONTRIBUTING.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Contribution
|
2
|
+
|
3
|
+
# Git Flow
|
4
|
+
|
5
|
+
The crypto-js project uses [git flow](https://github.com/nvie/gitflow) to manage branches.
|
6
|
+
Do your changes on the `develop` or even better on a `feature/*` branch. Don't do any changes on the `master` branch.
|
7
|
+
|
8
|
+
# Pull request
|
9
|
+
|
10
|
+
Target your pull request on `develop` branch. Other pull request won't be accepted.
|
11
|
+
|
12
|
+
# How to build
|
13
|
+
|
14
|
+
1. Clone
|
15
|
+
|
16
|
+
2. Run
|
17
|
+
|
18
|
+
```sh
|
19
|
+
npm install
|
20
|
+
```
|
21
|
+
|
22
|
+
3. Run
|
23
|
+
|
24
|
+
```sh
|
25
|
+
npm run build
|
26
|
+
```
|
27
|
+
|
28
|
+
4. Check `build` folder
|
package/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# License
|
2
|
+
|
3
|
+
[The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
4
|
+
|
5
|
+
Copyright (c) 2009-2013 Jeff Mott
|
6
|
+
Copyright (c) 2013-2016 Evan Vosberg
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
10
|
+
in the Software without restriction, including without limitation the rights
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
13
|
+
furnished to do so, subject to the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
16
|
+
all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
@@ -1,5 +1,275 @@
|
|
1
|
-
#
|
1
|
+
# @brix-crypto/crypto-js
|
2
|
+
|
3
|
+
JavaScript library of crypto standards.
|
4
|
+
|
5
|
+
## Discontinued
|
6
|
+
|
7
|
+
Active development of CryptoJS has been discontinued. This library is no longer maintained.
|
8
|
+
|
9
|
+
Nowadays, NodeJS and modern browsers have a native `Crypto` module. The latest version of CryptoJS already uses the native Crypto module for random number generation, since `Math.random()` is not crypto-safe. Further development of CryptoJS would result in it only being a wrapper of native Crypto. Therefore, development and maintenance has been discontinued, it is time to go for the native `crypto` module.
|
10
|
+
|
11
|
+
## Node.js (Install)
|
12
|
+
|
13
|
+
Requirements:
|
14
|
+
|
15
|
+
- Node.js
|
16
|
+
- npm (Node.js package manager)
|
17
|
+
|
18
|
+
```bash
|
19
|
+
npm install @brix-crypto/crypto-js
|
20
|
+
```
|
21
|
+
|
22
|
+
### Usage
|
23
|
+
|
24
|
+
ES6 import for typical API call signing use case:
|
25
|
+
|
26
|
+
```javascript
|
27
|
+
import sha256 from '@brix-crypto/crypto-js/sha256';
|
28
|
+
import hmacSHA512 from '@brix-crypto/crypto-js/hmac-sha512';
|
29
|
+
import Base64 from '@brix-crypto/crypto-js/enc-base64';
|
30
|
+
|
31
|
+
const message, nonce, path, privateKey; // ...
|
32
|
+
const hashDigest = sha256(nonce + message);
|
33
|
+
const hmacDigest = Base64.stringify(hmacSHA512(path + hashDigest, privateKey));
|
34
|
+
```
|
35
|
+
|
36
|
+
Modular include:
|
37
|
+
|
38
|
+
```javascript
|
39
|
+
var AES = require("@brix-crypto/crypto-js/aes");
|
40
|
+
var SHA256 = require("@brix-crypto/crypto-js/sha256");
|
41
|
+
...
|
42
|
+
console.log(SHA256("Message"));
|
43
|
+
```
|
44
|
+
|
45
|
+
Including all libraries, for access to extra methods:
|
46
|
+
|
47
|
+
```javascript
|
48
|
+
var CryptoJS = require("@brix-crypto/crypto-js");
|
49
|
+
console.log(CryptoJS.HmacSHA1("Message", "Key"));
|
50
|
+
```
|
51
|
+
|
52
|
+
## Client (browser)
|
53
|
+
|
54
|
+
Requirements:
|
55
|
+
|
56
|
+
- Node.js
|
57
|
+
- Bower (package manager for frontend)
|
58
|
+
|
59
|
+
```bash
|
60
|
+
bower install @brix-crypto/crypto-js
|
61
|
+
```
|
62
|
+
|
63
|
+
### Usage
|
64
|
+
|
65
|
+
Modular include:
|
66
|
+
|
67
|
+
```javascript
|
68
|
+
require.config({
|
69
|
+
packages: [
|
70
|
+
{
|
71
|
+
name: '@brix-crypto/crypto-js',
|
72
|
+
location: 'path-to/bower_components/@brix-crypto/crypto-js',
|
73
|
+
main: 'index'
|
74
|
+
}
|
75
|
+
]
|
76
|
+
});
|
77
|
+
|
78
|
+
require(["@brix-crypto/crypto-js/aes", "@brix-crypto/crypto-js/sha256"], function (AES, SHA256) {
|
79
|
+
console.log(SHA256("Message"));
|
80
|
+
});
|
81
|
+
```
|
82
|
+
|
83
|
+
Including all libraries, for access to extra methods:
|
84
|
+
|
85
|
+
```javascript
|
86
|
+
// Above-mentioned will work or use this simple form
|
87
|
+
require.config({
|
88
|
+
paths: {
|
89
|
+
'@brix-crypto/crypto-js': 'path-to/bower_components/@brix-crypto/crypto-js/crypto-js'
|
90
|
+
}
|
91
|
+
});
|
92
|
+
|
93
|
+
require(["@brix-crypto/crypto-js"], function (CryptoJS) {
|
94
|
+
console.log(CryptoJS.HmacSHA1("Message", "Key"));
|
95
|
+
});
|
96
|
+
```
|
97
|
+
|
98
|
+
### Usage without RequireJS
|
99
|
+
|
100
|
+
```html
|
101
|
+
<script type="text/javascript" src="path-to/bower_components/@brix-crypto/crypto-js/crypto-js.js"></script>
|
102
|
+
<script type="text/javascript">
|
103
|
+
var encrypted = CryptoJS.AES(...);
|
104
|
+
var encrypted = CryptoJS.SHA256(...);
|
105
|
+
</script>
|
106
|
+
```
|
107
|
+
|
108
|
+
## API
|
109
|
+
|
110
|
+
See: https://cryptojs.gitbook.io/docs/
|
111
|
+
|
112
|
+
### AES Encryption
|
113
|
+
|
114
|
+
#### Plain text encryption
|
115
|
+
|
116
|
+
```javascript
|
117
|
+
var CryptoJS = require("@brix-crypto/crypto-js");
|
118
|
+
|
119
|
+
// Encrypt
|
120
|
+
var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123').toString();
|
121
|
+
|
122
|
+
// Decrypt
|
123
|
+
var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
|
124
|
+
var originalText = bytes.toString(CryptoJS.enc.Utf8);
|
125
|
+
|
126
|
+
console.log(originalText); // 'my message'
|
127
|
+
```
|
128
|
+
|
129
|
+
#### Object encryption
|
130
|
+
|
131
|
+
```javascript
|
132
|
+
var CryptoJS = require("@brix-crypto/crypto-js");
|
133
|
+
|
134
|
+
var data = [{id: 1}, {id: 2}]
|
135
|
+
|
136
|
+
// Encrypt
|
137
|
+
var ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123').toString();
|
138
|
+
|
139
|
+
// Decrypt
|
140
|
+
var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
|
141
|
+
var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
|
142
|
+
|
143
|
+
console.log(decryptedData); // [{id: 1}, {id: 2}]
|
144
|
+
```
|
145
|
+
|
146
|
+
### List of modules
|
147
|
+
|
148
|
+
|
149
|
+
- ```@brix-crypto/crypto-js/core```
|
150
|
+
- ```@brix-crypto/crypto-js/x64-core```
|
151
|
+
- ```@brix-crypto/crypto-js/lib-typedarrays```
|
152
|
+
|
153
|
+
---
|
154
|
+
|
155
|
+
- ```@brix-crypto/crypto-js/md5```
|
156
|
+
- ```@brix-crypto/crypto-js/sha1```
|
157
|
+
- ```@brix-crypto/crypto-js/sha256```
|
158
|
+
- ```@brix-crypto/crypto-js/sha224```
|
159
|
+
- ```@brix-crypto/crypto-js/sha512```
|
160
|
+
- ```@brix-crypto/crypto-js/sha384```
|
161
|
+
- ```@brix-crypto/crypto-js/sha3```
|
162
|
+
- ```@brix-crypto/crypto-js/ripemd160```
|
163
|
+
|
164
|
+
---
|
165
|
+
|
166
|
+
- ```@brix-crypto/crypto-js/hmac-md5```
|
167
|
+
- ```@brix-crypto/crypto-js/hmac-sha1```
|
168
|
+
- ```@brix-crypto/crypto-js/hmac-sha256```
|
169
|
+
- ```@brix-crypto/crypto-js/hmac-sha224```
|
170
|
+
- ```@brix-crypto/crypto-js/hmac-sha512```
|
171
|
+
- ```@brix-crypto/crypto-js/hmac-sha384```
|
172
|
+
- ```@brix-crypto/crypto-js/hmac-sha3```
|
173
|
+
- ```@brix-crypto/crypto-js/hmac-ripemd160```
|
174
|
+
|
175
|
+
---
|
176
|
+
|
177
|
+
- ```@brix-crypto/crypto-js/pbkdf2```
|
178
|
+
|
179
|
+
---
|
180
|
+
|
181
|
+
- ```@brix-crypto/crypto-js/aes```
|
182
|
+
- ```@brix-crypto/crypto-js/tripledes```
|
183
|
+
- ```@brix-crypto/crypto-js/rc4```
|
184
|
+
- ```@brix-crypto/crypto-js/rabbit```
|
185
|
+
- ```@brix-crypto/crypto-js/rabbit-legacy```
|
186
|
+
- ```@brix-crypto/crypto-js/evpkdf```
|
187
|
+
|
188
|
+
---
|
189
|
+
|
190
|
+
- ```@brix-crypto/crypto-js/format-openssl```
|
191
|
+
- ```@brix-crypto/crypto-js/format-hex```
|
192
|
+
|
193
|
+
---
|
194
|
+
|
195
|
+
- ```@brix-crypto/crypto-js/enc-latin1```
|
196
|
+
- ```@brix-crypto/crypto-js/enc-utf8```
|
197
|
+
- ```@brix-crypto/crypto-js/enc-hex```
|
198
|
+
- ```@brix-crypto/crypto-js/enc-utf16```
|
199
|
+
- ```@brix-crypto/crypto-js/enc-base64```
|
200
|
+
|
201
|
+
---
|
202
|
+
|
203
|
+
- ```@brix-crypto/crypto-js/mode-cfb```
|
204
|
+
- ```@brix-crypto/crypto-js/mode-ctr```
|
205
|
+
- ```@brix-crypto/crypto-js/mode-ctr-gladman```
|
206
|
+
- ```@brix-crypto/crypto-js/mode-ofb```
|
207
|
+
- ```@brix-crypto/crypto-js/mode-ecb```
|
208
|
+
|
209
|
+
---
|
210
|
+
|
211
|
+
- ```@brix-crypto/crypto-js/pad-pkcs7```
|
212
|
+
- ```@brix-crypto/crypto-js/pad-ansix923```
|
213
|
+
- ```@brix-crypto/crypto-js/pad-iso10126```
|
214
|
+
- ```@brix-crypto/crypto-js/pad-iso97971```
|
215
|
+
- ```@brix-crypto/crypto-js/pad-zeropadding```
|
216
|
+
- ```@brix-crypto/crypto-js/pad-nopadding```
|
217
|
+
|
218
|
+
|
219
|
+
## Release notes
|
220
|
+
|
221
|
+
### 4.2.0
|
222
|
+
|
223
|
+
Change default hash algorithm and iteration's for PBKDF2 to prevent weak security by using the default configuration.
|
224
|
+
|
225
|
+
Custom KDF Hasher
|
226
|
+
|
227
|
+
Blowfish support
|
228
|
+
|
229
|
+
### 4.1.1
|
230
|
+
|
231
|
+
Fix module order in bundled release.
|
232
|
+
|
233
|
+
Include the browser field in the released package.json.
|
234
|
+
|
235
|
+
### 4.1.0
|
236
|
+
|
237
|
+
Added url safe variant of base64 encoding. [357](https://github.com/brix/crypto-js/pull/357)
|
238
|
+
|
239
|
+
Avoid webpack to add crypto-browser package. [364](https://github.com/brix/crypto-js/pull/364)
|
240
|
+
|
241
|
+
### 4.0.0
|
242
|
+
|
243
|
+
This is an update including breaking changes for some environments.
|
244
|
+
|
245
|
+
In this version `Math.random()` has been replaced by the random methods of the native crypto module.
|
246
|
+
|
247
|
+
For this reason CryptoJS might not run in some JavaScript environments without native crypto module. Such as IE 10 or before or React Native.
|
248
|
+
|
249
|
+
### 3.3.0
|
250
|
+
|
251
|
+
Rollback, `3.3.0` is the same as `3.1.9-1`.
|
252
|
+
|
253
|
+
The move of using native secure crypto module will be shifted to a new `4.x.x` version. As it is a breaking change the impact is too big for a minor release.
|
254
|
+
|
255
|
+
### 3.2.1
|
256
|
+
|
257
|
+
The usage of the native crypto module has been fixed. The import and access of the native crypto module has been improved.
|
258
|
+
|
259
|
+
### 3.2.0
|
260
|
+
|
261
|
+
In this version `Math.random()` has been replaced by the random methods of the native crypto module.
|
262
|
+
|
263
|
+
For this reason CryptoJS might does not run in some JavaScript environments without native crypto module. Such as IE 10 or before.
|
264
|
+
|
265
|
+
If it's absolute required to run CryptoJS in such an environment, stay with `3.1.x` version. Encrypting and decrypting stays compatible. But keep in mind `3.1.x` versions still use `Math.random()` which is cryptographically not secure, as it's not random enough.
|
266
|
+
|
267
|
+
This version came along with `CRITICAL` `BUG`.
|
268
|
+
|
269
|
+
DO NOT USE THIS VERSION! Please, go for a newer version!
|
270
|
+
|
271
|
+
### 3.1.x
|
272
|
+
|
273
|
+
The `3.1.x` are based on the original CryptoJS, wrapped in CommonJS modules.
|
2
274
|
|
3
|
-
This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
|
4
275
|
|
5
|
-
Please refer to www.npmjs.com/advisories?search=%40brix-crypto%2Fcrypto-js for more information.
|
package/aes.js
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
;(function (root, factory, undef) {
|
2
|
+
if (typeof exports === "object") {
|
3
|
+
// CommonJS
|
4
|
+
module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
|
5
|
+
}
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
7
|
+
// AMD
|
8
|
+
define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], 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 BlockCipher = C_lib.BlockCipher;
|
21
|
+
var C_algo = C.algo;
|
22
|
+
|
23
|
+
// Lookup tables
|
24
|
+
var SBOX = [];
|
25
|
+
var INV_SBOX = [];
|
26
|
+
var SUB_MIX_0 = [];
|
27
|
+
var SUB_MIX_1 = [];
|
28
|
+
var SUB_MIX_2 = [];
|
29
|
+
var SUB_MIX_3 = [];
|
30
|
+
var INV_SUB_MIX_0 = [];
|
31
|
+
var INV_SUB_MIX_1 = [];
|
32
|
+
var INV_SUB_MIX_2 = [];
|
33
|
+
var INV_SUB_MIX_3 = [];
|
34
|
+
|
35
|
+
// Compute lookup tables
|
36
|
+
(function () {
|
37
|
+
// Compute double table
|
38
|
+
var d = [];
|
39
|
+
for (var i = 0; i < 256; i++) {
|
40
|
+
if (i < 128) {
|
41
|
+
d[i] = i << 1;
|
42
|
+
} else {
|
43
|
+
d[i] = (i << 1) ^ 0x11b;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
// Walk GF(2^8)
|
48
|
+
var x = 0;
|
49
|
+
var xi = 0;
|
50
|
+
for (var i = 0; i < 256; i++) {
|
51
|
+
// Compute sbox
|
52
|
+
var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
|
53
|
+
sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
|
54
|
+
SBOX[x] = sx;
|
55
|
+
INV_SBOX[sx] = x;
|
56
|
+
|
57
|
+
// Compute multiplication
|
58
|
+
var x2 = d[x];
|
59
|
+
var x4 = d[x2];
|
60
|
+
var x8 = d[x4];
|
61
|
+
|
62
|
+
// Compute sub bytes, mix columns tables
|
63
|
+
var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
|
64
|
+
SUB_MIX_0[x] = (t << 24) | (t >>> 8);
|
65
|
+
SUB_MIX_1[x] = (t << 16) | (t >>> 16);
|
66
|
+
SUB_MIX_2[x] = (t << 8) | (t >>> 24);
|
67
|
+
SUB_MIX_3[x] = t;
|
68
|
+
|
69
|
+
// Compute inv sub bytes, inv mix columns tables
|
70
|
+
var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
|
71
|
+
INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
|
72
|
+
INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
|
73
|
+
INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
|
74
|
+
INV_SUB_MIX_3[sx] = t;
|
75
|
+
|
76
|
+
// Compute next counter
|
77
|
+
if (!x) {
|
78
|
+
x = xi = 1;
|
79
|
+
} else {
|
80
|
+
x = x2 ^ d[d[d[x8 ^ x2]]];
|
81
|
+
xi ^= d[d[xi]];
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}());
|
85
|
+
|
86
|
+
// Precomputed Rcon lookup
|
87
|
+
var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
|
88
|
+
|
89
|
+
/**
|
90
|
+
* AES block cipher algorithm.
|
91
|
+
*/
|
92
|
+
var AES = C_algo.AES = BlockCipher.extend({
|
93
|
+
_doReset: function () {
|
94
|
+
var t;
|
95
|
+
|
96
|
+
// Skip reset of nRounds has been set before and key did not change
|
97
|
+
if (this._nRounds && this._keyPriorReset === this._key) {
|
98
|
+
return;
|
99
|
+
}
|
100
|
+
|
101
|
+
// Shortcuts
|
102
|
+
var key = this._keyPriorReset = this._key;
|
103
|
+
var keyWords = key.words;
|
104
|
+
var keySize = key.sigBytes / 4;
|
105
|
+
|
106
|
+
// Compute number of rounds
|
107
|
+
var nRounds = this._nRounds = keySize + 6;
|
108
|
+
|
109
|
+
// Compute number of key schedule rows
|
110
|
+
var ksRows = (nRounds + 1) * 4;
|
111
|
+
|
112
|
+
// Compute key schedule
|
113
|
+
var keySchedule = this._keySchedule = [];
|
114
|
+
for (var ksRow = 0; ksRow < ksRows; ksRow++) {
|
115
|
+
if (ksRow < keySize) {
|
116
|
+
keySchedule[ksRow] = keyWords[ksRow];
|
117
|
+
} else {
|
118
|
+
t = keySchedule[ksRow - 1];
|
119
|
+
|
120
|
+
if (!(ksRow % keySize)) {
|
121
|
+
// Rot word
|
122
|
+
t = (t << 8) | (t >>> 24);
|
123
|
+
|
124
|
+
// Sub word
|
125
|
+
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
126
|
+
|
127
|
+
// Mix Rcon
|
128
|
+
t ^= RCON[(ksRow / keySize) | 0] << 24;
|
129
|
+
} else if (keySize > 6 && ksRow % keySize == 4) {
|
130
|
+
// Sub word
|
131
|
+
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
132
|
+
}
|
133
|
+
|
134
|
+
keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
// Compute inv key schedule
|
139
|
+
var invKeySchedule = this._invKeySchedule = [];
|
140
|
+
for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
|
141
|
+
var ksRow = ksRows - invKsRow;
|
142
|
+
|
143
|
+
if (invKsRow % 4) {
|
144
|
+
var t = keySchedule[ksRow];
|
145
|
+
} else {
|
146
|
+
var t = keySchedule[ksRow - 4];
|
147
|
+
}
|
148
|
+
|
149
|
+
if (invKsRow < 4 || ksRow <= 4) {
|
150
|
+
invKeySchedule[invKsRow] = t;
|
151
|
+
} else {
|
152
|
+
invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
|
153
|
+
INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
|
154
|
+
}
|
155
|
+
}
|
156
|
+
},
|
157
|
+
|
158
|
+
encryptBlock: function (M, offset) {
|
159
|
+
this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
|
160
|
+
},
|
161
|
+
|
162
|
+
decryptBlock: function (M, offset) {
|
163
|
+
// Swap 2nd and 4th rows
|
164
|
+
var t = M[offset + 1];
|
165
|
+
M[offset + 1] = M[offset + 3];
|
166
|
+
M[offset + 3] = t;
|
167
|
+
|
168
|
+
this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
|
169
|
+
|
170
|
+
// Inv swap 2nd and 4th rows
|
171
|
+
var t = M[offset + 1];
|
172
|
+
M[offset + 1] = M[offset + 3];
|
173
|
+
M[offset + 3] = t;
|
174
|
+
},
|
175
|
+
|
176
|
+
_doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
|
177
|
+
// Shortcut
|
178
|
+
var nRounds = this._nRounds;
|
179
|
+
|
180
|
+
// Get input, add round key
|
181
|
+
var s0 = M[offset] ^ keySchedule[0];
|
182
|
+
var s1 = M[offset + 1] ^ keySchedule[1];
|
183
|
+
var s2 = M[offset + 2] ^ keySchedule[2];
|
184
|
+
var s3 = M[offset + 3] ^ keySchedule[3];
|
185
|
+
|
186
|
+
// Key schedule row counter
|
187
|
+
var ksRow = 4;
|
188
|
+
|
189
|
+
// Rounds
|
190
|
+
for (var round = 1; round < nRounds; round++) {
|
191
|
+
// Shift rows, sub bytes, mix columns, add round key
|
192
|
+
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++];
|
193
|
+
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++];
|
194
|
+
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++];
|
195
|
+
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++];
|
196
|
+
|
197
|
+
// Update state
|
198
|
+
s0 = t0;
|
199
|
+
s1 = t1;
|
200
|
+
s2 = t2;
|
201
|
+
s3 = t3;
|
202
|
+
}
|
203
|
+
|
204
|
+
// Shift rows, sub bytes, add round key
|
205
|
+
var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
|
206
|
+
var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
|
207
|
+
var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
|
208
|
+
var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
|
209
|
+
|
210
|
+
// Set output
|
211
|
+
M[offset] = t0;
|
212
|
+
M[offset + 1] = t1;
|
213
|
+
M[offset + 2] = t2;
|
214
|
+
M[offset + 3] = t3;
|
215
|
+
},
|
216
|
+
|
217
|
+
keySize: 256/32
|
218
|
+
});
|
219
|
+
|
220
|
+
/**
|
221
|
+
* Shortcut functions to the cipher's object interface.
|
222
|
+
*
|
223
|
+
* @example
|
224
|
+
*
|
225
|
+
* var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
|
226
|
+
* var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
|
227
|
+
*/
|
228
|
+
C.AES = BlockCipher._createHelper(AES);
|
229
|
+
}());
|
230
|
+
|
231
|
+
|
232
|
+
return CryptoJS.AES;
|
233
|
+
|
234
|
+
}));
|