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

Try to fix failing CI test on macOS #14

Merged
merged 9 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://docs.codecov.io/docs/codecovyml-reference

# We have 2 parallel jobs in ci.yml
codecov:
notify:
after_n_builds: 2
comment:
after_n_builds: 2

github_checks:
annotations: false
2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }} # optional
run: julia -e 'using CompatHelper; CompatHelper.main()'
run: julia -e 'using CompatHelper; CompatHelper.main(; subdirs=["", "docs", "test"])'
24 changes: 24 additions & 0 deletions .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Documentation

on:
push:
branches:
- main
tags: '*'
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: '1.5'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
run: julia --project=docs/ docs/make.jl
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ jobs:
fail_ci_if_error: true # optional (default = false)
# verbose: true # optional (default = false)

finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
# finish:
# needs: test
# runs-on: ubuntu-latest
# steps:
# - name: Coveralls Finished
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# parallel-finished: true
55 changes: 38 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ After installation, load SEAL.jl by running
```julia
using SEAL
```
in the REPL. A **minimal** working example for encrypting an integer using the BFV
in the REPL. A **minimal** working example for encrypting an array of integers using the BFV
scheme, squaring it, and decrypting it, looks as follows:
```julia
julia> using SEAL
[ Info: Precompiling SEAL [bac81e26-86e4-4b48-8696-7d0406d5dbc1]

julia> parms = EncryptionParameters(SchemeType.BFV)
julia> parms = EncryptionParameters(SchemeType.bfv)
EncryptionParameters(Ptr{Nothing} @0x0000000002e1d3a0)

julia> poly_modulus_degree = 4096
Expand All @@ -62,7 +62,7 @@ EncryptionParameters(Ptr{Nothing} @0x0000000002e1d3a0)
julia> set_coeff_modulus!(parms, coeff_modulus_bfv_default(poly_modulus_degree))
EncryptionParameters(Ptr{Nothing} @0x0000000002e1d3a0)

julia> set_plain_modulus!(parms, 512)
julia> set_plain_modulus!(parms, plain_modulus_batching(poly_modulus_degree, 20))
EncryptionParameters(Ptr{Nothing} @0x0000000002e1d3a0)

julia> context = SEALContext(parms)
Expand All @@ -88,32 +88,53 @@ Evaluator(Ptr{Nothing} @0x000000000428bdd0)
julia> decryptor = Decryptor(context, secret_key_)
Decryptor(Ptr{Nothing} @0x00000000037670d0)

julia> encoder = IntegerEncoder(context) #FIXME fix-tests
IntegerEncoder(Ptr{Nothing} @0x0000000002ec3350, SEALContext(Ptr{Nothing} @0x0000000004298440)) #FIXME fix-tests
julia> batch_encoder = BatchEncoder(context)
BatchEncoder(Ptr{Nothing} @0x0000000001fb4bd0, SEALContext(Ptr{Nothing} @0x0000000001b87780))

julia> value = 7
7
julia> pod_matrix = collect(UInt64, 1:slot_count(batch_encoder));

julia> plain = encode(value, encoder) #FIXME fix-tests
julia> Int.(vcat(pod_matrix[1:3], pod_matrix[end-3:end]))
7-element Array{Int64,1}:
1
2
3
4093
4094
4095
4096

julia> plain_matrix = Plaintext()
Plaintext(Ptr{Nothing} @0x00000000042db6e0)

julia> encrypted = Ciphertext()
Ciphertext(Ptr{Nothing} @0x0000000002d91b80)
julia> encode!(plain_matrix, pod_matrix, batch_encoder)
Plaintext(Ptr{Nothing} @0x0000000002ce0370)

julia> encrypt!(encrypted, plain, encryptor)
julia> encrypted_matrix = Ciphertext()
Ciphertext(Ptr{Nothing} @0x0000000002d91b80)

julia> square_inplace!(encrypted, evaluator)
julia> encrypt!(encrypted_matrix, plain_matrix, encryptor)
Ciphertext(Ptr{Nothing} @0x0000000002d91b80)

julia> add_inplace!(encrypted_matrix, encrypted_matrix, evaluator)
Ciphertext(Ptr{Nothing} @0x0000000002ce1280)

julia> plain_result = Plaintext()
Plaintext(Ptr{Nothing} @0x0000000004591550)

julia> decrypt!(plain_result, encrypted, decryptor)
julia> decrypt!(plain_result, encrypted_matrix, decryptor)
Plaintext(Ptr{Nothing} @0x0000000004591550)

julia> decode_int32(plain_result, encoder) #FIXME fix-tests
49
julia> decode!(pod_matrix, plain_result, batch_encoder);

julia> Int.(vcat(pod_matrix[1:3], pod_matrix[end-3:end]))
7-element Array{Int64,1}:
2
4
6
8186
8188
8190
8192
```

### Examples
Expand All @@ -128,7 +149,7 @@ directory. Otherwise it will be very likely that you are using SEAL.jl (and SEAL
way that is either not secure, will produce unexpected results, or just crashes.
The examples included in SEAL.jl follow almost line-by-line the examples provided by the
[SEAL library](https://github.com/microsoft/SEAL/tree/master/native/examples).
For example, the snippet above is based on the `example_integer_encoder()` function in #FIXME fix-tests
For example, the snippet above is based on the `example_batch_encoder()` function in
[`examples/2_encoders.jl`](examples/2_encoders.jl).
The full list of examples is as follows:

Expand All @@ -155,7 +176,7 @@ julia --project=. -e 'include("SEAL.jl/examples/examples.jl"); seal_examples()'
You will be shown an interactive prompt that lets you run any of the available
examples:
```
Microsoft SEAL version: 3.5.5
Microsoft SEAL version: 3.6.2
+---------------------------------------------------------+
| The following examples should be executed while reading |
| comments in associated files in examples/. |
Expand Down
55 changes: 38 additions & 17 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ After installation, load SEAL.jl by running
```julia
using SEAL
```
in the REPL. A **minimal** working example for encrypting an integer using the BFV
in the REPL. A **minimal** working example for encrypting an array of integers using the BFV
scheme, squaring it, and decrypting it, looks as follows:
```julia
julia> using SEAL
[ Info: Precompiling SEAL [bac81e26-86e4-4b48-8696-7d0406d5dbc1]

julia> parms = EncryptionParameters(SchemeType.BFV)
julia> parms = EncryptionParameters(SchemeType.bfv)
EncryptionParameters(Ptr{Nothing} @0x0000000002e1d3a0)

julia> poly_modulus_degree = 4096
Expand All @@ -56,7 +56,7 @@ EncryptionParameters(Ptr{Nothing} @0x0000000002e1d3a0)
julia> set_coeff_modulus!(parms, coeff_modulus_bfv_default(poly_modulus_degree))
EncryptionParameters(Ptr{Nothing} @0x0000000002e1d3a0)

julia> set_plain_modulus!(parms, 512)
julia> set_plain_modulus!(parms, plain_modulus_batching(poly_modulus_degree, 20))
EncryptionParameters(Ptr{Nothing} @0x0000000002e1d3a0)

julia> context = SEALContext(parms)
Expand All @@ -82,32 +82,53 @@ Evaluator(Ptr{Nothing} @0x000000000428bdd0)
julia> decryptor = Decryptor(context, secret_key_)
Decryptor(Ptr{Nothing} @0x00000000037670d0)

julia> encoder = IntegerEncoder(context) #FIXME fix-tests
IntegerEncoder(Ptr{Nothing} @0x0000000002ec3350, SEALContext(Ptr{Nothing} @0x0000000004298440)) #FIXME fix-tests
julia> batch_encoder = BatchEncoder(context)
BatchEncoder(Ptr{Nothing} @0x0000000001fb4bd0, SEALContext(Ptr{Nothing} @0x0000000001b87780))

julia> value = 7
7
julia> pod_matrix = collect(UInt64, 1:slot_count(batch_encoder));

julia> plain = encode(value, encoder)
julia> Int.(vcat(pod_matrix[1:3], pod_matrix[end-3:end]))
7-element Array{Int64,1}:
1
2
3
4093
4094
4095
4096

julia> plain_matrix = Plaintext()
Plaintext(Ptr{Nothing} @0x00000000042db6e0)

julia> encrypted = Ciphertext()
Ciphertext(Ptr{Nothing} @0x0000000002d91b80)
julia> encode!(plain_matrix, pod_matrix, batch_encoder)
Plaintext(Ptr{Nothing} @0x0000000002ce0370)

julia> encrypt!(encrypted, plain, encryptor)
julia> encrypted_matrix = Ciphertext()
Ciphertext(Ptr{Nothing} @0x0000000002d91b80)

julia> square_inplace!(encrypted, evaluator)
julia> encrypt!(encrypted_matrix, plain_matrix, encryptor)
Ciphertext(Ptr{Nothing} @0x0000000002d91b80)

julia> add_inplace!(encrypted_matrix, encrypted_matrix, evaluator)
Ciphertext(Ptr{Nothing} @0x0000000002ce1280)

julia> plain_result = Plaintext()
Plaintext(Ptr{Nothing} @0x0000000004591550)

julia> decrypt!(plain_result, encrypted, decryptor)
julia> decrypt!(plain_result, encrypted_matrix, decryptor)
Plaintext(Ptr{Nothing} @0x0000000004591550)

julia> decode_int32(plain_result, encoder)
49
julia> decode!(pod_matrix, plain_result, batch_encoder);

julia> Int.(vcat(pod_matrix[1:3], pod_matrix[end-3:end]))
7-element Array{Int64,1}:
2
4
6
8186
8188
8190
8192
```

### Examples
Expand All @@ -122,7 +143,7 @@ directory. Otherwise it will be very likely that you are using SEAL.jl (and SEAL
way that is either not secure, will produce unexpected results, or just crashes.
The examples included in SEAL.jl follow almost line-by-line the examples provided by the
[SEAL library](https://github.com/microsoft/SEAL/tree/master/native/examples).
For example, the snippet above is based on the `example_integer_encoder()` function in # FIXME fix-tests
For example, the snippet above is based on the `example_batch_encoder()` function in
[`examples/2_encoders.jl`](https://github.com/JuliaCrypto/SEAL.jl/tree/main/examples/2_encoders.jl).
The full list of examples is as follows:

Expand All @@ -149,7 +170,7 @@ julia --project=. -e 'include("SEAL.jl/examples/examples.jl"); seal_examples()'
You will be shown an interactive prompt that lets you run any of the available
examples:
```
Microsoft SEAL version: 3.5.5
Microsoft SEAL version: 3.6.2
+---------------------------------------------------------+
| The following examples should be executed while reading |
| comments in associated files in examples/. |
Expand Down
2 changes: 1 addition & 1 deletion examples/7_performance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function bfv_performance_test(context)
encrypt!(encrypted1, plain1, encryptor)
encrypted2 = Ciphertext(context)
encode!(plain2, fill(UInt64(i+1), slot_count_), batch_encoder)
encrypt!(encrypted2, plain2, encryptor) #FIXME fix-tests
encrypt!(encrypted2, plain2, encryptor)
time_add_sum += @elapsedus begin
add_inplace!(encrypted1, encrypted1, evaluator)
add_inplace!(encrypted2, encrypted2, evaluator)
Expand Down
21 changes: 13 additions & 8 deletions src/SEAL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@ Abstract parent type for all types based on SEAL classes.
abstract type SEALObject end

"""
handle(object::SEALObject)
gethandle(object::SEALObject)

Return the raw C pointer to where `object` resides in memory.
"""
@inline handle(object::SEALObject) = object.handle
@inline gethandle(object::SEALObject) = object.handle

"""
sethandle!(object::SEALObject, handle)

Set the underlying raw C pointer to where `object` resides in memory to `handle`.
"""
@inline sethandle!(object::SEALObject, handle) = object.handle = handle

"""
destroy(object::SEALObject)
destroy!(object::SEALObject)

Call the corresponding destruction function on `object` to free up memory and reset object handle to
a null pointer. If `object` is not allocated, `destroy` will not do anything.
a null pointer. If `object` is not allocated, `destroy!` will not do anything.
"""
function destroy(object::SEALObject) end
function destroy!(object::SEALObject) end

"""
isnull(object::SEALObject)

Return true if the object handle is a null pointer and false otherwise.
"""
@inline isnull(object::SEALObject) = handle(object) == C_NULL
@inline isnull(object::SEALObject) = gethandle(object) == C_NULL

"""
isallocated(object::SEALObject)
Expand All @@ -41,9 +46,9 @@ Return true if the object is allocated, i.e., if it is not null.
"""
@inline isallocated(object::SEALObject) = !isnull(object)

export SEALObject, handle, destroy, isnull, isallocated
export SEALObject, gethandle, sethandle!, destroy!, isnull, isallocated

Base.unsafe_convert(::Type{Ptr{Cvoid}}, object::SEALObject) = handle(object)
Base.unsafe_convert(::Type{Ptr{Cvoid}}, object::SEALObject) = gethandle(object)

include("auxiliary.jl")
# Julia-only auxiliary methods -> no exports
Expand Down
9 changes: 6 additions & 3 deletions src/batchencoder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ mutable struct BatchEncoder <: SEALObject

function BatchEncoder(handle::Ptr{Cvoid}, context)
object = new(handle, context)
finalizer(destroy, object)
finalizer(destroy!, object)
return object
end
end

function destroy(object::BatchEncoder)
function destroy!(object::BatchEncoder)
if isallocated(object)
ccall((:BatchEncoder_Destroy, libsealc), Clong, (Ptr{Cvoid},), object)
@check_return_value ccall((:BatchEncoder_Destroy, libsealc), Clong, (Ptr{Cvoid},), object)
sethandle!(object, C_NULL)
end

return nothing
end

function slot_count(encoder::BatchEncoder)
Expand Down
9 changes: 6 additions & 3 deletions src/ciphertext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ mutable struct Ciphertext <: SEALObject

function Ciphertext(handle::Ptr{Cvoid})
object = new(handle)
finalizer(destroy, object)
finalizer(destroy!, object)
return object
end
end

function destroy(object::Ciphertext)
function destroy!(object::Ciphertext)
if isallocated(object)
ccall((:Ciphertext_Destroy, libsealc), Clong, (Ptr{Cvoid},), object)
@check_return_value ccall((:Ciphertext_Destroy, libsealc), Clong, (Ptr{Cvoid},), object)
sethandle!(object, C_NULL)
end

return nothing
end

function scale(encrypted::Ciphertext)
Expand Down
Loading