{"id":47444071,"url":"https://github.com/hpsc-lab/SecureArithmetic.jl","last_synced_at":"2026-04-06T13:00:55.992Z","repository":{"id":215304179,"uuid":"738595413","full_name":"hpsc-lab/SecureArithmetic.jl","owner":"hpsc-lab","description":"Secure arithmetic operations using fully homomorphic encryption","archived":false,"fork":false,"pushed_at":"2026-03-01T08:23:40.000Z","size":1413,"stargazers_count":6,"open_issues_count":6,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-03-09T10:32:00.073Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://hpsc-lab.github.io/SecureArithmetic.jl","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hpsc-lab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.bib","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":".zenodo.json","notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-03T15:37:37.000Z","updated_at":"2026-02-02T10:14:06.000Z","dependencies_parsed_at":"2024-02-01T10:24:52.825Z","dependency_job_id":"4674d42e-876d-482f-8de0-dd0a7ae7372d","html_url":"https://github.com/hpsc-lab/SecureArithmetic.jl","commit_stats":null,"previous_names":["sloede/securearithmetic.jl","hpsc-lab/securearithmetic.jl"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/hpsc-lab/SecureArithmetic.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpsc-lab%2FSecureArithmetic.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpsc-lab%2FSecureArithmetic.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpsc-lab%2FSecureArithmetic.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpsc-lab%2FSecureArithmetic.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hpsc-lab","download_url":"https://codeload.github.com/hpsc-lab/SecureArithmetic.jl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpsc-lab%2FSecureArithmetic.jl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31473271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T08:36:52.050Z","status":"ssl_error","status_checked_at":"2026-04-06T08:36:51.267Z","response_time":112,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-03-23T06:00:59.902Z","updated_at":"2026-04-06T13:00:55.969Z","avatar_url":"https://github.com/hpsc-lab.png","language":"Julia","funding_links":[],"categories":["Cryptography"],"sub_categories":["Homomorphic Encryption"],"readme":"# SecureArithmetic.jl\n\n[![Docs-stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://hpsc-lab.github.io/SecureArithmetic.jl/stable)\n[![Docs-dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://hpsc-lab.github.io/SecureArithmetic.jl/dev)\n[![Build Status](https://github.com/hpsc-lab/SecureArithmetic.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/hpsc-lab/SecureArithmetic.jl/actions?query=workflow%3ACI)\n[![Coveralls](https://coveralls.io/repos/github/hpsc-lab/SecureArithmetic.jl/badge.svg)](https://coveralls.io/github/hpsc-lab/SecureArithmetic.jl)\n[![Codecov](https://codecov.io/gh/hpsc-lab/SecureArithmetic.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/hpsc-lab/SecureArithmetic.jl)\n[![License: MIT](https://img.shields.io/badge/License-MIT-success.svg)](https://opensource.org/license/mit/)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10544790.svg)](https://doi.org/10.5281/zenodo.10544790)\n\nSecureArithmetic.jl is a Julia package for performing cryptographically secure arithmetic\noperations using fully homomorphic encryption. It currently provides a backend for\nOpenFHE-secured computations using [OpenFHE.jl](https://github.com/hpsc-lab/OpenFHE.jl), and\nan unencrypted backend for fast verification of a computation pipeline.\n\n\n## Getting started\n\n### Prerequisites\nIf you have not yet installed Julia, please [follow the instructions for your\noperating system](https://julialang.org/downloads/platform/).\n[SecureArithmetic.jl](https://github.com/hpsc-lab/SecureArithmetic.jl) works with Julia v1.10\nand later on Linux, macOS and Windows platforms.\n\n### Installation\nSince SecureArithmetic.jl  is a registered Julia package, you can install it by executing\nthe following commands in the Julia REPL:\n```julia\njulia\u003e import Pkg; Pkg.add(\"SecureArithmetic\")\n```\nIf you plan on running the examples in the\n[`examples`](https://github.com/hpsc-lab/SecureArithmetic.jl/tree/main/examples) directory,\nyou also need to install OpenFHE.jl:\n```julia\njulia\u003e import Pkg; Pkg.add(\"OpenFHE\")\n```\n\n### Usage\nThe easiest way to get started is to run one of the examples from the\n[`examples`](https://github.com/hpsc-lab/SecureArithmetic.jl/tree/main/examples) directory by\n`include`ing them in Julia, e.g.,\n```julia\njulia\u003e using SecureArithmetic\n\njulia\u003e include(joinpath(pkgdir(SecureArithmetic), \"examples\", \"simple_real_numbers.jl\"))\n================================================================================\nCreating OpenFHE context...\nCKKS scheme is using ring dimension 16384\n\n================================================================================\nCreating unencrypted context...\n\n================================================================================\nsimple_real_numbers with an OpenFHE context\nInput x1: [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0]\nInput x2: [5.0, 4.0, 3.0, 2.0, 1.0, 0.75, 0.5, 0.25]\n\nResults of homomorphic computations:\nx1 = [0.24999999999993638, 0.500000000000056, 0.7500000000000366, 0.9999999999999498, 2.0000000000000333, 3.0000000000000675, 3.9999999999999902, 4.99999999999997]\nx1 + x2 = [5.2499999999999485, 4.499999999999966, 3.7500000000000533, 3.0000000000000466, 3.000000000000019, 3.7499999999999836, 4.499999999999986, 5.249999999999975]\nx1 - x2 = [-4.749999999999893, -3.4999999999999805, -2.249999999999964, -0.9999999999998668, 0.9999999999999534, 2.249999999999984, 3.5000000000000973, 4.749999999999956]\n4 * x1 = [1.0000000000004539, 1.9999999999998535, 3.000000000000176, 4.000000000000274, 7.999999999998697, 12.000000000000373, 15.999999999998332, 20.00000000000011]\nx1 * x2 = [1.2500000000002318, 2.000000000000054, 2.2499999999994893, 1.9999999999998272, 2.000000000000205, 2.25000000000003, 1.9999999999997906, 1.2499999999996558]\nx1 shifted circularly by -1 = [0.4999999999998632, 0.749999999999976, 0.9999999999999369, 1.9999999999999858, 2.9999999999998677, 4.000000000000045, 5.000000000000059, 0.25000000000002087]\nx1 shifted circularly by 2 = [3.9999999999999973, 4.99999999999995, 0.2499999999999567, 0.49999999999996825, 0.7500000000000793, 0.9999999999998956, 2.00000000000004, 2.999999999999985]\n\n================================================================================\nsimple_real_numbers with an Unencrypted context\nInput x1: [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0]\nInput x2: [5.0, 4.0, 3.0, 2.0, 1.0, 0.75, 0.5, 0.25]\n\nResults of homomorphic computations:\nx1 = [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0]\nx1 + x2 = [5.25, 4.5, 3.75, 3.0, 3.0, 3.75, 4.5, 5.25]\nx1 - x2 = [-4.75, -3.5, -2.25, -1.0, 1.0, 2.25, 3.5, 4.75]\n4 * x1 = [1.0, 2.0, 3.0, 4.0, 8.0, 12.0, 16.0, 20.0]\nx1 * x2 = [1.25, 2.0, 2.25, 2.0, 2.0, 2.25, 2.0, 1.25]\nx1 shifted circularly by -1 = [0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0, 0.25]\nx1 shifted circularly by 2 = [4.0, 5.0, 0.25, 0.5, 0.75, 1.0, 2.0, 3.0]\n```\n\n### Memory issues\nOpenFHE is a memory-optimized C++ library, but these optimizations can cause\nmemory issues when transitioning to Julia.\n\nIn OpenFHE, large objects like `Ciphertext`, `Plaintext`, and `CryptoContext` are managed\nusing `std::shared_ptr`. These objects are not freed until all associated `std::shared_ptr`s\nare destroyed. Since the Julia objects that hold a reference to these shared pointers are relatively\nsmall, Julia's garbage collector does not always free them automatically, as they are not considered\na high priority for garbage collection. This is because Julia's garbage collector primarily\nfocuses on \"young\" objects during its incremental collections, leaving some `std::shared_ptr`s\nin memory even when they are no longer in use. This may result in a significant increase in memory\nconsumption over time, as a single `Ciphertext` object can occupy over 60 MB. Consequently, complex\noperations may lead to gigabytes of memory being occupied without being freed until the Julia\nsession is terminated. One possible solution is to manually trigger Julia's garbage collector\nto perform a full collection, which will also clean up these \"small\" objects:\n```julia\nGC.gc()\n```\n\nAdditionally, OpenFHE optimizes memory usage in C++ by storing evaluation keys and `CryptoContext`s\nin static objects. These objects, being quite large, remain in memory until the Julia REPL is\nclosed. To release them while the REPL is still running, you can execute the following function:\n```julia\nrelease_context_memory()\n```\nNote that this will invalidate all currently existing contexts, even those which are\nstill in use. Thus you should only call these functions once you are done with a given\nFHE setup and want to start a new one.\nFor more details, please refer to the documentation for [`release_context_memory`](@ref).\n\nTherefore, for a full cleanup of all OpenFHE-occupied memory, first ensure that all variables holding\nreferences to OpenFHE objects are out of scope and then execute\n```julia\nrelease_context_memory()\nGC.gc()\n```\nBy running these commands at appropriate points in your code, you can prevent excessive memory\nusage and ensure efficient memory management when using SecureArithmetic.jl.\n\n\n### Multithreading\n[`SecureArray`](@ref) internally stores encrypted data across multiple ciphertexts.\nSince most operations with secure arrays - such as addition, multiplication, or bootstrapping -\nare performed for each ciphertext individually, they can be parallelized across different threads.\nBy default, parallelization is disabled - you can enable it with [`enable_multithreading`](@ref):\n```julia\nenable_multithreading()\n```\nTo disable it, use [`disable_multithreading`](@ref):\n```julia\ndisable_multithreading()\n```\nWhen multithreading is enabled, `for` loops iterating over ciphertexts in `SecureArray` use\n`Threads.@threads` to distribute work across `Threads.nthreads()` threads. However, if Julia runs\nwith only one thread (`Threads.nthreads() == 1`), `Threads.@threads` is not applied for efficiency.\n\nSince multithreading works by splitting `for` loops over ciphertexts in `SecureArray`,\nit is only effective if there are at least two ciphertexts.\n\nPlease be aware that mixing Julia's multithreading with OpenFHE's builtin OpenMP-based\nmultithreading might cause troubles. Thus if in doubt, set the environment variable\n`OMP_NUM_THREADS=1` to avoid potential issues.\n\n\n## Referencing\nIf you use SecureArithmetic.jl in your own research, please cite this repository as follows:\n```bibtex\n@misc{schlottkelakemper2024securearithmetic,\n  title={{S}ecure{A}rithmetic.jl: {S}ecure arithmetic operations in {J}ulia using fully homomorphic encryption},\n  author={Schlottke-Lakemper, Michael},\n  year={2024},\n  howpublished={\\url{https://github.com/hpsc-lab/SecureArithmetic.jl}},\n  doi={10.5281/zenodo.10544790}\n}\n```\n\n\n## Authors\nSecureArithmetic.jl was initiated by [Michael Schlottke-Lakemper](https://hpsc.math.uni-augsburg.de)\n(University of Augsburg, Germany). Together with Arseniy Kholod (University of Augsburg, Germany),\nhe is its principal maintainer.\n\n\n## License and contributing\nSecureArithmetic.jl is available under the MIT license (see [LICENSE.md](LICENSE.md)).\nContributions by the community are very welcome! For larger proposed changes, feel free\nto reach out via an issue first.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhpsc-lab%2FSecureArithmetic.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhpsc-lab%2FSecureArithmetic.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhpsc-lab%2FSecureArithmetic.jl/lists"}