famoser/elliptic
Composer 安装命令:
composer require famoser/elliptic
包简介
PHP Elliptic Curve Cryptography library
README 文档
README
This library provides low-level access to elliptic curve group computations. Extensively tested (100% branch coverage, 9k third-party integration tests) and hardened against side-channels.
// get curves from SEC, brainpool and bernstein $repository = new CurveRepository(); $curve = $repository->findByName('secp256r1'); // hardened (against side-channels) math for most curves $mathFactory = new MathFactory($repository); $math = $mathFactory->createHardenedMath($curve); // can do double, add and mul $G2 = $math->double($curve->getG()); $G3 = $math->add($curve->getG(), $G2); $GA = $math->mul($curve->getG(), gmp_init(3)); if ($G3->equals($GA)) { echo "success"; }
Functionality overview:
- Curves: Use
SEC2,brainpooland the bernstein curves (curve25519andcurve448). - Math: Operate on the curves using
add,doubleandmul. - Decoders: Decode according to SEC or bernstein. Recover points given only an x or y coordinate.
Compared to the popular paragonie/phpecc, this library focuses on the math on the elliptic curves directly, and does not implement any cryptographic primitives.
For this task, this library is around 100x [sic!] faster, while not performing significantly worse in terms of side-channels.
Math overview
There are two types of math:
- Unsafe implementations (
$repository->createUnsafeMath($curve)): Simply implement the addition and double formulas for the given curve type ($repository->createUnsafeMath($curve)). - Hardened implementations (
$repository->createHardenedMath($curve)): Follow specifications and RFCs that notably aim to reduce the effectiveness of side-channels (side-channels may allow an adversary to recover the input to the algorithms, e.g. private key material, by observing the environment, e.g. time and power usage of the CPU).
All curves, except the secp*k1 and the brainpool*r1 variants, have hardened implementations available. Unless you have a good reason, you should use these hardened implementations.
| Hardened Math | Supported Curves | Correctness | Hardened | Runtime |
|---|---|---|---|---|
SW_ANeg3_Math |
secp*r1, brainpool*t1 |
✅ | ⚠️⚠️ | 4 |
SW_QT_ANeg3_Math |
brainpool*r1 |
✅ | ⚠️⚠️ | 4 |
MGXCalculator (mul only) |
curve25519, curve448 |
✅ | ⚠️⚠️⚠️ | 1 |
MG_TwED_ANeg1_Math |
curve25519 |
⚠️ | ⚠️ | 2.5 |
MG_ED_Math |
curve448 |
❌ | ❔ | 2 |
TwED_ANeg1_Math |
edwards25519 |
⚠️ | ❔ | 2.5 |
EDMath |
edwards448, curve448Edwards |
✅ | ❔ | 2 |
Correctness:
MG_ED_Mathpasses math sanity, but performs incorrectly in relation to baselines (e.g. third party testcases).MG_TwED_ANeg1_MathandTwED_ANeg1_Mathperform correctly based on third-party testcases, but math sanity (e.g. G*order = 0) fails.
Hardened:
- No implementation can be shown constant-time, and other side-channels are not quantitively assessed.
- Implementations finish faster with adversarial input (0 very small points and factors) vs random input.
- Unsafe maths show 50% variance in execution time, hardened math between 3% (
MG_TwED_ANeg1_Math) and 15% (MGXCalculator)
Runtime:
- Denoted is execution time of mul in some unit; hence lower is better.
MGXCalculatorperforms best, but is no full math implementation (nodouble, noadd).- The unsafe variants of SW are 2x faster, the unsafe variant of MG is 1.5x faster.
Project context
This library is part of a larger effort:
- Provide low-level library that executes math on elliptic curves (this project)
- Provide elliptic-crypto library which exposes general cryptographic primitives (signatures, encryptions and zero-knowledge proofs)
- Provide more specialized libraries for more exotic cryptographic primitives (verifiable shuffle)
famoser/elliptic 适用场景与选型建议
famoser/elliptic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「elliptic」 「curve」 「nist」 「brainpool」 「bernstein」 「weierstrass」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 famoser/elliptic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 famoser/elliptic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 famoser/elliptic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Searchable field-level encryption library for relational databases
The Scheme FFX[radix] of the FFX Mode of Operation for Format-Preserving Encryption
Virgil is a stack of security libraries (ECIES with Crypto Agility wrapped in Virgil Cryptogram) and all the necessary infrastructure to enable seamless, end-to-end encryption for any application, platform or device. See below for currently available languages and platforms. Get in touch with us to
Virgil is a stack of security libraries (ECIES with Crypto Agility wrapped in Virgil Cryptogram) and all the necessary infrastructure to enable seamless, end-to-end encryption for any application, platform or device. See below for currently available languages and platforms. Get in touch with us to
Fast elliptic curve cryptography
A bundle to calculate normal distribution and other related stuff
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-26