proof_system/statement/
verifiable_encryption_tz_21.rs

1use crate::{
2    error::ProofSystemError,
3    prelude::{SetupParams, Statement},
4    setup_params::ElgamalEncryptionParams,
5};
6use ark_ec::{pairing::Pairing, AffineRepr};
7use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
8use ark_std::vec::Vec;
9use dock_crypto_utils::serde_utils::ArkObjectBytes;
10use serde::{Deserialize, Serialize};
11use serde_with::serde_as;
12
13#[serde_as]
14#[derive(
15    Clone, Debug, PartialEq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
16)]
17#[serde(bound = "")]
18pub struct VerifiableEncryptionTZ21<G: AffineRepr> {
19    pub enc_params: Option<ElgamalEncryptionParams<G>>,
20    pub enc_params_ref: Option<usize>,
21    #[serde_as(as = "Option<Vec<ArkObjectBytes>>")]
22    pub comm_key: Option<Vec<G>>,
23    pub comm_key_ref: Option<usize>,
24}
25
26impl<G: AffineRepr> VerifiableEncryptionTZ21<G> {
27    /// Get statement for DKGitH protocol
28    pub fn new_statement_from_params<E: Pairing<G1Affine = G>>(
29        enc_params: ElgamalEncryptionParams<G>,
30        comm_key: Vec<G>,
31    ) -> Statement<E> {
32        Statement::VeTZ21(Self {
33            enc_params: Some(enc_params),
34            comm_key: Some(comm_key),
35            enc_params_ref: None,
36            comm_key_ref: None,
37        })
38    }
39
40    /// Get statement for Robust DKGitH protocol
41    pub fn new_statement_from_params_for_robust<E: Pairing<G1Affine = G>>(
42        enc_params: ElgamalEncryptionParams<G>,
43        comm_key: Vec<G>,
44    ) -> Statement<E> {
45        Statement::VeTZ21Robust(Self {
46            enc_params: Some(enc_params),
47            comm_key: Some(comm_key),
48            enc_params_ref: None,
49            comm_key_ref: None,
50        })
51    }
52
53    /// Get statement for DKGitH protocol
54    pub fn new_statement_from_params_ref<E: Pairing<G1Affine = G>>(
55        enc_params: usize,
56        comm_key: usize,
57    ) -> Statement<E> {
58        Statement::VeTZ21(Self {
59            enc_params: None,
60            comm_key: None,
61            enc_params_ref: Some(enc_params),
62            comm_key_ref: Some(comm_key),
63        })
64    }
65
66    /// Get statement for Robust DKGitH protocol
67    pub fn new_statement_from_params_ref_for_robust<E: Pairing<G1Affine = G>>(
68        enc_params: usize,
69        comm_key: usize,
70    ) -> Statement<E> {
71        Statement::VeTZ21Robust(Self {
72            enc_params: None,
73            comm_key: None,
74            enc_params_ref: Some(enc_params),
75            comm_key_ref: Some(comm_key),
76        })
77    }
78
79    pub fn get_comm_key<'a, E: Pairing<G1Affine = G>>(
80        &'a self,
81        setup_params: &'a [SetupParams<E>],
82        st_idx: usize,
83    ) -> Result<&'a Vec<G>, ProofSystemError> {
84        extract_param!(
85            setup_params,
86            &self.comm_key,
87            self.comm_key_ref,
88            PedersenCommitmentKey,
89            IncompatibleBoundCheckSetupParamAtIndex,
90            st_idx
91        )
92    }
93
94    pub fn get_enc_params<'a, E: Pairing<G1Affine = G>>(
95        &'a self,
96        setup_params: &'a [SetupParams<E>],
97        st_idx: usize,
98    ) -> Result<&'a ElgamalEncryptionParams<G>, ProofSystemError> {
99        extract_param!(
100            setup_params,
101            &self.enc_params,
102            self.enc_params_ref,
103            ElgamalEncryption,
104            IncompatibleBoundCheckSetupParamAtIndex,
105            st_idx
106        )
107    }
108}