secretflow / heu

A high-performance homomorphic encryption algorithm library.
https://www.secretflow.org.cn/docs/heu/en/
Apache License 2.0
83 stars 39 forks source link

增加secret_key构建hekit接口 #106

Closed tarantula-leo closed 8 months ago

tarantula-leo commented 9 months ago

目前可从公钥构造destinationhekit,得到evaluator、encryptor,但在仅有sk场景下(实际使用中只会对sk/pk进行序列化,不会对hekit做序列化),无法构造hekit对密文进行解密; 可类似地提供如下接口:

setup(public_key: heu.heu.phe.SecretKey) -> heu.heu.phe.xxxHeKit
# Setup phe environment by an already generated secret key.
decryptor(self: [heu.heu.phe.xxxHeKit] → heu::lib::phe::Decryptor
# Get decryptor
usafchn commented 9 months ago

好的,我们加一个从 sk 恢复 HeKit 的接口

tarantula-leo commented 9 months ago
  1. 增加完成是否可以提供wheel包下载/pip更新?
  2. pk_buffer的接口在python中是否未开放:
    
    DestinationHeKit::DestinationHeKit(std::shared_ptr<PublicKey> pk) {
    Setup(std::move(pk));
    public_key_->Visit(HE_DISPATCH(HE_SPECIAL_SETUP_BY_PK));
    }

DestinationHeKit::DestinationHeKit(yacl::ByteContainerView pk_buffer) { auto pk = std::make_shared(); pk->Deserialize(pk_buffer); Setup(std::move(pk)); publickey->Visit(HE_DISPATCH(HE_SPECIAL_SETUP_BY_PK)); }

} // namespace heu::lib::phe

usafchn commented 9 months ago
  1. 增加完成是否可以提供wheel包下载/pip更新?
  2. pk_buffer的接口在python中是否未开放:
  1. 会提供
  2. Python 中直接 kit = phe.setup(pickle.loads(pk_buffer))
tarantula-leo commented 9 months ago

DestinationHeKit::DestinationHeKit(yacl::ByteContainerView pk_buffer) 这个接口是在哪里会调用的?

usafchn commented 9 months ago

@tarantula-leo 这个是开放给 C++ 应用的接口,如果是 Python 侧过来的请求不会用到这个接口

usafchn commented 9 months ago

@tarantula-leo

Pip 包 https://pypi.org/project/sf-heu/0.5.0.dev20231128/

tarantula-leo commented 9 months ago

看merge的内容,是通过pk和sk恢复Hekit,如果对于Decryptor的单独使用,是不是只需要sk就可以?是否会考虑增加一个单独的HeKit类,类似DestinationHekit供Encryptor/Evaluator使用。

usafchn commented 9 months ago

看merge的内容,是通过pk和sk恢复Hekit,如果对于Decryptor的单独使用,是不是只需要sk就可以?是否会考虑增加一个单独的HeKit类,类似DestinationHekit供Encryptor/Evaluator使用。

这个不考虑,有些算法的 decrypt 依赖 pk 中的内容,所以 HEU 构造 Decryptor 的时候默认需要传入 pk 和 sk,上层多传一个 pk 应该不困难吧?