Skip to main content

plat_core/
lib.rs

1//! plat-core: Core types and traits for the plat FHE compute engine.
2//!
3//! This crate provides the foundational abstractions for fully homomorphic
4//! encryption operations within the hyde ecosystem:
5//!
6//! - Polynomial ring arithmetic in Z_q[X]/(X^N + 1)
7//! - Number Theoretic Transform (NTT) for fast multiplication
8//! - RLWE encryption primitives
9//! - Discrete Gaussian and uniform sampling
10//! - Parameter sets for different security levels
11
12pub mod modular;
13pub mod ntt;
14pub mod params;
15pub mod poly;
16pub mod rlwe;
17pub mod sampling;
18
19/// Errors that can occur during FHE operations.
20#[derive(Debug)]
21pub enum FheError {
22    /// Encryption failed.
23    EncryptionError(String),
24    /// Decryption failed.
25    DecryptionError(String),
26    /// The requested operation is not supported.
27    Unsupported(String),
28    /// Key mismatch or missing key for multi-key operation.
29    KeyError(String),
30    /// Parameter mismatch between ciphertexts.
31    ParamsMismatch(String),
32}
33
34impl std::fmt::Display for FheError {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        match self {
37            FheError::EncryptionError(msg) => write!(f, "encryption error: {msg}"),
38            FheError::DecryptionError(msg) => write!(f, "decryption error: {msg}"),
39            FheError::Unsupported(msg) => write!(f, "unsupported: {msg}"),
40            FheError::KeyError(msg) => write!(f, "key error: {msg}"),
41            FheError::ParamsMismatch(msg) => write!(f, "params mismatch: {msg}"),
42        }
43    }
44}
45
46impl std::error::Error for FheError {}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn error_display() {
54        let err = FheError::Unsupported("not yet implemented".into());
55        assert_eq!(format!("{err}"), "unsupported: not yet implemented");
56    }
57
58    #[test]
59    fn key_error_display() {
60        let err = FheError::KeyError("missing party 3".into());
61        assert_eq!(format!("{err}"), "key error: missing party 3");
62    }
63}