-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using OpenFHE | ||
|
||
plaintext_modulus = 65537 | ||
multiplicative_depth = 2 | ||
|
||
parameters = CCParams{CryptoContextBGVRNS}() | ||
SetPlaintextModulus(parameters, plaintext_modulus) | ||
SetMultiplicativeDepth(parameters, multiplicative_depth) | ||
|
||
cc = GenCryptoContext(parameters) | ||
Enable(cc, PKE) | ||
Enable(cc, KEYSWITCH) | ||
Enable(cc, LEVELEDSHE) | ||
|
||
keys = KeyGen(cc) | ||
privkey = OpenFHE.private_key(keys) | ||
pubkey = OpenFHE.public_key(keys) | ||
EvalMultKeyGen(cc, privkey) | ||
|
||
EvalRotateKeyGen(cc, privkey, [1, 2, -1, -2]) | ||
|
||
vectorOfInts1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | ||
plaintext1 = MakePackedPlaintext(cc, vectorOfInts1) | ||
vectorOfInts2 = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12] | ||
plaintext2 = MakePackedPlaintext(cc, vectorOfInts2) | ||
vectorOfInts3 = [1, 2, 5, 2, 5, 6, 7, 8, 9, 10, 11, 12] | ||
plaintext3 = MakePackedPlaintext(cc, vectorOfInts3) | ||
|
||
ct1 = Encrypt(cc, pubkey, plaintext1) | ||
ct2 = Encrypt(cc, pubkey, plaintext2) | ||
ct3 = Encrypt(cc, pubkey, plaintext3) | ||
|
||
ct_add12 = EvalAdd(cc, ct1, ct2); | ||
ct_add_result = EvalAdd(cc, ct_add12, ct3); | ||
|
||
ct_mult12 = EvalMult(cc, ct1, ct2); | ||
ct_mult_result = EvalMult(cc, ct_mult12, ct3); | ||
|
||
ct_rot1 = EvalRotate(cc, ct1, 1); | ||
ct_rot2 = EvalRotate(cc, ct1, 2); | ||
ct_rot3 = EvalRotate(cc, ct1, -1); | ||
ct_rot4 = EvalRotate(cc, ct1, -2); | ||
|
||
pt_add_result = Plaintext() | ||
Decrypt(cc, privkey, ct_add_result, pt_add_result) | ||
|
||
pt_mult_result = Plaintext() | ||
Decrypt(cc, privkey, ct_mult_result, pt_mult_result) | ||
|
||
pt_rot1 = Plaintext() | ||
Decrypt(cc, privkey, ct_rot1, pt_rot1) | ||
pt_rot2 = Plaintext() | ||
Decrypt(cc, privkey, ct_rot2, pt_rot2) | ||
pt_rot3 = Plaintext() | ||
Decrypt(cc, privkey, ct_rot3, pt_rot3) | ||
pt_rot4 = Plaintext() | ||
Decrypt(cc, privkey, ct_rot4, pt_rot4) | ||
|
||
SetLength(pt_rot1, length(vectorOfInts1)) | ||
SetLength(pt_rot2, length(vectorOfInts1)) | ||
SetLength(pt_rot3, length(vectorOfInts1)) | ||
SetLength(pt_rot4, length(vectorOfInts1)) | ||
|
||
println("Plaintext #1: ", plaintext1) | ||
println("Plaintext #2: ", plaintext2) | ||
println("Plaintext #3: ", plaintext3) | ||
|
||
println() | ||
println("Results of homomorphic computations") | ||
println("#1 + #2 + #3: ", pt_add_result) | ||
println("#1 * #2 * #3: ", pt_mult_result) | ||
println("Left rotation of #1 by 1: ", pt_rot1) | ||
println("Left rotation of #1 by 2: ", pt_rot2) | ||
println("Right rotation of #1 by 1: ", pt_rot3) | ||
println("Right rotation of #1 by 2: ", pt_rot4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module TestBGV | ||
|
||
using Test | ||
using OpenFHE | ||
|
||
# Note: Much of the basic CCParams/CryptoContext functionality is already tested in | ||
# test_ckks.jl and test_bfv.jl. | ||
@testset verbose=true showtiming=true "test_bgv.jl" begin | ||
|
||
plaintext_modulus = 65537 | ||
multiplicative_depth = 2 | ||
|
||
@testset verbose=true showtiming=true "CCParams" begin | ||
@test_nowarn CCParams{CryptoContextBGVRNS}() | ||
parameters = CCParams{CryptoContextBGVRNS}() | ||
|
||
@test_nowarn SetPlaintextModulus(parameters, plaintext_modulus) | ||
@test_nowarn SetMultiplicativeDepth(parameters, multiplicative_depth) | ||
end | ||
|
||
end # @testset "test_bgv.jl" | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters