Neptune-Crypto / twenty-first

Collection of mathematics routines and cryptography for the twenty-first century
GNU General Public License v2.0
74 stars 22 forks source link

Rework `ntt` interface. #211

Closed jan-ferdinand closed 1 month ago

jan-ferdinand commented 6 months ago

I think it's time we rework the ntt interface from its current

pub fn ntt<FF>(x: &mut [FF], omega: BFieldElement, log_2_of_n: u32) { /* … */ }

to be something like

pub fn ntt<FF>(mut x: Vec<FF>) -> Vec<FF> {/* … */}

The current interface feels quite clunky. For example, the passed-in primitive root of unity omega and the $\mathsf{log}_2(\mathtt{x.len()})$ have restrictions that are so tight that they might as well be computed inside the function.

Admittedly, the current signature seems to have some merit – sometimes, it is actually used on sub-slices. However, most of time, a mutable reference to an entire vector is passed in. Maybe the above suggestion is a wrapper for an internal fn ntt_mut_slice(…). Looking at how we use ntt, it seems that this wrapper would become the default use.