9

阈值PSI代码 - PamShao

 2 years ago
source link: https://www.cnblogs.com/pam-sh/p/16479540.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

阈值PSI

若交集数量超过某个给定阈值时,允许分布式的各个参与方在自己集合中找到交集,且除了交集外,得不到其他额外信息。

实现论文: Multi-Party Threshold Private Set Intersection with Sublinear Communication

源码地址:https://github.com/ontanj/tpsi

其中FTPSI−intFTPSI−int做出部分修改,因为基于TFHE无法实现自举(bootstrapping)技术。

用到的加密算法:

TAHETAHE:Paillier-https://github.com/niclabs/tcpaillier

TFHETFHE:BFV-https://github.com/ldsec/lattigo

接口:

(1)AHE_CryptosystemFHE_Cryptosystem实现同态运算

type AHE_Cryptosystem interface {

    // 密文+密文
    Add(Ciphertext, Ciphertext) (sum Ciphertext, err error)

    // 密文^{明文}
    Scale(cipher Ciphertext, factor *big.Int) (product Ciphertext, err error)
    
    // 加密
    Encrypt(*big.Int) (Ciphertext, error)

    // 聚合明文
    CombinePartials([]Partial_decryption) (*big.Int, error)

    // 计算加密矩阵
    EvaluationSpace() gm.Space

    // 明文空间大小
    N() *big.Int
}
type FHE_Cryptosystem interface {
    AHE_Cryptosystem

    // 密文*密文
    Multiply(Ciphertext, Ciphertext) (Ciphertext, error)
}

(2)AHE_settingFHE_setting包含参与方数量、阈值大小和通信方式

type AHE_setting interface {
	// 阈值
	Threshold() int

	// 参与方
	Parties() int

	// AHE
	AHE_cryptosystem() AHE_Cryptosystem

	// central方发布消息给其他方
	Distribute(interface{})

	// 其他方给central方传递消息
	Send(interface{})

	// central方给指定方发送消息
	SendTo(int, interface{})

	// central方等待来其他方的消息,并将其(按顺序)分组
	ReceiveAll() []interface{}

	// 接手central方的消息
	Receive() interface{}

	// 判断是否为central方
	IsCentral() bool
}
type FHE_setting interface {
	AHE_setting

	// FHE
	FHE_cryptosystem() FHE_Cryptosystem
}

本实验是在一台机器上模拟多方通信,通过goroutine实现。

goroutine:在go语言中,每一个并发的执行单元叫做goroutine,如果一个程序中包含多个goroutine,对两个函数的调用则可能发生在同一时刻。

运行:

go run main/main.go diff dj 7 main/elements

其中FTPSI-diff使用的是TAHE,阈值为7。

功能:

(1)TPSIdiffWorker,在交集测试下求交集和差集

(2)TPSIintWorker:在差集测试下求交集和差集

image

测试:

P1:0,3,6,9,13,16
P2:0,3,6,9,14,17
P3:0,3,6,9,14,15
P4:0,3,6,9,12,17
P5:0,3,6,9,13,15

T=7

//交集大时用TFHE求
go run main/main.go int bfv 7 main/elements
//差集小时用TAHE求
go run main/main.go diff dj 7 main/elements
//差集小时用TFHE求
go run main/main.go diff bfv 7 main/elements
s/秒 int diff
TFHE 515.532007 2391.952714
TAHE / 26.436323

总结
用FHE实现,效率是显而易见的!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK