// (c) 2021-2024 The Johns Hopkins University Applied Physics Laboratory LLC (JHU/APL). // encrypt, decrypt, keygeneration, and the like #ifndef BGV_ENCRYPTION_OPENFHE_PYTHON_BINDINGS_H #define BGV_ENCRYPTION_OPENFHE_PYTHON_BINDINGS_H #include #include #include "bgv/BGV_ciphertext_extension.hpp" #include "utils/utils.hpp" using namespace boost::python; using namespace boost::python::numpy; using namespace lbcrypto; namespace pyOpenFHE_BGV { class BGVCiphertext; // BGV-specific crypto context wrapper class BGVCryptoContext { public: // reminder to self that CryptoContext = shared_ptr CryptoContext context; // default for pickling BGVCryptoContext() {}; BGVCryptoContext(CryptoContext cc) : context(cc){}; BGVCryptoContext(const BGVCryptoContext &cc) { context = cc.context; }; void enable(PKESchemeFeature m) { context->Enable(m); }; KeyPair keyGen() { return context->KeyGen(); }; void evalMultKeyGen(const PrivateKey privateKey) { context->EvalMultKeyGen(privateKey); }; void evalMultKeysGen(const PrivateKey privateKey) { context->EvalMultKeysGen(privateKey); }; EvalKey keySwitchGen(const PrivateKey oldPrivateKey, const PrivateKey newPrivateKey) { return context->KeySwitchGen(oldPrivateKey, newPrivateKey); }; SCHEME getSchemeId() { return context->getSchemeId(); } void evalAtIndexKeyGen1(const PrivateKey privateKey, const list &index_list) { context->EvalAtIndexKeyGen( privateKey, pyOpenFHE::pythonListToCppIntVector(index_list), nullptr); }; void evalAtIndexKeyGen2(const PrivateKey privateKey, const ndarray &index_list) { context->EvalAtIndexKeyGen( privateKey, pyOpenFHE::numpyListToCppIntVector(index_list), nullptr); }; void evalPowerOf2RotationKeyGen(const PrivateKey &); void evalBootstrapSetup(); void evalBootstrapKeyGen(const PrivateKey &); list evalBootstrapList(list); pyOpenFHE_BGV::BGVCiphertext evalBootstrap(pyOpenFHE_BGV::BGVCiphertext); Plaintext encode(std::vector); pyOpenFHE_BGV::BGVCiphertext encryptPrivate(const PrivateKey &, const list &); pyOpenFHE_BGV::BGVCiphertext encryptPrivate2(const PrivateKey &, const ndarray &); pyOpenFHE_BGV::BGVCiphertext encryptPublic(const PublicKey &, const list &); pyOpenFHE_BGV::BGVCiphertext encryptPublic2(const PublicKey &, const ndarray &); ndarray decrypt(const PrivateKey &, pyOpenFHE_BGV::BGVCiphertext &); usint getBatchSize() { return context->GetEncodingParams()->GetBatchSize(); }; usint getRingDimension() { return context->GetRingDimension(); }; usint getPlaintextModulus() { return context->GetEncodingParams()->GetPlaintextModulus(); }; ndarray zeroPadToBatchSize(std::vector); ndarray zeroPadToBatchSizeList(const list &); ndarray zeroPadToBatchSizeNumpy(const ndarray &); template void serialize(Archive &ar) { ar(context); }; }; // not entirely sure what the BGV crypto context is like // TODO: verify this is the same BGVCryptoContext genBGVContext(usint multiplicativeDepth, usint batchSize, usint plaintextModulus, SecurityLevel stdLevel = HEStd_128_classic, usint ringDim = 0); } // namespace pyOpenFHE_BGV #endif /* BGV_ENCRYPTION_OPENFHE_PYTHON_BINDINGS_H */