Giter VIP home page Giter VIP logo

Comments (1)

ldudzsim avatar ldudzsim commented on September 2, 2024 2

Sorry for delay. I look into you post and everything in your example is ok. If you look futher into article you linked, you can see that in 4. point there is deterministic ECDSA signature and this output is exatly the same as your

30450220587ce0cf0252e2db3a7c3c91b355aa8f3385e128227cd8727c5f7777877ad772022100edc508b7c14891ed15ab38c687019d7ebaf5c12908cf21a83e8ae57e8c47e95c

In our lib all ECDSA signatures are generated in "deterministic" way by default. If you want to get not deterministic signature you should pass k option to sign method. K option is a function which should return BN number. If you generate signature in not determinsitic way, each signature will be different, but all these still will successfully validate. In article in 3. point there is a not deterministic signature which is almost imposible to regenerate because to achieve that you should generate the same k. Example how to generate not deterministic signature:

use Elliptic\EC;
use BN\BN;

$message = "30f10a6468b7d98257af63fb40dfcf2cefe991346fd37c67cf7b51ff8d4404d3";
$privKeyHex = "0ecd20654c2e2be708495853e8da35c664247040c00bd10b9b13e5e86e6a808d";
$pubKeyHex = "042daa93315eebbe2cb9b5c3505df4c6fb6caca8b756786098567550d4820c09db988fe9997d049d687292f815ccd6e7fb5c1b1a91137999818d17c73d0f80aef9";

$ec = new EC('secp256k1');
$privKey = $ec->keyFromPrivate($privKeyHex);
$pubKey = $ec->keyFromPublic($pubKeyHex, "hex");
$notDeterministicOptions = array(
    "k" => function() {
        return new BN(openssl_random_pseudo_bytes(32), 256);
    }
);

$determinsiticSignature = $privKey->sign($message);
echo "Determinsitic signature: " . $determinsiticSignature->toDER("hex") . "\n";
echo "Validating determinisitic signature: " . ($pubKey->verify($message, $determinsiticSignature) ? "Success" : "Failure") . "\n";

$notDeterminsiticSignature1 = $privKey->sign($message, $notDeterministicOptions);
echo "Not determinsitic signature no. 1: " . $notDeterminsiticSignature1->toDER("hex") . "\n";
echo "Validating not determinisitic signature no. 1: " . ($pubKey->verify($message, $notDeterminsiticSignature1) ? "Success" : "Failure") . "\n";

$notDeterminsiticSignature2 = $privKey->sign($message, $notDeterministicOptions);
echo "Not determinsitic signature no. 2: " . $notDeterminsiticSignature2->toDER("hex") . "\n";
echo "Validating not determinisitic signature no. 2: " . ($pubKey->verify($message, $notDeterminsiticSignature2) ? "Success" : "Failure") . "\n";

from elliptic-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.