hop-core 0.1.0

HOP core — finite-field companion-matrix stream primitives (prototype)
Documentation
// Copyright (c) 2025 Lex Luger. All Rights Reserved.
// This software (HOP-CORE) is proprietary and confidential.
// Unauthorized copying, distribution, or use is strictly prohibited
// without explicit written permission from the author.
// Commercial licenses are available. Contact: lexluger.dev@proton.me
use crate::modules::companion::{Mat, identity, multiply_mat};
use crate::modules::field::Field;
use std::ops::{Add, Mul};

/// Evaluate polynomial g(C) where C is the companion matrix.
/// g is given as coefficient slice [g0, g1, ..., g_{d}] meaning g(x) = g0 + g1 x + ...
/// Returns a k×k matrix representing g(C).
pub fn poly_matrix_eval(g_coeffs: &[u64], c: &Mat) -> Mat {
    let k = c.len();
    // precompute powers of C: C^0 = I, C^1 = C, ...
    let mut powers: Vec<Mat> = Vec::with_capacity(g_coeffs.len());
    powers.push(identity(k));
    if g_coeffs.len() > 1 {
        powers.push(c.clone());
        for e in 2..g_coeffs.len() {
            let next = multiply_mat(&powers[e-1], c);
            powers.push(next);
        }
    }

    // accumulate sum g_i * C^i
    let mut accum = vec![vec![Field::zero(); k]; k];
    for (i, &coef) in g_coeffs.iter().enumerate() {
        if coef == 0 { continue; }
        let mulf = Field::new(coef as u128);
        let pow = &powers[i];
        for r in 0..k {
            for c in 0..k {
                let addval = pow[r][c].mul(mulf);
                accum[r][c] = accum[r][c].add(addval);
            }
        }
    }
    accum
}