mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-16 02:07:09 +00:00
Merge pull request #1390 from terrafrost/diffie-hellman
add a new diffie-hellman key exchange class
This commit is contained in:
commit
d51b72abbf
@ -81,13 +81,13 @@ abstract class AsymmetricKey
|
||||
private static $plugins = [];
|
||||
|
||||
/**
|
||||
* Supported plugins (original case)
|
||||
* Invisible plugins
|
||||
*
|
||||
* @see self::initialize_static_variables()
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
private static $origPlugins = [];
|
||||
private static $invisiblePlugins = [];
|
||||
|
||||
/**
|
||||
* Supported signature formats (lower case)
|
||||
@ -137,7 +137,7 @@ abstract class AsymmetricKey
|
||||
}
|
||||
|
||||
self::loadPlugins('Keys');
|
||||
if (static::ALGORITHM != 'RSA') {
|
||||
if (static::ALGORITHM != 'RSA' && static::ALGORITHM != 'DH') {
|
||||
self::loadPlugins('Signature');
|
||||
}
|
||||
}
|
||||
@ -146,31 +146,25 @@ abstract class AsymmetricKey
|
||||
* Load the key
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
* @param string $password
|
||||
* @return array|bool
|
||||
* @param string $password optional
|
||||
* @return AsymmetricKey
|
||||
*/
|
||||
protected static function load($key, $type, $password)
|
||||
public static function load($key, $password = false)
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
$components = false;
|
||||
if ($type === false) {
|
||||
foreach (self::$plugins[static::ALGORITHM]['Keys'] as $format) {
|
||||
try {
|
||||
$components = $format::load($key, $password);
|
||||
} catch (\Exception $e) {
|
||||
$components = false;
|
||||
}
|
||||
if ($components !== false) {
|
||||
break;
|
||||
}
|
||||
foreach (self::$plugins[static::ALGORITHM]['Keys'] as $format) {
|
||||
if (isset(self::$invisiblePlugins[static::ALGORITHM]) && in_array($format, self::$invisiblePlugins[static::ALGORITHM])) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$format = strtolower($type);
|
||||
if (isset(self::$plugins[static::ALGORITHM]['Keys'][$format])) {
|
||||
$format = self::$plugins[static::ALGORITHM]['Keys'][$format];
|
||||
try {
|
||||
$components = $format::load($key, $password);
|
||||
} catch (\Exception $e) {
|
||||
$components = false;
|
||||
}
|
||||
if ($components !== false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,7 +174,41 @@ abstract class AsymmetricKey
|
||||
|
||||
$components['format'] = $format;
|
||||
|
||||
return $components;
|
||||
$new = static::onLoad($components);
|
||||
return $new instanceof PrivateKey ?
|
||||
$new->withPassword($password) :
|
||||
$new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the key, assuming a specific format
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
* @param string $password optional
|
||||
* @return AsymmetricKey
|
||||
*/
|
||||
public static function loadFormat($type, $key, $password = false)
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
$components = false;
|
||||
$format = strtolower($type);
|
||||
if (isset(self::$plugins[static::ALGORITHM]['Keys'][$format])) {
|
||||
$format = self::$plugins[static::ALGORITHM]['Keys'][$format];
|
||||
$components = $format::load($key, $password);
|
||||
}
|
||||
|
||||
if ($components === false) {
|
||||
throw new NoKeyLoadedException('Unable to read key');
|
||||
}
|
||||
|
||||
$components['format'] = $format;
|
||||
|
||||
$new = static::onLoad($components);
|
||||
return $new instanceof PrivateKey ?
|
||||
$new->withPassword($password) :
|
||||
$new;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -227,7 +255,9 @@ abstract class AsymmetricKey
|
||||
continue;
|
||||
}
|
||||
self::$plugins[static::ALGORITHM][$format][strtolower($name)] = $type;
|
||||
self::$origPlugins[static::ALGORITHM][$format][] = $name;
|
||||
if ($reflect->hasConstant('IS_INVISIBLE')) {
|
||||
self::$invisiblePlugins[static::ALGORITHM][] = $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -264,7 +294,9 @@ abstract class AsymmetricKey
|
||||
$meta = new \ReflectionClass($fullname);
|
||||
$shortname = $meta->getShortName();
|
||||
self::$plugins[static::ALGORITHM]['Keys'][strtolower($shortname)] = $fullname;
|
||||
self::$origPlugins[static::ALGORITHM]['Keys'][] = $shortname;
|
||||
if ($meta->hasConstant('IS_INVISIBLE')) {
|
||||
self::$invisiblePlugins[static::ALGORITHM] = strtolower($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
401
phpseclib/Crypt/DH.php
Normal file
401
phpseclib/Crypt/DH.php
Normal file
@ -0,0 +1,401 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Pure-PHP (EC)DH implementation
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Here's an example of how to compute a shared secret with this library:
|
||||
* <code>
|
||||
* <?php
|
||||
* include 'vendor/autoload.php';
|
||||
*
|
||||
* $ourPrivate = \phpseclib\Crypt\DH::createKey();
|
||||
* $secret = DH::computeSecret($ourPrivate, $theirPublic);
|
||||
*
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @category Crypt
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2016 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt;
|
||||
|
||||
use phpseclib\Exception\NoKeyLoadedException;
|
||||
use phpseclib\Exception\UnsupportedOperationException;
|
||||
use phpseclib\Crypt\Common\AsymmetricKey;
|
||||
use phpseclib\Crypt\DH\PrivateKey;
|
||||
use phpseclib\Crypt\DH\PublicKey;
|
||||
use phpseclib\Crypt\DH\Parameters;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
/**
|
||||
* Pure-PHP (EC)DH implementation
|
||||
*
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
abstract class DH extends AsymmetricKey
|
||||
{
|
||||
/**
|
||||
* Algorithm Name
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
const ALGORITHM = 'DH';
|
||||
|
||||
/**
|
||||
* DH prime
|
||||
*
|
||||
* @var \phpseclib\Math\BigInteger
|
||||
* @access private
|
||||
*/
|
||||
protected $prime;
|
||||
|
||||
/**
|
||||
* DH Base
|
||||
*
|
||||
* Prime divisor of p-1
|
||||
*
|
||||
* @var \phpseclib\Math\BigInteger
|
||||
* @access private
|
||||
*/
|
||||
protected $base;
|
||||
|
||||
/**
|
||||
* Create DH parameters
|
||||
*
|
||||
* This method is a bit polymorphic. It can take any of the following:
|
||||
* - two BigInteger's (prime and base)
|
||||
* - an integer representing the size of the prime in bits (the base is assumed to be 2)
|
||||
* - a string (eg. diffie-hellman-group14-sha1)
|
||||
*
|
||||
* @access public
|
||||
* @return \phpseclib\Crypt\DH|bool
|
||||
*/
|
||||
public static function createParameters(...$args)
|
||||
{
|
||||
$params = new Parameters;
|
||||
if (count($args) == 2 && $args[0] instanceof BigInteger && $args[1] instanceof BigInteger) {
|
||||
//if (!$args[0]->isPrime()) {
|
||||
// throw new \InvalidArgumentException('The first parameter should be a prime number');
|
||||
//}
|
||||
$params->prime = $args[0];
|
||||
$params->base = $args[1];
|
||||
return $params;
|
||||
} elseif (count($args) == 1 && is_numeric($args[0])) {
|
||||
$params->prime = BigInteger::randomPrime($args[0]);
|
||||
$params->base = new BigInteger(2);
|
||||
return $params;
|
||||
} elseif (count($args) != 1 || !is_string($args[0])) {
|
||||
throw new \InvalidArgumentException('Valid parameters are either: two BigInteger\'s (prime and base), a single integer (the length of the prime; base is assumed to be 2) or a string');
|
||||
}
|
||||
switch ($args[0]) {
|
||||
// see http://tools.ietf.org/html/rfc2409#section-6.2 and
|
||||
// http://tools.ietf.org/html/rfc2412, appendex E
|
||||
case 'diffie-hellman-group1-sha1':
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF';
|
||||
break;
|
||||
// see http://tools.ietf.org/html/rfc3526#section-3
|
||||
case 'diffie-hellman-group14-sha1': // 2048-bit MODP Group
|
||||
case 'diffie-hellman-group14-sha256':
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
|
||||
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
|
||||
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
|
||||
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
|
||||
'3995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF';
|
||||
break;
|
||||
// see https://tools.ietf.org/html/rfc3526#section-4
|
||||
case 'diffie-hellman-group15-sha512': // 3072-bit MODP Group
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
|
||||
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
|
||||
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
|
||||
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
|
||||
'3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33' .
|
||||
'A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' .
|
||||
'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864' .
|
||||
'D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2' .
|
||||
'08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF';
|
||||
break;
|
||||
// see https://tools.ietf.org/html/rfc3526#section-5
|
||||
case 'diffie-hellman-group16-sha512': // 4096-bit MODP Group
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
|
||||
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
|
||||
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
|
||||
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
|
||||
'3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33' .
|
||||
'A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' .
|
||||
'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864' .
|
||||
'D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2' .
|
||||
'08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7' .
|
||||
'88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8' .
|
||||
'DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2' .
|
||||
'233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9' .
|
||||
'93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF';
|
||||
break;
|
||||
// see https://tools.ietf.org/html/rfc3526#section-6
|
||||
case 'diffie-hellman-group17-sha512': // 6144-bit MODP Group
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
|
||||
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
|
||||
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
|
||||
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
|
||||
'3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33' .
|
||||
'A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' .
|
||||
'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864' .
|
||||
'D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2' .
|
||||
'08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7' .
|
||||
'88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8' .
|
||||
'DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2' .
|
||||
'233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9' .
|
||||
'93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026' .
|
||||
'C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AE' .
|
||||
'B06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B' .
|
||||
'DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92EC' .
|
||||
'F032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E' .
|
||||
'59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA' .
|
||||
'CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76' .
|
||||
'F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468' .
|
||||
'043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DCC4024FFFFFFFFFFFFFFFF';
|
||||
break;
|
||||
// see https://tools.ietf.org/html/rfc3526#section-7
|
||||
case 'diffie-hellman-group18-sha512': // 8192-bit MODP Group
|
||||
$prime = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' .
|
||||
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' .
|
||||
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' .
|
||||
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05' .
|
||||
'98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB' .
|
||||
'9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B' .
|
||||
'E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718' .
|
||||
'3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33' .
|
||||
'A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7' .
|
||||
'ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864' .
|
||||
'D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2' .
|
||||
'08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7' .
|
||||
'88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8' .
|
||||
'DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2' .
|
||||
'233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9' .
|
||||
'93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026' .
|
||||
'C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AE' .
|
||||
'B06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B' .
|
||||
'DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92EC' .
|
||||
'F032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E' .
|
||||
'59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA' .
|
||||
'CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76' .
|
||||
'F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468' .
|
||||
'043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E4' .
|
||||
'38777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300741FA7BF8AFC47ED' .
|
||||
'2576F6936BA424663AAB639C5AE4F5683423B4742BF1C978238F16CBE39D652D' .
|
||||
'E3FDB8BEFC848AD922222E04A4037C0713EB57A81A23F0C73473FC646CEA306B' .
|
||||
'4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A062B3CF5B3A278A6' .
|
||||
'6D2A13F83F44F82DDF310EE074AB6A364597E899A0255DC164F31CC50846851D' .
|
||||
'F9AB48195DED7EA1B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F92' .
|
||||
'4009438B481C6CD7889A002ED5EE382BC9190DA6FC026E479558E4475677E9AA' .
|
||||
'9E3050E2765694DFC81F56E880B96E7160C980DD98EDD3DFFFFFFFFFFFFFFFFF';
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid named prime provided');
|
||||
}
|
||||
|
||||
$params->prime = new BigInteger($prime, 16);
|
||||
$params->base = new BigInteger(2);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create public / private key pair.
|
||||
*
|
||||
* The rationale for the second parameter is described in http://tools.ietf.org/html/rfc4419#section-6.2 :
|
||||
*
|
||||
* "To increase the speed of the key exchange, both client and server may
|
||||
* reduce the size of their private exponents. It should be at least
|
||||
* twice as long as the key material that is generated from the shared
|
||||
* secret. For more details, see the paper by van Oorschot and Wiener
|
||||
* [VAN-OORSCHOT]."
|
||||
*
|
||||
* $length is in bits
|
||||
*
|
||||
* @param Parameters $params
|
||||
* @param int $length optional
|
||||
* @access public
|
||||
* @return DH\PrivateKey
|
||||
*/
|
||||
public static function createKey(Parameters $params, $length = 0)
|
||||
{
|
||||
$one = new BigInteger(1);
|
||||
if ($length) {
|
||||
$max = $one->bitwise_leftShift($length);
|
||||
$max = $max->subtract($one);
|
||||
} else {
|
||||
$max = $params->prime->subtract($one);
|
||||
}
|
||||
|
||||
$key = new PrivateKey;
|
||||
$key->prime = $params->prime;
|
||||
$key->base = $params->base;
|
||||
$key->privateKey = BigInteger::randomRange($one, $max);
|
||||
$key->publicKey = $key->base->powMod($key->privateKey, $key->prime);
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute Shared Secret
|
||||
*
|
||||
* @param PrivateKey|EC $private
|
||||
* @param PublicKey|BigInteger|string $public
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public static function computeSecret($private, $public)
|
||||
{
|
||||
if ($private instanceof PrivateKey) { // DH\PrivateKey
|
||||
switch (true) {
|
||||
case $public instanceof PublicKey:
|
||||
if (!$private->prime->equals($public->prime) || !$private->base->equals($public->base)) {
|
||||
throw new \InvalidArgumentException('The public and private key do not share the same prime and / or base numbers');
|
||||
}
|
||||
return $public->publicKey->powMod($private->privateKey, $private->prime)->toBytes(true);
|
||||
case is_string($public):
|
||||
$public = new BigInteger($public, -256);
|
||||
case $public instanceof BigInteger:
|
||||
return $public->powMod($private->privateKey, $private->prime)->toBytes(true);
|
||||
default:
|
||||
throw new \InvalidArgumentException('$public needs to be an instance of DH\PublicKey, a BigInteger or a string');
|
||||
}
|
||||
}
|
||||
|
||||
if ($private instanceof EC\PrivateKey) {
|
||||
switch (true) {
|
||||
case $public instanceof EC\PublicKey:
|
||||
$public = $public->getEncodedCoordinates();
|
||||
case is_string($public):
|
||||
$point = $private->multiply($public);
|
||||
switch ($private->getCurve()) {
|
||||
case 'Curve25519':
|
||||
case 'Curve448':
|
||||
$secret = $point;
|
||||
break;
|
||||
default:
|
||||
// according to https://www.secg.org/sec1-v2.pdf#page=33 only X is returned
|
||||
$secret = substr($point, 1, (strlen($point) - 1) >> 1);
|
||||
}
|
||||
/*
|
||||
if (($secret[0] & "\x80") === "\x80") {
|
||||
$secret = "\0$secret";
|
||||
}
|
||||
*/
|
||||
return $secret;
|
||||
default:
|
||||
throw new \InvalidArgumentException('$public needs to be an instance of EC\PublicKey or a string (an encoded coordinate)');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the key
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return AsymmetricKey
|
||||
*/
|
||||
public static function load($key, $password = false)
|
||||
{
|
||||
try {
|
||||
return EC::load($key, $password);
|
||||
} catch (NoKeyLoadedException $e) {}
|
||||
|
||||
return parent::load($key, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* OnLoad Handler
|
||||
*
|
||||
* @return bool
|
||||
* @access protected
|
||||
* @param array $components
|
||||
*/
|
||||
protected static function onLoad($components)
|
||||
{
|
||||
if (!isset($components['privateKey']) && !isset($components['publicKey'])) {
|
||||
$new = new Parameters;
|
||||
} else {
|
||||
$new = isset($components['privateKey']) ?
|
||||
new PrivateKey :
|
||||
new PublicKey;
|
||||
}
|
||||
|
||||
$new->prime = $components['prime'];
|
||||
$new->base = $components['base'];
|
||||
|
||||
if (isset($components['privateKey'])) {
|
||||
$new->privateKey = $components['privateKey'];
|
||||
}
|
||||
if (isset($components['publicKey'])) {
|
||||
$new->publicKey = $components['publicKey'];
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines which hashing function should be used
|
||||
*
|
||||
* @access public
|
||||
* @param string $hash
|
||||
*/
|
||||
public function withHash($hash)
|
||||
{
|
||||
throw new UnsupportedOperationException('DH does not use a hash algorithm');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash algorithm currently being used
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getHash()
|
||||
{
|
||||
throw new UnsupportedOperationException('DH does not use a hash algorithm');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parameters
|
||||
*
|
||||
* A public / private key is only returned if the currently loaded "key" contains an x or y
|
||||
* value.
|
||||
*
|
||||
* @see self::getPublicKey()
|
||||
* @access public
|
||||
* @param string $type optional
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
$type = self::validatePlugin('Keys', 'PKCS1', 'saveParameters');
|
||||
|
||||
$key = $type::saveParameters($this->prime, $this->base);
|
||||
return self::load($key, 'PKCS1');
|
||||
}
|
||||
}
|
83
phpseclib/Crypt/DH/Formats/Keys/PKCS1.php
Normal file
83
phpseclib/Crypt/DH/Formats/Keys/PKCS1.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* "PKCS1" Formatted EC Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Processes keys with the following headers:
|
||||
*
|
||||
* -----BEGIN DH PARAMETERS-----
|
||||
*
|
||||
* Technically, PKCS1 is for RSA keys, only, but we're using PKCS1 to describe
|
||||
* DSA, whose format isn't really formally described anywhere, so might as well
|
||||
* use it to describe this, too.
|
||||
*
|
||||
* @category Crypt
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\DH\Formats\Keys;
|
||||
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\Common\Formats\Keys\PKCS1 as Progenitor;
|
||||
use phpseclib\File\ASN1;
|
||||
use phpseclib\File\ASN1\Maps;
|
||||
|
||||
/**
|
||||
* "PKCS1" Formatted DH Key Handler
|
||||
*
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
abstract class PKCS1 extends Progenitor
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @access public
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
$key = parent::load($key, $password);
|
||||
|
||||
$decoded = ASN1::decodeBER($key);
|
||||
if (empty($decoded)) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
|
||||
$components = ASN1::asn1map($decoded[0], Maps\DHParameter::MAP);
|
||||
if (!is_array($components)) {
|
||||
throw new \RuntimeException('Unable to perform ASN1 mapping on parameters');
|
||||
}
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert EC parameters to the appropriate format
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function saveParameters(BigInteger $prime, BigInteger $base, array $options = [])
|
||||
{
|
||||
$params = [
|
||||
'prime' => $prime,
|
||||
'base' => $base
|
||||
];
|
||||
$params = ASN1::encodeDER($params, Maps\DHParameter::MAP);
|
||||
|
||||
return "-----BEGIN DH PARAMETERS-----\r\n" .
|
||||
chunk_split(base64_encode($params), 64) .
|
||||
"-----END DH PARAMETERS-----\r\n";
|
||||
}
|
||||
}
|
156
phpseclib/Crypt/DH/Formats/Keys/PKCS8.php
Normal file
156
phpseclib/Crypt/DH/Formats/Keys/PKCS8.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PKCS#8 Formatted DH Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Processes keys with the following headers:
|
||||
*
|
||||
* -----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
* -----BEGIN PRIVATE KEY-----
|
||||
* -----BEGIN PUBLIC KEY-----
|
||||
*
|
||||
* @category Crypt
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\DH\Formats\Keys;
|
||||
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\Common\Formats\Keys\PKCS8 as Progenitor;
|
||||
use phpseclib\File\ASN1;
|
||||
use phpseclib\File\ASN1\Maps;
|
||||
|
||||
/**
|
||||
* PKCS#8 Formatted DH Key Handler
|
||||
*
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
abstract class PKCS8 extends Progenitor
|
||||
{
|
||||
/**
|
||||
* OID Name
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
const OID_NAME = 'dhKeyAgreement';
|
||||
|
||||
/**
|
||||
* OID Value
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
const OID_VALUE = '1.2.840.113549.1.3.1';
|
||||
|
||||
/**
|
||||
* Child OIDs loaded
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
protected static $childOIDsLoaded = false;
|
||||
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @access public
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!is_string($key)) {
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
|
||||
}
|
||||
|
||||
$isPublic = strpos($key, 'PUBLIC') !== false;
|
||||
|
||||
$key = parent::load($key, $password);
|
||||
|
||||
$type = isset($key['privateKey']) ? 'privateKey' : 'publicKey';
|
||||
|
||||
switch (true) {
|
||||
case !$isPublic && $type == 'publicKey':
|
||||
throw new \UnexpectedValueException('Human readable string claims non-public key but DER encoded string claims public key');
|
||||
case $isPublic && $type == 'privateKey':
|
||||
throw new \UnexpectedValueException('Human readable string claims public key but DER encoded string claims private key');
|
||||
}
|
||||
|
||||
$decoded = ASN1::decodeBER($key[$type . 'Algorithm']['parameters']->element);
|
||||
if (empty($decoded)) {
|
||||
throw new \RuntimeException('Unable to decode BER of parameters');
|
||||
}
|
||||
$components = ASN1::asn1map($decoded[0], Maps\DHParameter::MAP);
|
||||
if (!is_array($components)) {
|
||||
throw new \RuntimeException('Unable to perform ASN1 mapping on parameters');
|
||||
}
|
||||
|
||||
$decoded = ASN1::decodeBER($key[$type]);
|
||||
switch (true) {
|
||||
case empty($decoded):
|
||||
case !is_array($decoded):
|
||||
case !isset($decoded[0]['content']):
|
||||
case !$decoded[0]['content'] instanceof BigInteger:
|
||||
throw new \RuntimeException('Unable to decode BER of parameters');
|
||||
}
|
||||
$components[$type] = $decoded[0]['content'];
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a private key to the appropriate format.
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Math\BigInteger $prime
|
||||
* @param \phpseclib\Math\BigInteger $base
|
||||
* @param \phpseclib\Math\BigInteger $privateKey
|
||||
* @param \phpseclib\Math\BigInteger $publicKey
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePrivateKey(BigInteger $prime, BigInteger $base, BigInteger $privateKey, BigInteger $publicKey, $password = '', array $options = [])
|
||||
{
|
||||
$params = [
|
||||
'prime' => $prime,
|
||||
'base' => $base
|
||||
];
|
||||
$params = ASN1::encodeDER($params, Maps\DHParameter::MAP);
|
||||
$params = new ASN1\Element($params);
|
||||
$key = ASN1::encodeDER($privateKey, ['type' => ASN1::TYPE_INTEGER]);
|
||||
return self::wrapPrivateKey($key, [], $params, $password, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a public key to the appropriate format
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Math\BigInteger $prime
|
||||
* @param \phpseclib\Math\BigInteger $base
|
||||
* @param \phpseclib\Math\BigInteger $publicKey
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(BigInteger $prime, BigInteger $base, BigInteger $publicKey, array $options = [])
|
||||
{
|
||||
$params = [
|
||||
'prime' => $prime,
|
||||
'base' => $base
|
||||
];
|
||||
$params = ASN1::encodeDER($params, Maps\DHParameter::MAP);
|
||||
$params = new ASN1\Element($params);
|
||||
$key = ASN1::encodeDER($publicKey, ['type' => ASN1::TYPE_INTEGER]);
|
||||
return self::wrapPublicKey($key, $params);
|
||||
}
|
||||
}
|
40
phpseclib/Crypt/DH/Parameters.php
Normal file
40
phpseclib/Crypt/DH/Parameters.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DH Parameters
|
||||
*
|
||||
* @category Crypt
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\DH;
|
||||
|
||||
use phpseclib\Crypt\DH;
|
||||
|
||||
/**
|
||||
* DH Parameters
|
||||
*
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Parameters extends DH
|
||||
{
|
||||
/**
|
||||
* Returns the parameters
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public function toString($type = 'PKCS1', array $options = [])
|
||||
{
|
||||
$type = self::validatePlugin('Keys', 'PKCS1', 'saveParameters');
|
||||
|
||||
return $type::saveParameters($this->prime, $this->base, $options);
|
||||
}
|
||||
}
|
82
phpseclib/Crypt/DH/PrivateKey.php
Normal file
82
phpseclib/Crypt/DH/PrivateKey.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DH Private Key
|
||||
*
|
||||
* @category Crypt
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\DH;
|
||||
|
||||
use phpseclib\Crypt\DH;
|
||||
use phpseclib\Crypt\Common;
|
||||
|
||||
/**
|
||||
* DH Private Key
|
||||
*
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PrivateKey extends DH
|
||||
{
|
||||
use Common\Traits\PasswordProtected;
|
||||
|
||||
/**
|
||||
* Private Key
|
||||
*
|
||||
* @var \phpseclib\Math\BigInteger
|
||||
* @access private
|
||||
*/
|
||||
protected $privateKey;
|
||||
|
||||
/**
|
||||
* Public Key
|
||||
*
|
||||
* @var \phpseclib\Math\BigInteger
|
||||
* @access private
|
||||
*/
|
||||
protected $publicKey;
|
||||
|
||||
/**
|
||||
* Returns the public key
|
||||
*
|
||||
* @access public
|
||||
* @return DH
|
||||
*/
|
||||
public function getPublicKey()
|
||||
{
|
||||
$type = self::validatePlugin('Keys', 'PKCS8', 'savePublicKey');
|
||||
|
||||
if (!isset($this->publicKey)) {
|
||||
$this->publicKey = $this->base->powMod($this->privateKey, $this->prime);
|
||||
}
|
||||
|
||||
$key = $type::savePublicKey($this->prime, $this->base, $this->publicKey);
|
||||
|
||||
return DH::loadFormat('PKCS8', $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the private key
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public function toString($type, array $options = [])
|
||||
{
|
||||
$type = self::validatePlugin('Keys', $type, 'savePrivateKey');
|
||||
|
||||
if (!isset($this->publicKey)) {
|
||||
$this->publicKey = $this->base->powMod($this->privateKey, $this->prime);
|
||||
}
|
||||
|
||||
return $type::savePrivateKey($this->prime, $this->base, $this->privateKey, $this->publicKey, $this->password, $options);
|
||||
}
|
||||
}
|
53
phpseclib/Crypt/DH/PublicKey.php
Normal file
53
phpseclib/Crypt/DH/PublicKey.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DH Public Key
|
||||
*
|
||||
* @category Crypt
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\DH;
|
||||
|
||||
use phpseclib\Crypt\DH;
|
||||
use phpseclib\Crypt\Common;
|
||||
|
||||
/**
|
||||
* DH Public Key
|
||||
*
|
||||
* @package DH
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PublicKey extends DH
|
||||
{
|
||||
use Common\Traits\Fingerprint;
|
||||
|
||||
/**
|
||||
* Returns the public key
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public function toString($type, array $options = [])
|
||||
{
|
||||
$type = self::validatePlugin('Keys', $type, 'savePublicKey');
|
||||
|
||||
return $type::savePublicKey($this->prime, $this->base, $this->publicKey, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public key as a BigInteger
|
||||
*
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
public function toBigInteger()
|
||||
{
|
||||
return $this->publicKey;
|
||||
}
|
||||
}
|
@ -224,24 +224,18 @@ abstract class DSA extends AsymmetricKey
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a public or private key
|
||||
* OnLoad Handler
|
||||
*
|
||||
* Returns true on success and false on failure (ie. an incorrect password was provided or the key was malformed)
|
||||
* @return bool
|
||||
* @access public
|
||||
* @param string $key
|
||||
* @param string $type optional
|
||||
* @param string $password optional
|
||||
* @access protected
|
||||
* @param array $components
|
||||
*/
|
||||
public static function load($key, $type = false, $password = false)
|
||||
protected static function onLoad($components)
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
if (!isset(self::$engines['PHP'])) {
|
||||
self::useBestEngine();
|
||||
}
|
||||
|
||||
$components = parent::load($key, $type, $password);
|
||||
if (!isset($components['x']) && !isset($components['y'])) {
|
||||
$new = new Parameters;
|
||||
} else if (isset($components['x'])) {
|
||||
|
@ -63,6 +63,6 @@ abstract class ASN1
|
||||
*/
|
||||
public static function save(BigInteger $r, BigInteger $s)
|
||||
{
|
||||
return ASN1::encodeDER(compact('r', 's'), Maps\DssSigValue::MAP);
|
||||
return Encoder::encodeDER(compact('r', 's'), Maps\DssSigValue::MAP);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace phpseclib\Crypt\DSA;
|
||||
|
||||
use phpseclib\Crypt\DSA;
|
||||
use phpseclib\Crypt\ECDSA\Formats\Signature\ASN1 as ASN1Signature;
|
||||
use phpseclib\Crypt\DSA\Formats\Signature\ASN1 as ASN1Signature;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\Common;
|
||||
|
||||
@ -70,7 +70,7 @@ class PrivateKey extends DSA implements Common\PrivateKey
|
||||
|
||||
$key = $type::savePublicKey($this->p, $this->q, $this->g, $this->y);
|
||||
|
||||
return DSA::load($key, 'PKCS8')
|
||||
return DSA::loadFormat('PKCS8', $key)
|
||||
->withHash($this->hash->getHash())
|
||||
->withSignatureFormat($this->shortFormat);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace phpseclib\Crypt\DSA;
|
||||
|
||||
use phpseclib\Crypt\DSA;
|
||||
use phpseclib\Crypt\ECDSA\Formats\Signature\ASN1 as ASN1Signature;
|
||||
use phpseclib\Crypt\DSA\Formats\Signature\ASN1 as ASN1Signature;
|
||||
use phpseclib\Crypt\Common;
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of ECDSA.
|
||||
* Pure-PHP implementation of EC.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
@ -10,7 +10,7 @@
|
||||
* <?php
|
||||
* include 'vendor/autoload.php';
|
||||
*
|
||||
* $private = \phpseclib\Crypt\ECDSA::createKey('secp256k1');
|
||||
* $private = \phpseclib\Crypt\EC::createKey('secp256k1');
|
||||
* $public = $private->getPublicKey();
|
||||
*
|
||||
* $plaintext = 'terrafrost';
|
||||
@ -22,7 +22,7 @@
|
||||
* </code>
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2016 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
@ -32,26 +32,30 @@
|
||||
namespace phpseclib\Crypt;
|
||||
|
||||
use phpseclib\Crypt\Common\AsymmetricKey;
|
||||
use phpseclib\Crypt\ECDSA\PrivateKey;
|
||||
use phpseclib\Crypt\ECDSA\PublicKey;
|
||||
use phpseclib\Crypt\ECDSA\Parameters;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\ECDSA\Curves\Ed25519;
|
||||
use phpseclib\Crypt\ECDSA\Curves\Ed448;
|
||||
use phpseclib\Crypt\ECDSA\Formats\Keys\PKCS1;
|
||||
use phpseclib\Crypt\EC\PrivateKey;
|
||||
use phpseclib\Crypt\EC\PublicKey;
|
||||
use phpseclib\Crypt\EC\Parameters;
|
||||
use phpseclib\Crypt\EC\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Montgomery as MontgomeryCurve;
|
||||
use phpseclib\Crypt\EC\Curves\Curve25519;
|
||||
use phpseclib\Crypt\EC\Curves\Ed25519;
|
||||
use phpseclib\Crypt\EC\Curves\Ed448;
|
||||
use phpseclib\Crypt\EC\Formats\Keys\PKCS1;
|
||||
use phpseclib\File\ASN1\Maps\ECParameters;
|
||||
use phpseclib\File\ASN1;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Exception\UnsupportedCurveException;
|
||||
use phpseclib\Exception\UnsupportedAlgorithmException;
|
||||
use phpseclib\Exception\UnsupportedOperationException;
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of ECDSA.
|
||||
* Pure-PHP implementation of EC.
|
||||
*
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
abstract class ECDSA extends AsymmetricKey
|
||||
abstract class EC extends AsymmetricKey
|
||||
{
|
||||
/**
|
||||
* Algorithm Name
|
||||
@ -59,7 +63,7 @@ abstract class ECDSA extends AsymmetricKey
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
const ALGORITHM = 'ECDSA';
|
||||
const ALGORITHM = 'EC';
|
||||
|
||||
/**
|
||||
* Public Key QA
|
||||
@ -71,7 +75,7 @@ abstract class ECDSA extends AsymmetricKey
|
||||
/**
|
||||
* Curve
|
||||
*
|
||||
* @var \phpseclib\Crypt\ECDSA\BaseCurves\Base
|
||||
* @var \phpseclib\Crypt\EC\BaseCurves\Base
|
||||
*/
|
||||
protected $curve;
|
||||
|
||||
@ -131,7 +135,7 @@ abstract class ECDSA extends AsymmetricKey
|
||||
*
|
||||
* @access public
|
||||
* @param string $curve
|
||||
* @return \phpseclib\Crypt\ECDSA\PrivateKey
|
||||
* @return \phpseclib\Crypt\EC\PrivateKey
|
||||
*/
|
||||
public static function createKey($curve)
|
||||
{
|
||||
@ -145,8 +149,8 @@ abstract class ECDSA extends AsymmetricKey
|
||||
if (self::$engines['libsodium'] && $curve == 'ed25519' && function_exists('sodium_crypto_sign_keypair')) {
|
||||
$kp = sodium_crypto_sign_keypair();
|
||||
|
||||
$privatekey = ECDSA::load(sodium_crypto_sign_secretkey($kp), 'libsodium');
|
||||
//$publickey = ECDSA::load(sodium_crypto_sign_publickey($kp), 'libsodium');
|
||||
$privatekey = EC::loadFormat('libsodium', sodium_crypto_sign_secretkey($kp));
|
||||
//$publickey = EC::loadFormat('libsodium', sodium_crypto_sign_publickey($kp));
|
||||
|
||||
$privatekey->curveName = 'Ed25519';
|
||||
//$publickey->curveName = $curve;
|
||||
@ -157,9 +161,13 @@ abstract class ECDSA extends AsymmetricKey
|
||||
$privatekey = new PrivateKey;
|
||||
|
||||
$curveName = $curve;
|
||||
$curve = '\phpseclib\Crypt\ECDSA\Curves\\' . $curve;
|
||||
$curve = '\phpseclib\Crypt\EC\Curves\\' . $curveName;
|
||||
if (!class_exists($curve)) {
|
||||
throw new UnsupportedCurveException('Named Curve of ' . $curveName . ' is not supported');
|
||||
$curveName = ucfirst($curveName);
|
||||
$curve = '\phpseclib\Crypt\EC\Curves\\' . $curveName;
|
||||
if (!class_exists($curve)) {
|
||||
throw new UnsupportedCurveException('Named Curve of ' . $curveName . ' is not supported');
|
||||
}
|
||||
}
|
||||
|
||||
$reflect = new \ReflectionClass($curve);
|
||||
@ -169,7 +177,14 @@ abstract class ECDSA extends AsymmetricKey
|
||||
|
||||
$curve = new $curve();
|
||||
$privatekey->dA = $dA = $curve->createRandomMultiplier();
|
||||
$privatekey->QA = $curve->multiplyPoint($curve->getBasePoint(), $dA);
|
||||
if ($curve instanceof Curve25519 && self::$engines['libsodium']) {
|
||||
//$r = pack('H*', '0900000000000000000000000000000000000000000000000000000000000000');
|
||||
//$QA = sodium_crypto_scalarmult($dA->toBytes(), $r);
|
||||
$QA = sodium_crypto_box_publickey_from_secretkey($dA->toBytes());
|
||||
$privatekey->QA = [$curve->convertInteger(new BigInteger(strrev($QA), 256))];
|
||||
} else {
|
||||
$privatekey->QA = $curve->multiplyPoint($curve->getBasePoint(), $dA);
|
||||
}
|
||||
$privatekey->curve = $curve;
|
||||
|
||||
//$publickey = clone $privatekey;
|
||||
@ -187,25 +202,18 @@ abstract class ECDSA extends AsymmetricKey
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a public or private key
|
||||
* OnLoad Handler
|
||||
*
|
||||
* Returns true on success and false on failure (ie. an incorrect password was provided or the key was malformed)
|
||||
* @return bool
|
||||
* @access public
|
||||
* @param string $key
|
||||
* @param string $type optional
|
||||
* @param string $password optional
|
||||
* @access protected
|
||||
* @param array $components
|
||||
*/
|
||||
public static function load($key, $type = false, $password = false)
|
||||
protected static function onLoad($components)
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
if (!isset(self::$engines['PHP'])) {
|
||||
self::useBestEngine();
|
||||
}
|
||||
|
||||
$components = parent::load($key, $type, $password);
|
||||
|
||||
if (!isset($components['dA']) && !isset($components['QA'])) {
|
||||
$new = new Parameters;
|
||||
$new->curve = $components['curve'];
|
||||
@ -256,6 +264,11 @@ abstract class ECDSA extends AsymmetricKey
|
||||
return $this->curveName;
|
||||
}
|
||||
|
||||
if ($this->curve instanceof MontgomeryCurve) {
|
||||
$this->curveName = $this->curve instanceof Curve25519 ? 'Curve25519' : 'Curve448';
|
||||
return $this->curveName;
|
||||
}
|
||||
|
||||
if ($this->curve instanceof TwistedEdwardsCurve) {
|
||||
$this->curveName = $this->curve instanceof Ed25519 ? 'Ed25519' : 'Ed448';
|
||||
return $this->curveName;
|
||||
@ -317,6 +330,24 @@ abstract class ECDSA extends AsymmetricKey
|
||||
'OpenSSL' : 'PHP';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public key coordinates as a string
|
||||
*
|
||||
* Used by ECDH
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncodedCoordinates()
|
||||
{
|
||||
if ($this->curve instanceof MontgomeryCurve) {
|
||||
return strrev($this->QA[0]->toBytes(true));
|
||||
}
|
||||
if ($this->curve instanceof TwistedEdwardsCurve) {
|
||||
return $this->curve->encodePoint($this->QA);
|
||||
}
|
||||
return "\4" . $this->QA[0]->toBytes(true) . $this->QA[1]->toBytes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parameters
|
||||
*
|
||||
@ -331,7 +362,7 @@ abstract class ECDSA extends AsymmetricKey
|
||||
|
||||
$key = $type::saveParameters($this->curve);
|
||||
|
||||
return ECDSA::load($key, 'PKCS1')
|
||||
return EC::load($key, 'PKCS1')
|
||||
->withHash($this->hash->getHash())
|
||||
->withSignatureFormat($this->shortFormat);
|
||||
}
|
||||
@ -346,6 +377,10 @@ abstract class ECDSA extends AsymmetricKey
|
||||
*/
|
||||
public function withSignatureFormat($format)
|
||||
{
|
||||
if ($this->curve instanceof MontgomeryCurve) {
|
||||
throw new UnsupportedOperationException('Montgomery Curves cannot be used to create signatures');
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->shortFormat = $format;
|
||||
$new->format = self::validatePlugin('Signature', $format);
|
||||
@ -411,6 +446,9 @@ abstract class ECDSA extends AsymmetricKey
|
||||
*/
|
||||
public function withHash($hash)
|
||||
{
|
||||
if ($this->curve instanceof MontgomeryCurve) {
|
||||
throw new UnsupportedOperationException('Montgomery Curves cannot be used to create signatures');
|
||||
}
|
||||
if ($this->curve instanceof Ed25519 && $hash != 'sha512') {
|
||||
throw new UnsupportedAlgorithmException('Ed25519 only supports sha512 as a hash');
|
||||
}
|
||||
@ -420,4 +458,18 @@ abstract class ECDSA extends AsymmetricKey
|
||||
|
||||
return parent::withHash($hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* __toString() magic method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->curve instanceof MontgomeryCurve) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return parent::__toString();
|
||||
}
|
||||
}
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\BaseCurves;
|
||||
namespace phpseclib\Crypt\EC\BaseCurves;
|
||||
|
||||
use phpseclib\Math\Common\FiniteField;
|
||||
use phpseclib\Math\BigInteger;
|
@ -14,14 +14,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\BaseCurves;
|
||||
namespace phpseclib\Crypt\EC\BaseCurves;
|
||||
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Math\BinaryField;
|
@ -21,14 +21,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\BaseCurves;
|
||||
namespace phpseclib\Crypt\EC\BaseCurves;
|
||||
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Math\PrimeField;
|
285
phpseclib/Crypt/EC/BaseCurves/Montgomery.php
Normal file
285
phpseclib/Crypt/EC/BaseCurves/Montgomery.php
Normal file
@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Curves over y^2 = x^3 + a*x + x
|
||||
*
|
||||
* Technically, a Montgomery curve has a coefficient for y^2 but for Curve25519 and Curve448 that
|
||||
* coefficient is 1.
|
||||
*
|
||||
* Curve25519 and Curve448 do not make use of the y coordinate, which makes it unsuitable for use
|
||||
* with ECDSA / EdDSA. A few other differences between Curve25519 and Ed25519 are discussed at
|
||||
* https://crypto.stackexchange.com/a/43058/4520
|
||||
*
|
||||
* More info:
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Montgomery_curve
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2019 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\EC\BaseCurves;
|
||||
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Math\PrimeField;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\EC\Curves\Curve25519;
|
||||
use phpseclib\Math\PrimeField\Integer as PrimeInteger;
|
||||
|
||||
/**
|
||||
* Curves over y^2 = x^3 + a*x + x
|
||||
*
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Montgomery extends Base
|
||||
{
|
||||
/**
|
||||
* Prime Field Integer factory
|
||||
*
|
||||
* @var \phpseclib\Math\PrimeFields
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
/**
|
||||
* Cofficient for x
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $a;
|
||||
|
||||
/**
|
||||
* Constant used for point doubling
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $a24;
|
||||
|
||||
/**
|
||||
* The Number Zero
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $zero;
|
||||
|
||||
/**
|
||||
* The Number One
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $one;
|
||||
|
||||
/**
|
||||
* Base Point
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $p;
|
||||
|
||||
/**
|
||||
* The modulo
|
||||
*
|
||||
* @var BigInteger
|
||||
*/
|
||||
protected $modulo;
|
||||
|
||||
/**
|
||||
* The Order
|
||||
*
|
||||
* @var BigInteger
|
||||
*/
|
||||
protected $order;
|
||||
|
||||
/**
|
||||
* Sets the modulo
|
||||
*/
|
||||
public function setModulo(BigInteger $modulo)
|
||||
{
|
||||
$this->modulo = $modulo;
|
||||
$this->factory = new PrimeField($modulo);
|
||||
$this->zero = $this->factory->newInteger(new BigInteger());
|
||||
$this->one = $this->factory->newInteger(new BigInteger(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set coefficients a
|
||||
*/
|
||||
public function setCoefficients(BigInteger $a)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
$this->a = $this->factory->newInteger($a);
|
||||
$two = $this->factory->newInteger(new BigInteger(2));
|
||||
$four = $this->factory->newInteger(new BigInteger(4));
|
||||
$this->a24 = $this->a->subtract($two)->divide($four);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set x and y coordinates for the base point
|
||||
*
|
||||
* @param BigInteger|PrimeInteger $x
|
||||
* @param BigInteger|PrimeInteger $y
|
||||
* @return PrimeInteger[]
|
||||
*/
|
||||
public function setBasePoint($x, $y)
|
||||
{
|
||||
switch (true) {
|
||||
case !$x instanceof BigInteger && !$x instanceof PrimeInteger:
|
||||
throw new \UnexpectedValueException('Argument 1 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\Integer');
|
||||
case !$y instanceof BigInteger && !$y instanceof PrimeInteger:
|
||||
throw new \UnexpectedValueException('Argument 2 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\Integer');
|
||||
}
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
$this->p = [
|
||||
$x instanceof BigInteger ? $this->factory->newInteger($x) : $x,
|
||||
$y instanceof BigInteger ? $this->factory->newInteger($y) : $y
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the base point as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBasePoint()
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
/*
|
||||
if (!isset($this->p)) {
|
||||
throw new \RuntimeException('setBasePoint needs to be called before this method');
|
||||
}
|
||||
*/
|
||||
return $this->p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubles and adds a point on a curve
|
||||
*
|
||||
* See https://tools.ietf.org/html/draft-ietf-tls-curve25519-01#appendix-A.1.3
|
||||
*
|
||||
* @return FiniteField[][]
|
||||
*/
|
||||
private function doubleAndAddPoint(array $p, array $q, PrimeInteger $x1)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
|
||||
if (!count($p) || !count($q)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!isset($p[1])) {
|
||||
throw new \RuntimeException('Affine coordinates need to be manually converted to XZ coordinates');
|
||||
}
|
||||
|
||||
list($x2, $z2) = $p;
|
||||
list($x3, $z3) = $q;
|
||||
|
||||
$a = $x2->add($z2);
|
||||
$aa = $a->multiply($a);
|
||||
$b = $x2->subtract($z2);
|
||||
$bb = $b->multiply($b);
|
||||
$e = $aa->subtract($bb);
|
||||
$c = $x3->add($z3);
|
||||
$d = $x3->subtract($z3);
|
||||
$da = $d->multiply($a);
|
||||
$cb = $c->multiply($b);
|
||||
$temp = $da->add($cb);
|
||||
$x5 = $temp->multiply($temp);
|
||||
$temp = $da->subtract($cb);
|
||||
$z5 = $x1->multiply($temp->multiply($temp));
|
||||
$x4 = $aa->multiply($bb);
|
||||
$temp = static::class == Curve25519::class ? $bb : $aa;
|
||||
$z4 = $e->multiply($temp->add($this->a24->multiply($e)));
|
||||
|
||||
return [
|
||||
[$x4, $z4],
|
||||
[$x5, $z5]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply a point on the curve by a scalar
|
||||
*
|
||||
* Uses the montgomery ladder technique as described here:
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Montgomery_ladder
|
||||
* https://github.com/phpecc/phpecc/issues/16#issuecomment-59176772
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiplyPoint(array $p, Integer $d)
|
||||
{
|
||||
$p1 = [$this->one, $this->zero];
|
||||
$alreadyInternal = isset($x[1]);
|
||||
$p2 = $this->convertToInternal($p);
|
||||
$x = $p[0];
|
||||
|
||||
$b = $d->toBits();
|
||||
$b = str_pad($b, 256, '0', STR_PAD_LEFT);
|
||||
for ($i = 0; $i < strlen($b); $i++) {
|
||||
$b_i = (int) $b[$i];
|
||||
if ($b_i) {
|
||||
list($p2, $p1) = $this->doubleAndAddPoint($p2, $p1, $x);
|
||||
} else {
|
||||
list($p1, $p2) = $this->doubleAndAddPoint($p1, $p2, $x);
|
||||
}
|
||||
}
|
||||
|
||||
return $alreadyInternal ? $p1 : $this->convertToAffine($p1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an affine point to an XZ coordinate
|
||||
*
|
||||
* From https://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html
|
||||
*
|
||||
* XZ coordinates represent x y as X Z satsfying the following equations:
|
||||
*
|
||||
* x=X/Z
|
||||
*
|
||||
* @return \phpseclib\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToInternal(array $p)
|
||||
{
|
||||
if (empty($p)) {
|
||||
return [clone $this->zero, clone $this->one];
|
||||
}
|
||||
|
||||
if (isset($p[1])) {
|
||||
return $p;
|
||||
}
|
||||
|
||||
$p[1] = clone $this->one;
|
||||
|
||||
return $p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the affine point
|
||||
*
|
||||
* @return \phpseclib\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToAffine(array $p)
|
||||
{
|
||||
if (!isset($p[1])) {
|
||||
return $p;
|
||||
}
|
||||
list($x, $z) = $p;
|
||||
return [$x->divide($z)];
|
||||
}
|
||||
}
|
@ -14,14 +14,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\BaseCurves;
|
||||
namespace phpseclib\Crypt\EC\BaseCurves;
|
||||
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
use phpseclib\Common\Functions\Strings;
|
@ -19,14 +19,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\BaseCurves;
|
||||
namespace phpseclib\Crypt\EC\BaseCurves;
|
||||
|
||||
use phpseclib\Math\PrimeField;
|
||||
use phpseclib\Math\BigInteger;
|
||||
@ -216,21 +216,4 @@ class TwistedEdwards extends Base
|
||||
|
||||
return $lhs->equals($rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the x / y values satisfy the equation
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function get(array $p)
|
||||
{
|
||||
list($x, $y) = $p;
|
||||
$x2 = $x->multiply($x);
|
||||
$y2 = $y->multiply($y);
|
||||
|
||||
$lhs = $this->a->multiply($x2)->add($y2);
|
||||
$rhs = $this->d->multiply($x2)->multiply($y2)->add($this->one);
|
||||
|
||||
return $lhs->equals($rhs);
|
||||
}
|
||||
}
|
64
phpseclib/Crypt/EC/Curves/Curve25519.php
Normal file
64
phpseclib/Crypt/EC/Curves/Curve25519.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Curve25519
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2019 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Montgomery;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class Curve25519 extends Montgomery
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// 2^255 - 19
|
||||
$this->setModulo(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED', 16));
|
||||
$this->a24 = $this->factory->newInteger(new BigInteger('121666'));
|
||||
$this->p = [$this->factory->newInteger(new BigInteger(9))];
|
||||
// 2^252 + 0x14def9dea2f79cd65812631a5cf5d3ed
|
||||
$this->setOrder(new BigInteger('1000000000000000000000000000000014DEF9DEA2F79CD65812631A5CF5D3ED', 16));
|
||||
|
||||
/*
|
||||
$this->setCoefficients(
|
||||
new BigInteger('486662'), // a
|
||||
);
|
||||
$this->setBasePoint(
|
||||
new BigInteger(9),
|
||||
new BigInteger('14781619447589544791020593568409986887264606134616475288964881837755586237401')
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply a point on the curve by a scalar
|
||||
*
|
||||
* Modifies the scalar as described at https://tools.ietf.org/html/rfc7748#page-8
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiplyPoint(array $p, Integer $d)
|
||||
{
|
||||
//$r = strrev(sodium_crypto_scalarmult($d->toBytes(), strrev($p[0]->toBytes())));
|
||||
//return [$this->factory->newInteger(new BigInteger($r, 256))];
|
||||
|
||||
$d = $d->toBytes();
|
||||
$d&= "\xF8" . str_repeat("\xFF", 30) . "\x7F";
|
||||
$d = strrev($d);
|
||||
$d|= "\x40";
|
||||
$d = $this->factory->newInteger(new BigInteger($d, -256));
|
||||
|
||||
return parent::multiplyPoint($p, $d);
|
||||
}
|
||||
}
|
71
phpseclib/Crypt/EC/Curves/Curve448.php
Normal file
71
phpseclib/Crypt/EC/Curves/Curve448.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Curve448
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2019 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Montgomery;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class Curve448 extends Montgomery
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// 2^448 - 2^224 - 1
|
||||
$this->setModulo(new BigInteger(
|
||||
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' .
|
||||
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 16));
|
||||
$this->a24 = $this->factory->newInteger(new BigInteger('39081'));
|
||||
$this->p = [$this->factory->newInteger(new BigInteger(5))];
|
||||
// 2^446 - 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
|
||||
$this->setOrder(new BigInteger(
|
||||
'3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' .
|
||||
'7CCA23E9C44EDB49AED63690216CC2728DC58F552378C292AB5844F3', 16));
|
||||
|
||||
/*
|
||||
$this->setCoefficients(
|
||||
new BigInteger('156326'), // a
|
||||
);
|
||||
$this->setBasePoint(
|
||||
new BigInteger(5),
|
||||
new BigInteger(
|
||||
'355293926785568175264127502063783334808976399387714271831880898' .
|
||||
'435169088786967410002932673765864550910142774147268105838985595290' .
|
||||
'606362')
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply a point on the curve by a scalar
|
||||
*
|
||||
* Modifies the scalar as described at https://tools.ietf.org/html/rfc7748#page-8
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function multiplyPoint(array $p, Integer $d)
|
||||
{
|
||||
//$r = strrev(sodium_crypto_scalarmult($d->toBytes(), strrev($p[0]->toBytes())));
|
||||
//return [$this->factory->newInteger(new BigInteger($r, 256))];
|
||||
|
||||
$d = $d->toBytes();
|
||||
$d[0] = $d[0] & "\xFC";
|
||||
$d = strrev($d);
|
||||
$d|= "\x80";
|
||||
$d = $this->factory->newInteger(new BigInteger($d, 256));
|
||||
|
||||
return parent::multiplyPoint($p, $d);
|
||||
}
|
||||
}
|
@ -6,15 +6,15 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\TwistedEdwards;
|
||||
use phpseclib\Crypt\EC\BaseCurves\TwistedEdwards;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\Hash;
|
||||
use phpseclib\Crypt\Random;
|
||||
@ -100,7 +100,7 @@ class Ed25519 extends TwistedEdwards
|
||||
*
|
||||
* Implements steps 2-4 at https://tools.ietf.org/html/rfc8032#section-5.1.3
|
||||
*
|
||||
* Used by ECDSA\Keys\Common.php
|
||||
* Used by EC\Keys\Common.php
|
||||
*
|
||||
* @param BigInteger $x
|
||||
* @param boolean $sign
|
@ -6,15 +6,15 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\TwistedEdwards;
|
||||
use phpseclib\Crypt\EC\BaseCurves\TwistedEdwards;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\Hash;
|
||||
use phpseclib\Crypt\Random;
|
||||
@ -52,7 +52,7 @@ class Ed448 extends TwistedEdwards
|
||||
*
|
||||
* Implements steps 2-4 at https://tools.ietf.org/html/rfc8032#section-5.2.3
|
||||
*
|
||||
* Used by ECDSA\Keys\Common.php
|
||||
* Used by EC\Keys\Common.php
|
||||
*
|
||||
* @param BigInteger $x
|
||||
* @param boolean $sign
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP160r1 extends Prime
|
@ -19,16 +19,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP160t1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP192r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP192t1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP224r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP224t1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP256r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP256t1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP320r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP320t1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP384r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP384t1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP512r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class brainpoolP512t1 extends Prime
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistb233 extends sect233r1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistb409 extends sect409r1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistk163 extends sect163k1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistk233 extends sect233k1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistk283 extends sect283k1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistk409 extends sect409k1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistp192 extends secp192r1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistp224 extends secp224r1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistp256 extends secp256r1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistp384 extends secp384r1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistp521 extends secp521r1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class nistt571 extends sect571k1
|
||||
{
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class prime192v1 extends secp192r1
|
||||
{
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class prime192v2 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class prime192v3 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class prime239v1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class prime239v2 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class prime239v3 extends Prime
|
@ -6,14 +6,14 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
final class prime256v1 extends secp256r1
|
||||
{
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp112r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp112r2 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp128r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp128r2 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\KoblitzPrime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\KoblitzPrime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp160k1 extends KoblitzPrime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp160r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp160r2 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\KoblitzPrime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\KoblitzPrime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp192k1 extends KoblitzPrime
|
@ -8,16 +8,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp192r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\KoblitzPrime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\KoblitzPrime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp224k1 extends KoblitzPrime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp224r1 extends Prime
|
@ -8,17 +8,17 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
//use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\KoblitzPrime;
|
||||
//use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\KoblitzPrime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
//class secp256k1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp256r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp384r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class secp521r1 extends Prime
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect113r1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect113r2 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect131r1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect131r2 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect163k1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect163r1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect163r2 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect193r1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect193r2 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect233k1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect233r1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wiggint on <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect239k1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wiggint on <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect283k1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wiggint on <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect283r1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wiggint on <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect409k1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wiggint on <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect409r1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wiggint on <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect571k1 extends Binary
|
@ -6,16 +6,16 @@
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wiggint on <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://pear.php.net/package/Math_BigInteger
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Curves;
|
||||
namespace phpseclib\Crypt\EC\Curves;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
class sect571r1 extends Binary
|
@ -1,25 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Generic ECDSA Key Parsing Helper functions
|
||||
* Generic EC Key Parsing Helper functions
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Keys;
|
||||
namespace phpseclib\Crypt\EC\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Hex;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime as PrimeCurve;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Binary as BinaryCurve;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime as PrimeCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Binary as BinaryCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Math\PrimeField;
|
||||
@ -28,9 +28,9 @@ use phpseclib\File\ASN1\Maps;
|
||||
use phpseclib\Exception\UnsupportedCurveException;
|
||||
|
||||
/**
|
||||
* Generic ECDSA Key Parsing Helper functions
|
||||
* Generic EC Key Parsing Helper functions
|
||||
*
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
@ -189,7 +189,7 @@ trait Common
|
||||
* If the key contains an implicit curve phpseclib needs the curve
|
||||
* to be explicitly provided
|
||||
*
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
*/
|
||||
public static function setImplicitCurve(BaseCurve $curve)
|
||||
{
|
||||
@ -197,11 +197,11 @@ trait Common
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of \phpseclib\Crypt\ECDSA\BaseCurves\Base based
|
||||
* Returns an instance of \phpseclib\Crypt\EC\BaseCurves\Base based
|
||||
* on the curve parameters
|
||||
*
|
||||
* @param array $params
|
||||
* @return \phpseclib\Crypt\ECDSA\BaseCurves\Base|false
|
||||
* @return \phpseclib\Crypt\EC\BaseCurves\Base|false
|
||||
*/
|
||||
protected static function loadCurveByParam(array $params)
|
||||
{
|
||||
@ -209,7 +209,7 @@ trait Common
|
||||
throw new \RuntimeException('No parameters are present');
|
||||
}
|
||||
if (isset($params['namedCurve'])) {
|
||||
$curve = '\phpseclib\Crypt\ECDSA\Curves\\' . $params['namedCurve'];
|
||||
$curve = '\phpseclib\Crypt\EC\Curves\\' . $params['namedCurve'];
|
||||
if (!class_exists($curve)) {
|
||||
throw new UnsupportedCurveException('Named Curve of ' . $params['namedCurve'] . ' is not supported');
|
||||
}
|
||||
@ -275,7 +275,7 @@ trait Common
|
||||
* Supports both compressed and uncompressed points
|
||||
*
|
||||
* @param string $str
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @return object[]
|
||||
*/
|
||||
public static function extractPoint($str, BaseCurve $curve)
|
||||
@ -341,7 +341,7 @@ trait Common
|
||||
* Encode Parameters
|
||||
*
|
||||
* @todo Maybe at some point this could be moved to __toString() for each of the curves?
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @param bool $returnArray optional
|
||||
* @param array $options optional
|
||||
* @return string|false
|
||||
@ -367,7 +367,7 @@ trait Common
|
||||
continue;
|
||||
}
|
||||
$testName = $file->getBasename('.php');
|
||||
$class = 'phpseclib\Crypt\ECDSA\Curves\\' . $testName;
|
||||
$class = 'phpseclib\Crypt\EC\Curves\\' . $testName;
|
||||
$reflect = new \ReflectionClass($class);
|
||||
if ($reflect->isFinal()) {
|
||||
continue;
|
||||
@ -544,7 +544,7 @@ trait Common
|
||||
/**
|
||||
* Use Named Curve
|
||||
*
|
||||
* A named curve does not include any parameters. It is up to the ECDSA parameters to
|
||||
* A named curve does not include any parameters. It is up to the EC parameters to
|
||||
* know what the coefficients, the base points, etc, are from the name of the curve.
|
||||
* A named curve is a more concise way of representing a curve
|
||||
*/
|
103
phpseclib/Crypt/EC/Formats/Keys/MontgomeryPrivate.php
Normal file
103
phpseclib/Crypt/EC/Formats/Keys/MontgomeryPrivate.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Montgomery Private Key Handler
|
||||
*
|
||||
* "Naked" Curve25519 private keys can pretty much be any sequence of random 32x bytes so unless
|
||||
* we have a "hidden" key handler pretty much every 32 byte string will be loaded as a curve25519
|
||||
* private key even if it probably isn't one by PublicKeyLoader.
|
||||
*
|
||||
* "Naked" Curve25519 public keys also a string of 32 bytes so distinguishing between a "naked"
|
||||
* curve25519 private key and a public key is nigh impossible, hence separate plugins for each
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Crypt
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\EC\Formats\Keys;
|
||||
|
||||
use phpseclib\Crypt\EC\Curves\Curve25519;
|
||||
use phpseclib\Crypt\EC\Curves\Curve448;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Montgomery as MontgomeryCurve;
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
/**
|
||||
* Montgomery Curve Private Key Handler
|
||||
*
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
abstract class MontgomeryPrivate
|
||||
{
|
||||
/**
|
||||
* Is invisible flag
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
const IS_INVISIBLE = true;
|
||||
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @access public
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
switch (strlen($key)) {
|
||||
case 32:
|
||||
$curve = new Curve25519;
|
||||
break;
|
||||
case 56:
|
||||
$curve = new Curve448;
|
||||
break;
|
||||
default:
|
||||
throw new \LengthException('The only supported lengths are 32 and 56');
|
||||
}
|
||||
|
||||
$components = ['curve' => $curve];
|
||||
$components['dA'] = $components['curve']->convertInteger(new BigInteger($key, 256));
|
||||
// note that EC::getEncodedCoordinates does some additional "magic" (it does strrev on the result)
|
||||
$components['QA'] = $components['curve']->multiplyPoint($components['curve']->getBasePoint(), $components['dA']);
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an EC public key to the appropriate format
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Crypt\EC\Curves\MontgomeryCurve $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(MontgomeryCurve $curve, array $publicKey)
|
||||
{
|
||||
return strrev($publicKey[0]->toBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a private key to the appropriate format.
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer $privateKey
|
||||
* @param \phpseclib\Crypt\EC\Curves\Montgomery $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @param string $password optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePrivateKey(Integer $privateKey, MontgomeryCurve $curve, array $publicKey, $password = '')
|
||||
{
|
||||
return $privateKey->toBytes();
|
||||
}
|
||||
}
|
79
phpseclib/Crypt/EC/Formats/Keys/MontgomeryPublic.php
Normal file
79
phpseclib/Crypt/EC/Formats/Keys/MontgomeryPublic.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Montgomery Public Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Crypt
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\EC\Formats\Keys;
|
||||
|
||||
use phpseclib\Crypt\EC\Curves\Curve25519;
|
||||
use phpseclib\Crypt\EC\Curves\Curve448;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Montgomery as MontgomeryCurve;
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
use phpseclib\Math\BigInteger;
|
||||
|
||||
/**
|
||||
* Montgomery Public Key Handler
|
||||
*
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
abstract class MontgomeryPublic
|
||||
{
|
||||
/**
|
||||
* Is invisible flag
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
const IS_INVISIBLE = true;
|
||||
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @access public
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
switch (strlen($key)) {
|
||||
case 32:
|
||||
$curve = new Curve25519;
|
||||
break;
|
||||
case 56:
|
||||
$curve = new Curve448;
|
||||
break;
|
||||
default:
|
||||
throw new \LengthException('The only supported lengths are 32 and 56');
|
||||
}
|
||||
|
||||
$components = ['curve' => $curve];
|
||||
$components['QA'] = [$components['curve']->convertInteger(new BigInteger(strrev($key), 256))];
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an EC public key to the appropriate format
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Crypt\EC\Curves\Montgomery $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(MontgomeryCurve $curve, array $publicKey)
|
||||
{
|
||||
return strrev($publicKey[0]->toBytes());
|
||||
}
|
||||
}
|
@ -1,35 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenSSH Formatted ECDSA Key Handler
|
||||
* OpenSSH Formatted EC Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Place in $HOME/.ssh/authorized_keys
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Keys;
|
||||
namespace phpseclib\Crypt\EC\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Crypt\Common\Formats\Keys\OpenSSH as Progenitor;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Exception\UnsupportedCurveException;
|
||||
use phpseclib\Crypt\ECDSA\Curves\Ed25519;
|
||||
use phpseclib\Crypt\EC\Curves\Ed25519;
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
|
||||
/**
|
||||
* OpenSSH Formatted ECDSA Key Handler
|
||||
* OpenSSH Formatted EC Key Handler
|
||||
*
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
@ -92,7 +92,7 @@ abstract class OpenSSH extends Progenitor
|
||||
$qa = self::extractPoint($parsed['publicKey'], $curve);
|
||||
} else {
|
||||
list($curveName, $publicKey) = Strings::unpackSSH2('ss', $parsed['publicKey']);
|
||||
$curveName = '\phpseclib\Crypt\ECDSA\Curves\\' . $curveName;
|
||||
$curveName = '\phpseclib\Crypt\EC\Curves\\' . $curveName;
|
||||
$curve = new $curveName();
|
||||
|
||||
$qa = self::extractPoint("\0" . $publicKey, $curve);
|
||||
@ -138,10 +138,10 @@ abstract class OpenSSH extends Progenitor
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an ECDSA public key to the appropriate format
|
||||
* Convert an EC public key to the appropriate format
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
@ -180,7 +180,7 @@ abstract class OpenSSH extends Progenitor
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer $privateKey
|
||||
* @param \phpseclib\Crypt\ECDSA\Curves\Ed25519 $curve
|
||||
* @param \phpseclib\Crypt\EC\Curves\Ed25519 $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* "PKCS1" (RFC5915) Formatted ECDSA Key Handler
|
||||
* "PKCS1" (RFC5915) Formatted EC Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
@ -18,29 +18,30 @@
|
||||
* all. I suppose this could also be named IETF but idk
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Keys;
|
||||
namespace phpseclib\Crypt\EC\Formats\Keys;
|
||||
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
use phpseclib\Crypt\Common\Formats\Keys\PKCS1 as Progenitor;
|
||||
use phpseclib\File\ASN1;
|
||||
use phpseclib\File\ASN1\Maps;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Montgomery as MontgomeryCurve;
|
||||
use phpseclib\Exception\UnsupportedCurveException;
|
||||
|
||||
/**
|
||||
* "PKCS1" (RFC5915) Formatted ECDSA Key Handler
|
||||
* "PKCS1" (RFC5915) Formatted EC Key Handler
|
||||
*
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
@ -87,7 +88,7 @@ abstract class PKCS1 extends Progenitor
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ECDSA parameters to the appropriate format
|
||||
* Convert EC parameters to the appropriate format
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
@ -96,8 +97,8 @@ abstract class PKCS1 extends Progenitor
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
if ($curve instanceof TwistedEdwardsCurve) {
|
||||
throw new UnsupportedCurveException('TwistedEdwards Curves are not supported');
|
||||
if ($curve instanceof TwistedEdwardsCurve || $curve instanceof MontgomeryCurve) {
|
||||
throw new UnsupportedCurveException('TwistedEdwards and Montgomery Curves are not supported');
|
||||
}
|
||||
|
||||
$key = self::encodeParameters($curve, false, $options);
|
||||
@ -112,7 +113,7 @@ abstract class PKCS1 extends Progenitor
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer $privateKey
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
||||
@ -122,7 +123,7 @@ abstract class PKCS1 extends Progenitor
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
if ($curve instanceof TwistedEdwardsCurve) {
|
||||
if ($curve instanceof TwistedEdwardsCurve || $curve instanceof MontgomeryCurve) {
|
||||
throw new UnsupportedCurveException('TwistedEdwards Curves are not supported');
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PKCS#8 Formatted ECDSA Key Handler
|
||||
* PKCS#8 Formatted EC Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
@ -16,29 +16,31 @@
|
||||
* for keys. This just extends that same concept to public keys (much like ssh-keygen)
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Keys;
|
||||
namespace phpseclib\Crypt\EC\Formats\Keys;
|
||||
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\Common\Formats\Keys\PKCS8 as Progenitor;
|
||||
use phpseclib\File\ASN1;
|
||||
use phpseclib\File\ASN1\Maps;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Montgomery as MontgomeryCurve;
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
use phpseclib\Crypt\ECDSA\Curves\Ed25519;
|
||||
use phpseclib\Crypt\ECDSA\Curves\Ed448;
|
||||
use phpseclib\Crypt\EC\Curves\Ed25519;
|
||||
use phpseclib\Crypt\EC\Curves\Ed448;
|
||||
use phpseclib\Exception\UnsupportedCurveException;
|
||||
|
||||
/**
|
||||
* PKCS#8 Formatted ECDSA Key Handler
|
||||
* PKCS#8 Formatted EC Key Handler
|
||||
*
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
@ -164,10 +166,10 @@ abstract class PKCS8 extends Progenitor
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an ECDSA public key to the appropriate format
|
||||
* Convert an EC public key to the appropriate format
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @param array $optiona optional
|
||||
* @return string
|
||||
@ -176,6 +178,10 @@ abstract class PKCS8 extends Progenitor
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
if ($curve instanceof MontgomeryCurve) {
|
||||
throw new UnsupportedCurveException('Montgomery Curves are not supported');
|
||||
}
|
||||
|
||||
if ($curve instanceof TwistedEdwardsCurve) {
|
||||
return self::wrapPublicKey(
|
||||
$curve->encodePoint($publicKey),
|
||||
@ -196,7 +202,7 @@ abstract class PKCS8 extends Progenitor
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer $privateKey
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
||||
@ -206,6 +212,10 @@ abstract class PKCS8 extends Progenitor
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
if ($curve instanceof MontgomeryCurve) {
|
||||
throw new UnsupportedCurveException('Montgomery Curves are not supported');
|
||||
}
|
||||
|
||||
if ($curve instanceof TwistedEdwardsCurve) {
|
||||
return self::wrapPrivateKey(
|
||||
"\x04\x20" . $privateKey->secret,
|
@ -1,32 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PuTTY Formatted ECDSA Key Handler
|
||||
* PuTTY Formatted EC Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Keys;
|
||||
namespace phpseclib\Crypt\EC\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Crypt\Common\Formats\Keys\PuTTY as Progenitor;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
|
||||
/**
|
||||
* PuTTY Formatted ECDSA Key Handler
|
||||
* PuTTY Formatted EC Key Handler
|
||||
*
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
@ -40,7 +40,7 @@ abstract class PuTTY extends Progenitor
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
const PUBLIC_HANDLER = 'phpseclib\Crypt\ECDSA\Formats\Keys\OpenSSH';
|
||||
const PUBLIC_HANDLER = 'phpseclib\Crypt\EC\Formats\Keys\OpenSSH';
|
||||
|
||||
/**
|
||||
* Supported Key Types
|
||||
@ -93,7 +93,7 @@ abstract class PuTTY extends Progenitor
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer $privateKey
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
||||
@ -126,10 +126,10 @@ abstract class PuTTY extends Progenitor
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an ECDSA public key to the appropriate format
|
||||
* Convert an EC public key to the appropriate format
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField[] $publicKey
|
||||
* @return string
|
||||
*/
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* XML Formatted ECDSA Key Handler
|
||||
* XML Formatted EC Key Handler
|
||||
*
|
||||
* More info:
|
||||
*
|
||||
@ -11,26 +11,27 @@
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Keys;
|
||||
namespace phpseclib\Crypt\EC\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\Prime as PrimeCurve;
|
||||
use phpseclib\Crypt\ECDSA\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Prime as PrimeCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\TwistedEdwards as TwistedEdwardsCurve;
|
||||
use phpseclib\Crypt\EC\BaseCurves\Montgomery as MontgomeryCurve;
|
||||
use phpseclib\Exception\UnsupportedCurveException;
|
||||
|
||||
/**
|
||||
* XML Formatted ECDSA Key Handler
|
||||
* XML Formatted EC Key Handler
|
||||
*
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
@ -168,7 +169,7 @@ abstract class XML
|
||||
* Extract points from an XML document
|
||||
*
|
||||
* @param \DOMXPath $xpath
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @return object[]
|
||||
*/
|
||||
private static function extractPointRFC4050(\DOMXPath $xpath, BaseCurve $curve)
|
||||
@ -192,11 +193,11 @@ abstract class XML
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of \phpseclib\Crypt\ECDSA\BaseCurves\Base based
|
||||
* Returns an instance of \phpseclib\Crypt\EC\BaseCurves\Base based
|
||||
* on the curve parameters
|
||||
*
|
||||
* @param \DomXPath $xpath
|
||||
* @return \phpseclib\Crypt\ECDSA\BaseCurves\Base|false
|
||||
* @return \phpseclib\Crypt\EC\BaseCurves\Base|false
|
||||
*/
|
||||
private static function loadCurveByParam(\DOMXPath $xpath)
|
||||
{
|
||||
@ -209,7 +210,7 @@ abstract class XML
|
||||
throw new UnsupportedCurveException('Curve with OID of ' . $oid . ' is not supported');
|
||||
}
|
||||
|
||||
$curve = '\phpseclib\Crypt\ECDSA\Curves\\' . $name;
|
||||
$curve = '\phpseclib\Crypt\EC\Curves\\' . $name;
|
||||
if (!class_exists($curve)) {
|
||||
throw new UnsupportedCurveException('Named Curve of ' . $name . ' is not supported');
|
||||
}
|
||||
@ -272,11 +273,11 @@ abstract class XML
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of \phpseclib\Crypt\ECDSA\BaseCurves\Base based
|
||||
* Returns an instance of \phpseclib\Crypt\EC\BaseCurves\Base based
|
||||
* on the curve parameters
|
||||
*
|
||||
* @param \DomXPath $xpath
|
||||
* @return \phpseclib\Crypt\ECDSA\BaseCurves\Base|false
|
||||
* @return \phpseclib\Crypt\EC\BaseCurves\Base|false
|
||||
*/
|
||||
private static function loadCurveByParamRFC4050(\DOMXPath $xpath)
|
||||
{
|
||||
@ -363,7 +364,7 @@ abstract class XML
|
||||
/**
|
||||
* Convert a public key to the appropriate format
|
||||
*
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
@ -372,8 +373,8 @@ abstract class XML
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
if ($curve instanceof TwistedEdwardsCurve) {
|
||||
throw new UnsupportedCurveException('TwistedEdwards Curves are not supported');
|
||||
if ($curve instanceof TwistedEdwardsCurve || $curve instanceof MontgomeryCurve) {
|
||||
throw new UnsupportedCurveException('TwistedEdwards and Montgomery Curves are not supported');
|
||||
}
|
||||
|
||||
if (empty(static::$namespace)) {
|
||||
@ -395,16 +396,16 @@ abstract class XML
|
||||
|
||||
$publicKey = "\4" . $publicKey[0]->toBytes() . $publicKey[1]->toBytes();
|
||||
|
||||
return '<' . $pre . 'ECKeyValue xmlns' . $post . '="http://www.w3.org/2009/xmldsig11#">' . "\r\n" .
|
||||
return '<' . $pre . 'ECDSAKeyValue xmlns' . $post . '="http://www.w3.org/2009/xmldsig11#">' . "\r\n" .
|
||||
self::encodeXMLParameters($curve, $pre, $options) . "\r\n" .
|
||||
'<' . $pre . 'PublicKey>' . Base64::encode($publicKey) . '</' . $pre . 'PublicKey>' . "\r\n" .
|
||||
'</' . $pre . 'ECKeyValue>';
|
||||
'</' . $pre . 'ECDSAKeyValue>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Parameters
|
||||
*
|
||||
* @param \phpseclib\Crypt\ECDSA\BaseCurves\Base $curve
|
||||
* @param \phpseclib\Crypt\EC\BaseCurves\Base $curve
|
||||
* @param string $pre
|
||||
* @param array $options optional
|
||||
* @return string|false
|
@ -10,22 +10,22 @@
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Crypt
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2015 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Keys;
|
||||
namespace phpseclib\Crypt\EC\Formats\Keys;
|
||||
|
||||
use phpseclib\Crypt\ECDSA\Curves\Ed25519;
|
||||
use phpseclib\Crypt\EC\Curves\Ed25519;
|
||||
use phpseclib\Math\Common\FiniteField\Integer;
|
||||
|
||||
/**
|
||||
* libsodium Key Handler
|
||||
*
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
@ -33,6 +33,13 @@ abstract class libsodium
|
||||
{
|
||||
use Common;
|
||||
|
||||
/**
|
||||
* Is invisible flag
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
const IS_INVISIBLE = true;
|
||||
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
@ -76,10 +83,10 @@ abstract class libsodium
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an ECDSA public key to the appropriate format
|
||||
* Convert an EC public key to the appropriate format
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Crypt\ECDSA\Curves\Ed25519 $curve
|
||||
* @param \phpseclib\Crypt\EC\Curves\Ed25519 $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @return string
|
||||
*/
|
||||
@ -93,7 +100,7 @@ abstract class libsodium
|
||||
*
|
||||
* @access public
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer $privateKey
|
||||
* @param \phpseclib\Crypt\ECDSA\Curves\Ed25519 $curve
|
||||
* @param \phpseclib\Crypt\EC\Curves\Ed25519 $curve
|
||||
* @param \phpseclib\Math\Common\FiniteField\Integer[] $publicKey
|
||||
* @param string $password optional
|
||||
* @return string
|
@ -16,7 +16,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Signature;
|
||||
namespace phpseclib\Crypt\EC\Formats\Signature;
|
||||
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\File\ASN1 as Encoder;
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Raw ECDSA Signature Handler
|
||||
* Raw EC Signature Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
@ -13,14 +13,14 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Signature;
|
||||
namespace phpseclib\Crypt\EC\Formats\Signature;
|
||||
|
||||
use phpseclib\Crypt\Common\Formats\Signature\Raw as Progenitor;
|
||||
|
||||
/**
|
||||
* Raw DSA Signature Handler
|
||||
*
|
||||
* @package ECDSA
|
||||
* @package EC
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
@ -15,7 +15,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Crypt\ECDSA\Formats\Signature;
|
||||
namespace phpseclib\Crypt\EC\Formats\Signature;
|
||||
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Common\Functions\Strings;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user