tpsi

package module
v0.0.0-...-57f3735 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

README

Threshold Private Set Intersection

This projects provides implementations of FTPSI-diff using AHE and FTPSI-int described in Multi-Party Threshold Private Set Intersection with Sublinear Communication by Badrinarayanan, Miao and Rindal. However FTPSI-int is slightly modified as bootstrapping was not enable in the cryptosystem used. Threshold Private Set Intersection allows multiple distrustful parties find the intersection of the respective sets, if this intersection exceeds a given threshold, without revealing what is not in the intersection.

Cryptosystems

The protocol used Paillier Threshold Encryption Scheme Implementation for the additive homomorphic part and Lattigo for the fully homomorphic part. However the implementations builds on the interfaces AHE_Cryptosystem and FHE_Cryptosystem which allows the use of any implementation satisfying the homomorphic properties.

Setting

The setting is described by the interfaces AHE_setting and FHE_setting which contains the number of parties, the threshold value and means of communication. This implementation has only been run on a single machine with parties modelled as goroutines. However by creating a new setting, network communication should be easily achieved.

Usage

The basic functionalities are implemented in TPSIdiffWorker and TPSIintWorker.

A simple example application is provided and can be run as go run main/main.go diff dj 7 main/elements, which runs FTPSI-diff using the Damgård-Jurik cryptosystem provided in Paillier Threshold Encryption Scheme Implementation, with a threshold value of 7.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CPComputeHankelMatrix

func CPComputeHankelMatrix(items []*big.Int, u *big.Int, setting AHE_setting) (H gm.Matrix, err error)

compute the encrypted Hankel Matrix for central party

func CentralASSWorker

func CentralASSWorker(a Ciphertext, sk Secret_key, setting AHE_setting) *big.Int

func CentralBFVEncryptionGenerator

func CentralBFVEncryptionGenerator(channels []chan interface{}) (BFV_encryption, BFV_secret_key)

func CentralCardinalityTestWorker

func CentralCardinalityTestWorker(items []*big.Int, sk Secret_key, setting AHE_setting) bool

returns true if number of elements not shared by all is <= setting.Threshold()

func CentralDecryptionWorker

func CentralDecryptionWorker(cipher Ciphertext, sk Secret_key, setting AHE_setting) *big.Int

func CentralFHECardinalityTestWorker

func CentralFHECardinalityTestWorker(items []*big.Int, sk Secret_key, setting FHE_setting) bool

returns true if cardinality test passes

func CentralHankelMatrix

func CentralHankelMatrix(items []*big.Int, sk Secret_key, setting AHE_setting) gm.Matrix

func CentralIntersectionPolyWorker

func CentralIntersectionPolyWorker(root_poly gm.Matrix, sk Secret_key, setting AHE_setting) (gm.Matrix, gm.Matrix)

step 3 of TPSI-diff

func CentralMatrixMultiplicationWorker

func CentralMatrixMultiplicationWorker(a, b gm.Matrix, sk Secret_key, setting AHE_setting) gm.Matrix

func CentralMinPolyWorker

func CentralMinPolyWorker(seq gm.Matrix, rec_ord int, sk Secret_key, setting AHE_setting) (gm.Matrix, gm.Matrix)

func CentralSingularityTestWorker

func CentralSingularityTestWorker(m gm.Matrix, sk Secret_key, setting AHE_setting) bool

returns true if m is singular

func CentralZeroTestWorker

func CentralZeroTestWorker(a Ciphertext, sk Secret_key, setting AHE_setting) bool

func CombineMatrixMultiplication

func CombineMatrixMultiplication(MA_enc, MB_enc gm.Matrix, MAis, MBis []gm.Matrix, ctis []gm.Matrix, setting AHE_setting) (AB gm.Matrix, err error)

step 4 of MMult

func CombineMatrixShares

func CombineMatrixShares(part_mat []gm.Matrix, enc_mat gm.Matrix, setting AHE_setting) (decrypted gm.Matrix, err error)

combine partial matrix decryptions to receive plaintext matrix

func ComputeHankelMatrix

func ComputeHankelMatrix(items []*big.Int, u *big.Int, setting AHE_setting) (gm.Matrix, error)

compute and encrypt the Hankel Matrix for items and (random) u.

func ComputePlainHankelMatrix

func ComputePlainHankelMatrix(items []*big.Int, u *big.Int, setting AHE_setting) gm.Matrix

compute the Hankel Matrix for items and (random) u.

func DecodeElements

func DecodeElements(elements []*big.Int) []*big.Int

func EncodeElements

func EncodeElements(elements []*big.Int) []*big.Int

func EncryptMatrix

func EncryptMatrix(a gm.Matrix, setting AHE_setting) (b gm.Matrix, err error)

encrypt matrix item-wise

func EncryptedOneMatrix

func EncryptedOneMatrix(rows, cols int, setting AHE_setting) (m gm.Matrix, err error)

func EncryptedZeroMatrix

func EncryptedZeroMatrix(rows, cols int, setting AHE_setting) (m gm.Matrix, err error)

func EvalIntPolys

func EvalIntPolys(root_poly gm.Matrix, sample_max int, setting AHE_setting) (R_values_enc, R_tilde_values, p_values gm.Matrix)

func EvalPoly

func EvalPoly(p gm.Matrix, x, mod *big.Int) *big.Int

evaluate polynomial p at point x

func GenCRP

func GenCRP(params *bfv.Parameters) (*ring.Poly, []*ring.Poly)

func GetCti

func GetCti(MA, MB, RA, RAi, RBi gm.Matrix, setting AHE_setting, Secret_key Secret_key) (cti gm.Matrix, MA_part, MB_part gm.Matrix, err error)

step 3 of MMult

func GetMulMatrices

func GetMulMatrices(A, B gm.Matrix, RAs, RBs []gm.Matrix, setting AHE_setting) (RA, MA, MB gm.Matrix, err error)

step 2 of MMult

func HSeq

func HSeq(Hvs gm.Matrix, mat_size int, setting AHE_setting) (h_seq gm.Matrix, err error)

step 3e of CTest-diff

func Interpolation

func Interpolation(vs, ps gm.Matrix, setting AHE_setting) gm.Matrix

step 4 of TPSI-diff

func IntersectionWorker

func IntersectionWorker(items []*big.Int, sk Secret_key, setting AHE_setting) ([]*big.Int, []*big.Int)

returns two slices, shared elements & unique elements

func IsRoot

func IsRoot(poly gm.Matrix, x *big.Int, mod *big.Int) bool

func MaskH

func MaskH(Hs gm.Matrix, HMasks []gm.Matrix, setting AHE_setting) (diff gm.Matrix, err error)

step 3g of CTest-diff

func MaskRootPoly

func MaskRootPoly(p_values, party_values, R_tilde_values gm.Matrix, sample_max int, setting AHE_setting) gm.Matrix

func MultPoly

func MultPoly(p1, p2 gm.Matrix) gm.Matrix

polynomial multiplication

func NbrMMultInstances

func NbrMMultInstances(m gm.Matrix) int

calculates how many instances of MMult is needed to get all H, according to: n = ceil( log(matrix size) ) H^2^n being the highest order needed

func NegateValue

func NegateValue(d *big.Int, setting AHE_setting) *big.Int

ASS, step 7

func NewCustomDJCryptosystem

func NewCustomDJCryptosystem(n, bitSize, s int) (cryptosystem DJ_encryption, secret_keys []DJ_secret_key, err error)

func NewDJCryptosystem

func NewDJCryptosystem(n int) (cryptosystem DJ_encryption, secret_keys []DJ_secret_key, err error)

func OuterASSWorker

func OuterASSWorker(a Ciphertext, sk Secret_key, setting AHE_setting) *big.Int

func OuterBFVEncryptionGenerator

func OuterBFVEncryptionGenerator(channel chan interface{}) (BFV_encryption, BFV_secret_key)

func OuterCardinalityTestWorker

func OuterCardinalityTestWorker(items []*big.Int, sk Secret_key, setting AHE_setting) bool

returns true if number of elements not shared by all is <= setting.Threshold()

func OuterDecryptionWorker

func OuterDecryptionWorker(cipher Ciphertext, sk Secret_key, setting AHE_setting) *big.Int

func OuterFHECardinalityTestWorker

func OuterFHECardinalityTestWorker(items []*big.Int, sk Secret_key, setting FHE_setting) bool

returns true if cardinality test passes

func OuterHankelMatrix

func OuterHankelMatrix(items []*big.Int, sk Secret_key, setting AHE_setting) gm.Matrix

func OuterIntersectionPolyWorker

func OuterIntersectionPolyWorker(root_poly gm.Matrix, sk Secret_key, setting AHE_setting) (gm.Matrix, gm.Matrix)

step 3 of TPSI-diff

func OuterMatrixMultiplicationWorker

func OuterMatrixMultiplicationWorker(a, b gm.Matrix, sk Secret_key, setting AHE_setting) gm.Matrix

func OuterMinPolyWorker

func OuterMinPolyWorker(seq gm.Matrix, rec_ord int, sk Secret_key, setting AHE_setting) (gm.Matrix, gm.Matrix)

func OuterSingularityTestWorker

func OuterSingularityTestWorker(m gm.Matrix, sk Secret_key, setting AHE_setting) bool

returns true if m is singular

func OuterZeroTestWorker

func OuterZeroTestWorker(a Ciphertext, sk Secret_key, setting AHE_setting) bool

func PartialDecryptMatrix

func PartialDecryptMatrix(cipher gm.Matrix, Secret_key Secret_key) (part_mat gm.Matrix, err error)

perform partial decryption for key share Secret_key

func PolyFromRoots

func PolyFromRoots(roots []*big.Int, mod *big.Int) gm.Matrix

func PolyMult

func PolyMult(a_num, a_den, b_num, b_den gm.Matrix, sk Secret_key, setting AHE_setting) (prod_num, prod_den gm.Matrix, err error)

func PolySub

func PolySub(a_num, a_den, b_num, b_den gm.Matrix, sk Secret_key, setting AHE_setting) (diff_num, diff_den gm.Matrix, err error)

func RootMask

func RootMask(root_poly gm.Matrix, setting AHE_setting) gm.Matrix

func SampleHMasks

func SampleHMasks(setting AHE_setting)

step 3f of CTest-diff

func SampleInt

func SampleInt(q *big.Int) (*big.Int, error)

sample a uniform random integer smaller than q

func SampleMatrix

func SampleMatrix(rows, cols int, q *big.Int) (a gm.Matrix, err error)

sample a matrix with size rows x cols, with elements from field defined by q

func SampleRMatrices

func SampleRMatrices(a, b gm.Matrix, setting AHE_setting) (RAi_plain, RAi_enc, RBi_plain, RBi_enc gm.Matrix, err error)

step 1 of MMult

func SampleSlice

func SampleSlice(l int, q *big.Int) (a []*big.Int, err error)

func SampleUVector

func SampleUVector(m gm.Matrix, setting AHE_setting) (u gm.Matrix, err error)

sample u from step 3e of CTest-diff

func SampleVVector

func SampleVVector(m gm.Matrix, setting AHE_setting) (v gm.Matrix, err error)

step 3b of CTest-diff

func SecretShare

func SecretShare(d, e *big.Int, setting AHE_setting) *big.Int

ASS, step 7

func SetupBFV

func SetupBFV(n int) ([]BFV_encryption, []BFV_secret_key)

func TPSIdiffWorker

func TPSIdiffWorker(items []*big.Int, sk Secret_key, setting AHE_setting) ([]*big.Int, []*big.Int)

returns two slices: shared elements & unique elements if cardinality test passes, otherwise nil, nil

func TPSIintWorker

func TPSIintWorker(items []*big.Int, sk Secret_key, setting FHE_setting) ([]*big.Int, []*big.Int)

returns two slices: shared elements & unique elements if cardinality test passes, otherwise nil, nil

Types

type AHESetting

type AHESetting struct {
	T int // threshold
	// contains filtered or unexported fields
}

func SetupAHE

func SetupAHE(n, T int, cs AHE_Cryptosystem) []AHESetting

func (AHESetting) AHE_cryptosystem

func (s AHESetting) AHE_cryptosystem() AHE_Cryptosystem

func (AHESetting) Distribute

func (s AHESetting) Distribute(any interface{})

func (AHESetting) IsCentral

func (s AHESetting) IsCentral() bool

func (AHESetting) Parties

func (s AHESetting) Parties() int

func (AHESetting) Receive

func (s AHESetting) Receive() interface{}

func (AHESetting) ReceiveAll

func (s AHESetting) ReceiveAll() []interface{}

func (AHESetting) Send

func (s AHESetting) Send(any interface{})

func (AHESetting) SendTo

func (s AHESetting) SendTo(i int, any interface{})

func (AHESetting) Threshold

func (s AHESetting) Threshold() int

type AHE_Cryptosystem

type AHE_Cryptosystem interface {

	// addition of two elements
	Add(Ciphertext, Ciphertext) (sum Ciphertext, err error)

	// scaling of an element by scalar factor
	Scale(cipher Ciphertext, factor *big.Int) (product Ciphertext, err error)

	// encrypt a plaintext message
	Encrypt(*big.Int) (Ciphertext, error)

	// combine partial decryptions to plaintext
	CombinePartials([]Partial_decryption) (*big.Int, error)

	// encrypted matrix evaluation
	EvaluationSpace() gm.Space

	// size of plaintext space
	N() *big.Int
}

type AHE_setting

type AHE_setting interface {
	// threshold value
	Threshold() int

	// numer of parties
	Parties() int

	// ahe cryptosystem
	AHE_cryptosystem() AHE_Cryptosystem

	// used by central party to send a value to all
	Distribute(interface{})

	// used by outer parties to send to central party
	Send(interface{})

	// used by central party to send
	// a message to given party
	SendTo(int, interface{})

	// for central to await messages from all
	// and get them (ordered) in a slice
	ReceiveAll() []interface{}

	// receive a message from central party
	Receive() interface{}

	// true if this party is central
	IsCentral() bool
}

type BFV_ciphertext

type BFV_ciphertext struct {
	// contains filtered or unexported fields
}

func CentralRefresh

func CentralRefresh(cipher BFV_ciphertext, pk BFV_encryption) BFV_ciphertext

func OuterRefresh

func OuterRefresh(cipher BFV_ciphertext, pk BFV_encryption) BFV_ciphertext

type BFV_encryption

type BFV_encryption struct {
	// contains filtered or unexported fields
}

func CentralKeyGenerator

func CentralKeyGenerator(init BFV_init, channels []chan interface{}) (BFV_encryption, *bfv.SecretKey)

func OuterKeyGenerator

func OuterKeyGenerator(init BFV_init, channel chan interface{}) (BFV_encryption, *bfv.SecretKey)

func (BFV_encryption) Add

func (pk BFV_encryption) Add(a, b Ciphertext) (sum Ciphertext, err error)

func (BFV_encryption) CombinePartials

func (pk BFV_encryption) CombinePartials(parts []Partial_decryption) (*big.Int, error)

func (BFV_encryption) Encrypt

func (pk BFV_encryption) Encrypt(a *big.Int) (Ciphertext, error)

func (BFV_encryption) EvaluationSpace

func (pk BFV_encryption) EvaluationSpace() gm.Space

func (BFV_encryption) Multiply

func (pk BFV_encryption) Multiply(a, b Ciphertext) (product Ciphertext, err error)

func (BFV_encryption) N

func (pk BFV_encryption) N() *big.Int

func (BFV_encryption) Scale

func (pk BFV_encryption) Scale(cipher Ciphertext, factor *big.Int) (product Ciphertext, err error)

type BFV_eval_space

type BFV_eval_space struct {
	BFV_encryption
}

func (BFV_eval_space) Add

func (pk BFV_eval_space) Add(a, b interface{}) (interface{}, error)

func (BFV_eval_space) Multiply

func (pk BFV_eval_space) Multiply(a, b interface{}) (product interface{}, err error)

func (BFV_eval_space) Scalarspace

func (pk BFV_eval_space) Scalarspace() bool

func (BFV_eval_space) Scale

func (pk BFV_eval_space) Scale(ciphertext interface{}, factor interface{}) (product interface{}, err error)

func (BFV_eval_space) Subtract

func (pk BFV_eval_space) Subtract(a, b interface{}) (diff interface{}, err error)

type BFV_init

type BFV_init struct {
	// contains filtered or unexported fields
}

type BFV_partial

type BFV_partial struct {
	// contains filtered or unexported fields
}

type BFV_secret_key

type BFV_secret_key struct {
	// contains filtered or unexported fields
}

func (BFV_secret_key) PartialDecrypt

func (sk BFV_secret_key) PartialDecrypt(ciphertext Ciphertext) (Partial_decryption, error)

type Ciphertext

type Ciphertext interface{}

func CentralInverseWorker

func CentralInverseWorker(a Ciphertext, sk Secret_key, setting FHE_setting) Ciphertext

func CentralInverseWorkerWithFactor

func CentralInverseWorkerWithFactor(a Ciphertext, factor *big.Int, sk Secret_key, setting FHE_setting) Ciphertext

func CentralMultWorker

func CentralMultWorker(a, b Ciphertext, sk Secret_key, setting AHE_setting) Ciphertext

func FHEEvaluate

func FHEEvaluate(x *big.Int, poly []Ciphertext, setting FHE_setting) Ciphertext

func FHEInterpolation

func FHEInterpolation(q []Ciphertext, sk Secret_key, setting FHE_setting) []Ciphertext

func GetRandomEncrypted

func GetRandomEncrypted(setting AHE_setting) (plain *big.Int, cipher Ciphertext, err error)

ASS, step 1

func OuterInverseWorker

func OuterInverseWorker(a Ciphertext, sk Secret_key, setting FHE_setting) Ciphertext

func OuterInverseWorkerWithFactor

func OuterInverseWorkerWithFactor(a Ciphertext, factor *big.Int, sk Secret_key, setting FHE_setting) Ciphertext

func OuterMultWorker

func OuterMultWorker(a, b Ciphertext, sk Secret_key, setting AHE_setting) Ciphertext

func PolynomialDivisionWorker

func PolynomialDivisionWorker(a, b gm.Matrix, a_den, b_den Ciphertext, sk Secret_key, setting AHE_setting) (gm.Matrix, gm.Matrix, gm.Matrix, Ciphertext)

returns:

  • q numerator
  • q denominator
  • r numerator
  • r denominator

func SumSlice

func SumSlice(values []Ciphertext, setting AHE_setting) (sum Ciphertext, err error)

Mult, step 6

type DJ_ds

type DJ_ds struct {
	*tcpaillier.DecryptionShare
}

type DJ_encryption

type DJ_encryption struct {
	gm.DJ_public_key
}

func (DJ_encryption) Add

func (pk DJ_encryption) Add(a, b Ciphertext) (sum Ciphertext, err error)

func (DJ_encryption) CombinePartials

func (pk DJ_encryption) CombinePartials(parts []Partial_decryption) (plaintext *big.Int, err error)

func (DJ_encryption) Encrypt

func (pk DJ_encryption) Encrypt(plaintext *big.Int) (ciphertext Ciphertext, err error)

func (DJ_encryption) EvaluationSpace

func (pk DJ_encryption) EvaluationSpace() gm.Space

func (DJ_encryption) N

func (pk DJ_encryption) N() *big.Int

func (DJ_encryption) Scale

func (pk DJ_encryption) Scale(cipher Ciphertext, factor *big.Int) (Ciphertext, error)

type DJ_secret_key

type DJ_secret_key struct {
	*tcpaillier.KeyShare
}

func (DJ_secret_key) PartialDecrypt

func (sk DJ_secret_key) PartialDecrypt(ciphertext Ciphertext) (Partial_decryption, error)

type FHESetting

type FHESetting struct {
	AHESetting
	// contains filtered or unexported fields
}

func SetupFHE

func SetupFHE(n, T int, cs []FHE_Cryptosystem) []FHESetting

func (FHESetting) AHE_cryptosystem

func (s FHESetting) AHE_cryptosystem() AHE_Cryptosystem

func (FHESetting) FHE_cryptosystem

func (s FHESetting) FHE_cryptosystem() FHE_Cryptosystem

type FHE_Cryptosystem

type FHE_Cryptosystem interface {
	AHE_Cryptosystem

	// multiplication of two elements
	Multiply(Ciphertext, Ciphertext) (Ciphertext, error)
}

type FHE_setting

type FHE_setting interface {
	AHE_setting

	// fhe cryptosystem
	FHE_cryptosystem() FHE_Cryptosystem
}

type Partial_decryption

type Partial_decryption interface{}

func SumMasksDecrypt

func SumMasksDecrypt(a Ciphertext, ds []Ciphertext, sk Secret_key, setting AHE_setting) (e_partial Partial_decryption, err error)

ASS, step 5 & 6

type Secret_key

type Secret_key interface {
	PartialDecrypt(Ciphertext) (Partial_decryption, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL