Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix X(N)OR’s mapping functions #578

Closed
HONGDUCK opened this issue Nov 4, 2023 · 0 comments · Fixed by #593
Closed

Fix X(N)OR’s mapping functions #578

HONGDUCK opened this issue Nov 4, 2023 · 0 comments · Fixed by #593
Assignees
Labels
optimization Improves performance
Milestone

Comments

@HONGDUCK
Copy link
Contributor

HONGDUCK commented Nov 4, 2023

LWECiphertext BinFHEScheme::EvalBinGate(const std::shared_ptr<BinFHECryptoParams>& params, BINGATE gate,
                                        const RingGSWBTKey& EK, ConstLWECiphertext& ct1,
                                        ConstLWECiphertext& ct2) const {
    if (ct1 == ct2)
        OPENFHE_THROW(config_error, "Input ciphertexts should be independant");

    // By default, we compute XOR/XNOR using a combination of AND, OR, and NOT gates
    if ((gate == XOR) || (gate == XNOR)) {
        const auto& ctAND1 = EvalBinGate(params, AND, EK, ct1, EvalNOT(params, ct2));
        const auto& ctAND2 = EvalBinGate(params, AND, EK, EvalNOT(params, ct1), ct2);
        const auto& ctOR   = EvalBinGate(params, OR, EK, ctAND1, ctAND2);

        // NOT is free so there is not cost to do it an extra time for XNOR
        return (gate == XOR) ? ctOR : EvalNOT(params, ctOR);
    }

    LWECiphertext ctprep = std::make_shared<LWECiphertextImpl>(*ct1);
    // the additive homomorphic operation for XOR/NXOR is different from the other gates we compute
    // 2*(ct1 - ct2) mod 4 for XOR, me map 1,2 -> 1 and 3,0 -> 0
    if ((gate == XOR_FAST) || (gate == XNOR_FAST)) {
        LWEscheme->EvalSubEq(ctprep, ct2);
        LWEscheme->EvalAddEq(ctprep, ctprep);
    }
    else {
        // for all other gates, we simply compute (ct1 + ct2) mod 4
        // for AND: 0,1 -> 0 and 2,3 -> 1
        // for OR: 1,2 -> 1 and 3,0 -> 0
        LWEscheme->EvalAddEq(ctprep, ct2);
    }

    auto acc{BootstrapGateCore(params, gate, EK.BSkey, ctprep)};
    ...

I think that this code is implemented like described in https://eprint.iacr.org/2020/086.

When we use X(N)OR gate, we execute (ct1 && ~ct2) || (~ct1 && ct2). This process need 3 blind rotation so it’s slower then AND, OR gate.

If we use X(N)OR_FAST gate, we use following mapping function.
스크린샷 2023-11-03 오전 10 08 38

Ref : https://eprint.iacr.org/2020/086

This process will make a big noise.

If we fix mapping function of X(N)OR gate like 2(C1 + C2) [q/4, 3q/4] [-q/4, q/4], then we can operate X(N)OR gate with the same failure probability as other gates(AND, OR). And of course, we need only one blind rotation.

@yspolyakov yspolyakov added this to the Release 1.1.2 milestone Nov 8, 2023
@yspolyakov yspolyakov added the optimization Improves performance label Nov 8, 2023
@yspolyakov yspolyakov linked a pull request Nov 16, 2023 that will close this issue
@HONGDUCK HONGDUCK removed their assignment Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Improves performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants