Skip to content
This repository was archived by the owner on Nov 20, 2022. It is now read-only.

Commit dea4b07

Browse files
committed
Import 2.2
1 parent e03e632 commit dea4b07

File tree

4 files changed

+85
-22
lines changed

4 files changed

+85
-22
lines changed

builder/builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

33
$copyrightInfo = '/*!
4-
* Crypto-JS v2.1.0
4+
* Crypto-JS v2.2.0
55
* http://code.google.com/p/crypto-js/
66
* Copyright (c) 2011, Jeff Mott. All rights reserved.
77
* http://code.google.com/p/crypto-js/wiki/License
88
*/
99
';
1010

1111
$files = array('crypto', 'md5', 'sha1', 'sha256', 'hmac', 'pbkdf2', 'pbkdf2async',
12-
'marc4', 'rabbit', 'aes', 'cbc', 'ofb');
12+
'marc4', 'rabbit', 'aes', 'cbc', 'cbc-nopad', 'ofb');
1313
$rollups = array(
1414
array('crypto', 'md5'),
1515
array('crypto', 'sha1'),

docs/QuickStartGuide.wiki

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
MD5 is a widely used hash function. It's been used in a variety of security applications and is also commonly used to check the integrity of files. Though, MD5 is not collision resistant, and it isn't suitable for applications like SSL certificates or digital signatures that rely on this property.
88

99
{{{
10-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-md5.js"></script>
10+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-md5.js"></script>
1111
<script type="text/javascript">
1212

1313
var digest = Crypto.MD5("Message");
@@ -23,7 +23,7 @@ var digestString = Crypto.MD5("Message", { asString: true });
2323
The SHA hash functions were designed by the National Security Agency (NSA). SHA-1 is the most established of the existing SHA hash functions, and it's used in a variety of security applications and protocols. Though, SHA-1's collision resistance has been weakening as new attacks are discovered or improved.
2424

2525
{{{
26-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-sha1.js"></script>
26+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha1.js"></script>
2727
<script type="text/javascript">
2828

2929
var digest = Crypto.SHA1("Message");
@@ -39,7 +39,7 @@ var digestString = Crypto.SHA1("Message", { asString: true });
3939
SHA-256 is one of the three variants in the SHA-2 set. It isn't as widely used as SHA-1, though it appears to provide much better security.
4040

4141
{{{
42-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-sha256.js"></script>
42+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha256.js"></script>
4343
<script type="text/javascript">
4444

4545
var digest = Crypto.SHA256("Message");
@@ -55,7 +55,7 @@ var digestString = Crypto.SHA256("Message", { asString: true });
5555
The Advanced Encryption Standard (AES) is a U.S. Federal Information Processing Standard (FIPS). It was selected after a 5-year process where 15 competing designs were evaluated.
5656

5757
{{{
58-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-sha1-hmac-pbkdf2-ofb-aes.js"></script>
58+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha1-hmac-pbkdf2-ofb-aes.js"></script>
5959
<script type="text/javascript">
6060

6161
var crypted = Crypto.AES.encrypt("Message", "Secret Passphrase");
@@ -69,7 +69,7 @@ var plain = Crypto.AES.decrypt(crypted, "Secret Passphrase");
6969
Rabbit is a high-performance stream cipher and a finalist in the eSTREAM Portfolio. It is one of the four designs selected after a 3 1/2-year process where 22 designs were evaluated.
7070

7171
{{{
72-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-sha1-hmac-pbkdf2-rabbit.js"></script>
72+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha1-hmac-pbkdf2-rabbit.js"></script>
7373
<script type="text/javascript">
7474

7575
var crypted = Crypto.Rabbit.encrypt("Message", "Secret Passphrase");
@@ -83,7 +83,7 @@ var plain = Crypto.Rabbit.decrypt(crypted, "Secret Passphrase");
8383
MARC4 (Modified Allegedly RC4) is based on RC4, a widely-used stream cipher. RC4 is used in popular protocols such as SSL and WEP. But though it's remarkable for its simplicity and speed, it has weaknesses. Crypto-JS provides a modified version that corrects these weaknesses, but the algorithm's history still doesn't inspire confidence in its security.
8484

8585
{{{
86-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-sha1-hmac-pbkdf2-marc4.js"></script>
86+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha1-hmac-pbkdf2-marc4.js"></script>
8787
<script type="text/javascript">
8888

8989
var crypted = Crypto.MARC4.encrypt("Message", "Secret Passphrase");
@@ -99,8 +99,8 @@ Keyed-hash message authentication codes (HMAC) is a mechanism for message authen
9999
=== HMAC-MD5 ===
100100

101101
{{{
102-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-md5.js"></script>
103-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-hmac-min.js"></script>
102+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-md5.js"></script>
103+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-hmac-min.js"></script>
104104
<script type="text/javascript">
105105

106106
var hmac = Crypto.HMAC(Crypto.MD5, "Message", "Secret Passphrase");
@@ -114,8 +114,8 @@ var hmacString = Crypto.HMAC(Crypto.MD5, "Message", "Secret Passphrase", { asStr
114114
=== HMAC-SHA1 ===
115115

116116
{{{
117-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-sha1.js"></script>
118-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-hmac-min.js"></script>
117+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha1.js"></script>
118+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-hmac-min.js"></script>
119119
<script type="text/javascript">
120120

121121
var hmac = Crypto.HMAC(Crypto.SHA1, "Message", "Secret Passphrase");
@@ -129,8 +129,8 @@ var hmacString = Crypto.HMAC(Crypto.SHA1, "Message", "Secret Passphrase", { asSt
129129
=== HMAC-SHA256 ===
130130

131131
{{{
132-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-sha256.js"></script>
133-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-hmac-min.js"></script>
132+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha256.js"></script>
133+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-hmac-min.js"></script>
134134
<script type="text/javascript">
135135

136136
var hmac = Crypto.HMAC(Crypto.SHA256, "Message", "Secret Passphrase");
@@ -148,7 +148,7 @@ PBKDF2 is a password-based key derivation function. In many applications of cryp
148148
A salt provides a large set of keys for any given password, and an iteration count increases the cost of producing keys from a password, thereby also increasing the difficulty of attack.
149149

150150
{{{
151-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-sha1-hmac-pbkdf2.js"></script>
151+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha1-hmac-pbkdf2.js"></script>
152152
<script type="text/javascript">
153153

154154
var salt = Crypto.util.bytesToString(Crypto.util.randomBytes(16));
@@ -165,7 +165,7 @@ var key512bit1000 = Crypto.PBKDF2("Secret Passphrase", salt, 64, { iterations: 1
165165
PBKDF2 with a large iteration count can take a long time to compute. To avoid long-running script warnings, CryptoJS provided an alternative version that executes asyncronously and passes the result to a callback. You also have the option to specify an onProgressChange callback that allows you to keep the user updated.
166166

167167
{{{
168-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-sha1-hmac-pbkdf2async.js"></script>
168+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha1-hmac-pbkdf2async.js"></script>
169169
<script type="text/javascript">
170170

171171
var salt = Crypto.util.bytesToString(Crypto.util.randomBytes(16));
@@ -186,7 +186,7 @@ Crypto.PBKDF2Async("Secret Passphrase", salt, 64, onCompleteHandler, { iteration
186186
== Utilities ==
187187

188188
{{{
189-
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.1.0-crypto-min.js"></script>
189+
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-min.js"></script>
190190
<script type="text/javascript">
191191

192192
var helloBytes = Crypto.charenc.Binary.stringToBytes("Hello, World!");

src/AES.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ var AES = C.AES = {
8989

9090
encrypt: function (message, password, options) {
9191

92+
options = options || {};
93+
9294
var
9395

9496
// Convert to bytes
9597
m = UTF8.stringToBytes(message),
9698

9799
// Generate random IV
98-
iv = util.randomBytes(AES._blocksize * 4),
100+
iv = options.iv || util.randomBytes(AES._blocksize * 4),
99101

100102
// Generate key
101103
k = (
@@ -107,26 +109,28 @@ var AES = C.AES = {
107109
),
108110

109111
// Determine mode
110-
mode = options && options.mode || C.mode.OFB;
112+
mode = options.mode || C.mode.OFB;
111113

112114
// Encrypt
113115
AES._init(k);
114116
mode.encrypt(AES, m, iv);
115117

116118
// Return ciphertext
117-
return util.bytesToBase64(iv.concat(m));
119+
return util.bytesToBase64(options.iv ? m : iv.concat(m));
118120

119121
},
120122

121123
decrypt: function (ciphertext, password, options) {
122124

125+
options = options || {};
126+
123127
var
124128

125129
// Convert to bytes
126130
c = util.base64ToBytes(ciphertext),
127131

128132
// Separate IV and message
129-
iv = c.splice(0, AES._blocksize * 4),
133+
iv = options.iv || c.splice(0, AES._blocksize * 4),
130134

131135
// Generate key
132136
k = (
@@ -138,7 +142,7 @@ var AES = C.AES = {
138142
),
139143

140144
// Determine mode
141-
mode = options && options.mode || C.mode.OFB;
145+
mode = options.mode || C.mode.OFB;
142146

143147
// Decrypt
144148
AES._init(k);

src/CBC-nopad.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Crypto.mode.CBCNoPad = {
2+
3+
encrypt: function (cipher, m, iv) {
4+
5+
var blockSizeInBytes = cipher._blocksize * 4;
6+
7+
// Encrypt each block
8+
for (var offset = 0; offset < m.length; offset += blockSizeInBytes) {
9+
10+
if (offset == 0) {
11+
// XOR first block using IV
12+
for (var i = 0; i < blockSizeInBytes; i++)
13+
m[i] ^= iv[i];
14+
}
15+
else {
16+
// XOR this block using previous crypted block
17+
for (var i = 0; i < blockSizeInBytes; i++)
18+
m[offset + i] ^= m[offset + i - blockSizeInBytes];
19+
}
20+
21+
// Encrypt block
22+
cipher._encryptblock(m, offset);
23+
24+
}
25+
26+
},
27+
28+
decrypt: function (cipher, c, iv) {
29+
30+
var blockSizeInBytes = cipher._blocksize * 4;
31+
32+
// Decrypt each block
33+
for (var offset = 0; offset < c.length; offset += blockSizeInBytes) {
34+
35+
// Save this crypted block
36+
var thisCryptedBlock = c.slice(offset, offset + blockSizeInBytes);
37+
38+
// Decrypt block
39+
cipher._decryptblock(c, offset);
40+
41+
if (offset == 0) {
42+
// XOR first block using IV
43+
for (var i = 0; i < blockSizeInBytes; i++)
44+
c[i] ^= iv[i];
45+
}
46+
else {
47+
// XOR decrypted block using previous crypted block
48+
for (var i = 0; i < blockSizeInBytes; i++)
49+
c[offset + i] ^= prevCryptedBlock[i];
50+
}
51+
52+
// This crypted block is the new previous crypted block
53+
var prevCryptedBlock = thisCryptedBlock;
54+
55+
}
56+
57+
}
58+
59+
};

0 commit comments

Comments
 (0)