1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-11 16:49:42 +01:00

Merge pull request #1752 from Slamdunk/ec_sign_without_password

EC: decipher private key to generate signature
This commit is contained in:
terrafrost 2022-02-04 10:36:23 -06:00 committed by GitHub
commit dbe7daff1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -106,7 +106,7 @@ class PrivateKey extends EC implements Common\PrivateKey
if ($this->curve instanceof TwistedEdwardsCurve) { if ($this->curve instanceof TwistedEdwardsCurve) {
if ($this->curve instanceof Ed25519 && self::$engines['libsodium'] && !isset($this->context)) { if ($this->curve instanceof Ed25519 && self::$engines['libsodium'] && !isset($this->context)) {
$result = sodium_crypto_sign_detached($message, $this->toString('libsodium')); $result = sodium_crypto_sign_detached($message, $this->withPassword(false)->toString('libsodium'));
return $shortFormat == 'SSH2' ? Strings::packSSH2('ss', 'ssh-' . strtolower($this->getCurve()), $result) : $result; return $shortFormat == 'SSH2' ? Strings::packSSH2('ss', 'ssh-' . strtolower($this->getCurve()), $result) : $result;
} }

View File

@ -190,6 +190,19 @@ class Unit_Crypt_EC_CurveTest extends PhpseclibTestCase
$this->assertTrue($publickey->verify($plaintext, $sig)); $this->assertTrue($publickey->verify($plaintext, $sig));
} }
public function testCanSignWithAnEncryptedPrivateKey()
{
EC::useBestEngine();
$plaintext = 'zzz';
$privatekey = EC::createKey('Ed25519')->withPassword('foo');
$publickey = $privatekey->getPublicKey();
$sig = $privatekey->sign($plaintext);
$this->assertTrue($publickey->verify($plaintext, $sig));
}
/** /**
* Sign with best engine, verify with internal engine * Sign with best engine, verify with internal engine
* *