pir

package module
v0.0.0-...-8ab59fc Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

pir

Library for single-server and multi-server private information retrieval

Documentation

Index

Constants

View Source
const BenchmarkDBHeight = 1 << 10
View Source
const BenchmarkDBSize = 1 << 20
View Source
const MaxGroupSize = 5
View Source
const MinGroupSize = 1
View Source
const NumProcsForQuery = 4 // number of parallel processors
View Source
const NumQueries = 50 // number of queries to run
View Source
const SlotBytes = 3
View Source
const SlotBytesStep = 5
View Source
const StatisticalSecurityBytes = 8 // 8 bytes of stat sec
View Source
const TestDBHeight = 1 << 5

test configuration parameters

View Source
const TestDBSize = 1 << 10

Variables

This section is empty.

Functions

func AuthCheck

func AuthCheck(pk *paillier.PublicKey, query *AuthenticatedEncryptedQuery, chalToken *ChalToken, proofToken *ProofToken) bool

AuthCheck verifies the proof provided by the client and outputs True if and only if the proof is valid

func CheckAudit

func CheckAudit(auditTokens ...*AuditTokenShare) bool

CheckAudit outputs True of all provided audit tokens xor to zero

func GetOptimalDBDimentions

func GetOptimalDBDimentions(slotSize int, dbSize int) (int, int)

GetOptimalDBDimentions returns the optimal DB dimentions for PIR

func GetOptimalWeightedDBDimentions

func GetOptimalWeightedDBDimentions(slotSize int, dbSize int, weight int) (int, int)

GetOptimalWeightedDBDimentions returns the optimal DB dimentions for PIR where the height of the database is weighted by weight (int) >= 1

func GetRequiredSlotSize

func GetRequiredSlotSize(data []string) int

GetRequiredSlotSize returns the minimum number of bytes required to represent each data point

func PadToPowerOf2

func PadToPowerOf2(data []string) []string

PadToPowerOf2 pads the data to a power of 2

func PadToSqrt

func PadToSqrt(data []string) []string

PadToSqrt pads the data such that sqrt(N) is an sinteger

func RandomOracleDigest

func RandomOracleDigest(values ...*gmp.Int) []byte

RandomOracleDigest returns the digest of all the input bytes using SHA 256 to model a random oracle

func XorSlots

func XorSlots(a, b *Slot)

XorSlots compute xor a and b storing result in a

Types

type AuditTokenShare

type AuditTokenShare struct {
	T *Slot
}

AuditTokenShare is a secret share of an audit token used to authenticate two-server PIR queries

func GenerateAuditForSharedQuery

func GenerateAuditForSharedQuery(
	keyDB *Database,
	query *AuthenticatedQueryShare,
	nprocs int) (*AuditTokenShare, error)

GenerateAuditForSharedQuery generates an audit share that is sent to the other server(s)

func GenerateAuditForSharedQueryWithExpandedBits

func GenerateAuditForSharedQueryWithExpandedBits(
	keyDB *Database,
	query *AuthenticatedQueryShare,
	bits []bool,
	nprocs int) (*AuditTokenShare, error)

GenerateAuditForSharedQueryWithExpandedBits generates an audit share that is sent to the other server(s) using the expanded DPF bits provided to it

type AuthQueryPrivateState

type AuthQueryPrivateState struct {
	Sk         *paillier.SecretKey
	Bit        int
	AuthToken0 *paillier.Ciphertext
	AuthToken1 *paillier.Ciphertext
}

AuthQueryPrivateState the client's private state

type AuthTokenShare

type AuthTokenShare struct {
	T *Slot
}

AuthTokenShare is a share of the key associated with the queried item

func NewAuthTokenSharesForKey

func NewAuthTokenSharesForKey(authKey *Slot, numShares uint) []*AuthTokenShare

NewAuthTokenSharesForKey generates auth token shares for a specific AuthKey (encoded as a slot)

type AuthenticatedEncryptedQuery

type AuthenticatedEncryptedQuery struct {
	Query0         *DoublyEncryptedQuery
	Query1         *DoublyEncryptedQuery
	AuthTokenComm0 *ROCommitment
	AuthTokenComm1 *ROCommitment
}

AuthenticatedEncryptedQuery is a single-server encrypted query attached with an authentication token that proves knowledge of a secret associated with the retrieved item. Either Query0 or Query1`is a "null" query that doesn't retrieve any value. It is needed to prevent the server from generating a ”tagged” key database in an attempt to learn which item is being retrieved by the client ...

type AuthenticatedQueryShare

type AuthenticatedQueryShare struct {
	*QueryShare
	AuthToken *AuthTokenShare
}

AuthenticatedQueryShare contains a secret share of the auth token it doesn't need an "equivocation" query like AuthenticatedEncryptedQuery does because the verification happens between 2 or more servers

type ChalToken

type ChalToken struct {
	Token0   *paillier.Ciphertext
	Token1   *paillier.Ciphertext
	SecParam int
}

ChalToken is the challenge issued to the client in order to prove knowledge of the key associated with the retrieved item

func GenerateAuthChalForQuery

func GenerateAuthChalForQuery(
	secparam int,
	keyDB *Database,
	query *AuthenticatedEncryptedQuery,
	nprocs int) (*ChalToken, error)

GenerateAuthChalForQuery generates a challenge token for the provided PIR query

type DBMetadata

type DBMetadata struct {
	SlotBytes int
	DBSize    int
}

DBMetadata contains information on the layout and size information for a slot database type

func (*DBMetadata) GetDimentionsForDatabase

func (dbmd *DBMetadata) GetDimentionsForDatabase(height int, groupSize int) (int, int)

GetDimentionsForDatabase returns the width and height given a height constraint height is the desired height of the database (number of rows) groupSize is the number of *adjacent* slots needed to constitute a "group" (default = 1)

func (*DBMetadata) GetSqrtOfDBSize

func (dbmd *DBMetadata) GetSqrtOfDBSize() int

GetSqrtOfDBSize returns sqrt(DBSize) + 1

func (*DBMetadata) IndexToCoordinates

func (dbmd *DBMetadata) IndexToCoordinates(index, width, height int) (int, int)

IndexToCoordinates returns the 2D coodindates for an index a PIR query should use the first value to recover the row and the second value to recover the column in the response

func (*DBMetadata) NewAuthenticatedIndexQueryShares

func (dbmd *DBMetadata) NewAuthenticatedIndexQueryShares(
	index int, authKey *Slot, groupSize int, numShares uint) []*AuthenticatedQueryShare

NewAuthenticatedIndexQueryShares generates PIR query shares for the index

func (*DBMetadata) NewAuthenticatedQuery

func (dbmd *DBMetadata) NewAuthenticatedQuery(
	sk *paillier.SecretKey,
	groupSize, index int,
	authKey *Slot) (*AuthenticatedEncryptedQuery, *AuthQueryPrivateState)

NewAuthenticatedQuery generates an authenticated PIR query that can be verified by the server

func (*DBMetadata) NewDoublyEncryptedNullQuery

func (dbmd *DBMetadata) NewDoublyEncryptedNullQuery(pk *paillier.PublicKey, groupSize int) *DoublyEncryptedQuery

NewDoublyEncryptedNullQuery generates a PIR query that does not retrieve any value

func (*DBMetadata) NewDoublyEncryptedQuery

func (dbmd *DBMetadata) NewDoublyEncryptedQuery(pk *paillier.PublicKey, groupSize, index int) *DoublyEncryptedQuery

NewDoublyEncryptedQuery generates two encrypted point function that acts as a PIR query to select the row and column in the database

func (*DBMetadata) NewDoublyEncryptedQueryWithDimentions

func (dbmd *DBMetadata) NewDoublyEncryptedQueryWithDimentions(pk *paillier.PublicKey, width, height, groupSize, index int) *DoublyEncryptedQuery

NewDoublyEncryptedQueryWithDimentions generates two encrypted point function that acts as a PIR query to select the row and column in the database that is viewed as a width x height grid

func (*DBMetadata) NewEncryptedQuery

func (dbmd *DBMetadata) NewEncryptedQuery(pk *paillier.PublicKey, groupSize, index int) *EncryptedQuery

NewEncryptedQuery generates a new encrypted point function that acts as a PIR query defaults to sqrt sized grid database layout

func (*DBMetadata) NewEncryptedQueryWithDimentions

func (dbmd *DBMetadata) NewEncryptedQueryWithDimentions(pk *paillier.PublicKey, width, height, groupSize, index int) *EncryptedQuery

NewEncryptedQueryWithDimentions generates a new encrypted point function that acts as a PIR query where the database is viewed as a width x height grid

func (*DBMetadata) NewIndexQueryShares

func (dbmd *DBMetadata) NewIndexQueryShares(index int, groupSize int, numShares uint) []*QueryShare

NewIndexQueryShares generates PIR query shares for the index

func (*DBMetadata) NewKeywordQueryShares

func (dbmd *DBMetadata) NewKeywordQueryShares(keyword int, groupSize int, numShares uint) []*QueryShare

NewKeywordQueryShares generates keyword-based PIR query shares for keyword

type Database

type Database struct {
	DBMetadata
	Slots    []*Slot
	Keywords []uint // set of keywords (optional)
}

Database is a set of slots arranged in a grid of size width x height where each slot has size slotBytes

func GenerateEmptyDB

func GenerateEmptyDB(size, numBytes int) *Database

GenerateEmptyDB generates an empty database

func GenerateRandomDB

func GenerateRandomDB(size, numBytes int) *Database

GenerateRandomDB generates a database of slots (where each slot is of size NumBytes) the width and height parameter specify the number of rows and columns in the database

func NewDatabase

func NewDatabase() *Database

NewDatabase returns an empty database

func (*Database) BuildForData

func (db *Database) BuildForData(data []string)

BuildForData constrcuts a PIR database of slots where each string gets a slot and automatically finds the bandwidth-optimal width and height for PIR

func (*Database) BuildForDataWithSlotSize

func (db *Database) BuildForDataWithSlotSize(data []string, slotSize int)

BuildForDataWithSlotSize constrcuts a PIR database of slots where each string gets a slot of the specified size

func (*Database) ExpandSharedQuery

func (db *Database) ExpandSharedQuery(query *QueryShare, nprocs int) []bool

ExpandSharedQuery returns the expands the DPF and returns an array of bits

func (*Database) PrivateDoublyEncryptedQuery

func (db *Database) PrivateDoublyEncryptedQuery(query *DoublyEncryptedQuery, nprocs int) (*DoublyEncryptedQueryResult, error)

PrivateDoublyEncryptedQuery executes a row PIR query and col PIR query by recursively applying PrivateEncryptedQuery

func (*Database) PrivateEncryptedQuery

func (db *Database) PrivateEncryptedQuery(query *EncryptedQuery, nprocs int) (*EncryptedQueryResult, error)

PrivateEncryptedQuery uses the provided PIR query to retreive a slot row (encrypted) the tricky details are in regards to converting slot bytes to ciphertexts, specifically the encryption scheme might not have a message space large enough to accomodate all the bytes in a slot, thus requiring the bytes to be split up into several ciphertexts

func (*Database) PrivateEncryptedQueryOverEncryptedResult

func (db *Database) PrivateEncryptedQueryOverEncryptedResult(query *EncryptedQuery, result *EncryptedQueryResult, nprocs int) (*DoublyEncryptedQueryResult, error)

PrivateEncryptedQueryOverEncryptedResult executes the query over an encrypted query result

func (*Database) PrivateSecretSharedQuery

func (db *Database) PrivateSecretSharedQuery(query *QueryShare, nprocs int) (*SecretSharedQueryResult, error)

PrivateSecretSharedQuery uses the provided PIR query to retreive a slot row

func (*Database) PrivateSecretSharedQueryWithExpandedBits

func (db *Database) PrivateSecretSharedQueryWithExpandedBits(query *QueryShare, bits []bool, nprocs int) (*SecretSharedQueryResult, error)

PrivateSecretSharedQueryWithExpandedBits returns the result without expanding the query DPF

func (*Database) SetKeywords

func (db *Database) SetKeywords(keywords []uint)

SetKeywords set the keywords (uints) associated with each row of the database

type DoublyEncryptedQuery

type DoublyEncryptedQuery struct {
	Row *EncryptedQuery
	Col *EncryptedQuery
}

DoublyEncryptedQuery consists of two encrypted point functions that evaluates to 1 at the desired row and column in the database

type DoublyEncryptedQueryResult

type DoublyEncryptedQueryResult struct {
	Slots                 []*DoublyEncryptedSlot
	Pk                    *paillier.PublicKey
	SlotBytes             int
	NumBytesPerCiphertext int
}

DoublyEncryptedQueryResult is an array of encrypted slots

type DoublyEncryptedSlot

type DoublyEncryptedSlot struct {
	Cts []*paillier.Ciphertext // note: level2 ciphertexts (see Paillier)
}

DoublyEncryptedSlot is an array of doubly encrypted ciphertexts which decrypt to a set of ciphertexts that then decrypt to a slot

type EncryptedQuery

type EncryptedQuery struct {
	Pk                *paillier.PublicKey
	EBits             []*paillier.Ciphertext
	GroupSize         int
	DBWidth, DBHeight int // if a specific will force these dimentiojs
}

EncryptedQuery is an encryption of a point function that evaluates to 1 at the desired row in the database bits = (0, 0,.., 1, ...0, 0)

type EncryptedQueryResult

type EncryptedQueryResult struct {
	Slots                 []*EncryptedSlot
	Pk                    *paillier.PublicKey
	SlotBytes             int
	NumBytesPerCiphertext int
}

EncryptedQueryResult is an array of encrypted slots

type EncryptedSlot

type EncryptedSlot struct {
	Cts []*paillier.Ciphertext
}

EncryptedSlot is an array of ciphertext bytes

type PrivateSqrtST

type PrivateSqrtST struct {
	FirstLayer  []string
	SecondLayer *Database
	NumKeys     int
	SlotBytes   int
	Width       int
	Height      int
}

PrivateSqrtST is a search tree structure with sqrt nodes per layer. Requires 1 PIR query to get the index First round: get FirstLayer (sqrt N boundries) Second round: PIR query (sqrt N boundries) This is optimal in when the boundries are small but PrivateBST gets better asymptotic bandwidth

func NewPrivateSqrtST

func NewPrivateSqrtST() *PrivateSqrtST

NewPrivateSqrtST returns an empty PrivateBST struct

func (*PrivateSqrtST) BuildForData

func (sqst *PrivateSqrtST) BuildForData(data []string) error

BuildForData first generates a PrivateSqrtST for the data and then converts one layer into a PIR database with optimal width/height

func (*PrivateSqrtST) GetSecondLayerMetadata

func (sqst *PrivateSqrtST) GetSecondLayerMetadata() *DBMetadata

GetSecondLayerMetadata returns the metadata for PIR database of the second layer

func (*PrivateSqrtST) PrivateEncryptedQuery

func (sqst *PrivateSqrtST) PrivateEncryptedQuery(
	query *EncryptedQuery,
	nprocs int) (*EncryptedQueryResult, error)

PrivateEncryptedQuery queries the specified layer of the BST using cPIR

func (*PrivateSqrtST) PrivateQuery

func (sqst *PrivateSqrtST) PrivateQuery(
	query *QueryShare,
	nprocs int) (*SecretSharedQueryResult, error)

PrivateQuery queries the specified layer of the BST using PIR

type ProofToken

type ProofToken struct {
	AuthToken *paillier.Ciphertext
	T         *paillier.Ciphertext
	P         *paillier.DDLEQProof
	QBit      int
	R         *gmp.Int
	S         *gmp.Int
}

ProofToken is the response provided by the client to a ChalToken

func AuthProve

func AuthProve(state *AuthQueryPrivateState, chalToken *ChalToken) (*ProofToken, error)

AuthProve proves that challenge token is correct (a nested encryption of zero) bit indicate which query (query0 or query1) is the real query

type QueryShare

type QueryShare struct {
	KeyTwoParty    *dpf.Key2P
	KeyMultiParty  *dpf.KeyMP
	PrfKeys        []*dpf.PrfKey
	IsKeywordBased bool
	IsTwoParty     bool
	ShareNumber    uint
	GroupSize      int // height of the database
}

QueryShare is a secret share of a query over the database to retrieve a row

type ROCommitment

type ROCommitment struct {
	HashBytes []byte
	R         *gmp.Int
}

ROCommitment is a hiding and binding commitment consisting of a random oracle hash of the commited value

func Commit

func Commit(value *gmp.Int) *ROCommitment

Commit uses the random oracle to generate a commitment

func (*ROCommitment) CheckOpen

func (c *ROCommitment) CheckOpen(value *gmp.Int) bool

CheckOpen returns true if the commitment opening is valid

type SecretSharedQueryResult

type SecretSharedQueryResult struct {
	SlotBytes int
	Shares    []*Slot
}

SecretSharedQueryResult contains shares of the resulting slots

type Slot

type Slot struct {
	Data []byte
}

Slot is a set of bytes which can be xor'ed and comapred

func NewEmptySlot

func NewEmptySlot(numBytes int) *Slot

NewEmptySlot returns an all-zero slot

func NewRandomSlot

func NewRandomSlot(numBytes int) *Slot

NewRandomSlot returns a slot filled with random bytes

func NewSlot

func NewSlot(b []byte) *Slot

NewSlot returns a slot populated with data

func NewSlotFromGmpIntArray

func NewSlotFromGmpIntArray(arr []*gmp.Int, numBytes int, numBytesPerInt int) *Slot

NewSlotFromGmpIntArray parses an array of ints into a slot type numBytes is the final size of the slot numBytesPerInt the the number of bytes to extract from each int

func NewSlotFromString

func NewSlotFromString(s string, slotSize int) *Slot

NewSlotFromString converts a string to a slot type

func Recover

func Recover(resShares []*SecretSharedQueryResult) []*Slot

Recover combines shares of slots to recover the data

func RecoverDoublyEncrypted

func RecoverDoublyEncrypted(res *DoublyEncryptedQueryResult, sk *paillier.SecretKey) []*Slot

RecoverDoublyEncrypted decryptes the encrypted slot and returns slot

func RecoverEncrypted

func RecoverEncrypted(res *EncryptedQueryResult, sk *paillier.SecretKey) []*Slot

RecoverEncrypted decryptes the encrypted slot and returns slot

func (*Slot) Compare

func (slot *Slot) Compare(other *Slot) int

Compare returns the comparison of the two byte arrays 0 if slot == other -1 if slot < other 1 if slot > other

func (*Slot) Equal

func (slot *Slot) Equal(other *Slot) bool

Equal compute xor a and b storing result in a

func (*Slot) ToGmpIntArray

func (slot *Slot) ToGmpIntArray(numChuncks int) ([]*gmp.Int, int, error)

ToGmpIntArray converts the slot into an array of gmp.Ints returns array of gmp.Ints, number of bytes per int

func (*Slot) ToString

func (slot *Slot) ToString() string

ToString converts slot data to a string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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