├── .bazelignore ├── .bazeliskrc ├── .bazelrc ├── .bcr ├── metadata.template.json ├── presubmit.yml └── source.template.json ├── .circleci ├── config.yml ├── continue-config.yml └── release-config.yml ├── .clang-format ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── feature_request.yml └── workflows │ ├── black.yml │ ├── buildifier.yml │ ├── cla.yml │ ├── clang-format-linter.yml │ ├── license-check.yml │ ├── oscp.yml │ ├── trigger-circleci.yml │ └── yaml-linter.yaml ├── .gitignore ├── .licenserc.yaml ├── .pre-commit-config.yaml ├── BUILD.bazel ├── CHANGELOGS.md ├── CONTRIBUTING.md ├── LEGAL.md ├── LICENSE ├── MODULE.bazel ├── README.md ├── README_cn.md ├── SECURITY.md ├── bazel ├── BUILD.bazel └── defs.bzl ├── build_wheel_entrypoint.sh ├── docs ├── Makefile ├── _static │ ├── css │ │ └── custom.css │ ├── favicon.ico │ ├── logo-dark.png │ └── logo.png ├── conf.py ├── development │ ├── _img │ │ ├── matrix_matmul.png │ │ ├── matrix_op.png │ │ └── phe_spi.png │ ├── arch.rst │ ├── index.rst │ └── phe_dev.rst ├── getting_started │ ├── _img │ │ ├── batch_encoding.png │ │ ├── heu_client_server.png │ │ └── obj_type.png │ ├── algo_choice.rst │ ├── faq.rst │ ├── index.rst │ ├── installation.rst │ ├── numpy.rst │ └── quick_start.rst ├── images │ └── heu_arch.png ├── index.rst ├── locale │ ├── en │ │ └── LC_MESSAGES │ │ │ ├── development │ │ │ ├── arch.po │ │ │ ├── index.po │ │ │ └── phe_dev.po │ │ │ ├── getting_started │ │ │ ├── algo_choice.po │ │ │ ├── faq.po │ │ │ ├── index.po │ │ │ ├── installation.po │ │ │ ├── numpy.po │ │ │ └── quick_start.po │ │ │ ├── index.po │ │ │ └── references │ │ │ ├── index.po │ │ │ ├── numpy_api.po │ │ │ ├── phe_api.po │ │ │ └── upgrade_guide.po │ └── zh_CN │ │ └── LC_MESSAGES │ │ └── references │ │ ├── numpy_api.po │ │ └── phe_api.po ├── make.bat ├── readme.md ├── references │ ├── _img │ │ ├── 0_2_flow.png │ │ ├── 0_3_encoder.png │ │ └── 0_3_flow.png │ ├── index.rst │ ├── numpy_api.rst │ ├── phe_api.rst │ └── upgrade_guide.rst └── requirements.txt ├── heu ├── BUILD.bazel ├── algorithms │ ├── BUILD.bazel │ ├── README.md │ ├── common │ │ ├── BUILD.bazel │ │ ├── he_assert.h │ │ └── type_alias.h │ ├── incubator │ │ ├── README.md │ │ ├── ishe │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── base.cc │ │ │ ├── base.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── he_kit.cc │ │ │ ├── he_kit.h │ │ │ └── ishe_test.cc │ │ ├── mock_fhe │ │ │ ├── BUILD.bazel │ │ │ ├── base.cc │ │ │ ├── base.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── encoders.cc │ │ │ ├── encoders.h │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── he_kit.cc │ │ │ └── he_kit.h │ │ └── mock_phe │ │ │ ├── BUILD.bazel │ │ │ ├── base.cc │ │ │ ├── base.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── he_kit.cc │ │ │ └── he_kit.h │ ├── ou │ │ ├── BUILD.bazel │ │ ├── base.cc │ │ ├── base.h │ │ ├── decryptor.cc │ │ ├── decryptor.h │ │ ├── encryptor.cc │ │ ├── encryptor.h │ │ ├── evaluator.cc │ │ ├── evaluator.h │ │ ├── he_kit.cc │ │ └── he_kit.h │ └── paillier_zahlen │ │ ├── BUILD.bazel │ │ ├── base.cc │ │ ├── base.h │ │ ├── decryptor.cc │ │ ├── decryptor.h │ │ ├── encryptor.cc │ │ ├── encryptor.h │ │ ├── evaluator.cc │ │ ├── evaluator.h │ │ ├── he_kit.cc │ │ └── he_kit.h ├── experimental │ ├── gemini-rlwe │ │ ├── BUILD.bazel │ │ ├── a2h.cc │ │ ├── a2h.h │ │ ├── a2h_test.cc │ │ ├── lwe_ct.cc │ │ ├── lwe_decryptor.cc │ │ ├── lwe_decryptor.h │ │ ├── lwe_secret_key.cc │ │ ├── lwe_types.h │ │ ├── matvec.cc │ │ ├── matvec.h │ │ ├── matvec_test.cc │ │ ├── modswitch_helper.cc │ │ ├── modswitch_helper.h │ │ ├── modswitch_helper_test.cc │ │ ├── poly_encoder.cc │ │ ├── poly_encoder.h │ │ ├── rlwe_2_lwe_test.cc │ │ ├── util.cc │ │ └── util.h │ ├── gpu-ckks │ │ └── README.md │ └── tfhe │ │ ├── .rustfmt.toml │ │ ├── Cargo.toml │ │ ├── README.md │ │ ├── benches │ │ └── zq_bench.rs │ │ ├── src │ │ ├── BUILD.bazel │ │ ├── bin │ │ │ └── bench_bootstrap.rs │ │ ├── lib.rs │ │ ├── tools │ │ │ └── mod.rs │ │ └── zq │ │ │ ├── decryptor.rs │ │ │ ├── encryptor.rs │ │ │ ├── evaluator.rs │ │ │ ├── ffi.rs │ │ │ ├── key_generator.rs │ │ │ └── mod.rs │ │ └── tests │ │ ├── BUILD.bazel │ │ ├── boolean.rs │ │ ├── bootstrap.rs │ │ ├── cxxbind │ │ ├── BUILD.bazel │ │ └── basic.cc │ │ └── linear.rs ├── library │ ├── algorithms │ │ ├── clean_template │ │ │ ├── ciphertext.h │ │ │ ├── key_generator.h │ │ │ ├── mix_spi_demo.h │ │ │ ├── plaintext.h │ │ │ ├── public_key.h │ │ │ ├── scalar_decryptor.h │ │ │ ├── scalar_encryptor.h │ │ │ ├── scalar_evaluator.h │ │ │ ├── secret_key.h │ │ │ ├── vector_decryptor.h │ │ │ ├── vector_encryptor.h │ │ │ └── vector_evaluator.h │ │ ├── dgk │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── ciphertext.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── dgk.h │ │ │ ├── dgk_test.cc │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ ├── secret_key.cc │ │ │ └── secret_key.h │ │ ├── dj │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── ciphertext.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── dj.h │ │ │ ├── dj_test.cc │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ ├── secret_key.cc │ │ │ └── secret_key.h │ │ ├── elgamal │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── ciphertext.cc │ │ │ ├── ciphertext.h │ │ │ ├── elgamal.h │ │ │ ├── elgamal_test.cc │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── plaintext.h │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ ├── scalar_decryptor.cc │ │ │ ├── scalar_decryptor.h │ │ │ ├── scalar_encryptor.cc │ │ │ ├── scalar_encryptor.h │ │ │ ├── scalar_evaluator.cc │ │ │ ├── scalar_evaluator.h │ │ │ ├── secret_key.cc │ │ │ ├── secret_key.h │ │ │ └── utils │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── hash_map.h │ │ │ │ ├── lookup_table.cc │ │ │ │ ├── lookup_table.h │ │ │ │ └── lookup_table_test.cc │ │ ├── mock │ │ │ ├── BUILD.bazel │ │ │ ├── ciphertext.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── mock.h │ │ │ ├── plaintext.h │ │ │ ├── public_key.h │ │ │ ├── secret_key.h │ │ │ └── switch_spi.h │ │ ├── ou │ │ │ ├── BUILD.bazel │ │ │ ├── ciphertext.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── encryptor_test.cc │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── evaluator_test.cc │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── key_generator_test.cc │ │ │ ├── ou.h │ │ │ ├── ou_test.cc │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ └── secret_key.h │ │ ├── paillier_clustar_fpga │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── ciphertext.cc │ │ │ ├── ciphertext.h │ │ │ ├── ciphertext_test.cc │ │ │ ├── clustar_fpga.h │ │ │ ├── enc_dec_test.cc │ │ │ ├── evaluator_test.cc │ │ │ ├── fpga_engine │ │ │ │ ├── config │ │ │ │ │ ├── BUILD.bazel │ │ │ │ │ ├── config.cc │ │ │ │ │ └── config.h │ │ │ │ ├── driver │ │ │ │ │ ├── BUILD.bazel │ │ │ │ │ ├── dma.cc │ │ │ │ │ ├── dma.h │ │ │ │ │ ├── driver.cc │ │ │ │ │ ├── driver.h │ │ │ │ │ ├── mpint_wrapper.cc │ │ │ │ │ ├── mpint_wrapper.h │ │ │ │ │ ├── multi_driver.cc │ │ │ │ │ ├── reg.cc │ │ │ │ │ ├── reg.h │ │ │ │ │ ├── task.cc │ │ │ │ │ └── task.h │ │ │ │ └── paillier_operators │ │ │ │ │ ├── BUILD.bazel │ │ │ │ │ ├── fpga_types.cc │ │ │ │ │ ├── fpga_types.h │ │ │ │ │ ├── paillier_operators.cc │ │ │ │ │ └── paillier_operators.h │ │ │ ├── key_gen_test.cc │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── plaintext.cc │ │ │ ├── plaintext.h │ │ │ ├── plaintext_test.cc │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ ├── secret_key.cc │ │ │ ├── secret_key.h │ │ │ ├── utils │ │ │ │ ├── facility.cc │ │ │ │ ├── facility.h │ │ │ │ ├── pub_key_helper.cc │ │ │ │ ├── pub_key_helper.h │ │ │ │ ├── secr_key_helper.cc │ │ │ │ └── secr_key_helper.h │ │ │ ├── vector_decryptor.cc │ │ │ ├── vector_decryptor.h │ │ │ ├── vector_encryptor.cc │ │ │ ├── vector_encryptor.h │ │ │ ├── vector_evaluator.cc │ │ │ └── vector_evaluator.h │ │ ├── paillier_float │ │ │ ├── BUILD.bazel │ │ │ ├── ciphertext.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── internal │ │ │ │ ├── codec.cc │ │ │ │ ├── codec.h │ │ │ │ └── codec_test.cc │ │ │ ├── key_gen.cc │ │ │ ├── key_gen.h │ │ │ ├── paillier.h │ │ │ ├── paillier_test.cc │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ ├── secret_key.cc │ │ │ └── secret_key.h │ │ ├── paillier_gpu │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── ciphertext.cc │ │ │ ├── ciphertext.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── gpulib │ │ │ │ ├── error.h │ │ │ │ ├── gpu_paillier.h │ │ │ │ ├── gpupaillier.h │ │ │ │ └── paillier.cu │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── key_generator_test.cc │ │ │ ├── paillier.h │ │ │ ├── paillier_gpu_test.cc │ │ │ ├── paillier_gpu_test_con.cc │ │ │ ├── plaintext.h │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ ├── secret_key.cc │ │ │ └── secret_key.h │ │ ├── paillier_ic │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── ciphertext.cc │ │ │ ├── ciphertext.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── paillier.h │ │ │ ├── paillier_test.cc │ │ │ ├── pb_utils.cc │ │ │ ├── pb_utils.h │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ └── secret_key.h │ │ ├── paillier_ipcl │ │ │ ├── BUILD.bazel │ │ │ ├── ciphertext.cc │ │ │ ├── ciphertext.h │ │ │ ├── ipcl.h │ │ │ ├── ipcl_test.cc │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── plaintext.cc │ │ │ ├── plaintext.h │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ ├── secret_key.cc │ │ │ ├── secret_key.h │ │ │ ├── utils.cc │ │ │ ├── utils.h │ │ │ ├── vector_decryptor.cc │ │ │ ├── vector_decryptor.h │ │ │ ├── vector_encryptor.cc │ │ │ ├── vector_encryptor.h │ │ │ ├── vector_evaluator.cc │ │ │ └── vector_evaluator.h │ │ ├── paillier_zahlen │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── ciphertext.h │ │ │ ├── decryptor.cc │ │ │ ├── decryptor.h │ │ │ ├── encryptor.cc │ │ │ ├── encryptor.h │ │ │ ├── evaluator.cc │ │ │ ├── evaluator.h │ │ │ ├── key_generator.cc │ │ │ ├── key_generator.h │ │ │ ├── key_generator_test.cc │ │ │ ├── paillier.h │ │ │ ├── paillier_test.cc │ │ │ ├── public_key.cc │ │ │ ├── public_key.h │ │ │ ├── secret_key.cc │ │ │ └── secret_key.h │ │ └── util │ │ │ ├── BUILD.bazel │ │ │ ├── big_int.h │ │ │ ├── he_assert.h │ │ │ ├── he_object.h │ │ │ ├── mp_int.h │ │ │ └── spi_traits.h │ ├── benchmark │ │ ├── BUILD.bazel │ │ ├── README.md │ │ ├── algos │ │ │ ├── BUILD.bazel │ │ │ ├── ou_bench.cc │ │ │ └── paillier_float_bench.cc │ │ ├── bigint │ │ │ ├── BUILD.bazel │ │ │ ├── bigint_bench.cc │ │ │ └── crt_bench.cc │ │ ├── np_bench.cc │ │ ├── phe_bench.cc │ │ └── python_paillier │ │ │ ├── README.md │ │ │ ├── python_paillier_bench.py │ │ │ └── requirements.txt │ ├── numpy │ │ ├── BUILD.bazel │ │ ├── decryptor.cc │ │ ├── decryptor.h │ │ ├── eigen_traits.h │ │ ├── encryptor.cc │ │ ├── encryptor.h │ │ ├── evaluator.cc │ │ ├── evaluator.h │ │ ├── matrix.cc │ │ ├── matrix.h │ │ ├── numpy.h │ │ ├── random.cc │ │ ├── random.h │ │ ├── random_test.cc │ │ ├── shape.h │ │ ├── test │ │ │ ├── BUILD.bazel │ │ │ ├── ic_test.cc │ │ │ ├── matmul_test.cc │ │ │ ├── numpy_test.cc │ │ │ └── test_tools.h │ │ ├── toolbox.cc │ │ └── toolbox.h │ └── phe │ │ ├── BUILD.bazel │ │ ├── base │ │ ├── BUILD.bazel │ │ ├── key_def.h │ │ ├── plaintext.cc │ │ ├── plaintext.h │ │ ├── plaintext_test.cc │ │ ├── predefined_functions.h │ │ ├── schema.cc │ │ ├── schema.h │ │ ├── schema_test.cc │ │ ├── serializable_types.cc │ │ ├── serializable_types.h │ │ └── variant_helper.h │ │ ├── decryptor.cc │ │ ├── decryptor.h │ │ ├── decryptor_test.cc │ │ ├── encoding │ │ ├── BUILD.bazel │ │ ├── batch_encoder.h │ │ ├── batch_encoder_test.cc │ │ ├── coding.cc │ │ ├── coding.h │ │ ├── encoding.h │ │ ├── plain_encoder.h │ │ └── plain_encoder_test.cc │ │ ├── encryptor.cc │ │ ├── encryptor.h │ │ ├── encryptor_test.cc │ │ ├── evaluator.cc │ │ ├── evaluator.h │ │ ├── evaluator_test.cc │ │ ├── phe.cc │ │ ├── phe.h │ │ └── phe_test │ │ ├── BUILD.bazel │ │ ├── batch_eval_test.cc │ │ └── ser_test.cc ├── pylib │ ├── BUILD.bazel │ ├── __init__.py │ ├── common │ │ ├── BUILD.bazel │ │ ├── py_utils.cc │ │ ├── py_utils.h │ │ └── traits.h │ ├── exported_symbols.lds │ ├── heu_modules.cc │ ├── numpy_binding │ │ ├── BUILD.bazel │ │ ├── bind_numpy.cc │ │ ├── bind_numpy.h │ │ ├── extension_functions.cc │ │ ├── extension_functions.h │ │ ├── infeed.h │ │ ├── outfeed.h │ │ ├── py_slicer.cc │ │ ├── py_slicer.h │ │ ├── slice_tool.cc │ │ └── slice_tool.h │ ├── numpy_test.py │ ├── phe_binding │ │ ├── BUILD.bazel │ │ ├── bind_phe.cc │ │ ├── bind_phe.h │ │ ├── py_batch_encoder.cc │ │ ├── py_batch_encoder.h │ │ ├── py_bigint_encoder.cc │ │ ├── py_bigint_encoder.h │ │ ├── py_encoders.h │ │ ├── py_float_encoder.cc │ │ ├── py_float_encoder.h │ │ ├── py_integer_encoder.cc │ │ └── py_integer_encoder.h │ ├── phe_test.py │ ├── version.py │ └── version_script.lds └── spi │ ├── BUILD.bazel │ ├── README.md │ ├── auto_test │ ├── BUILD.bazel │ ├── README.md │ ├── arithmetic_test.cc │ ├── ckks_test.cc │ ├── serialize_test.cc │ ├── tool.cc │ └── tool.h │ ├── he │ ├── BUILD.bazel │ ├── binary_evaluator.h │ ├── decryptor.h │ ├── encoder.h │ ├── encryptor.h │ ├── factory.cc │ ├── factory.h │ ├── gate_evaluator.h │ ├── he.h │ ├── he_configs.cc │ ├── he_configs.h │ ├── he_kit.h │ ├── item.cc │ ├── item.h │ ├── item_test.cc │ ├── item_tool.h │ ├── schema.cc │ ├── schema.h │ ├── sketches │ │ ├── README.md │ │ ├── common │ │ │ ├── BUILD.bazel │ │ │ ├── batch_encoder.h │ │ │ ├── encoder.h │ │ │ ├── he_kit.h │ │ │ ├── item_tool.h │ │ │ ├── keys.cc │ │ │ ├── keys.h │ │ │ ├── placeholder.h │ │ │ ├── plain_encoder.h │ │ │ └── pt_ct.h │ │ ├── scalar │ │ │ ├── BUILD.bazel │ │ │ ├── decryptor.h │ │ │ ├── encryptor.h │ │ │ ├── helpful_macros.h │ │ │ ├── item_tool.h │ │ │ ├── phe │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── encryptor.h │ │ │ │ ├── he_kit.h │ │ │ │ ├── scaled_batch_encoder.h │ │ │ │ ├── scaled_batch_encoder_test.cc │ │ │ │ ├── scaled_plain_encoder.h │ │ │ │ └── word_evaluator.h │ │ │ ├── test │ │ │ │ ├── BUILD.bazel │ │ │ │ ├── dummy_encoder.h │ │ │ │ ├── dummy_hekit.h │ │ │ │ ├── dummy_ops.h │ │ │ │ ├── scalar_call_test.cc │ │ │ │ ├── test_decryptor.cc │ │ │ │ ├── test_encoder.cc │ │ │ │ ├── test_encryptor.cc │ │ │ │ ├── test_hekit.cc │ │ │ │ └── vec_call_test.cc │ │ │ └── word_evaluator.h │ │ └── vector │ │ │ └── word_evaluator.h │ └── word_evaluator.h │ ├── poly │ ├── ntt_op.h │ ├── poly_def.h │ └── poly_op.h │ └── utils │ ├── BUILD.bazel │ ├── formater.h │ └── math_tool.h ├── pyproject.toml ├── requirements.txt ├── requirements_lock.txt ├── setup.py └── third_party ├── bazel_cpp ├── BUILD.bazel ├── cereal.BUILD ├── cgbn.BUILD ├── fmtlib.BUILD ├── ipcl.BUILD ├── ipp.BUILD ├── patches │ ├── cgbn.patch │ ├── ipcl.patch │ ├── ippcp.patch │ ├── seal-evaluator.patch │ └── seal.patch ├── repositories.bzl └── seal.BUILD └── bazel_rust ├── BUILD.bazel └── cargo ├── BUILD.bazel ├── crates.bzl ├── remote ├── BUILD.addr2line-0.17.0.bazel ├── BUILD.adler-1.0.2.bazel ├── BUILD.aes-soft-0.6.4.bazel ├── BUILD.atty-0.2.14.bazel ├── BUILD.autocfg-1.0.1.bazel ├── BUILD.backtrace-0.3.63.bazel ├── BUILD.bazel ├── BUILD.bincode-1.3.3.bazel ├── BUILD.bitflags-1.3.2.bazel ├── BUILD.bstr-0.2.17.bazel ├── BUILD.bumpalo-3.8.0.bazel ├── BUILD.cast-0.2.7.bazel ├── BUILD.cc-1.0.72.bazel ├── BUILD.cfg-if-1.0.0.bazel ├── BUILD.cipher-0.2.5.bazel ├── BUILD.clap-2.34.0.bazel ├── BUILD.clap-3.1.1.bazel ├── BUILD.codespan-reporting-0.11.1.bazel ├── BUILD.colored-2.0.0.bazel ├── BUILD.concrete-0.1.11.bazel ├── BUILD.concrete-boolean-0.1.0.bazel ├── BUILD.concrete-commons-0.1.1.bazel ├── BUILD.concrete-core-0.1.10.bazel ├── BUILD.concrete-csprng-0.1.7.bazel ├── BUILD.concrete-fftw-0.1.2.bazel ├── BUILD.concrete-fftw-sys-0.1.2.bazel ├── BUILD.concrete-npe-0.1.9.bazel ├── BUILD.criterion-0.3.5.bazel ├── BUILD.criterion-plot-0.4.4.bazel ├── BUILD.crossbeam-channel-0.5.1.bazel ├── BUILD.crossbeam-deque-0.8.1.bazel ├── BUILD.crossbeam-epoch-0.9.5.bazel ├── BUILD.crossbeam-utils-0.8.5.bazel ├── BUILD.csv-1.1.6.bazel ├── BUILD.csv-core-0.1.10.bazel ├── BUILD.cxx-1.0.65.bazel ├── BUILD.cxxbridge-cmd-1.0.65.bazel ├── BUILD.cxxbridge-flags-1.0.65.bazel ├── BUILD.cxxbridge-macro-1.0.65.bazel ├── BUILD.either-1.6.1.bazel ├── BUILD.fastrand-1.6.0.bazel ├── BUILD.fs_extra-1.2.0.bazel ├── BUILD.generic-array-0.14.4.bazel ├── BUILD.gimli-0.26.1.bazel ├── BUILD.half-1.8.2.bazel ├── BUILD.hashbrown-0.11.2.bazel ├── BUILD.hermit-abi-0.1.19.bazel ├── BUILD.indexmap-1.8.0.bazel ├── BUILD.instant-0.1.12.bazel ├── BUILD.itertools-0.10.3.bazel ├── BUILD.itertools-0.9.0.bazel ├── BUILD.itoa-0.4.8.bazel ├── BUILD.js-sys-0.3.55.bazel ├── BUILD.lazy_static-1.4.0.bazel ├── BUILD.libc-0.2.109.bazel ├── BUILD.link-cplusplus-1.0.6.bazel ├── BUILD.log-0.4.14.bazel ├── BUILD.memchr-2.4.1.bazel ├── BUILD.memoffset-0.6.5.bazel ├── BUILD.miniz_oxide-0.4.4.bazel ├── BUILD.num-complex-0.4.0.bazel ├── BUILD.num-traits-0.2.14.bazel ├── BUILD.num_cpus-1.13.0.bazel ├── BUILD.object-0.27.1.bazel ├── BUILD.oorandom-11.1.3.bazel ├── BUILD.opaque-debug-0.3.0.bazel ├── BUILD.os_str_bytes-6.0.0.bazel ├── BUILD.plotters-0.3.1.bazel ├── BUILD.plotters-backend-0.3.2.bazel ├── BUILD.plotters-svg-0.3.1.bazel ├── BUILD.proc-macro2-1.0.33.bazel ├── BUILD.quote-1.0.10.bazel ├── BUILD.rayon-1.5.1.bazel ├── BUILD.rayon-core-1.9.1.bazel ├── BUILD.redox_syscall-0.2.10.bazel ├── BUILD.regex-1.5.4.bazel ├── BUILD.regex-automata-0.1.10.bazel ├── BUILD.regex-syntax-0.6.25.bazel ├── BUILD.remove_dir_all-0.5.3.bazel ├── BUILD.rustc-demangle-0.1.21.bazel ├── BUILD.rustc_version-0.4.0.bazel ├── BUILD.ryu-1.0.6.bazel ├── BUILD.same-file-1.0.6.bazel ├── BUILD.scopeguard-1.1.0.bazel ├── BUILD.semver-1.0.4.bazel ├── BUILD.serde-1.0.130.bazel ├── BUILD.serde_cbor-0.11.2.bazel ├── BUILD.serde_derive-1.0.130.bazel ├── BUILD.serde_json-1.0.72.bazel ├── BUILD.simple_logger-2.1.0.bazel ├── BUILD.strsim-0.10.0.bazel ├── BUILD.syn-1.0.82.bazel ├── BUILD.tempfile-3.3.0.bazel ├── BUILD.termcolor-1.1.2.bazel ├── BUILD.textwrap-0.11.0.bazel ├── BUILD.textwrap-0.14.2.bazel ├── BUILD.time-0.3.5.bazel ├── BUILD.time-macros-0.2.3.bazel ├── BUILD.tinytemplate-1.2.1.bazel ├── BUILD.typenum-1.14.0.bazel ├── BUILD.unicode-width-0.1.9.bazel ├── BUILD.unicode-xid-0.2.2.bazel ├── BUILD.version_check-0.9.3.bazel ├── BUILD.walkdir-2.3.2.bazel ├── BUILD.wasm-bindgen-0.2.78.bazel ├── BUILD.wasm-bindgen-backend-0.2.78.bazel ├── BUILD.wasm-bindgen-macro-0.2.78.bazel ├── BUILD.wasm-bindgen-macro-support-0.2.78.bazel ├── BUILD.wasm-bindgen-shared-0.2.78.bazel ├── BUILD.web-sys-0.3.55.bazel ├── BUILD.winapi-0.3.9.bazel ├── BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel ├── BUILD.winapi-util-0.1.5.bazel └── BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel └── rust_cxx_bridge.bzl /.bazelignore: -------------------------------------------------------------------------------- 1 | 2 | # TODO(FIXME): add it back 3 | heu/experimental/tfhe/ -------------------------------------------------------------------------------- /.bazeliskrc: -------------------------------------------------------------------------------- 1 | USE_BAZEL_VERSION=7.5.0 -------------------------------------------------------------------------------- /.bcr/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/secretflow/heu", 3 | "maintainers": [], 4 | "repository": ["github:secretflow/heu"], 5 | "versions": [], 6 | "yanked_versions": {} 7 | } 8 | -------------------------------------------------------------------------------- /.bcr/presubmit.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | platform: 3 | - debian10 4 | - ubuntu2004 5 | - macos 6 | - macos_arm64 7 | - windows 8 | bazel: 9 | - 7.x 10 | tasks: 11 | verify_targets: 12 | name: Verify build targets 13 | platform: ${{ platform }} 14 | bazel: ${{ bazel }} 15 | build_targets: 16 | - "@heu//heu/..." 17 | -------------------------------------------------------------------------------- /.bcr/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "", 3 | "strip_prefix": "{REPO}-{VERSION}", 4 | "url": "https://github.com/{OWNER}/{REPO}/archive/refs/tags/{TAG}.tar.gz" 5 | } 6 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # Use the Google style in this project. 2 | BasedOnStyle: Google 3 | 4 | IncludeBlocks: Regroup 5 | IncludeCategories: 6 | - Regex: '^<.*\.h>' 7 | Priority: 1 8 | - Regex: '^<.*' 9 | Priority: 2 10 | - Regex: '.*\.pb\.h"$' 11 | Priority: 5 12 | - Regex: '^"heu.*' 13 | Priority: 4 14 | - Regex: '^".*' 15 | Priority: 3 16 | 17 | SeparateDefinitionBlocks: Always 18 | EmptyLineBeforeAccessModifier: LogicalBlock 19 | InsertNewlineAtEOF: true 20 | 21 | DerivePointerAlignment: false 22 | PointerAlignment: Right 23 | ReferenceAlignment: Pointer 24 | QualifierAlignment: Left 25 | -------------------------------------------------------------------------------- /.github/workflows/black.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | name: Python Linter 17 | on: 18 | push: 19 | branches: 20 | - main 21 | pull_request: 22 | branches: 23 | - main 24 | jobs: 25 | python-linter: 26 | uses: secretflow/.github/.github/workflows/python-linter.yml@main 27 | -------------------------------------------------------------------------------- /.github/workflows/buildifier.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | name: Bazel files linter 17 | on: 18 | push: 19 | branches: 20 | - main 21 | pull_request: 22 | branches: 23 | - main 24 | jobs: 25 | bazel-formatting-check: 26 | uses: secretflow/.github/.github/workflows/bazel-linter.yml@main 27 | -------------------------------------------------------------------------------- /.github/workflows/cla.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | name: CLA Assistant 17 | on: 18 | issue_comment: 19 | types: [created] 20 | pull_request_target: 21 | types: [opened, closed, synchronize] 22 | jobs: 23 | CLAssistant: 24 | uses: secretflow/.github/.github/workflows/cla.yml@main 25 | secrets: inherit 26 | -------------------------------------------------------------------------------- /.github/workflows/clang-format-linter.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | name: Run clang-format Linter 17 | on: 18 | push: 19 | branches: 20 | - main 21 | pull_request_target: 22 | branches: 23 | - main 24 | jobs: 25 | run-clang-format: 26 | uses: secretflow/.github/.github/workflows/clang-format.yml@main 27 | -------------------------------------------------------------------------------- /.github/workflows/license-check.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: License Check 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | permissions: 11 | contents: read 12 | jobs: 13 | license-checker: 14 | uses: secretflow/.github/.github/workflows/license-check.yml@main 15 | -------------------------------------------------------------------------------- /.github/workflows/oscp.yml: -------------------------------------------------------------------------------- 1 | name: Unassign Stale OSCP Issues 2 | 3 | on: 4 | schedule: 5 | - cron: "0 */6 * * *" # Every 6 hours 6 | 7 | jobs: 8 | unassign-stale-issues: 9 | uses: secretflow/.github/.github/workflows/oscp-unassign.yml@main 10 | -------------------------------------------------------------------------------- /.github/workflows/trigger-circleci.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: "Publish Python Package" 16 | on: 17 | release: 18 | types: [published] 19 | jobs: 20 | trigger-circleci: 21 | runs-on: ubuntu-latest 22 | steps: 23 | - name: secretflow-heu-deploy 24 | id: secretflow-heu-deploy 25 | uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.1.0 26 | env: 27 | CCI_TOKEN: ${{ secrets.CCI_TOKEN }} 28 | -------------------------------------------------------------------------------- /.github/workflows/yaml-linter.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | name: Yaml Lint 17 | on: 18 | push: 19 | branches: 20 | - main 21 | pull_request: 22 | branches: 23 | - main 24 | jobs: 25 | yaml-linter: 26 | uses: secretflow/.github/.github/workflows/yaml-linter.yml@main 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | debug/ 4 | target/ 5 | 6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 8 | Cargo.lock 9 | 10 | # These are backup files generated by rustfmt 11 | **/*.rs.bk 12 | 13 | # Bazel files 14 | bazel-* 15 | MODULE.bazel.lock 16 | 17 | # Temp IDE files 18 | *.pdb 19 | /.idea 20 | /.vscode 21 | 22 | # sphinx files 23 | /docs/*.mo 24 | /docs/_build 25 | 26 | # custom ignored files 27 | __pycache__ 28 | cache/ 29 | unpack 30 | build/ 31 | dist/ 32 | 33 | pylib.name 34 | *.whl 35 | *.egg-info/ 36 | 37 | # MacOS files 38 | .DS_Store 39 | -------------------------------------------------------------------------------- /BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_python//python:pip.bzl", "compile_pip_requirements") 16 | 17 | compile_pip_requirements( 18 | name = "requirements", 19 | src = "requirements.txt", 20 | requirements_txt = "requirements_lock.txt", 21 | ) 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution guidelines 2 | 3 | ## Contributor License Agreement 4 | 5 | Contributions to this project must be accompanied by a Contributor License 6 | Agreement. You (or your employer) retain the copyright to your contribution; 7 | this simply gives us permission to use and redistribute your contributions as 8 | part of the project. 9 | 10 | ## Style 11 | 12 | ### C++ coding style 13 | 14 | In general, please use clang-format to format code, and follow clang-tidy tips. 15 | 16 | Most of the code style is derived from 17 | the [Google C++ style guidelines](https://google.github.io/styleguide/cppguide.html) 18 | , except: 19 | 20 | * Exceptions are allowed and encouraged where appropriate. 21 | * Header guards should use `#pragma once`. 22 | 23 | ### Other tips 24 | 25 | * Git commit message should be meaningful, we suggest 26 | imperative [keywords](https://github.com/joelparkerhenderson/git_commit_message#summary-keywords) 27 | * Developer must write unit-test (line coverage must be greater than 80%), tests 28 | should be deterministic 29 | * Read awesome [Abseil Tips](https://abseil.io/tips/) 30 | 31 | ## Change log 32 | 33 | Please keep updating changes to the staging area of [change log](CHANGELOGS.md) 34 | 35 | Changelog should contain: 36 | 37 | - all public API changes, including new features, breaking changes and 38 | deprecations. 39 | - notable internal changes, like performance improvement. 40 | -------------------------------------------------------------------------------- /LEGAL.md: -------------------------------------------------------------------------------- 1 | Legal Disclaimer 2 | 3 | Within this source code, the comments in Chinese shall be the original, governing version. Any comment in other languages are for reference only. In the event of any conflict between the Chinese language version comments and other language version comments, the Chinese language version shall prevail. 4 | 5 | 法律免责声明 6 | 7 | 关于代码注释部分,中文注释为官方版本,其它语言注释仅做参考。中文注释可能与其它语言注释存在不一致,当中文注释与其它语言注释存在不一致时,请以中文注释为准。 -------------------------------------------------------------------------------- /bazel/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /bazel/defs.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("//third_party/bazel_cpp:repositories.bzl", "heu_cpp_deps") 16 | 17 | def _non_module_dependencies_impl(_ctx): 18 | heu_cpp_deps() 19 | 20 | non_module_dependencies = module_extension( 21 | implementation = _non_module_dependencies_impl, 22 | ) 23 | -------------------------------------------------------------------------------- /build_wheel_entrypoint.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # Copyright 2022 Ant Group Co., Ltd. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | set -e 17 | 18 | 19 | rm -rf dist 20 | 21 | python setup.py bdist_wheel 22 | python3 -m pip install dist/*.whl --force-reinstall 23 | 24 | # check import ok 25 | python -c "import heu" 26 | python -c "from heu import numpy" 27 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Minimal makefile for Sphinx documentation 16 | # 17 | 18 | # You can set these variables from the command line, and also 19 | # from the environment for the first two. 20 | SPHINXOPTS ?= 21 | SPHINXBUILD ?= sphinx-build 22 | SOURCEDIR = . 23 | BUILDDIR = _build 24 | 25 | # Put it first so that "make" without argument is like "make help". 26 | help: 27 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 28 | 29 | .PHONY: help Makefile 30 | 31 | # Catch-all target: route all unknown targets to Sphinx using the new 32 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 33 | %: Makefile 34 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 35 | -------------------------------------------------------------------------------- /docs/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Ant Group Co., Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | html[data-theme="light"] { 18 | --pst-color-primary: rgb(22 119 255); 19 | --pst-color-secondary: rgb(22 255 201); 20 | } 21 | 22 | html[data-theme="dark"] { 23 | --pst-color-primary: rgb(22 119 255); 24 | --pst-color-secondary: rgb(22 255 201); 25 | --pst-color-background: rgb(56, 56, 56); 26 | } 27 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/_static/logo-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/_static/logo-dark.png -------------------------------------------------------------------------------- /docs/_static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/_static/logo.png -------------------------------------------------------------------------------- /docs/development/_img/matrix_matmul.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/development/_img/matrix_matmul.png -------------------------------------------------------------------------------- /docs/development/_img/matrix_op.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/development/_img/matrix_op.png -------------------------------------------------------------------------------- /docs/development/_img/phe_spi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/development/_img/phe_spi.png -------------------------------------------------------------------------------- /docs/development/arch.rst: -------------------------------------------------------------------------------- 1 | HEU 架构 2 | ================== 3 | 4 | 请查阅 `隐语开发者文档 `_ 5 | 6 | -------------------------------------------------------------------------------- /docs/development/index.rst: -------------------------------------------------------------------------------- 1 | 开发 2 | ============== 3 | 4 | 下列文档有助于您了解 HEU 的设计思想和原则。 5 | 6 | .. toctree:: 7 | :maxdepth: 1 8 | 9 | arch 10 | phe_dev 11 | -------------------------------------------------------------------------------- /docs/getting_started/_img/batch_encoding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/getting_started/_img/batch_encoding.png -------------------------------------------------------------------------------- /docs/getting_started/_img/heu_client_server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/getting_started/_img/heu_client_server.png -------------------------------------------------------------------------------- /docs/getting_started/_img/obj_type.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/getting_started/_img/obj_type.png -------------------------------------------------------------------------------- /docs/getting_started/index.rst: -------------------------------------------------------------------------------- 1 | 准备开始 2 | ============ 3 | 4 | 您可以按照下面步骤来快速上手 HEU 5 | 6 | 7 | .. toctree:: 8 | :maxdepth: 2 9 | 10 | installation 11 | quick_start 12 | numpy 13 | algo_choice 14 | faq 15 | -------------------------------------------------------------------------------- /docs/getting_started/installation.rst: -------------------------------------------------------------------------------- 1 | 安装 2 | ==== 3 | 4 | 环境准备 5 | -------------- 6 | 7 | Python 3.9 - 3.11 8 | 9 | OS: 10 | - Centos 7 11 | - Ubuntu 18.04+ 12 | - macOS 12.0+ (macOS Monterey+) 13 | 14 | 15 | 安装 16 | ---- 17 | 18 | 19 | 20 | 通过 Pip 安装 21 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22 | 23 | HEU 安装包已经发布到了 PyPi,您可以通过 pip 工具安装 HEU 24 | 25 | .. code-block:: bash 26 | 27 | pip install sf-heu 28 | 29 | 30 | 从源码安装 31 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 32 | 33 | 34 | 如果您需要使用最新测试版本,可以从 `源码 `_ 编译安装。 35 | 36 | 依赖工具: 37 | - `Bazelisk `_ 38 | - nasm(x86 架构) 39 | - GCC >= 11 40 | 41 | 编译和安装: 42 | 43 | .. code-block:: bash 44 | 45 | git clone --recursive https://github.com/secretflow/heu.git 46 | cd heu 47 | sh build_wheel_entrypoint.sh 48 | 49 | 50 | 测试运行 51 | --------------------------- 52 | 53 | 安装完成后,建议执行以下命令检查 HEU 是否工作正常 54 | 55 | .. code-block:: bash 56 | 57 | python -c "from heu import phe" 58 | 59 | 上述命令,如果没有任何输出,则说明安装成功;反之如果报错,则说明安装未成功,请参考 :doc:`FAQ ` 60 | -------------------------------------------------------------------------------- /docs/images/heu_arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/images/heu_arch.png -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. HEU documentation master file, created by 2 | sphinx-quickstart on Mon Jun 27 17:06:46 2022. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | HEU 文档 7 | =============================== 8 | 9 | 同态加密计算引擎(homomorphic encryption processing unit, HEU) 是隐语的一个子项目,实现了高性能的同态加密算法。 10 | 11 | HEU 的目的是降低同态加密的使用门槛,使得用户无需专业知识就能利用同态加密算法构建任意程序。 12 | 13 | .. image:: ./images/heu_arch.png 14 | 15 | 由于 HEU 还处在起步阶段,当前 HEU 仅仅是一个加法同态加密的 library,还不具备像 SPU 一样执行任意程序的能力。 16 | 17 | 18 | .. toctree:: 19 | :maxdepth: 2 20 | :caption: Contents 21 | 22 | getting_started/index 23 | development/index 24 | references/index 25 | 26 | -------------------------------------------------------------------------------- /docs/locale/en/LC_MESSAGES/development/arch.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) 2022 Ant Group Co., Ltd 3 | # This file is distributed under the same license as the HEU package. 4 | # FIRST AUTHOR , 2022. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: HEU \n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2022-11-09 15:31+0800\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=utf-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Generated-By: Babel 2.10.3\n" 19 | 20 | #: ../../development/arch.rst:2 21 | msgid "HEU 架构" 22 | msgstr "HEU Architecture" 23 | 24 | #: ../../development/arch.rst:4 25 | msgid "" 26 | "请查阅 `隐语开发者文档 " 27 | "`_" 28 | msgstr "Please refer to `Secretflow Developer Documentation `_" 29 | 30 | -------------------------------------------------------------------------------- /docs/locale/en/LC_MESSAGES/development/index.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) 2022 Ant Group Co., Ltd 3 | # This file is distributed under the same license as the HEU package. 4 | # FIRST AUTHOR , 2022. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: HEU \n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2022-11-07 18:53+0800\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=utf-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Generated-By: Babel 2.10.3\n" 19 | 20 | #: ../../development/index.rst:2 21 | msgid "开发" 22 | msgstr "Development" 23 | 24 | #: ../../development/index.rst:4 25 | msgid "下列文档有助于您了解 HEU 的设计思想和原则。" 26 | msgstr "The following documents will help you understand the design philosophy and principles of HEU." 27 | 28 | -------------------------------------------------------------------------------- /docs/locale/en/LC_MESSAGES/getting_started/index.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) Copyright 2022 Ant Group Co., Ltd. 3 | # This file is distributed under the same license as the HEU package. 4 | # FIRST AUTHOR , 2022. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: HEU \n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2022-06-28 20:23+0800\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=utf-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Generated-By: Babel 2.10.3\n" 19 | 20 | #: ../../getting_started/index.rst:3 383117a4c6cf4b42a5fba851ebfd2f6a 21 | msgid "准备开始" 22 | msgstr "Getting started" 23 | 24 | #: ../../getting_started/index.rst:5 52b15dc929004fab8170256247b725c6 25 | msgid "您可以按照下面步骤来快速上手 HEU" 26 | msgstr "The following tutorials will help you get started quickly with HEU." 27 | 28 | -------------------------------------------------------------------------------- /docs/locale/en/LC_MESSAGES/references/index.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) 2022 Ant Group Co., Ltd 3 | # This file is distributed under the same license as the HEU package. 4 | # FIRST AUTHOR , 2022. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: HEU \n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2022-08-23 10:58+0800\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=utf-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Generated-By: Babel 2.10.3\n" 19 | 20 | #: ../../references/index.rst:2 21 | msgid "API 手册" 22 | msgstr "API Reference" 23 | 24 | #: ../../references/index.rst:4 25 | msgid "当前 HEU 提供了两大模块:" 26 | msgstr "HEU consists of two modules:" 27 | 28 | #: ../../references/index.rst:6 29 | msgid "``heu.phe``: 实现了多种 PHE 算法" 30 | msgstr "``heu.phe``: implements various PHE algorithms" 31 | 32 | #: ../../references/index.rst:7 33 | msgid "``heu.numpy``: phe 模块的装饰器,提供了 PHE 矩阵运算接口,支持并行计算" 34 | msgstr "" 35 | "``heu.numpy``: a decorator for phe module, which provides a matrix " 36 | "operation interface and supports parallel computing" 37 | 38 | #: ../../references/index.rst:10 39 | msgid "模块列表" 40 | msgstr "Module list" 41 | 42 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/readme.md: -------------------------------------------------------------------------------- 1 | # Basis 基本操作 2 | 3 | ## Install dependencies 安装依赖 4 | 5 | ```shell 6 | pip install -r requirements.txt 7 | ``` 8 | 9 | ## Generate html 生成 html 文档 10 | 11 | ```shell 12 | make html 13 | ``` 14 | 15 | Now you can open the _build/html/index.html file in your browser to read the HEU 16 | documentation. 17 | 现在您可以通过浏览器打开 _build/html/index.html 文件阅读 HEU 文档。 18 | 19 | 20 | # Internationalization 国际化(可选) 21 | 22 | This section describes how to translate documentation into other languages 23 | 本节介绍如何将文档翻译为另一种语言 24 | 25 | sphinx detail doc: 26 | https://www.sphinx-doc.org/en/master/usage/advanced/intl.html 27 | 28 | ```shell 29 | # generate/update pot files 30 | make gettext 31 | 32 | # generate/update po files 33 | # (merge pot to exist po files or create new po files if not exist) 34 | sphinx-intl update -p _build/gettext 35 | 36 | # <--- Long term work: Add translated text in po file ---> 37 | 38 | # generate html (en) 39 | sphinx-build -D language='en' . _build/html/en/ 40 | ``` 41 | -------------------------------------------------------------------------------- /docs/references/_img/0_2_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/references/_img/0_2_flow.png -------------------------------------------------------------------------------- /docs/references/_img/0_3_encoder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/references/_img/0_3_encoder.png -------------------------------------------------------------------------------- /docs/references/_img/0_3_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/docs/references/_img/0_3_flow.png -------------------------------------------------------------------------------- /docs/references/index.rst: -------------------------------------------------------------------------------- 1 | API 手册 2 | ============= 3 | 4 | 当前 HEU 提供了两大模块: 5 | 6 | - ``heu.phe``: 实现了多种 PHE 算法 7 | - ``heu.numpy``: phe 模块的装饰器,提供了 PHE 矩阵运算接口,支持并行计算 8 | 9 | 10 | 模块列表 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | 15 | phe_api 16 | numpy_api 17 | upgrade_guide 18 | -------------------------------------------------------------------------------- /docs/references/numpy_api.rst: -------------------------------------------------------------------------------- 1 | Numpy 模块 2 | ================ 3 | 4 | .. tip:: 请使用 ``from heu import numpy as hnp`` 引入 phe 模块 5 | 6 | .. automodule:: heu.numpy 7 | :members: 8 | :undoc-members: 9 | -------------------------------------------------------------------------------- /docs/references/phe_api.rst: -------------------------------------------------------------------------------- 1 | PHE 模块 2 | ================ 3 | 4 | .. tip:: 请使用 ``from heu import phe`` 引入 phe 模块 5 | 6 | .. automodule:: heu.phe 7 | :members: 8 | :undoc-members: 9 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx 2 | sphinx-intl 3 | sphinx-copybutton 4 | sphinx-togglebutton 5 | sphinx-inline-tabs 6 | sphinxcontrib-htmlhelp 7 | sphinxcontrib-applehelp 8 | # matplotlib 9 | # myst-parser 10 | sf-heu 11 | 12 | # theme 13 | pydata-sphinx-theme 14 | -------------------------------------------------------------------------------- /heu/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | package(default_visibility = ["//visibility:public"]) 16 | 17 | ### global configs ### 18 | config_setting( 19 | name = "enable_clustar_fpga", 20 | define_values = { 21 | "enable_clustar_fpga": "true", 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /heu/algorithms/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@bazel_skylib//lib:subpackages.bzl", "subpackages") 16 | load("@yacl//bazel:yacl.bzl", "yacl_cc_library") 17 | 18 | package(default_visibility = ["//visibility:public"]) 19 | 20 | # A collection of all implementation libraries. 21 | # doc of @bazel_skylib//lib:subpackages.bzl: 22 | # https://github.com/bazelbuild/bazel-skylib/blob/main/docs/subpackages_doc.md 23 | yacl_cc_library( 24 | name = "algorithms", 25 | deps = subpackages.all(exclude = ["common"]), 26 | ) 27 | -------------------------------------------------------------------------------- /heu/algorithms/README.md: -------------------------------------------------------------------------------- 1 | 该目录存放所有 HEU 支持的算法,包括 PHE、FHE。 2 | 3 | 新贡献的算法请放到 incubator/ 目录下 4 | 5 | 算法由 SPI 调用,关于 SPI 的介绍,请参考 [/heu/spi](/heu/spi) 目录 6 | 7 | ``` 8 | ┌─────────────────────────────────┐ 9 | │ HE Based APPs │ 10 | The /heu/spi ├─────────────────────────────────┤ 11 | folder ---> │ SPI │ 12 | └─────────────────────────────────┘ 13 | ┌───────────┐ ┌───────────┐ 14 | │ │ │ │ 15 | This folder --> │ LIB 1 │ │ LIB 2 │ ...... 16 | │ │ │ │ 17 | └───────────┘ └───────────┘ 18 | ``` 19 | 20 | `algorithm` 或者 `algorithms/incubator` 路径下每个文件夹即为一个 Lib,每个 Lib 实现了一个或多个 HE 算法,算法可以由软件实现,也可以基于硬件加速器实现。 21 | 22 | 例如: 23 | - `paillier_zahlen` Lib 名称为 paillier_zahlen,实现了 Paillier 算法 24 | - `ou` Lib 名称为 ou,实现了同名的 OU 算法 25 | 26 | 如果同一个算法被多个 Lib 实现,用户可以强制指定使用某个 Lib 中的某个算法,也可以让 SPI 自动选择 Lib,SPI 将根据运行时软硬件配置和 Lib 性能估算自动选择最合适的 Lib 27 | -------------------------------------------------------------------------------- /heu/algorithms/common/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@yacl//bazel:yacl.bzl", "yacl_cc_library") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | yacl_cc_library( 20 | name = "common", 21 | deps = [ 22 | ":he_assert", 23 | ":type_alias", 24 | ], 25 | ) 26 | 27 | yacl_cc_library( 28 | name = "type_alias", 29 | hdrs = ["type_alias.h"], 30 | deps = [ 31 | "@yacl//yacl/math/bigint", 32 | ], 33 | ) 34 | 35 | yacl_cc_library( 36 | name = "he_assert", 37 | hdrs = ["he_assert.h"], 38 | deps = ["@yacl//yacl/base:exception"], 39 | ) 40 | -------------------------------------------------------------------------------- /heu/algorithms/common/he_assert.h: -------------------------------------------------------------------------------- 1 | // Copyright 20244 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "yacl/base/exception.h" 18 | 19 | #ifdef NDEBUG 20 | #define HE_ASSERT(condition, ...) ((void)0) 21 | #else 22 | #define HE_ASSERT(condition, ...) YACL_ENFORCE(condition, __VA_ARGS__) 23 | #endif 24 | -------------------------------------------------------------------------------- /heu/algorithms/common/type_alias.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "yacl/math/bigint/bigint.h" 18 | 19 | namespace heu::algos { 20 | 21 | using yacl::math::BigInt; 22 | using yacl::math::PrimeType; 23 | 24 | using yacl::math::BaseTable; 25 | using yacl::math::MontgomerySpace; 26 | 27 | } // namespace heu::algos 28 | -------------------------------------------------------------------------------- /heu/algorithms/incubator/README.md: -------------------------------------------------------------------------------- 1 | 该目录存放孵化中的算法。 2 | 3 | 出于严谨性考虑,新算法请放到该目录,未来经由多轮专家审核和测试环境验证无误后方可移到上级目录。 -------------------------------------------------------------------------------- /heu/algorithms/incubator/ishe/README.md: -------------------------------------------------------------------------------- 1 | # iSHE 2 | 3 | ## 简介 4 | 5 | iSHE(improved SHE),是一种对主流的对称同态加密技术的改进的对称同态加密技术(Symmetric Homomorphic Encryption,SHE)而提出的新的同态加密技术,它可以在不损害安全性的情况下提高原始SHE的性能,并在一些解决方案中作为加密原语。SHE被证明是CPA安全的,被广泛应用于可搜索的加密方案中,而iSHE是原始SHE在抵抗AGCD(Approximate Greatest Common Divisor)攻击的同时提高性能的一个新版本。 6 | 7 | 8 | ## 同态性质 9 | 10 | ### Mul-1 11 | 12 | Ciphertext mul ciphertext: 13 | 14 | iSHE.Dec(sk,(⟦m1⟧·⟦m_2⟧) mod N, d) = m1· m2 15 | 16 | ### Mul-2 17 | 18 | Ciphertext mul plaintext: 19 | 20 | iSHE.Dec(sk,(⟦m1⟧·m2) mod N, d) = m1·m2 21 | 22 | ### Add-1 23 | 24 | Ciphertext add ciphertext: 25 | 26 | iSHE.Dec(sk,(⟦m1⟧+ ⟦m2⟧) mod N, d) = m1+m2 27 | 28 | ### Add-2 29 | 30 | Ciphertext add plaintext: 31 | 32 | iSHE.Dec(sk,(⟦m1⟧+ m2) mod N, d) = m1+m2 33 | 34 | ## 相关文献 35 | 36 | ### 安全性和详细证明请参考文献: 37 | 38 | https://ieeexplore.ieee.org/document/10517763 39 | 40 | Performance Enhanced Secure Spatial Keyword Similarity Query With Arbitrary Spatial Ranges (TIFS’24) 41 | 42 | section Ⅴ.A on page 5280 43 | 44 | ### AGCD攻击相关定义和理论: 45 | 46 | https://eprint.iacr.org/2009/616.pdf 47 | 48 | Fully Homomorphic Encryption over the Integers 49 | 50 | https://eprint.iacr.org/2016/215.pdf 51 | 52 | Algorithms for the Approximate Common Divisor Problem 53 | -------------------------------------------------------------------------------- /heu/algorithms/incubator/ishe/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 CyberChangAn Group, Xidian University. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | #include "heu/algorithms/incubator/ishe/base.h" 20 | #include "heu/spi/he/sketches/scalar/decryptor.h" 21 | 22 | namespace heu::algos::ishe { 23 | 24 | class Decryptor : public spi::DecryptorScalarSketch { 25 | public: 26 | void Decrypt(const Ciphertext &ct, Plaintext *out) const override; 27 | [[nodiscard]] Plaintext Decrypt(const Ciphertext &ct) const override; 28 | 29 | Decryptor(std::shared_ptr sk, std::shared_ptr pk) 30 | : sk_(std::move(sk)), pk_(std::move(pk)) {} 31 | 32 | private: 33 | std::shared_ptr sk_; 34 | std::shared_ptr pk_; 35 | }; 36 | 37 | } // namespace heu::algos::ishe 38 | -------------------------------------------------------------------------------- /heu/algorithms/incubator/mock_fhe/base.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/algorithms/incubator/mock_fhe/base.h" 16 | 17 | #include 18 | 19 | #include "yacl/utils/serializer.h" 20 | 21 | #include "heu/spi/utils/formater.h" 22 | 23 | namespace heu::algos::mock_fhe { 24 | 25 | std::string Plaintext::ToString() const { 26 | return fmt::format("PT({}, scale={})", 27 | spi::utils::ArrayToStringCompact(array_), scale_); 28 | } 29 | 30 | std::string Ciphertext::ToString() const { 31 | return fmt::format("CT({}, scale={})", 32 | spi::utils::ArrayToStringCompact(array_), scale_); 33 | } 34 | 35 | Plaintext ItemTool::Clone(const Plaintext &pt) const { return pt; } 36 | 37 | Ciphertext ItemTool::Clone(const Ciphertext &ct) const { return ct; } 38 | 39 | } // namespace heu::algos::mock_fhe 40 | -------------------------------------------------------------------------------- /heu/algorithms/incubator/mock_fhe/decryptor.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/algorithms/incubator/mock_fhe/decryptor.h" 16 | 17 | namespace heu::algos::mock_fhe { 18 | 19 | Decryptor::Decryptor(const std::shared_ptr &pk, 20 | const std::shared_ptr &sk) 21 | : pk_(pk), sk_(sk) {} 22 | 23 | void Decryptor::Decrypt(const Ciphertext &ct, Plaintext *out) const { 24 | out->array_ = ct.array_; 25 | out->scale_ = ct.scale_; 26 | } 27 | 28 | Plaintext Decryptor::Decrypt(const Ciphertext &ct) const { 29 | return Plaintext(ct.array_, ct.scale_); 30 | } 31 | 32 | } // namespace heu::algos::mock_fhe 33 | -------------------------------------------------------------------------------- /heu/algorithms/incubator/mock_fhe/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | #include "heu/algorithms/incubator/mock_fhe/base.h" 20 | #include "heu/spi/he/sketches/scalar/decryptor.h" 21 | 22 | namespace heu::algos::mock_fhe { 23 | 24 | class Decryptor : public spi::DecryptorScalarSketch { 25 | public: 26 | Decryptor(const std::shared_ptr &pk, 27 | const std::shared_ptr &sk); 28 | 29 | void Decrypt(const Ciphertext &ct, Plaintext *out) const override; 30 | Plaintext Decrypt(const Ciphertext &ct) const override; 31 | 32 | private: 33 | std::shared_ptr pk_; 34 | std::shared_ptr sk_; 35 | }; 36 | 37 | } // namespace heu::algos::mock_fhe 38 | -------------------------------------------------------------------------------- /heu/algorithms/incubator/mock_phe/base.cc: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2024 Ant Group Co., Ltd. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #include "heu/algorithms/incubator/mock_phe/base.h" 17 | 18 | namespace heu::algos::mock_phe { 19 | 20 | Plaintext ItemTool::Clone(const Plaintext &pt) const { return pt; } 21 | 22 | Ciphertext ItemTool::Clone(const Ciphertext &ct) const { 23 | return Ciphertext(ct.bn_); 24 | } 25 | 26 | } // namespace heu::algos::mock_phe 27 | -------------------------------------------------------------------------------- /heu/algorithms/incubator/mock_phe/decryptor.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/algorithms/incubator/mock_phe/decryptor.h" 16 | 17 | namespace heu::algos::mock_phe { 18 | 19 | void Decryptor::Decrypt(const Ciphertext &ct, Plaintext *out) const { 20 | *out = ct.bn_; 21 | } 22 | 23 | Plaintext Decryptor::Decrypt(const Ciphertext &ct) const { return ct.bn_; } 24 | 25 | } // namespace heu::algos::mock_phe 26 | -------------------------------------------------------------------------------- /heu/algorithms/incubator/mock_phe/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | #include "heu/algorithms/incubator/mock_phe/base.h" 20 | #include "heu/spi/he/sketches/scalar/decryptor.h" 21 | 22 | namespace heu::algos::mock_phe { 23 | 24 | class Decryptor : public spi::DecryptorScalarSketch { 25 | public: 26 | void Decrypt(const Ciphertext &ct, Plaintext *out) const override; 27 | Plaintext Decrypt(const Ciphertext &ct) const override; 28 | }; 29 | 30 | } // namespace heu::algos::mock_phe 31 | -------------------------------------------------------------------------------- /heu/algorithms/ou/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/algorithms/ou/base.h" 18 | #include "heu/spi/he/sketches/scalar/decryptor.h" 19 | 20 | namespace heu::algos::ou { 21 | 22 | class Decryptor : public spi::DecryptorScalarSketch { 23 | public: 24 | explicit Decryptor(const std::shared_ptr &pk, 25 | const std::shared_ptr &sk); 26 | 27 | void Decrypt(const Ciphertext &ct, Plaintext *out) const override; 28 | Plaintext Decrypt(const Ciphertext &ct) const override; 29 | 30 | private: 31 | std::shared_ptr pk_; 32 | std::shared_ptr sk_; 33 | }; 34 | 35 | } // namespace heu::algos::ou 36 | -------------------------------------------------------------------------------- /heu/algorithms/paillier_zahlen/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/algorithms/paillier_zahlen/base.h" 18 | #include "heu/spi/he/sketches/scalar/decryptor.h" 19 | 20 | namespace heu::algos::paillier_z { 21 | 22 | class Decryptor : public spi::DecryptorScalarSketch { 23 | public: 24 | explicit Decryptor(const std::shared_ptr &pk, 25 | const std::shared_ptr &sk); 26 | 27 | void Decrypt(const Ciphertext &ct, Plaintext *out) const override; 28 | Plaintext Decrypt(const Ciphertext &ct) const override; 29 | 30 | private: 31 | std::shared_ptr pk_; 32 | std::shared_ptr sk_; 33 | }; 34 | 35 | } // namespace heu::algos::paillier_z 36 | -------------------------------------------------------------------------------- /heu/experimental/tfhe/.rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | use_small_heuristics = "Max" -------------------------------------------------------------------------------- /heu/experimental/tfhe/README.md: -------------------------------------------------------------------------------- 1 | ## update rust 2 | 3 | ```shell 4 | rustup update stable 5 | ``` 6 | 7 | ## update deps in cargo.toml 8 | 9 | ```shell 10 | cargo upgrade 11 | ``` 12 | 13 | ## generate bazel build file from cargo.toml 14 | 15 | ```shell 16 | # Install cargo-raze. (optional) 17 | cargo install cargo-raze 18 | 19 | cargo raze 20 | ``` 21 | 22 | detail doc: https://github.com/google/cargo-raze 23 | -------------------------------------------------------------------------------- /heu/experimental/tfhe/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | extern crate concrete; 16 | extern crate concrete_boolean; 17 | extern crate cxx; 18 | 19 | pub mod tools; 20 | pub mod zq; 21 | -------------------------------------------------------------------------------- /heu/experimental/tfhe/src/tools/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This macro allows to compute the duration of the execution of the expressions enclosed. Note that 16 | // the variables are not captured. 17 | #[macro_export] 18 | macro_rules! measure_duration { 19 | ($title: tt, {$($block:tt)+}) => { 20 | println!("{} ... ", $title); 21 | let __now = std::time::SystemTime::now(); 22 | $( 23 | $block 24 | )+ 25 | let __time = __now.elapsed().unwrap().as_millis() as f64 / 1000.; 26 | let __s_time = format!("{} s", __time); 27 | println!("{} ... Duration: {}", $title, __s_time.green().bold()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /heu/experimental/tfhe/src/zq/decryptor.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use concrete::CryptoAPIError; 16 | 17 | use super::key_generator::SecretKey; 18 | use super::Ciphertext; 19 | 20 | pub struct Decryptor<'a> { 21 | sk: &'a SecretKey, 22 | } 23 | 24 | impl<'a> Decryptor<'a> { 25 | pub fn new(sk: &'a SecretKey) -> Decryptor<'a> { 26 | Decryptor { sk } 27 | } 28 | 29 | pub fn decrypt(&self, a: &Ciphertext) -> Result { 30 | let p = a.lwe.decrypt_decode_round(&self.sk.lwe_key)?; 31 | Ok(p as u32) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /heu/experimental/tfhe/src/zq/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // pub use concrete::LWE as Ciphertext; 16 | pub struct Ciphertext { 17 | lwe: concrete::LWE, 18 | } 19 | 20 | pub type CleartextType = u32; 21 | 22 | const ENCODING_PADDING: usize = 5; 23 | const MAX_CLEARTEXT_BITS: usize = std::mem::size_of::() * 8; 24 | 25 | pub mod decryptor; 26 | pub mod encryptor; 27 | pub mod evaluator; 28 | mod ffi; 29 | pub mod key_generator; 30 | -------------------------------------------------------------------------------- /heu/experimental/tfhe/tests/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_rust//rust:defs.bzl", "rust_test", "rust_test_suite") 16 | load("//third_party/bazel_rust/cargo:crates.bzl", "all_crate_deps") 17 | 18 | package(default_visibility = ["//visibility:public"]) 19 | 20 | rust_test_suite( 21 | name = "torus_tests", 22 | srcs = glob(["*.rs"]), 23 | deps = all_crate_deps(package_name = "heu/experimental/tfhe") + ["//heu/experimental/tfhe/src:torus"], 24 | ) 25 | -------------------------------------------------------------------------------- /heu/experimental/tfhe/tests/cxxbind/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | test_suite( 16 | name = "tfhe_cxxbind_tests", 17 | ) 18 | 19 | cc_test( 20 | name = "basic", 21 | size = "large", 22 | srcs = ["basic.cc"], 23 | deps = [ 24 | "//heu/experimental/tfhe/src:cxx_torus", 25 | "@googletest//:gtest_main", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /heu/library/algorithms/clean_template/ciphertext.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | 20 | #include "yacl/base/byte_container_view.h" 21 | 22 | namespace heu::lib::algorithms::your_algo { 23 | 24 | // SPI: Do not change class name. 25 | class Ciphertext { 26 | public: 27 | Ciphertext() = default; 28 | 29 | std::string ToString() const; 30 | friend std::ostream &operator<<(std::ostream &os, const Ciphertext &c); 31 | 32 | bool operator==(const Ciphertext &other) const; 33 | bool operator!=(const Ciphertext &other) const; 34 | 35 | yacl::Buffer Serialize() const; 36 | void Deserialize(yacl::ByteContainerView in); 37 | }; 38 | 39 | } // namespace heu::lib::algorithms::your_algo 40 | -------------------------------------------------------------------------------- /heu/library/algorithms/clean_template/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/clean_template/public_key.h" 18 | #include "heu/library/algorithms/clean_template/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::your_algo { 21 | 22 | class KeyGenerator { 23 | public: 24 | // Generate PHE key pair 25 | static void Generate(int key_size, SecretKey *sk, PublicKey *pk); 26 | // Generate PHE key pair by default configs 27 | static void Generate(SecretKey *sk, PublicKey *pk); 28 | }; 29 | 30 | } // namespace heu::lib::algorithms::your_algo 31 | -------------------------------------------------------------------------------- /heu/library/algorithms/clean_template/public_key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/clean_template/plaintext.h" 18 | 19 | namespace heu::lib::algorithms::your_algo { 20 | 21 | class PublicKey { 22 | public: 23 | bool operator==(const PublicKey &other) const; 24 | bool operator!=(const PublicKey &other) const; 25 | 26 | std::string ToString() const; 27 | 28 | // Valid plaintext range: [max_int_, -max_int_] 29 | const Plaintext &PlaintextBound() const &; 30 | 31 | yacl::Buffer Serialize() const; 32 | void Deserialize(yacl::ByteContainerView in); 33 | }; 34 | 35 | } // namespace heu::lib::algorithms::your_algo 36 | -------------------------------------------------------------------------------- /heu/library/algorithms/clean_template/scalar_decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | #include "heu/library/algorithms/clean_template/ciphertext.h" 20 | #include "heu/library/algorithms/clean_template/plaintext.h" 21 | #include "heu/library/algorithms/clean_template/public_key.h" 22 | #include "heu/library/algorithms/clean_template/secret_key.h" 23 | 24 | namespace heu::lib::algorithms::your_algo { 25 | 26 | class Decryptor { 27 | public: 28 | explicit Decryptor(const PublicKey &_, const SecretKey &sk); 29 | 30 | void Decrypt(const Ciphertext &ct, Plaintext *out) const; 31 | Plaintext Decrypt(const Ciphertext &ct) const; 32 | }; 33 | 34 | } // namespace heu::lib::algorithms::your_algo 35 | -------------------------------------------------------------------------------- /heu/library/algorithms/clean_template/scalar_encryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/clean_template/ciphertext.h" 18 | #include "heu/library/algorithms/clean_template/plaintext.h" 19 | #include "heu/library/algorithms/clean_template/public_key.h" 20 | 21 | namespace heu::lib::algorithms::your_algo { 22 | 23 | class Encryptor { 24 | public: 25 | explicit Encryptor(const PublicKey &pk); 26 | 27 | Ciphertext EncryptZero() const; 28 | Ciphertext Encrypt(const Plaintext &m) const; 29 | 30 | std::pair EncryptWithAudit(const Plaintext &m) const; 31 | }; 32 | 33 | } // namespace heu::lib::algorithms::your_algo 34 | -------------------------------------------------------------------------------- /heu/library/algorithms/clean_template/secret_key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "yacl/base/byte_container_view.h" 18 | 19 | namespace heu::lib::algorithms::your_algo { 20 | 21 | class SecretKey { 22 | public: 23 | bool operator==(const SecretKey &other) const; 24 | bool operator!=(const SecretKey &other) const; 25 | 26 | std::string ToString() const; 27 | 28 | yacl::Buffer Serialize() const; 29 | void Deserialize(yacl::ByteContainerView in); 30 | }; 31 | 32 | } // namespace heu::lib::algorithms::your_algo 33 | -------------------------------------------------------------------------------- /heu/library/algorithms/clean_template/vector_decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/clean_template/ciphertext.h" 18 | #include "heu/library/algorithms/clean_template/plaintext.h" 19 | #include "heu/library/algorithms/clean_template/public_key.h" 20 | #include "heu/library/algorithms/clean_template/secret_key.h" 21 | #include "heu/library/algorithms/util/spi_traits.h" 22 | 23 | namespace heu::lib::algorithms::your_algo { 24 | 25 | class Decryptor { 26 | public: 27 | explicit Decryptor(const PublicKey &_, const SecretKey &sk); 28 | 29 | std::vector Decrypt(ConstSpan<Ciphertext> cts) const; 30 | void Decrypt(ConstSpan<Ciphertext> in_cts, Span<Plaintext> out_pts) const; 31 | }; 32 | 33 | } // namespace heu::lib::algorithms::your_algo 34 | -------------------------------------------------------------------------------- /heu/library/algorithms/clean_template/vector_encryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/clean_template/ciphertext.h" 18 | #include "heu/library/algorithms/clean_template/plaintext.h" 19 | #include "heu/library/algorithms/clean_template/public_key.h" 20 | #include "heu/library/algorithms/util/spi_traits.h" 21 | 22 | namespace heu::lib::algorithms::your_algo { 23 | 24 | class Encryptor { 25 | public: 26 | explicit Encryptor(const PublicKey &pk); 27 | 28 | std::vector<Ciphertext> EncryptZero(int64_t size) const; 29 | std::vector<Ciphertext> Encrypt(ConstSpan<Plaintext> pts) const; 30 | 31 | std::pair<std::vector<Ciphertext>, std::vector<std::string>> EncryptWithAudit( 32 | ConstSpan<Plaintext> pts) const; 33 | }; 34 | 35 | } // namespace heu::lib::algorithms::your_algo 36 | -------------------------------------------------------------------------------- /heu/library/algorithms/dgk/decryptor.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/algorithms/dgk/decryptor.h" 16 | 17 | #include "heu/library/algorithms/util/he_assert.h" 18 | 19 | namespace heu::lib::algorithms::dgk { 20 | 21 | Plaintext Decryptor::Decrypt(const Ciphertext &ct) const { 22 | HE_ASSERT(!ct.c_.IsNegative() && ct.c_ < pk_.CipherModule(), 23 | "Decryptor: Invalid ciphertext"); 24 | auto m = sk_.Decrypt(pk_.MapBackToZSpace(ct.c_)); 25 | return m > pk_.PlaintextBound() ? m - pk_.U() : m; 26 | } 27 | 28 | } // namespace heu::lib::algorithms::dgk 29 | -------------------------------------------------------------------------------- /heu/library/algorithms/dgk/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <utility> 18 | 19 | #include "heu/library/algorithms/dgk/ciphertext.h" 20 | #include "heu/library/algorithms/dgk/public_key.h" 21 | #include "heu/library/algorithms/dgk/secret_key.h" 22 | 23 | namespace heu::lib::algorithms::dgk { 24 | 25 | class Decryptor { 26 | public: 27 | explicit Decryptor(PublicKey pk, SecretKey sk) 28 | : pk_(std::move(pk)), sk_(std::move(sk)) {} 29 | 30 | void Decrypt(const Ciphertext &ct, Plaintext *out) const { 31 | *out = Decrypt(ct); 32 | } 33 | 34 | Plaintext Decrypt(const Ciphertext &ct) const; 35 | 36 | private: 37 | PublicKey pk_; 38 | SecretKey sk_; 39 | }; 40 | 41 | } // namespace heu::lib::algorithms::dgk 42 | -------------------------------------------------------------------------------- /heu/library/algorithms/dgk/dgk.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/dgk/ciphertext.h" 18 | #include "heu/library/algorithms/dgk/decryptor.h" 19 | #include "heu/library/algorithms/dgk/encryptor.h" 20 | #include "heu/library/algorithms/dgk/evaluator.h" 21 | #include "heu/library/algorithms/dgk/key_generator.h" 22 | #include "heu/library/algorithms/dgk/public_key.h" 23 | #include "heu/library/algorithms/dgk/secret_key.h" 24 | -------------------------------------------------------------------------------- /heu/library/algorithms/dgk/encryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <mutex> 18 | #include <utility> 19 | 20 | #include "heu/library/algorithms/dgk/ciphertext.h" 21 | #include "heu/library/algorithms/dgk/public_key.h" 22 | #include "heu/library/algorithms/dgk/secret_key.h" 23 | 24 | namespace heu::lib::algorithms::dgk { 25 | 26 | class Encryptor { 27 | public: 28 | explicit Encryptor(const PublicKey &pk) : pk_{std::move(pk)} {} 29 | 30 | Ciphertext EncryptZero() const; 31 | Ciphertext Encrypt(const Plaintext &m) const; 32 | 33 | std::pair<Ciphertext, std::string> EncryptWithAudit(const Plaintext &m) const; 34 | 35 | private: 36 | const PublicKey pk_; 37 | }; 38 | 39 | } // namespace heu::lib::algorithms::dgk 40 | -------------------------------------------------------------------------------- /heu/library/algorithms/dgk/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/dgk/public_key.h" 18 | #include "heu/library/algorithms/dgk/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::dgk { 21 | 22 | class KeyGenerator { 23 | public: 24 | static void Generate(size_t key_size, SecretKey *sk, PublicKey *pk); 25 | static void Generate(SecretKey *sk, PublicKey *pk); 26 | 27 | constexpr static size_t l{16}; // recommended u size 28 | constexpr static size_t t{160}; // recommended v size; FIXME 29 | }; 30 | 31 | } // namespace heu::lib::algorithms::dgk 32 | -------------------------------------------------------------------------------- /heu/library/algorithms/dj/ciphertext.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/util/big_int.h" 18 | #include "heu/library/algorithms/util/he_object.h" 19 | 20 | namespace heu::lib::algorithms::dj { 21 | 22 | using Plaintext = BigInt; 23 | 24 | class Ciphertext : public HeObject<Ciphertext> { 25 | public: 26 | Ciphertext() = default; 27 | 28 | explicit Ciphertext(BigInt c) : c_(std::move(c)) {} 29 | 30 | [[nodiscard]] std::string ToString() const override { return c_.ToString(); } 31 | 32 | bool operator==(const Ciphertext &other) const { return c_ == other.c_; } 33 | 34 | bool operator!=(const Ciphertext &other) const { 35 | return !this->operator==(other); 36 | } 37 | 38 | MSGPACK_DEFINE(c_); 39 | 40 | // TODO: make this private. 41 | BigInt c_; 42 | }; 43 | 44 | } // namespace heu::lib::algorithms::dj 45 | -------------------------------------------------------------------------------- /heu/library/algorithms/dj/decryptor.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/algorithms/dj/decryptor.h" 16 | 17 | #include "heu/library/algorithms/util/he_assert.h" 18 | 19 | namespace heu::lib::algorithms::dj { 20 | 21 | Plaintext Decryptor::Decrypt(const Ciphertext &ct) const { 22 | HE_ASSERT(!ct.c_.IsNegative() && ct.c_ < pk_.CipherModule(), 23 | "Decryptor: Invalid ciphertext"); 24 | Plaintext m{sk_.Decrypt(pk_.MapBackToZSpace(ct.c_))}; 25 | return m > pk_.PlaintextBound() ? m - pk_.PlainModule() : m; 26 | } 27 | 28 | } // namespace heu::lib::algorithms::dj 29 | -------------------------------------------------------------------------------- /heu/library/algorithms/dj/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <utility> 18 | 19 | #include "heu/library/algorithms/dj/ciphertext.h" 20 | #include "heu/library/algorithms/dj/public_key.h" 21 | #include "heu/library/algorithms/dj/secret_key.h" 22 | 23 | namespace heu::lib::algorithms::dj { 24 | 25 | class Decryptor { 26 | public: 27 | explicit Decryptor(PublicKey pk, SecretKey sk) 28 | : pk_(std::move(pk)), sk_(std::move(sk)) {} 29 | 30 | void Decrypt(const Ciphertext &ct, Plaintext *out) const { 31 | *out = Decrypt(ct); 32 | } 33 | 34 | Plaintext Decrypt(const Ciphertext &ct) const; 35 | 36 | private: 37 | PublicKey pk_; 38 | SecretKey sk_; 39 | }; 40 | 41 | } // namespace heu::lib::algorithms::dj 42 | -------------------------------------------------------------------------------- /heu/library/algorithms/dj/dj.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/dj/ciphertext.h" 18 | #include "heu/library/algorithms/dj/decryptor.h" 19 | #include "heu/library/algorithms/dj/encryptor.h" 20 | #include "heu/library/algorithms/dj/evaluator.h" 21 | #include "heu/library/algorithms/dj/key_generator.h" 22 | #include "heu/library/algorithms/dj/public_key.h" 23 | #include "heu/library/algorithms/dj/secret_key.h" 24 | -------------------------------------------------------------------------------- /heu/library/algorithms/dj/encryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <mutex> 18 | #include <utility> 19 | 20 | #include "heu/library/algorithms/dj/ciphertext.h" 21 | #include "heu/library/algorithms/dj/public_key.h" 22 | #include "heu/library/algorithms/dj/secret_key.h" 23 | 24 | namespace heu::lib::algorithms::dj { 25 | 26 | class Encryptor { 27 | public: 28 | explicit Encryptor(const PublicKey &pk) : pk_{std::move(pk)} {} 29 | 30 | Ciphertext EncryptZero() const; 31 | Ciphertext Encrypt(const Plaintext &m) const; 32 | 33 | std::pair<Ciphertext, std::string> EncryptWithAudit(const Plaintext &m) const; 34 | 35 | private: 36 | const PublicKey pk_; 37 | }; 38 | 39 | } // namespace heu::lib::algorithms::dj 40 | -------------------------------------------------------------------------------- /heu/library/algorithms/dj/key_generator.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/algorithms/dj/key_generator.h" 16 | 17 | #include "yacl/base/exception.h" 18 | 19 | namespace heu::lib::algorithms::dj { 20 | 21 | void KeyGenerator::Generate(size_t key_size, SecretKey *sk, PublicKey *pk) { 22 | YACL_ENFORCE(key_size % 2 == 0, "Key size must be even"); 23 | 24 | BigInt q, gcd; 25 | BigInt p = BigInt::RandPrimeOver(key_size / 2, PrimeType::BBS); 26 | do { 27 | q = BigInt::RandPrimeOver(key_size / 2, PrimeType::BBS); 28 | gcd = (p - 1).Gcd(q - 1); 29 | } while (gcd != 2); 30 | sk->Init(p, q, s_); 31 | pk->Init(p * q, s_, BigInt{0}); 32 | } 33 | 34 | void KeyGenerator::Generate(SecretKey *sk, PublicKey *pk) { 35 | Generate(2048, sk, pk); 36 | } 37 | 38 | } // namespace heu::lib::algorithms::dj 39 | -------------------------------------------------------------------------------- /heu/library/algorithms/dj/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 zhangwfjh 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/dj/public_key.h" 18 | #include "heu/library/algorithms/dj/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::dj { 21 | 22 | class KeyGenerator { 23 | public: 24 | static void Generate(size_t key_size, SecretKey *sk, PublicKey *pk); 25 | static void Generate(SecretKey *sk, PublicKey *pk); 26 | 27 | static inline uint32_t s_{2u}; 28 | }; 29 | 30 | } // namespace heu::lib::algorithms::dj 31 | -------------------------------------------------------------------------------- /heu/library/algorithms/elgamal/elgamal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | // Exponential EC Elgamal implementation 18 | 19 | #include "heu/library/algorithms/elgamal/key_generator.h" 20 | #include "heu/library/algorithms/elgamal/public_key.h" 21 | #include "heu/library/algorithms/elgamal/scalar_decryptor.h" 22 | #include "heu/library/algorithms/elgamal/scalar_encryptor.h" 23 | #include "heu/library/algorithms/elgamal/scalar_evaluator.h" 24 | #include "heu/library/algorithms/elgamal/secret_key.h" 25 | -------------------------------------------------------------------------------- /heu/library/algorithms/elgamal/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/elgamal/public_key.h" 18 | #include "heu/library/algorithms/elgamal/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::elgamal { 21 | 22 | class KeyGenerator { 23 | public: 24 | // Generate a PHE key pair 25 | static void Generate(const yacl::crypto::CurveName &curve_name, SecretKey *sk, 26 | PublicKey *pk); 27 | static void Generate(size_t key_size, SecretKey *sk, PublicKey *pk); 28 | // Generate a PHE key pair by default configs 29 | static void Generate(SecretKey *sk, PublicKey *pk); 30 | }; 31 | 32 | } // namespace heu::lib::algorithms::elgamal 33 | -------------------------------------------------------------------------------- /heu/library/algorithms/elgamal/plaintext.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/util/mp_int.h" 18 | 19 | namespace heu::lib::algorithms::elgamal { 20 | 21 | using Plaintext = yacl::crypto::MPInt; 22 | 23 | } // namespace heu::lib::algorithms::elgamal 24 | -------------------------------------------------------------------------------- /heu/library/algorithms/elgamal/scalar_decryptor.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/algorithms/elgamal/scalar_decryptor.h" 16 | 17 | namespace heu::lib::algorithms::elgamal { 18 | 19 | void Decryptor::Decrypt(const Ciphertext &ct, Plaintext *out) const { 20 | auto mg = pk_.GetCurve()->Sub(ct.c2, pk_.GetCurve()->Mul(ct.c1, sk_.GetX())); 21 | 22 | // now we know G and mG, recover m by a lookup table 23 | out->Set(sk_.GetInitedLookupTable()->Search(mg)); 24 | } 25 | 26 | Plaintext Decryptor::Decrypt(const Ciphertext &ct) const { 27 | auto mg = pk_.GetCurve()->Sub(ct.c2, pk_.GetCurve()->Mul(ct.c1, sk_.GetX())); 28 | 29 | // now we know G and mG, recover m by a lookup table 30 | return Plaintext(sk_.GetInitedLookupTable()->Search(mg)); 31 | } 32 | 33 | } // namespace heu::lib::algorithms::elgamal 34 | -------------------------------------------------------------------------------- /heu/library/algorithms/elgamal/scalar_decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <utility> 18 | 19 | #include "heu/library/algorithms/elgamal/ciphertext.h" 20 | #include "heu/library/algorithms/elgamal/plaintext.h" 21 | #include "heu/library/algorithms/elgamal/public_key.h" 22 | #include "heu/library/algorithms/elgamal/secret_key.h" 23 | 24 | namespace heu::lib::algorithms::elgamal { 25 | 26 | class Decryptor { 27 | public: 28 | Decryptor(const PublicKey &pk, const SecretKey &sk) : pk_(pk), sk_(sk) {}; 29 | 30 | void Decrypt(const Ciphertext &ct, Plaintext *out) const; 31 | Plaintext Decrypt(const Ciphertext &ct) const; 32 | 33 | private: 34 | PublicKey pk_; 35 | SecretKey sk_; 36 | }; 37 | 38 | } // namespace heu::lib::algorithms::elgamal 39 | -------------------------------------------------------------------------------- /heu/library/algorithms/elgamal/scalar_encryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/elgamal/ciphertext.h" 18 | #include "heu/library/algorithms/elgamal/plaintext.h" 19 | #include "heu/library/algorithms/elgamal/public_key.h" 20 | 21 | namespace heu::lib::algorithms::elgamal { 22 | 23 | class Encryptor { 24 | public: 25 | explicit Encryptor(const PublicKey &pk); 26 | 27 | Ciphertext EncryptZero() const; 28 | Ciphertext Encrypt(const Plaintext &m) const; 29 | 30 | std::pair<Ciphertext, std::string> EncryptWithAudit(const Plaintext &m) const; 31 | 32 | private: 33 | PublicKey pk_; 34 | }; 35 | 36 | } // namespace heu::lib::algorithms::elgamal 37 | -------------------------------------------------------------------------------- /heu/library/algorithms/mock/key_generator.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/algorithms/mock/key_generator.h" 16 | 17 | namespace heu::lib::algorithms::mock { 18 | 19 | void KeyGenerator::Generate(int key_size, SecretKey *sk, PublicKey *pk) { 20 | sk->key_size_ = key_size; 21 | pk->key_size_ = key_size; 22 | pk->max_int_.Set(1); 23 | pk->max_int_ <<= (key_size - 2); 24 | } 25 | 26 | void KeyGenerator::Generate(SecretKey *sk, PublicKey *pk) { 27 | Generate(2048, sk, pk); 28 | } 29 | 30 | } // namespace heu::lib::algorithms::mock 31 | -------------------------------------------------------------------------------- /heu/library/algorithms/mock/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/mock/public_key.h" 18 | #include "heu/library/algorithms/mock/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::mock { 21 | 22 | class KeyGenerator { 23 | public: 24 | // Generate PHE key pair 25 | // [SPI: Critical] 26 | static void Generate(int key_size, SecretKey *sk, PublicKey *pk); 27 | // Generate PHE key pair by default configs 28 | static void Generate(SecretKey *sk, PublicKey *pk); 29 | }; 30 | 31 | } // namespace heu::lib::algorithms::mock 32 | -------------------------------------------------------------------------------- /heu/library/algorithms/mock/mock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/mock/decryptor.h" 18 | #include "heu/library/algorithms/mock/encryptor.h" 19 | #include "heu/library/algorithms/mock/evaluator.h" 20 | #include "heu/library/algorithms/mock/key_generator.h" 21 | #include "heu/library/algorithms/mock/public_key.h" 22 | #include "heu/library/algorithms/mock/secret_key.h" 23 | -------------------------------------------------------------------------------- /heu/library/algorithms/ou/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <utility> 18 | 19 | #include "heu/library/algorithms/ou/ciphertext.h" 20 | #include "heu/library/algorithms/ou/public_key.h" 21 | #include "heu/library/algorithms/ou/secret_key.h" 22 | 23 | namespace heu::lib::algorithms::ou { 24 | 25 | class Decryptor { 26 | public: 27 | explicit Decryptor(PublicKey pk, SecretKey sk); 28 | 29 | void Decrypt(const Ciphertext &ct, BigInt *out) const; 30 | [[nodiscard]] BigInt Decrypt(const Ciphertext &ct) const; 31 | 32 | private: 33 | PublicKey pk_; 34 | SecretKey sk_; 35 | }; 36 | 37 | } // namespace heu::lib::algorithms::ou 38 | -------------------------------------------------------------------------------- /heu/library/algorithms/ou/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/ou/public_key.h" 18 | #include "heu/library/algorithms/ou/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::ou { 21 | 22 | class KeyGenerator { 23 | public: 24 | // Generate OU key pair 25 | static void Generate(size_t key_size, SecretKey *sk, PublicKey *pk); 26 | // Generate PHE key pair by default configs 27 | static void Generate(SecretKey *sk, PublicKey *pk); 28 | }; 29 | 30 | } // namespace heu::lib::algorithms::ou 31 | -------------------------------------------------------------------------------- /heu/library/algorithms/ou/ou.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | // Okamoto–Uchiyama cryptosystem 18 | 19 | #include "heu/library/algorithms/ou/decryptor.h" 20 | #include "heu/library/algorithms/ou/encryptor.h" 21 | #include "heu/library/algorithms/ou/evaluator.h" 22 | #include "heu/library/algorithms/ou/key_generator.h" 23 | #include "heu/library/algorithms/ou/public_key.h" 24 | #include "heu/library/algorithms/ou/secret_key.h" 25 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_clustar_fpga/clustar_fpga.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Clustar Technology Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #ifndef ENABLE_CLUSTAR_FPGA 18 | #define ENABLE_CLUSTAR_FPGA false 19 | #endif 20 | 21 | #if ENABLE_CLUSTAR_FPGA == true 22 | 23 | #include "heu/library/algorithms/paillier_clustar_fpga/ciphertext.h" 24 | #include "heu/library/algorithms/paillier_clustar_fpga/key_generator.h" 25 | #include "heu/library/algorithms/paillier_clustar_fpga/plaintext.h" 26 | #include "heu/library/algorithms/paillier_clustar_fpga/public_key.h" 27 | #include "heu/library/algorithms/paillier_clustar_fpga/secret_key.h" 28 | #include "heu/library/algorithms/paillier_clustar_fpga/vector_decryptor.h" 29 | #include "heu/library/algorithms/paillier_clustar_fpga/vector_encryptor.h" 30 | #include "heu/library/algorithms/paillier_clustar_fpga/vector_evaluator.h" 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_clustar_fpga/fpga_engine/config/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@yacl//bazel:yacl.bzl", "yacl_cc_library") 16 | 17 | yacl_cc_library( 18 | name = "fpga_config", 19 | srcs = [ 20 | "config.cc", 21 | ], 22 | hdrs = [ 23 | "config.h", 24 | ], 25 | visibility = ["//visibility:public"], 26 | ) 27 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_clustar_fpga/fpga_engine/config/config.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Clustar Technology Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "config.h" 16 | 17 | namespace heu::lib::algorithms::paillier_clustar_fpga::fpga_engine { 18 | 19 | struct timeval time_point[40]; 20 | struct timeval fpgaid_time_point[8][30]; 21 | 22 | // FPGA's longest wait_time in all cases(unit: us) 23 | 24 | #ifdef MULTI_CARD_DEBUG 25 | long double maximum_time = 10000000.0; 26 | long double single_task_maximum_time = 10000000.0; 27 | #else 28 | long double maximum_time = 3600000000.0; 29 | long double single_task_maximum_time = 3600000000.0; 30 | 31 | } // heu::lib::algorithms::paillier_clustar_fpga::fpga_engine 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_clustar_fpga/fpga_engine/driver/mpint_wrapper.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Clustar Technology Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "mpint_wrapper.h" 16 | 17 | namespace heu::lib::algorithms::paillier_clustar_fpga::fpga_engine { 18 | 19 | void CMPIntWrapper::MPIntToBytes(const MPInt &v, char *ptr, size_t len) { 20 | memset(ptr, 0, len); 21 | v.ToMagBytes(reinterpret_cast<unsigned char *>(ptr), len, Endian::little); 22 | } 23 | 24 | } // namespace heu::lib::algorithms::paillier_clustar_fpga::fpga_engine 25 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_clustar_fpga/fpga_engine/driver/mpint_wrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Clustar Technology Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <string.h> 18 | 19 | #include "heu/library/algorithms/util/mp_int.h" 20 | #include "heu/library/algorithms/util/spi_traits.h" 21 | 22 | namespace heu::lib::algorithms::paillier_clustar_fpga::fpga_engine { 23 | 24 | class CMPIntWrapper { 25 | public: 26 | CMPIntWrapper() = default; 27 | ~CMPIntWrapper() = default; 28 | 29 | static void MPIntToBytes(const MPInt &v, char *ptr, size_t len); 30 | }; 31 | 32 | } // namespace heu::lib::algorithms::paillier_clustar_fpga::fpga_engine 33 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_clustar_fpga/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Clustar Technology Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/paillier_clustar_fpga/public_key.h" 18 | #include "heu/library/algorithms/paillier_clustar_fpga/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::paillier_clustar_fpga { 21 | 22 | class KeyGenerator { 23 | public: 24 | // Generate paillier key pair 25 | static void Generate(size_t key_size, SecretKey *sk, PublicKey *pk); 26 | // Generate PHE key pair by default configs 27 | static void Generate(SecretKey *sk, PublicKey *pk); 28 | }; 29 | 30 | } // namespace heu::lib::algorithms::paillier_clustar_fpga 31 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_float/key_gen.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/paillier_float/public_key.h" 18 | #include "heu/library/algorithms/paillier_float/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::paillier_f { 21 | 22 | class KeyGenerator { 23 | public: 24 | static void Generate(size_t key_bits, SecretKey *sk, PublicKey *pk); 25 | // Generate PHE key pair by default configs 26 | static void Generate(SecretKey *sk, PublicKey *pk); 27 | }; 28 | 29 | } // namespace heu::lib::algorithms::paillier_f 30 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_float/paillier.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | // Paillier_float supports encrypt floating numbers, 18 | // and supports ciphertext overflow detection in decryption stage 19 | 20 | #include "heu/library/algorithms/paillier_float/ciphertext.h" 21 | #include "heu/library/algorithms/paillier_float/decryptor.h" 22 | #include "heu/library/algorithms/paillier_float/encryptor.h" 23 | #include "heu/library/algorithms/paillier_float/evaluator.h" 24 | #include "heu/library/algorithms/paillier_float/key_gen.h" 25 | #include "heu/library/algorithms/paillier_float/public_key.h" 26 | #include "heu/library/algorithms/paillier_float/secret_key.h" 27 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_float/public_key.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/algorithms/paillier_float/public_key.h" 16 | 17 | #include <utility> 18 | 19 | namespace heu::lib::algorithms::paillier_f { 20 | 21 | PublicKey::PublicKey(const BigInt &n) : n_(n) { Init(); } 22 | 23 | PublicKey::PublicKey(BigInt &&n) : n_(std::move(n)) { Init(); } 24 | 25 | void PublicKey::Init() { 26 | g_ = n_ + 1; 27 | n_square_ = n_ * n_; 28 | max_int_ = n_ / 3; 29 | } 30 | 31 | std::string PublicKey::ToString() const { 32 | return fmt::format("F-paillier PK: n={}[{}bits], max_plaintext={}[~{}bits]", 33 | n_.ToHexString(), n_.BitCount(), 34 | PlaintextBound().ToHexString(), 35 | PlaintextBound().BitCount()); 36 | } 37 | 38 | } // namespace heu::lib::algorithms::paillier_f 39 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_float/secret_key.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/algorithms/paillier_float/secret_key.h" 16 | 17 | namespace heu::lib::algorithms::paillier_f { 18 | 19 | SecretKey::SecretKey(PublicKey pk, BigInt p, BigInt q) : pk_(std::move(pk)) { 20 | lambda_ = (p - 1).Lcm(q - 1); // lambda_ = lcm(p-1, q-1) 21 | 22 | x_ = pk_.g_.PowMod(lambda_, pk_.n_square_); 23 | x_ = (x_ - 1) / pk_.n_; 24 | x_ = x_.InvMod(pk_.n_); 25 | } 26 | 27 | std::string SecretKey::ToString() const { 28 | return fmt::format("F-paillier SK: lambda={}[{}bits], x={}[{}bits]", 29 | lambda_.ToHexString(), lambda_.BitCount(), 30 | x_.ToHexString(), x_.BitCount()); 31 | } 32 | 33 | } // namespace heu::lib::algorithms::paillier_f 34 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_gpu/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/paillier_gpu//public_key.h" 18 | #include "heu/library/algorithms/paillier_gpu//secret_key.h" 19 | 20 | namespace heu::lib::algorithms::paillier_g { 21 | 22 | class KeyGenerator { 23 | public: 24 | // Generate paillier key pair 25 | static void Generate(size_t key_size, SecretKey *sk, PublicKey *pk); 26 | // Generate PHE key pair by default configs 27 | static void Generate(SecretKey *sk, PublicKey *pk); 28 | }; 29 | 30 | } // namespace heu::lib::algorithms::paillier_g 31 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_gpu/paillier.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | // DJ paillier scheme, reference: https://www.brics.dk/DS/03/9/BRICS-DS-03-9.pdf 18 | 19 | #ifndef ENABLE_GPAILLIER 20 | #define ENABLE_GPAILLIER false 21 | #endif 22 | 23 | #if ENABLE_GPAILLIER == true 24 | #include "heu/library/algorithms/paillier_gpu/ciphertext.h" 25 | #include "heu/library/algorithms/paillier_gpu/decryptor.h" 26 | #include "heu/library/algorithms/paillier_gpu/encryptor.h" 27 | #include "heu/library/algorithms/paillier_gpu/evaluator.h" 28 | #include "heu/library/algorithms/paillier_gpu/key_generator.h" 29 | #include "heu/library/algorithms/paillier_gpu/public_key.h" 30 | #include "heu/library/algorithms/paillier_gpu/secret_key.h" 31 | #endif 32 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_gpu/plaintext.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/util/big_int.h" 18 | 19 | namespace heu::lib::algorithms::paillier_g { 20 | 21 | using Plaintext = BigInt; 22 | 23 | } // namespace heu::lib::algorithms::paillier_g 24 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ic/README.md: -------------------------------------------------------------------------------- 1 | 互联互通版 Paillier 实现 2 | 3 | 算法主体按照 Paillier03 实现,序列化格式符合信通院互联互通团标协议 4 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ic/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <utility> 18 | 19 | #include "heu/library/algorithms/paillier_ic/ciphertext.h" 20 | #include "heu/library/algorithms/paillier_ic/public_key.h" 21 | #include "heu/library/algorithms/paillier_ic/secret_key.h" 22 | 23 | namespace heu::lib::algorithms::paillier_ic { 24 | 25 | class Decryptor { 26 | public: 27 | explicit Decryptor(PublicKey pk, SecretKey sk) 28 | : pk_(std::move(pk)), sk_(std::move(sk)) {} 29 | 30 | void Decrypt(const Ciphertext &ct, BigInt *out) const; 31 | BigInt Decrypt(const Ciphertext &ct) const; 32 | 33 | private: 34 | PublicKey pk_; 35 | SecretKey sk_; 36 | }; 37 | 38 | } // namespace heu::lib::algorithms::paillier_ic 39 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ic/key_generator.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/algorithms/paillier_ic/key_generator.h" 16 | 17 | #include "heu/library/algorithms/paillier_zahlen/key_generator.h" 18 | 19 | namespace heu::lib::algorithms::paillier_ic { 20 | 21 | void KeyGenerator::Generate(size_t key_size, SecretKey *sk, PublicKey *pk) { 22 | paillier_z::PublicKey zpk; 23 | 24 | paillier_z::KeyGenerator::Generate(key_size, sk, &zpk); 25 | pk->n_ = zpk.n_; 26 | pk->h_s_ = zpk.h_s_; 27 | pk->Init(); 28 | } 29 | 30 | void KeyGenerator::Generate(SecretKey *sk, PublicKey *pk) { 31 | Generate(2048, sk, pk); 32 | } 33 | 34 | } // namespace heu::lib::algorithms::paillier_ic 35 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ic/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/paillier_ic//public_key.h" 18 | #include "heu/library/algorithms/paillier_ic//secret_key.h" 19 | 20 | namespace heu::lib::algorithms::paillier_ic { 21 | 22 | class KeyGenerator { 23 | public: 24 | // Generate paillier key pair 25 | static void Generate(size_t key_size, SecretKey *sk, PublicKey *pk); 26 | // Generate PHE key pair by default configs 27 | static void Generate(SecretKey *sk, PublicKey *pk); 28 | }; 29 | 30 | } // namespace heu::lib::algorithms::paillier_ic 31 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ic/paillier.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | // DJ paillier scheme, reference: https://www.brics.dk/DS/03/9/BRICS-DS-03-9.pdf 18 | 19 | #include "heu/library/algorithms/paillier_ic/ciphertext.h" 20 | #include "heu/library/algorithms/paillier_ic/decryptor.h" 21 | #include "heu/library/algorithms/paillier_ic/encryptor.h" 22 | #include "heu/library/algorithms/paillier_ic/evaluator.h" 23 | #include "heu/library/algorithms/paillier_ic/key_generator.h" 24 | #include "heu/library/algorithms/paillier_ic/public_key.h" 25 | #include "heu/library/algorithms/paillier_ic/secret_key.h" 26 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ic/pb_utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/util/big_int.h" 18 | 19 | #include "interconnection/runtime/phe.pb.h" 20 | 21 | namespace heu::lib::algorithms::paillier_ic { 22 | 23 | namespace pb_ns = ::org::interconnection::v2::runtime; 24 | 25 | pb_ns::Bigint BigInt2PbBigint(const BigInt &bi); 26 | void PbBigint2BigInt(const pb_ns::Bigint &pb_bi, BigInt &bigint); 27 | 28 | } // namespace heu::lib::algorithms::paillier_ic 29 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ic/secret_key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/paillier_zahlen/secret_key.h" 18 | 19 | namespace heu::lib::algorithms::paillier_ic { 20 | 21 | class SecretKey : public ::heu::lib::algorithms::paillier_z::SecretKey { 22 | public: 23 | MSGPACK_DEFINE(MSGPACK_BASE(::heu::lib::algorithms::paillier_z::SecretKey)); 24 | 25 | std::string ToString() const { 26 | return fmt::format( 27 | "[interconnection] paillier03 SK: p={}[{}bits], q={}[{}bits]", 28 | p_.ToHexString(), p_.BitCount(), q_.ToHexString(), q_.BitCount()); 29 | } 30 | }; 31 | 32 | } // namespace heu::lib::algorithms::paillier_ic 33 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ipcl/key_generator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/algorithms/paillier_ipcl/key_generator.h" 16 | 17 | #include "ipcl/ipcl.hpp" 18 | 19 | namespace heu::lib::algorithms::paillier_ipcl { 20 | 21 | void KeyGenerator::Generate(int key_size, SecretKey *sk, PublicKey *pk) { 22 | ipcl::KeyPair key_pair; 23 | bool enable_DJN = true; // enable DJN scheme by default 24 | 25 | key_pair = ipcl::generateKeypair(key_size, enable_DJN); 26 | pk->Init(key_pair.pub_key); 27 | sk->Init(key_pair.priv_key); 28 | } 29 | 30 | void KeyGenerator::Generate(SecretKey *sk, PublicKey *pk) { 31 | Generate(2048, sk, pk); 32 | } 33 | 34 | } // namespace heu::lib::algorithms::paillier_ipcl 35 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ipcl/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/paillier_ipcl/public_key.h" 18 | #include "heu/library/algorithms/paillier_ipcl/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::paillier_ipcl { 21 | 22 | class KeyGenerator { 23 | public: 24 | // Generate PHE key pair 25 | static void Generate(int key_size, SecretKey *sk, PublicKey *pk); 26 | // Generate PHE key pair by default configs 27 | static void Generate(SecretKey *sk, PublicKey *pk); 28 | }; 29 | 30 | } // namespace heu::lib::algorithms::paillier_ipcl 31 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_ipcl/secret_key.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "ipcl/pri_key.hpp" 18 | #include "yacl/base/byte_container_view.h" 19 | 20 | namespace heu::lib::algorithms::paillier_ipcl { 21 | 22 | class SecretKey { 23 | public: 24 | void Init(ipcl::PrivateKey sk) { ipcl_prikey_ = sk; } 25 | 26 | bool operator==(const SecretKey &other) const; 27 | bool operator!=(const SecretKey &other) const; 28 | 29 | std::string ToString() const; 30 | 31 | yacl::Buffer Serialize() const; 32 | 33 | void Deserialize(yacl::ByteContainerView in); 34 | ipcl::PrivateKey ipcl_prikey_; 35 | }; 36 | 37 | } // namespace heu::lib::algorithms::paillier_ipcl 38 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_zahlen/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <utility> 18 | 19 | #include "heu/library/algorithms/paillier_zahlen/ciphertext.h" 20 | #include "heu/library/algorithms/paillier_zahlen/public_key.h" 21 | #include "heu/library/algorithms/paillier_zahlen/secret_key.h" 22 | 23 | namespace heu::lib::algorithms::paillier_z { 24 | 25 | class Decryptor { 26 | public: 27 | explicit Decryptor(PublicKey pk, SecretKey sk); 28 | 29 | void Decrypt(const Ciphertext &ct, BigInt *out) const; 30 | BigInt Decrypt(const Ciphertext &ct) const; 31 | 32 | private: 33 | PublicKey pk_; 34 | SecretKey sk_; 35 | }; 36 | 37 | } // namespace heu::lib::algorithms::paillier_z 38 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_zahlen/key_generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/algorithms/paillier_zahlen/public_key.h" 18 | #include "heu/library/algorithms/paillier_zahlen/secret_key.h" 19 | 20 | namespace heu::lib::algorithms::paillier_z { 21 | 22 | class KeyGenerator { 23 | public: 24 | // Generate paillier key pair 25 | static void Generate(size_t key_size, SecretKey *sk, PublicKey *pk); 26 | // Generate PHE key pair by default configs 27 | static void Generate(SecretKey *sk, PublicKey *pk); 28 | }; 29 | 30 | } // namespace heu::lib::algorithms::paillier_z 31 | -------------------------------------------------------------------------------- /heu/library/algorithms/paillier_zahlen/paillier.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | // DJ paillier scheme, reference: https://www.brics.dk/DS/03/9/BRICS-DS-03-9.pdf 18 | 19 | #include "heu/library/algorithms/paillier_zahlen/ciphertext.h" 20 | #include "heu/library/algorithms/paillier_zahlen/decryptor.h" 21 | #include "heu/library/algorithms/paillier_zahlen/encryptor.h" 22 | #include "heu/library/algorithms/paillier_zahlen/evaluator.h" 23 | #include "heu/library/algorithms/paillier_zahlen/key_generator.h" 24 | #include "heu/library/algorithms/paillier_zahlen/public_key.h" 25 | #include "heu/library/algorithms/paillier_zahlen/secret_key.h" 26 | -------------------------------------------------------------------------------- /heu/library/algorithms/util/big_int.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "yacl/math/bigint/bigint.h" 18 | 19 | namespace heu::lib::algorithms { 20 | 21 | using yacl::math::BaseTable; 22 | using yacl::math::BigInt; 23 | using yacl::math::MontgomerySpace; 24 | using yacl::math::PrimeType; 25 | 26 | } // namespace heu::lib::algorithms 27 | -------------------------------------------------------------------------------- /heu/library/algorithms/util/he_assert.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "yacl/base/exception.h" 18 | 19 | #ifdef NDEBUG 20 | #define HE_ASSERT(condition, ...) ((void)0) 21 | #else 22 | #define HE_ASSERT(condition, ...) YACL_ENFORCE(condition, __VA_ARGS__) 23 | #endif 24 | -------------------------------------------------------------------------------- /heu/library/algorithms/util/mp_int.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "yacl/math/mpint/mp_int.h" 18 | 19 | namespace heu::lib::algorithms { 20 | 21 | // MPInt has moved to YACL, we leave a shortcut here ... 22 | using yacl::math::MPInt; 23 | 24 | } // namespace heu::lib::algorithms 25 | -------------------------------------------------------------------------------- /heu/library/algorithms/util/spi_traits.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "absl/types/span.h" 18 | #include "yacl/utils/spi/type_traits.h" 19 | 20 | namespace heu::lib::algorithms { 21 | 22 | template <typename T> 23 | using Span = absl::Span<T *const>; 24 | 25 | template <typename T> 26 | using ConstSpan = absl::Span<const T *const>; 27 | 28 | using yacl::Endian; 29 | 30 | } // namespace heu::lib::algorithms 31 | -------------------------------------------------------------------------------- /heu/library/benchmark/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@yacl//bazel:yacl.bzl", "yacl_cc_binary") 16 | 17 | yacl_cc_binary( 18 | name = "phe", 19 | srcs = ["phe_bench.cc"], 20 | deps = [ 21 | "//heu/library/phe", 22 | "@fmt", 23 | "@gflags", 24 | "@google_benchmark//:benchmark", 25 | ], 26 | ) 27 | 28 | yacl_cc_binary( 29 | name = "np", 30 | srcs = ["np_bench.cc"], 31 | deps = [ 32 | "//heu/library/numpy", 33 | "@fmt", 34 | "@gflags", 35 | "@google_benchmark//:benchmark", 36 | ], 37 | ) 38 | -------------------------------------------------------------------------------- /heu/library/benchmark/README.md: -------------------------------------------------------------------------------- 1 | # How to run benchmark 2 | 3 | # Run benchmark for all algorithms 4 | 5 | 测试算法在 scalar 运算场景下的性能 6 | 7 | Test the performance of algorithms in scalar computing scenarios 8 | 9 | ```shell 10 | bazel run -c opt heu/library/benchmark:phe 11 | ``` 12 | 13 | 测试算法在矩阵运算场景下的性能 14 | 15 | Test the performance of algorithms in matrix operation scenarios 16 | 17 | ```shell 18 | bazel run -c opt heu/library/benchmark:np 19 | ``` 20 | 21 | # Run benchmark for specified algorithm 22 | 23 | `--schema` 参数可以指定要跑的算法,例如: 24 | 25 | The `--schema` parameter can specify the algorithm to run, for example: 26 | 27 | ```shell 28 | bazel run -c opt heu/library/benchmark:phe -- --schema=paillier 29 | bazel run -c opt heu/library/benchmark:np -- --schema=paillier 30 | ``` 31 | 32 | 另外,`--schema` 参数支持正则匹配算法名称,例如 `paillier.+` 可以匹配全部 paillier 33 | 体系的算法。 34 | 35 | In addition, the `--schema` parameter supports regex matching, for 36 | example `paillier.+` can match all the algorithms of paillier system. 37 | 38 | # Run benchmark with different key size 39 | 40 | 您可以通过 `--key_size` 参数调整 phe 所用的密钥长度。 41 | 42 | You can adjust the key size used by phe algorithms with the `--key_size` 43 | parameter. 44 | 45 | ```shell 46 | bazel run -c opt heu/library/benchmark:phe -- --schema=paillier --key_size=3072 47 | bazel run -c opt heu/library/benchmark:np -- --schema=paillier --key_size=3072 48 | ``` 49 | -------------------------------------------------------------------------------- /heu/library/benchmark/algos/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@yacl//bazel:yacl.bzl", "yacl_cc_binary") 16 | 17 | yacl_cc_binary( 18 | name = "ou", 19 | srcs = ["ou_bench.cc"], 20 | deps = [ 21 | "//heu/library/algorithms/ou", 22 | "@google_benchmark//:benchmark_main", 23 | ], 24 | ) 25 | 26 | yacl_cc_binary( 27 | name = "paillier_float", 28 | srcs = ["paillier_float_bench.cc"], 29 | deps = [ 30 | "//heu/library/algorithms/paillier_float", 31 | "@google_benchmark//:benchmark_main", 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /heu/library/benchmark/bigint/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@yacl//bazel:yacl.bzl", "yacl_cc_binary") 16 | 17 | yacl_cc_binary( 18 | name = "bigint", 19 | srcs = ["bigint_bench.cc"], 20 | linkopts = ["-lm"], 21 | deps = [ 22 | "//heu/library/algorithms/ou", 23 | "//heu/library/algorithms/util:big_int", 24 | "@google_benchmark//:benchmark", 25 | ], 26 | ) 27 | 28 | yacl_cc_binary( 29 | name = "crt", 30 | srcs = ["crt_bench.cc"], 31 | deps = [ 32 | "//heu/library/algorithms/paillier_zahlen", 33 | "@google_benchmark//:benchmark", 34 | ], 35 | ) 36 | -------------------------------------------------------------------------------- /heu/library/benchmark/python_paillier/README.md: -------------------------------------------------------------------------------- 1 | # Python Paillier Benchmark 2 | 3 | doc: 4 | https://python-paillier.readthedocs.io/en/develop/index.html 5 | 6 | github: 7 | https://github.com/data61/python-paillier 8 | 9 | Please make sure python package 'gmpy2' is installed. 10 | 11 | ```shell 12 | # pip install -r requirements.txt 13 | python python_paillier_bench.py 14 | ``` 15 | -------------------------------------------------------------------------------- /heu/library/benchmark/python_paillier/requirements.txt: -------------------------------------------------------------------------------- 1 | # If you want to run this benchmark, please uncomment the following line. 2 | # phe==1.5.0 3 | google-benchmark==1.6.1 4 | gmpy2==2.1.2 5 | -------------------------------------------------------------------------------- /heu/library/numpy/encryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <utility> 18 | 19 | #include "heu/library/numpy/matrix.h" 20 | #include "heu/library/phe/phe.h" 21 | 22 | namespace heu::lib::numpy { 23 | 24 | class Encryptor : public phe::Encryptor { 25 | public: 26 | explicit Encryptor(phe::Encryptor encryptor) 27 | : phe::Encryptor(std::move(encryptor)) {} 28 | 29 | using phe::Encryptor::Encrypt; 30 | CMatrix Encrypt(const PMatrix &in) const; 31 | 32 | std::pair<CMatrix, DenseMatrix<std::string>> EncryptWithAudit( 33 | const PMatrix &in) const; 34 | }; 35 | 36 | } // namespace heu::lib::numpy 37 | -------------------------------------------------------------------------------- /heu/library/numpy/random.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/numpy/matrix.h" 18 | 19 | namespace heu::lib::numpy { 20 | 21 | class Random { 22 | public: 23 | static PMatrix RandInt(const phe::Plaintext &min, const phe::Plaintext &max, 24 | const Shape &size); 25 | 26 | static PMatrix RandBits(phe::SchemaType schema, size_t bits, 27 | const Shape &size); 28 | }; 29 | 30 | } // namespace heu::lib::numpy 31 | -------------------------------------------------------------------------------- /heu/library/numpy/test/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@yacl//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test") 16 | 17 | yacl_cc_library( 18 | name = "test_tools", 19 | hdrs = ["test_tools.h"], 20 | deps = ["//heu/library/numpy"], 21 | ) 22 | 23 | yacl_cc_test( 24 | name = "numpy_test", 25 | srcs = ["numpy_test.cc"], 26 | deps = [":test_tools"], 27 | ) 28 | 29 | yacl_cc_test( 30 | name = "matmul_test", 31 | srcs = ["matmul_test.cc"], 32 | deps = [":test_tools"], 33 | ) 34 | 35 | yacl_cc_test( 36 | name = "ic_test", 37 | srcs = ["ic_test.cc"], 38 | deps = [":test_tools"], 39 | ) 40 | -------------------------------------------------------------------------------- /heu/library/numpy/toolbox.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "heu/library/numpy/toolbox.h" 16 | 17 | namespace heu::lib::numpy { 18 | 19 | yacl::Buffer Toolbox::PMatrixToBytes(const PMatrix &pm, size_t bytes_per_int, 20 | algorithms::Endian endian) { 21 | yacl::Buffer res(bytes_per_int * pm.size()); 22 | auto *buf = res.data<unsigned char>(); 23 | int64_t cols = pm.cols(); 24 | pm.ForEach([&](int64_t row, int64_t col, const phe::Plaintext &pt) { 25 | // row major 26 | pt.ToBytes(buf + bytes_per_int * (row * cols + col), bytes_per_int, endian); 27 | }); 28 | return res; 29 | } 30 | 31 | } // namespace heu::lib::numpy 32 | -------------------------------------------------------------------------------- /heu/library/numpy/toolbox.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/numpy/matrix.h" 18 | 19 | namespace heu::lib::numpy { 20 | 21 | class Toolbox { 22 | public: 23 | static yacl::Buffer PMatrixToBytes(const PMatrix &pm, size_t bytes_per_int, 24 | algorithms::Endian endian); 25 | }; 26 | 27 | } // namespace heu::lib::numpy 28 | -------------------------------------------------------------------------------- /heu/library/phe/decryptor_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "gtest/gtest.h" 16 | 17 | #include "heu/library/phe/encoding/encoding.h" 18 | #include "heu/library/phe/phe.h" 19 | 20 | namespace heu::lib::phe::test { 21 | 22 | class DecryptorTest : public ::testing::Test { 23 | protected: 24 | HeKit he_kit_ = HeKit(SchemaType::OU, 2048); 25 | PlainEncoder edr_ = he_kit_.GetEncoder<PlainEncoder>(1); 26 | }; 27 | 28 | TEST_F(DecryptorTest, CheckRangeWorks) { 29 | auto pt = edr_.Encode(std::numeric_limits<uint64_t>::max()); 30 | auto ct = he_kit_.GetEncryptor()->Encrypt(pt); 31 | EXPECT_NO_THROW(he_kit_.GetDecryptor()->DecryptInRange(ct, 64)); 32 | 33 | he_kit_.GetEvaluator()->AddInplace(&ct, edr_.Encode(1)); 34 | EXPECT_ANY_THROW(he_kit_.GetDecryptor()->DecryptInRange(ct, 64)); 35 | } 36 | 37 | } // namespace heu::lib::phe::test 38 | -------------------------------------------------------------------------------- /heu/library/phe/encoding/coding.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <cstdint> 18 | #include <string> 19 | 20 | namespace heu::lib::phe { 21 | 22 | void EncodeFixed32(char *str, uint32_t value); 23 | 24 | void PutFixed32(std::string *str, uint32_t value); 25 | 26 | uint32_t DecodeFixed32(const char *data); 27 | 28 | } // namespace heu::lib::phe 29 | -------------------------------------------------------------------------------- /heu/library/phe/encoding/encoding.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/library/phe/encoding/batch_encoder.h" 18 | #include "heu/library/phe/encoding/plain_encoder.h" 19 | -------------------------------------------------------------------------------- /heu/library/phe/phe_test/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@yacl//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | test_suite( 20 | name = "phe_tests", 21 | ) 22 | 23 | yacl_cc_test( 24 | name = "batch_eval_test", 25 | srcs = ["batch_eval_test.cc"], 26 | deps = ["//heu/library/phe"], 27 | ) 28 | 29 | yacl_cc_test( 30 | name = "ser_test", 31 | srcs = ["ser_test.cc"], 32 | deps = ["//heu/library/phe"], 33 | ) 34 | -------------------------------------------------------------------------------- /heu/pylib/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from .version import __version__ # type: ignore 17 | from .heu import * 18 | 19 | __all__ = [ 20 | "__version__", 21 | ] 22 | -------------------------------------------------------------------------------- /heu/pylib/common/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@pybind11_bazel//:build_defs.bzl", "pybind_library") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | pybind_library( 20 | name = "traits", 21 | hdrs = ["traits.h"], 22 | deps = [ 23 | "//heu/library/phe", 24 | ], 25 | ) 26 | 27 | pybind_library( 28 | name = "py_utils", 29 | srcs = ["py_utils.cc"], 30 | hdrs = ["py_utils.h"], 31 | deps = [ 32 | "//heu/library/phe", 33 | "@yacl//yacl/base:int128", 34 | ], 35 | ) 36 | -------------------------------------------------------------------------------- /heu/pylib/common/traits.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "pybind11/pybind11.h" 18 | 19 | #include "heu/library/phe/phe.h" 20 | 21 | namespace heu::pylib { 22 | 23 | namespace py = ::pybind11; 24 | namespace phe = ::heu::lib::phe; 25 | namespace hnp = ::heu::lib::numpy; 26 | 27 | inline constexpr int64_t kHeOpGrainSize = 1; 28 | 29 | } // namespace heu::pylib 30 | -------------------------------------------------------------------------------- /heu/pylib/exported_symbols.lds: -------------------------------------------------------------------------------- 1 | _PyInit_* 2 | -------------------------------------------------------------------------------- /heu/pylib/numpy_binding/bind_numpy.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "pybind11/pybind11.h" 18 | 19 | namespace heu::pylib { 20 | 21 | void PyBindNumpy(pybind11::module &m); 22 | 23 | } // namespace heu::pylib 24 | -------------------------------------------------------------------------------- /heu/pylib/numpy_binding/py_slicer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "pybind11/pybind11.h" 18 | 19 | #include "heu/library/numpy/evaluator.h" 20 | #include "heu/library/numpy/matrix.h" 21 | 22 | // These functions deal with slicing from python. 23 | 24 | namespace heu::pylib { 25 | 26 | template <typename T> 27 | class PySlicer { 28 | public: 29 | static pybind11::object GetItem(const lib::numpy::DenseMatrix<T> &p_matrix, 30 | const pybind11::object &key); 31 | static void SetItem(lib::numpy::DenseMatrix<T> *p_matrix, 32 | const pybind11::object &key, 33 | const pybind11::object &value); 34 | }; 35 | 36 | } // namespace heu::pylib 37 | -------------------------------------------------------------------------------- /heu/pylib/phe_binding/bind_phe.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "pybind11/pybind11.h" 18 | 19 | namespace heu::pylib { 20 | 21 | void PyBindPhe(pybind11::module &m); 22 | 23 | } // namespace heu::pylib 24 | -------------------------------------------------------------------------------- /heu/pylib/phe_binding/py_encoders.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/pylib/phe_binding/py_batch_encoder.h" 18 | #include "heu/pylib/phe_binding/py_bigint_encoder.h" 19 | #include "heu/pylib/phe_binding/py_float_encoder.h" 20 | #include "heu/pylib/phe_binding/py_integer_encoder.h" 21 | -------------------------------------------------------------------------------- /heu/pylib/version.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | __version__ = "0.6.0b0" 17 | -------------------------------------------------------------------------------- /heu/pylib/version_script.lds: -------------------------------------------------------------------------------- 1 | VERS_1.0 { 2 | # Export symbols in pybind. 3 | global: 4 | PyInit_*; 5 | 6 | # Hide everything else. 7 | local: 8 | *; 9 | }; 10 | -------------------------------------------------------------------------------- /heu/spi/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@yacl//bazel:yacl.bzl", "yacl_cc_library") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | # A collection of SPI and all Libs. 20 | yacl_cc_library( 21 | name = "spi", 22 | deps = [ 23 | # This is the ONLY place where SPI needs to rely on implementation libraries. 24 | # SPI rules do not allow dependence on implementation libraries anywhere else. 25 | "//heu/algorithms", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /heu/spi/auto_test/README.md: -------------------------------------------------------------------------------- 1 | # Auto-test Module 2 | 3 | An automated testing framework for testing all libraries integrated into SPI 4 | 5 | 一个自动化测试框架,用于测试所有 LIB 6 | -------------------------------------------------------------------------------- /heu/spi/he/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/spi/he/item.h" 18 | 19 | namespace heu::spi { 20 | 21 | class Decryptor { 22 | public: 23 | virtual ~Decryptor() = default; 24 | 25 | // CT -> PT 26 | // CTs -> PTs 27 | virtual void Decrypt(const Item &ct, Item *out) const = 0; 28 | virtual Item Decrypt(const Item &ct) const = 0; 29 | }; 30 | 31 | } // namespace heu::spi 32 | -------------------------------------------------------------------------------- /heu/spi/he/he.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | // This is the entry point of HE SPI 18 | // The 'he_kit.h' defines all the necessary classes and interfaces. 19 | // The 'he_configs.h' defines all the configurations needed for initializing 20 | // HeKit. 21 | 22 | #include "heu/spi/he/factory.h" 23 | #include "heu/spi/he/he_configs.h" 24 | #include "heu/spi/he/he_kit.h" 25 | -------------------------------------------------------------------------------- /heu/spi/he/sketches/scalar/decryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/spi/he/decryptor.h" 18 | #include "heu/spi/he/sketches/scalar/helpful_macros.h" 19 | 20 | namespace heu::spi { 21 | 22 | template <typename PlaintextT, typename CiphertextT> 23 | class DecryptorScalarSketch : public Decryptor { 24 | public: 25 | virtual void Decrypt(const CiphertextT &ct, PlaintextT *out) const = 0; 26 | virtual PlaintextT Decrypt(const CiphertextT &ct) const = 0; 27 | 28 | private: 29 | DefineUnaryFuncCStyle(Decrypt, CiphertextT, PlaintextT); 30 | DefineUnaryFuncCT(Decrypt); 31 | }; 32 | 33 | } // namespace heu::spi 34 | -------------------------------------------------------------------------------- /heu/spi/he/sketches/scalar/phe/encryptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/spi/he/sketches/scalar/encryptor.h" 18 | 19 | namespace heu::spi { 20 | 21 | template <typename PlaintextT, typename CiphertextT> 22 | class PheEncryptorScalarSketch 23 | : public EncryptorScalarSketch<PlaintextT, CiphertextT> { 24 | public: 25 | CiphertextT SemiEncrypt(const PlaintextT &plaintext) const override { 26 | return this->Encrypt(plaintext); 27 | } 28 | }; 29 | 30 | } // namespace heu::spi 31 | -------------------------------------------------------------------------------- /heu/spi/poly/ntt_op.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "heu/spi/poly/poly_def.h" 18 | 19 | namespace heu::spi { 20 | 21 | // Performs nega-cyclic forward and inverse number-theoretic transform (NTT) 22 | // nega-cyclic means polynomial is mod by (X^N + 1) 23 | class NttOperator { 24 | public: 25 | virtual ~NttOperator() = default; 26 | 27 | //=== (Batched) NTT Operations ===// 28 | virtual Polys Forward(const Polys &Polys_in) const = 0; 29 | virtual void ForwardInplace(Polys *Polys) const = 0; 30 | 31 | virtual Polys Inverse(const Polys &Polys_in) const = 0; 32 | virtual void InverseInplace(Polys *Polys) const = 0; 33 | }; 34 | 35 | } // namespace heu::spi 36 | -------------------------------------------------------------------------------- /heu/spi/poly/poly_def.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <cstdint> 18 | #include <vector> 19 | 20 | namespace heu::spi { 21 | 22 | class Poly : public std::vector<uint64_t> { 23 | public: 24 | using std::vector<uint64_t>::vector; 25 | }; 26 | 27 | // Polys can store a batch of independent Polys, or sub-polynomials decomposed 28 | // by RNS. 29 | class Polys { 30 | public: 31 | // add public functions here 32 | private: 33 | std::vector<Poly> polys_; 34 | }; 35 | 36 | using Moduli = std::vector<uint64_t>; 37 | 38 | using RnsPoly = Polys; 39 | 40 | } // namespace heu::spi 41 | -------------------------------------------------------------------------------- /heu/spi/utils/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@yacl//bazel:yacl.bzl", "yacl_cc_library") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | yacl_cc_library( 20 | name = "math_tool", 21 | hdrs = ["math_tool.h"], 22 | ) 23 | 24 | yacl_cc_library( 25 | name = "formater", 26 | hdrs = ["formater.h"], 27 | deps = [ 28 | "@abseil-cpp//absl/types:span", 29 | "@fmt", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /heu/spi/utils/math_tool.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Ant Group Co., Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include <cstdint> 18 | 19 | namespace heu::spi::utils { 20 | 21 | inline bool IsPowerOf2(uint64_t x) { return (x != 0) && !(x & (x - 1)); } 22 | 23 | } // namespace heu::spi::utils 24 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | skip-string-normalization = true 3 | 4 | [tool.isort] 5 | profile = "black" 6 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy>=1.22.0 2 | -------------------------------------------------------------------------------- /third_party/bazel_cpp/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | package(default_visibility = ["//visibility:public"]) 16 | 17 | config_setting( 18 | name = "heu_build_as_release", 19 | values = {"compilation_mode": "opt"}, 20 | ) 21 | 22 | config_setting( 23 | name = "heu_build_as_debug", 24 | values = {"compilation_mode": "dbg"}, 25 | ) 26 | 27 | config_setting( 28 | name = "heu_build_as_fast", 29 | values = {"compilation_mode": "fastbuild"}, 30 | ) 31 | -------------------------------------------------------------------------------- /third_party/bazel_cpp/cereal.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | filegroup( 20 | name = "all", 21 | srcs = glob(["**"]), 22 | ) 23 | 24 | cmake( 25 | name = "cereal", 26 | cache_entries = { 27 | "BUILD_DOC": "OFF", 28 | "BUILD_TESTS": "OFF", 29 | "BUILD_SANDBOX": "OFF", 30 | "SKIP_PERFORMANCE_COMPARISON": "ON", 31 | }, 32 | lib_source = ":all", 33 | out_headers_only = True, 34 | ) 35 | -------------------------------------------------------------------------------- /third_party/bazel_cpp/cgbn.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_cuda//cuda:defs.bzl", "cuda_library") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | cuda_library( 20 | name = "arith", 21 | srcs = [], 22 | hdrs = glob([ 23 | "include/cgbn/arith/*.h", 24 | "include/cgbn/arith/*.cuh", 25 | ]), 26 | ) 27 | 28 | cuda_library( 29 | name = "core", 30 | srcs = [], 31 | hdrs = glob([ 32 | "include/cgbn/core/*.cuh", 33 | ]), 34 | ) 35 | 36 | cuda_library( 37 | name = "cgbn", 38 | srcs = [], 39 | hdrs = glob([ 40 | "include/cgbn/*.h", 41 | "include/cgbn/*.cuh", 42 | ]), 43 | deps = [ 44 | ":arith", 45 | ":core", 46 | ], 47 | ) 48 | -------------------------------------------------------------------------------- /third_party/bazel_cpp/fmtlib.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "configure_make") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | filegroup( 20 | name = "all_srcs", 21 | srcs = glob(["**"]), 22 | ) 23 | 24 | cmake( 25 | name = "fmtlib", 26 | build_args = ["-j"], 27 | cache_entries = { 28 | "FMT_TEST": "OFF", 29 | }, 30 | defines = ["FMT_HEADER_ONLY"], 31 | lib_source = ":all_srcs", 32 | out_headers_only = True, 33 | ) 34 | -------------------------------------------------------------------------------- /third_party/bazel_cpp/ipp.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | filegroup( 20 | name = "all_srcs", 21 | srcs = glob(["**"]), 22 | ) 23 | 24 | cmake( 25 | name = "ipp", 26 | cache_entries = { 27 | "ARCH": "intel64", 28 | "OPENSSL_INCLUDE_DIR": "$EXT_BUILD_DEPS/openssl/include", 29 | "OPENSSL_LIBRARIES": "$EXT_BUILD_DEPS/openssl/lib", 30 | "OPENSSL_ROOT_DIR": "$EXT_BUILD_DEPS/openssl", 31 | "CMAKE_BUILD_TYPE": "Release", 32 | }, 33 | generate_args = ["-G Ninja"], 34 | lib_source = ":all_srcs", 35 | out_static_libs = [ 36 | "intel64/libippcp.a", 37 | "intel64/libcrypto_mb.a", 38 | ], 39 | deps = [ 40 | "@openssl//:crypto", 41 | ], 42 | ) 43 | -------------------------------------------------------------------------------- /third_party/bazel_cpp/seal.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Ant Group Co., Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | filegroup( 20 | name = "all", 21 | srcs = glob(["**"]), 22 | ) 23 | 24 | cmake( 25 | name = "seal", 26 | cache_entries = { 27 | "SEAL_USE_MSGSL": "OFF", 28 | "SEAL_BUILD_DEPS": "OFF", 29 | "SEAL_USE_ZSTD": "OFF", 30 | "SEAL_USE_ZLIB": "OFF", 31 | "SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT": "OFF", 32 | "CMAKE_INSTALL_LIBDIR": "lib", 33 | }, 34 | lib_source = "@seal//:all", 35 | out_include_dir = "include/SEAL-3.6", 36 | out_static_libs = ["libseal-3.6.a"], 37 | deps = ["@zlib"], 38 | ) 39 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/BUILD.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze generated Bazel file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # Export file for Stardoc support 9 | exports_files( 10 | [ 11 | "crates.bzl", 12 | ], 13 | visibility = ["//visibility:public"], 14 | ) 15 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.adler-1.0.2.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "0BSD OR (MIT OR Apache-2.0)" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | # Unsupported target "bench" with type "bench" omitted 35 | 36 | rust_library( 37 | name = "adler", 38 | srcs = glob(["**/*.rs"]), 39 | crate_features = [ 40 | ], 41 | crate_root = "src/lib.rs", 42 | data = [], 43 | edition = "2015", 44 | rustc_flags = [ 45 | "--cap-lints=allow", 46 | ], 47 | tags = [ 48 | "cargo-raze", 49 | "crate-name=adler", 50 | "manual", 51 | ], 52 | version = "1.0.2", 53 | # buildifier: leave-alone 54 | deps = [ 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.bazel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secretflow/heu/e89140faaf5c295ac8c28d32c0b427e92251aff0/third_party/bazel_rust/cargo/remote/BUILD.bazel -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.bincode-1.3.3.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "bincode", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2015", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=bincode", 48 | "manual", 49 | ], 50 | version = "1.3.3", 51 | # buildifier: leave-alone 52 | deps = [ 53 | "@rust__serde__1_0_130//:serde", 54 | ], 55 | ) 56 | 57 | # Unsupported target "test" with type "test" omitted 58 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.cfg-if-1.0.0.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "cfg_if", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=cfg-if", 48 | "manual", 49 | ], 50 | version = "1.0.0", 51 | # buildifier: leave-alone 52 | deps = [ 53 | ], 54 | ) 55 | 56 | # Unsupported target "xcrate" with type "test" omitted 57 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.cipher-0.2.5.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "cipher", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=cipher", 48 | "manual", 49 | ], 50 | version = "0.2.5", 51 | # buildifier: leave-alone 52 | deps = [ 53 | "@rust__generic_array__0_14_4//:generic_array", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.concrete-npe-0.1.9.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "restricted", # BSD-3-Clause-Clear from expression "BSD-3-Clause-Clear" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "concrete_npe", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=concrete-npe", 48 | "manual", 49 | ], 50 | version = "0.1.9", 51 | # buildifier: leave-alone 52 | deps = [ 53 | "@rust__itertools__0_9_0//:itertools", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.criterion-plot-0.4.4.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "criterion_plot", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=criterion-plot", 48 | "manual", 49 | ], 50 | version = "0.4.4", 51 | # buildifier: leave-alone 52 | deps = [ 53 | "@rust__cast__0_2_7//:cast", 54 | "@rust__itertools__0_10_3//:itertools", 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.cxxbridge-flags-1.0.65.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "cxxbridge_flags", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | "default", 39 | ], 40 | crate_root = "src/lib.rs", 41 | data = [], 42 | edition = "2018", 43 | rustc_flags = [ 44 | "--cap-lints=allow", 45 | ], 46 | tags = [ 47 | "cargo-raze", 48 | "crate-name=cxxbridge-flags", 49 | "manual", 50 | ], 51 | version = "1.0.65", 52 | # buildifier: leave-alone 53 | deps = [ 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.either-1.6.1.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "either", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2015", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=either", 48 | "manual", 49 | ], 50 | version = "1.6.1", 51 | # buildifier: leave-alone 52 | deps = [ 53 | ], 54 | ) 55 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.half-1.8.2.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | # Unsupported target "convert" with type "bench" omitted 35 | 36 | rust_library( 37 | name = "half", 38 | srcs = glob(["**/*.rs"]), 39 | crate_features = [ 40 | ], 41 | crate_root = "src/lib.rs", 42 | data = [], 43 | edition = "2018", 44 | rustc_flags = [ 45 | "--cap-lints=allow", 46 | ], 47 | tags = [ 48 | "cargo-raze", 49 | "crate-name=half", 50 | "manual", 51 | ], 52 | version = "1.8.2", 53 | # buildifier: leave-alone 54 | deps = [ 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.hermit-abi-0.1.19.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "hermit_abi", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | "default", 39 | ], 40 | crate_root = "src/lib.rs", 41 | data = [], 42 | edition = "2018", 43 | rustc_flags = [ 44 | "--cap-lints=allow", 45 | ], 46 | tags = [ 47 | "cargo-raze", 48 | "crate-name=hermit-abi", 49 | "manual", 50 | ], 51 | version = "0.1.19", 52 | # buildifier: leave-alone 53 | deps = [ 54 | "@rust__libc__0_2_109//:libc", 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.instant-0.1.12.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # BSD-3-Clause from expression "BSD-3-Clause" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "instant", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=instant", 48 | "manual", 49 | ], 50 | version = "0.1.12", 51 | # buildifier: leave-alone 52 | deps = [ 53 | "@rust__cfg_if__1_0_0//:cfg_if", 54 | ], 55 | ) 56 | 57 | # Unsupported target "wasm" with type "test" omitted 58 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.num_cpus-1.13.0.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | # Unsupported target "values" with type "example" omitted 35 | 36 | rust_library( 37 | name = "num_cpus", 38 | srcs = glob(["**/*.rs"]), 39 | crate_features = [ 40 | ], 41 | crate_root = "src/lib.rs", 42 | data = [], 43 | edition = "2015", 44 | rustc_flags = [ 45 | "--cap-lints=allow", 46 | ], 47 | tags = [ 48 | "cargo-raze", 49 | "crate-name=num_cpus", 50 | "manual", 51 | ], 52 | version = "1.13.0", 53 | # buildifier: leave-alone 54 | deps = [ 55 | "@rust__libc__0_2_109//:libc", 56 | ], 57 | ) 58 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.oorandom-11.1.3.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "oorandom", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=oorandom", 48 | "manual", 49 | ], 50 | version = "11.1.3", 51 | # buildifier: leave-alone 52 | deps = [ 53 | ], 54 | ) 55 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.opaque-debug-0.3.0.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "opaque_debug", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=opaque-debug", 48 | "manual", 49 | ], 50 | version = "0.3.0", 51 | # buildifier: leave-alone 52 | deps = [ 53 | ], 54 | ) 55 | 56 | # Unsupported target "mod" with type "test" omitted 57 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.plotters-backend-0.3.2.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "plotters_backend", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=plotters-backend", 48 | "manual", 49 | ], 50 | version = "0.3.2", 51 | # buildifier: leave-alone 52 | deps = [ 53 | ], 54 | ) 55 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.plotters-svg-0.3.1.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "plotters_svg", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=plotters-svg", 48 | "manual", 49 | ], 50 | version = "0.3.1", 51 | # buildifier: leave-alone 52 | deps = [ 53 | "@rust__plotters_backend__0_3_2//:plotters_backend", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.regex-automata-0.1.10.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "unencumbered", # Unlicense from expression "Unlicense OR MIT" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "regex_automata", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2015", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=regex-automata", 48 | "manual", 49 | ], 50 | version = "0.1.10", 51 | # buildifier: leave-alone 52 | deps = [ 53 | ], 54 | ) 55 | 56 | # Unsupported target "default" with type "test" omitted 57 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.regex-syntax-0.6.25.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | # Unsupported target "bench" with type "bench" omitted 35 | 36 | rust_library( 37 | name = "regex_syntax", 38 | srcs = glob(["**/*.rs"]), 39 | crate_features = [ 40 | ], 41 | crate_root = "src/lib.rs", 42 | data = [], 43 | edition = "2018", 44 | rustc_flags = [ 45 | "--cap-lints=allow", 46 | ], 47 | tags = [ 48 | "cargo-raze", 49 | "crate-name=regex-syntax", 50 | "manual", 51 | ], 52 | version = "0.6.25", 53 | # buildifier: leave-alone 54 | deps = [ 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.rustc-demangle-0.1.21.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "rustc_demangle", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2015", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=rustc-demangle", 48 | "manual", 49 | ], 50 | version = "0.1.21", 51 | # buildifier: leave-alone 52 | deps = [ 53 | ], 54 | ) 55 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.scopeguard-1.1.0.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | # Unsupported target "readme" with type "example" omitted 35 | 36 | rust_library( 37 | name = "scopeguard", 38 | srcs = glob(["**/*.rs"]), 39 | crate_features = [ 40 | ], 41 | crate_root = "src/lib.rs", 42 | data = [], 43 | edition = "2015", 44 | rustc_flags = [ 45 | "--cap-lints=allow", 46 | ], 47 | tags = [ 48 | "cargo-raze", 49 | "crate-name=scopeguard", 50 | "manual", 51 | ], 52 | version = "1.1.0", 53 | # buildifier: leave-alone 54 | deps = [ 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.strsim-0.10.0.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | # Unsupported target "benches" with type "bench" omitted 35 | 36 | rust_library( 37 | name = "strsim", 38 | srcs = glob(["**/*.rs"]), 39 | crate_features = [ 40 | ], 41 | crate_root = "src/lib.rs", 42 | data = [], 43 | edition = "2015", 44 | rustc_flags = [ 45 | "--cap-lints=allow", 46 | ], 47 | tags = [ 48 | "cargo-raze", 49 | "crate-name=strsim", 50 | "manual", 51 | ], 52 | version = "0.10.0", 53 | # buildifier: leave-alone 54 | deps = [ 55 | ], 56 | ) 57 | 58 | # Unsupported target "lib" with type "test" omitted 59 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.time-macros-0.2.3.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_proc_macro( 35 | name = "time_macros", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2018", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=time-macros", 48 | "manual", 49 | ], 50 | version = "0.2.3", 51 | # buildifier: leave-alone 52 | deps = [ 53 | ], 54 | ) 55 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.unicode-width-0.1.9.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "unicode_width", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | "default", 39 | ], 40 | crate_root = "src/lib.rs", 41 | data = [], 42 | edition = "2015", 43 | rustc_flags = [ 44 | "--cap-lints=allow", 45 | ], 46 | tags = [ 47 | "cargo-raze", 48 | "crate-name=unicode-width", 49 | "manual", 50 | ], 51 | version = "0.1.9", 52 | # buildifier: leave-alone 53 | deps = [ 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /third_party/bazel_rust/cargo/remote/BUILD.version_check-0.9.3.bazel: -------------------------------------------------------------------------------- 1 | """ 2 | @generated 3 | cargo-raze crate build file. 4 | 5 | DO NOT EDIT! Replaced on runs of cargo-raze 6 | """ 7 | 8 | # buildifier: disable=load 9 | load("@bazel_skylib//lib:selects.bzl", "selects") 10 | 11 | # buildifier: disable=load 12 | load( 13 | "@rules_rust//rust:defs.bzl", 14 | "rust_binary", 15 | "rust_library", 16 | "rust_proc_macro", 17 | "rust_test", 18 | ) 19 | 20 | package(default_visibility = [ 21 | # Public for visibility by "@raze__crate__version//" targets. 22 | # 23 | # Prefer access through "//third_party/bazel_rust/cargo", which limits external 24 | # visibility to explicit Cargo.toml dependencies. 25 | "//visibility:public", 26 | ]) 27 | 28 | licenses([ 29 | "notice", # MIT from expression "MIT OR Apache-2.0" 30 | ]) 31 | 32 | # Generated Targets 33 | 34 | rust_library( 35 | name = "version_check", 36 | srcs = glob(["**/*.rs"]), 37 | crate_features = [ 38 | ], 39 | crate_root = "src/lib.rs", 40 | data = [], 41 | edition = "2015", 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-raze", 47 | "crate-name=version_check", 48 | "manual", 49 | ], 50 | version = "0.9.3", 51 | # buildifier: leave-alone 52 | deps = [ 53 | ], 54 | ) 55 | --------------------------------------------------------------------------------