Skip to content

crypto.pbkdf2 fails silently with NaN bitlength #2987

@coolaj86

Description

@coolaj86

Here's an example:

    'use strict';

    function sha256(buf) {
      return crypto.createHash('sha256').update(buf).digest('hex');
    }

    var crypto = require('crypto');
    var secret = 'my special secret';
    var appPbkdf2Salt = sha256(new Buffer("MY_SALT"));
    var iterations = 1000;
    var bitLength; // oops, forgot to define bit length
    var keyByteLength = bitLength / 8;
    var hashname = 'sha256';

    crypto.pbkdf2(secret, appPbkdf2Salt, iterations, keyByteLength, hashname, function (err, bytes) {
      if (err) {
        throw err;
      }

      console.log('bytes', bytes.toString('hex'));
    });

I'm assuming that NaN is coerced to 0. I would think that 0 should also throw an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cryptoIssues and PRs related to the crypto subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions