Skip to content

Commit be13cdd

Browse files
authored
Extend evaluator (#21)
* Fix devbranch name * Add bindings negate_inplace!, sub!, sub_inplace!
1 parent 98b6729 commit be13cdd

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ makedocs(
4343

4444
deploydocs(
4545
repo = "github.com/JuliaCrypto/SEAL.jl.git",
46+
devbranch = "main"
4647
)

src/SEAL.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export Evaluator, square!, square_inplace!, relinearize!, relinearize_inplace!,
107107
mod_switch_to_next_inplace!, add!, add_inplace!, add_plain!, add_plain_inplace!,
108108
rotate_vector!, rotate_vector_inplace!, rotate_rows!, rotate_rows_inplace!,
109109
rotate_columns!, rotate_columns_inplace!, complex_conjugate!, complex_conjugate_inplace!,
110-
negate!
110+
negate!, negate_inplace!, sub!, sub_inplace!
111111

112112
include("decryptor.jl")
113113
export Decryptor, decrypt!, invariant_noise_budget

src/evaluator.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,20 @@ function negate!(destination::Ciphertext, encrypted::Ciphertext, evaluator::Eval
228228
@check_return_value retval
229229
return destination
230230
end
231+
232+
function negate_inplace!(encrypted::Ciphertext, evaluator::Evaluator)
233+
return negate!(encrypted, encrypted, evaluator)
234+
end
235+
236+
function sub!(destination::Ciphertext, encrypted1::Ciphertext, encrypted2::Ciphertext,
237+
evaluator::Evaluator)
238+
retval = ccall((:Evaluator_Sub, libsealc), Clong,
239+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
240+
evaluator, encrypted1, encrypted2, destination)
241+
@check_return_value retval
242+
return destination
243+
end
244+
245+
function sub_inplace!(encrypted1::Ciphertext, encrypted2::Ciphertext, evaluator::Evaluator)
246+
return sub!(encrypted1, encrypted1, encrypted2, evaluator)
247+
end

test/test_extra.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,31 @@
161161
@test negate!(c11, c10, evaluator) == c11
162162
end
163163

164+
@testset "negate_inplace!" begin
165+
c12 = Ciphertext()
166+
encrypt!(c12, p, encryptor)
167+
@test negate_inplace!(c12, evaluator) == c12
168+
end
169+
170+
@testset "sub!" begin
171+
c13 = Ciphertext()
172+
c14 = Ciphertext()
173+
c15 = Ciphertext()
174+
encrypt!(c13, p, encryptor)
175+
encrypt!(c14, p, encryptor)
176+
@test sub!(c15, c13, c14, evaluator) == c15
177+
end
178+
179+
@testset "sub_inplace!" begin
180+
c16 = Ciphertext()
181+
c17 = Ciphertext()
182+
encrypt!(c16, p, encryptor)
183+
encrypt!(c17, p, encryptor)
184+
@test sub_inplace!(c16, c17, evaluator) == c16
185+
end
186+
164187
@testset "using_keyswitching" begin
165-
using_keyswitching(context) == true
188+
@test using_keyswitching(context) == true
166189
end
167190

168191
@testset "Plaintext constructor" begin

0 commit comments

Comments
 (0)