plat-core 0.1.0

Core types and traits for the plat FHE compute engine
Documentation
//! plat-core: Core types and traits for the plat FHE compute engine.
//!
//! This crate provides the foundational abstractions for fully homomorphic
//! encryption operations within the hyde ecosystem:
//!
//! - Polynomial ring arithmetic in Z_q[X]/(X^N + 1)
//! - Number Theoretic Transform (NTT) for fast multiplication
//! - RLWE encryption primitives
//! - Discrete Gaussian and uniform sampling
//! - Parameter sets for different security levels

pub mod modular;
pub mod ntt;
pub mod params;
pub mod poly;
pub mod rlwe;
pub mod sampling;

/// Errors that can occur during FHE operations.
#[derive(Debug)]
pub enum FheError {
    /// Encryption failed.
    EncryptionError(String),
    /// Decryption failed.
    DecryptionError(String),
    /// The requested operation is not supported.
    Unsupported(String),
    /// Key mismatch or missing key for multi-key operation.
    KeyError(String),
    /// Parameter mismatch between ciphertexts.
    ParamsMismatch(String),
}

impl std::fmt::Display for FheError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            FheError::EncryptionError(msg) => write!(f, "encryption error: {msg}"),
            FheError::DecryptionError(msg) => write!(f, "decryption error: {msg}"),
            FheError::Unsupported(msg) => write!(f, "unsupported: {msg}"),
            FheError::KeyError(msg) => write!(f, "key error: {msg}"),
            FheError::ParamsMismatch(msg) => write!(f, "params mismatch: {msg}"),
        }
    }
}

impl std::error::Error for FheError {}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn error_display() {
        let err = FheError::Unsupported("not yet implemented".into());
        assert_eq!(format!("{err}"), "unsupported: not yet implemented");
    }

    #[test]
    fn key_error_display() {
        let err = FheError::KeyError("missing party 3".into());
        assert_eq!(format!("{err}"), "key error: missing party 3");
    }
}