curveforge-macro

Crates.iocurveforge-macro
lib.rscurveforge-macro
version0.3.0
created_at2025-09-15 14:29:13.246199+00
updated_at2025-09-15 14:29:13.246199+00
descriptionOptimised, secure, and generalised algorithms for elliptic curve arithmetic
homepage
repository
max_upload_size
id1840130
size209,513
Ruben De Smet (rubdos)

documentation

README

CurveForge Macro

curveforge_macro is a procedural macro crate that provides a set of powerful macros for generating elliptic curve and finite field implementations. These macros conform to the trait-based abstractions defined in the curveforge_traits crate, enabling modular, secure, and efficient cryptographic structures.

Macros Provided

  • finite_field!
    Define a prime finite field for cryptographic applications. Assumes the modulus is greater than 2.

  • elliptic_curve_model!
    Specify the algebraic form of an elliptic curve (e.g., Weierstrass, Montgomery).

  • elliptic_curve!
    Combine a finite field and model to create a complete elliptic curve implementation.

Features

  • Generates efficient, type-safe, and trait-compliant elliptic curve types.
  • Works seamlessly with curveforge_traits to provide a unified algebraic interface.
  • Modular and composable macros for flexibility in curve and field definitions.
  • Input is parsed and validated at compile-time, with informative errors.

Example

Here is a basic usage example. Grammars for the model and curve can be found in model.pest and curve.pest.

use curveforge::prelude::*;

// Define a finite field over any prime number (larger than 2). Order can be given in hex.
finite_field!(MyFiniteField, 7); 

// Define a type of elliptic curve.
elliptic_curve_model! {
    // Attribute section
    [attributes]
    name = MyCurveModel // Required
    coordinates = (x, y) // Required
    constants = (a, b) // Have to be provided by the specific curve that uses this model

    // Functions section (define behaviour matching traits in [curveforge_traits::curve_model])
    [functions]
    add: (P: Self, Q: Self) -> Self
        // Series of statements
        x <- P.x + Q.x
        y <- P.y + Q.y
        // Return expression
        Self::new(x, y)
}

elliptic_curve! {
    // Attribute section
    [attributes]
    name = MyCurve // Required
    model = MyCurveModel // Required, matching a model in scope

    // Required prime base field and prime order subgroup sizes
    field_size = 7 
    group_size = 7 

    // Generator and identity points on the curve
    generator = (1, 1)
    identity = (0, 0)

    // Constants section
    [constants]
    // Define constants required by the model
    a = 1
    b = 2
}
Commit count: 0

cargo fmt