composite_modulus_proofs 0.1.0

Proofs about several propoerties of a composite modulus - square-free, product of 2 primes, a blum integer
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
//! Proof that `gcd(x, phi(N)) = 1` where `x` is coprime to a composite `N` and `phi` is the Euler's totient
//! Described in section 3.1 of the paper [Efficient Noninteractive Certification of RSA Moduli and Beyond](https://eprint.iacr.org/2018/057)

use crate::{
    error::Error,
    join,
    math::{
        misc::{crt_combine, euler_totient},
        prime_check::is_divisible_by_prime_upto,
    },
    setup::{Modulus, Primes, PrimesWithPrecomp},
    util::{log_base_2, uint_le_bytes},
};
use alloc::vec;
use ark_std::{cfg_into_iter, cfg_iter_mut, io::Write};
use crypto_bigint::{
    modular::{MontyForm, MontyParams, SafeGcdInverter},
    Concat, Odd, PrecomputeInverter, Split, Uint,
};
use digest::{ExtendableOutput, Update};

use crate::util::get_inv_mod_p_minus_1_and_q_minus_1;
#[cfg(feature = "parallel")]
use rayon::prelude::*;

/// Proof that `gcd(x, phi(N)) = 1`. `NUM_CHALLENGES` depends on `ALPHA` and `KAPPA` as per the paper but can also
/// be set independently as done in another protocol
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProofGcdIsOne<
    const MODULUS_LIMBS: usize,
    const NUM_CHALLENGES: usize,
    const ALPHA: usize,
    const KAPPA: usize,
>(
    /// Responses to the challenges
    pub [Uint<MODULUS_LIMBS>; NUM_CHALLENGES],
);

impl<
        const MODULUS_LIMBS: usize,
        const NUM_CHALLENGES: usize,
        const ALPHA: usize,
        const KAPPA: usize,
    > ProofGcdIsOne<MODULUS_LIMBS, NUM_CHALLENGES, ALPHA, KAPPA>
{
    /// Create a proof that `gcd(x, phi(N)) = 1`. `transcript` is the proof transcript that is shared by
    /// other sub-protocols as well which this is running as a sub-protocol of a larger protocol.
    pub fn new<
        D: Default + Update + ExtendableOutput,
        W: Write + AsRef<[u8]>,
        const PRIME_LIMBS: usize,
        const MODULUS_UNSAT_LIMBS: usize,
    >(
        x: &Uint<MODULUS_LIMBS>,
        primes: Primes<PRIME_LIMBS>,
        modulus: &Modulus<MODULUS_LIMBS>,
        nonce: &[u8],
        transcript: &mut W,
    ) -> Result<Self, Error>
    where
        Uint<PRIME_LIMBS>: Concat<Output = Uint<MODULUS_LIMBS>>,
        Odd<Uint<MODULUS_LIMBS>>:
            PrecomputeInverter<Inverter = SafeGcdInverter<MODULUS_LIMBS, MODULUS_UNSAT_LIMBS>>,
    {
        let (proof, _) = Self::new_and_return_challenges::<D, W, PRIME_LIMBS, MODULUS_UNSAT_LIMBS>(
            x, primes, modulus, nonce, transcript,
        )?;
        Ok(proof)
    }

    /// Same as `Self::new` but returns the challenges used to create the proof. Useful when used with certain other protocols
    pub fn new_and_return_challenges<
        D: Default + Update + ExtendableOutput,
        W: Write + AsRef<[u8]>,
        const PRIME_LIMBS: usize,
        const MODULUS_UNSAT_LIMBS: usize,
    >(
        x: &Uint<MODULUS_LIMBS>,
        primes: Primes<PRIME_LIMBS>,
        modulus: &Modulus<MODULUS_LIMBS>,
        nonce: &[u8],
        transcript: &mut W,
    ) -> Result<(Self, [Uint<MODULUS_LIMBS>; NUM_CHALLENGES]), Error>
    where
        Uint<PRIME_LIMBS>: Concat<Output = Uint<MODULUS_LIMBS>>,
        Odd<Uint<MODULUS_LIMBS>>:
            PrecomputeInverter<Inverter = SafeGcdInverter<MODULUS_LIMBS, MODULUS_UNSAT_LIMBS>>,
    {
        let phi = euler_totient(&primes.p, &primes.q);
        let x_inv = x.inv_mod(&phi);
        if x_inv.is_none().into() {
            // gcd(x, phi(N)) isn't 1
            return Err(Error::NotInvertible);
        }
        let x_inv = x_inv.unwrap();
        let challenges = Self::challenges::<D, W>(x, modulus, nonce, transcript);
        let mut responses = [Uint::<MODULUS_LIMBS>::ZERO; NUM_CHALLENGES];
        let params = MontyParams::new_vartime(modulus.0);
        cfg_iter_mut!(responses).enumerate().for_each(|(i, s)| {
            *s = MontyForm::new(&challenges[i], params)
                .pow(&x_inv)
                .retrieve();
        });
        Ok((Self(responses), challenges))
    }

    /// Same as `Self::new` but takes the primes and some precomputation to make the proof generation is faster.
    /// Use it if creating frequent proofs.
    pub fn new_given_precomputation<
        D: Default + Update + ExtendableOutput,
        W: Write + AsRef<[u8]>,
        const PRIME_LIMBS: usize,
        const PRIME_UNSAT_LIMBS: usize,
    >(
        x: &Uint<MODULUS_LIMBS>,
        primes: PrimesWithPrecomp<PRIME_LIMBS, MODULUS_LIMBS>,
        modulus: &Modulus<MODULUS_LIMBS>,
        nonce: &[u8],
        transcript: &mut W,
    ) -> Result<Self, Error>
    where
        Uint<PRIME_LIMBS>: Concat<Output = Uint<MODULUS_LIMBS>>,
        Uint<MODULUS_LIMBS>: Split<Output = Uint<PRIME_LIMBS>>,
        Odd<Uint<PRIME_LIMBS>>: PrecomputeInverter<
            Inverter = SafeGcdInverter<PRIME_LIMBS, PRIME_UNSAT_LIMBS>,
            Output = Uint<PRIME_LIMBS>,
        >,
    {
        let (proof, _) = Self::new_given_precomputation_and_return_challenges::<
            D,
            W,
            PRIME_LIMBS,
            PRIME_UNSAT_LIMBS,
        >(x, primes, modulus, nonce, transcript)?;
        Ok(proof)
    }

    /// Same as `Self::new_given_precomputation` but takes `x^-1 mod p-1` and `x^-1 mod q-1` as well.
    pub fn new_given_x_inv_and_precomputation<
        D: Default + Update + ExtendableOutput,
        W: Write + AsRef<[u8]>,
        const PRIME_LIMBS: usize,
    >(
        x: &Uint<MODULUS_LIMBS>,
        x_inv_p_minus_1: &Uint<PRIME_LIMBS>,
        x_inv_q_minus_1: &Uint<PRIME_LIMBS>,
        primes: PrimesWithPrecomp<PRIME_LIMBS, MODULUS_LIMBS>,
        modulus: &Modulus<MODULUS_LIMBS>,
        nonce: &[u8],
        transcript: &mut W,
    ) -> Result<Self, Error>
    where
        Uint<PRIME_LIMBS>: Concat<Output = Uint<MODULUS_LIMBS>>,
        Uint<MODULUS_LIMBS>: Split<Output = Uint<PRIME_LIMBS>>,
    {
        let (proof, _) =
            Self::new_given_x_inv_and_precomputation_and_return_challenges::<D, W, PRIME_LIMBS>(
                x,
                x_inv_p_minus_1,
                x_inv_q_minus_1,
                primes,
                modulus,
                nonce,
                transcript,
            )?;
        Ok(proof)
    }

    /// Same as `Self::new_given_precomputation` but returns the challenges used to create the proof. Useful when used with certain other protocols
    pub fn new_given_precomputation_and_return_challenges<
        D: Default + Update + ExtendableOutput,
        W: Write + AsRef<[u8]>,
        const PRIME_LIMBS: usize,
        const PRIME_UNSAT_LIMBS: usize,
    >(
        x: &Uint<MODULUS_LIMBS>,
        primes: PrimesWithPrecomp<PRIME_LIMBS, MODULUS_LIMBS>,
        modulus: &Modulus<MODULUS_LIMBS>,
        nonce: &[u8],
        transcript: &mut W,
    ) -> Result<(Self, [Uint<MODULUS_LIMBS>; NUM_CHALLENGES]), Error>
    where
        Uint<PRIME_LIMBS>: Concat<Output = Uint<MODULUS_LIMBS>>,
        Uint<MODULUS_LIMBS>: Split<Output = Uint<PRIME_LIMBS>>,
        Odd<Uint<PRIME_LIMBS>>: PrecomputeInverter<
            Inverter = SafeGcdInverter<PRIME_LIMBS, PRIME_UNSAT_LIMBS>,
            Output = Uint<PRIME_LIMBS>,
        >,
    {
        // As x^-1 will be the exponent when computing mod p and mod q using CRT, reduce x^-1 mod p-1 and mod q-1 as per Fermat's little theorem
        // x_inv_p_minus_1 = x^-1 mod p-1, x_inv_q_minus_1 = x^-1 mod q-1
        let (x_inv_p_minus_1, x_inv_q_minus_1) = get_inv_mod_p_minus_1_and_q_minus_1(
            &x,
            primes.p_mtg.modulus(),
            primes.q_mtg.modulus(),
        )?;
        Self::new_given_x_inv_and_precomputation_and_return_challenges::<D, W, PRIME_LIMBS>(
            x,
            &x_inv_p_minus_1,
            &x_inv_q_minus_1,
            primes,
            modulus,
            nonce,
            transcript,
        )
    }

    /// Same as `Self::new_given_precomputation_and_return_challenges` but takes `x^-1 mod p-1` and `x^-1 mod q-1` as well.
    pub fn new_given_x_inv_and_precomputation_and_return_challenges<
        D: Default + Update + ExtendableOutput,
        W: Write + AsRef<[u8]>,
        const PRIME_LIMBS: usize,
    >(
        x: &Uint<MODULUS_LIMBS>,
        x_inv_p_minus_1: &Uint<PRIME_LIMBS>,
        x_inv_q_minus_1: &Uint<PRIME_LIMBS>,
        primes: PrimesWithPrecomp<PRIME_LIMBS, MODULUS_LIMBS>,
        modulus: &Modulus<MODULUS_LIMBS>,
        nonce: &[u8],
        transcript: &mut W,
    ) -> Result<(Self, [Uint<MODULUS_LIMBS>; NUM_CHALLENGES]), Error>
    where
        Uint<PRIME_LIMBS>: Concat<Output = Uint<MODULUS_LIMBS>>,
        Uint<MODULUS_LIMBS>: Split<Output = Uint<PRIME_LIMBS>>,
    {
        let challenges = Self::challenges::<D, W>(x, modulus, nonce, transcript);
        let mut responses = [Uint::<MODULUS_LIMBS>::ZERO; NUM_CHALLENGES];

        cfg_iter_mut!(responses).enumerate().for_each(|(i, s)| {
            let (resp_p, resp_q) = join!(
                {
                    let c_p = MontyForm::new(&challenges[i], primes.p_mtg_1)
                        .retrieve()
                        .resize();
                    MontyForm::new(&c_p, primes.p_mtg)
                        .pow(x_inv_p_minus_1)
                        .retrieve()
                },
                {
                    let c_q = MontyForm::new(&challenges[i], primes.q_mtg_1)
                        .retrieve()
                        .resize();
                    MontyForm::new(&c_q, primes.q_mtg)
                        .pow(x_inv_q_minus_1)
                        .retrieve()
                }
            );
            *s = crt_combine::<PRIME_LIMBS, MODULUS_LIMBS>(
                &resp_p,
                &resp_q,
                primes.p_inv,
                primes.p_mtg.modulus(),
                primes.q_mtg,
            );
        });
        Ok((Self(responses), challenges))
    }

    pub fn num_responses(&self) -> usize {
        self.0.len()
    }

    /// Verify the proof that `gcd(x, phi(N)) = 1`. `transcript` is the proof transcript that is shared by
    /// other sub-protocols as well which this is running as a sub-protocol of a larger protocol.
    pub fn verify<D: Default + Update + ExtendableOutput, W: Write + AsRef<[u8]>>(
        &self,
        x: &Uint<MODULUS_LIMBS>,
        modulus: &Modulus<MODULUS_LIMBS>,
        nonce: &[u8],
        transcript: &mut W,
    ) -> Result<(), Error> {
        let (res, _) = self.verify_and_return_challenges::<D, W>(x, modulus, nonce, transcript)?;
        Ok(res)
    }

    /// Same as `Self::verify` but returns the challenges used to create the proof. Useful when used with certain other protocols
    pub fn verify_and_return_challenges<
        D: Default + Update + ExtendableOutput,
        W: Write + AsRef<[u8]>,
    >(
        &self,
        x: &Uint<MODULUS_LIMBS>,
        modulus: &Modulus<MODULUS_LIMBS>,
        nonce: &[u8],
        transcript: &mut W,
    ) -> Result<((), [Uint<MODULUS_LIMBS>; NUM_CHALLENGES]), Error> {
        if let Some(i) = is_divisible_by_prime_upto(&modulus.0, ALPHA as u32) {
            return Err(Error::DivisibleByPrime(i));
        }
        let challenges = Self::challenges::<D, W>(x, modulus, nonce, transcript);
        let params = MontyParams::new_vartime(modulus.0);
        #[allow(unused_mut)]
        let mut res = cfg_into_iter!(0..NUM_CHALLENGES).map(|i| {
            if !modulus.is_greater_than(&self.0[i]) {
                return Err(Error::GreaterThanModulus(i as u32));
            }
            if MontyForm::new(&self.0[i], params).pow(x).retrieve() != challenges[i] {
                return Err(Error::InvalidProofForIndex(i as u32));
            }
            Ok(())
        });

        let res = report_error_if_any!(res)?;
        Ok((res, challenges))
    }

    /// Generate challenges by rejection sampling
    pub fn challenges<D: Default + Update + ExtendableOutput, W: Write + AsRef<[u8]>>(
        x: &Uint<MODULUS_LIMBS>,
        modulus: &Modulus<MODULUS_LIMBS>,
        nonce: &[u8],
        transcript: &mut W,
    ) -> [Uint<MODULUS_LIMBS>; NUM_CHALLENGES] {
        let mut chals = [Uint::<MODULUS_LIMBS>::ZERO; NUM_CHALLENGES];
        let mut ctr = 0;
        transcript.write_all(b"proof-of-gcd-is-1").unwrap();
        transcript.write_all(&uint_le_bytes(x)).unwrap();
        transcript.write_all(&uint_le_bytes(&modulus.0)).unwrap();
        // Not hashing in MODULUS_LIMBS since it can change if proof generation and verification happen on different arch. (64 bit vs 32 bit)
        transcript
            .write_all(modulus.size_for_hashing().as_slice())
            .unwrap();
        transcript.write_all(nonce).unwrap();
        let mut c_bytes = vec![0; Uint::<MODULUS_LIMBS>::BYTES];
        let mut i = 0_u32;
        while ctr < NUM_CHALLENGES as u32 {
            transcript.write_all(i.to_le_bytes().as_slice()).unwrap();
            D::digest_xof(transcript.as_ref(), &mut c_bytes);
            let c = Uint::<MODULUS_LIMBS>::from_le_slice(&c_bytes);
            if modulus.is_greater_than(&c) {
                chals[ctr as usize] = c;
                ctr += 1;
            }
            i += 1;
        }
        chals
    }
}

pub const fn num_challenges<const ALPHA: usize, const KAPPA: usize>() -> u32 {
    let l = log_base_2::<ALPHA>();
    ((l + KAPPA - 1) / l) as u32
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{
        safegcd_nlimbs,
        util::{get_1024_bit_primes, get_2048_bit_primes, get_coprime, timing_info},
    };
    use core::ops::Sub;
    use crypto_bigint::{U1024, U128, U2048, U256, U64};
    use rand_core::OsRng;
    use sha3::Shake256;
    use std::{ops::Add, time::Instant};

    macro_rules! check_given_primes {
        ( $num_iters: ident, $prime_type:ident, $primes: ident ) => {
            const KAPPA: usize = 128;
            const ALPHA: usize = 65537;
            const NUM_CHALLENGES: usize = num_challenges::<ALPHA, KAPPA>() as usize;

            const PRIME_LIMBS: usize = $prime_type::LIMBS;
            const PRIME_UNSAT_LIMBS: usize = safegcd_nlimbs!(Uint::<PRIME_LIMBS>::BITS as usize);
            const MODULUS_LIMBS: usize = PRIME_LIMBS * 2;
            const MODULUS_UNSAT_LIMBS: usize =
                safegcd_nlimbs!(Uint::<MODULUS_LIMBS>::BITS as usize);

            let mut rng = OsRng::default();
            let modulus = Modulus::<MODULUS_LIMBS>::new(&$primes);
            let primes_with_crt = PrimesWithPrecomp::from($primes.clone());
            let phi = euler_totient(&$primes.p, &$primes.q);
            let nonce = b"123";

            let mut prove_times = vec![];
            let mut prove_crt_times = vec![];
            let mut ver_times = vec![];

            println!(
                "Running {} iterations for {} bits prime",
                $num_iters,
                $prime_type::BITS
            );
            for _ in 0..$num_iters {
                let x = get_coprime(&mut rng, &phi, modulus.0.as_nz_ref());

                let mut transcript = vec![];
                let start = Instant::now();
                let proof = ProofGcdIsOne::<MODULUS_LIMBS, NUM_CHALLENGES, ALPHA, KAPPA>::new::<
                    Shake256,
                    _,
                    PRIME_LIMBS,
                    MODULUS_UNSAT_LIMBS,
                >(&x, $primes.clone(), &modulus, nonce, &mut transcript)
                .unwrap();
                prove_times.push(start.elapsed());

                assert_eq!(proof.num_responses(), NUM_CHALLENGES);

                let mut transcript = vec![];
                let start = Instant::now();
                proof
                    .verify::<Shake256, _>(&x, &modulus, nonce, &mut transcript)
                    .unwrap();
                ver_times.push(start.elapsed());

                let mut transcript = vec![];
                let start = Instant::now();
                let proof =
                    ProofGcdIsOne::<MODULUS_LIMBS, NUM_CHALLENGES, ALPHA, KAPPA>::new_given_precomputation::<
                        Shake256,
                        _,
                        PRIME_LIMBS,
                        PRIME_UNSAT_LIMBS,
                    >(
                        &x,
                        primes_with_crt.clone(),
                        &modulus,
                        nonce,
                        &mut transcript,
                    )
                    .unwrap();
                prove_crt_times.push(start.elapsed());

                assert_eq!(proof.num_responses(), NUM_CHALLENGES);

                let mut transcript = vec![];
                proof
                    .verify::<Shake256, _>(&x, &modulus, nonce, &mut transcript)
                    .unwrap();
            }

            println!("Proving time: {:?}", timing_info(prove_times));
            println!("Proving time with CRT: {:?}", timing_info(prove_crt_times));
            println!("Verification time: {:?}", timing_info(ver_times));
        };
    }

    #[test]
    fn bad_proofs() {
        const KAPPA: usize = 128;
        const ALPHA: usize = 65537;
        const NUM_CHALLENGES: usize = num_challenges::<ALPHA, KAPPA>() as usize;

        const PRIME_LIMBS: usize = U64::LIMBS;
        const MODULUS_LIMBS: usize = PRIME_LIMBS * 2;
        const MODULUS_UNSAT_LIMBS: usize = safegcd_nlimbs!(Uint::<MODULUS_LIMBS>::BITS as usize);

        let mut rng = OsRng::default();
        let primes = Primes::<PRIME_LIMBS>::new(&mut rng);
        let modulus = Modulus::<MODULUS_LIMBS>::new(&primes);
        let phi = euler_totient(&primes.p, &primes.q);

        let nonce = b"123";
        // Trying to invert p-1 should fail since its a factor of the totient
        let mut transcript = vec![];
        let x = primes.p.sub(&Uint::ONE).resize();
        assert!(matches!(
            ProofGcdIsOne::<MODULUS_LIMBS, NUM_CHALLENGES, ALPHA, KAPPA>::new::<
                Shake256,
                _,
                PRIME_LIMBS,
                MODULUS_UNSAT_LIMBS,
            >(&x, primes.clone(), &modulus, nonce, &mut transcript)
            .err()
            .unwrap(),
            Error::NotInvertible
        ));

        let x = get_coprime(&mut rng, &phi, modulus.0.as_nz_ref());
        let mut transcript = vec![];
        let mut proof = ProofGcdIsOne::<MODULUS_LIMBS, NUM_CHALLENGES, ALPHA, KAPPA>::new::<
            Shake256,
            _,
            PRIME_LIMBS,
            MODULUS_UNSAT_LIMBS,
        >(&x, primes.clone(), &modulus, nonce, &mut transcript)
        .unwrap();

        // Modulus is a multiple of a small prime
        let mut bad_modulus = modulus.clone();
        bad_modulus.0 = primes.p.widening_mul(&U64::from(5_u32)).to_odd().unwrap();
        let mut transcript = vec![];
        assert!(matches!(
            proof
                .verify::<Shake256, _>(&x, &bad_modulus, nonce, &mut transcript)
                .err()
                .unwrap(),
            Error::DivisibleByPrime(5)
        ));

        // Responses shouldn't be bigger than modulus
        proof.0[0] = modulus.0.as_nz_ref().add(&U128::ONE);
        let mut transcript = vec![];
        assert!(matches!(
            proof
                .verify::<Shake256, _>(&x, &modulus, nonce, &mut transcript)
                .err()
                .unwrap(),
            Error::GreaterThanModulus(0)
        ));

        // Responses should be valid
        proof.0[0] = proof.0[1];
        let mut transcript = vec![];
        assert!(matches!(
            proof
                .verify::<Shake256, _>(&x, &modulus, nonce, &mut transcript)
                .err()
                .unwrap(),
            Error::InvalidProofForIndex(0)
        ));
    }

    #[test]
    fn proof() {
        let mut rng = OsRng::default();
        let primes = Primes::<{ U256::LIMBS }>::new(&mut rng);
        let num_iters = 100;
        check_given_primes!(num_iters, U256, primes);
    }

    #[test]
    fn proof_with_1024_bit_primes() {
        let (p, q) = get_1024_bit_primes();
        let primes = Primes::from_primes(p, q);
        let num_iters = 10;
        check_given_primes!(num_iters, U1024, primes);
    }

    #[test]
    fn proof_with_2048_bit_primes() {
        let (p, q) = get_2048_bit_primes();
        let primes = Primes::from_primes(p, q);
        let num_iters = 10;
        check_given_primes!(num_iters, U2048, primes);
    }
}