PHP Elliptic Curve Cryptography library

dev-master 2020-07-25 11:43 UTC

This package is not auto-updated.

Last update: 2024-12-09 06:33:53 UTC


README

Build Status HHVM Status

Scrutinizer Code Quality Code Coverage

Latest Stable Version Total Downloads Latest Unstable Version License

Information

This library is a rewrite/update of Matyas Danter's ECC library. All credit goes to him.

For more information on Elliptic Curve Cryptography please read this fine article.

The library supports the following curves:

  • secp112r1
  • secp256k1
  • nistp192
  • nistp224
  • nistp256 / secg256r1
  • nistp384 / secg384r1
  • nistp521

The library exposes a class for random byte generation, for PHP7+ users is provided by random_bytes. PHP5.6 users will use the paragonie/random_bytes polyfill.

During ECDSA, a random value k is required. It is acceptable to use a true RNG to generate this value, but should the same k value ever be repeatedly used for a key, an attacker can recover that signing key. The HMAC random generator can derive a deterministic k value from the message hash and private key, voiding this concern.

The library uses a non-branching Montgomery ladder for scalar multiplication, as it's constant time and avoids secret dependant branches.

Compatibility notice:

A dependency used by this library in v0.4.x interacts with a newly reserved keyword in PHP 7.2. Therefore the library cannot be used on 7.2. For a PHP7.0+ branch, you should upgrade to v0.5.x

License

This package is released under the MIT license.

Requirements

  • PHP 5.6+
  • composer
  • ext-gmp

Installation

You can install this library via Composer :

composer require mdanter/ecc

Contribute

When sending in pull requests, please make sure to run the make command.

The default target runs all PHPUnit and PHPCS tests. All tests must validate for your contribution to be accepted.

It's also always a good idea to check the results of the Scrutinizer analysis for your pull requests.

Usage

Examples: