|
1 | 1 | //! Proof of knowledge of the signature and corresponding messages as per section 4.5 of the paper |
2 | | -//! <https://eprint.iacr.org/2016/663.pdf> |
3 | 2 | //! # Examples |
4 | 3 | //! |
5 | 4 | //! Creating proof of knowledge of signature and verifying it: |
|
14 | 13 | //! let params_g1 = SignatureParamsG1::<Bls12_381>::generate_using_rng(&mut rng, 5); |
15 | 14 | //! let keypair_g2 = KeypairG2::<Bls12_381>::generate(&mut rng, ¶ms_g1); |
16 | 15 | //! |
| 16 | +//! let pk_g2 = &keypair_g2.public_key; |
| 17 | +//! |
| 18 | +//! // Verifiers should check that the signature parameters and public key are valid before verifying |
| 19 | +//! // any signatures. This just needs to be done once when the verifier fetches/receives them. |
| 20 | +//! |
| 21 | +//! assert!(params_g1.is_valid()); |
| 22 | +//! assert!(pk_g2.is_valid()); |
| 23 | +//! |
17 | 24 | //! // `messages` contains elements of the scalar field |
18 | 25 | //! let sig_g1 = SignatureG1::<Bls12_381>::new(&mut rng, &messages, &keypair_g2.secret_key, ¶ms_g1).unwrap(); |
| 26 | +//! |
19 | 27 | //! let mut blindings = BTreeMap::new(); |
20 | 28 | //! let mut revealed_indices = BTreeSet::new(); |
21 | | -//! // Populate blindings with message index and corresponding blinding |
22 | | -//! // Populate revealed_indices with 0-based indices of revealed messages |
| 29 | +//! |
| 30 | +//! // Populate `blindings` with message index and corresponding blinding |
| 31 | +//! // Populate `revealed_indices` with 0-based indices of revealed messages |
| 32 | +//! |
23 | 33 | //! let pok = PoKOfSignatureG1Protocol::init( |
24 | 34 | //! &mut rng, |
25 | 35 | //! &sig_g1, |
|
38 | 48 | //! .verify( |
39 | 49 | //! &revealed_msgs, |
40 | 50 | //! &challenge, |
41 | | -//! &keypair_g2.public_key, |
| 51 | +//! pk_g2, |
42 | 52 | //! ¶ms_g1, |
43 | 53 | //! ) |
44 | 54 | //! .unwrap(); |
@@ -67,6 +77,7 @@ use schnorr_pok::{error::SchnorrError, SchnorrCommitment, SchnorrResponse}; |
67 | 77 | use serde::{Deserialize, Serialize}; |
68 | 78 | use serde_with::serde_as; |
69 | 79 | pub use serialization::*; |
| 80 | +use zeroize::Zeroize; |
70 | 81 |
|
71 | 82 | /// Proof of knowledge of BBS+ signature in group G1 |
72 | 83 | /// The BBS+ signature proves validity of a set of messages {m_i}, i in I. This stateful protocol proves knowledge of such |
@@ -334,11 +345,28 @@ where |
334 | 345 | } |
335 | 346 | } |
336 | 347 |
|
| 348 | +impl<E: PairingEngine> Zeroize for PoKOfSignatureG1Protocol<E> { |
| 349 | + fn zeroize(&mut self) { |
| 350 | + // Other members of `self` are public anyway |
| 351 | + self.sc_comm_1.zeroize(); |
| 352 | + self.sc_wits_1.zeroize(); |
| 353 | + self.sc_comm_2.zeroize(); |
| 354 | + self.sc_wits_2.zeroize(); |
| 355 | + } |
| 356 | +} |
| 357 | + |
| 358 | +impl<E: PairingEngine> Drop for PoKOfSignatureG1Protocol<E> { |
| 359 | + fn drop(&mut self) { |
| 360 | + self.zeroize(); |
| 361 | + } |
| 362 | +} |
| 363 | + |
337 | 364 | impl<E> PoKOfSignatureG1Proof<E> |
338 | 365 | where |
339 | 366 | E: PairingEngine, |
340 | 367 | { |
341 | | - /// Verify if the proof is valid |
| 368 | + /// Verify if the proof is valid. Assumes that the public key and parameters have been |
| 369 | + /// validated already. |
342 | 370 | pub fn verify( |
343 | 371 | &self, |
344 | 372 | revealed_msgs: &BTreeMap<usize, E::Fr>, |
@@ -675,22 +703,23 @@ mod tests { |
675 | 703 | let proof = pok.gen_proof(&challenge_prover).unwrap(); |
676 | 704 | proof_create_duration += start.elapsed(); |
677 | 705 |
|
| 706 | + let public_key = &keypair.public_key; |
| 707 | + assert!(params.is_valid()); |
| 708 | + assert!(public_key.is_valid()); |
| 709 | + |
678 | 710 | let mut chal_bytes_verifier = vec![]; |
679 | 711 | proof |
680 | 712 | .challenge_contribution(&revealed_msgs, ¶ms, &mut chal_bytes_verifier) |
681 | 713 | .unwrap(); |
682 | 714 | let challenge_verifier = |
683 | 715 | compute_random_oracle_challenge::<Fr, Blake2b>(&chal_bytes_verifier); |
684 | 716 |
|
| 717 | + assert_eq!(chal_bytes_prover, chal_bytes_verifier); |
| 718 | + |
685 | 719 | let mut proof_verif_duration = Duration::default(); |
686 | 720 | let start = Instant::now(); |
687 | 721 | proof |
688 | | - .verify( |
689 | | - &revealed_msgs, |
690 | | - &challenge_verifier, |
691 | | - &keypair.public_key, |
692 | | - ¶ms, |
693 | | - ) |
| 722 | + .verify(&revealed_msgs, &challenge_verifier, public_key, ¶ms) |
694 | 723 | .unwrap(); |
695 | 724 | proof_verif_duration += start.elapsed(); |
696 | 725 |
|
|
0 commit comments