Merged in feature/MAW-855-import-code-into-aws (pull request #2)
code import from pantheon * code import from pantheon
This commit is contained in:
@@ -102,8 +102,7 @@ class UsersMessages extends \WPMailSMTP\Vendor\Google\Service\Resource
|
||||
* scanning and classification similar to receiving via SMTP. This method
|
||||
* doesn't perform SPF checks, so it might not work for some spam messages, such
|
||||
* as those attempting to perform domain spoofing. This method does not send a
|
||||
* message. Note: This function doesn't trigger forwarding rules or filters set
|
||||
* up by the user. (messages.import)
|
||||
* message. (messages.import)
|
||||
*
|
||||
* @param string $userId The user's email address. The special value `me` can be
|
||||
* used to indicate the authenticated user.
|
||||
|
||||
@@ -232,7 +232,7 @@ class Verify
|
||||
return 'phpseclib3\\Crypt\\AES::ENGINE_OPENSSL';
|
||||
}
|
||||
if (\class_exists('WPMailSMTP\\Vendor\\phpseclib\\Crypt\\RSA')) {
|
||||
return 'WPMailSMTP\\Vendor\\phpseclib\\Crypt\\RSA::MODE_OPENSSL';
|
||||
return 'phpseclib\\Crypt\\RSA::MODE_OPENSSL';
|
||||
}
|
||||
if (\class_exists('WPMailSMTP\\Vendor\\Crypt_RSA')) {
|
||||
return 'CRYPT_RSA_MODE_OPENSSL';
|
||||
|
||||
@@ -59,7 +59,7 @@ final class Each
|
||||
*/
|
||||
public static function ofLimitAll($iterable, $concurrency, callable $onFulfilled = null)
|
||||
{
|
||||
return each_limit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $aggregate) {
|
||||
return self::ofLimit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $aggregate) {
|
||||
$aggregate->reject($reason);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ final class Utils
|
||||
{
|
||||
$results = [];
|
||||
foreach ($promises as $key => $promise) {
|
||||
$results[$key] = inspect($promise);
|
||||
$results[$key] = self::inspect($promise);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ final class AppendStream implements \WPMailSMTP\Vendor\Psr\Http\Message\StreamIn
|
||||
if ($this->current === $total) {
|
||||
break;
|
||||
}
|
||||
$this->current++;
|
||||
++$this->current;
|
||||
}
|
||||
$result = $this->streams[$this->current]->read($remaining);
|
||||
if ($result === '') {
|
||||
@@ -194,8 +194,6 @@ final class AppendStream implements \WPMailSMTP\Vendor\Psr\Http\Message\StreamIn
|
||||
throw new \RuntimeException('Cannot write to an AppendStream');
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
|
||||
@@ -109,8 +109,6 @@ final class BufferStream implements \WPMailSMTP\Vendor\Psr\Http\Message\StreamIn
|
||||
return \strlen($string);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
|
||||
@@ -139,8 +139,6 @@ final class FnStream implements \WPMailSMTP\Vendor\Psr\Http\Message\StreamInterf
|
||||
return \call_user_func($this->_fn_getContents);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
|
||||
@@ -81,7 +81,7 @@ final class Header
|
||||
$v = '';
|
||||
$isQuoted = \false;
|
||||
$isEscaped = \false;
|
||||
for ($i = 0, $max = \strlen($value); $i < $max; $i++) {
|
||||
for ($i = 0, $max = \strlen($value); $i < $max; ++$i) {
|
||||
if ($isEscaped) {
|
||||
$v .= $value[$i];
|
||||
$isEscaped = \false;
|
||||
|
||||
@@ -11,9 +11,9 @@ use WPMailSMTP\Vendor\Psr\Http\Message\StreamInterface;
|
||||
* then appends the zlib.inflate filter. The stream is then converted back
|
||||
* to a Guzzle stream resource to be used as a Guzzle stream.
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc1950
|
||||
* @link http://tools.ietf.org/html/rfc1952
|
||||
* @link http://php.net/manual/en/filters.compression.php
|
||||
* @see http://tools.ietf.org/html/rfc1950
|
||||
* @see http://tools.ietf.org/html/rfc1952
|
||||
* @see http://php.net/manual/en/filters.compression.php
|
||||
*/
|
||||
final class InflateStream implements \WPMailSMTP\Vendor\Psr\Http\Message\StreamInterface
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ final class Message
|
||||
throw new \InvalidArgumentException('Unknown message type');
|
||||
}
|
||||
foreach ($message->getHeaders() as $name => $values) {
|
||||
if (\strtolower($name) === 'set-cookie') {
|
||||
if (\is_string($name) && \strtolower($name) === 'set-cookie') {
|
||||
foreach ($values as $value) {
|
||||
$msg .= "\r\n{$name}: " . $value;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ use WPMailSMTP\Vendor\Psr\Http\Message\StreamInterface;
|
||||
*/
|
||||
trait MessageTrait
|
||||
{
|
||||
/** @var array<string, string[]> Map of all registered headers, as original name => array of values */
|
||||
/** @var string[][] Map of all registered headers, as original name => array of values */
|
||||
private $headers = [];
|
||||
/** @var array<string, string> Map of lowercase header name => original name at registration */
|
||||
/** @var string[] Map of lowercase header name => original name at registration */
|
||||
private $headerNames = [];
|
||||
/** @var string */
|
||||
private $protocol = '1.1';
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -61,7 +61,7 @@ final class MultipartStream implements \WPMailSMTP\Vendor\Psr\Http\Message\Strea
|
||||
$stream = new \WPMailSMTP\Vendor\GuzzleHttp\Psr7\AppendStream();
|
||||
foreach ($elements as $element) {
|
||||
if (!\is_array($element)) {
|
||||
throw new \UnexpectedValueException("An array is expected");
|
||||
throw new \UnexpectedValueException('An array is expected');
|
||||
}
|
||||
$this->addElement($stream, $element);
|
||||
}
|
||||
@@ -105,9 +105,7 @@ final class MultipartStream implements \WPMailSMTP\Vendor\Psr\Http\Message\Strea
|
||||
// Set a default Content-Type if one was not supplied
|
||||
$type = $this->getHeader($headers, 'content-type');
|
||||
if (!$type && ($filename === '0' || $filename)) {
|
||||
if ($type = \WPMailSMTP\Vendor\GuzzleHttp\Psr7\MimeType::fromFilename($filename)) {
|
||||
$headers['Content-Type'] = $type;
|
||||
}
|
||||
$headers['Content-Type'] = \WPMailSMTP\Vendor\GuzzleHttp\Psr7\MimeType::fromFilename($filename) ?? 'application/octet-stream';
|
||||
}
|
||||
return [$stream, $headers];
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ final class PumpStream implements \WPMailSMTP\Vendor\Psr\Http\Message\StreamInte
|
||||
/** @var BufferStream */
|
||||
private $buffer;
|
||||
/**
|
||||
* @param callable(int): (string|null|false) $source Source of the stream data. The callable MAY
|
||||
* @param callable(int): (string|false|null) $source Source of the stream data. The callable MAY
|
||||
* accept an integer argument used to control the
|
||||
* amount of data to return. The callable MUST
|
||||
* return a string when called, or false|null on error
|
||||
@@ -123,8 +123,6 @@ final class PumpStream implements \WPMailSMTP\Vendor\Psr\Http\Message\StreamInte
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
|
||||
@@ -13,7 +13,7 @@ final class Rfc7230
|
||||
*
|
||||
* Note: header delimiter (\r\n) is modified to \r?\n to accept line feed only delimiters for BC reasons.
|
||||
*
|
||||
* @link https://github.com/amphp/http/blob/v1.0.1/src/Rfc7230.php#L12-L15
|
||||
* @see https://github.com/amphp/http/blob/v1.0.1/src/Rfc7230.php#L12-L15
|
||||
*
|
||||
* @license https://github.com/amphp/http/blob/v1.0.1/LICENSE
|
||||
*/
|
||||
|
||||
@@ -222,8 +222,6 @@ class ServerRequest extends \WPMailSMTP\Vendor\GuzzleHttp\Psr7\Request implement
|
||||
return $new;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return array|object|null
|
||||
*/
|
||||
public function getParsedBody()
|
||||
@@ -241,8 +239,6 @@ class ServerRequest extends \WPMailSMTP\Vendor\GuzzleHttp\Psr7\Request implement
|
||||
return $this->attributes;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAttribute($attribute, $default = null)
|
||||
|
||||
@@ -218,8 +218,6 @@ class Stream implements \WPMailSMTP\Vendor\Psr\Http\Message\StreamInterface
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
|
||||
@@ -69,8 +69,6 @@ trait StreamDecoratorTrait
|
||||
$this->stream->close();
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
|
||||
@@ -25,13 +25,13 @@ class Uri implements \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface, \JsonSeri
|
||||
/**
|
||||
* Unreserved characters for use in a regex.
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-2.3
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-2.3
|
||||
*/
|
||||
private const CHAR_UNRESERVED = 'a-zA-Z0-9_\\-\\.~';
|
||||
/**
|
||||
* Sub-delims for use in a regex.
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-2.2
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-2.2
|
||||
*/
|
||||
private const CHAR_SUB_DELIMS = '!\\$&\'\\(\\)\\*\\+,;=';
|
||||
private const QUERY_SEPARATORS_REPLACEMENT = ['=' => '%3D', '&' => '%26'];
|
||||
@@ -118,7 +118,7 @@ class Uri implements \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface, \JsonSeri
|
||||
* `file:///` is the more common syntax for the file scheme anyway (Chrome for example redirects to
|
||||
* that format).
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-5.3
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-5.3
|
||||
*/
|
||||
public static function composeComponents(?string $scheme, ?string $authority, string $path, ?string $query, ?string $fragment) : string
|
||||
{
|
||||
@@ -165,7 +165,7 @@ class Uri implements \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface, \JsonSeri
|
||||
* @see Uri::isNetworkPathReference
|
||||
* @see Uri::isAbsolutePathReference
|
||||
* @see Uri::isRelativePathReference
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-4
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-4
|
||||
*/
|
||||
public static function isAbsolute(\WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $uri) : bool
|
||||
{
|
||||
@@ -176,7 +176,7 @@ class Uri implements \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface, \JsonSeri
|
||||
*
|
||||
* A relative reference that begins with two slash characters is termed an network-path reference.
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-4.2
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-4.2
|
||||
*/
|
||||
public static function isNetworkPathReference(\WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $uri) : bool
|
||||
{
|
||||
@@ -187,7 +187,7 @@ class Uri implements \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface, \JsonSeri
|
||||
*
|
||||
* A relative reference that begins with a single slash character is termed an absolute-path reference.
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-4.2
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-4.2
|
||||
*/
|
||||
public static function isAbsolutePathReference(\WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $uri) : bool
|
||||
{
|
||||
@@ -198,7 +198,7 @@ class Uri implements \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface, \JsonSeri
|
||||
*
|
||||
* A relative reference that does not begin with a slash character is termed a relative-path reference.
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-4.2
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-4.2
|
||||
*/
|
||||
public static function isRelativePathReference(\WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $uri) : bool
|
||||
{
|
||||
@@ -214,7 +214,7 @@ class Uri implements \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface, \JsonSeri
|
||||
* @param UriInterface $uri The URI to check
|
||||
* @param UriInterface|null $base An optional base URI to compare against
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-4.4
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-4.4
|
||||
*/
|
||||
public static function isSameDocumentReference(\WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $uri, \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $base = null) : bool
|
||||
{
|
||||
@@ -276,7 +276,7 @@ class Uri implements \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface, \JsonSeri
|
||||
/**
|
||||
* Creates a URI from a hash of `parse_url` components.
|
||||
*
|
||||
* @link http://php.net/manual/en/function.parse-url.php
|
||||
* @see http://php.net/manual/en/function.parse-url.php
|
||||
*
|
||||
* @throws MalformedUriException If the components do not form a valid URI.
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@ use WPMailSMTP\Vendor\Psr\Http\Message\UriInterface;
|
||||
*
|
||||
* @author Tobias Schultze
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-6
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-6
|
||||
*/
|
||||
final class UriNormalizer
|
||||
{
|
||||
@@ -102,7 +102,7 @@ final class UriNormalizer
|
||||
* @param UriInterface $uri The URI to normalize
|
||||
* @param int $flags A bitmask of normalizations to apply, see constants
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-6.2
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-6.2
|
||||
*/
|
||||
public static function normalize(\WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $uri, int $flags = self::PRESERVING_NORMALIZATIONS) : \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface
|
||||
{
|
||||
@@ -146,7 +146,7 @@ final class UriNormalizer
|
||||
* @param UriInterface $uri2 An URI to compare
|
||||
* @param int $normalizations A bitmask of normalizations to apply, see constants
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-6.1
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-6.1
|
||||
*/
|
||||
public static function isEquivalent(\WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $uri1, \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $uri2, int $normalizations = self::PRESERVING_NORMALIZATIONS) : bool
|
||||
{
|
||||
|
||||
@@ -9,14 +9,14 @@ use WPMailSMTP\Vendor\Psr\Http\Message\UriInterface;
|
||||
*
|
||||
* @author Tobias Schultze
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3986#section-5
|
||||
* @see https://tools.ietf.org/html/rfc3986#section-5
|
||||
*/
|
||||
final class UriResolver
|
||||
{
|
||||
/**
|
||||
* Removes dot segments from a path and returns the new path.
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc3986#section-5.2.4
|
||||
* @see http://tools.ietf.org/html/rfc3986#section-5.2.4
|
||||
*/
|
||||
public static function removeDotSegments(string $path) : string
|
||||
{
|
||||
@@ -46,7 +46,7 @@ final class UriResolver
|
||||
/**
|
||||
* Converts the relative URI into a new URI that is resolved against the base URI.
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc3986#section-5.2
|
||||
* @see http://tools.ietf.org/html/rfc3986#section-5.2
|
||||
*/
|
||||
public static function resolve(\WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $base, \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $rel) : \WPMailSMTP\Vendor\Psr\Http\Message\UriInterface
|
||||
{
|
||||
|
||||
@@ -185,7 +185,7 @@ final class Utils
|
||||
* @param StreamInterface $stream Stream to read from
|
||||
* @param int|null $maxLength Maximum buffer length
|
||||
*/
|
||||
public static function readLine(\WPMailSMTP\Vendor\Psr\Http\Message\StreamInterface $stream, ?int $maxLength = null) : string
|
||||
public static function readLine(\WPMailSMTP\Vendor\Psr\Http\Message\StreamInterface $stream, int $maxLength = null) : string
|
||||
{
|
||||
$buffer = '';
|
||||
$size = 0;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
Copyright (c) 2011-2019 TerraFrost and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,454 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Common String Functions
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Common\Functions;
|
||||
|
||||
use WPMailSMTP\Vendor\ParagonIE\ConstantTime\Base64;
|
||||
use WPMailSMTP\Vendor\ParagonIE\ConstantTime\Base64UrlSafe;
|
||||
use WPMailSMTP\Vendor\ParagonIE\ConstantTime\Hex;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\Common\FiniteField;
|
||||
/**
|
||||
* Common String Functions
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class Strings
|
||||
{
|
||||
/**
|
||||
* String Shift
|
||||
*
|
||||
* Inspired by array_shift
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public static function shift(&$string, $index = 1)
|
||||
{
|
||||
$substr = \substr($string, 0, $index);
|
||||
$string = \substr($string, $index);
|
||||
return $substr;
|
||||
}
|
||||
/**
|
||||
* String Pop
|
||||
*
|
||||
* Inspired by array_pop
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public static function pop(&$string, $index = 1)
|
||||
{
|
||||
$substr = \substr($string, -$index);
|
||||
$string = \substr($string, 0, -$index);
|
||||
return $substr;
|
||||
}
|
||||
/**
|
||||
* Parse SSH2-style string
|
||||
*
|
||||
* Returns either an array or a boolean if $data is malformed.
|
||||
*
|
||||
* Valid characters for $format are as follows:
|
||||
*
|
||||
* C = byte
|
||||
* b = boolean (true/false)
|
||||
* N = uint32
|
||||
* Q = uint64
|
||||
* s = string
|
||||
* i = mpint
|
||||
* L = name-list
|
||||
*
|
||||
* uint64 is not supported.
|
||||
*
|
||||
* @param string $format
|
||||
* @param string $data
|
||||
* @return mixed
|
||||
*/
|
||||
public static function unpackSSH2($format, &$data)
|
||||
{
|
||||
$format = self::formatPack($format);
|
||||
$result = [];
|
||||
for ($i = 0; $i < \strlen($format); $i++) {
|
||||
switch ($format[$i]) {
|
||||
case 'C':
|
||||
case 'b':
|
||||
if (!\strlen($data)) {
|
||||
throw new \LengthException('At least one byte needs to be present for successful C / b decodes');
|
||||
}
|
||||
break;
|
||||
case 'N':
|
||||
case 'i':
|
||||
case 's':
|
||||
case 'L':
|
||||
if (\strlen($data) < 4) {
|
||||
throw new \LengthException('At least four byte needs to be present for successful N / i / s / L decodes');
|
||||
}
|
||||
break;
|
||||
case 'Q':
|
||||
if (\strlen($data) < 8) {
|
||||
throw new \LengthException('At least eight byte needs to be present for successful N / i / s / L decodes');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('$format contains an invalid character');
|
||||
}
|
||||
switch ($format[$i]) {
|
||||
case 'C':
|
||||
$result[] = \ord(self::shift($data));
|
||||
continue 2;
|
||||
case 'b':
|
||||
$result[] = \ord(self::shift($data)) != 0;
|
||||
continue 2;
|
||||
case 'N':
|
||||
list(, $temp) = \unpack('N', self::shift($data, 4));
|
||||
$result[] = $temp;
|
||||
continue 2;
|
||||
case 'Q':
|
||||
// pack() added support for Q in PHP 5.6.3 and PHP 5.6 is phpseclib 3's minimum version
|
||||
// so in theory we could support this BUT, "64-bit format codes are not available for
|
||||
// 32-bit versions" and phpseclib works on 32-bit installs. on 32-bit installs
|
||||
// 64-bit floats can be used to get larger numbers then 32-bit signed ints would allow
|
||||
// for. sure, you're not gonna get the full precision of 64-bit numbers but just because
|
||||
// you need > 32-bit precision doesn't mean you need the full 64-bit precision
|
||||
\extract(\unpack('Nupper/Nlower', self::shift($data, 8)));
|
||||
$temp = $upper ? 4294967296 * $upper : 0;
|
||||
$temp += $lower < 0 ? ($lower & 0x7ffffffff) + 0x80000000 : $lower;
|
||||
// $temp = hexdec(bin2hex(self::shift($data, 8)));
|
||||
$result[] = $temp;
|
||||
continue 2;
|
||||
}
|
||||
list(, $length) = \unpack('N', self::shift($data, 4));
|
||||
if (\strlen($data) < $length) {
|
||||
throw new \LengthException("{$length} bytes needed; " . \strlen($data) . ' bytes available');
|
||||
}
|
||||
$temp = self::shift($data, $length);
|
||||
switch ($format[$i]) {
|
||||
case 'i':
|
||||
$result[] = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger($temp, -256);
|
||||
break;
|
||||
case 's':
|
||||
$result[] = $temp;
|
||||
break;
|
||||
case 'L':
|
||||
$result[] = \explode(',', $temp);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Create SSH2-style string
|
||||
*
|
||||
* @param string $format
|
||||
* @param string|int|float|array|bool ...$elements
|
||||
* @return string
|
||||
*/
|
||||
public static function packSSH2($format, ...$elements)
|
||||
{
|
||||
$format = self::formatPack($format);
|
||||
if (\strlen($format) != \count($elements)) {
|
||||
throw new \InvalidArgumentException('There must be as many arguments as there are characters in the $format string');
|
||||
}
|
||||
$result = '';
|
||||
for ($i = 0; $i < \strlen($format); $i++) {
|
||||
$element = $elements[$i];
|
||||
switch ($format[$i]) {
|
||||
case 'C':
|
||||
if (!\is_int($element)) {
|
||||
throw new \InvalidArgumentException('Bytes must be represented as an integer between 0 and 255, inclusive.');
|
||||
}
|
||||
$result .= \pack('C', $element);
|
||||
break;
|
||||
case 'b':
|
||||
if (!\is_bool($element)) {
|
||||
throw new \InvalidArgumentException('A boolean parameter was expected.');
|
||||
}
|
||||
$result .= $element ? "\1" : "\0";
|
||||
break;
|
||||
case 'Q':
|
||||
if (!\is_int($element) && !\is_float($element)) {
|
||||
throw new \InvalidArgumentException('An integer was expected.');
|
||||
}
|
||||
// 4294967296 == 1 << 32
|
||||
$result .= \pack('NN', $element / 4294967296, $element);
|
||||
break;
|
||||
case 'N':
|
||||
if (\is_float($element)) {
|
||||
$element = (int) $element;
|
||||
}
|
||||
if (!\is_int($element)) {
|
||||
throw new \InvalidArgumentException('An integer was expected.');
|
||||
}
|
||||
$result .= \pack('N', $element);
|
||||
break;
|
||||
case 's':
|
||||
if (!self::is_stringable($element)) {
|
||||
throw new \InvalidArgumentException('A string was expected.');
|
||||
}
|
||||
$result .= \pack('Na*', \strlen($element), $element);
|
||||
break;
|
||||
case 'i':
|
||||
if (!$element instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger && !$element instanceof \WPMailSMTP\Vendor\phpseclib3\Math\Common\FiniteField\Integer) {
|
||||
throw new \InvalidArgumentException('A phpseclib3\\Math\\BigInteger or phpseclib3\\Math\\Common\\FiniteField\\Integer object was expected.');
|
||||
}
|
||||
$element = $element->toBytes(\true);
|
||||
$result .= \pack('Na*', \strlen($element), $element);
|
||||
break;
|
||||
case 'L':
|
||||
if (!\is_array($element)) {
|
||||
throw new \InvalidArgumentException('An array was expected.');
|
||||
}
|
||||
$element = \implode(',', $element);
|
||||
$result .= \pack('Na*', \strlen($element), $element);
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('$format contains an invalid character');
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Expand a pack string
|
||||
*
|
||||
* Converts C5 to CCCCC, for example.
|
||||
*
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
private static function formatPack($format)
|
||||
{
|
||||
$parts = \preg_split('#(\\d+)#', $format, -1, \PREG_SPLIT_DELIM_CAPTURE);
|
||||
$format = '';
|
||||
for ($i = 1; $i < \count($parts); $i += 2) {
|
||||
$format .= \substr($parts[$i - 1], 0, -1) . \str_repeat(\substr($parts[$i - 1], -1), $parts[$i]);
|
||||
}
|
||||
$format .= $parts[$i - 1];
|
||||
return $format;
|
||||
}
|
||||
/**
|
||||
* Convert binary data into bits
|
||||
*
|
||||
* bin2hex / hex2bin refer to base-256 encoded data as binary, whilst
|
||||
* decbin / bindec refer to base-2 encoded data as binary. For the purposes
|
||||
* of this function, bin refers to base-256 encoded data whilst bits refers
|
||||
* to base-2 encoded data
|
||||
*
|
||||
* @param string $x
|
||||
* @return string
|
||||
*/
|
||||
public static function bits2bin($x)
|
||||
{
|
||||
/*
|
||||
// the pure-PHP approach is faster than the GMP approach
|
||||
if (function_exists('gmp_export')) {
|
||||
return strlen($x) ? gmp_export(gmp_init($x, 2)) : gmp_init(0);
|
||||
}
|
||||
*/
|
||||
if (\preg_match('#[^01]#', $x)) {
|
||||
throw new \RuntimeException('The only valid characters are 0 and 1');
|
||||
}
|
||||
if (!\defined('PHP_INT_MIN')) {
|
||||
\define('PHP_INT_MIN', ~\PHP_INT_MAX);
|
||||
}
|
||||
$length = \strlen($x);
|
||||
if (!$length) {
|
||||
return '';
|
||||
}
|
||||
$block_size = \PHP_INT_SIZE << 3;
|
||||
$pad = $block_size - $length % $block_size;
|
||||
if ($pad != $block_size) {
|
||||
$x = \str_repeat('0', $pad) . $x;
|
||||
}
|
||||
$parts = \str_split($x, $block_size);
|
||||
$str = '';
|
||||
foreach ($parts as $part) {
|
||||
$xor = $part[0] == '1' ? \PHP_INT_MIN : 0;
|
||||
$part[0] = '0';
|
||||
$str .= \pack(\PHP_INT_SIZE == 4 ? 'N' : 'J', $xor ^ eval('return 0b' . $part . ';'));
|
||||
}
|
||||
return \ltrim($str, "\0");
|
||||
}
|
||||
/**
|
||||
* Convert bits to binary data
|
||||
*
|
||||
* @param string $x
|
||||
* @return string
|
||||
*/
|
||||
public static function bin2bits($x, $trim = \true)
|
||||
{
|
||||
/*
|
||||
// the pure-PHP approach is slower than the GMP approach BUT
|
||||
// i want to the pure-PHP version to be easily unit tested as well
|
||||
if (function_exists('gmp_import')) {
|
||||
return gmp_strval(gmp_import($x), 2);
|
||||
}
|
||||
*/
|
||||
$len = \strlen($x);
|
||||
$mod = $len % \PHP_INT_SIZE;
|
||||
if ($mod) {
|
||||
$x = \str_pad($x, $len + \PHP_INT_SIZE - $mod, "\0", \STR_PAD_LEFT);
|
||||
}
|
||||
$bits = '';
|
||||
if (\PHP_INT_SIZE == 4) {
|
||||
$digits = \unpack('N*', $x);
|
||||
foreach ($digits as $digit) {
|
||||
$bits .= \sprintf('%032b', $digit);
|
||||
}
|
||||
} else {
|
||||
$digits = \unpack('J*', $x);
|
||||
foreach ($digits as $digit) {
|
||||
$bits .= \sprintf('%064b', $digit);
|
||||
}
|
||||
}
|
||||
return $trim ? \ltrim($bits, '0') : $bits;
|
||||
}
|
||||
/**
|
||||
* Switch Endianness Bit Order
|
||||
*
|
||||
* @param string $x
|
||||
* @return string
|
||||
*/
|
||||
public static function switchEndianness($x)
|
||||
{
|
||||
$r = '';
|
||||
for ($i = \strlen($x) - 1; $i >= 0; $i--) {
|
||||
$b = \ord($x[$i]);
|
||||
if (\PHP_INT_SIZE === 8) {
|
||||
// 3 operations
|
||||
// from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv
|
||||
$r .= \chr(($b * 0x202020202 & 0x10884422010) % 1023);
|
||||
} else {
|
||||
// 7 operations
|
||||
// from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits
|
||||
$p1 = $b * 0x802 & 0x22110;
|
||||
$p2 = $b * 0x8020 & 0x88440;
|
||||
$r .= \chr(($p1 | $p2) * 0x10101 >> 16);
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Increment the current string
|
||||
*
|
||||
* @param string $var
|
||||
* @return string
|
||||
*/
|
||||
public static function increment_str(&$var)
|
||||
{
|
||||
if (\function_exists('sodium_increment')) {
|
||||
$var = \strrev($var);
|
||||
\sodium_increment($var);
|
||||
$var = \strrev($var);
|
||||
return $var;
|
||||
}
|
||||
for ($i = 4; $i <= \strlen($var); $i += 4) {
|
||||
$temp = \substr($var, -$i, 4);
|
||||
switch ($temp) {
|
||||
case "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>":
|
||||
$var = \substr_replace($var, "\0\0\0\0", -$i, 4);
|
||||
break;
|
||||
case "<EFBFBD><EFBFBD><EFBFBD>":
|
||||
$var = \substr_replace($var, "<EFBFBD>\0\0\0", -$i, 4);
|
||||
return $var;
|
||||
default:
|
||||
$temp = \unpack('Nnum', $temp);
|
||||
$var = \substr_replace($var, \pack('N', $temp['num'] + 1), -$i, 4);
|
||||
return $var;
|
||||
}
|
||||
}
|
||||
$remainder = \strlen($var) % 4;
|
||||
if ($remainder == 0) {
|
||||
return $var;
|
||||
}
|
||||
$temp = \unpack('Nnum', \str_pad(\substr($var, 0, $remainder), 4, "\0", \STR_PAD_LEFT));
|
||||
$temp = \substr(\pack('N', $temp['num'] + 1), -$remainder);
|
||||
$var = \substr_replace($var, $temp, 0, $remainder);
|
||||
return $var;
|
||||
}
|
||||
/**
|
||||
* Find whether the type of a variable is string (or could be converted to one)
|
||||
*
|
||||
* @param mixed $var
|
||||
* @return bool
|
||||
* @psalm-assert-if-true string|\Stringable $var
|
||||
*/
|
||||
public static function is_stringable($var)
|
||||
{
|
||||
return \is_string($var) || \is_object($var) && \method_exists($var, '__toString');
|
||||
}
|
||||
/**
|
||||
* Constant Time Base64-decoding
|
||||
*
|
||||
* ParagoneIE\ConstantTime doesn't use libsodium if it's available so we'll do so
|
||||
* ourselves. see https://github.com/paragonie/constant_time_encoding/issues/39
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function base64_decode($data)
|
||||
{
|
||||
return \function_exists('sodium_base642bin') ? \sodium_base642bin($data, \SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING, '=') : \WPMailSMTP\Vendor\ParagonIE\ConstantTime\Base64::decode($data);
|
||||
}
|
||||
/**
|
||||
* Constant Time Base64-decoding (URL safe)
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function base64url_decode($data)
|
||||
{
|
||||
// return self::base64_decode(str_replace(['-', '_'], ['+', '/'], $data));
|
||||
return \function_exists('sodium_base642bin') ? \sodium_base642bin($data, \SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING, '=') : \WPMailSMTP\Vendor\ParagonIE\ConstantTime\Base64UrlSafe::decode($data);
|
||||
}
|
||||
/**
|
||||
* Constant Time Base64-encoding
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function base64_encode($data)
|
||||
{
|
||||
return \function_exists('sodium_bin2base64') ? \sodium_bin2base64($data, \SODIUM_BASE64_VARIANT_ORIGINAL) : \WPMailSMTP\Vendor\ParagonIE\ConstantTime\Base64::encode($data);
|
||||
}
|
||||
/**
|
||||
* Constant Time Base64-encoding (URL safe)
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function base64url_encode($data)
|
||||
{
|
||||
// return str_replace(['+', '/'], ['-', '_'], self::base64_encode($data));
|
||||
return \function_exists('sodium_bin2base64') ? \sodium_bin2base64($data, \SODIUM_BASE64_VARIANT_URLSAFE) : \WPMailSMTP\Vendor\ParagonIE\ConstantTime\Base64UrlSafe::encode($data);
|
||||
}
|
||||
/**
|
||||
* Constant Time Hex Decoder
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function hex2bin($data)
|
||||
{
|
||||
return \function_exists('sodium_hex2bin') ? \sodium_hex2bin($data) : \WPMailSMTP\Vendor\ParagonIE\ConstantTime\Hex::decode($data);
|
||||
}
|
||||
/**
|
||||
* Constant Time Hex Encoder
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function bin2hex($data)
|
||||
{
|
||||
return \function_exists('sodium_bin2hex') ? \sodium_bin2hex($data) : \WPMailSMTP\Vendor\ParagonIE\ConstantTime\Hex::encode($data);
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of AES.
|
||||
*
|
||||
* Uses mcrypt, if available/possible, and an internal implementation, otherwise.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* NOTE: Since AES.php is (for compatibility and phpseclib-historical reasons) virtually
|
||||
* just a wrapper to Rijndael.php you may consider using Rijndael.php instead of
|
||||
* to save one include_once().
|
||||
*
|
||||
* If {@link self::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
|
||||
* {@link self::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
|
||||
* it'll be null-padded to 192-bits and 192 bits will be the key length until {@link self::setKey() setKey()}
|
||||
* is called, again, at which point, it'll be recalculated.
|
||||
*
|
||||
* Since \phpseclib3\Crypt\AES extends \phpseclib3\Crypt\Rijndael, some functions are available to be called that, in the context of AES, don't
|
||||
* make a whole lot of sense. {@link self::setBlockLength() setBlockLength()}, for instance. Calling that function,
|
||||
* however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one).
|
||||
*
|
||||
* Here's a short example of how to use this library:
|
||||
* <code>
|
||||
* <?php
|
||||
* include 'vendor/autoload.php';
|
||||
*
|
||||
* $aes = new \phpseclib3\Crypt\AES('ctr');
|
||||
*
|
||||
* $aes->setKey('abcdefghijklmnop');
|
||||
*
|
||||
* $size = 10 * 1024;
|
||||
* $plaintext = '';
|
||||
* for ($i = 0; $i < $size; $i++) {
|
||||
* $plaintext.= 'a';
|
||||
* }
|
||||
*
|
||||
* echo $aes->decrypt($aes->encrypt($plaintext));
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2008 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
namespace WPMailSMTP\Vendor\phpseclib3\Crypt;
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of AES.
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class AES extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Rijndael
|
||||
{
|
||||
/**
|
||||
* Dummy function
|
||||
*
|
||||
* Since \phpseclib3\Crypt\AES extends \phpseclib3\Crypt\Rijndael, this function is, technically, available, but it doesn't do anything.
|
||||
*
|
||||
* @see \phpseclib3\Crypt\Rijndael::setBlockLength()
|
||||
* @param int $length
|
||||
* @throws \BadMethodCallException anytime it's called
|
||||
*/
|
||||
public function setBlockLength($length)
|
||||
{
|
||||
throw new \BadMethodCallException('The block length cannot be set for AES.');
|
||||
}
|
||||
/**
|
||||
* Sets the key length
|
||||
*
|
||||
* Valid key lengths are 128, 192, and 256. Set the link to bool(false) to disable a fixed key length
|
||||
*
|
||||
* @see \phpseclib3\Crypt\Rijndael:setKeyLength()
|
||||
* @param int $length
|
||||
* @throws \LengthException if the key length isn't supported
|
||||
*/
|
||||
public function setKeyLength($length)
|
||||
{
|
||||
switch ($length) {
|
||||
case 128:
|
||||
case 192:
|
||||
case 256:
|
||||
break;
|
||||
default:
|
||||
throw new \LengthException('Key of size ' . $length . ' not supported by this algorithm. Only keys of sizes 128, 192 or 256 supported');
|
||||
}
|
||||
parent::setKeyLength($length);
|
||||
}
|
||||
/**
|
||||
* Sets the key.
|
||||
*
|
||||
* Rijndael supports five different key lengths, AES only supports three.
|
||||
*
|
||||
* @see \phpseclib3\Crypt\Rijndael:setKey()
|
||||
* @see setKeyLength()
|
||||
* @param string $key
|
||||
* @throws \LengthException if the key length isn't supported
|
||||
*/
|
||||
public function setKey($key)
|
||||
{
|
||||
switch (\strlen($key)) {
|
||||
case 16:
|
||||
case 24:
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
throw new \LengthException('Key of size ' . \strlen($key) . ' not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported');
|
||||
}
|
||||
parent::setKey($key);
|
||||
}
|
||||
}
|
||||
@@ -1,511 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base Class for all asymmetric key ciphers
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DSA;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Hash;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\RSA;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedFormatException;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* Base Class for all asymmetric cipher classes
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class AsymmetricKey
|
||||
{
|
||||
/**
|
||||
* Precomputed Zero
|
||||
*
|
||||
* @var \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
protected static $zero;
|
||||
/**
|
||||
* Precomputed One
|
||||
*
|
||||
* @var \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
protected static $one;
|
||||
/**
|
||||
* Format of the loaded key
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $format;
|
||||
/**
|
||||
* Hash function
|
||||
*
|
||||
* @var \phpseclib3\Crypt\Hash
|
||||
*/
|
||||
protected $hash;
|
||||
/**
|
||||
* HMAC function
|
||||
*
|
||||
* @var \phpseclib3\Crypt\Hash
|
||||
*/
|
||||
private $hmac;
|
||||
/**
|
||||
* Supported plugins (lower case)
|
||||
*
|
||||
* @see self::initialize_static_variables()
|
||||
* @var array
|
||||
*/
|
||||
private static $plugins = [];
|
||||
/**
|
||||
* Invisible plugins
|
||||
*
|
||||
* @see self::initialize_static_variables()
|
||||
* @var array
|
||||
*/
|
||||
private static $invisiblePlugins = [];
|
||||
/**
|
||||
* Available Engines
|
||||
*
|
||||
* @var boolean[]
|
||||
*/
|
||||
protected static $engines = [];
|
||||
/**
|
||||
* Key Comment
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
private $comment;
|
||||
/**
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public abstract function toString($type, array $options = []);
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
$this->hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha256');
|
||||
$this->hmac = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha256');
|
||||
}
|
||||
/**
|
||||
* Initialize static variables
|
||||
*/
|
||||
protected static function initialize_static_variables()
|
||||
{
|
||||
if (!isset(self::$zero)) {
|
||||
self::$zero = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(0);
|
||||
self::$one = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1);
|
||||
}
|
||||
self::loadPlugins('Keys');
|
||||
if (static::ALGORITHM != 'RSA' && static::ALGORITHM != 'DH') {
|
||||
self::loadPlugins('Signature');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Load the key
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return AsymmetricKey
|
||||
*/
|
||||
public static function load($key, $password = \false)
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
$class = new \ReflectionClass(static::class);
|
||||
if ($class->isFinal()) {
|
||||
throw new \RuntimeException('load() should not be called from final classes (' . static::class . ')');
|
||||
}
|
||||
$components = \false;
|
||||
foreach (self::$plugins[static::ALGORITHM]['Keys'] as $format) {
|
||||
if (isset(self::$invisiblePlugins[static::ALGORITHM]) && \in_array($format, self::$invisiblePlugins[static::ALGORITHM])) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$components = $format::load($key, $password);
|
||||
} catch (\Exception $e) {
|
||||
$components = \false;
|
||||
}
|
||||
if ($components !== \false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($components === \false) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException('Unable to read key');
|
||||
}
|
||||
$components['format'] = $format;
|
||||
$components['secret'] = isset($components['secret']) ? $components['secret'] : '';
|
||||
$comment = isset($components['comment']) ? $components['comment'] : null;
|
||||
$new = static::onLoad($components);
|
||||
$new->format = $format;
|
||||
$new->comment = $comment;
|
||||
return $new instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PrivateKey ? $new->withPassword($password) : $new;
|
||||
}
|
||||
/**
|
||||
* Loads a private key
|
||||
*
|
||||
* @return PrivateKey
|
||||
* @param string|array $key
|
||||
* @param string $password optional
|
||||
*/
|
||||
public static function loadPrivateKey($key, $password = '')
|
||||
{
|
||||
$key = self::load($key, $password);
|
||||
if (!$key instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PrivateKey) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException('The key that was loaded was not a private key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
/**
|
||||
* Loads a public key
|
||||
*
|
||||
* @return PublicKey
|
||||
* @param string|array $key
|
||||
*/
|
||||
public static function loadPublicKey($key)
|
||||
{
|
||||
$key = self::load($key);
|
||||
if (!$key instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PublicKey) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException('The key that was loaded was not a public key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
/**
|
||||
* Loads parameters
|
||||
*
|
||||
* @return AsymmetricKey
|
||||
* @param string|array $key
|
||||
*/
|
||||
public static function loadParameters($key)
|
||||
{
|
||||
$key = self::load($key);
|
||||
if (!$key instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PrivateKey && !$key instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PublicKey) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException('The key that was loaded was not a parameter');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
/**
|
||||
* Load the key, assuming a specific format
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return static
|
||||
*/
|
||||
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 \WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException('Unable to read key');
|
||||
}
|
||||
$components['format'] = $format;
|
||||
$components['secret'] = isset($components['secret']) ? $components['secret'] : '';
|
||||
$new = static::onLoad($components);
|
||||
$new->format = $format;
|
||||
return $new instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PrivateKey ? $new->withPassword($password) : $new;
|
||||
}
|
||||
/**
|
||||
* Loads a private key
|
||||
*
|
||||
* @return PrivateKey
|
||||
* @param string $type
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
*/
|
||||
public static function loadPrivateKeyFormat($type, $key, $password = \false)
|
||||
{
|
||||
$key = self::loadFormat($type, $key, $password);
|
||||
if (!$key instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PrivateKey) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException('The key that was loaded was not a private key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
/**
|
||||
* Loads a public key
|
||||
*
|
||||
* @return PublicKey
|
||||
* @param string $type
|
||||
* @param string $key
|
||||
*/
|
||||
public static function loadPublicKeyFormat($type, $key)
|
||||
{
|
||||
$key = self::loadFormat($type, $key);
|
||||
if (!$key instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PublicKey) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException('The key that was loaded was not a public key');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
/**
|
||||
* Loads parameters
|
||||
*
|
||||
* @return AsymmetricKey
|
||||
* @param string $type
|
||||
* @param string|array $key
|
||||
*/
|
||||
public static function loadParametersFormat($type, $key)
|
||||
{
|
||||
$key = self::loadFormat($type, $key);
|
||||
if (!$key instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PrivateKey && !$key instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PublicKey) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException('The key that was loaded was not a parameter');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
/**
|
||||
* Validate Plugin
|
||||
*
|
||||
* @param string $format
|
||||
* @param string $type
|
||||
* @param string $method optional
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function validatePlugin($format, $type, $method = null)
|
||||
{
|
||||
$type = \strtolower($type);
|
||||
if (!isset(self::$plugins[static::ALGORITHM][$format][$type])) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedFormatException("{$type} is not a supported format");
|
||||
}
|
||||
$type = self::$plugins[static::ALGORITHM][$format][$type];
|
||||
if (isset($method) && !\method_exists($type, $method)) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedFormatException("{$type} does not implement {$method}");
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
/**
|
||||
* Load Plugins
|
||||
*
|
||||
* @param string $format
|
||||
*/
|
||||
private static function loadPlugins($format)
|
||||
{
|
||||
if (!isset(self::$plugins[static::ALGORITHM][$format])) {
|
||||
self::$plugins[static::ALGORITHM][$format] = [];
|
||||
foreach (new \DirectoryIterator(__DIR__ . '/../' . static::ALGORITHM . '/Formats/' . $format . '/') as $file) {
|
||||
if ($file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
$name = $file->getBasename('.php');
|
||||
if ($name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
$type = 'WPMailSMTP\\Vendor\\phpseclib3\\Crypt\\' . static::ALGORITHM . '\\Formats\\' . $format . '\\' . $name;
|
||||
$reflect = new \ReflectionClass($type);
|
||||
if ($reflect->isTrait()) {
|
||||
continue;
|
||||
}
|
||||
self::$plugins[static::ALGORITHM][$format][\strtolower($name)] = $type;
|
||||
if ($reflect->hasConstant('IS_INVISIBLE')) {
|
||||
self::$invisiblePlugins[static::ALGORITHM][] = $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a list of supported formats.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSupportedKeyFormats()
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
return self::$plugins[static::ALGORITHM]['Keys'];
|
||||
}
|
||||
/**
|
||||
* Add a fileformat plugin
|
||||
*
|
||||
* The plugin needs to either already be loaded or be auto-loadable.
|
||||
* Loading a plugin whose shortname overwrite an existing shortname will overwrite the old plugin.
|
||||
*
|
||||
* @see self::load()
|
||||
* @param string $fullname
|
||||
* @return bool
|
||||
*/
|
||||
public static function addFileFormat($fullname)
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
if (\class_exists($fullname)) {
|
||||
$meta = new \ReflectionClass($fullname);
|
||||
$shortname = $meta->getShortName();
|
||||
self::$plugins[static::ALGORITHM]['Keys'][\strtolower($shortname)] = $fullname;
|
||||
if ($meta->hasConstant('IS_INVISIBLE')) {
|
||||
self::$invisiblePlugins[static::ALGORITHM] = \strtolower($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the format of the loaded key.
|
||||
*
|
||||
* If the key that was loaded wasn't in a valid or if the key was auto-generated
|
||||
* with RSA::createKey() then this will throw an exception.
|
||||
*
|
||||
* @see self::load()
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLoadedFormat()
|
||||
{
|
||||
if (empty($this->format)) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\NoKeyLoadedException('This key was created with createKey - it was not loaded with load. Therefore there is no "loaded format"');
|
||||
}
|
||||
$meta = new \ReflectionClass($this->format);
|
||||
return $meta->getShortName();
|
||||
}
|
||||
/**
|
||||
* Returns the key's comment
|
||||
*
|
||||
* Not all key formats support comments. If you want to set a comment use toString()
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
/**
|
||||
* Tests engine validity
|
||||
*
|
||||
*/
|
||||
public static function useBestEngine()
|
||||
{
|
||||
static::$engines = [
|
||||
'PHP' => \true,
|
||||
'OpenSSL' => \extension_loaded('openssl'),
|
||||
// this test can be satisfied by either of the following:
|
||||
// http://php.net/manual/en/book.sodium.php
|
||||
// https://github.com/paragonie/sodium_compat
|
||||
'libsodium' => \function_exists('sodium_crypto_sign_keypair'),
|
||||
];
|
||||
return static::$engines;
|
||||
}
|
||||
/**
|
||||
* Flag to use internal engine only (useful for unit testing)
|
||||
*
|
||||
*/
|
||||
public static function useInternalEngine()
|
||||
{
|
||||
static::$engines = ['PHP' => \true, 'OpenSSL' => \false, 'libsodium' => \false];
|
||||
}
|
||||
/**
|
||||
* __toString() magic method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toString('PKCS8');
|
||||
}
|
||||
/**
|
||||
* Determines which hashing function should be used
|
||||
*
|
||||
* @param string $hash
|
||||
*/
|
||||
public function withHash($hash)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash($hash);
|
||||
$new->hmac = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash($hash);
|
||||
return $new;
|
||||
}
|
||||
/**
|
||||
* Returns the hash algorithm currently being used
|
||||
*
|
||||
*/
|
||||
public function getHash()
|
||||
{
|
||||
return clone $this->hash;
|
||||
}
|
||||
/**
|
||||
* Compute the pseudorandom k for signature generation,
|
||||
* using the process specified for deterministic DSA.
|
||||
*
|
||||
* @param string $h1
|
||||
* @return string
|
||||
*/
|
||||
protected function computek($h1)
|
||||
{
|
||||
$v = \str_repeat("\1", \strlen($h1));
|
||||
$k = \str_repeat("\0", \strlen($h1));
|
||||
$x = $this->int2octets($this->x);
|
||||
$h1 = $this->bits2octets($h1);
|
||||
$this->hmac->setKey($k);
|
||||
$k = $this->hmac->hash($v . "\0" . $x . $h1);
|
||||
$this->hmac->setKey($k);
|
||||
$v = $this->hmac->hash($v);
|
||||
$k = $this->hmac->hash($v . "\1" . $x . $h1);
|
||||
$this->hmac->setKey($k);
|
||||
$v = $this->hmac->hash($v);
|
||||
$qlen = $this->q->getLengthInBytes();
|
||||
while (\true) {
|
||||
$t = '';
|
||||
while (\strlen($t) < $qlen) {
|
||||
$v = $this->hmac->hash($v);
|
||||
$t = $t . $v;
|
||||
}
|
||||
$k = $this->bits2int($t);
|
||||
if (!$k->equals(self::$zero) && $k->compare($this->q) < 0) {
|
||||
break;
|
||||
}
|
||||
$k = $this->hmac->hash($v . "\0");
|
||||
$this->hmac->setKey($k);
|
||||
$v = $this->hmac->hash($v);
|
||||
}
|
||||
return $k;
|
||||
}
|
||||
/**
|
||||
* Integer to Octet String
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $v
|
||||
* @return string
|
||||
*/
|
||||
private function int2octets($v)
|
||||
{
|
||||
$out = $v->toBytes();
|
||||
$rolen = $this->q->getLengthInBytes();
|
||||
if (\strlen($out) < $rolen) {
|
||||
return \str_pad($out, $rolen, "\0", \STR_PAD_LEFT);
|
||||
} elseif (\strlen($out) > $rolen) {
|
||||
return \substr($out, -$rolen);
|
||||
} else {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Bit String to Integer
|
||||
*
|
||||
* @param string $in
|
||||
* @return \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
protected function bits2int($in)
|
||||
{
|
||||
$v = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger($in, 256);
|
||||
$vlen = \strlen($in) << 3;
|
||||
$qlen = $this->q->getLength();
|
||||
if ($vlen > $qlen) {
|
||||
return $v->bitwise_rightShift($vlen - $qlen);
|
||||
}
|
||||
return $v;
|
||||
}
|
||||
/**
|
||||
* Bit String to Octet String
|
||||
*
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
private function bits2octets($in)
|
||||
{
|
||||
$z1 = $this->bits2int($in);
|
||||
$z2 = $z1->subtract($this->q);
|
||||
return $z2->compare(self::$zero) < 0 ? $this->int2octets($z1) : $this->int2octets($z2);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base Class for all block ciphers
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @copyright 2007 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
namespace WPMailSMTP\Vendor\phpseclib3\Crypt\Common;
|
||||
|
||||
/**
|
||||
* Base Class for all block cipher classes
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class BlockCipher extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\SymmetricKey
|
||||
{
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* JSON Web Key (RFC7517) Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
/**
|
||||
* JSON Web Key Formatted Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class JWK
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::is_stringable($key)) {
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . \gettype($key));
|
||||
}
|
||||
$key = \preg_replace('#\\s#', '', $key);
|
||||
// remove whitespace
|
||||
if (\PHP_VERSION_ID >= 73000) {
|
||||
$key = \json_decode($key, null, 512, \JSON_THROW_ON_ERROR);
|
||||
} else {
|
||||
$key = \json_decode($key);
|
||||
if (!$key) {
|
||||
throw new \RuntimeException('Unable to decode JSON');
|
||||
}
|
||||
}
|
||||
if (isset($key->kty)) {
|
||||
return $key;
|
||||
}
|
||||
if (\count($key->keys) != 1) {
|
||||
throw new \RuntimeException('Although the JWK key format supports multiple keys phpseclib does not');
|
||||
}
|
||||
return $key->keys[0];
|
||||
}
|
||||
/**
|
||||
* Wrap a key appropriately
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function wrapKey(array $key, array $options)
|
||||
{
|
||||
return \json_encode(['keys' => [$key + $options]]);
|
||||
}
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenSSH Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Place in $HOME/.ssh/authorized_keys
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\AES;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Random;
|
||||
/**
|
||||
* OpenSSH Formatted RSA Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class OpenSSH
|
||||
{
|
||||
/**
|
||||
* Default comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $comment = 'phpseclib-generated-key';
|
||||
/**
|
||||
* Binary key flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $binary = \false;
|
||||
/**
|
||||
* Sets the default comment
|
||||
*
|
||||
* @param string $comment
|
||||
*/
|
||||
public static function setComment($comment)
|
||||
{
|
||||
self::$comment = \str_replace(["\r", "\n"], '', $comment);
|
||||
}
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* $type can be either ssh-dss or ssh-rsa
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::is_stringable($key)) {
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . \gettype($key));
|
||||
}
|
||||
// key format is described here:
|
||||
// https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.key?annotate=HEAD
|
||||
if (\strpos($key, 'BEGIN OPENSSH PRIVATE KEY') !== \false) {
|
||||
$key = \preg_replace('#(?:^-.*?-[\\r\\n]*$)|\\s#ms', '', $key);
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_decode($key);
|
||||
$magic = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::shift($key, 15);
|
||||
if ($magic != "openssh-key-v1\0") {
|
||||
throw new \RuntimeException('Expected openssh-key-v1');
|
||||
}
|
||||
list($ciphername, $kdfname, $kdfoptions, $numKeys) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('sssN', $key);
|
||||
if ($numKeys != 1) {
|
||||
// if we wanted to support multiple keys we could update PublicKeyLoader to preview what the # of keys
|
||||
// would be; it'd then call Common\Keys\OpenSSH.php::load() and get the paddedKey. it'd then pass
|
||||
// that to the appropriate key loading parser $numKey times or something
|
||||
throw new \RuntimeException('Although the OpenSSH private key format supports multiple keys phpseclib does not');
|
||||
}
|
||||
switch ($ciphername) {
|
||||
case 'none':
|
||||
break;
|
||||
case 'aes256-ctr':
|
||||
if ($kdfname != 'bcrypt') {
|
||||
throw new \RuntimeException('Only the bcrypt kdf is supported (' . $kdfname . ' encountered)');
|
||||
}
|
||||
list($salt, $rounds) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('sN', $kdfoptions);
|
||||
$crypto = new \WPMailSMTP\Vendor\phpseclib3\Crypt\AES('ctr');
|
||||
//$crypto->setKeyLength(256);
|
||||
//$crypto->disablePadding();
|
||||
$crypto->setPassword($password, 'bcrypt', $salt, $rounds, 32);
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException('The only supported cipherse are: none, aes256-ctr (' . $ciphername . ' is being used)');
|
||||
}
|
||||
list($publicKey, $paddedKey) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('ss', $key);
|
||||
list($type) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('s', $publicKey);
|
||||
if (isset($crypto)) {
|
||||
$paddedKey = $crypto->decrypt($paddedKey);
|
||||
}
|
||||
list($checkint1, $checkint2) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('NN', $paddedKey);
|
||||
// any leftover bytes in $paddedKey are for padding? but they should be sequential bytes. eg. 1, 2, 3, etc.
|
||||
if ($checkint1 != $checkint2) {
|
||||
throw new \RuntimeException('The two checkints do not match');
|
||||
}
|
||||
self::checkType($type);
|
||||
return \compact('type', 'publicKey', 'paddedKey');
|
||||
}
|
||||
$parts = \explode(' ', $key, 3);
|
||||
if (!isset($parts[1])) {
|
||||
$key = \base64_decode($parts[0]);
|
||||
$comment = \false;
|
||||
} else {
|
||||
$asciiType = $parts[0];
|
||||
self::checkType($parts[0]);
|
||||
$key = \base64_decode($parts[1]);
|
||||
$comment = isset($parts[2]) ? $parts[2] : \false;
|
||||
}
|
||||
if ($key === \false) {
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . \gettype($key));
|
||||
}
|
||||
list($type) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('s', $key);
|
||||
self::checkType($type);
|
||||
if (isset($asciiType) && $asciiType != $type) {
|
||||
throw new \RuntimeException('Two different types of keys are claimed: ' . $asciiType . ' and ' . $type);
|
||||
}
|
||||
if (\strlen($key) <= 4) {
|
||||
throw new \UnexpectedValueException('Key appears to be malformed');
|
||||
}
|
||||
$publicKey = $key;
|
||||
return \compact('type', 'publicKey', 'comment');
|
||||
}
|
||||
/**
|
||||
* Toggle between binary and printable keys
|
||||
*
|
||||
* Printable keys are what are generated by default. These are the ones that go in
|
||||
* $HOME/.ssh/authorized_key.
|
||||
*
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public static function setBinaryOutput($enabled)
|
||||
{
|
||||
self::$binary = $enabled;
|
||||
}
|
||||
/**
|
||||
* Checks to see if the type is valid
|
||||
*
|
||||
* @param string $candidate
|
||||
*/
|
||||
private static function checkType($candidate)
|
||||
{
|
||||
if (!\in_array($candidate, static::$types)) {
|
||||
throw new \RuntimeException("The key type ({$candidate}) is not equal to: " . \implode(',', static::$types));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Wrap a private key appropriately
|
||||
*
|
||||
* @param string $publicKey
|
||||
* @param string $privateKey
|
||||
* @param string $password
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected static function wrapPrivateKey($publicKey, $privateKey, $password, $options)
|
||||
{
|
||||
list(, $checkint) = \unpack('N', \WPMailSMTP\Vendor\phpseclib3\Crypt\Random::string(4));
|
||||
$comment = isset($options['comment']) ? $options['comment'] : self::$comment;
|
||||
$paddedKey = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('NN', $checkint, $checkint) . $privateKey . \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('s', $comment);
|
||||
$usesEncryption = !empty($password) && \is_string($password);
|
||||
/*
|
||||
from http://tools.ietf.org/html/rfc4253#section-6 :
|
||||
|
||||
Note that the length of the concatenation of 'packet_length',
|
||||
'padding_length', 'payload', and 'random padding' MUST be a multiple
|
||||
of the cipher block size or 8, whichever is larger.
|
||||
*/
|
||||
$blockSize = $usesEncryption ? 16 : 8;
|
||||
$paddingLength = ($blockSize - 1) * \strlen($paddedKey) % $blockSize;
|
||||
for ($i = 1; $i <= $paddingLength; $i++) {
|
||||
$paddedKey .= \chr($i);
|
||||
}
|
||||
if (!$usesEncryption) {
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('sssNss', 'none', 'none', '', 1, $publicKey, $paddedKey);
|
||||
} else {
|
||||
$rounds = isset($options['rounds']) ? $options['rounds'] : 16;
|
||||
$salt = \WPMailSMTP\Vendor\phpseclib3\Crypt\Random::string(16);
|
||||
$kdfoptions = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('sN', $salt, $rounds);
|
||||
$crypto = new \WPMailSMTP\Vendor\phpseclib3\Crypt\AES('ctr');
|
||||
$crypto->setPassword($password, 'bcrypt', $salt, $rounds, 32);
|
||||
$paddedKey = $crypto->encrypt($paddedKey);
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('sssNss', 'aes256-ctr', 'bcrypt', $kdfoptions, 1, $publicKey, $paddedKey);
|
||||
}
|
||||
$key = "openssh-key-v1\0{$key}";
|
||||
return "-----BEGIN OPENSSH PRIVATE KEY-----\n" . \chunk_split(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($key), 70, "\n") . "-----END OPENSSH PRIVATE KEY-----\n";
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PKCS Formatted Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
/**
|
||||
* PKCS1 Formatted Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class PKCS
|
||||
{
|
||||
/**
|
||||
* Auto-detect the format
|
||||
*/
|
||||
const MODE_ANY = 0;
|
||||
/**
|
||||
* Require base64-encoded PEM's be supplied
|
||||
*/
|
||||
const MODE_PEM = 1;
|
||||
/**
|
||||
* Require raw DER's be supplied
|
||||
*/
|
||||
const MODE_DER = 2;
|
||||
/**#@-*/
|
||||
/**
|
||||
* Is the key a base-64 encoded PEM, DER or should it be auto-detected?
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected static $format = self::MODE_ANY;
|
||||
/**
|
||||
* Require base64-encoded PEM's be supplied
|
||||
*
|
||||
*/
|
||||
public static function requirePEM()
|
||||
{
|
||||
self::$format = self::MODE_PEM;
|
||||
}
|
||||
/**
|
||||
* Require raw DER's be supplied
|
||||
*
|
||||
*/
|
||||
public static function requireDER()
|
||||
{
|
||||
self::$format = self::MODE_DER;
|
||||
}
|
||||
/**
|
||||
* Accept any format and auto detect the format
|
||||
*
|
||||
* This is the default setting
|
||||
*
|
||||
*/
|
||||
public static function requireAny()
|
||||
{
|
||||
self::$format = self::MODE_ANY;
|
||||
}
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PKCS1 Formatted Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\AES;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DES;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Random;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\TripleDES;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1;
|
||||
/**
|
||||
* PKCS1 Formatted Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class PKCS1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS
|
||||
{
|
||||
/**
|
||||
* Default encryption algorithm
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $defaultEncryptionAlgorithm = 'AES-128-CBC';
|
||||
/**
|
||||
* Sets the default encryption algorithm
|
||||
*
|
||||
* @param string $algo
|
||||
*/
|
||||
public static function setEncryptionAlgorithm($algo)
|
||||
{
|
||||
self::$defaultEncryptionAlgorithm = $algo;
|
||||
}
|
||||
/**
|
||||
* Returns the mode constant corresponding to the mode string
|
||||
*
|
||||
* @param string $mode
|
||||
* @return int
|
||||
* @throws \UnexpectedValueException if the block cipher mode is unsupported
|
||||
*/
|
||||
private static function getEncryptionMode($mode)
|
||||
{
|
||||
switch ($mode) {
|
||||
case 'CBC':
|
||||
case 'ECB':
|
||||
case 'CFB':
|
||||
case 'OFB':
|
||||
case 'CTR':
|
||||
return $mode;
|
||||
}
|
||||
throw new \UnexpectedValueException('Unsupported block cipher mode of operation');
|
||||
}
|
||||
/**
|
||||
* Returns a cipher object corresponding to a string
|
||||
*
|
||||
* @param string $algo
|
||||
* @return string
|
||||
* @throws \UnexpectedValueException if the encryption algorithm is unsupported
|
||||
*/
|
||||
private static function getEncryptionObject($algo)
|
||||
{
|
||||
$modes = '(CBC|ECB|CFB|OFB|CTR)';
|
||||
switch (\true) {
|
||||
case \preg_match("#^AES-(128|192|256)-{$modes}\$#", $algo, $matches):
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\AES(self::getEncryptionMode($matches[2]));
|
||||
$cipher->setKeyLength($matches[1]);
|
||||
return $cipher;
|
||||
case \preg_match("#^DES-EDE3-{$modes}\$#", $algo, $matches):
|
||||
return new \WPMailSMTP\Vendor\phpseclib3\Crypt\TripleDES(self::getEncryptionMode($matches[1]));
|
||||
case \preg_match("#^DES-{$modes}\$#", $algo, $matches):
|
||||
return new \WPMailSMTP\Vendor\phpseclib3\Crypt\DES(self::getEncryptionMode($matches[1]));
|
||||
default:
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException($algo . ' is not a supported algorithm');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Generate a symmetric key for PKCS#1 keys
|
||||
*
|
||||
* @param string $password
|
||||
* @param string $iv
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
private static function generateSymmetricKey($password, $iv, $length)
|
||||
{
|
||||
$symkey = '';
|
||||
$iv = \substr($iv, 0, 8);
|
||||
while (\strlen($symkey) < $length) {
|
||||
$symkey .= \md5($symkey . $password . $iv, \true);
|
||||
}
|
||||
return \substr($symkey, 0, $length);
|
||||
}
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
protected static function load($key, $password)
|
||||
{
|
||||
if (!\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::is_stringable($key)) {
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . \gettype($key));
|
||||
}
|
||||
/* Although PKCS#1 proposes a format that public and private keys can use, encrypting them is
|
||||
"outside the scope" of PKCS#1. PKCS#1 then refers you to PKCS#12 and PKCS#15 if you're wanting to
|
||||
protect private keys, however, that's not what OpenSSL* does. OpenSSL protects private keys by adding
|
||||
two new "fields" to the key - DEK-Info and Proc-Type. These fields are discussed here:
|
||||
|
||||
http://tools.ietf.org/html/rfc1421#section-4.6.1.1
|
||||
http://tools.ietf.org/html/rfc1421#section-4.6.1.3
|
||||
|
||||
DES-EDE3-CBC as an algorithm, however, is not discussed anywhere, near as I can tell.
|
||||
DES-CBC and DES-EDE are discussed in RFC1423, however, DES-EDE3-CBC isn't, nor is its key derivation
|
||||
function. As is, the definitive authority on this encoding scheme isn't the IETF but rather OpenSSL's
|
||||
own implementation. ie. the implementation *is* the standard and any bugs that may exist in that
|
||||
implementation are part of the standard, as well.
|
||||
|
||||
* OpenSSL is the de facto standard. It's utilized by OpenSSH and other projects */
|
||||
if (\preg_match('#DEK-Info: (.+),(.+)#', $key, $matches)) {
|
||||
$iv = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::hex2bin(\trim($matches[2]));
|
||||
// remove the Proc-Type / DEK-Info sections as they're no longer needed
|
||||
$key = \preg_replace('#^(?:Proc-Type|DEK-Info): .*#m', '', $key);
|
||||
$ciphertext = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::extractBER($key);
|
||||
if ($ciphertext === \false) {
|
||||
$ciphertext = $key;
|
||||
}
|
||||
$crypto = self::getEncryptionObject($matches[1]);
|
||||
$crypto->setKey(self::generateSymmetricKey($password, $iv, $crypto->getKeyLength() >> 3));
|
||||
$crypto->setIV($iv);
|
||||
$key = $crypto->decrypt($ciphertext);
|
||||
} else {
|
||||
if (self::$format != self::MODE_DER) {
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::extractBER($key);
|
||||
if ($decoded !== \false) {
|
||||
$key = $decoded;
|
||||
} elseif (self::$format == self::MODE_PEM) {
|
||||
throw new \UnexpectedValueException('Expected base64-encoded PEM format but was unable to decode base64 text');
|
||||
}
|
||||
}
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
/**
|
||||
* Wrap a private key appropriately
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
* @param string $password
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
protected static function wrapPrivateKey($key, $type, $password, array $options = [])
|
||||
{
|
||||
if (empty($password) || !\is_string($password)) {
|
||||
return "-----BEGIN {$type} PRIVATE KEY-----\r\n" . \chunk_split(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($key), 64) . "-----END {$type} PRIVATE KEY-----";
|
||||
}
|
||||
$encryptionAlgorithm = isset($options['encryptionAlgorithm']) ? $options['encryptionAlgorithm'] : self::$defaultEncryptionAlgorithm;
|
||||
$cipher = self::getEncryptionObject($encryptionAlgorithm);
|
||||
$iv = \WPMailSMTP\Vendor\phpseclib3\Crypt\Random::string($cipher->getBlockLength() >> 3);
|
||||
$cipher->setKey(self::generateSymmetricKey($password, $iv, $cipher->getKeyLength() >> 3));
|
||||
$cipher->setIV($iv);
|
||||
$iv = \strtoupper(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::bin2hex($iv));
|
||||
return "-----BEGIN {$type} PRIVATE KEY-----\r\n" . "Proc-Type: 4,ENCRYPTED\r\n" . "DEK-Info: " . $encryptionAlgorithm . ",{$iv}\r\n" . "\r\n" . \chunk_split(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($cipher->encrypt($key)), 64) . "-----END {$type} PRIVATE KEY-----";
|
||||
}
|
||||
/**
|
||||
* Wrap a public key appropriately
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
protected static function wrapPublicKey($key, $type)
|
||||
{
|
||||
return "-----BEGIN {$type} PUBLIC KEY-----\r\n" . \chunk_split(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($key), 64) . "-----END {$type} PUBLIC KEY-----";
|
||||
}
|
||||
}
|
||||
@@ -1,598 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PKCS#8 Formatted Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Used by PHP's openssl_public_encrypt() and openssl's rsautl (when -pubin is set)
|
||||
*
|
||||
* Processes keys with the following headers:
|
||||
*
|
||||
* -----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
* -----BEGIN PRIVATE KEY-----
|
||||
* -----BEGIN PUBLIC KEY-----
|
||||
*
|
||||
* Analogous to ssh-keygen's pkcs8 format (as specified by -m). Although PKCS8
|
||||
* is specific to private keys it's basically creating a DER-encoded wrapper
|
||||
* for keys. This just extends that same concept to public keys (much like ssh-keygen)
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\AES;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DES;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Random;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\RC2;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\RC4;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\TripleDES;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Exception\InsufficientSetupException;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps;
|
||||
/**
|
||||
* PKCS#8 Formatted Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class PKCS8 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS
|
||||
{
|
||||
/**
|
||||
* Default encryption algorithm
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $defaultEncryptionAlgorithm = 'id-PBES2';
|
||||
/**
|
||||
* Default encryption scheme
|
||||
*
|
||||
* Only used when defaultEncryptionAlgorithm is id-PBES2
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $defaultEncryptionScheme = 'aes128-CBC-PAD';
|
||||
/**
|
||||
* Default PRF
|
||||
*
|
||||
* Only used when defaultEncryptionAlgorithm is id-PBES2
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $defaultPRF = 'id-hmacWithSHA256';
|
||||
/**
|
||||
* Default Iteration Count
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private static $defaultIterationCount = 2048;
|
||||
/**
|
||||
* OIDs loaded
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static $oidsLoaded = \false;
|
||||
/**
|
||||
* Sets the default encryption algorithm
|
||||
*
|
||||
* @param string $algo
|
||||
*/
|
||||
public static function setEncryptionAlgorithm($algo)
|
||||
{
|
||||
self::$defaultEncryptionAlgorithm = $algo;
|
||||
}
|
||||
/**
|
||||
* Sets the default encryption algorithm for PBES2
|
||||
*
|
||||
* @param string $algo
|
||||
*/
|
||||
public static function setEncryptionScheme($algo)
|
||||
{
|
||||
self::$defaultEncryptionScheme = $algo;
|
||||
}
|
||||
/**
|
||||
* Sets the iteration count
|
||||
*
|
||||
* @param int $count
|
||||
*/
|
||||
public static function setIterationCount($count)
|
||||
{
|
||||
self::$defaultIterationCount = $count;
|
||||
}
|
||||
/**
|
||||
* Sets the PRF for PBES2
|
||||
*
|
||||
* @param string $algo
|
||||
*/
|
||||
public static function setPRF($algo)
|
||||
{
|
||||
self::$defaultPRF = $algo;
|
||||
}
|
||||
/**
|
||||
* Returns a SymmetricKey object based on a PBES1 $algo
|
||||
*
|
||||
* @return \phpseclib3\Crypt\Common\SymmetricKey
|
||||
* @param string $algo
|
||||
*/
|
||||
private static function getPBES1EncryptionObject($algo)
|
||||
{
|
||||
$algo = \preg_match('#^pbeWith(?:MD2|MD5|SHA1|SHA)And(.*?)-CBC$#', $algo, $matches) ? $matches[1] : \substr($algo, 13);
|
||||
// strlen('pbeWithSHAAnd') == 13
|
||||
switch ($algo) {
|
||||
case 'DES':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\DES('cbc');
|
||||
break;
|
||||
case 'RC2':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\RC2('cbc');
|
||||
break;
|
||||
case '3-KeyTripleDES':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\TripleDES('cbc');
|
||||
break;
|
||||
case '2-KeyTripleDES':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\TripleDES('cbc');
|
||||
$cipher->setKeyLength(128);
|
||||
break;
|
||||
case '128BitRC2':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\RC2('cbc');
|
||||
$cipher->setKeyLength(128);
|
||||
break;
|
||||
case '40BitRC2':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\RC2('cbc');
|
||||
$cipher->setKeyLength(40);
|
||||
break;
|
||||
case '128BitRC4':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\RC4();
|
||||
$cipher->setKeyLength(128);
|
||||
break;
|
||||
case '40BitRC4':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\RC4();
|
||||
$cipher->setKeyLength(40);
|
||||
break;
|
||||
default:
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException("{$algo} is not a supported algorithm");
|
||||
}
|
||||
return $cipher;
|
||||
}
|
||||
/**
|
||||
* Returns a hash based on a PBES1 $algo
|
||||
*
|
||||
* @return string
|
||||
* @param string $algo
|
||||
*/
|
||||
private static function getPBES1Hash($algo)
|
||||
{
|
||||
if (\preg_match('#^pbeWith(MD2|MD5|SHA1|SHA)And.*?-CBC$#', $algo, $matches)) {
|
||||
return $matches[1] == 'SHA' ? 'sha1' : $matches[1];
|
||||
}
|
||||
return 'sha1';
|
||||
}
|
||||
/**
|
||||
* Returns a KDF baesd on a PBES1 $algo
|
||||
*
|
||||
* @return string
|
||||
* @param string $algo
|
||||
*/
|
||||
private static function getPBES1KDF($algo)
|
||||
{
|
||||
switch ($algo) {
|
||||
case 'pbeWithMD2AndDES-CBC':
|
||||
case 'pbeWithMD2AndRC2-CBC':
|
||||
case 'pbeWithMD5AndDES-CBC':
|
||||
case 'pbeWithMD5AndRC2-CBC':
|
||||
case 'pbeWithSHA1AndDES-CBC':
|
||||
case 'pbeWithSHA1AndRC2-CBC':
|
||||
return 'pbkdf1';
|
||||
}
|
||||
return 'pkcs12';
|
||||
}
|
||||
/**
|
||||
* Returns a SymmetricKey object baesd on a PBES2 $algo
|
||||
*
|
||||
* @return SymmetricKey
|
||||
* @param string $algo
|
||||
*/
|
||||
private static function getPBES2EncryptionObject($algo)
|
||||
{
|
||||
switch ($algo) {
|
||||
case 'desCBC':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\TripleDES('cbc');
|
||||
break;
|
||||
case 'des-EDE3-CBC':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\TripleDES('cbc');
|
||||
break;
|
||||
case 'rc2CBC':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\RC2('cbc');
|
||||
// in theory this can be changed
|
||||
$cipher->setKeyLength(128);
|
||||
break;
|
||||
case 'rc5-CBC-PAD':
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException('rc5-CBC-PAD is not supported for PBES2 PKCS#8 keys');
|
||||
case 'aes128-CBC-PAD':
|
||||
case 'aes192-CBC-PAD':
|
||||
case 'aes256-CBC-PAD':
|
||||
$cipher = new \WPMailSMTP\Vendor\phpseclib3\Crypt\AES('cbc');
|
||||
$cipher->setKeyLength(\substr($algo, 3, 3));
|
||||
break;
|
||||
default:
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException("{$algo} is not supported");
|
||||
}
|
||||
return $cipher;
|
||||
}
|
||||
/**
|
||||
* Initialize static variables
|
||||
*
|
||||
*/
|
||||
private static function initialize_static_variables()
|
||||
{
|
||||
if (!isset(static::$childOIDsLoaded)) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\InsufficientSetupException('This class should not be called directly');
|
||||
}
|
||||
if (!static::$childOIDsLoaded) {
|
||||
\WPMailSMTP\Vendor\phpseclib3\File\ASN1::loadOIDs(\is_array(static::OID_NAME) ? \array_combine(static::OID_NAME, static::OID_VALUE) : [static::OID_NAME => static::OID_VALUE]);
|
||||
static::$childOIDsLoaded = \true;
|
||||
}
|
||||
if (!self::$oidsLoaded) {
|
||||
// from https://tools.ietf.org/html/rfc2898
|
||||
\WPMailSMTP\Vendor\phpseclib3\File\ASN1::loadOIDs([
|
||||
// PBES1 encryption schemes
|
||||
'pbeWithMD2AndDES-CBC' => '1.2.840.113549.1.5.1',
|
||||
'pbeWithMD2AndRC2-CBC' => '1.2.840.113549.1.5.4',
|
||||
'pbeWithMD5AndDES-CBC' => '1.2.840.113549.1.5.3',
|
||||
'pbeWithMD5AndRC2-CBC' => '1.2.840.113549.1.5.6',
|
||||
'pbeWithSHA1AndDES-CBC' => '1.2.840.113549.1.5.10',
|
||||
'pbeWithSHA1AndRC2-CBC' => '1.2.840.113549.1.5.11',
|
||||
// from PKCS#12:
|
||||
// https://tools.ietf.org/html/rfc7292
|
||||
'pbeWithSHAAnd128BitRC4' => '1.2.840.113549.1.12.1.1',
|
||||
'pbeWithSHAAnd40BitRC4' => '1.2.840.113549.1.12.1.2',
|
||||
'pbeWithSHAAnd3-KeyTripleDES-CBC' => '1.2.840.113549.1.12.1.3',
|
||||
'pbeWithSHAAnd2-KeyTripleDES-CBC' => '1.2.840.113549.1.12.1.4',
|
||||
'pbeWithSHAAnd128BitRC2-CBC' => '1.2.840.113549.1.12.1.5',
|
||||
'pbeWithSHAAnd40BitRC2-CBC' => '1.2.840.113549.1.12.1.6',
|
||||
'id-PBKDF2' => '1.2.840.113549.1.5.12',
|
||||
'id-PBES2' => '1.2.840.113549.1.5.13',
|
||||
'id-PBMAC1' => '1.2.840.113549.1.5.14',
|
||||
// from PKCS#5 v2.1:
|
||||
// http://www.rsa.com/rsalabs/pkcs/files/h11302-wp-pkcs5v2-1-password-based-cryptography-standard.pdf
|
||||
'id-hmacWithSHA1' => '1.2.840.113549.2.7',
|
||||
'id-hmacWithSHA224' => '1.2.840.113549.2.8',
|
||||
'id-hmacWithSHA256' => '1.2.840.113549.2.9',
|
||||
'id-hmacWithSHA384' => '1.2.840.113549.2.10',
|
||||
'id-hmacWithSHA512' => '1.2.840.113549.2.11',
|
||||
'id-hmacWithSHA512-224' => '1.2.840.113549.2.12',
|
||||
'id-hmacWithSHA512-256' => '1.2.840.113549.2.13',
|
||||
'desCBC' => '1.3.14.3.2.7',
|
||||
'des-EDE3-CBC' => '1.2.840.113549.3.7',
|
||||
'rc2CBC' => '1.2.840.113549.3.2',
|
||||
'rc5-CBC-PAD' => '1.2.840.113549.3.9',
|
||||
'aes128-CBC-PAD' => '2.16.840.1.101.3.4.1.2',
|
||||
'aes192-CBC-PAD' => '2.16.840.1.101.3.4.1.22',
|
||||
'aes256-CBC-PAD' => '2.16.840.1.101.3.4.1.42',
|
||||
]);
|
||||
self::$oidsLoaded = \true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
protected static function load($key, $password = '')
|
||||
{
|
||||
if (!\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::is_stringable($key)) {
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . \gettype($key));
|
||||
}
|
||||
$isPublic = \strpos($key, 'PUBLIC') !== \false;
|
||||
$isPrivate = \strpos($key, 'PRIVATE') !== \false;
|
||||
$decoded = self::preParse($key);
|
||||
$meta = [];
|
||||
$decrypted = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\EncryptedPrivateKeyInfo::MAP);
|
||||
if (\strlen($password) && \is_array($decrypted)) {
|
||||
$algorithm = $decrypted['encryptionAlgorithm']['algorithm'];
|
||||
switch ($algorithm) {
|
||||
// PBES1
|
||||
case 'pbeWithMD2AndDES-CBC':
|
||||
case 'pbeWithMD2AndRC2-CBC':
|
||||
case 'pbeWithMD5AndDES-CBC':
|
||||
case 'pbeWithMD5AndRC2-CBC':
|
||||
case 'pbeWithSHA1AndDES-CBC':
|
||||
case 'pbeWithSHA1AndRC2-CBC':
|
||||
case 'pbeWithSHAAnd3-KeyTripleDES-CBC':
|
||||
case 'pbeWithSHAAnd2-KeyTripleDES-CBC':
|
||||
case 'pbeWithSHAAnd128BitRC2-CBC':
|
||||
case 'pbeWithSHAAnd40BitRC2-CBC':
|
||||
case 'pbeWithSHAAnd128BitRC4':
|
||||
case 'pbeWithSHAAnd40BitRC4':
|
||||
$cipher = self::getPBES1EncryptionObject($algorithm);
|
||||
$hash = self::getPBES1Hash($algorithm);
|
||||
$kdf = self::getPBES1KDF($algorithm);
|
||||
$meta['meta']['algorithm'] = $algorithm;
|
||||
$temp = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
if (!$temp) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
\extract(\WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($temp[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PBEParameter::MAP));
|
||||
$iterationCount = (int) $iterationCount->toString();
|
||||
$cipher->setPassword($password, $kdf, $hash, $salt, $iterationCount);
|
||||
$key = $cipher->decrypt($decrypted['encryptedData']);
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($key);
|
||||
if (!$decoded) {
|
||||
throw new \RuntimeException('Unable to decode BER 2');
|
||||
}
|
||||
break;
|
||||
case 'id-PBES2':
|
||||
$meta['meta']['algorithm'] = $algorithm;
|
||||
$temp = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
if (!$temp) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
$temp = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($temp[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PBES2params::MAP);
|
||||
\extract($temp);
|
||||
$cipher = self::getPBES2EncryptionObject($encryptionScheme['algorithm']);
|
||||
$meta['meta']['cipher'] = $encryptionScheme['algorithm'];
|
||||
$temp = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
if (!$temp) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
$temp = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($temp[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PBES2params::MAP);
|
||||
\extract($temp);
|
||||
if (!$cipher instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\RC2) {
|
||||
$cipher->setIV($encryptionScheme['parameters']['octetString']);
|
||||
} else {
|
||||
$temp = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($encryptionScheme['parameters']);
|
||||
if (!$temp) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
\extract(\WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($temp[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\RC2CBCParameter::MAP));
|
||||
$effectiveKeyLength = (int) $rc2ParametersVersion->toString();
|
||||
switch ($effectiveKeyLength) {
|
||||
case 160:
|
||||
$effectiveKeyLength = 40;
|
||||
break;
|
||||
case 120:
|
||||
$effectiveKeyLength = 64;
|
||||
break;
|
||||
case 58:
|
||||
$effectiveKeyLength = 128;
|
||||
break;
|
||||
}
|
||||
$cipher->setIV($iv);
|
||||
$cipher->setKeyLength($effectiveKeyLength);
|
||||
}
|
||||
$meta['meta']['keyDerivationFunc'] = $keyDerivationFunc['algorithm'];
|
||||
switch ($keyDerivationFunc['algorithm']) {
|
||||
case 'id-PBKDF2':
|
||||
$temp = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($keyDerivationFunc['parameters']);
|
||||
if (!$temp) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
$prf = ['algorithm' => 'id-hmacWithSHA1'];
|
||||
$params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($temp[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PBKDF2params::MAP);
|
||||
\extract($params);
|
||||
$meta['meta']['prf'] = $prf['algorithm'];
|
||||
$hash = \str_replace('-', '/', \substr($prf['algorithm'], 11));
|
||||
$params = [$password, 'pbkdf2', $hash, $salt, (int) $iterationCount->toString()];
|
||||
if (isset($keyLength)) {
|
||||
$params[] = (int) $keyLength->toString();
|
||||
}
|
||||
$cipher->setPassword(...$params);
|
||||
$key = $cipher->decrypt($decrypted['encryptedData']);
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($key);
|
||||
if (!$decoded) {
|
||||
throw new \RuntimeException('Unable to decode BER 3');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException('Only PBKDF2 is supported for PBES2 PKCS#8 keys');
|
||||
}
|
||||
break;
|
||||
case 'id-PBMAC1':
|
||||
//$temp = ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
//$value = ASN1::asn1map($temp[0], Maps\PBMAC1params::MAP);
|
||||
// since i can't find any implementation that does PBMAC1 it is unsupported
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException('Only PBES1 and PBES2 PKCS#8 keys are supported.');
|
||||
}
|
||||
}
|
||||
$private = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\OneAsymmetricKey::MAP);
|
||||
if (\is_array($private)) {
|
||||
if ($isPublic) {
|
||||
throw new \UnexpectedValueException('Human readable string claims public key but DER encoded string claims private key');
|
||||
}
|
||||
if (isset($private['privateKeyAlgorithm']['parameters']) && !$private['privateKeyAlgorithm']['parameters'] instanceof \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element && isset($decoded[0]['content'][1]['content'][1])) {
|
||||
$temp = $decoded[0]['content'][1]['content'][1];
|
||||
$private['privateKeyAlgorithm']['parameters'] = new \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element(\substr($key, $temp['start'], $temp['length']));
|
||||
}
|
||||
if (\is_array(static::OID_NAME)) {
|
||||
if (!\in_array($private['privateKeyAlgorithm']['algorithm'], static::OID_NAME)) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException($private['privateKeyAlgorithm']['algorithm'] . ' is not a supported key type');
|
||||
}
|
||||
} else {
|
||||
if ($private['privateKeyAlgorithm']['algorithm'] != static::OID_NAME) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException('Only ' . static::OID_NAME . ' keys are supported; this is a ' . $private['privateKeyAlgorithm']['algorithm'] . ' key');
|
||||
}
|
||||
}
|
||||
if (isset($private['publicKey'])) {
|
||||
if ($private['publicKey'][0] != "\0") {
|
||||
throw new \UnexpectedValueException('The first byte of the public key should be null - not ' . \bin2hex($private['publicKey'][0]));
|
||||
}
|
||||
$private['publicKey'] = \substr($private['publicKey'], 1);
|
||||
}
|
||||
return $private + $meta;
|
||||
}
|
||||
// EncryptedPrivateKeyInfo and PublicKeyInfo have largely identical "signatures". the only difference
|
||||
// is that the former has an octet string and the later has a bit string. the first byte of a bit
|
||||
// string represents the number of bits in the last byte that are to be ignored but, currently,
|
||||
// bit strings wanting a non-zero amount of bits trimmed are not supported
|
||||
$public = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PublicKeyInfo::MAP);
|
||||
if (\is_array($public)) {
|
||||
if ($isPrivate) {
|
||||
throw new \UnexpectedValueException('Human readable string claims private key but DER encoded string claims public key');
|
||||
}
|
||||
if ($public['publicKey'][0] != "\0") {
|
||||
throw new \UnexpectedValueException('The first byte of the public key should be null - not ' . \bin2hex($public['publicKey'][0]));
|
||||
}
|
||||
if (\is_array(static::OID_NAME)) {
|
||||
if (!\in_array($public['publicKeyAlgorithm']['algorithm'], static::OID_NAME)) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException($public['publicKeyAlgorithm']['algorithm'] . ' is not a supported key type');
|
||||
}
|
||||
} else {
|
||||
if ($public['publicKeyAlgorithm']['algorithm'] != static::OID_NAME) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException('Only ' . static::OID_NAME . ' keys are supported; this is a ' . $public['publicKeyAlgorithm']['algorithm'] . ' key');
|
||||
}
|
||||
}
|
||||
if (isset($public['publicKeyAlgorithm']['parameters']) && !$public['publicKeyAlgorithm']['parameters'] instanceof \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element && isset($decoded[0]['content'][0]['content'][1])) {
|
||||
$temp = $decoded[0]['content'][0]['content'][1];
|
||||
$public['publicKeyAlgorithm']['parameters'] = new \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element(\substr($key, $temp['start'], $temp['length']));
|
||||
}
|
||||
$public['publicKey'] = \substr($public['publicKey'], 1);
|
||||
return $public;
|
||||
}
|
||||
throw new \RuntimeException('Unable to parse using either OneAsymmetricKey or PublicKeyInfo ASN1 maps');
|
||||
}
|
||||
/**
|
||||
* Wrap a private key appropriately
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $attr
|
||||
* @param mixed $params
|
||||
* @param string $password
|
||||
* @param string $oid optional
|
||||
* @param string $publicKey optional
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
protected static function wrapPrivateKey($key, $attr, $params, $password, $oid = null, $publicKey = '', array $options = [])
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
$key = ['version' => 'v1', 'privateKeyAlgorithm' => ['algorithm' => \is_string(static::OID_NAME) ? static::OID_NAME : $oid], 'privateKey' => $key];
|
||||
if ($oid != 'id-Ed25519' && $oid != 'id-Ed448') {
|
||||
$key['privateKeyAlgorithm']['parameters'] = $params;
|
||||
}
|
||||
if (!empty($attr)) {
|
||||
$key['attributes'] = $attr;
|
||||
}
|
||||
if (!empty($publicKey)) {
|
||||
$key['version'] = 'v2';
|
||||
$key['publicKey'] = $publicKey;
|
||||
}
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($key, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\OneAsymmetricKey::MAP);
|
||||
if (!empty($password) && \is_string($password)) {
|
||||
$salt = \WPMailSMTP\Vendor\phpseclib3\Crypt\Random::string(8);
|
||||
$iterationCount = isset($options['iterationCount']) ? $options['iterationCount'] : self::$defaultIterationCount;
|
||||
$encryptionAlgorithm = isset($options['encryptionAlgorithm']) ? $options['encryptionAlgorithm'] : self::$defaultEncryptionAlgorithm;
|
||||
$encryptionScheme = isset($options['encryptionScheme']) ? $options['encryptionScheme'] : self::$defaultEncryptionScheme;
|
||||
$prf = isset($options['PRF']) ? $options['PRF'] : self::$defaultPRF;
|
||||
if ($encryptionAlgorithm == 'id-PBES2') {
|
||||
$crypto = self::getPBES2EncryptionObject($encryptionScheme);
|
||||
$hash = \str_replace('-', '/', \substr($prf, 11));
|
||||
$kdf = 'pbkdf2';
|
||||
$iv = \WPMailSMTP\Vendor\phpseclib3\Crypt\Random::string($crypto->getBlockLength() >> 3);
|
||||
$PBKDF2params = ['salt' => $salt, 'iterationCount' => $iterationCount, 'prf' => ['algorithm' => $prf, 'parameters' => null]];
|
||||
$PBKDF2params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($PBKDF2params, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PBKDF2params::MAP);
|
||||
if (!$crypto instanceof \WPMailSMTP\Vendor\phpseclib3\Crypt\RC2) {
|
||||
$params = ['octetString' => $iv];
|
||||
} else {
|
||||
$params = ['rc2ParametersVersion' => 58, 'iv' => $iv];
|
||||
$params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($params, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\RC2CBCParameter::MAP);
|
||||
$params = new \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element($params);
|
||||
}
|
||||
$params = ['keyDerivationFunc' => ['algorithm' => 'id-PBKDF2', 'parameters' => new \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element($PBKDF2params)], 'encryptionScheme' => ['algorithm' => $encryptionScheme, 'parameters' => $params]];
|
||||
$params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($params, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PBES2params::MAP);
|
||||
$crypto->setIV($iv);
|
||||
} else {
|
||||
$crypto = self::getPBES1EncryptionObject($encryptionAlgorithm);
|
||||
$hash = self::getPBES1Hash($encryptionAlgorithm);
|
||||
$kdf = self::getPBES1KDF($encryptionAlgorithm);
|
||||
$params = ['salt' => $salt, 'iterationCount' => $iterationCount];
|
||||
$params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($params, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PBEParameter::MAP);
|
||||
}
|
||||
$crypto->setPassword($password, $kdf, $hash, $salt, $iterationCount);
|
||||
$key = $crypto->encrypt($key);
|
||||
$key = ['encryptionAlgorithm' => ['algorithm' => $encryptionAlgorithm, 'parameters' => new \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element($params)], 'encryptedData' => $key];
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($key, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\EncryptedPrivateKeyInfo::MAP);
|
||||
return "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n" . \chunk_split(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($key), 64) . "-----END ENCRYPTED PRIVATE KEY-----";
|
||||
}
|
||||
return "-----BEGIN PRIVATE KEY-----\r\n" . \chunk_split(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($key), 64) . "-----END PRIVATE KEY-----";
|
||||
}
|
||||
/**
|
||||
* Wrap a public key appropriately
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $params
|
||||
* @param string $oid
|
||||
* @return string
|
||||
*/
|
||||
protected static function wrapPublicKey($key, $params, $oid = null)
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
$key = ['publicKeyAlgorithm' => ['algorithm' => \is_string(static::OID_NAME) ? static::OID_NAME : $oid], 'publicKey' => "\0" . $key];
|
||||
if ($oid != 'id-Ed25519' && $oid != 'id-Ed448') {
|
||||
$key['publicKeyAlgorithm']['parameters'] = $params;
|
||||
}
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($key, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PublicKeyInfo::MAP);
|
||||
return "-----BEGIN PUBLIC KEY-----\r\n" . \chunk_split(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($key), 64) . "-----END PUBLIC KEY-----";
|
||||
}
|
||||
/**
|
||||
* Perform some preliminary parsing of the key
|
||||
*
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
private static function preParse(&$key)
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
if (self::$format != self::MODE_DER) {
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::extractBER($key);
|
||||
if ($decoded !== \false) {
|
||||
$key = $decoded;
|
||||
} elseif (self::$format == self::MODE_PEM) {
|
||||
throw new \UnexpectedValueException('Expected base64-encoded PEM format but was unable to decode base64 text');
|
||||
}
|
||||
}
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($key);
|
||||
if (!$decoded) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
/**
|
||||
* Returns the encryption parameters used by the key
|
||||
*
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
public static function extractEncryptionAlgorithm($key)
|
||||
{
|
||||
if (!\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::is_stringable($key)) {
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . \gettype($key));
|
||||
}
|
||||
$decoded = self::preParse($key);
|
||||
$r = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\EncryptedPrivateKeyInfo::MAP);
|
||||
if (!\is_array($r)) {
|
||||
throw new \RuntimeException('Unable to parse using EncryptedPrivateKeyInfo map');
|
||||
}
|
||||
if ($r['encryptionAlgorithm']['algorithm'] == 'id-PBES2') {
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($r['encryptionAlgorithm']['parameters']->element);
|
||||
if (!$decoded) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
$r['encryptionAlgorithm']['parameters'] = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PBES2params::MAP);
|
||||
$kdf =& $r['encryptionAlgorithm']['parameters']['keyDerivationFunc'];
|
||||
switch ($kdf['algorithm']) {
|
||||
case 'id-PBKDF2':
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($kdf['parameters']->element);
|
||||
if (!$decoded) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
$kdf['parameters'] = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\PBKDF2params::MAP);
|
||||
}
|
||||
}
|
||||
return $r['encryptionAlgorithm'];
|
||||
}
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PuTTY Formatted Key Handler
|
||||
*
|
||||
* See PuTTY's SSHPUBK.C and https://tartarus.org/~simon/putty-snapshots/htmldoc/AppendixC.html
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\AES;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Hash;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Random;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException;
|
||||
/**
|
||||
* PuTTY Formatted Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class PuTTY
|
||||
{
|
||||
/**
|
||||
* Default comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $comment = 'phpseclib-generated-key';
|
||||
/**
|
||||
* Default version
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private static $version = 2;
|
||||
/**
|
||||
* Sets the default comment
|
||||
*
|
||||
* @param string $comment
|
||||
*/
|
||||
public static function setComment($comment)
|
||||
{
|
||||
self::$comment = \str_replace(["\r", "\n"], '', $comment);
|
||||
}
|
||||
/**
|
||||
* Sets the default version
|
||||
*
|
||||
* @param int $version
|
||||
*/
|
||||
public static function setVersion($version)
|
||||
{
|
||||
if ($version != 2 && $version != 3) {
|
||||
throw new \RuntimeException('Only supported versions are 2 and 3');
|
||||
}
|
||||
self::$version = $version;
|
||||
}
|
||||
/**
|
||||
* Generate a symmetric key for PuTTY v2 keys
|
||||
*
|
||||
* @param string $password
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
private static function generateV2Key($password, $length)
|
||||
{
|
||||
$symkey = '';
|
||||
$sequence = 0;
|
||||
while (\strlen($symkey) < $length) {
|
||||
$temp = \pack('Na*', $sequence++, $password);
|
||||
$symkey .= \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::hex2bin(\sha1($temp));
|
||||
}
|
||||
return \substr($symkey, 0, $length);
|
||||
}
|
||||
/**
|
||||
* Generate a symmetric key for PuTTY v3 keys
|
||||
*
|
||||
* @param string $password
|
||||
* @param string $flavour
|
||||
* @param int $memory
|
||||
* @param int $passes
|
||||
* @param string $salt
|
||||
* @return array
|
||||
*/
|
||||
private static function generateV3Key($password, $flavour, $memory, $passes, $salt)
|
||||
{
|
||||
if (!\function_exists('sodium_crypto_pwhash')) {
|
||||
throw new \RuntimeException('sodium_crypto_pwhash needs to exist for Argon2 password hasing');
|
||||
}
|
||||
switch ($flavour) {
|
||||
case 'Argon2i':
|
||||
$flavour = \SODIUM_CRYPTO_PWHASH_ALG_ARGON2I13;
|
||||
break;
|
||||
case 'Argon2id':
|
||||
$flavour = \SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13;
|
||||
break;
|
||||
default:
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException('Only Argon2i and Argon2id are supported');
|
||||
}
|
||||
$length = 80;
|
||||
// keylen + ivlen + mac_keylen
|
||||
$temp = \sodium_crypto_pwhash($length, $password, $salt, $passes, $memory << 10, $flavour);
|
||||
$symkey = \substr($temp, 0, 32);
|
||||
$symiv = \substr($temp, 32, 16);
|
||||
$hashkey = \substr($temp, -32);
|
||||
return \compact('symkey', 'symiv', 'hashkey');
|
||||
}
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password)
|
||||
{
|
||||
if (!\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::is_stringable($key)) {
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . \gettype($key));
|
||||
}
|
||||
if (\strpos($key, 'BEGIN SSH2 PUBLIC KEY') !== \false) {
|
||||
$lines = \preg_split('#[\\r\\n]+#', $key);
|
||||
switch (\true) {
|
||||
case $lines[0] != '---- BEGIN SSH2 PUBLIC KEY ----':
|
||||
throw new \UnexpectedValueException('Key doesn\'t start with ---- BEGIN SSH2 PUBLIC KEY ----');
|
||||
case $lines[\count($lines) - 1] != '---- END SSH2 PUBLIC KEY ----':
|
||||
throw new \UnexpectedValueException('Key doesn\'t end with ---- END SSH2 PUBLIC KEY ----');
|
||||
}
|
||||
$lines = \array_splice($lines, 1, -1);
|
||||
$lines = \array_map(function ($line) {
|
||||
return \rtrim($line, "\r\n");
|
||||
}, $lines);
|
||||
$data = $current = '';
|
||||
$values = [];
|
||||
$in_value = \false;
|
||||
foreach ($lines as $line) {
|
||||
switch (\true) {
|
||||
case \preg_match('#^(.*?): (.*)#', $line, $match):
|
||||
$in_value = $line[\strlen($line) - 1] == '\\';
|
||||
$current = \strtolower($match[1]);
|
||||
$values[$current] = $in_value ? \substr($match[2], 0, -1) : $match[2];
|
||||
break;
|
||||
case $in_value:
|
||||
$in_value = $line[\strlen($line) - 1] == '\\';
|
||||
$values[$current] .= $in_value ? \substr($line, 0, -1) : $line;
|
||||
break;
|
||||
default:
|
||||
$data .= $line;
|
||||
}
|
||||
}
|
||||
$components = \call_user_func([static::PUBLIC_HANDLER, 'load'], $data);
|
||||
if ($components === \false) {
|
||||
throw new \UnexpectedValueException('Unable to decode public key');
|
||||
}
|
||||
$components += $values;
|
||||
$components['comment'] = \str_replace(['\\\\', '\\"'], ['\\', '"'], $values['comment']);
|
||||
return $components;
|
||||
}
|
||||
$components = [];
|
||||
$key = \preg_split('#\\r\\n|\\r|\\n#', \trim($key));
|
||||
if (\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::shift($key[0], \strlen('PuTTY-User-Key-File-')) != 'PuTTY-User-Key-File-') {
|
||||
return \false;
|
||||
}
|
||||
$version = (int) \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::shift($key[0], 3);
|
||||
// should be either "2: " or "3: 0" prior to int casting
|
||||
if ($version != 2 && $version != 3) {
|
||||
throw new \RuntimeException('Only v2 and v3 PuTTY private keys are supported');
|
||||
}
|
||||
$components['type'] = $type = \rtrim($key[0]);
|
||||
if (!\in_array($type, static::$types)) {
|
||||
$error = \count(static::$types) == 1 ? 'Only ' . static::$types[0] . ' keys are supported. ' : '';
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\UnsupportedAlgorithmException($error . 'This is an unsupported ' . $type . ' key');
|
||||
}
|
||||
$encryption = \trim(\preg_replace('#Encryption: (.+)#', '$1', $key[1]));
|
||||
$components['comment'] = \trim(\preg_replace('#Comment: (.+)#', '$1', $key[2]));
|
||||
$publicLength = \trim(\preg_replace('#Public-Lines: (\\d+)#', '$1', $key[3]));
|
||||
$public = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_decode(\implode('', \array_map('trim', \array_slice($key, 4, $publicLength))));
|
||||
$source = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('ssss', $type, $encryption, $components['comment'], $public);
|
||||
\extract(\unpack('Nlength', \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::shift($public, 4)));
|
||||
$newtype = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::shift($public, $length);
|
||||
if ($newtype != $type) {
|
||||
throw new \RuntimeException('The binary type does not match the human readable type field');
|
||||
}
|
||||
$components['public'] = $public;
|
||||
switch ($version) {
|
||||
case 3:
|
||||
$hashkey = '';
|
||||
break;
|
||||
case 2:
|
||||
$hashkey = 'putty-private-key-file-mac-key';
|
||||
}
|
||||
$offset = $publicLength + 4;
|
||||
switch ($encryption) {
|
||||
case 'aes256-cbc':
|
||||
$crypto = new \WPMailSMTP\Vendor\phpseclib3\Crypt\AES('cbc');
|
||||
switch ($version) {
|
||||
case 3:
|
||||
$flavour = \trim(\preg_replace('#Key-Derivation: (.*)#', '$1', $key[$offset++]));
|
||||
$memory = \trim(\preg_replace('#Argon2-Memory: (\\d+)#', '$1', $key[$offset++]));
|
||||
$passes = \trim(\preg_replace('#Argon2-Passes: (\\d+)#', '$1', $key[$offset++]));
|
||||
$parallelism = \trim(\preg_replace('#Argon2-Parallelism: (\\d+)#', '$1', $key[$offset++]));
|
||||
$salt = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::hex2bin(\trim(\preg_replace('#Argon2-Salt: ([0-9a-f]+)#', '$1', $key[$offset++])));
|
||||
\extract(self::generateV3Key($password, $flavour, $memory, $passes, $salt));
|
||||
break;
|
||||
case 2:
|
||||
$symkey = self::generateV2Key($password, 32);
|
||||
$symiv = \str_repeat("\0", $crypto->getBlockLength() >> 3);
|
||||
$hashkey .= $password;
|
||||
}
|
||||
}
|
||||
switch ($version) {
|
||||
case 3:
|
||||
$hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha256');
|
||||
$hash->setKey($hashkey);
|
||||
break;
|
||||
case 2:
|
||||
$hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha1');
|
||||
$hash->setKey(\sha1($hashkey, \true));
|
||||
}
|
||||
$privateLength = \trim(\preg_replace('#Private-Lines: (\\d+)#', '$1', $key[$offset++]));
|
||||
$private = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_decode(\implode('', \array_map('trim', \array_slice($key, $offset, $privateLength))));
|
||||
if ($encryption != 'none') {
|
||||
$crypto->setKey($symkey);
|
||||
$crypto->setIV($symiv);
|
||||
$crypto->disablePadding();
|
||||
$private = $crypto->decrypt($private);
|
||||
}
|
||||
$source .= \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('s', $private);
|
||||
$hmac = \trim(\preg_replace('#Private-MAC: (.+)#', '$1', $key[$offset + $privateLength]));
|
||||
$hmac = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::hex2bin($hmac);
|
||||
if (!\hash_equals($hash->hash($source), $hmac)) {
|
||||
throw new \UnexpectedValueException('MAC validation error');
|
||||
}
|
||||
$components['private'] = $private;
|
||||
return $components;
|
||||
}
|
||||
/**
|
||||
* Wrap a private key appropriately
|
||||
*
|
||||
* @param string $public
|
||||
* @param string $private
|
||||
* @param string $type
|
||||
* @param string $password
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
protected static function wrapPrivateKey($public, $private, $type, $password, array $options = [])
|
||||
{
|
||||
$encryption = !empty($password) || \is_string($password) ? 'aes256-cbc' : 'none';
|
||||
$comment = isset($options['comment']) ? $options['comment'] : self::$comment;
|
||||
$version = isset($options['version']) ? $options['version'] : self::$version;
|
||||
$key = "PuTTY-User-Key-File-{$version}: {$type}\r\n";
|
||||
$key .= "Encryption: {$encryption}\r\n";
|
||||
$key .= "Comment: {$comment}\r\n";
|
||||
$public = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('s', $type) . $public;
|
||||
$source = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('ssss', $type, $encryption, $comment, $public);
|
||||
$public = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($public);
|
||||
$key .= "Public-Lines: " . (\strlen($public) + 63 >> 6) . "\r\n";
|
||||
$key .= \chunk_split($public, 64);
|
||||
if (empty($password) && !\is_string($password)) {
|
||||
$source .= \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('s', $private);
|
||||
switch ($version) {
|
||||
case 3:
|
||||
$hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha256');
|
||||
$hash->setKey('');
|
||||
break;
|
||||
case 2:
|
||||
$hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha1');
|
||||
$hash->setKey(\sha1('putty-private-key-file-mac-key', \true));
|
||||
}
|
||||
} else {
|
||||
$private .= \WPMailSMTP\Vendor\phpseclib3\Crypt\Random::string(16 - (\strlen($private) & 15));
|
||||
$source .= \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('s', $private);
|
||||
$crypto = new \WPMailSMTP\Vendor\phpseclib3\Crypt\AES('cbc');
|
||||
switch ($version) {
|
||||
case 3:
|
||||
$salt = \WPMailSMTP\Vendor\phpseclib3\Crypt\Random::string(16);
|
||||
$key .= "Key-Derivation: Argon2id\r\n";
|
||||
$key .= "Argon2-Memory: 8192\r\n";
|
||||
$key .= "Argon2-Passes: 13\r\n";
|
||||
$key .= "Argon2-Parallelism: 1\r\n";
|
||||
$key .= "Argon2-Salt: " . \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::bin2hex($salt) . "\r\n";
|
||||
\extract(self::generateV3Key($password, 'Argon2id', 8192, 13, $salt));
|
||||
$hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha256');
|
||||
$hash->setKey($hashkey);
|
||||
break;
|
||||
case 2:
|
||||
$symkey = self::generateV2Key($password, 32);
|
||||
$symiv = \str_repeat("\0", $crypto->getBlockLength() >> 3);
|
||||
$hashkey = 'putty-private-key-file-mac-key' . $password;
|
||||
$hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha1');
|
||||
$hash->setKey(\sha1($hashkey, \true));
|
||||
}
|
||||
$crypto->setKey($symkey);
|
||||
$crypto->setIV($symiv);
|
||||
$crypto->disablePadding();
|
||||
$private = $crypto->encrypt($private);
|
||||
$mac = $hash->hash($source);
|
||||
}
|
||||
$private = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($private);
|
||||
$key .= 'Private-Lines: ' . (\strlen($private) + 63 >> 6) . "\r\n";
|
||||
$key .= \chunk_split($private, 64);
|
||||
$key .= 'Private-MAC: ' . \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::bin2hex($hash->hash($source)) . "\r\n";
|
||||
return $key;
|
||||
}
|
||||
/**
|
||||
* Wrap a public key appropriately
|
||||
*
|
||||
* This is basically the format described in RFC 4716 (https://tools.ietf.org/html/rfc4716)
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
protected static function wrapPublicKey($key, $type)
|
||||
{
|
||||
$key = \pack('Na*a*', \strlen($type), $type, $key);
|
||||
$key = "---- BEGIN SSH2 PUBLIC KEY ----\r\n" . 'Comment: "' . \str_replace(['\\', '"'], ['\\\\', '\\"'], self::$comment) . "\"\r\n" . \chunk_split(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($key), 64) . '---- END SSH2 PUBLIC KEY ----';
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Raw Signature Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Handles signatures as arrays
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Signature;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* Raw Signature Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class Raw
|
||||
{
|
||||
/**
|
||||
* Loads a signature
|
||||
*
|
||||
* @param array $sig
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function load($sig)
|
||||
{
|
||||
switch (\true) {
|
||||
case !\is_array($sig):
|
||||
case !isset($sig['r']) || !isset($sig['s']):
|
||||
case !$sig['r'] instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger:
|
||||
case !$sig['s'] instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger:
|
||||
return \false;
|
||||
}
|
||||
return ['r' => $sig['r'], 's' => $sig['s']];
|
||||
}
|
||||
/**
|
||||
* Returns a signature in the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $r
|
||||
* @param \phpseclib3\Math\BigInteger $s
|
||||
* @return string
|
||||
*/
|
||||
public static function save(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $r, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $s)
|
||||
{
|
||||
return \compact('r', 's');
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PrivateKey interface
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2009 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
namespace WPMailSMTP\Vendor\phpseclib3\Crypt\Common;
|
||||
|
||||
/**
|
||||
* PrivateKey interface
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
interface PrivateKey
|
||||
{
|
||||
public function sign($message);
|
||||
//public function decrypt($ciphertext);
|
||||
public function getPublicKey();
|
||||
public function toString($type, array $options = []);
|
||||
/**
|
||||
* @param string|false $password
|
||||
* @return mixed
|
||||
*/
|
||||
public function withPassword($password = \false);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PublicKey interface
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2009 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
namespace WPMailSMTP\Vendor\phpseclib3\Crypt\Common;
|
||||
|
||||
/**
|
||||
* PublicKey interface
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
interface PublicKey
|
||||
{
|
||||
public function verify($message, $signature);
|
||||
//public function encrypt($plaintext);
|
||||
public function toString($type, array $options = []);
|
||||
public function getFingerprint($algorithm);
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base Class for all stream ciphers
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
||||
* @copyright 2007 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
namespace WPMailSMTP\Vendor\phpseclib3\Crypt\Common;
|
||||
|
||||
/**
|
||||
* Base Class for all stream cipher classes
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class StreamCipher extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\SymmetricKey
|
||||
{
|
||||
/**
|
||||
* Block Length of the cipher
|
||||
*
|
||||
* Stream ciphers do not have a block size
|
||||
*
|
||||
* @see \phpseclib3\Crypt\Common\SymmetricKey::block_size
|
||||
* @var int
|
||||
*/
|
||||
protected $block_size = 0;
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
* @see \phpseclib3\Crypt\Common\SymmetricKey::__construct()
|
||||
* @return \phpseclib3\Crypt\Common\StreamCipher
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('stream');
|
||||
}
|
||||
/**
|
||||
* Stream ciphers not use an IV
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function usesIV()
|
||||
{
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Fingerprint Trait for Public Keys
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Traits;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Hash;
|
||||
/**
|
||||
* Fingerprint Trait for Private Keys
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
trait Fingerprint
|
||||
{
|
||||
/**
|
||||
* Returns the public key's fingerprint
|
||||
*
|
||||
* The public key's fingerprint is returned, which is equivalent to running `ssh-keygen -lf rsa.pub`. If there is
|
||||
* no public key currently loaded, false is returned.
|
||||
* Example output (md5): "c1:b1:30:29:d7:b8:de:6c:97:77:10:d7:46:41:63:87" (as specified by RFC 4716)
|
||||
*
|
||||
* @param string $algorithm The hashing algorithm to be used. Valid options are 'md5' and 'sha256'. False is returned
|
||||
* for invalid values.
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFingerprint($algorithm = 'md5')
|
||||
{
|
||||
$type = self::validatePlugin('Keys', 'OpenSSH', 'savePublicKey');
|
||||
if ($type === \false) {
|
||||
return \false;
|
||||
}
|
||||
$key = $this->toString('OpenSSH', ['binary' => \true]);
|
||||
if ($key === \false) {
|
||||
return \false;
|
||||
}
|
||||
switch ($algorithm) {
|
||||
case 'sha256':
|
||||
$hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha256');
|
||||
$base = \base64_encode($hash->hash($key));
|
||||
return \substr($base, 0, \strlen($base) - 1);
|
||||
case 'md5':
|
||||
return \substr(\chunk_split(\md5($key), 2, ':'), 0, -1);
|
||||
default:
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Password Protected Trait for Private Keys
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Traits;
|
||||
|
||||
/**
|
||||
* Password Protected Trait for Private Keys
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
trait PasswordProtected
|
||||
{
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @var string|bool
|
||||
*/
|
||||
private $password = \false;
|
||||
/**
|
||||
* Sets the password
|
||||
*
|
||||
* Private keys can be encrypted with a password. To unset the password, pass in the empty string or false.
|
||||
* Or rather, pass in $password such that empty($password) && !is_string($password) is true.
|
||||
*
|
||||
* @see self::createKey()
|
||||
* @see self::load()
|
||||
* @param string|bool $password
|
||||
*/
|
||||
public function withPassword($password = \false)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->password = $password;
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
<?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.
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DH\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS1 as Progenitor;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* "PKCS1" Formatted DH Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class PKCS1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS1
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
$key = parent::load($key, $password);
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($key);
|
||||
if (!$decoded) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
$components = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\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
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function saveParameters(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $prime, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $base, array $options = [])
|
||||
{
|
||||
$params = ['prime' => $prime, 'base' => $base];
|
||||
$params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($params, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DHParameter::MAP);
|
||||
return "-----BEGIN DH PARAMETERS-----\r\n" . \chunk_split(\base64_encode($params), 64) . "-----END DH PARAMETERS-----\r\n";
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
<?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-----
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DH\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS8 as Progenitor;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* PKCS#8 Formatted DH Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class PKCS8 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS8
|
||||
{
|
||||
/**
|
||||
* OID Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OID_NAME = 'dhKeyAgreement';
|
||||
/**
|
||||
* OID Value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OID_VALUE = '1.2.840.113549.1.3.1';
|
||||
/**
|
||||
* Child OIDs loaded
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $childOIDsLoaded = \false;
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
$key = parent::load($key, $password);
|
||||
$type = isset($key['privateKey']) ? 'privateKey' : 'publicKey';
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($key[$type . 'Algorithm']['parameters']->element);
|
||||
if (empty($decoded)) {
|
||||
throw new \RuntimeException('Unable to decode BER of parameters');
|
||||
}
|
||||
$components = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DHParameter::MAP);
|
||||
if (!\is_array($components)) {
|
||||
throw new \RuntimeException('Unable to perform ASN1 mapping on parameters');
|
||||
}
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($key[$type]);
|
||||
switch (\true) {
|
||||
case !isset($decoded):
|
||||
case !isset($decoded[0]['content']):
|
||||
case !$decoded[0]['content'] instanceof \WPMailSMTP\Vendor\phpseclib3\Math\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.
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $prime
|
||||
* @param \phpseclib3\Math\BigInteger $base
|
||||
* @param \phpseclib3\Math\BigInteger $privateKey
|
||||
* @param \phpseclib3\Math\BigInteger $publicKey
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePrivateKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $prime, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $base, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $privateKey, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $publicKey, $password = '', array $options = [])
|
||||
{
|
||||
$params = ['prime' => $prime, 'base' => $base];
|
||||
$params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($params, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DHParameter::MAP);
|
||||
$params = new \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element($params);
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($privateKey, ['type' => \WPMailSMTP\Vendor\phpseclib3\File\ASN1::TYPE_INTEGER]);
|
||||
return self::wrapPrivateKey($key, [], $params, $password, null, '', $options);
|
||||
}
|
||||
/**
|
||||
* Convert a public key to the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $prime
|
||||
* @param \phpseclib3\Math\BigInteger $base
|
||||
* @param \phpseclib3\Math\BigInteger $publicKey
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $prime, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $base, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $publicKey, array $options = [])
|
||||
{
|
||||
$params = ['prime' => $prime, 'base' => $base];
|
||||
$params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($params, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DHParameter::MAP);
|
||||
$params = new \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element($params);
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($publicKey, ['type' => \WPMailSMTP\Vendor\phpseclib3\File\ASN1::TYPE_INTEGER]);
|
||||
return self::wrapPublicKey($key, $params);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DH Parameters
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DH;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DH;
|
||||
/**
|
||||
* DH Parameters
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
final class Parameters extends \WPMailSMTP\Vendor\phpseclib3\Crypt\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);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DH Private Key
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DH;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DH;
|
||||
/**
|
||||
* DH Private Key
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
final class PrivateKey extends \WPMailSMTP\Vendor\phpseclib3\Crypt\DH
|
||||
{
|
||||
use Common\Traits\PasswordProtected;
|
||||
/**
|
||||
* Private Key
|
||||
*
|
||||
* @var \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
protected $privateKey;
|
||||
/**
|
||||
* Public Key
|
||||
*
|
||||
* @var \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
protected $publicKey;
|
||||
/**
|
||||
* Returns the public key
|
||||
*
|
||||
* @return DH\PublicKey
|
||||
*/
|
||||
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 \WPMailSMTP\Vendor\phpseclib3\Crypt\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);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DH Public Key
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DH;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DH;
|
||||
/**
|
||||
* DH Public Key
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
final class PublicKey extends \WPMailSMTP\Vendor\phpseclib3\Crypt\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 \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
public function toBigInteger()
|
||||
{
|
||||
return $this->publicKey;
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenSSH Formatted DSA Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Place in $HOME/.ssh/authorized_keys
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\OpenSSH as Progenitor;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* OpenSSH Formatted DSA Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class OpenSSH extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\OpenSSH
|
||||
{
|
||||
/**
|
||||
* Supported Key Types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $types = ['ssh-dss'];
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
$parsed = parent::load($key, $password);
|
||||
if (isset($parsed['paddedKey'])) {
|
||||
list($type) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('s', $parsed['paddedKey']);
|
||||
if ($type != $parsed['type']) {
|
||||
throw new \RuntimeException("The public and private keys are not of the same type ({$type} vs {$parsed['type']})");
|
||||
}
|
||||
list($p, $q, $g, $y, $x, $comment) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('i5s', $parsed['paddedKey']);
|
||||
return \compact('p', 'q', 'g', 'y', 'x', 'comment');
|
||||
}
|
||||
list($p, $q, $g, $y) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('iiii', $parsed['publicKey']);
|
||||
$comment = $parsed['comment'];
|
||||
return \compact('p', 'q', 'g', 'y', 'comment');
|
||||
}
|
||||
/**
|
||||
* Convert a public key to the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y, array $options = [])
|
||||
{
|
||||
if ($q->getLength() != 160) {
|
||||
throw new \InvalidArgumentException('SSH only supports keys with an N (length of Group Order q) of 160');
|
||||
}
|
||||
// from <http://tools.ietf.org/html/rfc4253#page-15>:
|
||||
// string "ssh-dss"
|
||||
// mpint p
|
||||
// mpint q
|
||||
// mpint g
|
||||
// mpint y
|
||||
$DSAPublicKey = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('siiii', 'ssh-dss', $p, $q, $g, $y);
|
||||
if (isset($options['binary']) ? $options['binary'] : self::$binary) {
|
||||
return $DSAPublicKey;
|
||||
}
|
||||
$comment = isset($options['comment']) ? $options['comment'] : self::$comment;
|
||||
$DSAPublicKey = 'ssh-dss ' . \base64_encode($DSAPublicKey) . ' ' . $comment;
|
||||
return $DSAPublicKey;
|
||||
}
|
||||
/**
|
||||
* Convert a private key to the appropriate format.
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @param \phpseclib3\Math\BigInteger $x
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePrivateKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $x, $password = '', array $options = [])
|
||||
{
|
||||
$publicKey = self::savePublicKey($p, $q, $g, $y, ['binary' => \true]);
|
||||
$privateKey = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('si5', 'ssh-dss', $p, $q, $g, $y, $x);
|
||||
return self::wrapPrivateKey($publicKey, $privateKey, $password, $options);
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PKCS#1 Formatted DSA Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Used by File/X509.php
|
||||
*
|
||||
* Processes keys with the following headers:
|
||||
*
|
||||
* -----BEGIN DSA PRIVATE KEY-----
|
||||
* -----BEGIN DSA PUBLIC KEY-----
|
||||
* -----BEGIN DSA PARAMETERS-----
|
||||
*
|
||||
* Analogous to ssh-keygen's pem format (as specified by -m)
|
||||
*
|
||||
* Also, technically, PKCS1 decribes RSA but I am not aware of a formal specification for DSA.
|
||||
* The DSA private key format seems to have been adapted from the RSA private key format so
|
||||
* we're just re-using that as the name.
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS1 as Progenitor;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* PKCS#1 Formatted DSA Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class PKCS1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS1
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
$key = parent::load($key, $password);
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($key);
|
||||
if (!$decoded) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAParams::MAP);
|
||||
if (\is_array($key)) {
|
||||
return $key;
|
||||
}
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAPrivateKey::MAP);
|
||||
if (\is_array($key)) {
|
||||
return $key;
|
||||
}
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAPublicKey::MAP);
|
||||
if (\is_array($key)) {
|
||||
return $key;
|
||||
}
|
||||
throw new \RuntimeException('Unable to perform ASN1 mapping');
|
||||
}
|
||||
/**
|
||||
* Convert DSA parameters to the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @return string
|
||||
*/
|
||||
public static function saveParameters(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g)
|
||||
{
|
||||
$key = ['p' => $p, 'q' => $q, 'g' => $g];
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($key, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAParams::MAP);
|
||||
return "-----BEGIN DSA PARAMETERS-----\r\n" . \chunk_split(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($key), 64) . "-----END DSA PARAMETERS-----\r\n";
|
||||
}
|
||||
/**
|
||||
* Convert a private key to the appropriate format.
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @param \phpseclib3\Math\BigInteger $x
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePrivateKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $x, $password = '', array $options = [])
|
||||
{
|
||||
$key = ['version' => 0, 'p' => $p, 'q' => $q, 'g' => $g, 'y' => $y, 'x' => $x];
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($key, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAPrivateKey::MAP);
|
||||
return self::wrapPrivateKey($key, 'DSA', $password, $options);
|
||||
}
|
||||
/**
|
||||
* Convert a public key to the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y)
|
||||
{
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($y, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAPublicKey::MAP);
|
||||
return self::wrapPublicKey($key, 'DSA');
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PKCS#8 Formatted DSA Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Processes keys with the following headers:
|
||||
*
|
||||
* -----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
* -----BEGIN PRIVATE KEY-----
|
||||
* -----BEGIN PUBLIC KEY-----
|
||||
*
|
||||
* Analogous to ssh-keygen's pkcs8 format (as specified by -m). Although PKCS8
|
||||
* is specific to private keys it's basically creating a DER-encoded wrapper
|
||||
* for keys. This just extends that same concept to public keys (much like ssh-keygen)
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS8 as Progenitor;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* PKCS#8 Formatted DSA Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class PKCS8 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PKCS8
|
||||
{
|
||||
/**
|
||||
* OID Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OID_NAME = 'id-dsa';
|
||||
/**
|
||||
* OID Value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OID_VALUE = '1.2.840.10040.4.1';
|
||||
/**
|
||||
* Child OIDs loaded
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $childOIDsLoaded = \false;
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
$key = parent::load($key, $password);
|
||||
$type = isset($key['privateKey']) ? 'privateKey' : 'publicKey';
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($key[$type . 'Algorithm']['parameters']->element);
|
||||
if (!$decoded) {
|
||||
throw new \RuntimeException('Unable to decode BER of parameters');
|
||||
}
|
||||
$components = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAParams::MAP);
|
||||
if (!\is_array($components)) {
|
||||
throw new \RuntimeException('Unable to perform ASN1 mapping on parameters');
|
||||
}
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($key[$type]);
|
||||
if (empty($decoded)) {
|
||||
throw new \RuntimeException('Unable to decode BER');
|
||||
}
|
||||
$var = $type == 'privateKey' ? 'x' : 'y';
|
||||
$components[$var] = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAPublicKey::MAP);
|
||||
if (!$components[$var] instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger) {
|
||||
throw new \RuntimeException('Unable to perform ASN1 mapping');
|
||||
}
|
||||
if (isset($key['meta'])) {
|
||||
$components['meta'] = $key['meta'];
|
||||
}
|
||||
return $components;
|
||||
}
|
||||
/**
|
||||
* Convert a private key to the appropriate format.
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @param \phpseclib3\Math\BigInteger $x
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePrivateKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $x, $password = '', array $options = [])
|
||||
{
|
||||
$params = ['p' => $p, 'q' => $q, 'g' => $g];
|
||||
$params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($params, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAParams::MAP);
|
||||
$params = new \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element($params);
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($x, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAPublicKey::MAP);
|
||||
return self::wrapPrivateKey($key, [], $params, $password, null, '', $options);
|
||||
}
|
||||
/**
|
||||
* Convert a public key to the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y, array $options = [])
|
||||
{
|
||||
$params = ['p' => $p, 'q' => $q, 'g' => $g];
|
||||
$params = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($params, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAParams::MAP);
|
||||
$params = new \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Element($params);
|
||||
$key = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER($y, \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DSAPublicKey::MAP);
|
||||
return self::wrapPublicKey($key, $params);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PuTTY Formatted DSA Key Handler
|
||||
*
|
||||
* puttygen does not generate DSA keys with an N of anything other than 160, however,
|
||||
* it can still load them and convert them. PuTTY will load them, too, but SSH servers
|
||||
* won't accept them. Since PuTTY formatted keys are primarily used with SSH this makes
|
||||
* keys with N > 160 kinda useless, hence this handlers not supporting such keys.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PuTTY as Progenitor;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* PuTTY Formatted DSA Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class PuTTY extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Keys\PuTTY
|
||||
{
|
||||
/**
|
||||
* Public Handler
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PUBLIC_HANDLER = 'WPMailSMTP\\Vendor\\phpseclib3\\Crypt\\DSA\\Formats\\Keys\\OpenSSH';
|
||||
/**
|
||||
* Algorithm Identifier
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $types = ['ssh-dss'];
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
$components = parent::load($key, $password);
|
||||
if (!isset($components['private'])) {
|
||||
return $components;
|
||||
}
|
||||
\extract($components);
|
||||
unset($components['public'], $components['private']);
|
||||
list($p, $q, $g, $y) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('iiii', $public);
|
||||
list($x) = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('i', $private);
|
||||
return \compact('p', 'q', 'g', 'y', 'x', 'comment');
|
||||
}
|
||||
/**
|
||||
* Convert a private key to the appropriate format.
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @param \phpseclib3\Math\BigInteger $x
|
||||
* @param string $password optional
|
||||
* @param array $options optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePrivateKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $x, $password = \false, array $options = [])
|
||||
{
|
||||
if ($q->getLength() != 160) {
|
||||
throw new \InvalidArgumentException('SSH only supports keys with an N (length of Group Order q) of 160');
|
||||
}
|
||||
$public = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('iiii', $p, $q, $g, $y);
|
||||
$private = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('i', $x);
|
||||
return self::wrapPrivateKey($public, $private, 'ssh-dss', $password, $options);
|
||||
}
|
||||
/**
|
||||
* Convert a public key to the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y)
|
||||
{
|
||||
if ($q->getLength() != 160) {
|
||||
throw new \InvalidArgumentException('SSH only supports keys with an N (length of Group Order q) of 160');
|
||||
}
|
||||
return self::wrapPublicKey(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('iiii', $p, $q, $g, $y), 'ssh-dss');
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Raw DSA Key Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Reads and creates arrays as DSA keys
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* Raw DSA Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class Raw
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param array $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!\is_array($key)) {
|
||||
throw new \UnexpectedValueException('Key should be a array - not a ' . \gettype($key));
|
||||
}
|
||||
switch (\true) {
|
||||
case !isset($key['p']) || !isset($key['q']) || !isset($key['g']):
|
||||
case !$key['p'] instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger:
|
||||
case !$key['q'] instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger:
|
||||
case !$key['g'] instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger:
|
||||
case !isset($key['x']) && !isset($key['y']):
|
||||
case isset($key['x']) && !$key['x'] instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger:
|
||||
case isset($key['y']) && !$key['y'] instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger:
|
||||
throw new \UnexpectedValueException('Key appears to be malformed');
|
||||
}
|
||||
$options = ['p' => 1, 'q' => 1, 'g' => 1, 'x' => 1, 'y' => 1];
|
||||
return \array_intersect_key($key, $options);
|
||||
}
|
||||
/**
|
||||
* Convert a private key to the appropriate format.
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @param \phpseclib3\Math\BigInteger $x
|
||||
* @param string $password optional
|
||||
* @return string
|
||||
*/
|
||||
public static function savePrivateKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $x, $password = '')
|
||||
{
|
||||
return \compact('p', 'q', 'g', 'y', 'x');
|
||||
}
|
||||
/**
|
||||
* Convert a public key to the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y)
|
||||
{
|
||||
return \compact('p', 'q', 'g', 'y');
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* XML Formatted DSA Key Handler
|
||||
*
|
||||
* While XKMS defines a private key format for RSA it does not do so for DSA. Quoting that standard:
|
||||
*
|
||||
* "[XKMS] does not specify private key parameters for the DSA signature algorithm since the algorithm only
|
||||
* supports signature modes and so the application of server generated keys and key recovery is of limited
|
||||
* value"
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Keys;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Exception\BadConfigurationException;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* XML Formatted DSA Key Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class XML
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::is_stringable($key)) {
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . \gettype($key));
|
||||
}
|
||||
if (!\class_exists('DOMDocument')) {
|
||||
throw new \WPMailSMTP\Vendor\phpseclib3\Exception\BadConfigurationException('The dom extension is not setup correctly on this system');
|
||||
}
|
||||
$use_errors = \libxml_use_internal_errors(\true);
|
||||
$dom = new \DOMDocument();
|
||||
if (\substr($key, 0, 5) != '<?xml') {
|
||||
$key = '<xml>' . $key . '</xml>';
|
||||
}
|
||||
if (!$dom->loadXML($key)) {
|
||||
\libxml_use_internal_errors($use_errors);
|
||||
throw new \UnexpectedValueException('Key does not appear to contain XML');
|
||||
}
|
||||
$xpath = new \DOMXPath($dom);
|
||||
$keys = ['p', 'q', 'g', 'y', 'j', 'seed', 'pgencounter'];
|
||||
foreach ($keys as $key) {
|
||||
// $dom->getElementsByTagName($key) is case-sensitive
|
||||
$temp = $xpath->query("//*[translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='{$key}']");
|
||||
if (!$temp->length) {
|
||||
continue;
|
||||
}
|
||||
$value = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_decode($temp->item(0)->nodeValue), 256);
|
||||
switch ($key) {
|
||||
case 'p':
|
||||
// a prime modulus meeting the [DSS] requirements
|
||||
// Parameters P, Q, and G can be public and common to a group of users. They might be known
|
||||
// from application context. As such, they are optional but P and Q must either both appear
|
||||
// or both be absent
|
||||
$components['p'] = $value;
|
||||
break;
|
||||
case 'q':
|
||||
// an integer in the range 2**159 < Q < 2**160 which is a prime divisor of P-1
|
||||
$components['q'] = $value;
|
||||
break;
|
||||
case 'g':
|
||||
// an integer with certain properties with respect to P and Q
|
||||
$components['g'] = $value;
|
||||
break;
|
||||
case 'y':
|
||||
// G**X mod P (where X is part of the private key and not made public)
|
||||
$components['y'] = $value;
|
||||
// the remaining options do not do anything
|
||||
case 'j':
|
||||
// (P - 1) / Q
|
||||
// Parameter J is available for inclusion solely for efficiency as it is calculatable from
|
||||
// P and Q
|
||||
case 'seed':
|
||||
// a DSA prime generation seed
|
||||
// Parameters seed and pgenCounter are used in the DSA prime number generation algorithm
|
||||
// specified in [DSS]. As such, they are optional but must either both be present or both
|
||||
// be absent
|
||||
case 'pgencounter':
|
||||
}
|
||||
}
|
||||
\libxml_use_internal_errors($use_errors);
|
||||
if (!isset($components['y'])) {
|
||||
throw new \UnexpectedValueException('Key is missing y component');
|
||||
}
|
||||
switch (\true) {
|
||||
case !isset($components['p']):
|
||||
case !isset($components['q']):
|
||||
case !isset($components['g']):
|
||||
return ['y' => $components['y']];
|
||||
}
|
||||
return $components;
|
||||
}
|
||||
/**
|
||||
* Convert a public key to the appropriate format
|
||||
*
|
||||
* See https://www.w3.org/TR/xmldsig-core/#sec-DSAKeyValue
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $p
|
||||
* @param \phpseclib3\Math\BigInteger $q
|
||||
* @param \phpseclib3\Math\BigInteger $g
|
||||
* @param \phpseclib3\Math\BigInteger $y
|
||||
* @return string
|
||||
*/
|
||||
public static function savePublicKey(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $p, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $q, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $g, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y)
|
||||
{
|
||||
return "<DSAKeyValue>\r\n" . ' <P>' . \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($p->toBytes()) . "</P>\r\n" . ' <Q>' . \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($q->toBytes()) . "</Q>\r\n" . ' <G>' . \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($g->toBytes()) . "</G>\r\n" . ' <Y>' . \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::base64_encode($y->toBytes()) . "</Y>\r\n" . '</DSAKeyValue>';
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ASN1 Signature Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Handles signatures in the format described in
|
||||
* https://tools.ietf.org/html/rfc3279#section-2.2.2
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Signature;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1 as Encoder;
|
||||
use WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* ASN1 Signature Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class ASN1
|
||||
{
|
||||
/**
|
||||
* Loads a signature
|
||||
*
|
||||
* @param string $sig
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function load($sig)
|
||||
{
|
||||
if (!\is_string($sig)) {
|
||||
return \false;
|
||||
}
|
||||
$decoded = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::decodeBER($sig);
|
||||
if (empty($decoded)) {
|
||||
return \false;
|
||||
}
|
||||
$components = \WPMailSMTP\Vendor\phpseclib3\File\ASN1::asn1map($decoded[0], \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DssSigValue::MAP);
|
||||
return $components;
|
||||
}
|
||||
/**
|
||||
* Returns a signature in the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $r
|
||||
* @param \phpseclib3\Math\BigInteger $s
|
||||
* @return string
|
||||
*/
|
||||
public static function save(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $r, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $s)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\phpseclib3\File\ASN1::encodeDER(\compact('r', 's'), \WPMailSMTP\Vendor\phpseclib3\File\ASN1\Maps\DssSigValue::MAP);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Raw DSA Signature Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Signature;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Signature\Raw as Progenitor;
|
||||
/**
|
||||
* Raw DSA Signature Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class Raw extends \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\Formats\Signature\Raw
|
||||
{
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SSH2 Signature Handler
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* Handles signatures in the format used by SSH2
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Signature;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* SSH2 Signature Handler
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class SSH2
|
||||
{
|
||||
/**
|
||||
* Loads a signature
|
||||
*
|
||||
* @param string $sig
|
||||
* @return mixed
|
||||
*/
|
||||
public static function load($sig)
|
||||
{
|
||||
if (!\is_string($sig)) {
|
||||
return \false;
|
||||
}
|
||||
$result = \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::unpackSSH2('ss', $sig);
|
||||
if ($result === \false) {
|
||||
return \false;
|
||||
}
|
||||
list($type, $blob) = $result;
|
||||
if ($type != 'ssh-dss' || \strlen($blob) != 40) {
|
||||
return \false;
|
||||
}
|
||||
return ['r' => new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(\substr($blob, 0, 20), 256), 's' => new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(\substr($blob, 20), 256)];
|
||||
}
|
||||
/**
|
||||
* Returns a signature in the appropriate format
|
||||
*
|
||||
* @param \phpseclib3\Math\BigInteger $r
|
||||
* @param \phpseclib3\Math\BigInteger $s
|
||||
* @return string
|
||||
*/
|
||||
public static function save(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $r, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $s)
|
||||
{
|
||||
if ($r->getLength() > 160 || $s->getLength() > 160) {
|
||||
return \false;
|
||||
}
|
||||
return \WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::packSSH2('ss', 'ssh-dss', \str_pad($r->toBytes(), 20, "\0", \STR_PAD_LEFT) . \str_pad($s->toBytes(), 20, "\0", \STR_PAD_LEFT));
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DSA Parameters
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DSA;
|
||||
/**
|
||||
* DSA Parameters
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
final class Parameters extends \WPMailSMTP\Vendor\phpseclib3\Crypt\DSA
|
||||
{
|
||||
/**
|
||||
* 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->p, $this->q, $this->g, $options);
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DSA Private Key
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DSA;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Signature\ASN1 as ASN1Signature;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* DSA Private Key
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
final class PrivateKey extends \WPMailSMTP\Vendor\phpseclib3\Crypt\DSA implements \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PrivateKey
|
||||
{
|
||||
use Common\Traits\PasswordProtected;
|
||||
/**
|
||||
* DSA secret exponent x
|
||||
*
|
||||
* @var \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
protected $x;
|
||||
/**
|
||||
* Returns the public key
|
||||
*
|
||||
* If you do "openssl rsa -in private.rsa -pubout -outform PEM" you get a PKCS8 formatted key
|
||||
* that contains a publicKeyAlgorithm AlgorithmIdentifier and a publicKey BIT STRING.
|
||||
* An AlgorithmIdentifier contains an OID and a parameters field. With RSA public keys this
|
||||
* parameters field is NULL. With DSA PKCS8 public keys it is not - it contains the p, q and g
|
||||
* variables. The publicKey BIT STRING contains, simply, the y variable. This can be verified
|
||||
* by getting a DSA PKCS8 public key:
|
||||
*
|
||||
* "openssl dsa -in private.dsa -pubout -outform PEM"
|
||||
*
|
||||
* ie. just swap out rsa with dsa in the rsa command above.
|
||||
*
|
||||
* A PKCS1 public key corresponds to the publicKey portion of the PKCS8 key. In the case of RSA
|
||||
* the publicKey portion /is/ the key. In the case of DSA it is not. You cannot verify a signature
|
||||
* without the parameters and the PKCS1 DSA public key format does not include the parameters.
|
||||
*
|
||||
* @see self::getPrivateKey()
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPublicKey()
|
||||
{
|
||||
$type = self::validatePlugin('Keys', 'PKCS8', 'savePublicKey');
|
||||
if (!isset($this->y)) {
|
||||
$this->y = $this->g->powMod($this->x, $this->p);
|
||||
}
|
||||
$key = $type::savePublicKey($this->p, $this->q, $this->g, $this->y);
|
||||
return \WPMailSMTP\Vendor\phpseclib3\Crypt\DSA::loadFormat('PKCS8', $key)->withHash($this->hash->getHash())->withSignatureFormat($this->shortFormat);
|
||||
}
|
||||
/**
|
||||
* Create a signature
|
||||
*
|
||||
* @see self::verify()
|
||||
* @param string $message
|
||||
* @return mixed
|
||||
*/
|
||||
public function sign($message)
|
||||
{
|
||||
$format = $this->sigFormat;
|
||||
if (self::$engines['OpenSSL'] && \in_array($this->hash->getHash(), \openssl_get_md_methods())) {
|
||||
$signature = '';
|
||||
$result = \openssl_sign($message, $signature, $this->toString('PKCS8'), $this->hash->getHash());
|
||||
if ($result) {
|
||||
if ($this->shortFormat == 'ASN1') {
|
||||
return $signature;
|
||||
}
|
||||
\extract(\WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Signature\ASN1::load($signature));
|
||||
return $format::save($r, $s);
|
||||
}
|
||||
}
|
||||
$h = $this->hash->hash($message);
|
||||
$h = $this->bits2int($h);
|
||||
while (\true) {
|
||||
$k = \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger::randomRange(self::$one, $this->q->subtract(self::$one));
|
||||
$r = $this->g->powMod($k, $this->p);
|
||||
list(, $r) = $r->divide($this->q);
|
||||
if ($r->equals(self::$zero)) {
|
||||
continue;
|
||||
}
|
||||
$kinv = $k->modInverse($this->q);
|
||||
$temp = $h->add($this->x->multiply($r));
|
||||
$temp = $kinv->multiply($temp);
|
||||
list(, $s) = $temp->divide($this->q);
|
||||
if (!$s->equals(self::$zero)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// the following is an RFC6979 compliant implementation of deterministic DSA
|
||||
// it's unused because it's mainly intended for use when a good CSPRNG isn't
|
||||
// available. if phpseclib's CSPRNG isn't good then even key generation is
|
||||
// suspect
|
||||
/*
|
||||
$h1 = $this->hash->hash($message);
|
||||
$k = $this->computek($h1);
|
||||
$r = $this->g->powMod($k, $this->p);
|
||||
list(, $r) = $r->divide($this->q);
|
||||
$kinv = $k->modInverse($this->q);
|
||||
$h1 = $this->bits2int($h1);
|
||||
$temp = $h1->add($this->x->multiply($r));
|
||||
$temp = $kinv->multiply($temp);
|
||||
list(, $s) = $temp->divide($this->q);
|
||||
*/
|
||||
return $format::save($r, $s);
|
||||
}
|
||||
/**
|
||||
* 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->y)) {
|
||||
$this->y = $this->g->powMod($this->x, $this->p);
|
||||
}
|
||||
return $type::savePrivateKey($this->p, $this->q, $this->g, $this->y, $this->x, $this->password, $options);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DSA Public Key
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\DSA;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Common;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DSA;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Signature\ASN1 as ASN1Signature;
|
||||
/**
|
||||
* DSA Public Key
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
final class PublicKey extends \WPMailSMTP\Vendor\phpseclib3\Crypt\DSA implements \WPMailSMTP\Vendor\phpseclib3\Crypt\Common\PublicKey
|
||||
{
|
||||
use Common\Traits\Fingerprint;
|
||||
/**
|
||||
* Verify a signature
|
||||
*
|
||||
* @see self::verify()
|
||||
* @param string $message
|
||||
* @param string $signature
|
||||
* @return mixed
|
||||
*/
|
||||
public function verify($message, $signature)
|
||||
{
|
||||
$format = $this->sigFormat;
|
||||
$params = $format::load($signature);
|
||||
if ($params === \false || \count($params) != 2) {
|
||||
return \false;
|
||||
}
|
||||
\extract($params);
|
||||
if (self::$engines['OpenSSL'] && \in_array($this->hash->getHash(), \openssl_get_md_methods())) {
|
||||
$sig = $format != 'ASN1' ? \WPMailSMTP\Vendor\phpseclib3\Crypt\DSA\Formats\Signature\ASN1::save($r, $s) : $signature;
|
||||
$result = \openssl_verify($message, $sig, $this->toString('PKCS8'), $this->hash->getHash());
|
||||
if ($result != -1) {
|
||||
return (bool) $result;
|
||||
}
|
||||
}
|
||||
$q_1 = $this->q->subtract(self::$one);
|
||||
if (!$r->between(self::$one, $q_1) || !$s->between(self::$one, $q_1)) {
|
||||
return \false;
|
||||
}
|
||||
$w = $s->modInverse($this->q);
|
||||
$h = $this->hash->hash($message);
|
||||
$h = $this->bits2int($h);
|
||||
list(, $u1) = $h->multiply($w)->divide($this->q);
|
||||
list(, $u2) = $r->multiply($w)->divide($this->q);
|
||||
$v1 = $this->g->powMod($u1, $this->p);
|
||||
$v2 = $this->y->powMod($u2, $this->p);
|
||||
list(, $v) = $v1->multiply($v2)->divide($this->p);
|
||||
list(, $v) = $v->divide($this->q);
|
||||
return $v->equals($r);
|
||||
}
|
||||
/**
|
||||
* 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->p, $this->q, $this->g, $this->y, $options);
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Curve methods common to all curves
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
/**
|
||||
* Base
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class Base
|
||||
{
|
||||
/**
|
||||
* The Order
|
||||
*
|
||||
* @var BigInteger
|
||||
*/
|
||||
protected $order;
|
||||
/**
|
||||
* Finite Field Integer factory
|
||||
*
|
||||
* @var \phpseclib3\Math\FiniteField\Integer
|
||||
*/
|
||||
protected $factory;
|
||||
/**
|
||||
* Returns a random integer
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function randomInteger()
|
||||
{
|
||||
return $this->factory->randomInteger();
|
||||
}
|
||||
/**
|
||||
* Converts a BigInteger to a \phpseclib3\Math\FiniteField\Integer integer
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function convertInteger(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $x)
|
||||
{
|
||||
return $this->factory->newInteger($x);
|
||||
}
|
||||
/**
|
||||
* Returns the length, in bytes, of the modulo
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getLengthInBytes()
|
||||
{
|
||||
return $this->factory->getLengthInBytes();
|
||||
}
|
||||
/**
|
||||
* Returns the length, in bits, of the modulo
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
return $this->factory->getLength();
|
||||
}
|
||||
/**
|
||||
* 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, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $d)
|
||||
{
|
||||
$alreadyInternal = isset($p[2]);
|
||||
$r = $alreadyInternal ? [[], $p] : [[], $this->convertToInternal($p)];
|
||||
$d = $d->toBits();
|
||||
for ($i = 0; $i < \strlen($d); $i++) {
|
||||
$d_i = (int) $d[$i];
|
||||
$r[1 - $d_i] = $this->addPoint($r[0], $r[1]);
|
||||
$r[$d_i] = $this->doublePoint($r[$d_i]);
|
||||
}
|
||||
return $alreadyInternal ? $r[0] : $this->convertToAffine($r[0]);
|
||||
}
|
||||
/**
|
||||
* Creates a random scalar multiplier
|
||||
*
|
||||
* @return BigInteger
|
||||
*/
|
||||
public function createRandomMultiplier()
|
||||
{
|
||||
static $one;
|
||||
if (!isset($one)) {
|
||||
$one = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1);
|
||||
}
|
||||
return \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger::randomRange($one, $this->order->subtract($one));
|
||||
}
|
||||
/**
|
||||
* Performs range check
|
||||
*/
|
||||
public function rangeCheck(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $x)
|
||||
{
|
||||
static $zero;
|
||||
if (!isset($zero)) {
|
||||
$zero = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger();
|
||||
}
|
||||
if (!isset($this->order)) {
|
||||
throw new \RuntimeException('setOrder needs to be called before this method');
|
||||
}
|
||||
if ($x->compare($this->order) > 0 || $x->compare($zero) <= 0) {
|
||||
throw new \RangeException('x must be between 1 and the order of the curve');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sets the Order
|
||||
*/
|
||||
public function setOrder(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
/**
|
||||
* Returns the Order
|
||||
*
|
||||
* @return \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
/**
|
||||
* Use a custom defined modular reduction function
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function setReduction(callable $func)
|
||||
{
|
||||
$this->factory->setReduction($func);
|
||||
}
|
||||
/**
|
||||
* Returns the affine point
|
||||
*
|
||||
* @return object[]
|
||||
*/
|
||||
public function convertToAffine(array $p)
|
||||
{
|
||||
return $p;
|
||||
}
|
||||
/**
|
||||
* Converts an affine point to a jacobian coordinate
|
||||
*
|
||||
* @return object[]
|
||||
*/
|
||||
public function convertToInternal(array $p)
|
||||
{
|
||||
return $p;
|
||||
}
|
||||
/**
|
||||
* Negates a point
|
||||
*
|
||||
* @return object[]
|
||||
*/
|
||||
public function negatePoint(array $p)
|
||||
{
|
||||
$temp = [$p[0], $p[1]->negate()];
|
||||
if (isset($p[2])) {
|
||||
$temp[] = $p[2];
|
||||
}
|
||||
return $temp;
|
||||
}
|
||||
/**
|
||||
* Multiply and Add Points
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function multiplyAddPoints(array $points, array $scalars)
|
||||
{
|
||||
$p1 = $this->convertToInternal($points[0]);
|
||||
$p2 = $this->convertToInternal($points[1]);
|
||||
$p1 = $this->multiplyPoint($p1, $scalars[0]);
|
||||
$p2 = $this->multiplyPoint($p2, $scalars[1]);
|
||||
$r = $this->addPoint($p1, $p2);
|
||||
return $this->convertToAffine($r);
|
||||
}
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Curves over y^2 + x*y = x^3 + a*x^2 + b
|
||||
*
|
||||
* These are curves used in SEC 2 over prime fields: http://www.secg.org/SEC2-Ver-1.0.pdf
|
||||
* The curve is a weierstrass curve with a[3] and a[2] set to 0.
|
||||
*
|
||||
* Uses Jacobian Coordinates for speed if able:
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Jacobian_curve
|
||||
* https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BinaryField;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BinaryField\Integer as BinaryInteger;
|
||||
/**
|
||||
* Curves over y^2 + x*y = x^3 + a*x^2 + b
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class Binary extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Base
|
||||
{
|
||||
/**
|
||||
* Binary Field Integer factory
|
||||
*
|
||||
* @var \phpseclib3\Math\BinaryField
|
||||
*/
|
||||
protected $factory;
|
||||
/**
|
||||
* Cofficient for x^1
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $a;
|
||||
/**
|
||||
* Cofficient for x^0
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $b;
|
||||
/**
|
||||
* Base Point
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $p;
|
||||
/**
|
||||
* The number one over the specified finite field
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $one;
|
||||
/**
|
||||
* The modulo
|
||||
*
|
||||
* @var BigInteger
|
||||
*/
|
||||
protected $modulo;
|
||||
/**
|
||||
* The Order
|
||||
*
|
||||
* @var BigInteger
|
||||
*/
|
||||
protected $order;
|
||||
/**
|
||||
* Sets the modulo
|
||||
*/
|
||||
public function setModulo(...$modulo)
|
||||
{
|
||||
$this->modulo = $modulo;
|
||||
$this->factory = new \WPMailSMTP\Vendor\phpseclib3\Math\BinaryField(...$modulo);
|
||||
$this->one = $this->factory->newInteger("\1");
|
||||
}
|
||||
/**
|
||||
* Set coefficients a and b
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
*/
|
||||
public function setCoefficients($a, $b)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
$this->a = $this->factory->newInteger(\pack('H*', $a));
|
||||
$this->b = $this->factory->newInteger(\pack('H*', $b));
|
||||
}
|
||||
/**
|
||||
* Set x and y coordinates for the base point
|
||||
*
|
||||
* @param string|BinaryInteger $x
|
||||
* @param string|BinaryInteger $y
|
||||
*/
|
||||
public function setBasePoint($x, $y)
|
||||
{
|
||||
switch (\true) {
|
||||
case !\is_string($x) && !$x instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BinaryField\Integer:
|
||||
throw new \UnexpectedValueException('WPMailSMTP\\Vendor\\Argument 1 passed to Binary::setBasePoint() must be a string or an instance of BinaryField\\Integer');
|
||||
case !\is_string($y) && !$y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BinaryField\Integer:
|
||||
throw new \UnexpectedValueException('WPMailSMTP\\Vendor\\Argument 2 passed to Binary::setBasePoint() must be a string or an instance of BinaryField\\Integer');
|
||||
}
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
$this->p = [\is_string($x) ? $this->factory->newInteger(\pack('H*', $x)) : $x, \is_string($y) ? $this->factory->newInteger(\pack('H*', $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;
|
||||
}
|
||||
/**
|
||||
* Adds two points on the curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
public function addPoint(array $p, array $q)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
if (!\count($p) || !\count($q)) {
|
||||
if (\count($q)) {
|
||||
return $q;
|
||||
}
|
||||
if (\count($p)) {
|
||||
return $p;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
if (!isset($p[2]) || !isset($q[2])) {
|
||||
throw new \RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
|
||||
}
|
||||
if ($p[0]->equals($q[0])) {
|
||||
return !$p[1]->equals($q[1]) ? [] : $this->doublePoint($p);
|
||||
}
|
||||
// formulas from http://hyperelliptic.org/EFD/g12o/auto-shortw-jacobian.html
|
||||
list($x1, $y1, $z1) = $p;
|
||||
list($x2, $y2, $z2) = $q;
|
||||
$o1 = $z1->multiply($z1);
|
||||
$b = $x2->multiply($o1);
|
||||
if ($z2->equals($this->one)) {
|
||||
$d = $y2->multiply($o1)->multiply($z1);
|
||||
$e = $x1->add($b);
|
||||
$f = $y1->add($d);
|
||||
$z3 = $e->multiply($z1);
|
||||
$h = $f->multiply($x2)->add($z3->multiply($y2));
|
||||
$i = $f->add($z3);
|
||||
$g = $z3->multiply($z3);
|
||||
$p1 = $this->a->multiply($g);
|
||||
$p2 = $f->multiply($i);
|
||||
$p3 = $e->multiply($e)->multiply($e);
|
||||
$x3 = $p1->add($p2)->add($p3);
|
||||
$y3 = $i->multiply($x3)->add($g->multiply($h));
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
$o2 = $z2->multiply($z2);
|
||||
$a = $x1->multiply($o2);
|
||||
$c = $y1->multiply($o2)->multiply($z2);
|
||||
$d = $y2->multiply($o1)->multiply($z1);
|
||||
$e = $a->add($b);
|
||||
$f = $c->add($d);
|
||||
$g = $e->multiply($z1);
|
||||
$h = $f->multiply($x2)->add($g->multiply($y2));
|
||||
$z3 = $g->multiply($z2);
|
||||
$i = $f->add($z3);
|
||||
$p1 = $this->a->multiply($z3->multiply($z3));
|
||||
$p2 = $f->multiply($i);
|
||||
$p3 = $e->multiply($e)->multiply($e);
|
||||
$x3 = $p1->add($p2)->add($p3);
|
||||
$y3 = $i->multiply($x3)->add($g->multiply($g)->multiply($h));
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
/**
|
||||
* Doubles a point on a curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
public function doublePoint(array $p)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
if (!\count($p)) {
|
||||
return [];
|
||||
}
|
||||
if (!isset($p[2])) {
|
||||
throw new \RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
|
||||
}
|
||||
// formulas from http://hyperelliptic.org/EFD/g12o/auto-shortw-jacobian.html
|
||||
list($x1, $y1, $z1) = $p;
|
||||
$a = $x1->multiply($x1);
|
||||
$b = $a->multiply($a);
|
||||
if ($z1->equals($this->one)) {
|
||||
$x3 = $b->add($this->b);
|
||||
$z3 = clone $x1;
|
||||
$p1 = $a->add($y1)->add($z3)->multiply($this->b);
|
||||
$p2 = $a->add($y1)->multiply($b);
|
||||
$y3 = $p1->add($p2);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
$c = $z1->multiply($z1);
|
||||
$d = $c->multiply($c);
|
||||
$x3 = $b->add($this->b->multiply($d->multiply($d)));
|
||||
$z3 = $x1->multiply($c);
|
||||
$p1 = $b->multiply($z3);
|
||||
$p2 = $a->add($y1->multiply($z1))->add($z3)->multiply($x3);
|
||||
$y3 = $p1->add($p2);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
/**
|
||||
* Returns the X coordinate and the derived Y coordinate
|
||||
*
|
||||
* Not supported because it is covered by patents.
|
||||
* Quoting https://www.openssl.org/docs/man1.1.0/apps/ecparam.html ,
|
||||
*
|
||||
* "Due to patent issues the compressed option is disabled by default for binary curves
|
||||
* and can be enabled by defining the preprocessor macro OPENSSL_EC_BIN_PT_COMP at
|
||||
* compile time."
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function derivePoint($m)
|
||||
{
|
||||
throw new \RuntimeException('Point compression on binary finite field elliptic curves is not supported');
|
||||
}
|
||||
/**
|
||||
* Tests whether or not the x / y values satisfy the equation
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function verifyPoint(array $p)
|
||||
{
|
||||
list($x, $y) = $p;
|
||||
$lhs = $y->multiply($y);
|
||||
$lhs = $lhs->add($x->multiply($y));
|
||||
$x2 = $x->multiply($x);
|
||||
$x3 = $x2->multiply($x);
|
||||
$rhs = $x3->add($this->a->multiply($x2))->add($this->b);
|
||||
return $lhs->equals($rhs);
|
||||
}
|
||||
/**
|
||||
* Returns the modulo
|
||||
*
|
||||
* @return \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
public function getModulo()
|
||||
{
|
||||
return $this->modulo;
|
||||
}
|
||||
/**
|
||||
* Returns the a coefficient
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer
|
||||
*/
|
||||
public function getA()
|
||||
{
|
||||
return $this->a;
|
||||
}
|
||||
/**
|
||||
* Returns the a coefficient
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer
|
||||
*/
|
||||
public function getB()
|
||||
{
|
||||
return $this->b;
|
||||
}
|
||||
/**
|
||||
* Returns the affine point
|
||||
*
|
||||
* A Jacobian Coordinate is of the form (x, y, z).
|
||||
* To convert a Jacobian Coordinate to an Affine Point
|
||||
* you do (x / z^2, y / z^3)
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToAffine(array $p)
|
||||
{
|
||||
if (!isset($p[2])) {
|
||||
return $p;
|
||||
}
|
||||
list($x, $y, $z) = $p;
|
||||
$z = $this->one->divide($z);
|
||||
$z2 = $z->multiply($z);
|
||||
return [$x->multiply($z2), $y->multiply($z2)->multiply($z)];
|
||||
}
|
||||
/**
|
||||
* Converts an affine point to a jacobian coordinate
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToInternal(array $p)
|
||||
{
|
||||
if (isset($p[2])) {
|
||||
return $p;
|
||||
}
|
||||
$p[2] = clone $this->one;
|
||||
$p['fresh'] = \true;
|
||||
return $p;
|
||||
}
|
||||
}
|
||||
@@ -1,273 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Generalized Koblitz Curves over y^2 = x^3 + b.
|
||||
*
|
||||
* According to http://www.secg.org/SEC2-Ver-1.0.pdf Koblitz curves are over the GF(2**m)
|
||||
* finite field. Both the $a$ and $b$ coefficients are either 0 or 1. However, SEC2
|
||||
* generalizes the definition to include curves over GF(P) "which possess an efficiently
|
||||
* computable endomorphism".
|
||||
*
|
||||
* For these generalized Koblitz curves $b$ doesn't have to be 0 or 1. Whether or not $a$
|
||||
* has any restrictions on it is unclear, however, for all the GF(P) Koblitz curves defined
|
||||
* in SEC2 v1.0 $a$ is $0$ so all of the methods defined herein will assume that it is.
|
||||
*
|
||||
* I suppose we could rename the $b$ coefficient to $a$, however, the documentation refers
|
||||
* to $b$ so we'll just keep it.
|
||||
*
|
||||
* If a later version of SEC2 comes out wherein some $a$ values are non-zero we can create a
|
||||
* new method for those. eg. KoblitzA1Prime.php or something.
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\PrimeField;
|
||||
/**
|
||||
* Curves over y^2 = x^3 + b
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class KoblitzPrime extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
/**
|
||||
* Basis
|
||||
*
|
||||
* @var list<array{a: BigInteger, b: BigInteger}>
|
||||
*/
|
||||
protected $basis;
|
||||
/**
|
||||
* Beta
|
||||
*
|
||||
* @var PrimeField\Integer
|
||||
*/
|
||||
protected $beta;
|
||||
// don't overwrite setCoefficients() with one that only accepts one parameter so that
|
||||
// one might be able to switch between KoblitzPrime and Prime more easily (for benchmarking
|
||||
// purposes).
|
||||
/**
|
||||
* Multiply and Add Points
|
||||
*
|
||||
* Uses a efficiently computable endomorphism to achieve a slight speedup
|
||||
*
|
||||
* Adapted from:
|
||||
* https://github.com/indutny/elliptic/blob/725bd91/lib/elliptic/curve/short.js#L219
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function multiplyAddPoints(array $points, array $scalars)
|
||||
{
|
||||
static $zero, $one, $two;
|
||||
if (!isset($two)) {
|
||||
$two = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(2);
|
||||
$one = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1);
|
||||
}
|
||||
if (!isset($this->beta)) {
|
||||
// get roots
|
||||
$inv = $this->one->divide($this->two)->negate();
|
||||
$s = $this->three->negate()->squareRoot()->multiply($inv);
|
||||
$betas = [$inv->add($s), $inv->subtract($s)];
|
||||
$this->beta = $betas[0]->compare($betas[1]) < 0 ? $betas[0] : $betas[1];
|
||||
//echo strtoupper($this->beta->toHex(true)) . "\n"; exit;
|
||||
}
|
||||
if (!isset($this->basis)) {
|
||||
$factory = new \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField($this->order);
|
||||
$tempOne = $factory->newInteger($one);
|
||||
$tempTwo = $factory->newInteger($two);
|
||||
$tempThree = $factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(3));
|
||||
$inv = $tempOne->divide($tempTwo)->negate();
|
||||
$s = $tempThree->negate()->squareRoot()->multiply($inv);
|
||||
$lambdas = [$inv->add($s), $inv->subtract($s)];
|
||||
$lhs = $this->multiplyPoint($this->p, $lambdas[0])[0];
|
||||
$rhs = $this->p[0]->multiply($this->beta);
|
||||
$lambda = $lhs->equals($rhs) ? $lambdas[0] : $lambdas[1];
|
||||
$this->basis = static::extendedGCD($lambda->toBigInteger(), $this->order);
|
||||
///*
|
||||
foreach ($this->basis as $basis) {
|
||||
echo \strtoupper($basis['a']->toHex(\true)) . "\n";
|
||||
echo \strtoupper($basis['b']->toHex(\true)) . "\n\n";
|
||||
}
|
||||
exit;
|
||||
//*/
|
||||
}
|
||||
$npoints = $nscalars = [];
|
||||
for ($i = 0; $i < \count($points); $i++) {
|
||||
$p = $points[$i];
|
||||
$k = $scalars[$i]->toBigInteger();
|
||||
// begin split
|
||||
list($v1, $v2) = $this->basis;
|
||||
$c1 = $v2['b']->multiply($k);
|
||||
list($c1, $r) = $c1->divide($this->order);
|
||||
if ($this->order->compare($r->multiply($two)) <= 0) {
|
||||
$c1 = $c1->add($one);
|
||||
}
|
||||
$c2 = $v1['b']->negate()->multiply($k);
|
||||
list($c2, $r) = $c2->divide($this->order);
|
||||
if ($this->order->compare($r->multiply($two)) <= 0) {
|
||||
$c2 = $c2->add($one);
|
||||
}
|
||||
$p1 = $c1->multiply($v1['a']);
|
||||
$p2 = $c2->multiply($v2['a']);
|
||||
$q1 = $c1->multiply($v1['b']);
|
||||
$q2 = $c2->multiply($v2['b']);
|
||||
$k1 = $k->subtract($p1)->subtract($p2);
|
||||
$k2 = $q1->add($q2)->negate();
|
||||
// end split
|
||||
$beta = [$p[0]->multiply($this->beta), $p[1], clone $this->one];
|
||||
if (isset($p['naf'])) {
|
||||
$beta['naf'] = \array_map(function ($p) {
|
||||
return [$p[0]->multiply($this->beta), $p[1], clone $this->one];
|
||||
}, $p['naf']);
|
||||
$beta['nafwidth'] = $p['nafwidth'];
|
||||
}
|
||||
if ($k1->isNegative()) {
|
||||
$k1 = $k1->negate();
|
||||
$p = $this->negatePoint($p);
|
||||
}
|
||||
if ($k2->isNegative()) {
|
||||
$k2 = $k2->negate();
|
||||
$beta = $this->negatePoint($beta);
|
||||
}
|
||||
$pos = 2 * $i;
|
||||
$npoints[$pos] = $p;
|
||||
$nscalars[$pos] = $this->factory->newInteger($k1);
|
||||
$pos++;
|
||||
$npoints[$pos] = $beta;
|
||||
$nscalars[$pos] = $this->factory->newInteger($k2);
|
||||
}
|
||||
return parent::multiplyAddPoints($npoints, $nscalars);
|
||||
}
|
||||
/**
|
||||
* Returns the numerator and denominator of the slope
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
protected function doublePointHelper(array $p)
|
||||
{
|
||||
$numerator = $this->three->multiply($p[0])->multiply($p[0]);
|
||||
$denominator = $this->two->multiply($p[1]);
|
||||
return [$numerator, $denominator];
|
||||
}
|
||||
/**
|
||||
* Doubles a jacobian coordinate on the curve
|
||||
*
|
||||
* See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
protected function jacobianDoublePoint(array $p)
|
||||
{
|
||||
list($x1, $y1, $z1) = $p;
|
||||
$a = $x1->multiply($x1);
|
||||
$b = $y1->multiply($y1);
|
||||
$c = $b->multiply($b);
|
||||
$d = $x1->add($b);
|
||||
$d = $d->multiply($d)->subtract($a)->subtract($c)->multiply($this->two);
|
||||
$e = $this->three->multiply($a);
|
||||
$f = $e->multiply($e);
|
||||
$x3 = $f->subtract($this->two->multiply($d));
|
||||
$y3 = $e->multiply($d->subtract($x3))->subtract($this->eight->multiply($c));
|
||||
$z3 = $this->two->multiply($y1)->multiply($z1);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
/**
|
||||
* Doubles a "fresh" jacobian coordinate on the curve
|
||||
*
|
||||
* See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-mdbl-2007-bl
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
protected function jacobianDoublePointMixed(array $p)
|
||||
{
|
||||
list($x1, $y1) = $p;
|
||||
$xx = $x1->multiply($x1);
|
||||
$yy = $y1->multiply($y1);
|
||||
$yyyy = $yy->multiply($yy);
|
||||
$s = $x1->add($yy);
|
||||
$s = $s->multiply($s)->subtract($xx)->subtract($yyyy)->multiply($this->two);
|
||||
$m = $this->three->multiply($xx);
|
||||
$t = $m->multiply($m)->subtract($this->two->multiply($s));
|
||||
$x3 = $t;
|
||||
$y3 = $s->subtract($t);
|
||||
$y3 = $m->multiply($y3)->subtract($this->eight->multiply($yyyy));
|
||||
$z3 = $this->two->multiply($y1);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
/**
|
||||
* Tests whether or not the x / y values satisfy the equation
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function verifyPoint(array $p)
|
||||
{
|
||||
list($x, $y) = $p;
|
||||
$lhs = $y->multiply($y);
|
||||
$temp = $x->multiply($x)->multiply($x);
|
||||
$rhs = $temp->add($this->b);
|
||||
return $lhs->equals($rhs);
|
||||
}
|
||||
/**
|
||||
* Calculates the parameters needed from the Euclidean algorithm as discussed at
|
||||
* http://diamond.boisestate.edu/~liljanab/MATH308/GuideToECC.pdf#page=148
|
||||
*
|
||||
* @param BigInteger $u
|
||||
* @param BigInteger $v
|
||||
* @return BigInteger[]
|
||||
*/
|
||||
protected static function extendedGCD(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $u, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $v)
|
||||
{
|
||||
$one = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1);
|
||||
$zero = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger();
|
||||
$a = clone $one;
|
||||
$b = clone $zero;
|
||||
$c = clone $zero;
|
||||
$d = clone $one;
|
||||
$stop = $v->bitwise_rightShift($v->getLength() >> 1);
|
||||
$a1 = clone $zero;
|
||||
$b1 = clone $zero;
|
||||
$a2 = clone $zero;
|
||||
$b2 = clone $zero;
|
||||
$postGreatestIndex = 0;
|
||||
while (!$v->equals($zero)) {
|
||||
list($q) = $u->divide($v);
|
||||
$temp = $u;
|
||||
$u = $v;
|
||||
$v = $temp->subtract($v->multiply($q));
|
||||
$temp = $a;
|
||||
$a = $c;
|
||||
$c = $temp->subtract($a->multiply($q));
|
||||
$temp = $b;
|
||||
$b = $d;
|
||||
$d = $temp->subtract($b->multiply($q));
|
||||
if ($v->compare($stop) > 0) {
|
||||
$a0 = $v;
|
||||
$b0 = $c;
|
||||
} else {
|
||||
$postGreatestIndex++;
|
||||
}
|
||||
if ($postGreatestIndex == 1) {
|
||||
$a1 = $v;
|
||||
$b1 = $c->negate();
|
||||
}
|
||||
if ($postGreatestIndex == 2) {
|
||||
$rhs = $a0->multiply($a0)->add($b0->multiply($b0));
|
||||
$lhs = $v->multiply($v)->add($b->multiply($b));
|
||||
if ($lhs->compare($rhs) <= 0) {
|
||||
$a2 = $a0;
|
||||
$b2 = $b0->negate();
|
||||
} else {
|
||||
$a2 = $v;
|
||||
$b2 = $c->negate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [['a' => $a1, 'b' => $b1], ['a' => $a2, 'b' => $b2]];
|
||||
}
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
<?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
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\Curve25519;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\PrimeField;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer as PrimeInteger;
|
||||
/**
|
||||
* Curves over y^2 = x^3 + a*x + x
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class Montgomery extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Base
|
||||
{
|
||||
/**
|
||||
* Prime Field Integer factory
|
||||
*
|
||||
* @var \phpseclib3\Math\PrimeField
|
||||
*/
|
||||
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(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $modulo)
|
||||
{
|
||||
$this->modulo = $modulo;
|
||||
$this->factory = new \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField($modulo);
|
||||
$this->zero = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger());
|
||||
$this->one = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1));
|
||||
}
|
||||
/**
|
||||
* Set coefficients a
|
||||
*/
|
||||
public function setCoefficients(\WPMailSMTP\Vendor\phpseclib3\Math\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 \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(2));
|
||||
$four = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\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 \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger && !$x instanceof \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer:
|
||||
throw new \UnexpectedValueException('WPMailSMTP\\Vendor\\Argument 1 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\\Integer');
|
||||
case !$y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger && !$y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer:
|
||||
throw new \UnexpectedValueException('WPMailSMTP\\Vendor\\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 \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger ? $this->factory->newInteger($x) : $x, $y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\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, \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer $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 == \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\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, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $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 \phpseclib3\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 \phpseclib3\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToAffine(array $p)
|
||||
{
|
||||
if (!isset($p[1])) {
|
||||
return $p;
|
||||
}
|
||||
list($x, $z) = $p;
|
||||
return [$x->divide($z)];
|
||||
}
|
||||
}
|
||||
@@ -1,695 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Curves over y^2 = x^3 + a*x + b
|
||||
*
|
||||
* These are curves used in SEC 2 over prime fields: http://www.secg.org/SEC2-Ver-1.0.pdf
|
||||
* The curve is a weierstrass curve with a[1], a[3] and a[2] set to 0.
|
||||
*
|
||||
* Uses Jacobian Coordinates for speed if able:
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Jacobian_curve
|
||||
* https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\Common\FiniteField\Integer;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\PrimeField;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer as PrimeInteger;
|
||||
/**
|
||||
* Curves over y^2 = x^3 + a*x + b
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class Prime extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Base
|
||||
{
|
||||
/**
|
||||
* Prime Field Integer factory
|
||||
*
|
||||
* @var \phpseclib3\Math\PrimeFields
|
||||
*/
|
||||
protected $factory;
|
||||
/**
|
||||
* Cofficient for x^1
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $a;
|
||||
/**
|
||||
* Cofficient for x^0
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $b;
|
||||
/**
|
||||
* Base Point
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $p;
|
||||
/**
|
||||
* The number one over the specified finite field
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $one;
|
||||
/**
|
||||
* The number two over the specified finite field
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $two;
|
||||
/**
|
||||
* The number three over the specified finite field
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $three;
|
||||
/**
|
||||
* The number four over the specified finite field
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $four;
|
||||
/**
|
||||
* The number eight over the specified finite field
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $eight;
|
||||
/**
|
||||
* The modulo
|
||||
*
|
||||
* @var BigInteger
|
||||
*/
|
||||
protected $modulo;
|
||||
/**
|
||||
* The Order
|
||||
*
|
||||
* @var BigInteger
|
||||
*/
|
||||
protected $order;
|
||||
/**
|
||||
* Sets the modulo
|
||||
*/
|
||||
public function setModulo(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $modulo)
|
||||
{
|
||||
$this->modulo = $modulo;
|
||||
$this->factory = new \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField($modulo);
|
||||
$this->two = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(2));
|
||||
$this->three = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(3));
|
||||
// used by jacobian coordinates
|
||||
$this->one = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1));
|
||||
$this->four = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(4));
|
||||
$this->eight = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(8));
|
||||
}
|
||||
/**
|
||||
* Set coefficients a and b
|
||||
*/
|
||||
public function setCoefficients(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $a, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $b)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
$this->a = $this->factory->newInteger($a);
|
||||
$this->b = $this->factory->newInteger($b);
|
||||
}
|
||||
/**
|
||||
* 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 \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger && !$x instanceof \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer:
|
||||
throw new \UnexpectedValueException('WPMailSMTP\\Vendor\\Argument 1 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\\Integer');
|
||||
case !$y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger && !$y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer:
|
||||
throw new \UnexpectedValueException('WPMailSMTP\\Vendor\\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 \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger ? $this->factory->newInteger($x) : $x, $y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\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;
|
||||
}
|
||||
/**
|
||||
* Adds two "fresh" jacobian form on the curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
protected function jacobianAddPointMixedXY(array $p, array $q)
|
||||
{
|
||||
list($u1, $s1) = $p;
|
||||
list($u2, $s2) = $q;
|
||||
if ($u1->equals($u2)) {
|
||||
if (!$s1->equals($s2)) {
|
||||
return [];
|
||||
} else {
|
||||
return $this->doublePoint($p);
|
||||
}
|
||||
}
|
||||
$h = $u2->subtract($u1);
|
||||
$r = $s2->subtract($s1);
|
||||
$h2 = $h->multiply($h);
|
||||
$h3 = $h2->multiply($h);
|
||||
$v = $u1->multiply($h2);
|
||||
$x3 = $r->multiply($r)->subtract($h3)->subtract($v->multiply($this->two));
|
||||
$y3 = $r->multiply($v->subtract($x3))->subtract($s1->multiply($h3));
|
||||
return [$x3, $y3, $h];
|
||||
}
|
||||
/**
|
||||
* Adds one "fresh" jacobian form on the curve
|
||||
*
|
||||
* The second parameter should be the "fresh" one
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
protected function jacobianAddPointMixedX(array $p, array $q)
|
||||
{
|
||||
list($u1, $s1, $z1) = $p;
|
||||
list($x2, $y2) = $q;
|
||||
$z12 = $z1->multiply($z1);
|
||||
$u2 = $x2->multiply($z12);
|
||||
$s2 = $y2->multiply($z12->multiply($z1));
|
||||
if ($u1->equals($u2)) {
|
||||
if (!$s1->equals($s2)) {
|
||||
return [];
|
||||
} else {
|
||||
return $this->doublePoint($p);
|
||||
}
|
||||
}
|
||||
$h = $u2->subtract($u1);
|
||||
$r = $s2->subtract($s1);
|
||||
$h2 = $h->multiply($h);
|
||||
$h3 = $h2->multiply($h);
|
||||
$v = $u1->multiply($h2);
|
||||
$x3 = $r->multiply($r)->subtract($h3)->subtract($v->multiply($this->two));
|
||||
$y3 = $r->multiply($v->subtract($x3))->subtract($s1->multiply($h3));
|
||||
$z3 = $h->multiply($z1);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
/**
|
||||
* Adds two jacobian coordinates on the curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
protected function jacobianAddPoint(array $p, array $q)
|
||||
{
|
||||
list($x1, $y1, $z1) = $p;
|
||||
list($x2, $y2, $z2) = $q;
|
||||
$z12 = $z1->multiply($z1);
|
||||
$z22 = $z2->multiply($z2);
|
||||
$u1 = $x1->multiply($z22);
|
||||
$u2 = $x2->multiply($z12);
|
||||
$s1 = $y1->multiply($z22->multiply($z2));
|
||||
$s2 = $y2->multiply($z12->multiply($z1));
|
||||
if ($u1->equals($u2)) {
|
||||
if (!$s1->equals($s2)) {
|
||||
return [];
|
||||
} else {
|
||||
return $this->doublePoint($p);
|
||||
}
|
||||
}
|
||||
$h = $u2->subtract($u1);
|
||||
$r = $s2->subtract($s1);
|
||||
$h2 = $h->multiply($h);
|
||||
$h3 = $h2->multiply($h);
|
||||
$v = $u1->multiply($h2);
|
||||
$x3 = $r->multiply($r)->subtract($h3)->subtract($v->multiply($this->two));
|
||||
$y3 = $r->multiply($v->subtract($x3))->subtract($s1->multiply($h3));
|
||||
$z3 = $h->multiply($z1)->multiply($z2);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
/**
|
||||
* Adds two points on the curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
public function addPoint(array $p, array $q)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
if (!\count($p) || !\count($q)) {
|
||||
if (\count($q)) {
|
||||
return $q;
|
||||
}
|
||||
if (\count($p)) {
|
||||
return $p;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
// use jacobian coordinates
|
||||
if (isset($p[2]) && isset($q[2])) {
|
||||
if (isset($p['fresh']) && isset($q['fresh'])) {
|
||||
return $this->jacobianAddPointMixedXY($p, $q);
|
||||
}
|
||||
if (isset($p['fresh'])) {
|
||||
return $this->jacobianAddPointMixedX($q, $p);
|
||||
}
|
||||
if (isset($q['fresh'])) {
|
||||
return $this->jacobianAddPointMixedX($p, $q);
|
||||
}
|
||||
return $this->jacobianAddPoint($p, $q);
|
||||
}
|
||||
if (isset($p[2]) || isset($q[2])) {
|
||||
throw new \RuntimeException('Affine coordinates need to be manually converted to Jacobi coordinates or vice versa');
|
||||
}
|
||||
if ($p[0]->equals($q[0])) {
|
||||
if (!$p[1]->equals($q[1])) {
|
||||
return [];
|
||||
} else {
|
||||
// eg. doublePoint
|
||||
list($numerator, $denominator) = $this->doublePointHelper($p);
|
||||
}
|
||||
} else {
|
||||
$numerator = $q[1]->subtract($p[1]);
|
||||
$denominator = $q[0]->subtract($p[0]);
|
||||
}
|
||||
$slope = $numerator->divide($denominator);
|
||||
$x = $slope->multiply($slope)->subtract($p[0])->subtract($q[0]);
|
||||
$y = $slope->multiply($p[0]->subtract($x))->subtract($p[1]);
|
||||
return [$x, $y];
|
||||
}
|
||||
/**
|
||||
* Returns the numerator and denominator of the slope
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
protected function doublePointHelper(array $p)
|
||||
{
|
||||
$numerator = $this->three->multiply($p[0])->multiply($p[0])->add($this->a);
|
||||
$denominator = $this->two->multiply($p[1]);
|
||||
return [$numerator, $denominator];
|
||||
}
|
||||
/**
|
||||
* Doubles a jacobian coordinate on the curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
protected function jacobianDoublePoint(array $p)
|
||||
{
|
||||
list($x, $y, $z) = $p;
|
||||
$x2 = $x->multiply($x);
|
||||
$y2 = $y->multiply($y);
|
||||
$z2 = $z->multiply($z);
|
||||
$s = $this->four->multiply($x)->multiply($y2);
|
||||
$m1 = $this->three->multiply($x2);
|
||||
$m2 = $this->a->multiply($z2->multiply($z2));
|
||||
$m = $m1->add($m2);
|
||||
$x1 = $m->multiply($m)->subtract($this->two->multiply($s));
|
||||
$y1 = $m->multiply($s->subtract($x1))->subtract($this->eight->multiply($y2->multiply($y2)));
|
||||
$z1 = $this->two->multiply($y)->multiply($z);
|
||||
return [$x1, $y1, $z1];
|
||||
}
|
||||
/**
|
||||
* Doubles a "fresh" jacobian coordinate on the curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
protected function jacobianDoublePointMixed(array $p)
|
||||
{
|
||||
list($x, $y) = $p;
|
||||
$x2 = $x->multiply($x);
|
||||
$y2 = $y->multiply($y);
|
||||
$s = $this->four->multiply($x)->multiply($y2);
|
||||
$m1 = $this->three->multiply($x2);
|
||||
$m = $m1->add($this->a);
|
||||
$x1 = $m->multiply($m)->subtract($this->two->multiply($s));
|
||||
$y1 = $m->multiply($s->subtract($x1))->subtract($this->eight->multiply($y2->multiply($y2)));
|
||||
$z1 = $this->two->multiply($y);
|
||||
return [$x1, $y1, $z1];
|
||||
}
|
||||
/**
|
||||
* Doubles a point on a curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
public function doublePoint(array $p)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
if (!\count($p)) {
|
||||
return [];
|
||||
}
|
||||
// use jacobian coordinates
|
||||
if (isset($p[2])) {
|
||||
if (isset($p['fresh'])) {
|
||||
return $this->jacobianDoublePointMixed($p);
|
||||
}
|
||||
return $this->jacobianDoublePoint($p);
|
||||
}
|
||||
list($numerator, $denominator) = $this->doublePointHelper($p);
|
||||
$slope = $numerator->divide($denominator);
|
||||
$x = $slope->multiply($slope)->subtract($p[0])->subtract($p[0]);
|
||||
$y = $slope->multiply($p[0]->subtract($x))->subtract($p[1]);
|
||||
return [$x, $y];
|
||||
}
|
||||
/**
|
||||
* Returns the X coordinate and the derived Y coordinate
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function derivePoint($m)
|
||||
{
|
||||
$y = \ord(\WPMailSMTP\Vendor\phpseclib3\Common\Functions\Strings::shift($m));
|
||||
$x = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger($m, 256);
|
||||
$xp = $this->convertInteger($x);
|
||||
switch ($y) {
|
||||
case 2:
|
||||
$ypn = \false;
|
||||
break;
|
||||
case 3:
|
||||
$ypn = \true;
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException('Coordinate not in recognized format');
|
||||
}
|
||||
$temp = $xp->multiply($this->a);
|
||||
$temp = $xp->multiply($xp)->multiply($xp)->add($temp);
|
||||
$temp = $temp->add($this->b);
|
||||
$b = $temp->squareRoot();
|
||||
if (!$b) {
|
||||
throw new \RuntimeException('Unable to derive Y coordinate');
|
||||
}
|
||||
$bn = $b->isOdd();
|
||||
$yp = $ypn == $bn ? $b : $b->negate();
|
||||
return [$xp, $yp];
|
||||
}
|
||||
/**
|
||||
* Tests whether or not the x / y values satisfy the equation
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function verifyPoint(array $p)
|
||||
{
|
||||
list($x, $y) = $p;
|
||||
$lhs = $y->multiply($y);
|
||||
$temp = $x->multiply($this->a);
|
||||
$temp = $x->multiply($x)->multiply($x)->add($temp);
|
||||
$rhs = $temp->add($this->b);
|
||||
return $lhs->equals($rhs);
|
||||
}
|
||||
/**
|
||||
* Returns the modulo
|
||||
*
|
||||
* @return \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
public function getModulo()
|
||||
{
|
||||
return $this->modulo;
|
||||
}
|
||||
/**
|
||||
* Returns the a coefficient
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer
|
||||
*/
|
||||
public function getA()
|
||||
{
|
||||
return $this->a;
|
||||
}
|
||||
/**
|
||||
* Returns the a coefficient
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer
|
||||
*/
|
||||
public function getB()
|
||||
{
|
||||
return $this->b;
|
||||
}
|
||||
/**
|
||||
* Multiply and Add Points
|
||||
*
|
||||
* Adapted from:
|
||||
* https://github.com/indutny/elliptic/blob/725bd91/lib/elliptic/curve/base.js#L125
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function multiplyAddPoints(array $points, array $scalars)
|
||||
{
|
||||
$length = \count($points);
|
||||
foreach ($points as &$point) {
|
||||
$point = $this->convertToInternal($point);
|
||||
}
|
||||
$wnd = [$this->getNAFPoints($points[0], 7)];
|
||||
$wndWidth = [isset($points[0]['nafwidth']) ? $points[0]['nafwidth'] : 7];
|
||||
for ($i = 1; $i < $length; $i++) {
|
||||
$wnd[] = $this->getNAFPoints($points[$i], 1);
|
||||
$wndWidth[] = isset($points[$i]['nafwidth']) ? $points[$i]['nafwidth'] : 1;
|
||||
}
|
||||
$naf = [];
|
||||
// comb all window NAFs
|
||||
$max = 0;
|
||||
for ($i = $length - 1; $i >= 1; $i -= 2) {
|
||||
$a = $i - 1;
|
||||
$b = $i;
|
||||
if ($wndWidth[$a] != 1 || $wndWidth[$b] != 1) {
|
||||
$naf[$a] = $scalars[$a]->getNAF($wndWidth[$a]);
|
||||
$naf[$b] = $scalars[$b]->getNAF($wndWidth[$b]);
|
||||
$max = \max(\count($naf[$a]), \count($naf[$b]), $max);
|
||||
continue;
|
||||
}
|
||||
$comb = [
|
||||
$points[$a],
|
||||
// 1
|
||||
null,
|
||||
// 3
|
||||
null,
|
||||
// 5
|
||||
$points[$b],
|
||||
];
|
||||
$comb[1] = $this->addPoint($points[$a], $points[$b]);
|
||||
$comb[2] = $this->addPoint($points[$a], $this->negatePoint($points[$b]));
|
||||
$index = [
|
||||
-3,
|
||||
/* -1 -1 */
|
||||
-1,
|
||||
/* -1 0 */
|
||||
-5,
|
||||
/* -1 1 */
|
||||
-7,
|
||||
/* 0 -1 */
|
||||
0,
|
||||
/* 0 -1 */
|
||||
7,
|
||||
/* 0 1 */
|
||||
5,
|
||||
/* 1 -1 */
|
||||
1,
|
||||
/* 1 0 */
|
||||
3,
|
||||
];
|
||||
$jsf = self::getJSFPoints($scalars[$a], $scalars[$b]);
|
||||
$max = \max(\count($jsf[0]), $max);
|
||||
if ($max > 0) {
|
||||
$naf[$a] = \array_fill(0, $max, 0);
|
||||
$naf[$b] = \array_fill(0, $max, 0);
|
||||
} else {
|
||||
$naf[$a] = [];
|
||||
$naf[$b] = [];
|
||||
}
|
||||
for ($j = 0; $j < $max; $j++) {
|
||||
$ja = isset($jsf[0][$j]) ? $jsf[0][$j] : 0;
|
||||
$jb = isset($jsf[1][$j]) ? $jsf[1][$j] : 0;
|
||||
$naf[$a][$j] = $index[3 * ($ja + 1) + $jb + 1];
|
||||
$naf[$b][$j] = 0;
|
||||
$wnd[$a] = $comb;
|
||||
}
|
||||
}
|
||||
$acc = [];
|
||||
$temp = [0, 0, 0, 0];
|
||||
for ($i = $max; $i >= 0; $i--) {
|
||||
$k = 0;
|
||||
while ($i >= 0) {
|
||||
$zero = \true;
|
||||
for ($j = 0; $j < $length; $j++) {
|
||||
$temp[$j] = isset($naf[$j][$i]) ? $naf[$j][$i] : 0;
|
||||
if ($temp[$j] != 0) {
|
||||
$zero = \false;
|
||||
}
|
||||
}
|
||||
if (!$zero) {
|
||||
break;
|
||||
}
|
||||
$k++;
|
||||
$i--;
|
||||
}
|
||||
if ($i >= 0) {
|
||||
$k++;
|
||||
}
|
||||
while ($k--) {
|
||||
$acc = $this->doublePoint($acc);
|
||||
}
|
||||
if ($i < 0) {
|
||||
break;
|
||||
}
|
||||
for ($j = 0; $j < $length; $j++) {
|
||||
$z = $temp[$j];
|
||||
$p = null;
|
||||
if ($z == 0) {
|
||||
continue;
|
||||
}
|
||||
$p = $z > 0 ? $wnd[$j][$z - 1 >> 1] : $this->negatePoint($wnd[$j][-$z - 1 >> 1]);
|
||||
$acc = $this->addPoint($acc, $p);
|
||||
}
|
||||
}
|
||||
return $this->convertToAffine($acc);
|
||||
}
|
||||
/**
|
||||
* Precomputes NAF points
|
||||
*
|
||||
* Adapted from:
|
||||
* https://github.com/indutny/elliptic/blob/725bd91/lib/elliptic/curve/base.js#L351
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function getNAFPoints(array $point, $wnd)
|
||||
{
|
||||
if (isset($point['naf'])) {
|
||||
return $point['naf'];
|
||||
}
|
||||
$res = [$point];
|
||||
$max = (1 << $wnd) - 1;
|
||||
$dbl = $max == 1 ? null : $this->doublePoint($point);
|
||||
for ($i = 1; $i < $max; $i++) {
|
||||
$res[] = $this->addPoint($res[$i - 1], $dbl);
|
||||
}
|
||||
$point['naf'] = $res;
|
||||
/*
|
||||
$str = '';
|
||||
foreach ($res as $re) {
|
||||
$re[0] = bin2hex($re[0]->toBytes());
|
||||
$re[1] = bin2hex($re[1]->toBytes());
|
||||
$str.= " ['$re[0]', '$re[1]'],\r\n";
|
||||
}
|
||||
file_put_contents('temp.txt', $str);
|
||||
exit;
|
||||
*/
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* Precomputes points in Joint Sparse Form
|
||||
*
|
||||
* Adapted from:
|
||||
* https://github.com/indutny/elliptic/blob/725bd91/lib/elliptic/utils.js#L96
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private static function getJSFPoints(\WPMailSMTP\Vendor\phpseclib3\Math\Common\FiniteField\Integer $k1, \WPMailSMTP\Vendor\phpseclib3\Math\Common\FiniteField\Integer $k2)
|
||||
{
|
||||
static $three;
|
||||
if (!isset($three)) {
|
||||
$three = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(3);
|
||||
}
|
||||
$jsf = [[], []];
|
||||
$k1 = $k1->toBigInteger();
|
||||
$k2 = $k2->toBigInteger();
|
||||
$d1 = 0;
|
||||
$d2 = 0;
|
||||
while ($k1->compare(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(-$d1)) > 0 || $k2->compare(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(-$d2)) > 0) {
|
||||
// first phase
|
||||
$m14 = $k1->testBit(0) + 2 * $k1->testBit(1);
|
||||
$m14 += $d1;
|
||||
$m14 &= 3;
|
||||
$m24 = $k2->testBit(0) + 2 * $k2->testBit(1);
|
||||
$m24 += $d2;
|
||||
$m24 &= 3;
|
||||
if ($m14 == 3) {
|
||||
$m14 = -1;
|
||||
}
|
||||
if ($m24 == 3) {
|
||||
$m24 = -1;
|
||||
}
|
||||
$u1 = 0;
|
||||
if ($m14 & 1) {
|
||||
// if $m14 is odd
|
||||
$m8 = $k1->testBit(0) + 2 * $k1->testBit(1) + 4 * $k1->testBit(2);
|
||||
$m8 += $d1;
|
||||
$m8 &= 7;
|
||||
$u1 = ($m8 == 3 || $m8 == 5) && $m24 == 2 ? -$m14 : $m14;
|
||||
}
|
||||
$jsf[0][] = $u1;
|
||||
$u2 = 0;
|
||||
if ($m24 & 1) {
|
||||
// if $m24 is odd
|
||||
$m8 = $k2->testBit(0) + 2 * $k2->testBit(1) + 4 * $k2->testBit(2);
|
||||
$m8 += $d2;
|
||||
$m8 &= 7;
|
||||
$u2 = ($m8 == 3 || $m8 == 5) && $m14 == 2 ? -$m24 : $m24;
|
||||
}
|
||||
$jsf[1][] = $u2;
|
||||
// second phase
|
||||
if (2 * $d1 == $u1 + 1) {
|
||||
$d1 = 1 - $d1;
|
||||
}
|
||||
if (2 * $d2 == $u2 + 1) {
|
||||
$d2 = 1 - $d2;
|
||||
}
|
||||
$k1 = $k1->bitwise_rightShift(1);
|
||||
$k2 = $k2->bitwise_rightShift(1);
|
||||
}
|
||||
return $jsf;
|
||||
}
|
||||
/**
|
||||
* Returns the affine point
|
||||
*
|
||||
* A Jacobian Coordinate is of the form (x, y, z).
|
||||
* To convert a Jacobian Coordinate to an Affine Point
|
||||
* you do (x / z^2, y / z^3)
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToAffine(array $p)
|
||||
{
|
||||
if (!isset($p[2])) {
|
||||
return $p;
|
||||
}
|
||||
list($x, $y, $z) = $p;
|
||||
$z = $this->one->divide($z);
|
||||
$z2 = $z->multiply($z);
|
||||
return [$x->multiply($z2), $y->multiply($z2)->multiply($z)];
|
||||
}
|
||||
/**
|
||||
* Converts an affine point to a jacobian coordinate
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToInternal(array $p)
|
||||
{
|
||||
if (isset($p[2])) {
|
||||
return $p;
|
||||
}
|
||||
$p[2] = clone $this->one;
|
||||
$p['fresh'] = \true;
|
||||
return $p;
|
||||
}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Curves over a*x^2 + y^2 = 1 + d*x^2*y^2
|
||||
*
|
||||
* http://www.secg.org/SEC2-Ver-1.0.pdf provides for curves with custom parameters.
|
||||
* ie. the coefficients can be arbitrary set through specially formatted keys, etc.
|
||||
* As such, Prime.php is built very generically and it's not able to take full
|
||||
* advantage of curves with 0 coefficients to produce simplified point doubling,
|
||||
* point addition. Twisted Edwards curves, in contrast, do not have a way, currently,
|
||||
* to customize them. As such, we can omit the super generic stuff from this class
|
||||
* and let the named curves (Ed25519 and Ed448) define their own custom tailored
|
||||
* point addition and point doubling methods.
|
||||
*
|
||||
* More info:
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Twisted_Edwards_curve
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\PrimeField;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer as PrimeInteger;
|
||||
/**
|
||||
* Curves over a*x^2 + y^2 = 1 + d*x^2*y^2
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class TwistedEdwards extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Base
|
||||
{
|
||||
/**
|
||||
* The modulo
|
||||
*
|
||||
* @var BigInteger
|
||||
*/
|
||||
protected $modulo;
|
||||
/**
|
||||
* Cofficient for x^2
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $a;
|
||||
/**
|
||||
* Cofficient for x^2*y^2
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $d;
|
||||
/**
|
||||
* Base Point
|
||||
*
|
||||
* @var object[]
|
||||
*/
|
||||
protected $p;
|
||||
/**
|
||||
* The number zero over the specified finite field
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $zero;
|
||||
/**
|
||||
* The number one over the specified finite field
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $one;
|
||||
/**
|
||||
* The number two over the specified finite field
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $two;
|
||||
/**
|
||||
* Sets the modulo
|
||||
*/
|
||||
public function setModulo(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $modulo)
|
||||
{
|
||||
$this->modulo = $modulo;
|
||||
$this->factory = new \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField($modulo);
|
||||
$this->zero = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(0));
|
||||
$this->one = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1));
|
||||
$this->two = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(2));
|
||||
}
|
||||
/**
|
||||
* Set coefficients a and b
|
||||
*/
|
||||
public function setCoefficients(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $a, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $d)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
$this->a = $this->factory->newInteger($a);
|
||||
$this->d = $this->factory->newInteger($d);
|
||||
}
|
||||
/**
|
||||
* Set x and y coordinates for the base point
|
||||
*/
|
||||
public function setBasePoint($x, $y)
|
||||
{
|
||||
switch (\true) {
|
||||
case !$x instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger && !$x instanceof \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer:
|
||||
throw new \UnexpectedValueException('WPMailSMTP\\Vendor\\Argument 1 passed to Prime::setBasePoint() must be an instance of either BigInteger or PrimeField\\Integer');
|
||||
case !$y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger && !$y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\PrimeField\Integer:
|
||||
throw new \UnexpectedValueException('WPMailSMTP\\Vendor\\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 \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger ? $this->factory->newInteger($x) : $x, $y instanceof \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger ? $this->factory->newInteger($y) : $y];
|
||||
}
|
||||
/**
|
||||
* Returns the a coefficient
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer
|
||||
*/
|
||||
public function getA()
|
||||
{
|
||||
return $this->a;
|
||||
}
|
||||
/**
|
||||
* Returns the a coefficient
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer
|
||||
*/
|
||||
public function getD()
|
||||
{
|
||||
return $this->d;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
/**
|
||||
* Returns the affine point
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToAffine(array $p)
|
||||
{
|
||||
if (!isset($p[2])) {
|
||||
return $p;
|
||||
}
|
||||
list($x, $y, $z) = $p;
|
||||
$z = $this->one->divide($z);
|
||||
return [$x->multiply($z), $y->multiply($z)];
|
||||
}
|
||||
/**
|
||||
* Returns the modulo
|
||||
*
|
||||
* @return \phpseclib3\Math\BigInteger
|
||||
*/
|
||||
public function getModulo()
|
||||
{
|
||||
return $this->modulo;
|
||||
}
|
||||
/**
|
||||
* Tests whether or not the x / y values satisfy the equation
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function verifyPoint(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);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Curve25519
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Montgomery;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class Curve25519 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Montgomery
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// 2^255 - 19
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED', 16));
|
||||
$this->a24 = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('121666'));
|
||||
$this->p = [$this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(9))];
|
||||
// 2^252 + 0x14def9dea2f79cd65812631a5cf5d3ed
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\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, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $d)
|
||||
{
|
||||
//$r = strrev(sodium_crypto_scalarmult($d->toBytes(), strrev($p[0]->toBytes())));
|
||||
//return [$this->factory->newInteger(new BigInteger($r, 256))];
|
||||
$d = $d->toBytes();
|
||||
$d &= "<EFBFBD>" . \str_repeat("<EFBFBD>", 30) . "";
|
||||
$d = \strrev($d);
|
||||
$d |= "@";
|
||||
$d = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger($d, -256);
|
||||
return parent::multiplyPoint($p, $d);
|
||||
}
|
||||
/**
|
||||
* Creates a random scalar multiplier
|
||||
*
|
||||
* @return BigInteger
|
||||
*/
|
||||
public function createRandomMultiplier()
|
||||
{
|
||||
return \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger::random(256);
|
||||
}
|
||||
/**
|
||||
* Performs range check
|
||||
*/
|
||||
public function rangeCheck(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $x)
|
||||
{
|
||||
if ($x->getLength() > 256 || $x->isNegative()) {
|
||||
throw new \RangeException('x must be a positive integer less than 256 bytes in length');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Curve448
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Montgomery;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class Curve448 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Montgomery
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// 2^448 - 2^224 - 1
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' . 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 16));
|
||||
$this->a24 = $this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('39081'));
|
||||
$this->p = [$this->factory->newInteger(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(5))];
|
||||
// 2^446 - 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\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, \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $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] & "<EFBFBD>";
|
||||
$d = \strrev($d);
|
||||
$d |= "<EFBFBD>";
|
||||
$d = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger($d, 256);
|
||||
return parent::multiplyPoint($p, $d);
|
||||
}
|
||||
/**
|
||||
* Creates a random scalar multiplier
|
||||
*
|
||||
* @return BigInteger
|
||||
*/
|
||||
public function createRandomMultiplier()
|
||||
{
|
||||
return \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger::random(446);
|
||||
}
|
||||
/**
|
||||
* Performs range check
|
||||
*/
|
||||
public function rangeCheck(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $x)
|
||||
{
|
||||
if ($x->getLength() > 448 || $x->isNegative()) {
|
||||
throw new \RangeException('x must be a positive integer less than 446 bytes in length');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,295 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Ed25519
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
namespace WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Hash;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Random;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class Ed25519 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards
|
||||
{
|
||||
const HASH = 'sha512';
|
||||
/*
|
||||
Per https://tools.ietf.org/html/rfc8032#page-6 EdDSA has several parameters, one of which is b:
|
||||
|
||||
2. An integer b with 2^(b-1) > p. EdDSA public keys have exactly b
|
||||
bits, and EdDSA signatures have exactly 2*b bits. b is
|
||||
recommended to be a multiple of 8, so public key and signature
|
||||
lengths are an integral number of octets.
|
||||
|
||||
SIZE corresponds to b
|
||||
*/
|
||||
const SIZE = 32;
|
||||
public function __construct()
|
||||
{
|
||||
// 2^255 - 19
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED', 16));
|
||||
$this->setCoefficients(
|
||||
// -1
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC', 16),
|
||||
// a
|
||||
// -121665/121666
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('52036CEE2B6FFE738CC740797779E89800700A4D4141D8AB75EB4DCA135978A3', 16)
|
||||
);
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('6666666666666666666666666666666666666666666666666666666666666658', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('1000000000000000000000000000000014DEF9DEA2F79CD65812631A5CF5D3ED', 16));
|
||||
// algorithm 14.47 from http://cacr.uwaterloo.ca/hac/about/chap14.pdf#page=16
|
||||
/*
|
||||
$this->setReduction(function($x) {
|
||||
$parts = $x->bitwise_split(255);
|
||||
$className = $this->className;
|
||||
|
||||
if (count($parts) > 2) {
|
||||
list(, $r) = $x->divide($className::$modulo);
|
||||
return $r;
|
||||
}
|
||||
|
||||
$zero = new BigInteger();
|
||||
$c = new BigInteger(19);
|
||||
|
||||
switch (count($parts)) {
|
||||
case 2:
|
||||
list($qi, $ri) = $parts;
|
||||
break;
|
||||
case 1:
|
||||
$qi = $zero;
|
||||
list($ri) = $parts;
|
||||
break;
|
||||
case 0:
|
||||
return $zero;
|
||||
}
|
||||
$r = $ri;
|
||||
|
||||
while ($qi->compare($zero) > 0) {
|
||||
$temp = $qi->multiply($c)->bitwise_split(255);
|
||||
if (count($temp) == 2) {
|
||||
list($qi, $ri) = $temp;
|
||||
} else {
|
||||
$qi = $zero;
|
||||
list($ri) = $temp;
|
||||
}
|
||||
$r = $r->add($ri);
|
||||
}
|
||||
|
||||
while ($r->compare($className::$modulo) > 0) {
|
||||
$r = $r->subtract($className::$modulo);
|
||||
}
|
||||
return $r;
|
||||
});
|
||||
*/
|
||||
}
|
||||
/**
|
||||
* Recover X from Y
|
||||
*
|
||||
* Implements steps 2-4 at https://tools.ietf.org/html/rfc8032#section-5.1.3
|
||||
*
|
||||
* Used by EC\Keys\Common.php
|
||||
*
|
||||
* @param BigInteger $y
|
||||
* @param boolean $sign
|
||||
* @return object[]
|
||||
*/
|
||||
public function recoverX(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y, $sign)
|
||||
{
|
||||
$y = $this->factory->newInteger($y);
|
||||
$y2 = $y->multiply($y);
|
||||
$u = $y2->subtract($this->one);
|
||||
$v = $this->d->multiply($y2)->add($this->one);
|
||||
$x2 = $u->divide($v);
|
||||
if ($x2->equals($this->zero)) {
|
||||
if ($sign) {
|
||||
throw new \RuntimeException('Unable to recover X coordinate (x2 = 0)');
|
||||
}
|
||||
return clone $this->zero;
|
||||
}
|
||||
// find the square root
|
||||
/* we don't do $x2->squareRoot() because, quoting from
|
||||
https://tools.ietf.org/html/rfc8032#section-5.1.1:
|
||||
|
||||
"For point decoding or "decompression", square roots modulo p are
|
||||
needed. They can be computed using the Tonelli-Shanks algorithm or
|
||||
the special case for p = 5 (mod 8). To find a square root of a,
|
||||
first compute the candidate root x = a^((p+3)/8) (mod p)."
|
||||
*/
|
||||
$exp = $this->getModulo()->add(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(3));
|
||||
$exp = $exp->bitwise_rightShift(3);
|
||||
$x = $x2->pow($exp);
|
||||
// If v x^2 = -u (mod p), set x <-- x * 2^((p-1)/4), which is a square root.
|
||||
if (!$x->multiply($x)->subtract($x2)->equals($this->zero)) {
|
||||
$temp = $this->getModulo()->subtract(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1));
|
||||
$temp = $temp->bitwise_rightShift(2);
|
||||
$temp = $this->two->pow($temp);
|
||||
$x = $x->multiply($temp);
|
||||
if (!$x->multiply($x)->subtract($x2)->equals($this->zero)) {
|
||||
throw new \RuntimeException('Unable to recover X coordinate');
|
||||
}
|
||||
}
|
||||
if ($x->isOdd() != $sign) {
|
||||
$x = $x->negate();
|
||||
}
|
||||
return [$x, $y];
|
||||
}
|
||||
/**
|
||||
* Extract Secret Scalar
|
||||
*
|
||||
* Implements steps 1-3 at https://tools.ietf.org/html/rfc8032#section-5.1.5
|
||||
*
|
||||
* Used by the various key handlers
|
||||
*
|
||||
* @param string $str
|
||||
* @return array
|
||||
*/
|
||||
public function extractSecret($str)
|
||||
{
|
||||
if (\strlen($str) != 32) {
|
||||
throw new \LengthException('Private Key should be 32-bytes long');
|
||||
}
|
||||
// 1. Hash the 32-byte private key using SHA-512, storing the digest in
|
||||
// a 64-octet large buffer, denoted h. Only the lower 32 bytes are
|
||||
// used for generating the public key.
|
||||
$hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('sha512');
|
||||
$h = $hash->hash($str);
|
||||
$h = \substr($h, 0, 32);
|
||||
// 2. Prune the buffer: The lowest three bits of the first octet are
|
||||
// cleared, the highest bit of the last octet is cleared, and the
|
||||
// second highest bit of the last octet is set.
|
||||
$h[0] = $h[0] & \chr(0xf8);
|
||||
$h = \strrev($h);
|
||||
$h[0] = $h[0] & \chr(0x3f) | \chr(0x40);
|
||||
// 3. Interpret the buffer as the little-endian integer, forming a
|
||||
// secret scalar s.
|
||||
$dA = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger($h, 256);
|
||||
return ['dA' => $dA, 'secret' => $str];
|
||||
}
|
||||
/**
|
||||
* Encode a point as a string
|
||||
*
|
||||
* @param array $point
|
||||
* @return string
|
||||
*/
|
||||
public function encodePoint($point)
|
||||
{
|
||||
list($x, $y) = $point;
|
||||
$y = $y->toBytes();
|
||||
$y[0] = $y[0] & \chr(0x7f);
|
||||
if ($x->isOdd()) {
|
||||
$y[0] = $y[0] | \chr(0x80);
|
||||
}
|
||||
$y = \strrev($y);
|
||||
return $y;
|
||||
}
|
||||
/**
|
||||
* Creates a random scalar multiplier
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer
|
||||
*/
|
||||
public function createRandomMultiplier()
|
||||
{
|
||||
return $this->extractSecret(\WPMailSMTP\Vendor\phpseclib3\Crypt\Random::string(32))['dA'];
|
||||
}
|
||||
/**
|
||||
* Converts an affine point to an extended homogeneous coordinate
|
||||
*
|
||||
* From https://tools.ietf.org/html/rfc8032#section-5.1.4 :
|
||||
*
|
||||
* A point (x,y) is represented in extended homogeneous coordinates (X, Y, Z, T),
|
||||
* with x = X/Z, y = Y/Z, x * y = T/Z.
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToInternal(array $p)
|
||||
{
|
||||
if (empty($p)) {
|
||||
return [clone $this->zero, clone $this->one, clone $this->one, clone $this->zero];
|
||||
}
|
||||
if (isset($p[2])) {
|
||||
return $p;
|
||||
}
|
||||
$p[2] = clone $this->one;
|
||||
$p[3] = $p[0]->multiply($p[1]);
|
||||
return $p;
|
||||
}
|
||||
/**
|
||||
* Doubles a point on a curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
public function doublePoint(array $p)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
if (!\count($p)) {
|
||||
return [];
|
||||
}
|
||||
if (!isset($p[2])) {
|
||||
throw new \RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
|
||||
}
|
||||
// from https://tools.ietf.org/html/rfc8032#page-12
|
||||
list($x1, $y1, $z1, $t1) = $p;
|
||||
$a = $x1->multiply($x1);
|
||||
$b = $y1->multiply($y1);
|
||||
$c = $this->two->multiply($z1)->multiply($z1);
|
||||
$h = $a->add($b);
|
||||
$temp = $x1->add($y1);
|
||||
$e = $h->subtract($temp->multiply($temp));
|
||||
$g = $a->subtract($b);
|
||||
$f = $c->add($g);
|
||||
$x3 = $e->multiply($f);
|
||||
$y3 = $g->multiply($h);
|
||||
$t3 = $e->multiply($h);
|
||||
$z3 = $f->multiply($g);
|
||||
return [$x3, $y3, $z3, $t3];
|
||||
}
|
||||
/**
|
||||
* Adds two points on the curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
public function addPoint(array $p, array $q)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
if (!\count($p) || !\count($q)) {
|
||||
if (\count($q)) {
|
||||
return $q;
|
||||
}
|
||||
if (\count($p)) {
|
||||
return $p;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
if (!isset($p[2]) || !isset($q[2])) {
|
||||
throw new \RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
|
||||
}
|
||||
if ($p[0]->equals($q[0])) {
|
||||
return !$p[1]->equals($q[1]) ? [] : $this->doublePoint($p);
|
||||
}
|
||||
// from https://tools.ietf.org/html/rfc8032#page-12
|
||||
list($x1, $y1, $z1, $t1) = $p;
|
||||
list($x2, $y2, $z2, $t2) = $q;
|
||||
$a = $y1->subtract($x1)->multiply($y2->subtract($x2));
|
||||
$b = $y1->add($x1)->multiply($y2->add($x2));
|
||||
$c = $t1->multiply($this->two)->multiply($this->d)->multiply($t2);
|
||||
$d = $z1->multiply($this->two)->multiply($z2);
|
||||
$e = $b->subtract($a);
|
||||
$f = $d->subtract($c);
|
||||
$g = $d->add($c);
|
||||
$h = $b->add($a);
|
||||
$x3 = $e->multiply($f);
|
||||
$y3 = $g->multiply($h);
|
||||
$t3 = $e->multiply($h);
|
||||
$z3 = $f->multiply($g);
|
||||
return [$x3, $y3, $z3, $t3];
|
||||
}
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Ed448
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2017 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
namespace WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Hash;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\Random;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class Ed448 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards
|
||||
{
|
||||
const HASH = 'shake256-912';
|
||||
const SIZE = 57;
|
||||
public function __construct()
|
||||
{
|
||||
// 2^448 - 2^224 - 1
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' . 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 16));
|
||||
$this->setCoefficients(
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1),
|
||||
// -39081
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' . 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6756', 16)
|
||||
);
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('4F1970C66BED0DED221D15A622BF36DA9E146570470F1767EA6DE324' . 'A3D3A46412AE1AF72AB66511433B80E18B00938E2626A82BC70CC05E', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('693F46716EB6BC248876203756C9C7624BEA73736CA3984087789C1E' . '05A0C2D73AD3FF1CE67C39C4FDBD132C4ED7C8AD9808795BF230FA14', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' . '7CCA23E9C44EDB49AED63690216CC2728DC58F552378C292AB5844F3', 16));
|
||||
}
|
||||
/**
|
||||
* Recover X from Y
|
||||
*
|
||||
* Implements steps 2-4 at https://tools.ietf.org/html/rfc8032#section-5.2.3
|
||||
*
|
||||
* Used by EC\Keys\Common.php
|
||||
*
|
||||
* @param BigInteger $y
|
||||
* @param boolean $sign
|
||||
* @return object[]
|
||||
*/
|
||||
public function recoverX(\WPMailSMTP\Vendor\phpseclib3\Math\BigInteger $y, $sign)
|
||||
{
|
||||
$y = $this->factory->newInteger($y);
|
||||
$y2 = $y->multiply($y);
|
||||
$u = $y2->subtract($this->one);
|
||||
$v = $this->d->multiply($y2)->subtract($this->one);
|
||||
$x2 = $u->divide($v);
|
||||
if ($x2->equals($this->zero)) {
|
||||
if ($sign) {
|
||||
throw new \RuntimeException('Unable to recover X coordinate (x2 = 0)');
|
||||
}
|
||||
return clone $this->zero;
|
||||
}
|
||||
// find the square root
|
||||
$exp = $this->getModulo()->add(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger(1));
|
||||
$exp = $exp->bitwise_rightShift(2);
|
||||
$x = $x2->pow($exp);
|
||||
if (!$x->multiply($x)->subtract($x2)->equals($this->zero)) {
|
||||
throw new \RuntimeException('Unable to recover X coordinate');
|
||||
}
|
||||
if ($x->isOdd() != $sign) {
|
||||
$x = $x->negate();
|
||||
}
|
||||
return [$x, $y];
|
||||
}
|
||||
/**
|
||||
* Extract Secret Scalar
|
||||
*
|
||||
* Implements steps 1-3 at https://tools.ietf.org/html/rfc8032#section-5.2.5
|
||||
*
|
||||
* Used by the various key handlers
|
||||
*
|
||||
* @param string $str
|
||||
* @return array
|
||||
*/
|
||||
public function extractSecret($str)
|
||||
{
|
||||
if (\strlen($str) != 57) {
|
||||
throw new \LengthException('Private Key should be 57-bytes long');
|
||||
}
|
||||
// 1. Hash the 57-byte private key using SHAKE256(x, 114), storing the
|
||||
// digest in a 114-octet large buffer, denoted h. Only the lower 57
|
||||
// bytes are used for generating the public key.
|
||||
$hash = new \WPMailSMTP\Vendor\phpseclib3\Crypt\Hash('shake256-912');
|
||||
$h = $hash->hash($str);
|
||||
$h = \substr($h, 0, 57);
|
||||
// 2. Prune the buffer: The two least significant bits of the first
|
||||
// octet are cleared, all eight bits the last octet are cleared, and
|
||||
// the highest bit of the second to last octet is set.
|
||||
$h[0] = $h[0] & \chr(0xfc);
|
||||
$h = \strrev($h);
|
||||
$h[0] = "\0";
|
||||
$h[1] = $h[1] | \chr(0x80);
|
||||
// 3. Interpret the buffer as the little-endian integer, forming a
|
||||
// secret scalar s.
|
||||
$dA = new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger($h, 256);
|
||||
return ['dA' => $dA, 'secret' => $str];
|
||||
$dA->secret = $str;
|
||||
return $dA;
|
||||
}
|
||||
/**
|
||||
* Encode a point as a string
|
||||
*
|
||||
* @param array $point
|
||||
* @return string
|
||||
*/
|
||||
public function encodePoint($point)
|
||||
{
|
||||
list($x, $y) = $point;
|
||||
$y = "\0" . $y->toBytes();
|
||||
if ($x->isOdd()) {
|
||||
$y[0] = $y[0] | \chr(0x80);
|
||||
}
|
||||
$y = \strrev($y);
|
||||
return $y;
|
||||
}
|
||||
/**
|
||||
* Creates a random scalar multiplier
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer
|
||||
*/
|
||||
public function createRandomMultiplier()
|
||||
{
|
||||
return $this->extractSecret(\WPMailSMTP\Vendor\phpseclib3\Crypt\Random::string(57))['dA'];
|
||||
}
|
||||
/**
|
||||
* Converts an affine point to an extended homogeneous coordinate
|
||||
*
|
||||
* From https://tools.ietf.org/html/rfc8032#section-5.2.4 :
|
||||
*
|
||||
* A point (x,y) is represented in extended homogeneous coordinates (X, Y, Z, T),
|
||||
* with x = X/Z, y = Y/Z, x * y = T/Z.
|
||||
*
|
||||
* @return \phpseclib3\Math\PrimeField\Integer[]
|
||||
*/
|
||||
public function convertToInternal(array $p)
|
||||
{
|
||||
if (empty($p)) {
|
||||
return [clone $this->zero, clone $this->one, clone $this->one];
|
||||
}
|
||||
if (isset($p[2])) {
|
||||
return $p;
|
||||
}
|
||||
$p[2] = clone $this->one;
|
||||
return $p;
|
||||
}
|
||||
/**
|
||||
* Doubles a point on a curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
public function doublePoint(array $p)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
if (!\count($p)) {
|
||||
return [];
|
||||
}
|
||||
if (!isset($p[2])) {
|
||||
throw new \RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
|
||||
}
|
||||
// from https://tools.ietf.org/html/rfc8032#page-18
|
||||
list($x1, $y1, $z1) = $p;
|
||||
$b = $x1->add($y1);
|
||||
$b = $b->multiply($b);
|
||||
$c = $x1->multiply($x1);
|
||||
$d = $y1->multiply($y1);
|
||||
$e = $c->add($d);
|
||||
$h = $z1->multiply($z1);
|
||||
$j = $e->subtract($this->two->multiply($h));
|
||||
$x3 = $b->subtract($e)->multiply($j);
|
||||
$y3 = $c->subtract($d)->multiply($e);
|
||||
$z3 = $e->multiply($j);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
/**
|
||||
* Adds two points on the curve
|
||||
*
|
||||
* @return FiniteField[]
|
||||
*/
|
||||
public function addPoint(array $p, array $q)
|
||||
{
|
||||
if (!isset($this->factory)) {
|
||||
throw new \RuntimeException('setModulo needs to be called before this method');
|
||||
}
|
||||
if (!\count($p) || !\count($q)) {
|
||||
if (\count($q)) {
|
||||
return $q;
|
||||
}
|
||||
if (\count($p)) {
|
||||
return $p;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
if (!isset($p[2]) || !isset($q[2])) {
|
||||
throw new \RuntimeException('Affine coordinates need to be manually converted to "Jacobi" coordinates or vice versa');
|
||||
}
|
||||
if ($p[0]->equals($q[0])) {
|
||||
return !$p[1]->equals($q[1]) ? [] : $this->doublePoint($p);
|
||||
}
|
||||
// from https://tools.ietf.org/html/rfc8032#page-17
|
||||
list($x1, $y1, $z1) = $p;
|
||||
list($x2, $y2, $z2) = $q;
|
||||
$a = $z1->multiply($z2);
|
||||
$b = $a->multiply($a);
|
||||
$c = $x1->multiply($x2);
|
||||
$d = $y1->multiply($y2);
|
||||
$e = $this->d->multiply($c)->multiply($d);
|
||||
$f = $b->subtract($e);
|
||||
$g = $b->add($e);
|
||||
$h = $x1->add($y1)->multiply($x2->add($y2));
|
||||
$x3 = $a->multiply($f)->multiply($h->subtract($c)->subtract($d));
|
||||
$y3 = $a->multiply($g)->multiply($d->subtract($c));
|
||||
$z3 = $f->multiply($g);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP160r1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP160r1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('E95E4A5F737059DC60DFC7AD95B3D8139515620F', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('340E7BE2A280EB74E2BE61BADA745D97E8F7C300', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('1E589A8595423412134FAA2DBDEC95C8D8675E58', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('BED5AF16EA3F6A4F62938C4631EB5AF7BDBCDBC3', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('1667CB477A1A8EC338F94741669C976316DA6321', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('E95E4A5F737059DC60DF5991D45029409E60FC09', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP160t1
|
||||
*
|
||||
* This curve is a twisted version of brainpoolP160r1 with A = -3. With brainpool,
|
||||
* the curves ending in r1 are the "regular" curves and the curves ending in "t1"
|
||||
* are the twisted version of the r1 curves. Per https://tools.ietf.org/html/rfc5639#page-7
|
||||
* you can convert a point on an r1 curve to a point on a t1 curve thusly:
|
||||
*
|
||||
* F(x,y) := (x*Z^2, y*Z^3)
|
||||
*
|
||||
* The advantage of A = -3 is that some of the point doubling and point addition can be
|
||||
* slightly optimized. See http://hyperelliptic.org/EFD/g1p/auto-shortw-projective-3.html
|
||||
* vs http://hyperelliptic.org/EFD/g1p/auto-shortw-projective.html for example.
|
||||
*
|
||||
* phpseclib does not currently take advantage of this optimization opportunity
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP160t1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('E95E4A5F737059DC60DFC7AD95B3D8139515620F', 16));
|
||||
$this->setCoefficients(
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('E95E4A5F737059DC60DFC7AD95B3D8139515620C', 16),
|
||||
// eg. -3
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7A556B6DAE535B7B51ED2C4D7DAA7A0B5C55F380', 16)
|
||||
);
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('B199B13B9B34EFC1397E64BAEB05ACC265FF2378', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('ADD6718B7C7C1961F0991B842443772152C9E0AD', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('E95E4A5F737059DC60DF5991D45029409E60FC09', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP192r1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP192r1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('6A91174076B1E0E19C39C031FE8685C1CAE040E5C69A28EF', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('469A28EF7C28CCA3DC721D044F4496BCCA7EF4146FBF25C9', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('C0A0647EAAB6A48753B033C56CB0F0900A2F5C4853375FD6', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('14B690866ABD5BB88B5F4828C1490002E6773FA2FA299B8F', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP192t1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP192t1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297', 16));
|
||||
$this->setCoefficients(
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86294', 16),
|
||||
// eg. -3
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('13D56FFAEC78681E68F9DEB43B35BEC2FB68542E27897B79', 16)
|
||||
);
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('3AE9E58C82F63C30282E1FE7BBF43FA72C446AF6F4618129', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('097E2C5667C2223A902AB5CA449D0084B7E5B3DE7CCC01C9', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP224r1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP224r1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('68A5E62CA9CE6C1C299803A6C1530B514E182AD8B0042A59CAD29F43', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('2580F63CCFE44138870713B1A92369E33E2135D266DBB372386C400B', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('0D9029AD2C7E5CF4340823B2A87DC68C9E4CE3174C1E6EFDEE12C07D', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('58AA56F772C0726F24C6B89E4ECDAC24354B9E99CAA3F6D3761402CD', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP224t1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP224t1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF', 16));
|
||||
$this->setCoefficients(
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FC', 16),
|
||||
// eg. -3
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('4B337D934104CD7BEF271BF60CED1ED20DA14C08B3BB64F18A60888D', 16)
|
||||
);
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('6AB1E344CE25FF3896424E7FFE14762ECB49F8928AC0C76029B4D580', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('0374E9F5143E568CD23F3F4D7C0D4B1E41C8CC0D1C6ABD5F1A46DB4C', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP256r1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP256r1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP256t1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP256t1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377', 16));
|
||||
$this->setCoefficients(
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5374', 16),
|
||||
// eg. -3
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('662C61C430D84EA4FE66A7733D0B76B7BF93EBC4AF2F49256AE58101FEE92B04', 16)
|
||||
);
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('A3E8EB3CC1CFE7B7732213B23A656149AFA142C47AAFBC2B79A191562E1305F4', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('2D996C823439C56D7F7B22E14644417E69BCB6DE39D027001DABE8F35B25C9BE', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP320r1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP320r1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F9' . '2B9EC7893EC28FCD412B1F1B32E27', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('3EE30B568FBAB0F883CCEBD46D3F3BB8A2A73513F5EB79DA66190EB085FFA9F4' . '92F375A97D860EB4', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('520883949DFDBC42D3AD198640688A6FE13F41349554B49ACC31DCCD88453981' . '6F5EB4AC8FB1F1A6', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('43BD7E9AFB53D8B85289BCC48EE5BFE6F20137D10A087EB6E7871E2A10A599C7' . '10AF8D0D39E20611', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('14FDD05545EC1CC8AB4093247F77275E0743FFED117182EAA9C77877AAAC6AC7' . 'D35245D1692E8EE1', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D4' . '82EC7EE8658E98691555B44C59311', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP320t1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP320t1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F9' . '2B9EC7893EC28FCD412B1F1B32E27', 16));
|
||||
$this->setCoefficients(
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28' . 'FCD412B1F1B32E24', 16),
|
||||
// eg. -3
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('A7F561E038EB1ED560B3D147DB782013064C19F27ED27C6780AAF77FB8A547CE' . 'B5B4FEF422340353', 16)
|
||||
);
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('925BE9FB01AFC6FB4D3E7D4990010F813408AB106C4F09CB7EE07868CC136FFF' . '3357F624A21BED52', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('63BA3A7A27483EBF6671DBEF7ABB30EBEE084E58A0B077AD42A5A0989D1EE71B' . '1B9BC0455FB0D2C3', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D4' . '82EC7EE8658E98691555B44C59311', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP384r1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP384r1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A7' . '1874700133107EC53', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7BC382C63D8C150C3C72080ACE05AFA0C2BEA28E4FB22787139165EFBA91F90F8AA5814A503' . 'AD4EB04A8C7DD22CE2826', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('4A8C7DD22CE28268B39B55416F0447C2FB77DE107DCD2A62E880EA53EEB62D57CB4390295DB' . 'C9943AB78696FA504C11', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('1D1C64F068CF45FFA2A63A81B7C13F6B8847A3E77EF14FE3DB7FCAFE0CBD10E8E826E03436D' . '646AAEF87B2E247D4AF1E', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('8ABE1D7520F9C2A45CB1EB8E95CFD55262B70B29FEEC5864E19C054FF99129280E464621779' . '1811142820341263C5315', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC31' . '03B883202E9046565', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP384t1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP384t1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A7' . '1874700133107EC53', 16));
|
||||
$this->setCoefficients(
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901' . 'D1A71874700133107EC50', 16),
|
||||
// eg. -3
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7F519EADA7BDA81BD826DBA647910F8C4B9346ED8CCDC64E4B1ABD11756DCE1D2074AA263B8' . '8805CED70355A33B471EE', 16)
|
||||
);
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('18DE98B02DB9A306F2AFCD7235F72A819B80AB12EBD653172476FECD462AABFFC4FF191B946' . 'A5F54D8D0AA2F418808CC', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('25AB056962D30651A114AFD2755AD336747F93475B7A1FCA3B88F2B6A208CCFE469408584DC' . '2B2912675BF5B9E582928', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC31' . '03B883202E9046565', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP512r1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP512r1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC' . '66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA82' . '53AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C' . '1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('81AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D0098EFF3B1F78E2D' . '0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F822', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F8111B2DCDE494A5' . 'F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA' . '92619418661197FAC10471DB1D381085DDADDB58796829CA90069', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* brainpoolP512t1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class brainpoolP512t1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC' . '66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3', 16));
|
||||
$this->setCoefficients(
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC' . '66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F0', 16),
|
||||
// eg. -3
|
||||
new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7CBBBCF9441CFAB76E1890E46884EAE321F70C0BCB4981527897504BEC3E36A62BCDFA23049' . '76540F6450085F2DAE145C22553B465763689180EA2571867423E', 16)
|
||||
);
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('640ECE5C12788717B9C1BA06CBC2A6FEBA85842458C56DDE9DB1758D39C0313D82BA51735CD' . 'B3EA499AA77A7D6943A64F7A3F25FE26F06B51BAA2696FA9035DA', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('5B534BD595F5AF0FA2C892376C84ACE1BB4E3019B71634C01131159CAE03CEE9D9932184BEE' . 'F216BD71DF2DADF86A627306ECFF96DBB8BACE198B61E00F8B332', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA' . '92619418661197FAC10471DB1D381085DDADDB58796829CA90069', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistb233
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistb233 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\sect233r1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistb409
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistb409 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\sect409r1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistk163
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistk163 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\sect163k1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistk233
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistk233 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\sect233k1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* sect283k1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistk283 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\sect283k1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistk409
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistk409 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\sect409k1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistp192
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp192 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\secp192r1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistp224
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp224 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\secp224r1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistp256
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp256 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\secp256r1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistp384
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp384 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\secp384r1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistp521
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp521 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\secp521r1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* nistt571
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistt571 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\sect571k1
|
||||
{
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* prime192v1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class prime192v1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\secp192r1
|
||||
{
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* prime192v2
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class prime192v2 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('CC22D6DFB95C6B25E49C0D6364A4E5980C393AA21668D953', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('EEA2BAE7E1497842F2DE7769CFE9C989C072AD696F48034A', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('6574D11D69B6EC7A672BB82A083DF2F2B0847DE970B2DE15', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('FFFFFFFFFFFFFFFFFFFFFFFE5FB1A724DC80418648D8DD31', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* prime192v3
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class prime192v3 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('22123DC2395A05CAA7423DAECCC94760A7D462256BD56916', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7D29778100C65A1DA1783716588DCE2B8B4AEE8E228F1896', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('38A90F22637337334B49DCB66A6DC8F9978ACA7648A943B0', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('FFFFFFFFFFFFFFFFFFFFFFFF7A62D031C83F4294F640EC13', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* prime239v1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class prime239v1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('6B016C3BDCF18941D0D654921475CA71A9DB2FB27D1D37796185C2942C0A', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('0FFA963CDCA8816CCC33B8642BEDF905C3D358573D3F27FBBD3B3CB9AAAF', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7DEBE8E4E90A5DAE6E4054CA530BA04654B36818CE226B39FCCB7B02F1AE', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF9E5E9A9F5D9071FBD1522688909D0B', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* prime239v2
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class prime239v2 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('617FAB6832576CBBFED50D99F0249C3FEE58B94BA0038C7AE84C8C832F2C', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('38AF09D98727705120C921BB5E9E26296A3CDCF2F35757A0EAFD87B830E7', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('5B0125E4DBEA0EC7206DA0FC01D9B081329FB555DE6EF460237DFF8BE4BA', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF800000CFA7E8594377D414C03821BC582063', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* prime239v3
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
use WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime;
|
||||
use WPMailSMTP\Vendor\phpseclib3\Math\BigInteger;
|
||||
class prime239v3 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\BaseCurves\Prime
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModulo(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF', 16));
|
||||
$this->setCoefficients(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('255705FA2A306654B1F4CB03D6A750A30C250102D4988717D9BA15AB6D3E', 16));
|
||||
$this->setBasePoint(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('6768AE8E18BB92CFCF005C949AA2C6D94853D0E660BBF854B1C9505FE95A', 16), new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('1607E6898F390C06BC1D552BAD226F3B6FCFE48B6E818499AF18E3ED6CF3', 16));
|
||||
$this->setOrder(new \WPMailSMTP\Vendor\phpseclib3\Math\BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF975DEB41B3A6057C3C432146526551', 16));
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* prime256v1
|
||||
*
|
||||
* PHP version 5 and 7
|
||||
*
|
||||
* @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 WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class prime256v1 extends \WPMailSMTP\Vendor\phpseclib3\Crypt\EC\Curves\secp256r1
|
||||
{
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user