Download the PHP package starkbank/ecdsa without Composer
On this page you can find all versions of the php package starkbank/ecdsa. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download starkbank/ecdsa
More information about starkbank/ecdsa
Files in starkbank/ecdsa
Package ecdsa
Short Description fast openSSL-compatible implementation of the Elliptic Curve Digital Signature Algorithm (ECDSA)
License MIT
Homepage https://github.com/starkbank/ecdsa-php
Informations about the package ecdsa
A lightweight and fast pure PHP ECDSA
Overview
This is a pure PHP implementation of the Elliptic Curve Digital Signature Algorithm. It is compatible with OpenSSL and uses elegant math such as Jacobian Coordinates to speed up the ECDSA on pure PHP.
Security
starkbank-ecdsa includes the following security features:
- RFC 6979 deterministic nonces: Eliminates the catastrophic risk of nonce reuse that leaks private keys
- Low-S signature normalization: Prevents signature malleability (BIP-62)
- Public key on-curve validation: Blocks invalid-curve attacks during verification
- Montgomery ladder scalar multiplication: Constant-operation point multiplication to mitigate timing side channels
- Hash truncation: Correctly handles hash functions larger than the curve order (e.g. SHA-512 with secp256k1)
Installation
Composer
To install the package with Composer, run:
To use the bindings, use Composer's autoload:
External dependencies
The package makes use of the 'GNU Multiple Precision' (GMP) library. For installation details, see: https://www.php.net/manual/en/gmp.installation.php
Curves
We currently support secp256k1 and prime256v1 (P-256), but you can add more curves to the project. You just need to use the CurveFp::add() method.
Speed
We ran a test on a MAC Pro using PHP 8.5. The library was run 100 times and the averages displayed below were obtained:
| Library | sign | verify |
|---|---|---|
| starkbank-ecdsa | 0.3ms | 0.8ms |
Performance is driven by Jacobian coordinates, a branch-balanced Montgomery ladder for variable-base scalar multiplication, a precomputed affine table of powers-of-two multiples of the generator ([G, 2G, 4G, ..., 2^n*G]) combined with a width-2 NAF of the scalar to eliminate doublings during signing, a mixed affine+Jacobian addition fast path, curve-specific shortcuts in point doubling (A=0 for secp256k1, A=-3 for prime256v1), the secp256k1 GLV endomorphism to split 256-bit scalars into two ~128-bit halves for a 4-scalar simultaneous multi-exponentiation during verification, Shamir's trick with Joint Sparse Form as the fallback path for curves without an efficient endomorphism, and the extended Euclidean algorithm for modular inversion.
Sample Code
How to sign a json message for Stark Bank:
Simple use:
How to add more curves:
How to generate a compressed public key:
How to recover a compressed public key:
OpenSSL
This library is compatible with OpenSSL, so you can use it to generate keys:
Create a message.txt file and sign it:
It's time to verify:
You can also verify it on terminal:
NOTE: If you want to create a Digital Signature to use in the Stark Bank, you need to convert the binary signature to base64.
You can also verify it with this library:
Run all unit tests
Run benchmark
All versions of ecdsa with dependencies
ext-gmp Version *