mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-11 08:10:58 +00:00
Merge branch '3.0'
This commit is contained in:
commit
d587dd5e1f
@ -153,7 +153,7 @@ abstract class OpenSSH extends Progenitor
|
|||||||
if ($curve instanceof Ed25519) {
|
if ($curve instanceof Ed25519) {
|
||||||
$key = Strings::packSSH2('ss', 'ssh-ed25519', $curve->encodePoint($publicKey));
|
$key = Strings::packSSH2('ss', 'ssh-ed25519', $curve->encodePoint($publicKey));
|
||||||
|
|
||||||
if (self::$binary) {
|
if (isset($options['binary']) ? $options['binary'] : self::$binary) {
|
||||||
return $key;
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ use phpseclib\Crypt\EC\Curves\Curve25519;
|
|||||||
use phpseclib\Crypt\EC\Formats\Keys\PKCS1;
|
use phpseclib\Crypt\EC\Formats\Keys\PKCS1;
|
||||||
use phpseclib\Crypt\Common;
|
use phpseclib\Crypt\Common;
|
||||||
use phpseclib\Exception\UnsupportedOperationException;
|
use phpseclib\Exception\UnsupportedOperationException;
|
||||||
|
use phpseclib\Common\Functions\Strings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EC Private Key
|
* EC Private Key
|
||||||
@ -98,9 +99,16 @@ class PrivateKey extends EC implements Common\PrivateKey
|
|||||||
|
|
||||||
$order = $this->curve->getOrder();
|
$order = $this->curve->getOrder();
|
||||||
|
|
||||||
|
$shortFormat = $this->shortFormat;
|
||||||
|
$format = $this->format;
|
||||||
|
if ($format === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
return sodium_crypto_sign_detached($message, $this->toString('libsodium'));
|
$result = sodium_crypto_sign_detached($message, $this->toString('libsodium'));
|
||||||
|
return $shortFormat == 'SSH2' ? Strings::packSSH2('ss', 'ssh-' . strtolower($this->getCurve()), $result) : $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// contexts (Ed25519ctx) are supported but prehashing (Ed25519ph) is not.
|
// contexts (Ed25519ctx) are supported but prehashing (Ed25519ph) is not.
|
||||||
@ -133,13 +141,7 @@ class PrivateKey extends EC implements Common\PrivateKey
|
|||||||
$S = $k->multiply($dA)->add($r);
|
$S = $k->multiply($dA)->add($r);
|
||||||
list(, $S) = $S->divide($order);
|
list(, $S) = $S->divide($order);
|
||||||
$S = str_pad(strrev($S->toBytes()), $curve::SIZE, "\0");
|
$S = str_pad(strrev($S->toBytes()), $curve::SIZE, "\0");
|
||||||
return $R . $S;
|
return $shortFormat == 'SSH2' ? Strings::packSSH2('ss', 'ssh-' . strtolower($this->getCurve()), $R . $S) : $R . $S;
|
||||||
}
|
|
||||||
|
|
||||||
$shortFormat = $this->shortFormat;
|
|
||||||
$format = $this->format;
|
|
||||||
if ($format === false) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) {
|
if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) {
|
||||||
|
@ -23,6 +23,7 @@ use phpseclib\Crypt\EC\Curves\Ed25519;
|
|||||||
use phpseclib\Crypt\EC\Formats\Keys\PKCS1;
|
use phpseclib\Crypt\EC\Formats\Keys\PKCS1;
|
||||||
use phpseclib\Crypt\Common;
|
use phpseclib\Crypt\Common;
|
||||||
use phpseclib\Exception\UnsupportedOperationException;
|
use phpseclib\Exception\UnsupportedOperationException;
|
||||||
|
use phpseclib\Common\Functions\Strings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EC Public Key
|
* EC Public Key
|
||||||
@ -50,9 +51,19 @@ class PublicKey extends EC implements Common\PublicKey
|
|||||||
throw new UnsupportedOperationException('Montgomery Curves cannot be used to create signatures');
|
throw new UnsupportedOperationException('Montgomery Curves cannot be used to create signatures');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$shortFormat = $this->shortFormat;
|
||||||
|
$format = $this->format;
|
||||||
|
if ($format === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$order = $this->curve->getOrder();
|
$order = $this->curve->getOrder();
|
||||||
|
|
||||||
if ($this->curve instanceof TwistedEdwardsCurve) {
|
if ($this->curve instanceof TwistedEdwardsCurve) {
|
||||||
|
if ($shortFormat == 'SSH2') {
|
||||||
|
list(, $signature) = Strings::unpackSSH2('ss', $signature);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->curve instanceof Ed25519 && self::$engines['libsodium'] && !isset($this->context)) {
|
if ($this->curve instanceof Ed25519 && self::$engines['libsodium'] && !isset($this->context)) {
|
||||||
return sodium_crypto_sign_verify_detached($signature, $message, $this->toString('libsodium'));
|
return sodium_crypto_sign_verify_detached($signature, $message, $this->toString('libsodium'));
|
||||||
}
|
}
|
||||||
@ -105,8 +116,6 @@ class PublicKey extends EC implements Common\PublicKey
|
|||||||
return $lhs[0]->equals($rhs[0]) && $lhs[1]->equals($rhs[1]);
|
return $lhs[0]->equals($rhs[0]) && $lhs[1]->equals($rhs[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$format = $this->format;
|
|
||||||
|
|
||||||
$params = $format::load($signature);
|
$params = $format::load($signature);
|
||||||
if ($params === false || count($params) != 2) {
|
if ($params === false || count($params) != 2) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -480,10 +480,12 @@ lEIq93iMVzIArjGaKrFDAAAADHJvb3RAdmFncmFudAE=
|
|||||||
|
|
||||||
$key = PublicKeyLoader::load($key);
|
$key = PublicKeyLoader::load($key);
|
||||||
$sig = $key->sign('zzz');
|
$sig = $key->sign('zzz');
|
||||||
|
$sig2 = $key->withSignatureFormat('SSH2')->sign('zzz');
|
||||||
|
|
||||||
$key = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKGEJnCqQiHjcB9RE86BvJh5lEIq93iMVzIArjGaKrFD root@vagrant';
|
$key = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKGEJnCqQiHjcB9RE86BvJh5lEIq93iMVzIArjGaKrFD root@vagrant';
|
||||||
$key = PublicKeyLoader::load($key);
|
$key = PublicKeyLoader::load($key);
|
||||||
|
|
||||||
$this->assertTrue($key->verify('zzz', $sig));
|
$this->assertTrue($key->verify('zzz', $sig));
|
||||||
|
$this->assertTrue($key->withSignatureFormat('SSH2')->verify('zzz', $sig2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user