sessions

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: 12 Imported by: 0

Documentation

Overview

Package sessions implements helium sessions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CtxNodeID is the context key for the node ID.
	CtxNodeID ctxKey = "node_id"
	// CtxSessionID is the context key for the session ID.
	// Helium contexts must always have a session id.
	CtxSessionID ctxKey = "session_id"
	// CtxCircuitID is the context key for the circuit ID.
	// The circuit ID is optional and is only present in the context
	// of a circuit execution.
	CtxCircuitID ctxKey = "circuit_id"
)

Functions

func ContextWithCircuitID

func ContextWithCircuitID(ctx context.Context, circID CircuitID) context.Context

ContextWithCircuitID returns a new context derived from ctx with the given session ID.

func ContextWithNodeID

func ContextWithNodeID(ctx context.Context, nodeID NodeID) context.Context

ContextWithNodeID returns a new context derived from ctx with the given node ID.

func GenTestSecretKeys

func GenTestSecretKeys(sessParams Parameters) (secs map[NodeID]*Secrets, err error)

func NewBackgroundContext

func NewBackgroundContext(sessID ID, circID ...CircuitID) context.Context

NewBackgroundContext returns a new context derived from context.Background with the given session and circuit IDs.

func NewContext

func NewContext(ctx context.Context, sessID ID, circID ...CircuitID) context.Context

NewContext returns a new context derived from ctx with the given session and circuit IDs.

Types

type CachedKeyBackend

type CachedKeyBackend struct {
	sync.Mutex // TODO: could be more clever
	MemoryKeyStore
	PublicKeyProvider
}

CachedKeyBackend is a PublicKeyProvider queries a PublicKeyProvider for keys and caches them. The cached keys are cached indefinitely. This implementation is blocking if the underlying PublicKeyProvider is blocking. It returns an error if the underlying PublicKeyProvider returns an error. The implementation is safe for concurrent use.

func NewCachedPublicKeyBackend

func NewCachedPublicKeyBackend(kb PublicKeyProvider) (ckb *CachedKeyBackend)

NewCachedPublicKeyBackend creates a new CachedKeyBackend for the given PublicKeyProvider. The function panics if kb is nil.

func (*CachedKeyBackend) GetCollectivePublicKey

func (ckb *CachedKeyBackend) GetCollectivePublicKey(ctx context.Context) (*rlwe.PublicKey, error)

GetCollectivePublicKey returns the collective public key for the session in ctx. The method returns an error if the key is not in the store and the underlying PublicKeyProvider returns an error.

func (*CachedKeyBackend) GetGaloisKey

func (ckb *CachedKeyBackend) GetGaloisKey(ctx context.Context, galEl uint64) (*rlwe.GaloisKey, error)

GetGaloisKey returns the galois key for the session in ctx and the given Galois element. The method returns an error if the key is not in the store and the underlying PublicKeyProvider returns an error.

func (*CachedKeyBackend) GetRelinearizationKey

func (ckb *CachedKeyBackend) GetRelinearizationKey(ctx context.Context) (*rlwe.RelinearizationKey, error)

GetRelinearizationKey returns the relinearization key for the session in ctx. The method returns an error if the key is not in the store and the underlying PublicKeyProvider returns an error.

type Ciphertext

type Ciphertext struct {
	rlwe.Ciphertext
	CiphertextMetadata
}

Ciphertext is a type for ciphertext within the helium framework.

type CiphertextID

type CiphertextID string

type CiphertextMetadata

type CiphertextMetadata struct {
	ID   CiphertextID
	Type CiphertextType
}

CiphertextMetadata contains information on ciphertexts. In the current bgv-specific implementation, the type is not used.

type CiphertextType

type CiphertextType int

CiphertextType is an enumerated type for the types of ciphertexts.

const (
	// Unspecified is the default value for the type of a ciphertext.
	Unspecified CiphertextType = iota
	// BFV is the type of a ciphertext in the BFV scheme.
	BFV
	// BGV is the type of a ciphertext in the BGV scheme.
	BGV
	// CKKS is the type of a ciphertext in the CKKS scheme.
	CKKS
	// RGSW is the type of a ciphertext in the RGSW scheme.
	RGSW
)

func (CiphertextType) String

func (ctt CiphertextType) String() string

String returns a string representation of the ciphertext type.

type CircuitID

type CircuitID string

CircuitID is the unique identifier of a running circuit.

func CircuitIDFromContext

func CircuitIDFromContext(ctx context.Context) (CircuitID, bool)

CircuitIDFromContext returns the circuit ID from the context, if present.

type FHEParamerersLiteralProvider

type FHEParamerersLiteralProvider interface {
	GetRLWEParametersLiteral() rlwe.ParametersLiteral
}

type FHEParameters

type FHEParameters interface {
	GetRLWEParameters() *rlwe.Parameters
}

type ID

type ID string

ID is the unique identifier of a session.

func IDFromContext

func IDFromContext(ctx context.Context) (ID, bool)

IDFromContext returns the session ID from the context.

type MemoryKeyStore

type MemoryKeyStore struct {
	*rlwe.PublicKey
	GaloisKeys map[uint64]*rlwe.GaloisKey
	*rlwe.RelinearizationKey
}

MemoryKeyStore is a simple in-memory implementation of PublicKeyProvider. This implementation is non-blocking and returns an error if the keys are not available.

func (*MemoryKeyStore) GetCollectivePublicKey

func (pkb *MemoryKeyStore) GetCollectivePublicKey(ctx context.Context) (cpk *rlwe.PublicKey, err error)

GetCollectivePublicKey returns the collective public key for the session in ctx. If the public key is not in the store, it returns an error.

func (*MemoryKeyStore) GetGaloisKey

func (pkb *MemoryKeyStore) GetGaloisKey(ctx context.Context, galEl uint64) (gk *rlwe.GaloisKey, err error)

GetGaloisKey returns the galois key for the session in ctx and the given Galois element. If the galois key is not in the store, it returns an error.

func (*MemoryKeyStore) GetRelinearizationKey

func (pkb *MemoryKeyStore) GetRelinearizationKey(ctx context.Context) (rlk *rlwe.RelinearizationKey, err error)

GetRelinearizationKey returns the relinearization key for the session in ctx. If the relinearization key is not in the store, it returns an error.

type NodeID

type NodeID string

NodeID is the unique identifier of a node.

func NodeIDFromContext

func NodeIDFromContext(ctx context.Context) (NodeID, bool)

NodeIDFromContext returns the node ID from the context.

type Parameters

type Parameters struct {
	ID            ID
	Nodes         []NodeID
	FHEParameters FHEParamerersLiteralProvider
	Threshold     int
	ShamirPks     map[NodeID]drlwe.ShamirPublicPoint
	PublicSeed    []byte
	*Secrets
}

Parameters contains data used to initialize a Session.

type Provider

type Provider interface {
	GetSessionFromID(sessionID ID) (*Session, bool)
	GetSessionFromContext(ctx context.Context) (*Session, bool)
}

type PublicKeyProvider

type PublicKeyProvider interface {
	// GetCollectivePublicKey returns the collective public key for the session in ctx.
	GetCollectivePublicKey(ctx context.Context) (*rlwe.PublicKey, error)
	// GetGaloisKey returns the galois key for the session in ctx and the given Galois element.
	GetGaloisKey(ctx context.Context, galEl uint64) (*rlwe.GaloisKey, error)
	// GetRelinearizationKey returns the relinearization key for the session in ctx.
	GetRelinearizationKey(ctx context.Context) (*rlwe.RelinearizationKey, error)
}

PublicKeyProvider is an interface for retrieving public keys. Implementations return the keys for the session provided in the context. It is not specified whether implementations should block or return an error if the keys are not available.

Notable implementations of this interface are setup.Service, and key stores like MemoryKeyStore and the CachedkeyStore.

type Secrets

type Secrets struct {
	PrivateSeed        []byte
	ThresholdSecretKey *drlwe.ShamirSecretShare
}

type Session

type Session struct {
	Parameters
	NodeID NodeID

	Params FHEParameters
	// contains filtered or unexported fields
}

Session holds the session's critical state.

func NewSession

func NewSession(sessParams Parameters, nodeID NodeID) (sess *Session, err error)

NewSession creates a new session.

func (*Session) Contains

func (sess *Session) Contains(nodeID NodeID) bool

func (*Session) GetRLKEphemeralSecretKey

func (sess *Session) GetRLKEphemeralSecretKey() (*rlwe.SecretKey, error)

func (*Session) GetSecretKey

func (sess *Session) GetSecretKey() (*rlwe.SecretKey, error)

GetSecretKey loads the secret key from the ObjectStore.

func (*Session) GetSecretKeyForGroup

func (sess *Session) GetSecretKeyForGroup(parties []NodeID) (sk *rlwe.SecretKey, err error)

func (*Session) GetSessionFromContext

func (sess *Session) GetSessionFromContext(ctx context.Context) (*Session, bool)

func (*Session) GetSessionFromID

func (sess *Session) GetSessionFromID(sessionID ID) (*Session, bool)

func (*Session) GetShamirPublicPoints

func (sess *Session) GetShamirPublicPoints() map[NodeID]drlwe.ShamirPublicPoint

func (*Session) GetShamirPublicPointsList

func (sess *Session) GetShamirPublicPointsList() []drlwe.ShamirPublicPoint

func (*Session) GetThresholdSecretKey

func (sess *Session) GetThresholdSecretKey() (*drlwe.ShamirSecretShare, error)

GetThresholdSecretKey loads the secret key from the ObjectStore.

func (*Session) String

func (sess *Session) String() string

type Store

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

func NewStore

func NewStore() *Store

func (*Store) GetSessionFromID

func (s *Store) GetSessionFromID(id ID) (*Session, bool)

func (*Store) NewRLWESession

func (s *Store) NewRLWESession(sessParams Parameters, nodeID NodeID) (sess *Session, err error)

type TestKeyProvider

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

TestKeyProvider is an implementation of a PublicKeyProvider that generates the keys on the fly, and is used for testing purposes. The implementation is not safe for concurrent use.

func NewTestKeyBackend

func NewTestKeyBackend(params rlwe.Parameters, skIdeal *rlwe.SecretKey) *TestKeyProvider

NewTestKeyBackend creates a new TestKeyProvider for the given parameters and ideal secret key.

func (*TestKeyProvider) GetCollectivePublicKey

func (tkb *TestKeyProvider) GetCollectivePublicKey(ctx context.Context) (*rlwe.PublicKey, error)

GetCollectivePublicKey returns the collective public key for the session in ctx.

func (*TestKeyProvider) GetGaloisKey

func (tkb *TestKeyProvider) GetGaloisKey(ctx context.Context, galEl uint64) (*rlwe.GaloisKey, error)

GetGaloisKey returns the galois key for the session in ctx and the given Galois element.

func (*TestKeyProvider) GetRelinearizationKey

func (tkb *TestKeyProvider) GetRelinearizationKey(ctx context.Context) (*rlwe.RelinearizationKey, error)

GetRelinearizationKey returns the relinearization key for the session in ctx.

type TestSession

type TestSession struct {
	SessParams    Parameters
	RlweParams    rlwe.Parameters
	SkIdeal       *rlwe.SecretKey
	NodeSessions  map[NodeID]*Session
	HelperSession *Session

	// key backend
	*CachedKeyBackend

	// lattigo helpers
	//Encoder   *bgv.Encoder
	Encryptor *rlwe.Encryptor
	Decrpytor *rlwe.Decryptor
}

func NewTestSession

func NewTestSession(N, T int, rlweparams FHEParamerersLiteralProvider, helperID NodeID) (*TestSession, error)

func NewTestSessionFromParams

func NewTestSessionFromParams(sp Parameters, helperID NodeID) (*TestSession, error)

Jump to

Keyboard shortcuts

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