-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
evp: simplify overall logic #12
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aeaf4a3
evp: simplify overall logic
dcousens 8058c1e
evp: remove unused ii, avoid inline expressions
dcousens be4e43d
evp: standard-ish formatting
dcousens ed059dd
evp: simplify md_buf logic
dcousens 080e62b
evp: improve variable names
dcousens 403330f
evp: remove semicolon
dcousens 7e1b6e5
evp: remove another semicolon
dcousens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
var createHash = require('create-hash'); | ||
module.exports = function evp(password, salt, keyLen) { | ||
keyLen = keyLen/8; | ||
var ki = 0; | ||
var ii = 0; | ||
var key = new Buffer(keyLen); | ||
var addmd = 0; | ||
var md, md_buf; | ||
var i; | ||
while (true) { | ||
md = createHash('md5'); | ||
if(addmd++ > 0) { | ||
md.update(md_buf); | ||
var createHash = require('create-hash') | ||
|
||
module.exports = function evp (password, salt, keyLen) { | ||
keyLen = keyLen / 8 | ||
|
||
var offset = 0 | ||
var key = new Buffer(keyLen) | ||
var buffer | ||
|
||
while (keyLen > 0) { | ||
var hash = createHash('md5') | ||
|
||
if (buffer) { | ||
hash.update(buffer) | ||
} | ||
md.update(password); | ||
md.update(salt); | ||
md_buf = md.digest(); | ||
i = 0; | ||
if(keyLen > 0) { | ||
while(true) { | ||
if(keyLen === 0) { | ||
break; | ||
} | ||
if(i === md_buf.length) { | ||
break; | ||
} | ||
key[ki++] = md_buf[i++]; | ||
keyLen--; | ||
} | ||
|
||
hash.update(password) | ||
hash.update(salt) | ||
buffer = hash.digest() | ||
|
||
for (var i = 0; i < buffer.length; ++i) { | ||
if (keyLen === 0) break | ||
|
||
key[offset] = buffer[i] | ||
|
||
keyLen-- | ||
offset++ | ||
} | ||
if(keyLen === 0) { | ||
break; | ||
} | ||
} | ||
for(i=0;i<md_buf.length;i++) { | ||
md_buf[i] = 0; | ||
} | ||
return key; | ||
}; | ||
|
||
// zero the temporary buffer | ||
buffer.fill(0) | ||
|
||
return key | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the reasoning for this, but can we even make the guarantee that the key won't be around in some other buffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make us less secure and hopefully at least lowers the number of places in memory the key sits and makes it less likely for somebody to recover it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'm just trying to ensure we don't give off any false assertions, this could very easily still be in memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we could leave a comment
On Wed, May 20, 2015 at 9:59 AM Daniel Cousens notifications@github.com
wrote: