Skip to content

Commit

Permalink
Drop PHP 7.0 support
Browse files Browse the repository at this point in the history
We need nullable types, but we cannot support them in both 7.0 and 8.4, so we're cutting 7.0 out.
  • Loading branch information
paragonie-security committed Apr 23, 2024
1 parent 897a8b5 commit 597d123
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 34 deletions.
41 changes: 39 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,49 @@ on:
pull_request:

jobs:
test:
test-php7:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-20.04', 'ubuntu-22.04']
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.1', '8.2', '8.3', '8.4']
php-versions: ['7.1', '7.2', '7.3', '7.4']
phpunit-versions: ['latest']
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: gmp
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist

- name: Run tests
run: make phpunit-full-ci

test-php8:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-20.04', 'ubuntu-22.04']
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
phpunit-versions: ['latest']
steps:
- name: Checkout
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,10 @@ This package is released under the MIT license.

### Requirements

* PHP 7.0+ or PHP 8.0+
* PHP 7.1+ or PHP 8.0+
* composer
* ext-gmp

Support for older PHP versions:
* v0.4.x: php ^5.6|<7.2
* v0.5.x: php ^7.0
* v1.0.x: php ^7.0|^8.0

### Installation

You can install this library via Composer :
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
],
"require": {
"php": "^7.0||^8.0",
"php": "^7.1||^8.0",
"ext-gmp": "*",
"genkgo/php-asn1": "^2.0"
},
Expand Down
2 changes: 2 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<directory suffix="Test.php">./tests/unit</directory>
</testsuite>
</testsuites>
<!--
<logging>
<log type="coverage-html" target="./tests/output/Coverage/"
charset="UTF-8" yui="true" highlight="true" />
Expand All @@ -25,4 +26,5 @@
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
-->
</phpunit>
2 changes: 2 additions & 0 deletions src/Math/ConstantTimeMath.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function binaryGcd(GMP $X, GMP $Y): array
$d = \gmp_init(1, 10);

do {
// Iterate over U
for ($bits = $this->trailingZeroes($u); $bits > 0; --$bits) {
$u = $this->rightShift($u, 1);
$swap = (~$this->lsb($a) & ~$this->lsb($b)) & 1;
Expand All @@ -133,6 +134,7 @@ public function binaryGcd(GMP $X, GMP $Y): array
$b = $this->rightShift($b, 1);
}

// Iterate over V
for ($bits = $this->trailingZeroes($v); $bits > 0; --$bits) {
$v = $this->rightShift($v, 1);
$swap = (~$this->lsb($c) & ~$this->lsb($d)) & 1;
Expand Down
6 changes: 3 additions & 3 deletions src/Math/MathAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
class MathAdapterFactory
{
/**
* @var GmpMathInterface
* @var >GmpMathInterface
*/
private static $forcedAdapter = null;

/**
* @param GmpMathInterface $adapter
* @param ?GmpMathInterface $adapter
*/
public static function forceAdapter(GmpMathInterface $adapter = null)
public static function forceAdapter(?GmpMathInterface $adapter = null)
{
self::$forcedAdapter = $adapter;
}
Expand Down
60 changes: 38 additions & 22 deletions src/Math/NumberTheory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @author Matyas Danter
*/

use GMP;
use Mdanter\Ecc\Exception\NumberTheoryException;
use Mdanter\Ecc\Exception\SquareRootException;

Expand All @@ -44,6 +45,21 @@ class NumberTheory
*/
private $adapter;

/**
* @var GMP|resource
*/
private $zero;

/**
* @var GMP|resource
*/
private $one;

/**
* @var GMP|resource
*/
private $two;

/**
* @param GmpMathInterface $adapter
*/
Expand All @@ -56,17 +72,17 @@ public function __construct(GmpMathInterface $adapter)
}

/**
* @param \GMP[] $poly
* @param \GMP[] $polymod
* @param \GMP $p
* @return \GMP[]
* @param GMP[] $poly
* @param GMP[] $polymod
* @param GMP $p
* @return GMP[]
*/
public function polynomialReduceMod(array $poly, array $polymod, \GMP $p): array
public function polynomialReduceMod(array $poly, array $polymod, GMP $p): array
{
$adapter = $this->adapter;

// Only enter if last value is set, implying count > 0
if ((($last = end($polymod)) instanceof \GMP) && $adapter->equals($last, $this->one)) {
if ((($last = end($polymod)) instanceof GMP) && $adapter->equals($last, $this->one)) {
$count_polymod = count($polymod);
while (count($poly) >= $count_polymod) {
if (!$adapter->equals(end($poly), $this->zero)) {
Expand Down Expand Up @@ -95,13 +111,13 @@ public function polynomialReduceMod(array $poly, array $polymod, \GMP $p): array
}

/**
* @param \GMP[] $m1
* @param \GMP[] $m2
* @param \GMP[] $polymod
* @param \GMP $p
* @return \GMP[]
* @param GMP[] $m1
* @param GMP[] $m2
* @param GMP[] $polymod
* @param GMP $p
* @return GMP[]
*/
public function polynomialMultiplyMod(array $m1, array $m2, array $polymod, \GMP $p): array
public function polynomialMultiplyMod(array $m1, array $m2, array $polymod, GMP $p): array
{
$prod = array();
$cm1 = count($m1);
Expand Down Expand Up @@ -131,13 +147,13 @@ public function polynomialMultiplyMod(array $m1, array $m2, array $polymod, \GMP
}

/**
* @param \GMP[] $base
* @param \GMP $exponent
* @param \GMP[] $polymod
* @param \GMP $p
* @return \GMP[]
* @param GMP[] $base
* @param GMP $exponent
* @param GMP[] $polymod
* @param GMP $p
* @return GMP[]
*/
public function polynomialPowMod(array $base, \GMP $exponent, array $polymod, \GMP $p): array
public function polynomialPowMod(array $base, GMP $exponent, array $polymod, GMP $p): array
{
$adapter = $this->adapter;

Expand Down Expand Up @@ -171,11 +187,11 @@ public function polynomialPowMod(array $base, \GMP $exponent, array $polymod, \G
}

/**
* @param \GMP $a
* @param \GMP $p
* @return \GMP
* @param GMP $a
* @param GMP $p
* @return GMP
*/
public function squareRootModP(\GMP $a, \GMP $p): \GMP
public function squareRootModP(GMP $a, GMP $p): GMP
{
$math = $this->adapter;
$four = gmp_init(4, 10);
Expand Down

0 comments on commit 597d123

Please sign in to comment.