1212use criterion:: * ;
1313use qfall_math:: {
1414 integer_mod_q:: {
15- MatNTTPolynomialRingZq , MatPolynomialRingZq , Modulus , ModulusPolynomialRingZq ,
16- NTTPolynomialRingZq , PolyOverZq , PolynomialRingZq ,
15+ MatNTTPolynomialRingZq , MatPolynomialRingZq , ModulusPolynomialRingZq , NTTPolynomialRingZq ,
16+ PolyOverZq , PolynomialRingZq ,
1717 } ,
1818 traits:: * ,
1919} ;
@@ -52,7 +52,6 @@ pub fn get_hawk1024_setup() -> ModulusPolynomialRingZq {
5252/// `n=256`, `q = 2^23 - 2^13 + 1` and `zeta = 1753`
5353pub fn bench_ntt_dilithium_params_with_ntt ( c : & mut Criterion ) {
5454 let modulus = get_dilithium_setup ( ) ;
55- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
5655
5756 let p1 = PolynomialRingZq :: sample_uniform ( & modulus) ;
5857 let p2 = PolynomialRingZq :: sample_uniform ( & modulus) ;
@@ -62,15 +61,14 @@ pub fn bench_ntt_dilithium_params_with_ntt(c: &mut Criterion) {
6261
6362 c. bench_function (
6463 "PolynomialRingZq Multiplication with NTT (Dilithium)" ,
65- |b| b. iter ( || ntt1 . mul ( & ntt2 , & mod_q ) ) ,
64+ |b| b. iter ( || & ntt1 * & ntt2 ) ,
6665 ) ;
6766}
6867
6968/// benchmark multiplication in typical dilithium parameter set with NTT & Transforms
7069/// `n=256`, `q = 2^23 - 2^13 + 1` and `zeta = 1753`
7170pub fn bench_ntt_dilithium_params_with_ntt_and_transforms ( c : & mut Criterion ) {
7271 let modulus = get_dilithium_setup ( ) ;
73- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
7472
7573 let p1 = PolynomialRingZq :: sample_uniform ( & modulus) ;
7674 let p2 = PolynomialRingZq :: sample_uniform ( & modulus) ;
@@ -82,9 +80,9 @@ pub fn bench_ntt_dilithium_params_with_ntt_and_transforms(c: &mut Criterion) {
8280 let ntt1 = NTTPolynomialRingZq :: from ( & p1) ;
8381 let ntt2 = NTTPolynomialRingZq :: from ( & p2) ;
8482
85- let ntt_res = ntt1 . mul ( & ntt2 , & mod_q ) ;
83+ let ntt_res = & ntt1 * & ntt2 ;
8684
87- let _ = PolynomialRingZq :: from ( ( ntt_res, & modulus ) ) ;
85+ let _ = PolynomialRingZq :: from ( ntt_res) ;
8886 } )
8987 } ,
9088 ) ;
@@ -108,7 +106,6 @@ pub fn bench_ntt_dilithium_params_without_ntt(c: &mut Criterion) {
108106/// `n=256`, `q = 12289` and `zeta = 1945`
109107pub fn bench_ntt_hawk1024_params_with_ntt ( c : & mut Criterion ) {
110108 let modulus = get_hawk1024_setup ( ) ;
111- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
112109
113110 let p1 = PolynomialRingZq :: sample_uniform ( & modulus) ;
114111 let p2 = PolynomialRingZq :: sample_uniform ( & modulus) ;
@@ -117,15 +114,14 @@ pub fn bench_ntt_hawk1024_params_with_ntt(c: &mut Criterion) {
117114 let ntt2 = NTTPolynomialRingZq :: from ( & p2) ;
118115
119116 c. bench_function ( "PolynomialRingZq Multiplication with NTT (HAWK1024)" , |b| {
120- b. iter ( || ntt1 . mul ( & ntt2 , & mod_q ) )
117+ b. iter ( || & ntt1 * & ntt2 )
121118 } ) ;
122119}
123120
124121/// benchmark multiplication in typical HAWK1024 parameter set with NTT and Transforms
125122/// `n=256`, `q = 12289` and `zeta = 1945`
126123pub fn bench_ntt_hawk1024_params_with_ntt_and_transforms ( c : & mut Criterion ) {
127124 let modulus = get_hawk1024_setup ( ) ;
128- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
129125
130126 let p1 = PolynomialRingZq :: sample_uniform ( & modulus) ;
131127 let p2 = PolynomialRingZq :: sample_uniform ( & modulus) ;
@@ -137,9 +133,9 @@ pub fn bench_ntt_hawk1024_params_with_ntt_and_transforms(c: &mut Criterion) {
137133 let ntt1 = NTTPolynomialRingZq :: from ( & p1) ;
138134 let ntt2 = NTTPolynomialRingZq :: from ( & p2) ;
139135
140- let ntt_res = ntt1 . mul ( & ntt2 , & mod_q ) ;
136+ let ntt_res = & ntt1 * & ntt2 ;
141137
142- let _ = PolynomialRingZq :: from ( ( ntt_res, & modulus ) ) ;
138+ let _ = PolynomialRingZq :: from ( ntt_res) ;
143139 } )
144140 } ,
145141 ) ;
@@ -163,7 +159,6 @@ pub fn bench_ntt_hawk1024_params_without_ntt(c: &mut Criterion) {
163159/// `n=256`, `q = 2^23 - 2^13 + 1` and `zeta = 1753`
164160pub fn bench_mat_ntt_dilithium_params_with_ntt ( c : & mut Criterion ) {
165161 let modulus = get_dilithium_setup ( ) ;
166- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
167162
168163 let p1 = MatPolynomialRingZq :: sample_uniform ( 4 , 4 , & modulus) ;
169164 let p2 = MatPolynomialRingZq :: sample_uniform ( 4 , 1 , & modulus) ;
@@ -173,15 +168,14 @@ pub fn bench_mat_ntt_dilithium_params_with_ntt(c: &mut Criterion) {
173168
174169 c. bench_function (
175170 "MatPolynomialRingZq Multiplication with NTT (Dilithium)" ,
176- |b| b. iter ( || ntt1 . mul ( & ntt2 , & mod_q ) ) ,
171+ |b| b. iter ( || & ntt1 * & ntt2 ) ,
177172 ) ;
178173}
179174
180175/// benchmark multiplication in typical dilithium parameter set with NTT & Transforms
181176/// `n=256`, `q = 2^23 - 2^13 + 1` and `zeta = 1753`
182177pub fn bench_mat_ntt_dilithium_params_with_ntt_and_transforms ( c : & mut Criterion ) {
183178 let modulus = get_dilithium_setup ( ) ;
184- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
185179
186180 let p1 = MatPolynomialRingZq :: sample_uniform ( 4 , 4 , & modulus) ;
187181 let p2 = MatPolynomialRingZq :: sample_uniform ( 4 , 1 , & modulus) ;
@@ -193,9 +187,9 @@ pub fn bench_mat_ntt_dilithium_params_with_ntt_and_transforms(c: &mut Criterion)
193187 let ntt1 = MatNTTPolynomialRingZq :: from ( & p1) ;
194188 let ntt2 = MatNTTPolynomialRingZq :: from ( & p2) ;
195189
196- let mut ntt_res = ntt1 . mul ( & ntt2 , & mod_q ) ;
190+ let mut ntt_res = & ntt1 * & ntt2 ;
197191
198- let _ = MatPolynomialRingZq :: from ( ( & mut ntt_res, & modulus ) ) ;
192+ let _ = MatPolynomialRingZq :: from ( & mut ntt_res) ;
199193 } )
200194 } ,
201195 ) ;
@@ -219,7 +213,6 @@ pub fn bench_mat_ntt_dilithium_params_without_ntt(c: &mut Criterion) {
219213/// `n=256`, `q = 12289` and `zeta = 1945`
220214pub fn bench_mat_ntt_hawk1024_params_with_ntt ( c : & mut Criterion ) {
221215 let modulus = get_hawk1024_setup ( ) ;
222- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
223216
224217 let p1 = MatPolynomialRingZq :: sample_uniform ( 1 , 2 , & modulus) ;
225218 let p2 = MatPolynomialRingZq :: sample_uniform ( 2 , 2 , & modulus) ;
@@ -229,15 +222,14 @@ pub fn bench_mat_ntt_hawk1024_params_with_ntt(c: &mut Criterion) {
229222
230223 c. bench_function (
231224 "MatPolynomialRingZq Multiplication with NTT (HAWK1024)" ,
232- |b| b. iter ( || ntt1 . mul ( & ntt2 , & mod_q ) ) ,
225+ |b| b. iter ( || & ntt1 * & ntt2 ) ,
233226 ) ;
234227}
235228
236229/// benchmark multiplication in typical HAWK1024 parameter set with NTT and Transforms
237230/// `n=256`, `q = 12289` and `zeta = 1945`
238231pub fn bench_mat_ntt_hawk1024_params_with_ntt_and_transforms ( c : & mut Criterion ) {
239232 let modulus = get_hawk1024_setup ( ) ;
240- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
241233
242234 let p1 = MatPolynomialRingZq :: sample_uniform ( 2 , 2 , & modulus) ;
243235 let p2 = MatPolynomialRingZq :: sample_uniform ( 2 , 1 , & modulus) ;
@@ -249,9 +241,9 @@ pub fn bench_mat_ntt_hawk1024_params_with_ntt_and_transforms(c: &mut Criterion)
249241 let ntt1 = MatNTTPolynomialRingZq :: from ( & p1) ;
250242 let ntt2 = MatNTTPolynomialRingZq :: from ( & p2) ;
251243
252- let mut ntt_res = ntt1 . mul ( & ntt2 , & mod_q ) ;
244+ let mut ntt_res = & ntt1 * & ntt2 ;
253245
254- let _ = MatPolynomialRingZq :: from ( ( & mut ntt_res, & modulus ) ) ;
246+ let _ = MatPolynomialRingZq :: from ( & mut ntt_res) ;
255247 } )
256248 } ,
257249 ) ;
@@ -291,7 +283,6 @@ pub fn get_rbe_setup() -> ModulusPolynomialRingZq {
291283/// `n=256`, `q = 12289` and `zeta = 1945`
292284pub fn bench_mat_ntt_rbe_params_with_ntt ( c : & mut Criterion ) {
293285 let modulus = get_rbe_setup ( ) ;
294- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
295286
296287 let p1 = MatPolynomialRingZq :: sample_uniform ( 1 , 2 , & modulus) ;
297288 let p2 = MatPolynomialRingZq :: sample_uniform ( 2 , 12 , & modulus) ;
@@ -300,15 +291,14 @@ pub fn bench_mat_ntt_rbe_params_with_ntt(c: &mut Criterion) {
300291 let ntt2 = MatNTTPolynomialRingZq :: from ( & p2) ;
301292
302293 c. bench_function ( "MatPolynomialRingZq Multiplication with NTT (RBE)" , |b| {
303- b. iter ( || ntt1 . mul ( & ntt2 , & mod_q ) )
294+ b. iter ( || & ntt1 * & ntt2 )
304295 } ) ;
305296}
306297
307298/// benchmark multiplication in typical RBE parameter set with NTT and Transforms
308299/// `n=256`, `q = 12289` and `zeta = 1945`
309300pub fn bench_mat_ntt_rbe_params_with_ntt_and_transforms ( c : & mut Criterion ) {
310301 let modulus = get_rbe_setup ( ) ;
311- let mod_q = Modulus :: from ( modulus. get_q ( ) ) ;
312302
313303 let p1 = MatPolynomialRingZq :: sample_uniform ( 1 , 2 , & modulus) ;
314304 let p2 = MatPolynomialRingZq :: sample_uniform ( 2 , 12 , & modulus) ;
@@ -320,9 +310,9 @@ pub fn bench_mat_ntt_rbe_params_with_ntt_and_transforms(c: &mut Criterion) {
320310 let ntt1 = MatNTTPolynomialRingZq :: from ( & p1) ;
321311 let ntt2 = MatNTTPolynomialRingZq :: from ( & p2) ;
322312
323- let mut ntt_res = ntt1 . mul ( & ntt2 , & mod_q ) ;
313+ let mut ntt_res = & ntt1 * & ntt2 ;
324314
325- let _ = MatPolynomialRingZq :: from ( ( & mut ntt_res, & modulus ) ) ;
315+ let _ = MatPolynomialRingZq :: from ( & mut ntt_res) ;
326316 } )
327317 } ,
328318 ) ;
0 commit comments