SecureArithmetic
Secure arithmetic operations using fully homomorphic encryption
Science Score: 75.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 4 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Academic email domains
-
✓Institutional organization owner
Organization hpsc-lab has institutional domain (www.uni-augsburg.de) -
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.1%) to scientific vocabulary
Repository
Secure arithmetic operations using fully homomorphic encryption
Basic Info
- Host: GitHub
- Owner: hpsc-lab
- License: mit
- Language: Julia
- Default Branch: main
- Homepage: https://hpsc-lab.github.io/SecureArithmetic.jl
- Size: 746 KB
Statistics
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 4
- Releases: 8
Metadata Files
README.md
SecureArithmetic.jl
SecureArithmetic.jl is a Julia package for performing cryptographically secure arithmetic operations using fully homomorphic encryption. It currently provides a backend for OpenFHE-secured computations using OpenFHE.jl, and an unencrypted backend for fast verification of a computation pipeline.
Getting started
Prerequisites
If you have not yet installed Julia, please follow the instructions for your operating system. SecureArithmetic.jl works with Julia v1.10 and later on Linux, macOS and Windows platforms.
Installation
Since SecureArithmetic.jl is a registered Julia package, you can install it by executing
the following commands in the Julia REPL:
julia
julia> import Pkg; Pkg.add("SecureArithmetic")
If you plan on running the examples in the
examples directory,
you also need to install OpenFHE.jl:
julia
julia> import Pkg; Pkg.add("OpenFHE")
Usage
The easiest way to get started is to run one of the examples from the
examples directory by
includeing them in Julia, e.g.,
```julia
julia> using SecureArithmetic
julia> include(joinpath(pkgdir(SecureArithmetic), "examples", "simplerealnumbers.jl"))
Creating OpenFHE context... CKKS scheme is using ring dimension 16384
================================================================================ Creating unencrypted context...
================================================================================ simplerealnumbers with an OpenFHE context Input x1: [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0] Input x2: [5.0, 4.0, 3.0, 2.0, 1.0, 0.75, 0.5, 0.25]
Results of homomorphic computations: x1 = [0.24999999999993638, 0.500000000000056, 0.7500000000000366, 0.9999999999999498, 2.0000000000000333, 3.0000000000000675, 3.9999999999999902, 4.99999999999997] x1 + x2 = [5.2499999999999485, 4.499999999999966, 3.7500000000000533, 3.0000000000000466, 3.000000000000019, 3.7499999999999836, 4.499999999999986, 5.249999999999975] x1 - x2 = [-4.749999999999893, -3.4999999999999805, -2.249999999999964, -0.9999999999998668, 0.9999999999999534, 2.249999999999984, 3.5000000000000973, 4.749999999999956] 4 * x1 = [1.0000000000004539, 1.9999999999998535, 3.000000000000176, 4.000000000000274, 7.999999999998697, 12.000000000000373, 15.999999999998332, 20.00000000000011] x1 * x2 = [1.2500000000002318, 2.000000000000054, 2.2499999999994893, 1.9999999999998272, 2.000000000000205, 2.25000000000003, 1.9999999999997906, 1.2499999999996558] x1 shifted circularly by -1 = [0.4999999999998632, 0.749999999999976, 0.9999999999999369, 1.9999999999999858, 2.9999999999998677, 4.000000000000045, 5.000000000000059, 0.25000000000002087] x1 shifted circularly by 2 = [3.9999999999999973, 4.99999999999995, 0.2499999999999567, 0.49999999999996825, 0.7500000000000793, 0.9999999999998956, 2.00000000000004, 2.999999999999985]
================================================================================ simplerealnumbers with an Unencrypted context Input x1: [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0] Input x2: [5.0, 4.0, 3.0, 2.0, 1.0, 0.75, 0.5, 0.25]
Results of homomorphic computations: x1 = [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0] x1 + x2 = [5.25, 4.5, 3.75, 3.0, 3.0, 3.75, 4.5, 5.25] x1 - x2 = [-4.75, -3.5, -2.25, -1.0, 1.0, 2.25, 3.5, 4.75] 4 * x1 = [1.0, 2.0, 3.0, 4.0, 8.0, 12.0, 16.0, 20.0] x1 * x2 = [1.25, 2.0, 2.25, 2.0, 2.0, 2.25, 2.0, 1.25] x1 shifted circularly by -1 = [0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0, 0.25] x1 shifted circularly by 2 = [4.0, 5.0, 0.25, 0.5, 0.75, 1.0, 2.0, 3.0] ```
Memory issues
OpenFHE is a memory-optimized C++ library, but these optimizations can cause memory issues when transitioning to Julia.
In OpenFHE, large objects like Ciphertext, Plaintext, and CryptoContext are managed
using std::shared_ptr. These objects are not freed until all associated std::shared_ptrs
are destroyed. Since the Julia objects that hold a reference to these shared pointers are relatively
small, Julia's garbage collector does not always free them automatically, as they are not considered
a high priority for garbage collection. This is because Julia's garbage collector primarily
focuses on "young" objects during its incremental collections, leaving some std::shared_ptrs
in memory even when they are no longer in use. This may result in a significant increase in memory
consumption over time, as a single Ciphertext object can occupy over 60 MB. Consequently, complex
operations may lead to gigabytes of memory being occupied without being freed until the Julia
session is terminated. One possible solution is to manually trigger Julia's garbage collector
to perform a full collection, which will also clean up these "small" objects:
julia
GC.gc()
Additionally, OpenFHE optimizes memory usage in C++ by storing evaluation keys and CryptoContexts
in static objects. These objects, being quite large, remain in memory until the Julia REPL is
closed. To release them while the REPL is still running, you can execute the following function:
julia
release_context_memory()
Note that this will invalidate all currently existing contexts, even those which are
still in use. Thus you should only call these functions once you are done with a given
FHE setup and want to start a new one.
For more details, please refer to the documentation for release_context_memory.
Therefore, for a full cleanup of all OpenFHE-occupied memory, first ensure that all variables holding
references to OpenFHE objects are out of scope and then execute
julia
release_context_memory()
GC.gc()
By running these commands at appropriate points in your code, you can prevent excessive memory
usage and ensure efficient memory management when using SecureArithmetic.jl.
Multithreading
SecureArray internally stores encrypted data across multiple ciphertexts.
Since most operations with secure arrays - such as addition, multiplication, or bootstrapping -
are performed for each ciphertext individually, they can be parallelized across different threads.
By default, parallelization is disabled - you can enable it with enable_multithreading:
julia
enable_multithreading()
To disable it, use disable_multithreading:
julia
disable_multithreading()
When multithreading is enabled, for loops iterating over ciphertexts in SecureArray use
Threads.@threads to distribute work across Threads.nthreads() threads. However, if Julia runs
with only one thread (Threads.nthreads() == 1), Threads.@threads is not applied for efficiency.
Since multithreading works by splitting for loops over ciphertexts in SecureArray,
it is only effective if there are at least two ciphertexts.
Please be aware that mixing Julia's multithreading with OpenFHE's builtin OpenMP-based
multithreading might cause troubles. Thus if in doubt, set the environment variable
OMP_NUM_THREADS=1 to avoid potential issues.
Referencing
If you use SecureArithmetic.jl in your own research, please cite this repository as follows:
bibtex
@misc{schlottkelakemper2024securearithmetic,
title={{S}ecure{A}rithmetic.jl: {S}ecure arithmetic operations in {J}ulia using fully homomorphic encryption},
author={Schlottke-Lakemper, Michael},
year={2024},
howpublished={\url{https://github.com/hpsc-lab/SecureArithmetic.jl}},
doi={10.5281/zenodo.10544790}
}
Authors
SecureArithmetic.jl was initiated by Michael Schlottke-Lakemper (University of Augsburg, Germany). Together with Arseniy Kholod (University of Augsburg, Germany), he is its principal maintainer.
License and contributing
SecureArithmetic.jl is available under the MIT license (see LICENSE.md). Contributions by the community are very welcome! For larger proposed changes, feel free to reach out via an issue first.
Owner
- Name: High-Performance Scientific Computing Lab
- Login: hpsc-lab
- Kind: organization
- Email: michael.schlottke-lakemper@uni-a.de
- Location: Germany
- Website: https://www.uni-augsburg.de/fakultaet/mntf/math/prof/hpsc
- Repositories: 1
- Profile: https://github.com/hpsc-lab
Chair of High-Performance Scientific Computing, University of Augsburg
Citation (CITATION.bib)
@misc{schlottkelakemper2024securearithmetic,
title={{S}ecure{A}rithmetic.jl: {S}ecure arithmetic operations in {J}ulia using fully homomorphic encryption},
author={Schlottke-Lakemper, Michael},
year={2024},
howpublished={\url{https://github.com/hpsc-lab/SecureArithmetic.jl}},
doi={10.5281/zenodo.10544790}
}
GitHub Events
Total
- Create event: 14
- Commit comment event: 5
- Release event: 2
- Issues event: 6
- Delete event: 13
- Issue comment event: 39
- Push event: 46
- Pull request review comment event: 52
- Pull request review event: 52
- Pull request event: 40
Last Year
- Create event: 14
- Commit comment event: 5
- Release event: 2
- Issues event: 6
- Delete event: 13
- Issue comment event: 39
- Push event: 46
- Pull request review comment event: 52
- Pull request review event: 52
- Pull request event: 40
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 8
- Total pull requests: 31
- Average time to close issues: 24 days
- Average time to close pull requests: 9 days
- Total issue authors: 3
- Total pull request authors: 3
- Average comments per issue: 2.5
- Average comments per pull request: 0.71
- Merged pull requests: 23
- Bot issues: 0
- Bot pull requests: 15
Past Year
- Issues: 7
- Pull requests: 19
- Average time to close issues: 15 days
- Average time to close pull requests: 9 days
- Issue authors: 3
- Pull request authors: 3
- Average comments per issue: 1.29
- Average comments per pull request: 0.79
- Merged pull requests: 12
- Bot issues: 0
- Bot pull requests: 11
Top Authors
Issue Authors
- ArseniyKholod (4)
- sloede (3)
- Tortar (1)
Pull Request Authors
- dependabot[bot] (18)
- ArseniyKholod (16)
- sloede (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 8
juliahub.com: SecureArithmetic
Secure arithmetic operations using fully homomorphic encryption
- Homepage: https://hpsc-lab.github.io/SecureArithmetic.jl
- Documentation: https://docs.juliahub.com/General/SecureArithmetic/stable/
- License: MIT
-
Latest release: 0.2.1
published about 1 year ago
Rankings
Dependencies
- julia-actions/setup-julia v1 composite
- actions/checkout v4 composite
- julia-actions/julia-buildpkg v1 composite
- julia-actions/setup-julia v1 composite
- actions/checkout v4 composite
- crate-ci/typos v1.17.2 composite
- JuliaRegistries/TagBot v1 composite
- actions/checkout v4 composite
- codecov/codecov-action v3 composite
- coverallsapp/github-action master composite
- julia-actions/cache v1 composite
- julia-actions/julia-buildpkg v1 composite
- julia-actions/julia-processcoverage v1 composite
- julia-actions/julia-runtest v1 composite
- julia-actions/setup-julia v1 composite
- mxschmitt/action-tmate v3 composite