Skip to content

Commit

Permalink
Merge branch 'release/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
evanvosberg committed Oct 24, 2023
2 parents c755289 + d5af3ae commit 808f499
Show file tree
Hide file tree
Showing 10 changed files with 988 additions and 30 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ console.log(decryptedData); // [{id: 1}, {id: 2}]

## Release notes

### 4.2.0

Change default hash algorithm and iteration's for PBKDF2 to prevent weak security by using the default configuration.

Custom KDF Hasher

Blowfish support

### 4.1.1

Fix module order in bundled release.
Expand Down
471 changes: 471 additions & 0 deletions blowfish.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crypto-js",
"version": "4.1.1",
"version": "4.2.0",
"description": "JavaScript library of crypto standards.",
"license": "MIT",
"homepage": "http://github.com/brix/crypto-js",
Expand Down
13 changes: 9 additions & 4 deletions cipher-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,19 @@
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
*/
execute: function (password, keySize, ivSize, salt) {
execute: function (password, keySize, ivSize, salt, hasher) {
// Generate random salt
if (!salt) {
salt = WordArray.random(64/8);
}

// Derive key and IV
var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
if (!hasher) {
var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
} else {
var key = EvpKDF.create({ keySize: keySize + ivSize, hasher: hasher }).compute(password, salt);
}


// Separate key and IV
var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
Expand Down Expand Up @@ -834,7 +839,7 @@
cfg = this.cfg.extend(cfg);

// Derive key and other params
var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, cfg.salt, cfg.hasher);

// Add IV to config
cfg.iv = derivedParams.iv;
Expand Down Expand Up @@ -873,7 +878,7 @@
ciphertext = this._parse(ciphertext, cfg.format);

// Derive key and other params
var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt, cfg.hasher);

// Add IV to config
cfg.iv = derivedParams.iv;
Expand Down
490 changes: 478 additions & 12 deletions crypto-js.js

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions enc-base64url.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
*
* var base64String = CryptoJS.enc.Base64url.stringify(wordArray);
*/
stringify: function (wordArray, urlSafe=true) {
stringify: function (wordArray, urlSafe) {
if (urlSafe === undefined) {
urlSafe = true
}
// Shortcuts
var words = wordArray.words;
var sigBytes = wordArray.sigBytes;
Expand Down Expand Up @@ -88,7 +91,11 @@
*
* var wordArray = CryptoJS.enc.Base64url.parse(base64String);
*/
parse: function (base64Str, urlSafe=true) {
parse: function (base64Str, urlSafe) {
if (urlSafe === undefined) {
urlSafe = true
}

// Shortcuts
var base64StrLength = base64Str.length;
var map = urlSafe ? this._safe_map : this._map;
Expand Down Expand Up @@ -135,6 +142,7 @@
}
}());


return CryptoJS.enc.Base64url;

}));
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
;(function (root, factory, undef) {
if (typeof exports === "object") {
// CommonJS
module.exports = exports = factory(require("./core"), require("./x64-core"), require("./lib-typedarrays"), require("./enc-utf16"), require("./enc-base64"), require("./enc-base64url"), require("./md5"), require("./sha1"), require("./sha256"), require("./sha224"), require("./sha512"), require("./sha384"), require("./sha3"), require("./ripemd160"), require("./hmac"), require("./pbkdf2"), require("./evpkdf"), require("./cipher-core"), require("./mode-cfb"), require("./mode-ctr"), require("./mode-ctr-gladman"), require("./mode-ofb"), require("./mode-ecb"), require("./pad-ansix923"), require("./pad-iso10126"), require("./pad-iso97971"), require("./pad-zeropadding"), require("./pad-nopadding"), require("./format-hex"), require("./aes"), require("./tripledes"), require("./rc4"), require("./rabbit"), require("./rabbit-legacy"));
module.exports = exports = factory(require("./core"), require("./x64-core"), require("./lib-typedarrays"), require("./enc-utf16"), require("./enc-base64"), require("./enc-base64url"), require("./md5"), require("./sha1"), require("./sha256"), require("./sha224"), require("./sha512"), require("./sha384"), require("./sha3"), require("./ripemd160"), require("./hmac"), require("./pbkdf2"), require("./evpkdf"), require("./cipher-core"), require("./mode-cfb"), require("./mode-ctr"), require("./mode-ctr-gladman"), require("./mode-ofb"), require("./mode-ecb"), require("./pad-ansix923"), require("./pad-iso10126"), require("./pad-iso97971"), require("./pad-zeropadding"), require("./pad-nopadding"), require("./format-hex"), require("./aes"), require("./tripledes"), require("./rc4"), require("./rabbit"), require("./rabbit-legacy"), require("./blowfish"));
}
else if (typeof define === "function" && define.amd) {
// AMD
define(["./core", "./x64-core", "./lib-typedarrays", "./enc-utf16", "./enc-base64", "./enc-base64url", "./md5", "./sha1", "./sha256", "./sha224", "./sha512", "./sha384", "./sha3", "./ripemd160", "./hmac", "./pbkdf2", "./evpkdf", "./cipher-core", "./mode-cfb", "./mode-ctr", "./mode-ctr-gladman", "./mode-ofb", "./mode-ecb", "./pad-ansix923", "./pad-iso10126", "./pad-iso97971", "./pad-zeropadding", "./pad-nopadding", "./format-hex", "./aes", "./tripledes", "./rc4", "./rabbit", "./rabbit-legacy"], factory);
define(["./core", "./x64-core", "./lib-typedarrays", "./enc-utf16", "./enc-base64", "./enc-base64url", "./md5", "./sha1", "./sha256", "./sha224", "./sha512", "./sha384", "./sha3", "./ripemd160", "./hmac", "./pbkdf2", "./evpkdf", "./cipher-core", "./mode-cfb", "./mode-ctr", "./mode-ctr-gladman", "./mode-ofb", "./mode-ecb", "./pad-ansix923", "./pad-iso10126", "./pad-iso97971", "./pad-zeropadding", "./pad-nopadding", "./format-hex", "./aes", "./tripledes", "./rc4", "./rabbit", "./rabbit-legacy", "./blowfish"], factory);
}
else {
// Global (browser)
Expand Down
2 changes: 1 addition & 1 deletion md5.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
var M_offset_14 = M[offset + 14];
var M_offset_15 = M[offset + 15];

// Working varialbes
// Working variables
var a = H[0];
var b = H[1];
var c = H[2];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crypto-js",
"version": "4.1.1",
"version": "4.2.0",
"description": "JavaScript library of crypto standards.",
"license": "MIT",
"author": {
Expand Down
14 changes: 7 additions & 7 deletions pbkdf2.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
;(function (root, factory, undef) {
if (typeof exports === "object") {
// CommonJS
module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
module.exports = exports = factory(require("./core"), require("./sha256"), require("./hmac"));
}
else if (typeof define === "function" && define.amd) {
// AMD
define(["./core", "./sha1", "./hmac"], factory);
define(["./core", "./sha256", "./hmac"], factory);
}
else {
// Global (browser)
Expand All @@ -20,7 +20,7 @@
var Base = C_lib.Base;
var WordArray = C_lib.WordArray;
var C_algo = C.algo;
var SHA1 = C_algo.SHA1;
var SHA256 = C_algo.SHA256;
var HMAC = C_algo.HMAC;

/**
Expand All @@ -31,13 +31,13 @@
* Configuration options.
*
* @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
* @property {Hasher} hasher The hasher to use. Default: SHA1
* @property {number} iterations The number of iterations to perform. Default: 1
* @property {Hasher} hasher The hasher to use. Default: SHA256
* @property {number} iterations The number of iterations to perform. Default: 250000
*/
cfg: Base.extend({
keySize: 128/32,
hasher: SHA1,
iterations: 1
hasher: SHA256,
iterations: 250000
}),

/**
Expand Down

0 comments on commit 808f499

Please sign in to comment.