Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concat-kdf algorithm returns too many bytes in some cases #318

Open
ljoy913 opened this issue May 20, 2021 · 0 comments
Open

concat-kdf algorithm returns too many bytes in some cases #318

ljoy913 opened this issue May 20, 2021 · 0 comments

Comments

@ljoy913
Copy link

ljoy913 commented May 20, 2021

The caller passes in the desired keyLength which is expected as a bit count.
The slice call that returns the derived bytes, keyLength, as bits instead of bytes, returns the entire result without truncating.

concat.js

function concatDeriveFn(name) {
...
    var N = Math.ceil(keyLen / hashLen),   <==  keyLen is expected to be in bits to compute # of iterations
        idx = 0,
        okm = [];
    function step() {
      if (N === idx++) {
        return Buffer.concat(okm).slice(0, keyLen );   <==  keyLen is expected to be a byte count for slice()}
...
}

Dividing by 8 should fix the problem:

return Buffer.concat(okm).slice(0, Math.ceil(keyLen / 8))   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant