SPADE

package module
v0.0.0-...-9b815d0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 5 Imported by: 0

README ¶

SPADE: Selective and PArtial DEcryption using Functional Encryption

Go Go Report Card

SPADE is an FE-based scheme that enables running selective and partial decryption queries over vectors of ciphertexts.

To see two real-world applications of SPADE, please have a look at the usescases directory.

Notes

  1. Curators are required to specify both the number of users and the maximum number of entries allowed for each plaintext vector. Users must encrypt their data as a vector of integers, ensuring that none of the values are zero.
  2. Be careful when defining the users' data vector using make(); This method assigns the zero value to the elements during initialization.

🚀 Execution

Prerequisites
  • Go 1.21 or higher

Changing the protobuf structure

If you want to modify the protobuf structure, please first change the following file:

./spadeproto/spade.proto

and then run the proto compiler command as follows to generate the new protobuf files:

protoc --go_out=. --go-grpc_out=. spade.proto 

Testing Instruction

go test     

Benchmarking Instruction

go test -benchtime=10x -bench=BenchmarkSpade -benchmem -run=^$

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

View Source
var TestVector = []TestContext{
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
	{
		// contains filtered or unexported fields
	},
}

Functions ¶

func GCD ¶

func GCD(a, b *big.Int) int

GCD check if a and b are relatively prime to each other or not, if a and b are relatively prime returns 1, otherwise returns 0

func RandomElementInZMod ¶

func RandomElementInZMod(q *big.Int) *big.Int

RandomElementInZMod generates a random element from "Zq" correspond to q

func TestString ¶

func TestString(name string, t TestContext) string

Types ¶

type SPADE ¶

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

func NewSpade ¶

func NewSpade(modulus, generator *big.Int, maxPtVecSize int) *SPADE

NewSpade returns new instantiation of spade with "nil" values

func (*SPADE) Decrypt ¶

func (spade *SPADE) Decrypt(dk []*big.Int, value int, ciphertexts [][]*big.Int) []*big.Int

Decrypt decrypts the "ciphertexts" using decryption keys "dk" and value query "v", note: the value "v" must be the same value where the "dk" generated for (check KeyDerivation)

func (*SPADE) Encrypt ¶

func (spade *SPADE) Encrypt(pks []*big.Int, alpha *big.Int, data []int) [][]*big.Int

Encrypt encrypts a vector of integers "data" using master public key "pks" and user's "alpha", returns Elgamal style ciphertext vector c = [[C0, C1], ..., [C0, C1]]

func (*SPADE) KeyDerivation ¶

func (spade *SPADE) KeyDerivation(id, value int, sks []*big.Int, regKey *big.Int) []*big.Int

KeyDerivation generates the decryption keys for specific query value "v", where the query is to be executed for a specific user "id", by using master secret key vector "sks", user's registration key "regKey" returns decryption keys "dk"

func (*SPADE) Register ¶

func (spade *SPADE) Register(alpha *big.Int) *big.Int

Register accepts user's token "alpha" as input and generate user's registration key "regKey", which later on will be used by Curator for generating the decryption keys per query (check KeyDerivation), returns "regKey"

func (*SPADE) Setup ¶

func (spade *SPADE) Setup() ([]*big.Int, []*big.Int)

Setup generates q and g based on plaintext vector size m and number of users n, then generates master public keys "pks" (encryption key) and master secret keys "sks", the number of keys for both "pks" and "sks" is bounded to the m, returns the "sks" and "pks"

type TestCase ¶

type TestCase int
const (
	S TestCase = iota
	M
	L
)

type TestContext ¶

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

type Vanilla ¶

type Vanilla struct {
}

func NewVanilla ¶

func NewVanilla() *Vanilla

NewVanilla returns new instantiation of vanilla initialized with "nil"

func (*Vanilla) QueryNumRep ¶

func (vanilla *Vanilla) QueryNumRep(data []int, value int) map[int]int

QueryNumRep count the number of repeat for a value in a sequence shows the duration of the query value and the number of Transition to that value

func (*Vanilla) QueryTotalNum ¶

func (vanilla *Vanilla) QueryTotalNum(data []int, value int) int

QueryTotalNum counting the total number of occurrences for a value

Directories ¶

Path Synopsis
usecases
dna

Jump to

Keyboard shortcuts

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