pir

package
v0.0.0-...-0cd06db Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const Left int = 0
View Source
const Right int = 1
View Source
const (
	// SecParam is the security parameter in bits.
	SecParam = 128
)

Variables

This section is empty.

Functions

func MakeKeys

func MakeKeys(src *rand.Rand, nRows int) []uint32

func MathMod

func MathMod(x int, mod int) int

Go's % operator follows C semantics and can produce negative values if it's given a negative argument. We need an arithmetic mod operator.

func NewClientNonPrivate

func NewClientNonPrivate() *nonPrivateClient

func NewGGMSetGenerator

func NewGGMSetGenerator(randReader io.Reader) ggmSetGenerator

func RandSource

func RandSource() *rand.Rand

Types

type BaseGenerator

type BaseGenerator interface {
	Eval(seed []byte, elems []int)
	Punc(seed []byte, pos int) []byte
	EvalPunctured(pset []byte, hole int, elems []int)
	Distinct(elems []int) bool
}

type BufPRGReader

type BufPRGReader struct {
	Key PRGKey
	// contains filtered or unexported fields
}

func NewBufPRG

func NewBufPRG(prg *PRGReader) *BufPRGReader

func (*BufPRGReader) Int63

func (b *BufPRGReader) Int63() int64

func (*BufPRGReader) RandInt

func (b *BufPRGReader) RandInt(n int) int

func (*BufPRGReader) Seed

func (b *BufPRGReader) Seed(int64)

func (*BufPRGReader) Uint64

func (b *BufPRGReader) Uint64() uint64

type Client

type Client interface {
	Query(i int) ([]QueryReq, ReconstructFunc)
	DummyQuery() []QueryReq
	StateSize() (bitsPerKey, fixedBytes int)
}

type DBParams

type DBParams struct {
	NRows  int
	RowLen int
}

func (*DBParams) NumRows

func (p *DBParams) NumRows() int

type HintReq

type HintReq interface {
	Process(db StaticDB) (HintResp, error)
}

func NewHintReq

func NewHintReq(source *rand.Rand, pirType PirType) HintReq

type HintResp

type HintResp interface {
	InitClient(randSrc *rand.Rand) Client
	NumRows() int
}

type MatrixHintReq

type MatrixHintReq struct{}

func NewMatrixHintReq

func NewMatrixHintReq() *MatrixHintReq

func (*MatrixHintReq) Process

func (req *MatrixHintReq) Process(db StaticDB) (HintResp, error)

type MatrixHintResp

type MatrixHintResp struct {
	DBParams
}

func (*MatrixHintResp) InitClient

func (resp *MatrixHintResp) InitClient(source *rand.Rand) Client

type MatrixQueryReq

type MatrixQueryReq struct {
	BitVector []bool
}

func (*MatrixQueryReq) Process

func (req *MatrixQueryReq) Process(db StaticDB) (interface{}, error)

type MatrixQueryResp

type MatrixQueryResp struct {
	Answer []byte
}

type NonPrivateHintReq

type NonPrivateHintReq struct {
}

func NewNonPrivateHintReq

func NewNonPrivateHintReq() *NonPrivateHintReq

func (*NonPrivateHintReq) Process

func (req *NonPrivateHintReq) Process(db StaticDB) (HintResp, error)

type NonPrivateHintResp

type NonPrivateHintResp struct {
	NRows int
}

func (*NonPrivateHintResp) InitClient

func (resp *NonPrivateHintResp) InitClient(source *rand.Rand) Client

func (*NonPrivateHintResp) NumRows

func (resp *NonPrivateHintResp) NumRows() int

type NonPrivateQueryReq

type NonPrivateQueryReq struct {
	Index int
}

func (*NonPrivateQueryReq) Process

func (req *NonPrivateQueryReq) Process(db StaticDB) (interface{}, error)

type NonPrivateQueryResp

type NonPrivateQueryResp struct {
	Row
}

type PIRReader

type PIRReader interface {
	Init(pirType PirType) error
	Read(i int) (Row, error)
}

func NewPIRReader

func NewPIRReader(source *rand.Rand, serverL, serverR Server) PIRReader

type PRGKey

type PRGKey [aes.BlockSize]byte

func RandomPRGKey

func RandomPRGKey() *PRGKey

type PRGReader

type PRGReader struct {
	Key PRGKey
	// contains filtered or unexported fields
}

Copied from: https://github.com/henrycg/prio/blob/master/utils/rand.go We use the AES-CTR to generate pseudo-random numbers using a stream cipher. Go's native rand.Reader is extremely slow because it makes tons of system calls to generate a small number of pseudo-random bytes.

We pay the overhead of using a sync.Mutex to synchronize calls to AES-CTR, but this is relatively cheap.

func NewPRG

func NewPRG(key *PRGKey) *PRGReader

func (*PRGReader) Read

func (s *PRGReader) Read(p []byte) (int, error)

type PirType

type PirType int
const (
	None PirType = iota
	Matrix
	Punc
	Perm
	DPF
	NonPrivate
)

func PirTypeString

func PirTypeString(s string) (PirType, error)

PirTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func PirTypeValues

func PirTypeValues() []PirType

PirTypeValues returns all values of the enum

func (PirType) IsAPirType

func (i PirType) IsAPirType() bool

IsAPirType returns "true" if the value is listed in the enum definition. "false" otherwise

func (PirType) String

func (i PirType) String() string

type Present

type Present int
const Present_Yes Present = 0

type PuncClient

type PuncClient struct {
	RowLen int

	IdxToSetIdx []int32
	IdxMapping  map[int32][]int32
	// contains filtered or unexported fields
}

func (*PuncClient) DummyQuery

func (c *PuncClient) DummyQuery() []QueryReq

func (*PuncClient) NumCovered

func (c *PuncClient) NumCovered() int

func (*PuncClient) Query

func (c *PuncClient) Query(i int) ([]QueryReq, ReconstructFunc)

func (*PuncClient) Query2

func (c *PuncClient) Query2(i int) ([]QueryReq, ReconstructFunc)

func (*PuncClient) StateSize

func (c *PuncClient) StateSize() (bitsPerKey, fixedBytes int)

type PuncHintReq

type PuncHintReq struct {
	RandSeed           PRGKey
	NumHintsMultiplier int
}

func NewPuncHintReq

func NewPuncHintReq(randSource *rand.Rand) *PuncHintReq

func (*PuncHintReq) Process

func (req *PuncHintReq) Process(db StaticDB) (HintResp, error)

func (*PuncHintReq) ProcessWithMapping

func (req *PuncHintReq) ProcessWithMapping(db StaticDB) (HintResp, []int32, error)

type PuncHintResp

type PuncHintResp struct {
	NRows     int
	RowLen    int
	SetSize   int
	SetGenKey PRGKey
	Hints     []Row
}

func (*PuncHintResp) InitClient

func (resp *PuncHintResp) InitClient(source *rand.Rand) Client

func (*PuncHintResp) InitClientNoMap

func (resp *PuncHintResp) InitClientNoMap(source *rand.Rand, mapping *[]int32) Client

func (*PuncHintResp) NumRows

func (resp *PuncHintResp) NumRows() int

type PuncQueryReq

type PuncQueryReq struct {
	PuncturedSet PuncturedSet
	ExtraElem    int
}

func (*PuncQueryReq) Process

func (q *PuncQueryReq) Process(db StaticDB) (interface{}, error)

type PuncQueryResp

type PuncQueryResp struct {
	Answer    Row
	ExtraElem Row
}

type PuncturableSet

type PuncturableSet struct {
	SetKey
	// contains filtered or unexported fields
}

type PuncturedSet

type PuncturedSet struct {
	UnivSize, SetSize int
	Keys              []byte
	Hole              int
	Shift             uint32
}

func (*PuncturedSet) Eval

func (pset *PuncturedSet) Eval() Set

type QueryReq

type QueryReq interface {
	Process(db StaticDB) (interface{}, error)
}

QueryReq is a PIR query from a client to a server.

type ReconstructFunc

type ReconstructFunc func(resp []interface{}) (Row, error)

type Row

type Row []byte

One database row.

func MakeKeysRows

func MakeKeysRows(numRows, rowLen int) ([]uint32, []Row)

func MakeRows

func MakeRows(src *rand.Rand, nRows, rowLen int) []Row

type Server

type Server interface {
	Hint(req HintReq, resp *HintResp) error
	Answer(q QueryReq, resp *interface{}) error
}

type Set

type Set []int

type SetGenerator

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

func NewSetGenerator

func NewSetGenerator(masterKey PRGKey, startId uint32, univSize int, setSize int) SetGenerator

func (*SetGenerator) Eval

func (gen *SetGenerator) Eval(key SetKey) PuncturableSet

func (*SetGenerator) EvalInPlace

func (gen *SetGenerator) EvalInPlace(key SetKey, pset *PuncturableSet)

func (*SetGenerator) Gen

func (gen *SetGenerator) Gen(pset *PuncturableSet)

func (*SetGenerator) GenWith

func (gen *SetGenerator) GenWith(val int) (pset PuncturableSet)

func (*SetGenerator) Punc

func (gen *SetGenerator) Punc(pset PuncturableSet, idx int) PuncturedSet

type SetKey

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

type StaticDB

type StaticDB struct {
	NumRows int
	RowLen  int
	FlatDb  []byte
}

func MakeDB

func MakeDB(nRows int, rowLen int) StaticDB

func StaticDBFromRows

func StaticDBFromRows(data []Row) *StaticDB

func (StaticDB) Answer

func (db StaticDB) Answer(q QueryReq, resp *interface{}) (err error)

func (StaticDB) Hint

func (db StaticDB) Hint(req HintReq, resp *HintResp) (err error)

func (StaticDB) Params

func (db StaticDB) Params() *DBParams

func (*StaticDB) Row

func (db *StaticDB) Row(i int) Row

func (*StaticDB) Slice

func (db *StaticDB) Slice(start, end int) []byte

Jump to

Keyboard shortcuts

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