@@ -84,15 +84,17 @@ pub(crate) fn sign<
84
84
85
85
// Extract from expand_private()
86
86
let PrivateKey {
87
- rho : _ ,
87
+ rho,
88
88
cap_k,
89
89
tr,
90
90
s_hat_1_mont,
91
91
s_hat_2_mont,
92
92
t_hat_0_mont,
93
- cap_a_hat,
93
+ // cap_a_hat,
94
94
} = esk;
95
95
96
+ let cap_a_hat: [ [ T ; L ] ; K ] = expand_a :: < CTEST , K , L > ( rho) ;
97
+
96
98
// 6: 𝜇 ← H(BytesToBits(𝑡𝑟)||𝑀 , 64) ▷ Compute message representative µ
97
99
// We may have arrived from 3 different paths
98
100
let mut h6 = if nist {
@@ -134,7 +136,7 @@ pub(crate) fn sign<
134
136
// 12: w ← NTT−1(cap_a_hat ◦ NTT(y))
135
137
let w: [ R ; K ] = {
136
138
let y_hat: [ T ; L ] = ntt ( & y) ;
137
- let ay_hat: [ T ; K ] = mat_vec_mul ( cap_a_hat, & y_hat) ;
139
+ let ay_hat: [ T ; K ] = mat_vec_mul ( & cap_a_hat, & y_hat) ;
138
140
inv_ntt ( & ay_hat)
139
141
} ;
140
142
@@ -259,6 +261,7 @@ pub(crate) fn sign<
259
261
/// Continuation of `verify_start()`. The `lib.rs` wrapper around this will convert `Error()` to false.
260
262
#[ allow( clippy:: too_many_arguments, clippy:: similar_names) ]
261
263
pub ( crate ) fn verify <
264
+ const CTEST : bool ,
262
265
const K : usize ,
263
266
const L : usize ,
264
267
const LAMBDA_DIV4 : usize ,
@@ -270,7 +273,8 @@ pub(crate) fn verify<
270
273
sig : & [ u8 ; SIG_LEN ] , ctx : & [ u8 ] , oid : & [ u8 ] , phm : & [ u8 ] , nist : bool ,
271
274
) -> Result < bool , & ' static str > {
272
275
//
273
- let PublicKey { rho : _, cap_a_hat, tr, t1_d2_hat_mont } = epk;
276
+ //let PublicKey { rho: _, cap_a_hat, tr, t1_d2_hat_mont } = epk;
277
+ let PublicKey { rho, tr, t1_d2_hat_mont } = epk;
274
278
275
279
// 1: (ρ, t_1) ← pkDecode(pk)
276
280
// --> calculated in expand_public()
@@ -314,8 +318,10 @@ pub(crate) fn verify<
314
318
315
319
// 9: w′_Approx ← invNTT(cap_A_hat ◦ NTT(z) - NTT(c) ◦ NTT(t_1 · 2^d) ▷ w′_Approx = Az − ct1·2^d
316
320
let wp_approx: [ R ; K ] = {
321
+ // hardcode CTEST as false since everything is public here
322
+ let cap_a_hat: [ [ T ; L ] ; K ] = expand_a :: < CTEST , K , L > ( rho) ;
317
323
let z_hat: [ T ; L ] = ntt ( & z) ;
318
- let az_hat: [ T ; K ] = mat_vec_mul ( cap_a_hat, & z_hat) ;
324
+ let az_hat: [ T ; K ] = mat_vec_mul ( & cap_a_hat, & z_hat) ;
319
325
// NTT(t_1 · 2^d) --> calculated in expand_public()
320
326
let c_hat: & T = & ntt ( & [ c] ) [ 0 ] ;
321
327
inv_ntt ( & core:: array:: from_fn ( |k| {
@@ -378,22 +384,22 @@ pub(crate) fn key_gen_internal<
378
384
379
385
// There is effectively no step 2 due to formatting error in spec
380
386
381
- // 3: cap_a_hat ← ExpandA(ρ) ▷ A is generated and stored in NTT representation as Â
382
- let cap_a_hat: [ [ T ; L ] ; K ] = expand_a :: < CTEST , K , L > ( & rho) ;
383
-
384
387
// 4: (s_1, s_2) ← ExpandS(ρ′)
385
388
let ( s_1, s_2) : ( [ R ; L ] , [ R ; K ] ) = expand_s :: < CTEST , K , L > ( eta, & rho_prime) ;
386
389
390
+ // 3: cap_a_hat ← ExpandA(ρ) ▷ A is generated and stored in NTT representation as Â
387
391
// 5: t ← NTT−1(cap_a_hat ◦ NTT(s_1)) + s_2 ▷ Compute t = As1 + s2
388
- //let t: [R; K]
389
- let s_1_hat: [ T ; L ] = ntt ( & s_1) ;
390
- let as1_hat: [ T ; K ] = mat_vec_mul ( & cap_a_hat, & s_1_hat) ;
391
- let t_not_reduced: [ R ; K ] = add_vector_ntt ( & inv_ntt ( & as1_hat) , & s_2) ;
392
- let t: [ R ; K ] =
393
- core:: array:: from_fn ( |k| R ( core:: array:: from_fn ( |n| full_reduce32 ( t_not_reduced[ k] . 0 [ n] ) ) ) ) ;
394
-
395
392
// 6: (t_1, t_0) ← Power2Round(t, d) ▷ Compress t
396
- let ( t_1, t_0) : ( [ R ; K ] , [ R ; K ] ) = power2round ( & t) ;
393
+
394
+ let ( t_1, t_0) : ( [ R ; K ] , [ R ; K ] ) = {
395
+ let cap_a_hat: [ [ T ; L ] ; K ] = expand_a :: < CTEST , K , L > ( & rho) ;
396
+ let s_1_hat: [ T ; L ] = ntt ( & s_1) ;
397
+ let as1_hat: [ T ; K ] = mat_vec_mul ( & cap_a_hat, & s_1_hat) ;
398
+ let t_not_reduced: [ R ; K ] = add_vector_ntt ( & inv_ntt ( & as1_hat) , & s_2) ;
399
+ let t: [ R ; K ] =
400
+ core:: array:: from_fn ( |k| R ( core:: array:: from_fn ( |n| full_reduce32 ( t_not_reduced[ k] . 0 [ n] ) ) ) ) ;
401
+ power2round ( & t)
402
+ } ;
397
403
398
404
// There is effectively no step 7 due to formatting error in spec
399
405
@@ -414,10 +420,12 @@ pub(crate) fn key_gen_internal<
414
420
let t1_d2_hat_mont: [ T ; K ] = to_mont ( & core:: array:: from_fn ( |k| {
415
421
T ( core:: array:: from_fn ( |n| mont_reduce ( i64:: from ( t1_hat_mont[ k] . 0 [ n] ) << D ) ) )
416
422
} ) ) ;
417
- let pk = PublicKey { rho, cap_a_hat : cap_a_hat. clone ( ) , tr, t1_d2_hat_mont } ;
423
+ //let pk = PublicKey { rho, cap_a_hat: cap_a_hat.clone(), tr, t1_d2_hat_mont };
424
+ let pk = PublicKey { rho, tr, t1_d2_hat_mont } ;
418
425
419
426
// 2: s_hat_1 ← NTT(s_1)
420
- let s_hat_1_mont: [ T ; L ] = to_mont ( & s_1_hat) ; //ntt(&s_1));
427
+ //let s_hat_1_mont: [T; L] = to_mont(&s_1_hat); //ntt(&s_1));
428
+ let s_hat_1_mont: [ T ; L ] = to_mont ( & ntt ( & s_1) ) ;
421
429
// 3: s_hat_2 ← NTT(s_2)
422
430
let s_hat_2_mont: [ T ; K ] = to_mont ( & ntt ( & s_2) ) ;
423
431
// 4: t_hat_0 ← NTT(t_0)
@@ -429,7 +437,7 @@ pub(crate) fn key_gen_internal<
429
437
s_hat_1_mont,
430
438
s_hat_2_mont,
431
439
t_hat_0_mont,
432
- cap_a_hat,
440
+ // cap_a_hat,
433
441
} ;
434
442
435
443
// 11: return (pk, sk)
@@ -463,7 +471,7 @@ pub(crate) fn expand_private<
463
471
let t_hat_0_mont: [ T ; K ] = to_mont ( & ntt ( & t_0) ) ;
464
472
465
473
// 5: cap_a_hat ← ExpandA(ρ) ▷ A is generated and stored in NTT representation as Â
466
- let cap_a_hat: [ [ T ; L ] ; K ] = expand_a :: < CTEST , K , L > ( rho) ;
474
+ // let cap_a_hat: [[T; L]; K] = expand_a::<CTEST, K, L>(rho);
467
475
468
476
Ok ( PrivateKey {
469
477
rho : * rho,
@@ -472,7 +480,7 @@ pub(crate) fn expand_private<
472
480
s_hat_1_mont,
473
481
s_hat_2_mont,
474
482
t_hat_0_mont,
475
- cap_a_hat,
483
+ // cap_a_hat,
476
484
} )
477
485
}
478
486
@@ -489,7 +497,7 @@ pub(crate) fn expand_public<const K: usize, const L: usize, const PK_LEN: usize>
489
497
let ( rho, t_1) : ( & [ u8 ; 32 ] , [ R ; K ] ) = pk_decode ( pk) ?;
490
498
491
499
// 5: cap_a_hat ← ExpandA(ρ) ▷ A is generated and stored in NTT representation as cap_A_hat
492
- let cap_a_hat: [ [ T ; L ] ; K ] = expand_a :: < false , K , L > ( rho) ;
500
+ // let cap_a_hat: [[T; L]; K] = expand_a::<false, K, L>(rho);
493
501
494
502
// 6: tr ← H(pk, 64)
495
503
let mut h6 = h256_xof ( & [ pk] ) ;
@@ -503,5 +511,6 @@ pub(crate) fn expand_public<const K: usize, const L: usize, const PK_LEN: usize>
503
511
T ( core:: array:: from_fn ( |n| mont_reduce ( i64:: from ( t1_hat_mont[ k] . 0 [ n] ) << D ) ) )
504
512
} ) ) ;
505
513
506
- Ok ( PublicKey { rho : * rho, cap_a_hat, tr, t1_d2_hat_mont } )
514
+ //Ok(PublicKey { rho: *rho, cap_a_hat, tr, t1_d2_hat_mont })
515
+ Ok ( PublicKey { rho : * rho, tr, t1_d2_hat_mont } )
507
516
}
0 commit comments