distributed

package
v0.0.0-...-9e2d205 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

defines all protocols and entities for distributed refresh, key switch and oblivious decryption

Index

Constants

This section is empty.

Variables

View Source
var DELIM = []byte{'\r', '\n', '\r', '\n'}
View Source
var KB = 1024
View Source
var Lan = latency.Local //no overhead, used in real distributed env.
View Source
var Local = latency.Network{
	Kbps:    1024 * 1024,
	Latency: 20 * time.Millisecond,
	MTU:     1500,
}
View Source
var MAX_SIZE = 30 * MB //LogN = 15, setup included
View Source
var MB = 1024 * KB
View Source
var ServicePort = 9999 //port used by remote nodes to receive ProtocolMsg from master
View Source
var SetupPort = 7777 //port used by remote nodes to receive SetupMsg from master
View Source
var TYP = uint8(255)
View Source
var TYPES = []string{"PubKeySwitch", "Refresh", "End"}

Functions

func DeserializeKeys

func DeserializeKeys(path string, parties int) (sk *rlwe.SecretKey, skShares []*rlwe.SecretKey, rtks *rlwe.RotationKeySet)

reads keys from file

func DummyEncKeyGen

func DummyEncKeyGen(params ckks.Parameters, crs *lattigoUtils.KeyedPRNG, parties int) ([]*rlwe.SecretKey, *rlwe.SecretKey, *rlwe.PublicKey, ckks.KeyGenerator)

Returns array of secret key shares, secret key and collective encryption key

func DummyRelinKeyGen

func DummyRelinKeyGen(params ckks.Parameters, crs *lattigoUtils.KeyedPRNG, shares []*rlwe.SecretKey) *rlwe.RelinearizationKey

Dummy generation of relin keys

func MarshalCrp

func MarshalCrp(crp drlwe.CKSCRP) ([]byte, error)

HELPERS

func ReadFrom

func ReadFrom(c io.Reader) ([]byte, error)

reads TLV value

func SerializeKeys

func SerializeKeys(sk *rlwe.SecretKey, skshares []*rlwe.SecretKey, rtks *rlwe.RotationKeySet, path string)

writes key from experiment to file

func UnMarshalCrp

func UnMarshalCrp(buf []byte) (drlwe.CKSCRP, error)

func WriteTo

func WriteTo(c io.Writer, buf []byte) error

write TLV value

Types

type Client

type Client struct {
	ProtoBuf *sync.Map //ct id -> protocol instance *Protocol

	//comms
	ServerAddr *net.TCPAddr
	Network    latency.Network

	Box cipherUtils.CkksBox
	// contains filtered or unexported fields
}

Client in the 2PC oblivious decryption protocol

func NewClient

func NewClient(ServerAddr string, Box cipherUtils.CkksBox, poolSize int, localhost bool) (*Client, error)

Creates new client. Client runs inference on plaintext data with encrypted model Set localhost to true if LAN is simulated on localhost

func (*Client) ClientSetup

func (cl *Client) ClientSetup(serverAddr string, sk *rlwe.SecretKey)

Invoked by client to setup server listening on setup port

func (*Client) Dispatch

func (cl *Client) Dispatch(c net.Conn)

reads reply from open connection to player

func (*Client) DispatchMasking

func (cl *Client) DispatchMasking(resp ProtocolMsg)

Listen for shares and aggregates

func (*Client) RunEnd

func (cl *Client) RunEnd()

func (*Client) RunMasking

func (cl *Client) RunMasking(ctId int)

Runs the Masking protocol

func (*Client) StartProto

func (cl *Client) StartProto(proto ProtocolType, X *cipherUtils.EncInput) *cipherUtils.PlainInput

starts protocol instances in parallel

type DistributedBtp

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

distributed bootstrapper

func NewDistributedBootstrapper

func NewDistributedBootstrapper(master *LocalMaster, minLevel int) *DistributedBtp

func (*DistributedBtp) Bootstrap

func (Btp *DistributedBtp) Bootstrap(X *cipherUtils.EncInput, Box cipherUtils.CkksBox)

Starts refresh protocol with master

type LocalMaster

type LocalMaster struct {
	ProtoBuf *sync.Map //ct id -> protocol instance *Protocol

	Cpk     *rlwe.PublicKey
	Params  ckks.Parameters
	Parties int
	Network latency.Network
	//comms
	Addr        *net.TCPAddr
	PartiesAddr []*net.TCPAddr

	Done chan bool //flag caller that master is done with all instances
	// contains filtered or unexported fields
}

Local master is the master node for LAN setting

func NewLocalMaster

func NewLocalMaster(sk *rlwe.SecretKey, cpk *rlwe.PublicKey, params ckks.Parameters, parties int, partiesAddr []string, poolSize int, localhost bool) (*LocalMaster, error)

Creates and returns new master node. This node is in charge of the computations using the encrypted model and orchestrates the distributed bootstrap and refresh Set localhost to true if LAN is simulated on localhost

func (*LocalMaster) Dispatch

func (lmst *LocalMaster) Dispatch(c net.Conn)

reads reply from open connection to player

func (*LocalMaster) DispatchPCKS

func (lmst *LocalMaster) DispatchPCKS(resp ProtocolResp)

Listen for shares and aggregates

func (*LocalMaster) DispatchRef

func (lmst *LocalMaster) DispatchRef(resp ProtocolResp)

Listen for shares and Finalize

func (*LocalMaster) MasterSetup

func (lmst *LocalMaster) MasterSetup(playersAddr []string, parties int, skShares []*rlwe.SecretKey, pkP *rlwe.PublicKey)

Invoked by master to spawn players on remote servers

func (*LocalMaster) RunEnd

func (lmst *LocalMaster) RunEnd()

func (*LocalMaster) RunPubKeySwitch

func (lmst *LocalMaster) RunPubKeySwitch(proto *dckks.PCKSProtocol, pkQ *rlwe.PublicKey, ct *ckks.Ciphertext, ctId int)

Runs the PCKS protocol from master and sends messages to players

func (*LocalMaster) RunRefresh

func (lmst *LocalMaster) RunRefresh(proto *dckks.RefreshProtocol, ct *ckks.Ciphertext, crp drlwe.CKSCRP, minLevel int, logBound int, ctId int)

Runs the Refresh protocol from master and sends messages to players

func (*LocalMaster) StartProto

func (lmst *LocalMaster) StartProto(proto ProtocolType, X *cipherUtils.EncInput, pkQ *rlwe.PublicKey, minLevel int, Box cipherUtils.CkksBox)

starts protocol instances in parallel

type LocalPlayer

type LocalPlayer struct {
	Remote
	PCKS *dckks.PCKSProtocol    //PubKeySwitch
	BTP  *dckks.RefreshProtocol //Bootstrap

	Cpk    *rlwe.PublicKey
	Params ckks.Parameters
	Id     int
	Addr   *net.TCPAddr
	Conn   net.Listener
	// contains filtered or unexported fields
}

Local players hold sk shares for LAN Setting

func NewLocalPlayer

func NewLocalPlayer(sk *rlwe.SecretKey, cpk *rlwe.PublicKey, params ckks.Parameters, id int, addr string, localhost bool) (*LocalPlayer, error)

Returns a player node, which will take part in distributed bootstrap and key switch protocol Set localhost to true if LAN is simulated on localhost

func (*LocalPlayer) Dispatch

func (lp *LocalPlayer) Dispatch(c net.Conn)

Handler for the connection

func (*LocalPlayer) End

func (lp *LocalPlayer) End(c net.Conn)

func (*LocalPlayer) Listen

func (lp *LocalPlayer) Listen()

Accepts an incoming TCP connection and handles it (blocking)

func (*LocalPlayer) RunPubKeySwitch

func (lp *LocalPlayer) RunPubKeySwitch(c net.Conn, msg ProtocolMsg)

Generates and send share to Master

func (*LocalPlayer) RunRefresh

func (lp *LocalPlayer) RunRefresh(c net.Conn, msg ProtocolMsg)

Generate and send share to master

type MaskProtocol

type MaskProtocol struct {
	Ct *ckks.Ciphertext //ct to be blindly decrypted
	//Mask         *ckks.Plaintext  //used for masking
	Mask         *ring.Poly      //used for masking
	Pt           *ckks.Plaintext //result of decryption by server
	FeedbackChan chan *ckks.Plaintext
}

Masking protocol for scenario data clear - model encrypted

type PCKSExt

type PCKSExt struct {
	Pk []byte `json:"pk"` //Pub Key from Querier -> PubKeySwitch
}

Extension for PCKS

type Protocol

type Protocol struct {
	Protocol interface{}      //instance of protocol
	Crp      drlwe.CKSCRP     //Common reference poly if any
	Ct       *ckks.Ciphertext //ciphertext of the protocol

	Shares       []interface{}         //collects shares from parties
	Completion   int                   //counter to completion
	FeedbackChan chan *ckks.Ciphertext //final result of protocol
	// contains filtered or unexported fields
}

Wrapper for distributed key switch or refresh

type ProtocolMsg

type ProtocolMsg struct {
	Type ProtocolType `json:"type"`
	Id   int          `json:"id"` //this is the id of the ct in the Enc Block Matrix, like i*row+j
	Ct   []byte       `json:"ct"` //ciphertext

	//Protocol Dependent
	Extension interface{} `json:"extension"`
}

Master to player

type ProtocolResp

type ProtocolResp struct {
	ProtoId  int          `json:"protoId"`
	Type     ProtocolType `json:"type"`
	PlayerId int          `json:"playerId"`
	Share    []byte       `json:"share"`
}

Used by players for replying to master

type ProtocolType

type ProtocolType int16
const (
	CKSWITCH ProtocolType = iota
	REFRESH  ProtocolType = iota
	MASKING  ProtocolType = iota
	END      ProtocolType = iota
)

type RefreshExt

type RefreshExt struct {
	Crp       []byte  `json:"crp"`       //Common poly from CRS -> Refresh
	Precision int     `json:"precision"` //Precision for instance of Refresh Protocol
	MinLevel  int     `json:"minlevel"`
	Scale     float64 `json:"scale"`
}

Extension for Refresh

type Remote

type Remote interface {
	Listen()
}

Interface implemented by player or server in distributed package

func ListenForSetup

func ListenForSetup(addr string, params ckks.Parameters) Remote

Invoked by remote server for setup. The msg received will create either a player instance for the distributed bootstrap and keyswitch or a server instance for the oblivious decryption

type Server

type Server struct {
	Remote
	Box  cipherUtils.CkksBox
	Addr *net.TCPAddr
	Conn net.Listener
}

Server offers decryption as a service for oblivious decryption protocol

func NewServer

func NewServer(Box cipherUtils.CkksBox, addr string, localhost bool) (*Server, error)

func (*Server) Dispatch

func (s *Server) Dispatch(c net.Conn)

Handler for the connection

func (*Server) End

func (s *Server) End(c net.Conn)

func (*Server) Listen

func (s *Server) Listen()

Accepts an incoming TCP connection and handles it (blocking)

func (*Server) RunMask

func (s *Server) RunMask(c net.Conn, msg ProtocolMsg)

Generates and send share to Master

type ServerMsg

type ServerMsg struct {
	Sk *rlwe.SecretKey `json:"sk,omitempty"`
}

setup msg from client to server

type SetupMsg

type SetupMsg struct {
	SkShare *rlwe.SecretKey `json:"skShare,omitempty"`
	Pk      *rlwe.PublicKey `json:"pk,omitempty"`
	Id      int             `json:"id,omitempty"`
}

dummy setup msg sent from master to parties

Jump to

Keyboard shortcuts

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