1111
1212use criterion:: * ;
1313use qfall_math:: {
14- integer_mod_q:: { Modulus , ModulusPolynomialRingZq , PolyOverZq , PolynomialRingZq } ,
14+ integer_mod_q:: {
15+ Modulus , ModulusPolynomialRingZq , NTTPolynomialRingZq , PolyOverZq , PolynomialRingZq ,
16+ } ,
1517 traits:: * ,
1618} ;
1719
@@ -54,26 +56,36 @@ pub fn bench_ntt_dilithium_params_with_ntt(c: &mut Criterion) {
5456 let p1 = PolynomialRingZq :: sample_uniform ( & modulus) ;
5557 let p2 = PolynomialRingZq :: sample_uniform ( & modulus) ;
5658
57- let ntt1 = p1 . ntt ( ) . unwrap ( ) ;
58- let ntt2 = p2 . ntt ( ) . unwrap ( ) ;
59+ let ntt1 = NTTPolynomialRingZq :: from ( & p1 ) ;
60+ let ntt2 = NTTPolynomialRingZq :: from ( & p2 ) ;
5961
6062 c. bench_function (
6163 "PolynomialRingZq Multiplication with NTT (Dilithium)" ,
62- |b| b. iter ( || PolynomialRingZq :: real_mul_ntt ( & ntt1, & ntt2, & mod_q) ) ,
64+ |b| b. iter ( || ntt1. mul ( & ntt2, & mod_q) ) ,
6365 ) ;
6466}
6567
6668/// benchmark multiplication in typical dilithium parameter set with NTT & Transforms
6769/// `n=256`, `q = 2^23 - 2^13 + 1` and `zeta = 1753`
6870pub fn bench_ntt_dilithium_params_with_ntt_and_transforms ( c : & mut Criterion ) {
6971 let modulus = get_dilithium_setup ( ) ;
72+ let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
7073
7174 let p1 = PolynomialRingZq :: sample_uniform ( & modulus) ;
7275 let p2 = PolynomialRingZq :: sample_uniform ( & modulus) ;
7376
7477 c. bench_function (
7578 "PolynomialRingZq Multiplication with NTT + Transforms (Dilithium)" ,
76- |b| b. iter ( || PolynomialRingZq :: mul_ntt ( & p1, & p2) ) ,
79+ |b| {
80+ b. iter ( || {
81+ let ntt1 = NTTPolynomialRingZq :: from ( & p1) ;
82+ let ntt2 = NTTPolynomialRingZq :: from ( & p2) ;
83+
84+ let ntt_res = ntt1. mul ( & ntt2, & mod_q) ;
85+
86+ let _ = PolynomialRingZq :: from ( ( ntt_res, & modulus) ) ;
87+ } )
88+ } ,
7789 ) ;
7890}
7991
@@ -100,25 +112,36 @@ pub fn bench_ntt_hawk1024_params_with_ntt(c: &mut Criterion) {
100112 let p1 = PolynomialRingZq :: sample_uniform ( & modulus) ;
101113 let p2 = PolynomialRingZq :: sample_uniform ( & modulus) ;
102114
103- let ntt1 = p1 . ntt ( ) . unwrap ( ) ;
104- let ntt2 = p2 . ntt ( ) . unwrap ( ) ;
115+ let ntt1 = NTTPolynomialRingZq :: from ( & p1 ) ;
116+ let ntt2 = NTTPolynomialRingZq :: from ( & p2 ) ;
105117
106118 c. bench_function ( "PolynomialRingZq Multiplication with NTT (HAWK1024)" , |b| {
107- b. iter ( || PolynomialRingZq :: real_mul_ntt ( & ntt1, & ntt2, & mod_q) )
119+ b. iter ( || ntt1. mul ( & ntt2, & mod_q) )
108120 } ) ;
109121}
110122
111123/// benchmark multiplication in typical HAWK1024 parameter set with NTT and Transforms
112124/// `n=256`, `q = 12289` and `zeta = 1945`
113125pub fn bench_ntt_hawk1024_params_with_ntt_and_transforms ( c : & mut Criterion ) {
114126 let modulus = get_hawk1024_setup ( ) ;
127+ let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
115128
116129 let p1 = PolynomialRingZq :: sample_uniform ( & modulus) ;
117130 let p2 = PolynomialRingZq :: sample_uniform ( & modulus) ;
118131
119- c. bench_function ( "PolynomialRingZq Multiplication with NTT + Transforms (HAWK1024)" , |b| {
120- b. iter ( || PolynomialRingZq :: mul_ntt ( & p1, & p2) )
121- } ) ;
132+ c. bench_function (
133+ "PolynomialRingZq Multiplication with NTT + Transforms (HAWK1024)" ,
134+ |b| {
135+ b. iter ( || {
136+ let ntt1 = NTTPolynomialRingZq :: from ( & p1) ;
137+ let ntt2 = NTTPolynomialRingZq :: from ( & p2) ;
138+
139+ let ntt_res = ntt1. mul ( & ntt2, & mod_q) ;
140+
141+ let _ = PolynomialRingZq :: from ( ( ntt_res, & modulus) ) ;
142+ } )
143+ } ,
144+ ) ;
122145}
123146
124147/// benchmark multiplication in typical HAWK1024 parameter set without NTT
0 commit comments