Skip to content

Commit

Permalink
refactor: modularize elliptic curve implementation
Browse files Browse the repository at this point in the history
Move the elliptic curve (EC) implementation into separate modules for
better code organization and maintainability. The `ec.rs` file was split
into `ec/mod.rs` and `ec/weierstrass.rs` to group the EC trait
definition and Weierstrass curve logic respectively. This change
improves modularity and clarifies the separation between different curve
types, making it easier to extend with additional curve types in the
future.

The core elliptic curve trait remains unchanged, while the Weierstrass
curve has been refactored into its own module. Unit tests have been
preserved and moved accordingly.
  • Loading branch information
pycckuu committed Sep 30, 2024
1 parent 1df8bfd commit bf5e859
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 276 deletions.
275 changes: 0 additions & 275 deletions src/ec.rs

This file was deleted.

16 changes: 16 additions & 0 deletions src/ec/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::point::Point;
use num_bigint::BigUint;

pub mod weierstrass;
pub use weierstrass::WeierstrassCurve;

/// Base trait for all elliptic curves
pub trait EllipticCurve {
fn add(&self, p1: &Point, p2: &Point) -> Point;
fn double(&self, p: &Point) -> Point;
fn mul(&self, p: &Point, scalar: &BigUint) -> Point;
fn is_on_curve(&self, p: &Point) -> bool;
fn order(&self) -> &BigUint;
fn base_point(&self) -> &Point;
fn field_modulus(&self) -> &BigUint;
}
Loading

0 comments on commit bf5e859

Please sign in to comment.