Skip to content

Commit

Permalink
fix(kdf): Remove key length constraint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lester Kim committed Nov 9, 2018
1 parent 9356cf3 commit 2f3103f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
8 changes: 0 additions & 8 deletions kdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ function init(key, buffer) {
throw new TypeError('kdf.init: Expecting key to be defined.')
}

if (crypto_kdf_KEYBYTES !== key.length) {
throw new TypeError(`kdf.init: Invalid key length: ${key.length}`)
}

if (buffer) {
if (false === isBuffer(buffer)) {
throw new TypeError('kdf.init: Expecting context to be a buffer.')
Expand Down Expand Up @@ -103,10 +99,6 @@ function update(ctx, id) {
throw new TypeError('kdf.update: Expecting ctx.key to be a buffer.')
}

if (crypto_kdf_KEYBYTES !== ctx.key.length) {
throw new TypeError(`kdf.update: Invalid buffer length: ${ctx.key.length}.`)
}

if ('number' !== typeof id) {
throw new TypeError('kdf.update: Expecting id to be a number.')
}
Expand Down
14 changes: 1 addition & 13 deletions test/kdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,9 @@ test.cb('kdf.init(key, buffer) throws on bad input', (t) => {
t.throws(() => kdf.init(123), TypeError)
t.throws(() => kdf.init(true), TypeError)
t.throws(() => kdf.init(() => undefined), TypeError)
t.throws(() => kdf.init(''), TypeError)
t.throws(() => kdf.init('a'), TypeError)
t.throws(() => kdf.init({}), TypeError)

const smallKey = randomBytes(crypto_kdf_KEYBYTES - 1)
const largeKey = randomBytes(crypto_kdf_KEYBYTES + 1)
t.throws(() => kdf.init(smallKey), TypeError)
t.throws(() => kdf.init(largeKey), TypeError)

const key = randomBytes(crypto_kdf_KEYBYTES)
t.throws(() => kdf.init(key, 123), TypeError)
t.throws(() => kdf.init(key, true), TypeError)
Expand All @@ -94,7 +89,6 @@ test.cb('kdf.init(key, buffer) returns a context object without a context buffer
t.true(isBuffer(c1.buffer))
t.true(isBuffer(c1.key))
t.true(crypto_kdf_CONTEXTBYTES === c1.buffer.length)
t.true(crypto_kdf_KEYBYTES === c1.key.length)
t.true(0 === Buffer.compare(key, c1.key))
t.true(0 === Buffer.compare(c1.buffer, c2.buffer))
t.end()
Expand All @@ -112,7 +106,6 @@ test.cb('kdf.init(key, buffer) returns a context object with a context buffer.',
t.true(isBuffer(c1.buffer))
t.true(isBuffer(c1.key))
t.true(crypto_kdf_CONTEXTBYTES === c1.buffer.length)
t.true(crypto_kdf_KEYBYTES === c1.key.length)
t.true(0 === Buffer.compare(buffer, c1.buffer))
t.true(0 === Buffer.compare(buffer, c2.buffer))
t.true(0 === Buffer.compare(key, c1.key))
Expand Down Expand Up @@ -154,11 +147,6 @@ test.cb('kdf.update(ctx, id) throws on bad input', (t) => {
t.throws(() => kdf.update({ buffer, key: '' }), TypeError)
t.throws(() => kdf.update({ buffer, key: {} }), TypeError)

const smallKey = randomBytes(crypto_kdf_KEYBYTES - 1)
const largeKey = randomBytes(crypto_kdf_KEYBYTES + 1)
t.throws(() => kdf.update({ buffer, key: smallKey }), TypeError)
t.throws(() => kdf.update({ buffer, key: largeKey }), TypeError)

const key = randomBytes(crypto_kdf_KEYBYTES)
const ctx = { buffer, key }
t.throws(() => kdf.update(ctx, true), TypeError)
Expand Down

0 comments on commit 2f3103f

Please sign in to comment.