-
Notifications
You must be signed in to change notification settings - Fork 53
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
signature is not canonical #22
Comments
If you talking about this and forcing to use smaller s value in signature, we do not have it, because our lib is strict elliptic math, without implementation focused on bitcoin/blockchain or something. But if you need that, you can check this <?php
require_once("vendor/autoload.php");
use Elliptic\EC;
use Elliptic\EC\Signature;
function getNegativeSignature($ec, $sig) {
$res = new Signature($sig);
$res->s = $res->s->neg()->add($ec->n);
return $res;
}
$ec = new EC('secp256k1');
$key = $ec->genKeyPair();
$msg = 'ab4c3451';
$signature = $key->sign($msg);
$negativeSignature = getNegativeSignature($ec, $signature);
echo "Normal signature: " . $signature->toDER('hex') . "\n";
echo "Negative signature: " . $negativeSignature->toDER('hex') . "\n";
echo "Verify normal: " . (($key->verify($msg, $signature) == TRUE) ? "true" : "false") . "\n";
echo "Verify negative: " . (($key->verify($msg, $negativeSignature) == TRUE) ? "true" : "false") . "\n";
if ($signature->s->cmp($negativeSignature->s) < 0) {
echo "Normal is canonical\n";
}
else {
echo "Negative is canonical\n";
} |
sorry, it is work correct, i forgot make hash of message #21 canonical sign can be checked with DER
run sign one more time in loop if it is not canonical |
ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is it woking, did you check? blockchain tells it is not canonical
The text was updated successfully, but these errors were encountered: