Skip to content
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 IEEE P1363 signature format for EC keys #1956

Closed
allan-simon opened this issue Oct 30, 2023 · 6 comments
Closed

Add IEEE P1363 signature format for EC keys #1956

allan-simon opened this issue Oct 30, 2023 · 6 comments

Comments

@allan-simon
Copy link

allan-simon commented Oct 30, 2023

most tools using ECDSA keys will return the signature using the IEEE P1363 format and not ASN1

see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign#ecdsa

I'm not familliar enough to propose a PR but i locally get it working by doing

// this is of course an example private key :)
$key = PublicKeyLoader::load('{"alg":"ES256","crv":"P-256","d":"KRiXxoIFHmBQJdoCsqB8Bc9_f2Z-QCdRgoydMKdoL04","ext":true,"key_ops":["sign"],"kty":"EC","x":"FKwqyGd4i2NAl8RUXCCBRCAIbcpeGyfyXwgA_AWHb8Y","y":"njxhw5O6zGVkBlcPDKYj0E-6VO1giHTUkJWBhgKNqd8"}')
          $key = $key
              ->withHash('sha256')
              ->withSignatureFormat('Raw')
          ;
          $rawSignature = $key->sign($input);
          $r =  $rawSignature['r']->toHex();
          $s =  $rawSignature['s']->toHex();
          $signature =pack(
                 'H*', 
                 $r . $s
          );
@terrafrost
Copy link
Member

I'll work on this later this week! Got a late night meeting today and another one Thursday night and then longhornphp.com on Friday and Saturday!

@terrafrost
Copy link
Member

How does the following look?:

https://github.com/terrafrost/phpseclib/tree/IEEE
terrafrost@30bc7fc

@allan-simon
Copy link
Author

@terrafrost looks great ! Is there anyway I can help you test it ?

@terrafrost
Copy link
Member

See 0086be8

I added a unit test to test it.

Thanks!

@allan-simon
Copy link
Author

awesome ! thanks a lot, can't wait for a release 👼

@terrafrost
Copy link
Member

A new release with this code change has been released!:

https://github.com/phpseclib/phpseclib/releases/tag/3.0.34

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants