Skip to content

Commit

Permalink
Merge branch 'feature-key-derivation-hashers'
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed May 5, 2017
2 parents 59a36e7 + 4f844ea commit 53d89af
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/core/config/OperationConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,11 @@ const OperationConfig = {
type: "number",
value: Cipher.KDF_ITERATIONS
},
{
name: "Hashing function",
type: "option",
value: Cipher.HASHERS
},
{
name: "Salt (hex)",
type: "string",
Expand Down Expand Up @@ -1434,6 +1439,11 @@ const OperationConfig = {
type: "number",
value: Cipher.KDF_ITERATIONS
},
{
name: "Hashing function",
type: "option",
value: Cipher.HASHERS
},
{
name: "Salt (hex)",
type: "string",
Expand Down
31 changes: 23 additions & 8 deletions src/core/operations/Cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ const Cipher = {
* @default
*/
KDF_ITERATIONS: 1,
/**
* @constant
* @default
*/
HASHERS: ["MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", "SHA3", "RIPEMD160"],

/**
* Derive PBKDF2 key operation.
Expand All @@ -320,11 +325,16 @@ const Cipher = {
runPbkdf2: function (input, args) {
let keySize = args[0] / 32,
iterations = args[1],
salt = CryptoJS.enc.Hex.parse(args[2] || ""),
inputFormat = args[3],
outputFormat = args[4],
hasher = args[2],
salt = CryptoJS.enc.Hex.parse(args[3] || ""),
inputFormat = args[4],
outputFormat = args[5],
passphrase = Utils.format[inputFormat].parse(input),
key = CryptoJS.PBKDF2(passphrase, salt, { keySize: keySize, iterations: iterations });
key = CryptoJS.PBKDF2(passphrase, salt, {
keySize: keySize,
hasher: CryptoJS.algo[hasher],
iterations: iterations,
});

return key.toString(Utils.format[outputFormat]);
},
Expand All @@ -340,11 +350,16 @@ const Cipher = {
runEvpkdf: function (input, args) {
let keySize = args[0] / 32,
iterations = args[1],
salt = CryptoJS.enc.Hex.parse(args[2] || ""),
inputFormat = args[3],
outputFormat = args[4],
hasher = args[2],
salt = CryptoJS.enc.Hex.parse(args[3] || ""),
inputFormat = args[4],
outputFormat = args[5],
passphrase = Utils.format[inputFormat].parse(input),
key = CryptoJS.EvpKDF(passphrase, salt, { keySize: keySize, iterations: iterations });
key = CryptoJS.EvpKDF(passphrase, salt, {
keySize: keySize,
hasher: CryptoJS.algo[hasher],
iterations: iterations,
});

return key.toString(Utils.format[outputFormat]);
},
Expand Down

0 comments on commit 53d89af

Please sign in to comment.