Skip to content

Commit

Permalink
Fix EdDSA algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky authored Feb 13, 2024
1 parent 057fb11 commit 613e08e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Library/Signature/Algorithm/EdDSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function sign(JWK $key, string $input): string
throw new InvalidArgumentException('Invalid "d" parameter.');
}
if (! $key->has('x')) {
$x = sodium_crypto_sign_publickey_from_secretkey($d);
$x = $this->getPublicKey($key);

Check failure on line 43 in src/Library/Signature/Algorithm/EdDSA.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Dynamic call to static method Jose\Component\Signature\Algorithm\EdDSA::getPublicKey().
} else {
$x = $key->get('x');
}
Expand Down Expand Up @@ -84,6 +84,21 @@ public function name(): string
return 'EdDSA';
}

private static function getPublicKey(JWK $key): string
{
switch ($key->get('crv')) {
case 'Ed25519':
return Ed25519::publickey_from_secretkey($key->get('d'));

Check failure on line 91 in src/Library/Signature/Algorithm/EdDSA.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Call to static method publickey_from_secretkey() on an unknown class Jose\Component\Signature\Algorithm\Ed25519.
case 'X25519':
if (extension_loaded('sodium')) {
return sodium_crypto_scalarmult_base($key->get('d'));

Check failure on line 94 in src/Library/Signature/Algorithm/EdDSA.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Parameter #1 $secret_key of function sodium_crypto_scalarmult_base expects string, mixed given.
}
// no break
default:
throw new InvalidArgumentException('Unsupported key type');
}
}

private function checkKey(JWK $key): void
{
if (! in_array($key->get('kty'), $this->allowedKeyTypes(), true)) {
Expand Down

0 comments on commit 613e08e

Please sign in to comment.