栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SEAL开源库源码09

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SEAL开源库源码09

SEAL开源库源码09

文章目录
  • SEAL开源库源码09
  • seal/ckks.h
    • Arithmetic 类,复数运算
    • CKKSEncoder 类
  • seal/batchencoder.h
    • BatchEncoder 类
  • seal/encyptor.h
    • Encryptor 类
  • seal/decryptor.h
    • Decryptor 类

seal/ckks.h Arithmetic 类,复数运算
namespace seal
{
    template <
        typename T_out, typename = std::enable_if_t<
                            std::is_same, double>::value ||
                            std::is_same, std::complex>::value>>
    SEAL_NODISCARD inline T_out from_complex(std::complex in);

    template <>
    SEAL_NODISCARD inline double from_complex(std::complex in)
    {
        return in.real();
    }

    template <>
    SEAL_NODISCARD inline std::complex from_complex(std::complex in)
    {
        return in;
    }

    namespace util
    {
        template <>
        class Arithmetic, std::complex, double>
        {
        public:
            Arithmetic()
            {}

            inline std::complex add(const std::complex &a, const std::complex &b) const
            {
                return a + b;
            }

            inline std::complex sub(const std::complex &a, const std::complex &b) const
            {
                return a - b;
            }

            inline std::complex mul_root(const std::complex &a, const std::complex &r) const
            {
                return a * r;
            }

            inline std::complex mul_scalar(const std::complex &a, const double &s) const
            {
                return a * s;
            }

            inline std::complex mul_root_scalar(const std::complex &r, const double &s) const
            {
                return r * s;
            }

            inline std::complex guard(const std::complex &a) const
            {
                return a;
            }
        };
    } // namespace util
CKKSEncoder 类
Provides functionality for encoding vectors of complex or real numbers into
plaintext polynomials to be encrypted and computed on using the CKKS scheme.
If the polynomial modulus degree is N, then CKKSEncoder converts vectors of
N/2 complex numbers into plaintext elements. Homomorphic operations performed
on such encrypted vectors are applied coefficient (slot-)wise, enabling
powerful SIMD functionality for computations that are vectorizable. This
functionality is often called "batching" in the homomorphic encryption
literature.

提供将复数或实数向量编码为明文多项式的功能,以便使用CKKS方案进行加密和计算。如果多项式模度为N,则CKKSEncoder将N/2复数的向量转换为明文元素。对这些加密矢量执行的同态操作按系数(slot-)的方式应用,为可向量化的计算提供强大的SIMD功能。这种功能在同态加密文献中通常称为“批处理”。

包括 encode 和 decode

    
    class CKKSEncoder
    {
        using ComplexArith = util::Arithmetic, std::complex, double>;
        using FFTHandler = util::DWTHandler, std::complex, double>;

    public:
        
        CKKSEncoder(const SEALContext &context);

        
        template <
            typename T, typename = std::enable_if_t<
                            std::is_same, double>::value ||
                            std::is_same, std::complex>::value>>
        inline void encode(
            const std::vector &values, parms_id_type parms_id, double scale, Plaintext &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            encode_internal(values.data(), values.size(), parms_id, scale, destination, std::move(pool));
        }

        
        template <
            typename T, typename = std::enable_if_t<
                            std::is_same, double>::value ||
                            std::is_same, std::complex>::value>>
        inline void encode(
            const std::vector &values, double scale, Plaintext &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            encode(values, context_.first_parms_id(), scale, destination, std::move(pool));
        }
#ifdef SEAL_USE_MSGSL
        
        template <
            typename T, typename = std::enable_if_t<
                            std::is_same, double>::value ||
                            std::is_same, std::complex>::value>>
        inline void encode(
            gsl::span values, parms_id_type parms_id, double scale, Plaintext &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            encode_internal(
                values.data(), static_cast(values.size()), parms_id, scale, destination, std::move(pool));
        }

        
        template <
            typename T, typename = std::enable_if_t<
                            std::is_same, double>::value ||
                            std::is_same, std::complex>::value>>
        inline void encode(
            gsl::span values, double scale, Plaintext &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            encode(values, context_.first_parms_id(), scale, destination, std::move(pool));
        }
#endif
        
        inline void encode(
            double value, parms_id_type parms_id, double scale, Plaintext &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            encode_internal(value, parms_id, scale, destination, std::move(pool));
        }

        
        inline void encode(
            double value, double scale, Plaintext &destination, MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            encode(value, context_.first_parms_id(), scale, destination, std::move(pool));
        }

        
        inline void encode(
            std::complex value, parms_id_type parms_id, double scale, Plaintext &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            encode_internal(value, parms_id, scale, destination, std::move(pool));
        }

        
        inline void encode(
            std::complex value, double scale, Plaintext &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            encode(value, context_.first_parms_id(), scale, destination, std::move(pool));
        }

        
        inline void encode(std::int64_t value, parms_id_type parms_id, Plaintext &destination)
        {
            encode_internal(value, parms_id, destination);
        }

        
        inline void encode(std::int64_t value, Plaintext &destination)
        {
            encode(value, context_.first_parms_id(), destination);
        }

        
        template <
            typename T, typename = std::enable_if_t<
                            std::is_same, double>::value ||
                            std::is_same, std::complex>::value>>
        inline void decode(
            const Plaintext &plain, std::vector &destination, MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            destination.resize(slots_);
            decode_internal(plain, destination.data(), std::move(pool));
        }
#ifdef SEAL_USE_MSGSL
        
        template <
            typename T, typename = std::enable_if_t<
                            std::is_same, double>::value ||
                            std::is_same, std::complex>::value>>
        inline void decode(
            const Plaintext &plain, gsl::span destination, MemoryPoolHandle pool = MemoryManager::GetPool())
        {
            if (destination.size() != slots_)
            {
                throw std::invalid_argument("destination has invalid size");
            }
            decode_internal(plain, destination.data(), std::move(pool));
        }
#endif
        
        SEAL_NODISCARD inline std::size_t slot_count() const noexcept
        {
            return slots_;
        }

    private:
        template <
            typename T, typename = std::enable_if_t<
                            std::is_same, double>::value ||
                            std::is_same, std::complex>::value>>
        void encode_internal(
            const T *values, std::size_t values_size, parms_id_type parms_id, double scale, Plaintext &destination,
            MemoryPoolHandle pool)
        {
            // Verify parameters.
            auto context_data_ptr = context_.get_context_data(parms_id);
            if (!context_data_ptr)
            {
                throw std::invalid_argument("parms_id is not valid for encryption parameters");
            }
            if (!values && values_size > 0)
            {
                throw std::invalid_argument("values cannot be null");
            }
            if (values_size > slots_)
            {
                throw std::invalid_argument("values_size is too large");
            }
            if (!pool)
            {
                throw std::invalid_argument("pool is uninitialized");
            }

            auto &context_data = *context_data_ptr;
            auto &parms = context_data.parms();
            auto &coeff_modulus = parms.coeff_modulus();
            std::size_t coeff_modulus_size = coeff_modulus.size();
            std::size_t coeff_count = parms.poly_modulus_degree();

            // Quick sanity check
            if (!util::product_fits_in(coeff_modulus_size, coeff_count))
            {
                throw std::logic_error("invalid parameters");
            }

            // Check that scale is positive and not too large
            if (scale <= 0 || (static_cast(log2(scale)) + 1 >= context_data.total_coeff_modulus_bit_count()))
            {
                throw std::invalid_argument("scale out of bounds");
            }

            auto ntt_tables = context_data.small_ntt_tables();

            // values_size is guaranteed to be no bigger than slots_
            std::size_t n = util::mul_safe(slots_, std::size_t(2));

            auto conj_values = util::allocate>(n, pool, 0);
            for (std::size_t i = 0; i < values_size; i++)
            {
                conj_values[matrix_reps_index_map_[i]] = values[i];
                // TODO: if values are real, the following values should be set to zero, and multiply results by 2.
                conj_values[matrix_reps_index_map_[i + slots_]] = std::conj(values[i]);
            }
            double fix = scale / static_cast(n);
            fft_handler_.transform_from_rev(conj_values.get(), util::get_power_of_two(n), inv_root_powers_.get(), &fix);

            double max_coeff = 0;
            for (std::size_t i = 0; i < n; i++)
            {
                max_coeff = std::max<>(max_coeff, std::fabs(conj_values[i].real()));
            }
            // Verify that the values are not too large to fit in coeff_modulus
            // Note that we have an extra + 1 for the sign bit
            // Don't compute logarithmis of numbers less than 1
            int max_coeff_bit_count = static_cast(std::ceil(std::log2(std::max<>(max_coeff, 1.0)))) + 1;
            if (max_coeff_bit_count >= context_data.total_coeff_modulus_bit_count())
            {
                throw std::invalid_argument("encoded values are too large");
            }

            double two_pow_64 = std::pow(2.0, 64);

            // Resize destination to appropriate size
            // Need to first set parms_id to zero, otherwise resize
            // will throw an exception.
            destination.parms_id() = parms_id_zero;
            destination.resize(util::mul_safe(coeff_count, coeff_modulus_size));

            // Use faster decomposition methods when possible
            if (max_coeff_bit_count <= 64)
            {
                for (std::size_t i = 0; i < n; i++)
                {
                    double coeffd = std::round(conj_values[i].real());
                    bool is_negative = std::signbit(coeffd);

                    std::uint64_t coeffu = static_cast(std::fabs(coeffd));

                    if (is_negative)
                    {
                        for (std::size_t j = 0; j < coeff_modulus_size; j++)
                        {
                            destination[i + (j * coeff_count)] = util::negate_uint_mod(
                                util::barrett_reduce_64(coeffu, coeff_modulus[j]), coeff_modulus[j]);
                        }
                    }
                    else
                    {
                        for (std::size_t j = 0; j < coeff_modulus_size; j++)
                        {
                            destination[i + (j * coeff_count)] = util::barrett_reduce_64(coeffu, coeff_modulus[j]);
                        }
                    }
                }
            }
            else if (max_coeff_bit_count <= 128)
            {
                for (std::size_t i = 0; i < n; i++)
                {
                    double coeffd = std::round(conj_values[i].real());
                    bool is_negative = std::signbit(coeffd);
                    coeffd = std::fabs(coeffd);

                    std::uint64_t coeffu[2]{ static_cast(std::fmod(coeffd, two_pow_64)),
                                             static_cast(coeffd / two_pow_64) };

                    if (is_negative)
                    {
                        for (std::size_t j = 0; j < coeff_modulus_size; j++)
                        {
                            destination[i + (j * coeff_count)] = util::negate_uint_mod(
                                util::barrett_reduce_128(coeffu, coeff_modulus[j]), coeff_modulus[j]);
                        }
                    }
                    else
                    {
                        for (std::size_t j = 0; j < coeff_modulus_size; j++)
                        {
                            destination[i + (j * coeff_count)] = util::barrett_reduce_128(coeffu, coeff_modulus[j]);
                        }
                    }
                }
            }
            else
            {
                // Slow case
                auto coeffu(util::allocate_uint(coeff_modulus_size, pool));
                for (std::size_t i = 0; i < n; i++)
                {
                    double coeffd = std::round(conj_values[i].real());
                    bool is_negative = std::signbit(coeffd);
                    coeffd = std::fabs(coeffd);

                    // We are at this point guaranteed to fit in the allocated space
                    util::set_zero_uint(coeff_modulus_size, coeffu.get());
                    auto coeffu_ptr = coeffu.get();
                    while (coeffd >= 1)
                    {
                        *coeffu_ptr++ = static_cast(std::fmod(coeffd, two_pow_64));
                        coeffd /= two_pow_64;
                    }

                    // Next decompose this coefficient
                    context_data.rns_tool()->base_q()->decompose(coeffu.get(), pool);

                    // Finally replace the sign if necessary
                    if (is_negative)
                    {
                        for (std::size_t j = 0; j < coeff_modulus_size; j++)
                        {
                            destination[i + (j * coeff_count)] = util::negate_uint_mod(coeffu[j], coeff_modulus[j]);
                        }
                    }
                    else
                    {
                        for (std::size_t j = 0; j < coeff_modulus_size; j++)
                        {
                            destination[i + (j * coeff_count)] = coeffu[j];
                        }
                    }
                }
            }

            // Transform to NTT domain
            for (std::size_t i = 0; i < coeff_modulus_size; i++)
            {
                util::ntt_negacyclic_harvey(destination.data(i * coeff_count), ntt_tables[i]);
            }

            destination.parms_id() = parms_id;
            destination.scale() = scale;
        }

        template <
            typename T, typename = std::enable_if_t<
                            std::is_same, double>::value ||
                            std::is_same, std::complex>::value>>
        void decode_internal(const Plaintext &plain, T *destination, MemoryPoolHandle pool)
        {
            // Verify parameters.
            if (!is_valid_for(plain, context_))
            {
                throw std::invalid_argument("plain is not valid for encryption parameters");
            }
            if (!plain.is_ntt_form())
            {
                throw std::invalid_argument("plain is not in NTT form");
            }
            if (!destination)
            {
                throw std::invalid_argument("destination cannot be null");
            }
            if (!pool)
            {
                throw std::invalid_argument("pool is uninitialized");
            }

            auto &context_data = *context_.get_context_data(plain.parms_id());
            auto &parms = context_data.parms();
            std::size_t coeff_modulus_size = parms.coeff_modulus().size();
            std::size_t coeff_count = parms.poly_modulus_degree();
            std::size_t rns_poly_uint64_count = util::mul_safe(coeff_count, coeff_modulus_size);

            auto ntt_tables = context_data.small_ntt_tables();

            // Check that scale is positive and not too large
            if (plain.scale() <= 0 ||
                (static_cast(log2(plain.scale())) >= context_data.total_coeff_modulus_bit_count()))
            {
                throw std::invalid_argument("scale out of bounds");
            }

            auto decryption_modulus = context_data.total_coeff_modulus();
            auto upper_half_threshold = context_data.upper_half_threshold();
            int logn = util::get_power_of_two(coeff_count);

            // Quick sanity check
            if ((logn < 0) || (coeff_count < SEAL_POLY_MOD_DEGREE_MIN) || (coeff_count > SEAL_POLY_MOD_DEGREE_MAX))
            {
                throw std::logic_error("invalid parameters");
            }

            double inv_scale = double(1.0) / plain.scale();

            // Create mutable copy of input
            auto plain_copy(util::allocate_uint(rns_poly_uint64_count, pool));
            util::set_uint(plain.data(), rns_poly_uint64_count, plain_copy.get());

            // Transform each polynomial from NTT domain
            for (std::size_t i = 0; i < coeff_modulus_size; i++)
            {
                util::inverse_ntt_negacyclic_harvey(plain_copy.get() + (i * coeff_count), ntt_tables[i]);
            }

            // CRT-compose the polynomial
            context_data.rns_tool()->base_q()->compose_array(plain_copy.get(), coeff_count, pool);

            // Create floating-point representations of the multi-precision integer coefficients
            double two_pow_64 = std::pow(2.0, 64);
            auto res(util::allocate>(coeff_count, pool));
            for (std::size_t i = 0; i < coeff_count; i++)
            {
                res[i] = 0.0;
                if (util::is_greater_than_or_equal_uint(
                        plain_copy.get() + (i * coeff_modulus_size), upper_half_threshold, coeff_modulus_size))
                {
                    double scaled_two_pow_64 = inv_scale;
                    for (std::size_t j = 0; j < coeff_modulus_size; j++, scaled_two_pow_64 *= two_pow_64)
                    {
                        if (plain_copy[i * coeff_modulus_size + j] > decryption_modulus[j])
                        {
                            auto diff = plain_copy[i * coeff_modulus_size + j] - decryption_modulus[j];
                            res[i] += diff ? static_cast(diff) * scaled_two_pow_64 : 0.0;
                        }
                        else
                        {
                            auto diff = decryption_modulus[j] - plain_copy[i * coeff_modulus_size + j];
                            res[i] -= diff ? static_cast(diff) * scaled_two_pow_64 : 0.0;
                        }
                    }
                }
                else
                {
                    double scaled_two_pow_64 = inv_scale;
                    for (std::size_t j = 0; j < coeff_modulus_size; j++, scaled_two_pow_64 *= two_pow_64)
                    {
                        auto curr_coeff = plain_copy[i * coeff_modulus_size + j];
                        res[i] += curr_coeff ? static_cast(curr_coeff) * scaled_two_pow_64 : 0.0;
                    }
                }

                // Scaling instead incorporated above; this can help in cases
                // where otherwise pow(two_pow_64, j) would overflow due to very
                // large coeff_modulus_size and very large scale
                // res[i] = res_accum * inv_scale;
            }

            fft_handler_.transform_to_rev(res.get(), logn, root_powers_.get());

            for (std::size_t i = 0; i < slots_; i++)
            {
                destination[i] = from_complex(res[static_cast(matrix_reps_index_map_[i])]);
            }
        }

        void encode_internal(
            double value, parms_id_type parms_id, double scale, Plaintext &destination, MemoryPoolHandle pool);

        inline void encode_internal(
            std::complex value, parms_id_type parms_id, double scale, Plaintext &destination,
            MemoryPoolHandle pool)
        {
            auto input = util::allocate>(slots_, pool_, value);
            encode_internal(input.get(), slots_, parms_id, scale, destination, std::move(pool));
        }

        void encode_internal(std::int64_t value, parms_id_type parms_id, Plaintext &destination);

        MemoryPoolHandle pool_ = MemoryManager::GetPool();

        SEALContext context_;

        std::size_t slots_;

        std::shared_ptr complex_roots_;

        // Holds 1~(n-1)-th powers of root in bit-reversed order, the 0-th power is left unset.
        util::Pointer> root_powers_;

        // Holds 1~(n-1)-th powers of inverse root in scrambled order, the 0-th power is left unset.
        util::Pointer> inv_root_powers_;

        util::Pointer matrix_reps_index_map_;

        ComplexArith complex_arith_;

        FFTHandler fft_handler_;
    };
seal/batchencoder.h
 

这个是给 bgv 和 bfv 用的

BatchEncoder 类
    class BatchEncoder
    {
    public:
        
        BatchEncoder(const SEALContext &context);

        
        void encode(const std::vector &values, Plaintext &destination) const;

        
        void encode(const std::vector &values, Plaintext &destination) const;
#ifdef SEAL_USE_MSGSL
        
        void encode(gsl::span values, Plaintext &destination) const;

        
        void encode(gsl::span values, Plaintext &destination) const;
#endif
        
        void decode(
            const Plaintext &plain, std::vector &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool()) const;

        
        void decode(
            const Plaintext &plain, std::vector &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool()) const;
#ifdef SEAL_USE_MSGSL
        
        void decode(
            const Plaintext &plain, gsl::span destination,
            MemoryPoolHandle pool = MemoryManager::GetPool()) const;

        
        void decode(
            const Plaintext &plain, gsl::span destination,
            MemoryPoolHandle pool = MemoryManager::GetPool()) const;
#endif
        
        SEAL_NODISCARD inline auto slot_count() const noexcept
        {
            return slots_;
        }

    private:
        BatchEncoder(const BatchEncoder ©) = delete;

        BatchEncoder(BatchEncoder &&source) = delete;

        BatchEncoder &operator=(const BatchEncoder &assign) = delete;

        BatchEncoder &operator=(BatchEncoder &&assign) = delete;

        void populate_roots_of_unity_vector(const SEALContext::ContextData &context_data);

        void populate_matrix_reps_index_map();

        void reverse_bits(std::uint64_t *input);

        MemoryPoolHandle pool_ = MemoryManager::GetPool();

        SEALContext context_;

        std::size_t slots_;

        util::Pointer roots_of_unity_;

        util::Pointer matrix_reps_index_map_;
    };
} // names
seal/encyptor.h Encryptor 类

包括一个 context、一个 publickey、一个 secretkey

    class Encryptor
    {
    public:
        
        Encryptor(const SEALContext &context, const PublicKey &public_key);

        
        Encryptor(const SEALContext &context, const SecretKey &secret_key);

        
        Encryptor(const SEALContext &context, const PublicKey &public_key, const SecretKey &secret_key);

        
        inline void set_public_key(const PublicKey &public_key)
        {
            if (!is_valid_for(public_key, context_))
            {
                throw std::invalid_argument("public key is not valid for encryption parameters");
            }
            public_key_ = public_key;
        }

        
        inline void set_secret_key(const SecretKey &secret_key)
        {
            if (!is_valid_for(secret_key, context_))
            {
                throw std::invalid_argument("secret key is not valid for encryption parameters");
            }
            secret_key_ = secret_key;
        }

        
        inline void encrypt(
            const Plaintext &plain, Ciphertext &destination, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            encrypt_internal(plain, true, false, destination, pool);
        }

        
        SEAL_NODISCARD inline Serializable encrypt(
            const Plaintext &plain, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            Ciphertext destination;
            encrypt_internal(plain, true, true, destination, pool);
            return destination;
        }

        
        inline void encrypt_zero(Ciphertext &destination, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            encrypt_zero(context_.first_parms_id(), destination, pool);
        }

        
        SEAL_NODISCARD inline Serializable encrypt_zero(
            parms_id_type parms_id, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            Ciphertext destination;
            encrypt_zero_internal(parms_id, true, true, destination, pool);
            return destination;
        }

        
        inline void encrypt_zero(
            parms_id_type parms_id, Ciphertext &destination, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            encrypt_zero_internal(parms_id, true, false, destination, pool);
        }

        
        SEAL_NODISCARD inline Serializable encrypt_zero(
            MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            return encrypt_zero(context_.first_parms_id(), pool);
        }

        
        inline void encrypt_symmetric(
            const Plaintext &plain, Ciphertext &destination, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            encrypt_internal(plain, false, false, destination, pool);
        }

        
        SEAL_NODISCARD inline Serializable encrypt_symmetric(
            const Plaintext &plain, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            Ciphertext destination;
            encrypt_internal(plain, false, true, destination, pool);
            return destination;
        }

        
        inline void encrypt_zero_symmetric(
            parms_id_type parms_id, Ciphertext &destination, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            encrypt_zero_internal(parms_id, false, false, destination, pool);
        }

        
        SEAL_NODISCARD inline Serializable encrypt_zero_symmetric(
            parms_id_type parms_id, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            Ciphertext destination;
            encrypt_zero_internal(parms_id, false, true, destination, pool);
            return destination;
        }

        
        inline void encrypt_zero_symmetric(
            Ciphertext &destination, MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            encrypt_zero_symmetric(context_.first_parms_id(), destination, pool);
        }

        
        SEAL_NODISCARD inline Serializable encrypt_zero_symmetric(
            MemoryPoolHandle pool = MemoryManager::GetPool()) const
        {
            return encrypt_zero_symmetric(context_.first_parms_id(), pool);
        }

        
        struct EncryptorPrivateHelper;

    private:
        Encryptor(const Encryptor ©) = delete;

        Encryptor(Encryptor &&source) = delete;

        Encryptor &operator=(const Encryptor &assign) = delete;

        Encryptor &operator=(Encryptor &&assign) = delete;

        void encrypt_zero_internal(
            parms_id_type parms_id, bool is_asymmetric, bool save_seed, Ciphertext &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool()) const;

        void encrypt_internal(
            const Plaintext &plain, bool is_asymmetric, bool save_seed, Ciphertext &destination,
            MemoryPoolHandle pool = MemoryManager::GetPool()) const;

        SEALContext context_;

        PublicKey public_key_;

        SecretKey secret_key_;
    };
seal/decryptor.h Decryptor 类
 
    class Decryptor
    {
    public:
        
        Decryptor(const SEALContext &context, const SecretKey &secret_key);

        
        void decrypt(const Ciphertext &encrypted, Plaintext &destination);

        
        SEAL_NODISCARD int invariant_noise_budget(const Ciphertext &encrypted);

    private:
        void bfv_decrypt(const Ciphertext &encrypted, Plaintext &destination, MemoryPoolHandle pool);

        void ckks_decrypt(const Ciphertext &encrypted, Plaintext &destination, MemoryPoolHandle pool);

        void bgv_decrypt(const Ciphertext &encrypted, Plaintext &destination, MemoryPoolHandle pool);

        Decryptor(const Decryptor ©) = delete;

        Decryptor(Decryptor &&source) = delete;

        Decryptor &operator=(const Decryptor &assign) = delete;

        Decryptor &operator=(Decryptor &&assign) = delete;

        void compute_secret_key_array(std::size_t max_power);

        // Compute c_0 + c_1 *s + ... + c_{count-1} * s^{count-1} mod q.
        // Store result in destination in RNS form.
        // destination has the size of an RNS polynomial.
        void dot_product_ct_sk_array(const Ciphertext &encrypted, util::RNSIter destination, MemoryPoolHandle pool);

        // We use a fresh memory pool with `clear_on_destruction' enabled.
        MemoryPoolHandle pool_ = MemoryManager::GetPool(mm_prof_opt::mm_force_new, true);

        SEALContext context_;

        std::size_t secret_key_array_size_ = 0;

        util::Pointer secret_key_array_;

        mutable util::ReaderWriterLocker secret_key_array_locker_;
    };
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1014330.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号