strata/ext/src/lib.rs

#![no_std]
//! strata-ext β€” tier 4: structural traits.
//!
//! traits for specific algebraic structures that not every field needs.
//!
//! ## Extension
//!
//! tower fields: F_p β†’ Fp2 β†’ Fp3 β†’ Fp4 (nebu extensions), or
//! Fβ‚‚ β†’ Fβ‚‚Β² β†’ F₂⁴ β†’ ... β†’ F₂¹²⁸ (kuro tower). an extension field
//! has a base field, a degree, and a Frobenius endomorphism.
//!
//! ## Batch
//!
//! Montgomery's trick: invert N elements with 1 inversion + 3(N-1)
//! multiplications. nebu and kuro both implement this independently β€”
//! this trait unifies the interface.
//!
//! ## Blind
//!
//! timing-safe operations for privacy-critical code. genies (CSIDH)
//! requires constant-time arithmetic β€” no branches on secret data.
//! other algebras may implement this for defense in depth.

use strata_core::Field;

/// an extension field over a base field.
///
/// E is an extension of B if B βŠ‚ E and E is a vector space over B.
/// the extension degree [E:B] = dim_B(E) β€” how many base elements
/// represent one extension element.
///
/// examples:
/// - Fp2 over Goldilocks: degree 2, Frobenius is conjugation
/// - F₂¹²⁸ over F₂⁢⁴: degree 2, defined by xΒ² + x + Ξ±
/// - F₂¹²⁸ over Fβ‚‚: degree 128, Frobenius is squaring
pub trait Extension<Base: Field>: Field {
    /// extension degree: [Self : Base].
    const DEGREE: usize;

    /// decompose into base field coefficients.
    /// returns DEGREE elements.
    fn to_base_elements(&self) -> alloc::vec::Vec<Base>;

    /// construct from base field coefficients.
    fn from_base_elements(coeffs: &[Base]) -> Self;

    /// embed a base element into the extension (as degree-0 coefficient).
    fn from_base(b: Base) -> Self;

    /// Frobenius endomorphism: x ↦ x^(|Base|^power).
    /// for prime fields of char p: Frobenius(x) = x^p.
    /// for binary fields: Frobenius(x) = xΒ² (squaring).
    fn frobenius_map(&self, power: usize) -> Self;
}

/// batch operations via Montgomery's trick.
///
/// invert N elements using 1 inversion + 3(N-1) multiplications.
/// prefix products β†’ invert the product β†’ back-propagate individual inverses.
pub trait Batch: Field {
    /// batch-invert a slice of field elements in-place.
    /// zero elements are left as zero.
    fn batch_inv(elements: &mut [Self]);
}

/// constant-time operations for privacy-critical arithmetic.
///
/// genies (CSIDH) requires this: isogeny walks on secret exponents
/// must not leak timing information. no branches on secret data,
/// no variable-time memory access, no early exits.
pub trait Blind: Field {
    /// constant-time equality comparison.
    fn ct_eq(&self, other: &Self) -> bool;

    /// constant-time conditional select: if choice is true, return a; else b.
    /// executes both branches regardless of choice.
    fn ct_select(a: &Self, b: &Self, choice: bool) -> Self;

    /// constant-time conditional swap: if choice is true, swap a and b.
    fn ct_swap(a: &mut Self, b: &mut Self, choice: bool);
}

extern crate alloc;

Synonyms

bbg/src/lib.rs
optica/src/lib.rs
zheng/src/lib.rs
nox/rs/lib.rs
honeycrisp/src/lib.rs
trident/src/lib.rs
lens/src/lib.rs
strata/src/lib.rs
rs/macros/src/lib.rs
strata/nebu/rs/lib.rs
honeycrisp/rane/src/lib.rs
honeycrisp/acpu/src/lib.rs
lens/core/src/lib.rs
rs/mir-format/src/lib.rs
rs/core/src/lib.rs
hemera/wgsl/src/lib.rs
strata/kuro/rs/lib.rs
radio/iroh-ffi/src/lib.rs
cyb/src-tauri/src/lib.rs
strata/core/src/lib.rs
radio/iroh-docs/src/lib.rs
strata/compute/src/lib.rs
lens/porphyry/src/lib.rs
radio/cyber-bao/src/lib.rs
radio/iroh-relay/src/lib.rs
lens/assayer/src/lib.rs
lens/brakedown/src/lib.rs
radio/iroh-car/src/lib.rs
honeycrisp/unimem/src/lib.rs
honeycrisp/aruminium/src/lib.rs
lens/binius/src/lib.rs
hemera/rs/src/lib.rs
radio/iroh/src/lib.rs
radio/iroh-gossip/src/lib.rs
strata/proof/src/lib.rs
radio/iroh-blobs/src/lib.rs
radio/iroh-base/src/lib.rs
radio/iroh-dns-server/src/lib.rs
radio/iroh-willow/src/lib.rs
lens/ikat/src/lib.rs
rs/tests/macro-integration/src/lib.rs
cw-cyber/contracts/hub-networks/src/lib.rs
radio/tests/integration/src/lib.rs
cw-cyber/contracts/litium-core/src/lib.rs
strata/trop/wgsl/src/lib.rs
strata/kuro/wgsl/src/lib.rs
cw-cyber/contracts/hub-protocols/src/lib.rs
cw-cyber/contracts/cw-cyber-gift/src/lib.rs
strata/trop/rs/src/lib.rs
cw-cyber/contracts/cybernet/src/lib.rs
cw-cyber/contracts/hub-channels/src/lib.rs
strata/nebu/wgsl/src/lib.rs
cw-cyber/contracts/graph-filter/src/lib.rs
cw-cyber/contracts/litium-stake/src/lib.rs
trident/editor/zed/src/lib.rs
radio/iroh-ffi/iroh-js/src/lib.rs
cw-cyber/contracts/hub-tokens/src/lib.rs
cyb/cyb/cyb-services/src/lib.rs
cw-cyber/packages/hub-base/src/lib.rs
strata/genies/rs/src/lib.rs
cw-cyber/contracts/std-test/src/lib.rs
cw-cyber/packages/cyber-std-test/src/lib.rs
cw-cyber/contracts/litium-refer/src/lib.rs
strata/jali/rs/src/lib.rs
cw-cyber/contracts/hub-libs/src/lib.rs
cw-cyber/contracts/litium-wrap/src/lib.rs
cw-cyber/packages/cyber-std/src/lib.rs
strata/genies/wgsl/src/lib.rs
cw-cyber/contracts/hub-skills/src/lib.rs
strata/jali/wgsl/src/lib.rs
cw-cyber/contracts/cw-cyber-subgraph/src/lib.rs
radio/iroh/bench/src/lib.rs
cw-cyber/contracts/litium-mine/src/lib.rs
cw-cyber/contracts/cw-cyber-passport/src/lib.rs

Neighbours