1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! LWE ciphertext and key types.
use ;
/// LWE secret key: vector in Z_q^d sampled from error distribution.
///
/// The secret key is a vector of small integers (typically from a Gaussian
/// distribution) used for encryption and decryption.
///
/// # Fields
///
/// * `coeffs` - Secret key coefficients in Z_q
/// * `dim` - Dimension of the key (typically matches ring dimension)
/// * `q` - Ciphertext modulus
///
/// # Example
///
/// ```
/// use inspire::lwe::LweSecretKey;
/// use inspire::math::GaussianSampler;
/// use inspire::math::mod_q::DEFAULT_Q;
///
/// let mut sampler = GaussianSampler::new(3.2);
/// let sk = LweSecretKey::generate(256, DEFAULT_Q, &mut sampler);
/// assert_eq!(sk.dim, 256);
/// ```
/// LWE ciphertext: (a, b) where b = -<a, s> + e + Δ·m.
///
/// Encrypts a message m in Z_p using the LWE encryption scheme.
/// Supports homomorphic addition, subtraction, and scalar multiplication.
///
/// # Fields
///
/// * `a` - Random vector in Z_q^d
/// * `b` - Scalar in Z_q: b = -<a, s> + e + Δ·m
/// * `q` - Ciphertext modulus
///
/// # Decryption
///
/// To decrypt, compute `b + <a, s> = e + Δ·m`, then round to recover m.
///
/// # Example
///
/// ```
/// use inspire::lwe::{LweSecretKey, LweCiphertext};
/// use inspire::math::mod_q::DEFAULT_Q;
///
/// let sk = LweSecretKey::from_coeffs(vec![1, 2, 3, 4], DEFAULT_Q);
/// let ct = LweCiphertext::zero(4, DEFAULT_Q);
/// ```