support hybrid keys. see indutny/elliptic#91.
This commit is contained in:
parent
2738a4ed5d
commit
77d7916f1e
@ -120,6 +120,8 @@ ec.rand = function rand(min, max) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ec.verify = function verify(msg, sig, key, historical, high) {
|
ec.verify = function verify(msg, sig, key, historical, high) {
|
||||||
|
var hybrid, result;
|
||||||
|
|
||||||
if (key.getPublicKey)
|
if (key.getPublicKey)
|
||||||
key = key.getPublicKey();
|
key = key.getPublicKey();
|
||||||
|
|
||||||
@ -140,28 +142,46 @@ ec.verify = function verify(msg, sig, key, historical, high) {
|
|||||||
if (historical)
|
if (historical)
|
||||||
sig = ec.normalizeLength(sig);
|
sig = ec.normalizeLength(sig);
|
||||||
|
|
||||||
try {
|
if (secp256k1) {
|
||||||
if (secp256k1) {
|
// secp256k1 fails on high s values. This is
|
||||||
// secp256k1 fails on high s values. This is
|
// bad for verifying historical data.
|
||||||
// bad for verifying historical data.
|
if (high)
|
||||||
if (high)
|
sig = ec.toLowS(sig);
|
||||||
sig = ec.toLowS(sig);
|
|
||||||
|
|
||||||
|
try {
|
||||||
// Import from DER.
|
// Import from DER.
|
||||||
sig = secp256k1.signatureImport(sig);
|
sig = secp256k1.signatureImport(sig);
|
||||||
|
result = secp256k1.verify(msg, sig, key);
|
||||||
return secp256k1.verify(msg, sig, key);
|
} catch (e) {
|
||||||
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make elliptic mimic secp256k1's
|
return result;
|
||||||
// failure with high S values.
|
|
||||||
if (!high && !ec.isLowS(sig))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return ec.elliptic.verify(msg, sig, key);
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make elliptic mimic secp256k1's
|
||||||
|
// failure with high S values.
|
||||||
|
if (!high && !ec.isLowS(sig))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Elliptic does not support
|
||||||
|
// openssl's "hybrid" keys yet.
|
||||||
|
if (key[0] === 0x06 || key[0] === 0x07) {
|
||||||
|
hybrid = key[0];
|
||||||
|
key[0] = 0x04;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = ec.elliptic.verify(msg, sig, key);
|
||||||
|
} catch (e) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset the byte if we need to.
|
||||||
|
if (hybrid != null)
|
||||||
|
key[0] = hybrid;
|
||||||
|
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user