-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
add support for calling ECDSA signatures RSA signatures, cuz node allows it #33
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,19 @@ var BN = require('bn.js') | |
var parseKeys = require('parse-asn1') | ||
var curves = require('./curves.json') | ||
|
||
function sign (hash, key, hashType, signType) { | ||
function sign (hash, key, hashType, signType, tag) { | ||
var priv = parseKeys(key) | ||
if (priv.curve) { | ||
if (signType !== 'ecdsa') throw new Error('wrong private key type') | ||
// rsa keys can be interpreted as ecdsa ones in openssl | ||
if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type') | ||
return ecSign(hash, priv) | ||
} else if (priv.type === 'dsa') { | ||
if (signType !== 'dsa') throw new Error('wrong private key type') | ||
return dsaSign(hash, priv, hashType) | ||
} else { | ||
if (signType !== 'rsa') throw new Error('wrong private key type') | ||
if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type') | ||
} | ||
|
||
hash = Buffer.concat([tag, hash]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you move this in? Doesn't really matter I suppose, just seems odd There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah it's because we only need the tag when it is an rsa key NOT when it's an ecdsa key so since we can't tell based on the signature type asked for we have to do it based on what rutine they are using, so this code path only is executed for rsa signatures never (ec)dsa |
||
var len = priv.modulus.byteLength() | ||
var pad = [ 0, 1 ] | ||
while (hash.length + pad.length + 1 < len) pad.push(0xff) | ||
|
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.
Could you add a comment here about why this is the case?
ecdsa/rsa
seems strange