Program Listing for File lwe-pke.h

Return to documentation for file (binfhe/include/lwe-pke.h)

//==================================================================================
// BSD 2-Clause License
//
// Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors
//
// All rights reserved.
//
// Author TPOC: contact@openfhe.org
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//==================================================================================

#ifndef _LWE_PKE_H_
#define _LWE_PKE_H_

#include "binfhe-constants.h"
#include "lwe-ciphertext.h"
#include "lwe-keyswitchkey.h"
#include "lwe-privatekey.h"
#include "lwe-publickey.h"
#include "lwe-keypair.h"
#include "lwe-cryptoparameters.h"

#include <memory>

namespace lbcrypto {

class LWEEncryptionScheme {
    NativeInteger RoundqQ(const NativeInteger& v, const NativeInteger& q, const NativeInteger& Q) const;

public:
    LWEEncryptionScheme() = default;

    LWEPrivateKey KeyGen(usint size, const NativeInteger& modulus) const;

    LWEPrivateKey KeyGenGaussian(usint size, const NativeInteger& modulus) const;

    LWEKeyPair KeyGenPair(const std::shared_ptr<LWECryptoParams>& params) const;

    LWEPublicKey PubKeyGen(const std::shared_ptr<LWECryptoParams>& params, ConstLWEPrivateKey& skN) const;

    LWECiphertext Encrypt(const std::shared_ptr<LWECryptoParams>& params, ConstLWEPrivateKey& sk, LWEPlaintext m,
                          LWEPlaintextModulus p = 4, NativeInteger mod = 0) const;

    LWECiphertext EncryptN(const std::shared_ptr<LWECryptoParams>& params, ConstLWEPublicKey& pk, LWEPlaintext m,
                           LWEPlaintextModulus p = 4, NativeInteger mod = 0) const;

    LWECiphertext SwitchCTtoqn(const std::shared_ptr<LWECryptoParams>& params, ConstLWESwitchingKey& ksk,
                               ConstLWECiphertext& ct) const;

    void Decrypt(const std::shared_ptr<LWECryptoParams>& params, ConstLWEPrivateKey& sk, ConstLWECiphertext& ct,
                 LWEPlaintext* result, LWEPlaintextModulus p = 4) const;

    void EvalAddEq(LWECiphertext& ct1, ConstLWECiphertext& ct2) const;

    void EvalAddConstEq(LWECiphertext& ct, NativeInteger cnst) const;

    void EvalSubEq(LWECiphertext& ct1, ConstLWECiphertext& ct2) const;

    void EvalSubEq2(ConstLWECiphertext& ct1, LWECiphertext& ct2) const;

    void EvalSubConstEq(LWECiphertext& ct, NativeInteger cnst) const;

    void EvalMultConstEq(LWECiphertext& ct, NativeInteger cnst) const;

    LWECiphertext ModSwitch(NativeInteger q, ConstLWECiphertext& ctQ) const;

    LWESwitchingKey KeySwitchGen(const std::shared_ptr<LWECryptoParams>& params, ConstLWEPrivateKey& sk,
                                 ConstLWEPrivateKey& skN) const;

    LWECiphertext KeySwitch(const std::shared_ptr<LWECryptoParams>& params, ConstLWESwitchingKey& K,
                            ConstLWECiphertext& ctQN) const;

    LWECiphertext NoiselessEmbedding(const std::shared_ptr<LWECryptoParams>& params, LWEPlaintext m) const;
};

}  // namespace lbcrypto

#endif