paragonie/ecc
Pure-PHP elliptic curve cryptography (ECDSA/ECDH) with an OpenSSL 3+ fast path and hardened constant-time fallbacks. Fork of phpecc/mdanter. Supports secp256k1, NIST P-256/384/521, Brainpool, plus optional insecure curves.
openssl_*, hash_hmac), this package fills gaps where fine-grained control over ECC is needed (e.g., brainpool curves for BSI compliance, secp256k1 for Bitcoin-like systems, or Schnorr signatures for modern protocols).Ecc::generateKeyPair(), Ecc::signSchnorr()).config('ecc.curve'))./api/keys/generate, /api/sign).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Performance | OpenSSL fallback is faster; pure PHP is ~10-100x slower for large ops. | Benchmark before production; use OpenSSL 3.0+ where possible. |
| Side-Channel Attacks | Pure PHP implementations are constant-time but require careful usage. | Enforce SchnorrSigner for signatures; avoid custom k generation. |
| Key Management | No built-in key storage; risk of private key exposure. | Integrate with Laravel Vault or AWS KMS; use environment variables for secrets. |
| Curve Selection | Defaults to secure curves; insecure curves require opt-in. | Document allowed curves in Laravel config; audit dependencies. |
| PHP Version | Requires PHP 7.1+ (but PHP 8.1+ recommended for OpenSSL). | Enforce PHP 8.2+ in Laravel’s php.ini or Docker. |
| Schnorr Deprecation | SchnorrSignature → SchnorrSigner (backward-compatible until v3.0). |
Update codebase proactively; test migration path. |
config/cache, AWS Secrets Manager)?k reuse?web3/php-ethereum-cryptography)? If so, what’s the data format migration (e.g., hex vs. binary keys)?| Laravel Component | Integration Strategy |
|---|---|
| Service Container | Bind Mdanter\Ecc\EccFactory and SchnorrSigner as singletons with curve configs. |
| Facades | Create Ecc facade for fluent API (e.g., Ecc::generateKeyPair('secp256k1')). |
| Config Files | Define allowed curves, OpenSSL fallback, and default RNG in config/ecc.php. |
| Database | Store keys/signatures as hex strings (e.g., public_key in users table). |
| Artisan Commands | Add php artisan ecc:generate-key for CLI key creation. |
| API Resources | Expose /api/crypto/sign and /api/crypto/derive-shared-key endpoints. |
| Testing | Use PHPUnit with paragonie/random_compat for deterministic test RNG. |
openssl_sign, hash_hmac).laravel-ecc) with:
phpecc (e.g., for ECDH in a chat app).openssl_* calls in favor of phpecc methods.deprecated() helper for legacy code.| Dependency | Compatibility Notes |
|---|---|
| PHP 8.1+ | Required for OpenSSL 3.0+ fallback (best performance). |
| GMP Extension | Mandatory for pure PHP operations (check extension_loaded('gmp')). |
| OpenSSL 3.0+ | Preferred but optional (pure PHP works as fallback). |
| Laravel 9.0+ | Uses PHP 8.1+ features (e.g., SensitiveParameter attributes). |
| Composer | Install via composer require paragonie/ecc:^2. |
paragonie/ecc to composer.json.php artisan vendor:publish --tag=ecc-config).EccService class to abstract EccFactory and SchnorrSigner.AppServiceProvider.Ecc::logOperation('sign', $curve)).| Task | Effort | Notes |
|---|---|---|
| Dependency Updates | Low | Follow paragonie/ecc releases; test PHP 8.4+ compatibility. |
| Curve Policy | Medium | Update config/ecc.php if new curves are added/removed. |
| Key Rotation | High | Implement automated key rotation (e.g., via Laravel Queues). |
| Audit Logs | Medium | Extend EccService to log operations to laravel-log or SIEM. |
| Performance Tuning | Low | Cache frequently used curves (e.g., secp256k1) in a static variable. |
| Issue Type
How can I help you explore Laravel packages today?