pub struct GLWECiphertext<D: Data> {
pub data: VecZnx<D>,
pub basek: usize,
pub k: usize,
}Fields§
§data: VecZnx<D>§basek: usize§k: usizeImplementations§
Source§impl GLWECiphertext<Vec<u8>>
impl GLWECiphertext<Vec<u8>>
pub fn automorphism_scratch_space<B: Backend>( module: &Module<B>, basek: usize, k_out: usize, k_in: usize, k_ksk: usize, digits: usize, rank: usize, ) -> usize
pub fn automorphism_inplace_scratch_space<B: Backend>( module: &Module<B>, basek: usize, k_out: usize, k_ksk: usize, digits: usize, rank: usize, ) -> usize
Source§impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
pub fn automorphism<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
lhs: &GLWECiphertext<DataLhs>,
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxAutomorphismInplace<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
pub fn automorphism_inplace<DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxAutomorphismInplace<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
pub fn automorphism_add<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
lhs: &GLWECiphertext<DataLhs>,
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxBigAutomorphismInplace<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
pub fn automorphism_add_inplace<DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxBigAutomorphismInplace<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
pub fn automorphism_sub_ab<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
lhs: &GLWECiphertext<DataLhs>,
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxBigAutomorphismInplace<B> + VecZnxBigSubSmallAInplace<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
pub fn automorphism_sub_ab_inplace<DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxBigAutomorphismInplace<B> + VecZnxBigSubSmallAInplace<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
pub fn automorphism_sub_ba<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
lhs: &GLWECiphertext<DataLhs>,
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxBigAutomorphismInplace<B> + VecZnxBigSubSmallBInplace<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
pub fn automorphism_sub_ba_inplace<DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxBigAutomorphismInplace<B> + VecZnxBigSubSmallBInplace<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
Source§impl GLWECiphertext<Vec<u8>>
impl GLWECiphertext<Vec<u8>>
Source§impl<D: DataMut> GLWECiphertext<D>
impl<D: DataMut> GLWECiphertext<D>
pub fn from_lwe<DLwe, DKsk, B: Backend>(
&mut self,
module: &Module<B>,
lwe: &LWECiphertext<DLwe>,
ksk: &LWEToGLWESwitchingKeyPrepared<DKsk, B>,
scratch: &mut Scratch<B>,
)where
DLwe: DataRef,
DKsk: DataRef,
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B>,
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeGLWECt,
Source§impl GLWECiphertext<Vec<u8>>
impl GLWECiphertext<Vec<u8>>
Sourcepub fn decrypt_scratch_space<B: Backend>(
module: &Module<B>,
basek: usize,
k: usize,
) -> usize
pub fn decrypt_scratch_space<B: Backend>( module: &Module<B>, basek: usize, k: usize, ) -> usize
Examples found in repository?
examples/encryption.rs (line 49)
15fn main() {
16 // Ring degree
17 let log_n: usize = 10;
18
19 let n: usize = 1 << log_n;
20
21 // Base-2-k (implicit digit decomposition)
22 let basek: usize = 14;
23
24 // Ciphertext Torus precision (equivalent to ciphertext modulus)
25 let k_ct: usize = 27;
26
27 // Plaintext Torus precision (equivament to plaintext modulus)
28 let k_pt: usize = basek;
29
30 // GLWE rank
31 let rank: usize = 1;
32
33 // Instantiate Module (DFT Tables)
34 let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(n as u64);
35
36 // Allocates ciphertext & plaintexts
37 let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_ct, rank);
38 let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
39 let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
40
41 // CPRNG
42 let mut source_xs: Source = Source::new([0u8; 32]);
43 let mut source_xe: Source = Source::new([1u8; 32]);
44 let mut source_xa: Source = Source::new([2u8; 32]);
45
46 // Scratch space
47 let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
48 GLWECiphertext::encrypt_sk_scratch_space(&module, basek, ct.k())
49 | GLWECiphertext::decrypt_scratch_space(&module, basek, ct.k()),
50 );
51
52 // Generate secret-key
53 let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
54 sk.fill_ternary_prob(0.5, &mut source_xs);
55
56 // Backend-prepared secret
57 let sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk.prepare_alloc(&module, scratch.borrow());
58
59 // Uniform plaintext
60 module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, &mut source_xa);
61
62 // Encryption
63 ct.encrypt_sk(
64 &module,
65 &pt_want,
66 &sk_prepared,
67 &mut source_xa,
68 &mut source_xe,
69 scratch.borrow(),
70 );
71
72 // Decryption
73 ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
74
75 // Diff between pt - Dec(Enc(pt))
76 pt_want.sub_inplace_ab(&module, &pt_have);
77
78 // Ideal vs. actual noise
79 let noise_have: f64 = pt_want.data.std(basek, 0) * (ct.k() as f64).exp2();
80 let noise_want: f64 = SIGMA;
81
82 // Check
83 assert!(noise_have <= noise_want + 0.2);
84}Source§impl<DataSelf: DataRef> GLWECiphertext<DataSelf>
impl<DataSelf: DataRef> GLWECiphertext<DataSelf>
Sourcepub fn decrypt<DataPt: DataMut, DataSk: DataRef, B: Backend>(
&self,
module: &Module<B>,
pt: &mut GLWEPlaintext<DataPt>,
sk: &GLWESecretPrepared<DataSk, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftApply<B> + SvpApplyDftToDftInplace<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddInplace<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B>,
Scratch<B>: TakeVecZnxDft<B> + TakeVecZnxBig<B>,
pub fn decrypt<DataPt: DataMut, DataSk: DataRef, B: Backend>(
&self,
module: &Module<B>,
pt: &mut GLWEPlaintext<DataPt>,
sk: &GLWESecretPrepared<DataSk, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftApply<B> + SvpApplyDftToDftInplace<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddInplace<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B>,
Scratch<B>: TakeVecZnxDft<B> + TakeVecZnxBig<B>,
Examples found in repository?
examples/encryption.rs (line 73)
15fn main() {
16 // Ring degree
17 let log_n: usize = 10;
18
19 let n: usize = 1 << log_n;
20
21 // Base-2-k (implicit digit decomposition)
22 let basek: usize = 14;
23
24 // Ciphertext Torus precision (equivalent to ciphertext modulus)
25 let k_ct: usize = 27;
26
27 // Plaintext Torus precision (equivament to plaintext modulus)
28 let k_pt: usize = basek;
29
30 // GLWE rank
31 let rank: usize = 1;
32
33 // Instantiate Module (DFT Tables)
34 let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(n as u64);
35
36 // Allocates ciphertext & plaintexts
37 let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_ct, rank);
38 let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
39 let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
40
41 // CPRNG
42 let mut source_xs: Source = Source::new([0u8; 32]);
43 let mut source_xe: Source = Source::new([1u8; 32]);
44 let mut source_xa: Source = Source::new([2u8; 32]);
45
46 // Scratch space
47 let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
48 GLWECiphertext::encrypt_sk_scratch_space(&module, basek, ct.k())
49 | GLWECiphertext::decrypt_scratch_space(&module, basek, ct.k()),
50 );
51
52 // Generate secret-key
53 let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
54 sk.fill_ternary_prob(0.5, &mut source_xs);
55
56 // Backend-prepared secret
57 let sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk.prepare_alloc(&module, scratch.borrow());
58
59 // Uniform plaintext
60 module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, &mut source_xa);
61
62 // Encryption
63 ct.encrypt_sk(
64 &module,
65 &pt_want,
66 &sk_prepared,
67 &mut source_xa,
68 &mut source_xe,
69 scratch.borrow(),
70 );
71
72 // Decryption
73 ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
74
75 // Diff between pt - Dec(Enc(pt))
76 pt_want.sub_inplace_ab(&module, &pt_have);
77
78 // Ideal vs. actual noise
79 let noise_have: f64 = pt_want.data.std(basek, 0) * (ct.k() as f64).exp2();
80 let noise_want: f64 = SIGMA;
81
82 // Check
83 assert!(noise_have <= noise_want + 0.2);
84}Source§impl GLWECiphertext<Vec<u8>>
impl GLWECiphertext<Vec<u8>>
Sourcepub fn encrypt_sk_scratch_space<B: Backend>(
module: &Module<B>,
basek: usize,
k: usize,
) -> usize
pub fn encrypt_sk_scratch_space<B: Backend>( module: &Module<B>, basek: usize, k: usize, ) -> usize
Examples found in repository?
examples/encryption.rs (line 48)
15fn main() {
16 // Ring degree
17 let log_n: usize = 10;
18
19 let n: usize = 1 << log_n;
20
21 // Base-2-k (implicit digit decomposition)
22 let basek: usize = 14;
23
24 // Ciphertext Torus precision (equivalent to ciphertext modulus)
25 let k_ct: usize = 27;
26
27 // Plaintext Torus precision (equivament to plaintext modulus)
28 let k_pt: usize = basek;
29
30 // GLWE rank
31 let rank: usize = 1;
32
33 // Instantiate Module (DFT Tables)
34 let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(n as u64);
35
36 // Allocates ciphertext & plaintexts
37 let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_ct, rank);
38 let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
39 let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
40
41 // CPRNG
42 let mut source_xs: Source = Source::new([0u8; 32]);
43 let mut source_xe: Source = Source::new([1u8; 32]);
44 let mut source_xa: Source = Source::new([2u8; 32]);
45
46 // Scratch space
47 let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
48 GLWECiphertext::encrypt_sk_scratch_space(&module, basek, ct.k())
49 | GLWECiphertext::decrypt_scratch_space(&module, basek, ct.k()),
50 );
51
52 // Generate secret-key
53 let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
54 sk.fill_ternary_prob(0.5, &mut source_xs);
55
56 // Backend-prepared secret
57 let sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk.prepare_alloc(&module, scratch.borrow());
58
59 // Uniform plaintext
60 module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, &mut source_xa);
61
62 // Encryption
63 ct.encrypt_sk(
64 &module,
65 &pt_want,
66 &sk_prepared,
67 &mut source_xa,
68 &mut source_xe,
69 scratch.borrow(),
70 );
71
72 // Decryption
73 ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
74
75 // Diff between pt - Dec(Enc(pt))
76 pt_want.sub_inplace_ab(&module, &pt_have);
77
78 // Ideal vs. actual noise
79 let noise_have: f64 = pt_want.data.std(basek, 0) * (ct.k() as f64).exp2();
80 let noise_want: f64 = SIGMA;
81
82 // Check
83 assert!(noise_have <= noise_want + 0.2);
84}pub fn encrypt_pk_scratch_space<B: Backend>(
module: &Module<B>,
basek: usize,
k: usize,
) -> usizewhere
Module<B>: VecZnxDftAllocBytes + SvpPPolAllocBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes,
Source§impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
Sourcepub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
pt: &GLWEPlaintext<DataPt>,
sk: &GLWESecretPrepared<DataSk, B>,
source_xa: &mut Source,
source_xe: &mut Source,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B> + VecZnxDftApply<B> + SvpApplyDftToDftInplace<B> + VecZnxIdftApplyConsume<B> + VecZnxNormalizeTmpBytes + VecZnxFillUniform + VecZnxSubABInplace + VecZnxAddInplace + VecZnxNormalizeInplace<B> + VecZnxAddNormal + VecZnxNormalize<B> + VecZnxSub,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
pt: &GLWEPlaintext<DataPt>,
sk: &GLWESecretPrepared<DataSk, B>,
source_xa: &mut Source,
source_xe: &mut Source,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B> + VecZnxDftApply<B> + SvpApplyDftToDftInplace<B> + VecZnxIdftApplyConsume<B> + VecZnxNormalizeTmpBytes + VecZnxFillUniform + VecZnxSubABInplace + VecZnxAddInplace + VecZnxNormalizeInplace<B> + VecZnxAddNormal + VecZnxNormalize<B> + VecZnxSub,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
Examples found in repository?
examples/encryption.rs (lines 63-70)
15fn main() {
16 // Ring degree
17 let log_n: usize = 10;
18
19 let n: usize = 1 << log_n;
20
21 // Base-2-k (implicit digit decomposition)
22 let basek: usize = 14;
23
24 // Ciphertext Torus precision (equivalent to ciphertext modulus)
25 let k_ct: usize = 27;
26
27 // Plaintext Torus precision (equivament to plaintext modulus)
28 let k_pt: usize = basek;
29
30 // GLWE rank
31 let rank: usize = 1;
32
33 // Instantiate Module (DFT Tables)
34 let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(n as u64);
35
36 // Allocates ciphertext & plaintexts
37 let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_ct, rank);
38 let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
39 let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
40
41 // CPRNG
42 let mut source_xs: Source = Source::new([0u8; 32]);
43 let mut source_xe: Source = Source::new([1u8; 32]);
44 let mut source_xa: Source = Source::new([2u8; 32]);
45
46 // Scratch space
47 let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
48 GLWECiphertext::encrypt_sk_scratch_space(&module, basek, ct.k())
49 | GLWECiphertext::decrypt_scratch_space(&module, basek, ct.k()),
50 );
51
52 // Generate secret-key
53 let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
54 sk.fill_ternary_prob(0.5, &mut source_xs);
55
56 // Backend-prepared secret
57 let sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk.prepare_alloc(&module, scratch.borrow());
58
59 // Uniform plaintext
60 module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, &mut source_xa);
61
62 // Encryption
63 ct.encrypt_sk(
64 &module,
65 &pt_want,
66 &sk_prepared,
67 &mut source_xa,
68 &mut source_xe,
69 scratch.borrow(),
70 );
71
72 // Decryption
73 ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
74
75 // Diff between pt - Dec(Enc(pt))
76 pt_want.sub_inplace_ab(&module, &pt_have);
77
78 // Ideal vs. actual noise
79 let noise_have: f64 = pt_want.data.std(basek, 0) * (ct.k() as f64).exp2();
80 let noise_want: f64 = SIGMA;
81
82 // Check
83 assert!(noise_have <= noise_want + 0.2);
84}pub fn encrypt_zero_sk<DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
sk: &GLWESecretPrepared<DataSk, B>,
source_xa: &mut Source,
source_xe: &mut Source,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B> + VecZnxDftApply<B> + SvpApplyDftToDftInplace<B> + VecZnxIdftApplyConsume<B> + VecZnxNormalizeTmpBytes + VecZnxFillUniform + VecZnxSubABInplace + VecZnxAddInplace + VecZnxNormalizeInplace<B> + VecZnxAddNormal + VecZnxNormalize<B> + VecZnxSub,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
pub fn encrypt_pk<DataPt: DataRef, DataPk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
pt: &GLWEPlaintext<DataPt>,
pk: &GLWEPublicKeyPrepared<DataPk, B>,
source_xu: &mut Source,
source_xe: &mut Source,
scratch: &mut Scratch<B>,
)where
Module<B>: SvpPrepare<B> + SvpApplyDftToDft<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddNormal<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B>,
Scratch<B>: TakeSvpPPol<B> + TakeScalarZnx + TakeVecZnxDft<B>,
pub fn encrypt_zero_pk<DataPk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
pk: &GLWEPublicKeyPrepared<DataPk, B>,
source_xu: &mut Source,
source_xe: &mut Source,
scratch: &mut Scratch<B>,
)where
Module<B>: SvpPrepare<B> + SvpApplyDftToDft<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddNormal<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B>,
Scratch<B>: TakeSvpPPol<B> + TakeScalarZnx + TakeVecZnxDft<B>,
Source§impl GLWECiphertext<Vec<u8>>
impl GLWECiphertext<Vec<u8>>
pub fn external_product_scratch_space<B: Backend>( module: &Module<B>, basek: usize, k_out: usize, k_in: usize, k_ggsw: usize, digits: usize, rank: usize, ) -> usize
pub fn external_product_inplace_scratch_space<B: Backend>( module: &Module<B>, basek: usize, k_out: usize, k_ggsw: usize, digits: usize, rank: usize, ) -> usize
Source§impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
pub fn external_product<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
lhs: &GLWECiphertext<DataLhs>,
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxNormalizeTmpBytes + VecZnxDftApply<B> + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxIdftApplyConsume<B> + VecZnxBigNormalize<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
pub fn external_product_inplace<DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxNormalizeTmpBytes + VecZnxDftApply<B> + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxIdftApplyConsume<B> + VecZnxBigNormalize<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
Source§impl GLWECiphertext<Vec<u8>>
impl GLWECiphertext<Vec<u8>>
pub fn trace_galois_elements<B: Backend>(module: &Module<B>) -> Vec<i64>
pub fn trace_scratch_space<B: Backend>( module: &Module<B>, basek: usize, out_k: usize, in_k: usize, ksk_k: usize, digits: usize, rank: usize, ) -> usize
pub fn trace_inplace_scratch_space<B: Backend>( module: &Module<B>, basek: usize, out_k: usize, ksk_k: usize, digits: usize, rank: usize, ) -> usize
Source§impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
pub fn trace<DataLhs: DataRef, DataAK: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
start: usize,
end: usize,
lhs: &GLWECiphertext<DataLhs>,
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxBigAutomorphismInplace<B> + VecZnxRshInplace<B> + VecZnxCopy,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
pub fn trace_inplace<DataAK: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
start: usize,
end: usize,
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxBigAutomorphismInplace<B> + VecZnxRshInplace<B>,
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
Source§impl GLWECiphertext<Vec<u8>>
impl GLWECiphertext<Vec<u8>>
pub fn keyswitch_scratch_space<B: Backend>( module: &Module<B>, basek: usize, k_out: usize, k_in: usize, k_ksk: usize, digits: usize, rank_in: usize, rank_out: usize, ) -> usize
pub fn keyswitch_inplace_scratch_space<B: Backend>( module: &Module<B>, basek: usize, k_out: usize, k_ksk: usize, digits: usize, rank: usize, ) -> usize
Source§impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
impl<DataSelf: DataMut> GLWECiphertext<DataSelf>
pub fn keyswitch<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
lhs: &GLWECiphertext<DataLhs>,
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B>,
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
pub fn keyswitch_inplace<DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VmpApplyDftToDft<B> + VmpApplyDftToDftAdd<B> + VecZnxDftApply<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B>,
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
Source§impl<D: DataRef> GLWECiphertext<D>
impl<D: DataRef> GLWECiphertext<D>
pub fn assert_noise<B, DataSk, DataPt>(
&self,
module: &Module<B>,
sk_prepared: &GLWESecretPrepared<DataSk, B>,
pt_want: &GLWEPlaintext<DataPt>,
max_noise: f64,
)where
DataSk: DataRef,
DataPt: DataRef,
Module<B>: VecZnxDftAllocBytes + VecZnxBigAllocBytes + VecZnxDftApply<B> + SvpApplyDftToDftInplace<B> + VecZnxIdftApplyConsume<B> + VecZnxBigAddInplace<B> + VecZnxBigAddSmallInplace<B> + VecZnxBigNormalize<B> + VecZnxNormalizeTmpBytes + VecZnxSubABInplace + VecZnxNormalizeInplace<B>,
B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
Source§impl GLWECiphertext<Vec<u8>>
impl GLWECiphertext<Vec<u8>>
pub fn rsh_scratch_space(n: usize) -> usize
Source§impl GLWECiphertext<Vec<u8>>
impl GLWECiphertext<Vec<u8>>
Sourcepub fn alloc(n: usize, basek: usize, k: usize, rank: usize) -> Self
pub fn alloc(n: usize, basek: usize, k: usize, rank: usize) -> Self
Examples found in repository?
examples/encryption.rs (line 37)
15fn main() {
16 // Ring degree
17 let log_n: usize = 10;
18
19 let n: usize = 1 << log_n;
20
21 // Base-2-k (implicit digit decomposition)
22 let basek: usize = 14;
23
24 // Ciphertext Torus precision (equivalent to ciphertext modulus)
25 let k_ct: usize = 27;
26
27 // Plaintext Torus precision (equivament to plaintext modulus)
28 let k_pt: usize = basek;
29
30 // GLWE rank
31 let rank: usize = 1;
32
33 // Instantiate Module (DFT Tables)
34 let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(n as u64);
35
36 // Allocates ciphertext & plaintexts
37 let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_ct, rank);
38 let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
39 let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
40
41 // CPRNG
42 let mut source_xs: Source = Source::new([0u8; 32]);
43 let mut source_xe: Source = Source::new([1u8; 32]);
44 let mut source_xa: Source = Source::new([2u8; 32]);
45
46 // Scratch space
47 let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
48 GLWECiphertext::encrypt_sk_scratch_space(&module, basek, ct.k())
49 | GLWECiphertext::decrypt_scratch_space(&module, basek, ct.k()),
50 );
51
52 // Generate secret-key
53 let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
54 sk.fill_ternary_prob(0.5, &mut source_xs);
55
56 // Backend-prepared secret
57 let sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk.prepare_alloc(&module, scratch.borrow());
58
59 // Uniform plaintext
60 module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, &mut source_xa);
61
62 // Encryption
63 ct.encrypt_sk(
64 &module,
65 &pt_want,
66 &sk_prepared,
67 &mut source_xa,
68 &mut source_xe,
69 scratch.borrow(),
70 );
71
72 // Decryption
73 ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
74
75 // Diff between pt - Dec(Enc(pt))
76 pt_want.sub_inplace_ab(&module, &pt_have);
77
78 // Ideal vs. actual noise
79 let noise_have: f64 = pt_want.data.std(basek, 0) * (ct.k() as f64).exp2();
80 let noise_want: f64 = SIGMA;
81
82 // Check
83 assert!(noise_have <= noise_want + 0.2);
84}pub fn bytes_of(n: usize, basek: usize, k: usize, rank: usize) -> usize
Trait Implementations§
Source§impl<D: Clone + Data> Clone for GLWECiphertext<D>
impl<D: Clone + Data> Clone for GLWECiphertext<D>
Source§fn clone(&self) -> GLWECiphertext<D>
fn clone(&self) -> GLWECiphertext<D>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<D: DataRef> Debug for GLWECiphertext<D>
impl<D: DataRef> Debug for GLWECiphertext<D>
Source§impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GLWECiphertextCompressed<DR>> for GLWECiphertext<D>
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GLWECiphertextCompressed<DR>> for GLWECiphertext<D>
fn decompress( &mut self, module: &Module<B>, other: &GLWECiphertextCompressed<DR>, )
Source§impl<D: DataRef> Display for GLWECiphertext<D>
impl<D: DataRef> Display for GLWECiphertext<D>
Source§impl<D: DataMut> FillUniform for GLWECiphertext<D>
impl<D: DataMut> FillUniform for GLWECiphertext<D>
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source)
Source§impl<D: DataMut> GLWECiphertextToMut for GLWECiphertext<D>
impl<D: DataMut> GLWECiphertextToMut for GLWECiphertext<D>
fn to_mut(&mut self) -> GLWECiphertext<&mut [u8]>
Source§impl<D: DataRef> GLWECiphertextToRef for GLWECiphertext<D>
impl<D: DataRef> GLWECiphertextToRef for GLWECiphertext<D>
fn to_ref(&self) -> GLWECiphertext<&[u8]>
Source§impl<D: DataMut> GLWEOperations for GLWECiphertext<D>
impl<D: DataMut> GLWEOperations for GLWECiphertext<D>
fn add<A, B, BACKEND: Backend>( &mut self, module: &Module<BACKEND>, a: &A, b: &B, )
fn add_inplace<A, BACKEND: Backend>(&mut self, module: &Module<BACKEND>, a: &A)
fn sub<A, B, BACKEND: Backend>(
&mut self,
module: &Module<BACKEND>,
a: &A,
b: &B,
)where
A: GLWECiphertextToRef,
B: GLWECiphertextToRef,
Module<BACKEND>: VecZnxSub + VecZnxCopy + VecZnxNegateInplace,
fn sub_inplace_ab<A, BACKEND: Backend>( &mut self, module: &Module<BACKEND>, a: &A, )
fn sub_inplace_ba<A, BACKEND: Backend>( &mut self, module: &Module<BACKEND>, a: &A, )
fn rotate<A, B: Backend>(&mut self, module: &Module<B>, k: i64, a: &A)
fn rotate_inplace<B: Backend>(
&mut self,
module: &Module<B>,
k: i64,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxRotateInplace<B>,
fn mul_xp_minus_one<A, B: Backend>(&mut self, module: &Module<B>, k: i64, a: &A)
fn mul_xp_minus_one_inplace<B: Backend>(
&mut self,
module: &Module<B>,
k: i64,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxMulXpMinusOneInplace<B>,
fn copy<A, B: Backend>(&mut self, module: &Module<B>, a: &A)
fn rsh<B: Backend>(
&mut self,
module: &Module<B>,
k: usize,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxRshInplace<B>,
fn normalize<A, B: Backend>( &mut self, module: &Module<B>, a: &A, scratch: &mut Scratch<B>, )
fn normalize_inplace<B: Backend>(
&mut self,
module: &Module<B>,
scratch: &mut Scratch<B>,
)where
Module<B>: VecZnxNormalizeInplace<B>,
Source§impl<D: Data> Infos for GLWECiphertext<D>
impl<D: Data> Infos for GLWECiphertext<D>
Source§impl<D: DataMut> ReaderFrom for GLWECiphertext<D>
impl<D: DataMut> ReaderFrom for GLWECiphertext<D>
Source§impl<D: DataMut> Reset for GLWECiphertext<D>
impl<D: DataMut> Reset for GLWECiphertext<D>
Source§impl<D: DataMut> SetMetaData for GLWECiphertext<D>
impl<D: DataMut> SetMetaData for GLWECiphertext<D>
Source§impl<'a, B, D> TakeLike<'a, B, GLWECiphertext<D>> for Scratch<B>
impl<'a, B, D> TakeLike<'a, B, GLWECiphertext<D>> for Scratch<B>
type Output = GLWECiphertext<&'a mut [u8]>
fn take_like( &'a mut self, template: &GLWECiphertext<D>, ) -> (Self::Output, &'a mut Self)
Source§impl<D: DataRef> ToOwnedDeep for GLWECiphertext<D>
impl<D: DataRef> ToOwnedDeep for GLWECiphertext<D>
type Owned = GLWECiphertext<Vec<u8>>
fn to_owned_deep(&self) -> Self::Owned
Source§impl<D: DataRef> WriterTo for GLWECiphertext<D>
impl<D: DataRef> WriterTo for GLWECiphertext<D>
impl<D: Eq + Data> Eq for GLWECiphertext<D>
impl<D: Data> StructuralPartialEq for GLWECiphertext<D>
Auto Trait Implementations§
impl<D> Freeze for GLWECiphertext<D>where
D: Freeze,
impl<D> RefUnwindSafe for GLWECiphertext<D>where
D: RefUnwindSafe,
impl<D> Send for GLWECiphertext<D>where
D: Send,
impl<D> Sync for GLWECiphertext<D>where
D: Sync,
impl<D> Unpin for GLWECiphertext<D>where
D: Unpin,
impl<D> UnwindSafe for GLWECiphertext<D>where
D: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.