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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#![deny(missing_docs)]
#![deny(rustdoc::broken_intra_doc_links)]

//! This crate provides wrappers for Micorosft's SEAL Homomorphic encryption library.
//!
//! # Notes
//! All types in this crate implement Sync/Send. So long as you never dereference the
//! internal handle on any type after it has been dropped, these traits
//! should safely hold. The internal handles should be of little use to you anyways.
//!
//! This crate intentionally omits more esoteric use cases to streamline the API and
//! is currently incomplete (e.g. CKKS is not currently supported). If any underlying
//! SEAL API you care about is missing, please add it in a pull request or file
//! an [issue](https://github.com/Sunscreen-tech/Sunscreen/issues).

#![warn(missing_docs)]

#[cfg(not(target_arch = "wasm32"))]
extern crate link_cplusplus;

#[allow(dead_code)]
#[allow(non_camel_case_types)]
mod bindgen {
    use std::os::raw::c_long;

    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

    pub const E_OK: c_long = 0x0;
    pub const E_POINTER: c_long = 0x80004003u32 as c_long;
    pub const E_INVALIDARG: c_long = 0x80070057u32 as c_long;
    pub const E_OUTOFMEMORY: c_long = 0x8007000Eu32 as c_long;
    pub const E_UNEXPECTED: c_long = 0x8000FFFFu32 as c_long;
    pub const COR_E_IO: c_long = 0x80131620u32 as c_long;
    pub const COR_E_INVALIDOPERATION: c_long = 0x80131509u32 as c_long;
}

mod serialization {
    #[repr(u8)]
    pub enum CompressionType {
        // None = 0,
        // ZLib = 1,
        ZStd = 2,
    }
}

mod bfv_evaluator;
mod context;
mod encoder;
mod encryption_parameters;
mod encryptor_decryptor;
mod error;
mod evaluator;
mod evaluator_base;
mod key_generator;
mod modulus;
mod plaintext_ciphertext;

pub use bfv_evaluator::BFVEvaluator;
pub use context::Context;
pub use encoder::{BFVEncoder, BFVScalarEncoder};
pub use encryption_parameters::*;
pub use encryptor_decryptor::{Decryptor, Encryptor};
pub use error::{Error, Result};
pub use evaluator::Evaluator;
pub use key_generator::{GaloisKeys, KeyGenerator, PublicKey, RelinearizationKeys, SecretKey};
pub use modulus::{CoefficientModulus, Modulus, PlainModulus, SecurityLevel};
pub use plaintext_ciphertext::{Ciphertext, Plaintext};

/**
 * A trait for converting objects into byte arrays.
 */
pub trait ToBytes {
    /**
     * Returns the object as a byte array.
     */
    fn as_bytes(&self) -> Result<Vec<u8>>;
}

/**
 * A trait for converting data from a byte slice under a given SEAL context.
 */
pub trait FromBytes {
    /**
     * Deserialize an object from the given bytes using the given
     * context.
     */
    fn from_bytes(context: &Context, bytes: &[u8]) -> Result<Self>
    where
        Self: Sized;
}