protocols

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package protocols implements the MHE protocol execution. It uses Lattigo as the underlying MHE library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllocateOutput

func AllocateOutput(sig Signature, params rlwe.Parameters) interface{}

AllocateOutput returns a newly allocated output for the protocol signature.

func GetParticipants

func GetParticipants(sig Signature, onlineNodes utils.Set[sessions.NodeID], threshold int) ([]sessions.NodeID, error)

GetParticipants returns a set of protocol participants, given the online nodes and the threshold. This function handle the case of the DEC protocol, where the target must be considered a participant. It returns an error if there are not enough online nodes.

func GetProtocolPrivateRandomness

func GetProtocolPrivateRandomness(pd Descriptor, sess *sessions.Session) blake2b.XOF

GetProtocolPrivateRandomness intitializes a keyed PRF from the session's private seed and the protocol's information. This function ensures that the PRF is unique for each protocol execution.

func GetProtocolPublicRandomness

func GetProtocolPublicRandomness(pd Descriptor, sess *sessions.Session) blake2b.XOF

GetProtocolPublicRandomness intitializes a keyed PRF from the session's public seed and the protocol's information. This function ensures that the PRF is unique for each protocol execution.

Types

type AggregationOutput

type AggregationOutput struct {
	Descriptor Descriptor
	Share      Share
	Error      error
}

AggregationOutput is a type for the output of a protocol's aggregation step. In addition to the protocol's descriptor, it contains either the aggregated share or an error if the aggregation has failed.

type AggregationOutputReceiver

type AggregationOutputReceiver func(context.Context, AggregationOutput) error

AggregationOutputReceiver is the interface for receiving aggregation outputs from the executor. These types are registered as callbacks when requesting the execution of a protocol.

type CKGProtocol

type CKGProtocol struct {
	drlwe.PublicKeyGenProtocol
	// contains filtered or unexported fields
}

func NewCKGProtocol

func NewCKGProtocol(params rlwe.Parameters, arg map[string]string) (*CKGProtocol, error)

func (*CKGProtocol) AggregatedShares

func (ckg *CKGProtocol) AggregatedShares(dst Share, ss ...Share) error

func (*CKGProtocol) AllocateShare

func (ckg *CKGProtocol) AllocateShare() Share

func (*CKGProtocol) Finalize

func (ckg *CKGProtocol) Finalize(crp Input, aggShare Share, rec interface{}) error

func (*CKGProtocol) GenShare

func (ckg *CKGProtocol) GenShare(sk *rlwe.SecretKey, crp Input, share Share) error

func (*CKGProtocol) ReadCRP

func (ckg *CKGProtocol) ReadCRP(crs drlwe.CRS) (CRP, error)

type CKSProtocol

type CKSProtocol struct {
	drlwe.KeySwitchProtocol
	// contains filtered or unexported fields
}

func NewCKSProtocol

func NewCKSProtocol(params rlwe.Parameters, args map[string]string) (*CKSProtocol, error)

func (*CKSProtocol) AggregatedShares

func (cks *CKSProtocol) AggregatedShares(dst Share, ss ...Share) error

func (*CKSProtocol) AllocateShare

func (cks *CKSProtocol) AllocateShare() Share

func (*CKSProtocol) Finalize

func (cks *CKSProtocol) Finalize(in Input, aggShare Share, rec interface{}) error

func (*CKSProtocol) GenShare

func (cks *CKSProtocol) GenShare(sk *rlwe.SecretKey, in Input, share Share) error

func (*CKSProtocol) ReadCRP

func (cks *CKSProtocol) ReadCRP(crs drlwe.CRS) (CRP, error)

type CRP

type CRP interface{}

CRP is a type for the common reference polynomials used in the key generation protocol. A CRP is a polynomial that is sampled uniformly at random, yet is the same for all nodes. CRPs are expanded from the session's public seed.

type CompleteMap

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

CompleteMap implements a concurrent map of completed protocols. It enables waiting for the completion of a protocol and retrieving the completed descriptor.

func NewCompletedProt

func NewCompletedProt(sigs []Signature) *CompleteMap

NewCompletedProt creates a new CompleteMap. If sigs is empty, the CompleteMap will allow callers of the AwaitCompletedDescriptorFor method to wait for any protocol descriptor completion. Otherwise, awaiting on an unknown protocol signature will return an error.

func (*CompleteMap) AwaitCompletedDescriptorFor

func (p *CompleteMap) AwaitCompletedDescriptorFor(sig Signature) (pdp *Descriptor, err error)

AwaitCompletedDescriptorFor waits for the completion of a protocol. This method will return an error if the map was created with a specific list of signatures and the provided signature is not in the list.

func (*CompleteMap) CompletedProtocol

func (p *CompleteMap) CompletedProtocol(pd Descriptor) error

CompletedProtocol adds a completed protocol descriptor to the map.

func (*CompleteMap) Wait

func (p *CompleteMap) Wait() error

Wait waits for all protocols to complete.

type Descriptor

type Descriptor struct {
	Signature
	Participants []sessions.NodeID
	Aggregator   sessions.NodeID
}

Descriptor is a complete description of a protocol's execution (i.e., a protocol), by complementing the Signature with a role assignment.

Multiple protocols can share the same signature, but have different descriptors (e.g., in the case of a failure). However, a protocol is uniquely identified by its descriptor.

func (Descriptor) HID

func (pd Descriptor) HID() string

HID returns the human-readable (truncated) ID of the protocol, derived from the descriptor.

func (Descriptor) ID

func (pd Descriptor) ID() ID

ID returns the ID of the protocol, derived from the descriptor.

func (Descriptor) MarshalBinary

func (pd Descriptor) MarshalBinary() (b []byte, err error)

MarshalBinary returns the binary representation of the protocol descriptor.

func (Descriptor) String

func (pd Descriptor) String() string

String returns the string representation of the protocol descriptor.

func (*Descriptor) UnmarshalBinary

func (pd *Descriptor) UnmarshalBinary(b []byte) (err error)

UnmarshalBinary unmarshals the binary representation of the protocol descriptor.

type Event

type Event struct {
	EventType
	Descriptor
}

Event is a type for protocol-execution-related events.

func (Event) IsComputeEvent

func (ev Event) IsComputeEvent() bool

IsComputeEvent returns true if the event is a compute-related event.

func (Event) IsSetupEvent

func (ev Event) IsSetupEvent() bool

IsSetupEvent returns true if the event is a setup-related event.

func (Event) String

func (ev Event) String() string

String returns the string representation of the event.

type EventType

type EventType int8

EventType defines the type of protocol-execution-related events.

const (
	// Completed is the event type for a completed protocol.
	Completed EventType = iota
	// Started is the event type for a started protocol.
	Started
	// Executing is the event type for a protocol that is currently executing. It is currently not used.
	Executing
	// Failed is the event type for a protocol that has failed.
	Failed
)

func (EventType) String

func (t EventType) String() string

String returns the string representation of the event type.

type Executor

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

Executor is a type for executing protocols. It enables concurrent execution of protocols and handles both running the protocol as a participant and as an aggregator/coordinator. As a participant, the executor will generate the share and send it to the aggregator. As an aggregator/coordinator, the executor will decide on the participant list based on the regsitered nodes, and perform the aggregation.

func NewExectutor

func NewExectutor(config ExecutorConfig, ownID sessions.NodeID, sessProv sessions.Provider, upstream *coordinator.Channel[Event], ip InputProvider) (*Executor, error)

NewExectutor creates a new executor.

func (*Executor) GetOutput

func (s *Executor) GetOutput(ctx context.Context, aggOut AggregationOutput, rec interface{}) error

func (*Executor) Logf

func (s *Executor) Logf(msg string, v ...any)

func (*Executor) NodeID

func (s *Executor) NodeID() sessions.NodeID

func (*Executor) Register

func (s *Executor) Register(peer sessions.NodeID) error

Register is called by the transport when a new peer register itself for the setup.

func (*Executor) Run

func (s *Executor) Run(ctx context.Context, trans Transport) error

func (*Executor) RunDescriptorAsAggregator

func (s *Executor) RunDescriptorAsAggregator(ctx context.Context, pd Descriptor) (aggOut *AggregationOutput, err error)

func (*Executor) RunSignature

func (s *Executor) RunSignature(ctx context.Context, sig Signature, aggOutRec AggregationOutputReceiver) (err error)

func (*Executor) Unregister

func (s *Executor) Unregister(peer sessions.NodeID) error

Unregister is called by the transport when a peer is unregistered from the setup.

type ExecutorConfig

type ExecutorConfig struct {
	// As coordinator
	// SigQueueSize is the size of the signature queue. If the queue is full the RunSignature method blocks.
	SigQueueSize int
	// MaxProtoPerNode is the maximum number of parallel proto participation per registered node.
	MaxProtoPerNode int

	// as aggregator
	// MaxAggregation is the maximum number of parallel proto aggrations for this executor.
	MaxAggregation int

	// as participant
	// MaxParticipation is the maximum number of parallel proto participation for this executor.
	MaxParticipation int
}

ExecutorConfig is the configuration for the executor.

type ID

type ID string

ID is a type for protocol IDs. Protocol IDs are unique identifiers for a protocol. Since a protocol is uniquely identified by its descriptor, the ID is derived from the descriptor.

type Input

type Input interface{}

Input is a type for protocol inputs. Inputs are either:

  • a CRP in the case of a key generation protocol (CKG, RTG, RKG_1)
  • an aggregated share from a previous round (RKG)
  • a KeySwitchInput for the key-switching protocols (DEC, CKS, PCKS)

type InputProvider

type InputProvider func(ctx context.Context, pd Descriptor) (Input, error)

InputProvider is the interface the provision of protocol inputs. It is called by the executor to get the CRP (CKG, RTG, RKG) and ciphertexts (DEC, CKS, PCKS) for the protocols.

type KeySwitchInput

type KeySwitchInput struct {
	// OutputKey is the target output key of the key-switching protocol,
	// it is a secret key (*rlwe.SecretKey) for the collective key-switching protocol (CKS)
	// and a public key (*rlwe.PublicKey) for the collective public-key switching protocol (PCKS).
	OutputKey ReceiverKey

	// InpuCt is the ciphertext to be re-encrpted under the output key.
	InpuCt *rlwe.Ciphertext
}

KeySwitchInput is a type for the inputs to the key-switching protocols.

type LattigoShare

type LattigoShare interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

LattigoShare is a common interface for all Lattigo shares

type Output

type Output struct {
	Descriptor
	Result interface{}
}

Output is a type for protocol outputs. It contains the result of the protocol execution or an error if the protocol execution has failed.

type PCKSProtocol

type PCKSProtocol struct {
	drlwe.PublicKeySwitchProtocol
	// contains filtered or unexported fields
}

func NewPCKSProtocol

func NewPCKSProtocol(params rlwe.Parameters, args map[string]string) (*PCKSProtocol, error)

func (*PCKSProtocol) AggregatedShares

func (cks *PCKSProtocol) AggregatedShares(dst Share, ss ...Share) error

func (*PCKSProtocol) AllocateShare

func (cks *PCKSProtocol) AllocateShare() Share

func (*PCKSProtocol) Finalize

func (cks *PCKSProtocol) Finalize(in Input, aggShare Share, rec interface{}) error

func (*PCKSProtocol) GenShare

func (cks *PCKSProtocol) GenShare(sk *rlwe.SecretKey, in Input, share Share) error

func (*PCKSProtocol) ReadCRP

func (cks *PCKSProtocol) ReadCRP(crs drlwe.CRS) (CRP, error)

type Protocol

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

Protocol is a base struct for protocols.

func NewProtocol

func NewProtocol(pd Descriptor, sess *sessions.Session) (*Protocol, error)

NewProtocol creates a new protocol from the provided protocol descriptor, session and inputs.

func (*Protocol) Aggregate

func (p *Protocol) Aggregate(ctx context.Context, incoming <-chan Share) <-chan AggregationOutput

Aggregate is called by the aggregator node to aggregate the shares of the protocol. The method aggregates the shares received in the provided incoming channel in the background, and sends the aggregated share to the returned channel when the aggregation has completed. Upon receiving the aggregated share, the caller must check the Error field of the aggregation output to determine whether the aggregation has failed. The aggregation can be cancelled by cancelling the context. If the context is cancelled or the incoming channel is closed before the aggregation has completed, the method sends the aggregation output with the corresponding error to the returned channel. The method panics if called by a non-aggregator node.

func (*Protocol) AllocateShare

func (p *Protocol) AllocateShare() Share

AllocateShare returns a newly allocated share for the protocol.

func (*Protocol) Descriptor

func (p *Protocol) Descriptor() Descriptor

Descriptor returns the protocol descriptor of the protocol.

func (*Protocol) GenShare

func (p *Protocol) GenShare(sk *rlwe.SecretKey, in Input, shareOut *Share) error

GenShare is called by the session nodes to generate their share in the protocol, storing the result in the provided shareOut. The method returns an error if the node should not generate a share in the protocol.

func (*Protocol) HID

func (p *Protocol) HID() string

HID returns the human-readable (truncated) ID of the protocol.

func (*Protocol) HasRole

func (p *Protocol) HasRole() bool

HasRole returns whether the node is an aggregator or a participant in the protocol.

func (*Protocol) HasShareFrom

func (p *Protocol) HasShareFrom(nid sessions.NodeID) bool

HasShareFrom returns whether the protocol has already recieved a share from the specified node.

func (*Protocol) ID

func (p *Protocol) ID() ID

ID returns the ID of the protocol.

func (*Protocol) IsAggregator

func (p *Protocol) IsAggregator() bool

IsAggregator returns whether the node is the aggregator in the protocol.

func (*Protocol) IsParticipant

func (p *Protocol) IsParticipant() bool

IsParticipant returns whether the node is a participant in the protocol.

func (*Protocol) Logf

func (p *Protocol) Logf(msg string, v ...any)

Logf logs a message

func (*Protocol) Output

func (p *Protocol) Output(in Input, agg AggregationOutput, out interface{}) error

Output computes the output of the protocol from the input and aggregation output, storing the result in out. Out must be a pointer to the type of the protocol's output, see AllocateOutput.

func (*Protocol) ReadCRP

func (p *Protocol) ReadCRP() (CRP, error)

ReadCRP reads the common random polynomial for this protocol. Returns an error if called for a protocol that does not use CRP.

type RKGProtocol

type RKGProtocol struct {
	drlwe.RelinearizationKeyGenProtocol
	// contains filtered or unexported fields
}

func NewRKGProtocol

func NewRKGProtocol(params rlwe.Parameters, ephSk *rlwe.SecretKey, round uint64, _ map[string]string) (*RKGProtocol, error)

func (*RKGProtocol) AggregatedShares

func (rkg *RKGProtocol) AggregatedShares(dst Share, ss ...Share) error

func (*RKGProtocol) AllocateShare

func (rkg *RKGProtocol) AllocateShare() (share Share)

func (*RKGProtocol) Finalize

func (rkg *RKGProtocol) Finalize(round1 Input, aggShares Share, rec interface{}) error

func (*RKGProtocol) GenShare

func (rkg *RKGProtocol) GenShare(sk *rlwe.SecretKey, input Input, share Share) error

func (*RKGProtocol) ReadCRP

func (rkg *RKGProtocol) ReadCRP(crs drlwe.CRS) (CRP, error)

type RTGProtocol

type RTGProtocol struct {
	drlwe.GaloisKeyGenProtocol
	// contains filtered or unexported fields
}

func NewRTGProtocol

func NewRTGProtocol(params rlwe.Parameters, args map[string]string) (*RTGProtocol, error)

func (*RTGProtocol) AggregatedShares

func (rtg *RTGProtocol) AggregatedShares(dst Share, ss ...Share) error

func (*RTGProtocol) AllocateShare

func (rtg *RTGProtocol) AllocateShare() Share

func (*RTGProtocol) Finalize

func (rtg *RTGProtocol) Finalize(crp Input, aggShare Share, rec interface{}) error

func (*RTGProtocol) GenShare

func (rtg *RTGProtocol) GenShare(sk *rlwe.SecretKey, crp Input, share Share) error

func (*RTGProtocol) ReadCRP

func (rtg *RTGProtocol) ReadCRP(crs drlwe.CRS) (CRP, error)

type ReceiverKey

type ReceiverKey interface{}

ReceiverKey is a type for the output keys in the key switching protocols. Depending on the type of protocol, the receiver key can be either a *rlwe.SecretKey (collective key-switching, CKS) or a *rlwe.PublicKey (collective public-key switching, PCKS).

type SKGProtocol

type SKGProtocol struct {
	drlwe.Thresholdizer
}

type Share

type Share struct {
	ShareMetadata
	MHEShare LattigoShare
}

Share is a type for the nodes' protocol shares.

func (Share) Copy

func (s Share) Copy() Share

Copy returns a copy of the Share.

func (Share) MarshalBinary

func (s Share) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the share.

func (Share) UnmarshalBinary

func (s Share) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals the binary representation of the share.

type ShareMetadata

type ShareMetadata struct {
	ProtocolID   ID
	ProtocolType Type
	From         utils.Set[sessions.NodeID]
}

ShareMetadata retains the necessary information for the framework to identify the share and the protocol it belongs to.

type Signature

type Signature struct {
	Type Type
	Args map[string]string
}

Signature is a protocol prototype. In analogy to a function signature, it describes the type of the protocol and the arguments it expects.

func (Signature) Equals

func (s Signature) Equals(other Signature) bool

Equals returns whether the signature is equal to the other signature, i.e., whether the protocol outputs are equivalent.

func (Signature) String

func (s Signature) String() string

String returns the string representation of the protocol signature. the arguments are alphabetically sorted by name so thtat the output is deterministic.

type TestTransport added in v0.2.0

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

func NewTestTransport

func NewTestTransport() *TestTransport

func (*TestTransport) IncomingShares added in v0.2.0

func (tt *TestTransport) IncomingShares() <-chan Share

func (*TestTransport) OutgoingShares added in v0.2.0

func (tt *TestTransport) OutgoingShares() chan<- Share

func (*TestTransport) TransportFor added in v0.2.0

func (tt *TestTransport) TransportFor(nid sessions.NodeID) *TestTransport

type Transport

type Transport interface {
	OutgoingShares() chan<- Share
	IncomingShares() <-chan Share
}

Transport defines the transport interface required for the executor.

type Type

type Type uint

Type is an enumerated type for protocol types.

const (
	// Unspecified is the default value for the protocol type.
	Unspecified Type = iota
	// SKG is the secret-key generation protocol. // TODO: unsupported
	SKG
	// CKG is the collective public-key generation protocol.
	CKG
	// RKG1 is the first round of the relinearization key generation protocol.
	RKG1
	// RKG is the relinearization key generation protocol.
	RKG
	// RTG is the galois key generation protocol.
	RTG
	// CKS is the collective key-switching protocol. // TODO: unsupported
	CKS
	// DEC is the decryption protocol.
	DEC
	// PCKS is the collective public-key switching protocol. // TODO: unsupported
	PCKS
)

func (Type) IsCompute

func (t Type) IsCompute() bool

IsCompute returns whether the protocol type is a secret-key operation ciphertext operation.

func (Type) IsSetup

func (t Type) IsSetup() bool

IsSetup returns whether the protocol type is a key generation protocol.

func (Type) Share

func (t Type) Share() LattigoShare

Share returns a lattigo share with the correct go type for the protocol type.

func (Type) String

func (t Type) String() string

String returns the string representation of the protocol type.

Jump to

Keyboard shortcuts

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