ecRust
A Rust library for finite-field arithmetic, elliptic-curve operations, isogeny scaffolding, and higher-level elliptic-curve protocols.
The project is organized as a layered set of crates:
protocol ← ECDH / EC-ElGamal helpers built on curve points
↓
isogeny ← isogeny and kernel abstractions (work in progress)
↓
ec ← elliptic-curve models and point arithmetic
↓
fp ← finite fields: Fp, Fp^m, F2, F2^m
↓
crypto-bigint ← multi-precision integers / Montgomery arithmetic
Workspace crates
fp
Finite-field arithmetic.
Main building blocks:
FieldOps: common trait implemented by field elements.FpElement<MOD, LIMBS>: prime-field elements overFp.FpExt<MOD, LIMBS, M, P>: extension-field elements overFp^M.F2Element: the prime fieldF2.F2Ext<LIMBS, P>: binary extension fieldsF2^m.IrreduciblePoly/BinaryIrreducible: marker traits used to define extension fields.
ec
Elliptic-curve abstractions and affine Weierstrass arithmetic.
Main building blocks:
CurveOps: generic curve-model trait.PointOps: generic point/group API.
isogeny
Kernel and isogeny structs.
Current status:
KernelSubgroup<C>exists.Isogeny<C>exists as the main abstraction.- evaluation formulas are still TODO.
protocol
Small protocol layer on top of ec.
Current modules:
SecretScalar<LIMBS>EcdhEcElGamal
Current status
This workspace is usable for experiments and API exploration, with the following caveats:
fpis the most complete and best-tested layer.ecsupports affine Weierstrass arithmetic and scalar multiplication, but some methods still contain exceptional-case branching and should not yet be treated as hardened production code.isogenyis currently scaffolding.- protocol examples are functional API examples, not production-ready constructions.
Build and test
Quick start
1. Instantiate a prime field (FieldOps via FpElement)
use ;
use FieldOps;
use FpElement;
const_prime_monty_params!;
type F19 = ;
let a = F19from_u64;
let b = F19from_u64;
let c = a * b;
assert_eq!; // 56 mod 19 = 18
let inv = a.invert.into_option.unwrap;
assert!;
2. Instantiate an extension field (FieldOps via FpExt)
use FieldOps;
use FpElement;
use ;
;
;
type F19_2 = ;
let x = F19_2new; // 3 + 2u
let y = x.invert.into_option.unwrap;
assert!;
3. Instantiate a curve (Curve) and a point (PointOps)
use WeierstrassCurve;
use AffinePoint;
let curve = new_short;
let p = new;
assert!;
let q = p.double;
let r = p.add;
let s = p.scalar_mul;
Examples and demos
See DEMO.md for several concrete examples showing how to instantiate the main traits and concrete types in this workspace:
FieldOpswithFpElementFieldOpswithFpExtFieldOpswithF2ExtCurve/PointOpswithWeierstrassCurveandAffinePointSecretScalar,Ecdh, andEcElGamal- generic helper functions written against traits instead of concrete types
Repository layout
ecrust/
├── Cargo.toml
├── README.md
├── DEMO.md
├── fp/
│ ├── src/
│ │ ├── field_ops.rs
│ │ ├── fp_element.rs
│ │ ├── fp_ext.rs
│ │ ├── f2_element.rs
│ │ └── f2_ext.rs
│ └── tests/
├── ec/
│ ├── src/
│ │ ├── curve_ops.rs
│ │ ├── point_ops.rs
│ │ ├── curve_weierstrass.rs
│ │ └── point_weierstrass.rs
│ └── tests/
├── isogeny/
│ ├── src/
│ │ ├── kernel.rs
│ │ └── isogeny.rs
│ └── tests/
└── protocol/
├── src/
│ ├── scalar.rs
│ ├── ecdh.rs
│ └── elgamal.rs
└── tests/
Disclaimer
Disclaimer. This software is currently in an alpha stage. We are actively working toward constant-time implementations across the project, but achieving this systematically remains an ongoing effort. At this stage, the code should be treated as experimental, and it must not be assumed to provide full side-channel resistance or production-grade security guarantees.
Authors
- Gustavo Banegas
- Martin Azon
- Sam Frengley
License
Apache License 2.0. See LICENSE.