famoser/elliptic 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

famoser/elliptic

Composer 安装命令:

composer require famoser/elliptic

包简介

PHP Elliptic Curve Cryptography library

README 文档

README

MIT licensed Test Coverage Status

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, brainpool and the bernstein curves (curve25519 and curve448).
  • Math: Operate on the curves using add, double and mul.
  • 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_Math passes math sanity, but performs incorrectly in relation to baselines (e.g. third party testcases).
  • MG_TwED_ANeg1_Math and TwED_ANeg1_Math perform 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.
  • MGXCalculator performs best, but is no full math implementation (no double, no add).
  • 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 famoser/elliptic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-26