Skip to content

Commit 914b89b

Browse files
author
evanvosberg
committed
Merge branch 'release/3.1.3'
2 parents 8d4a2d3 + 6a60715 commit 914b89b

File tree

259 files changed

+12880
-19392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+12880
-19392
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,95 @@ require("crypto-js", function (CryptoJS) {
5050

5151
See: https://code.google.com/p/crypto-js
5252

53+
### List of modules
54+
55+
56+
- ```crypto-js/core```
57+
- ```crypto-js/x64-core```
58+
- ```crypto-js/lib-typedarrays```
59+
60+
---
61+
62+
- ```crypto-js/md5```
63+
- ```crypto-js/sha1```
64+
- ```crypto-js/sha256```
65+
- ```crypto-js/sha224```
66+
- ```crypto-js/sha512```
67+
- ```crypto-js/sha384```
68+
- ```crypto-js/sha3```
69+
- ```crypto-js/ripemd160```
70+
71+
---
72+
73+
- ```crypto-js/hmac-md5```
74+
- ```crypto-js/hmac-sha1```
75+
- ```crypto-js/hmac-sha256```
76+
- ```crypto-js/hmac-sha224```
77+
- ```crypto-js/hmac-sha512```
78+
- ```crypto-js/hmac-sha384```
79+
- ```crypto-js/hmac-sha3```
80+
- ```crypto-js/hmac-ripemd160```
81+
82+
---
83+
84+
- ```crypto-js/pbkdf2```
85+
86+
---
87+
88+
- ```crypto-js/aes```
89+
- ```crypto-js/tripledes```
90+
- ```crypto-js/rc4```
91+
- ```crypto-js/rabbit```
92+
- ```crypto-js/rabbit-legacy```
93+
- ```crypto-js/evpkdf```
94+
95+
---
96+
97+
- ```crypto-js/format-openssl```
98+
- ```crypto-js/format-hex```
99+
100+
---
101+
102+
- ```crypto-js/enc-latin1```
103+
- ```crypto-js/enc-utf8```
104+
- ```crypto-js/enc-hex```
105+
- ```crypto-js/enc-utf16```
106+
- ```crypto-js/enc-base64```
107+
108+
---
109+
110+
- ```crypto-js/mode-cfb```
111+
- ```crypto-js/mode-ctr```
112+
- ```crypto-js/mode-ctr-gladman```
113+
- ```crypto-js/mode-ofb```
114+
- ```crypto-js/mode-ecb```
115+
116+
---
117+
118+
- ```crypto-js/pad-pkcs7```
119+
- ```crypto-js/pad-ansix923```
120+
- ```crypto-js/pad-iso10126```
121+
- ```crypto-js/pad-iso97971```
122+
- ```crypto-js/pad-zeropadding```
123+
- ```crypto-js/pad-nopadding```
124+
125+
## Contribution
126+
127+
### Git Flow
128+
129+
The crypto-js project uses [git flow](https://github.com/nvie/gitflow) to manage branches.
130+
Do your changes on the `develop` or even better on a `feature/*` branch. Don't do any changes on the `master` branch.
131+
132+
### Pull request
133+
134+
Target your pull request on `develop` branch. Other pull request won't be accepted.
135+
53136
## License
54137

55138
[The MIT License (MIT)](http://opensource.org/licenses/MIT)
56139

57140
Copyright (c) 2009-2013 Jeff Mott
58-
Copyright (c) 2013-2014 Evan Vosberg
141+
Copyright (c) 2013-2015 Evan Vosberg
59142

60143
Permission is hereby granted, free of charge, to any person obtaining a copy
61144
of this software and associated documentation files (the "Software"), to deal

aes.js

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
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();
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+
// Shortcuts
95+
var key = this._key;
96+
var keyWords = key.words;
97+
var keySize = key.sigBytes / 4;
98+
99+
// Compute number of rounds
100+
var nRounds = this._nRounds = keySize + 6
101+
102+
// Compute number of key schedule rows
103+
var ksRows = (nRounds + 1) * 4;
104+
105+
// Compute key schedule
106+
var keySchedule = this._keySchedule = [];
107+
for (var ksRow = 0; ksRow < ksRows; ksRow++) {
108+
if (ksRow < keySize) {
109+
keySchedule[ksRow] = keyWords[ksRow];
110+
} else {
111+
var t = keySchedule[ksRow - 1];
112+
113+
if (!(ksRow % keySize)) {
114+
// Rot word
115+
t = (t << 8) | (t >>> 24);
116+
117+
// Sub word
118+
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
119+
120+
// Mix Rcon
121+
t ^= RCON[(ksRow / keySize) | 0] << 24;
122+
} else if (keySize > 6 && ksRow % keySize == 4) {
123+
// Sub word
124+
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
125+
}
126+
127+
keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
128+
}
129+
}
130+
131+
// Compute inv key schedule
132+
var invKeySchedule = this._invKeySchedule = [];
133+
for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
134+
var ksRow = ksRows - invKsRow;
135+
136+
if (invKsRow % 4) {
137+
var t = keySchedule[ksRow];
138+
} else {
139+
var t = keySchedule[ksRow - 4];
140+
}
141+
142+
if (invKsRow < 4 || ksRow <= 4) {
143+
invKeySchedule[invKsRow] = t;
144+
} else {
145+
invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
146+
INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
147+
}
148+
}
149+
},
150+
151+
encryptBlock: function (M, offset) {
152+
this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
153+
},
154+
155+
decryptBlock: function (M, offset) {
156+
// Swap 2nd and 4th rows
157+
var t = M[offset + 1];
158+
M[offset + 1] = M[offset + 3];
159+
M[offset + 3] = t;
160+
161+
this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
162+
163+
// Inv 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+
169+
_doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
170+
// Shortcut
171+
var nRounds = this._nRounds;
172+
173+
// Get input, add round key
174+
var s0 = M[offset] ^ keySchedule[0];
175+
var s1 = M[offset + 1] ^ keySchedule[1];
176+
var s2 = M[offset + 2] ^ keySchedule[2];
177+
var s3 = M[offset + 3] ^ keySchedule[3];
178+
179+
// Key schedule row counter
180+
var ksRow = 4;
181+
182+
// Rounds
183+
for (var round = 1; round < nRounds; round++) {
184+
// Shift rows, sub bytes, mix columns, add round key
185+
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++];
186+
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++];
187+
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++];
188+
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++];
189+
190+
// Update state
191+
s0 = t0;
192+
s1 = t1;
193+
s2 = t2;
194+
s3 = t3;
195+
}
196+
197+
// Shift rows, sub bytes, add round key
198+
var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
199+
var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
200+
var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
201+
var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
202+
203+
// Set output
204+
M[offset] = t0;
205+
M[offset + 1] = t1;
206+
M[offset + 2] = t2;
207+
M[offset + 3] = t3;
208+
},
209+
210+
keySize: 256/32
211+
});
212+
213+
/**
214+
* Shortcut functions to the cipher's object interface.
215+
*
216+
* @example
217+
*
218+
* var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
219+
* var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
220+
*/
221+
C.AES = BlockCipher._createHelper(AES);
222+
}());
223+
224+
225+
return CryptoJS.AES;
226+
227+
}));

bower.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "crypto-js",
3+
"version": "3.1.3",
4+
"description": "Modularized port of googlecode project crypto-js.",
5+
"homepage": "http://github.com/evanvosberg/crypto-js",
6+
"repository": {
7+
"type": "git",
8+
"url": "http://github.com/evanvosberg/crypto-js.git"
9+
},
10+
"keywords": [
11+
"security",
12+
"crypto",
13+
"Hash",
14+
"MD5",
15+
"SHA1",
16+
"SHA-1",
17+
"SHA256",
18+
"SHA-256",
19+
"RC4",
20+
"Rabbit",
21+
"AES",
22+
"DES",
23+
"PBKDF2",
24+
"HMAC",
25+
"OFB",
26+
"CFB",
27+
"CTR",
28+
"CBC",
29+
"Base64"
30+
],
31+
"main": "index.js",
32+
"dependencies": {},
33+
"ignore": []
34+
}

build/components/aes-min.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)