ITADN
google/heir
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

HEIR:同态加密中间表示

GitHub Workflow Status (with event) GitHub Contributors GitHub Discussions GitHub License OpenSSF Scorecard

基于 MLIR 的工具链,用于 同态加密](https://en.wikipedia.org/wiki/Homomorphic_encryption) 编译器。请在 HEIR 网站 阅读文档。

有关 MLIR 的更多信息,请参阅 MLIR 主页

快速入门 (Python)

通过 Pip 安装 heir_py

pip install heir_py

然后运行一个示例:

from heir import compile
from heir.mlir import I64, Secret

@compile()  # defaults to scheme="bgv", OpenFHE backend, and debug=False
def func(x: Secret[I64], y: Secret[I64]):
    sum = x + y
    diff = x - y
    mul = x * y
    expression = sum * diff + mul
    deadcode = expression * mul
    return expression

func.setup()
enc_x = func.encrypt_x(7)
enc_y = func.encrypt_y(8)
result_enc = func.eval(enc_x, enc_y)
result = func.decrypt_result(result_enc)

print(
  f"Expected result for `func`: {func.original(7,8)}, FHE result:"
  f" {result}"
)

这将使用 BGV 方案通过 OpenFHE 后端将上述函数编译为机器代码。 然后调用该函数将加密输入、运行函数并返回解密后的结果。函数调用 foo(7, 8) 运行完整的 加密-运行-解密流程,以便于测试。

从源代码构建

本项目使用 bazel 作为其构建系统。安装 bazelisk 以自动管理 bazel 版本。 然后,在路径中配置 bazel(指向 bazelisk),运行 以下命令以构建主要的 pass 运行工具。

bazel build //tools:heir-opt

或者运行一个端到端测试,例如

bazel test //tests/Examples/openfhe/ckks/halevi_shoup_matvec:all

HEIR 依赖于 LLVM(从源码构建),因此干净的构建可能需要 30 分钟,具体取决于您的机器。为了加快构建速度,请使用 BuildBuddy。注册一个账户,创建一个 API 密钥,并将以下内容添加到 HEIR 工作区根目录中的 .bazelrc.user

common --remote_header=x-buildbuddy-api-key=<YOUR_API_KEY>
common --config=remote

这应将一次干净构建的时间缩短至约 5 分钟。

请参阅 bazel 技巧 页面,以获取更多 示例命令以及使用 bazel 的技巧。

支持的后端和方案

后端库BGVBFVCKKSCGGI
OpenFHE
Lattigo
tfhe-rs
Jaxite

请注意,某些后端不支持所有方案。

贡献

有许多方式可以为 HEIR 做出贡献:

引用

HEIR 项目可以通过以下条目在学术工作中被引用:

@misc{ali2025heir,
      title={HEIR: A Universal Compiler for Homomorphic Encryption},
      author={Asra Ali and Jaeho Choi and Bryant Gipson and Shruthi Gorantala
              and Jeremy Kun and Wouter Legiest and Lawrence Lim and Alexander
              Viand and Meron Zerihun Demissie and Hongren Zheng},
      year={2025},
      eprint={2508.11095},
      archivePrefix={arXiv},
      primaryClass={cs.CR},
      url={https://arxiv.org/abs/2508.11095},
}

支持免责声明

这不是 Google 官方支持的产品。