Skip to main content

tfhe/core_crypto/algorithms/
lwe_zero_knowledge_verification.rs

1use crate::core_crypto::entities::{LweCompactCiphertextList, LweCompactPublicKey};
2use crate::core_crypto::prelude::{
3    CastFrom, Container, LweCiphertext, LweCiphertextCount, UnsignedInteger,
4};
5use crate::zk::{CompactPkeCrs, CompactPkeProof, ZkVerificationOutcome};
6
7/// Verifies with the given proof that a [`LweCompactCiphertextList`]
8/// is valid.
9pub fn verify_lwe_compact_ciphertext_list<Scalar, ListCont, KeyCont>(
10    lwe_compact_list: &LweCompactCiphertextList<ListCont>,
11    compact_public_key: &LweCompactPublicKey<KeyCont>,
12    proof: &CompactPkeProof,
13    crs: &CompactPkeCrs,
14    metadata: &[u8],
15) -> ZkVerificationOutcome
16where
17    Scalar: UnsignedInteger,
18    i64: CastFrom<Scalar>,
19    ListCont: Container<Element = Scalar>,
20    KeyCont: Container<Element = Scalar>,
21{
22    crs.verify(lwe_compact_list, compact_public_key, proof, metadata)
23}
24
25/// Verifies with the given proof that a single [`LweCiphertext`] is valid.
26pub fn verify_lwe_ciphertext<Scalar, Cont, KeyCont>(
27    lwe_ciphertext: &LweCiphertext<Cont>,
28    compact_public_key: &LweCompactPublicKey<KeyCont>,
29    proof: &CompactPkeProof,
30    crs: &CompactPkeCrs,
31    metadata: &[u8],
32) -> ZkVerificationOutcome
33where
34    Scalar: UnsignedInteger,
35    i64: CastFrom<Scalar>,
36    Cont: Container<Element = Scalar>,
37    KeyCont: Container<Element = Scalar>,
38{
39    crs.verify(
40        &LweCompactCiphertextList::from_container(
41            lwe_ciphertext.as_ref(),
42            lwe_ciphertext.lwe_size(),
43            LweCiphertextCount(1),
44            lwe_ciphertext.ciphertext_modulus(),
45        ),
46        compact_public_key,
47        proof,
48        metadata,
49    )
50}