-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeygenerator.jl
76 lines (66 loc) · 2.36 KB
/
keygenerator.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
KeyGenerator
Can be used to generate a pair of matching secret and public keys. In addition, the `KeyGenerator`
provides functions to obtain relinearization keys (required after multiplication) and Galois keys
(needed for rotation).
See also: [`SecretKey`](@ref), [`PublicKey`](@ref), [`RelinKeys`](@ref)
"""
mutable struct KeyGenerator <: SEALObject
handle::Ptr{Cvoid}
function KeyGenerator(context::SEALContext)
handleref = Ref{Ptr{Cvoid}}(C_NULL)
retval = ccall((:KeyGenerator_Create1, libsealc), Clong,
(Ptr{Cvoid}, Ref{Ptr{Cvoid}}),
context, handleref)
@check_return_value retval
return KeyGenerator(handleref[])
end
function KeyGenerator(handle::Ptr{Cvoid})
x = new(handle)
finalizer(x) do x
# @async println("Finalizing $x at line $(@__LINE__).")
ccall((:KeyGenerator_Destroy, libsealc), Clong, (Ptr{Cvoid},), x)
end
return x
end
end
function public_key(keygen::KeyGenerator)
keyptr = Ref{Ptr{Cvoid}}(C_NULL)
retval = ccall((:KeyGenerator_PublicKey, libsealc), Clong,
(Ptr{Cvoid}, Ref{Ptr{Cvoid}}),
keygen, keyptr)
@check_return_value retval
return PublicKey(keyptr[])
end
function secret_key(keygen::KeyGenerator)
keyptr = Ref{Ptr{Cvoid}}(C_NULL)
retval = ccall((:KeyGenerator_SecretKey, libsealc), Clong,
(Ptr{Cvoid}, Ref{Ptr{Cvoid}}),
keygen, keyptr)
@check_return_value retval
return SecretKey(keyptr[])
end
function relin_keys_local(keygen::KeyGenerator)
keyptr = Ref{Ptr{Cvoid}}(C_NULL)
retval = ccall((:KeyGenerator_RelinKeys, libsealc), Clong,
(Ptr{Cvoid}, UInt8, Ref{Ptr{Cvoid}}),
keygen, false, keyptr)
@check_return_value retval
return RelinKeys(keyptr[])
end
function relin_keys(keygen::KeyGenerator)
keyptr = Ref{Ptr{Cvoid}}(C_NULL)
retval = ccall((:KeyGenerator_RelinKeys, libsealc), Clong,
(Ptr{Cvoid}, UInt8, Ref{Ptr{Cvoid}}),
keygen, true, keyptr)
@check_return_value retval
return RelinKeys(keyptr[])
end
function galois_keys_local(keygen::KeyGenerator)
keyptr = Ref{Ptr{Cvoid}}(C_NULL)
retval = ccall((:KeyGenerator_GaloisKeysAll, libsealc), Clong,
(Ptr{Cvoid}, UInt8, Ref{Ptr{Cvoid}}),
keygen, false, keyptr)
@check_return_value retval
return GaloisKeys(keyptr[])
end