mdanter/ecc
Pure-PHP elliptic curve cryptography for ECDSA signatures and Diffie-Hellman key exchange. Supports common NIST and secp curves (including secp256k1), deterministic HMAC-based k generation, and constant-time scalar multiplication. Requires GMP.
mdanter/ecc) provides pure PHP Elliptic Curve Cryptography (ECC) for DSA (Digital Signature Algorithm) and DH (Diffie-Hellman key exchange). This is a niche but critical fit for:
Illuminate\Support\Facades\Crypt) and hashing (via Hash facade) rely on OpenSSL, but this package enables pure-PHP ECC—useful for:
EccService).Illuminate\Contracts\Events\Dispatcher for key generation/signing events.config/caching.php).| Risk Area | Mitigation Strategy |
|---|---|
| Cryptographic Security | Validate against NIST SP 800-186 for curve selection. Avoid weak curves (e.g., secp112r1). |
| Randomness (RNG) | Enforce CSPRNG (e.g., random_bytes()) for k generation. Reject weak entropy. |
| Side-Channel Attacks | Use constant-time comparisons for scalar multiplication (package may need patches). |
| Backward Compatibility | Test with PHP 8.0+ (package supports 7.2+). Deprecation warnings may arise in future PHP. |
| Key Management | Integrate with Laravel’s encryption config or AWS KMS/GCP KMS for HSM-backed keys. |
filesystem disk? Hashicorp Vault?)EccService in config/app.php with DI bindings.Ecc::sign(), Ecc::verify(), Ecc::deriveKey() methods.php artisan ecc:generate-key for CLI keygen.EccKeyGenerated events for logging/auditing.users table as hex or binary (use Laravel’s json column or binary type).$table->binary('public_key')->nullable(); // 33 bytes for secp256k1
$table->binary('private_key')->nullable(); // 32 bytes
/api/signature).openssl_ec_sign().mdanter/ecc as a fallback (e.g., in config/ecc.php).'driver' => env('ECC_DRIVER', 'openssl'), // or 'pure_php'
mdanter/ecc where needed.| Component | Compatibility Notes |
|---|---|
| PHP Version | Tested on PHP 7.2–8.2. May need polyfills for older versions. |
| Laravel Version | Works with Laravel 7+. For LTS, use ^1.0 branch. |
| Curves | All supported curves work, but nistp521 may be slow on low-end servers. |
| Existing Crypto | Avoid mixing with openssl_* functions (e.g., don’t use both for key exchange). |
| Database | Ensure DB supports BINARY/VARBINARY for key storage (MySQL, PostgreSQL). |
composer require mdanter/ecc
// app/Providers/EccServiceProvider.php
public function register() {
$this->app->singleton(EccService::class, function () {
return new EccService(config('ecc.curve'));
});
}
php artisan vendor:publish --provider="EccServiceProvider"
// app/Facades/Ecc.php
public static function sign(string $data, string $privateKey): string {
return (new EccService())->sign($data, $privateKey);
}
1.0.0) to avoid breaking changes.phpunit).try {
Ecc::verify($data, $signature, $publicKey);
} catch (EccException $e) {
Log::error("ECC verification failed", ['curve' => $e->getCurve()]);
}
Illuminate\Support\Facades\Cache).How can I help you explore Laravel packages today?