io

package
v0.0.0-...-7ce9f83 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: Apache-2.0 Imports: 25 Imported by: 2

Documentation

Overview

Copyright (c) 2021-2023 - for information on the respective copyright owner see the NOTICE file and/or the repository https://github.com/carbynestack/ephemeral.

SPDX-License-Identifier: Apache-2.0

Copyright (c) 2021 - for information on the respective copyright owner see the NOTICE file and/or the repository https://github.com/carbynestack/ephemeral.

SPDX-License-Identifier: Apache-2.0

Copyright (c) 2021-2023 - for information on the respective copyright owner see the NOTICE file and/or the repository https://github.com/carbynestack/ephemeral.

SPDX-License-Identifier: Apache-2.0

Copyright (c) 2021 - for information on the respective copyright owner see the NOTICE file and/or the repository https://github.com/carbynestack/ephemeral.

SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const BodySize = 32

BodySize equals to 32 = 16 bytes secret share + 16 bytes MAC.

View Source
const ErrInvalidBodySize = "Body size must be a multiple of 32"

ErrInvalidBodySize is thrown when a message of invalid length is provided.

View Source
const ErrInvalidResponseSize = "Response size must be equal to 20"

ErrInvalidResponseSize is thrown when a message of invalid length is returned.

View Source
const ErrInvalidWordSize = "plain text message size must be a multiple of 16"

ErrInvalidWordSize is thrown when a SPDZ runtime socket response is not equal to word size.

View Source
const ErrMarshal = "at 1 object must be provided to marshal"

ErrMarshal is thrown when provided input is < 1.

View Source
const ErrParcelToSPDZ = "parcelsToSPDZ error: "

ErrParcelToSPDZ is thrown when an error in parcelsToSPDZ method has occured.

View Source
const ErrSPDZToParcel = "spdzToParcels error: "

ErrSPDZToParcel is thrown when an error in spdzToParcels method has occured.

View Source
const ErrSizeTooBig = "size array must be <= 32 bits"

ErrSizeTooBig is thrown when the size of the parameters is exceeded.

View Source
const MessageSize = 36

MessageSize equals to 36 = 4 bytes Length + 32 bytes of message

View Source
const ParcelSizeLength = 4

ParcelSizeLength is the length of the Parcel size header in bytes.

View Source
const ResponseSizeCipher = 36

ResponseSizeCipher is the size of a byte array containing plain text.

View Source
const WordSize = 16

WordSize is the size of a single word in SPDZ runtime notation, e.g. secret share or MAC.

Variables

View Source
var MaxLength = int(math.Pow(2, 32))

MaxLength is the max size of Param's octet.

Functions

func GetTupleFileName

func GetTupleFileName(tt castor.TupleType, conf *SPDZEngineTypedConfig, threadNr int) string

GetTupleFileName returns the filename for a given tuple type, spdz configuration and thread number

Types

type AbstractCarrier

type AbstractCarrier interface {
	Connect(context.Context, int32, string, string) error
	Close() error
	Send([]amphora.SecretShare) error
	Read(ResponseConverter, bool) (*Result, error)
}

AbstractCarrier is the carriers interface.

type AmphoraFeeder

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

AmphoraFeeder provides parameters to the SPDZ execution based on the given activation.

func NewAmphoraFeeder

func NewAmphoraFeeder(l *zap.SugaredLogger, conf *SPDZEngineTypedConfig) *AmphoraFeeder

NewAmphoraFeeder returns a new instance of amphora feeder.

func (*AmphoraFeeder) Close

func (f *AmphoraFeeder) Close() error

Close closes the underlying socket connection.

func (*AmphoraFeeder) LoadFromRequestAndFeed

func (f *AmphoraFeeder) LoadFromRequestAndFeed(act *Activation, feedPort string, ctx *CtxConfig) ([]byte, error)

LoadFromRequestAndFeed loads input parameteters from the request body.

func (*AmphoraFeeder) LoadFromSecretStoreAndFeed

func (f *AmphoraFeeder) LoadFromSecretStoreAndFeed(act *Activation, feedPort string, ctx *CtxConfig) ([]byte, error)

LoadFromSecretStoreAndFeed loads input parameters from Amphora.

type Carrier

type Carrier struct {
	Dialer func(ctx context.Context, addr, port string) (net.Conn, error)
	Conn   net.Conn
	Packer Packer

	Logger *zap.SugaredLogger
	// contains filtered or unexported fields
}

Carrier is a TCP client for TCP sockets.

func (*Carrier) Close

func (c *Carrier) Close() error

Close closes the underlying TCP connection.

func (*Carrier) Connect

func (c *Carrier) Connect(ctx context.Context, playerID int32, host string, port string) error

Connect establishes a TCP connection to a socket on a given host and port.

func (*Carrier) Read

func (c *Carrier) Read(conv ResponseConverter, bulkObjects bool) (*Result, error)

Read reads the response from the TCP connection and unmarshals it.

func (*Carrier) Send

func (c *Carrier) Send(secret []amphora.SecretShare) error

Send transmits Amphora secret shares to a TCP socket opened by an MPC runtime.

type CastorTupleStreamer

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

CastorTupleStreamer provides tuples to the SPDZ execution for the given type and configuration.

func NewCastorTupleStreamer

func NewCastorTupleStreamer(l *zap.SugaredLogger, tt castor.TupleType, conf *SPDZEngineTypedConfig, playerDataDir string, gameID uuid.UUID, threadNr int) (*CastorTupleStreamer, error)

NewCastorTupleStreamer returns a new instance of castor tuple streamer.

func NewCastorTupleStreamerWithWriterFactory

func NewCastorTupleStreamerWithWriterFactory(l *zap.SugaredLogger, tt castor.TupleType, conf *SPDZEngineTypedConfig, playerDataDir string, gameID uuid.UUID, threadNr int, pipeWriterFactory PipeWriterFactory) (*CastorTupleStreamer, error)

NewCastorTupleStreamerWithWriterFactory returns a new instance of castor tuple streamer.

func (*CastorTupleStreamer) StartStreamTuples

func (ts *CastorTupleStreamer) StartStreamTuples(terminateCh chan struct{}, errCh chan error, wg *sync.WaitGroup)

StartStreamTuples repeatedly downloads a given type of tuples from castor and streams it to the according file as required by MP-SPDZ

type ConnectionInfo

type ConnectionInfo struct {
	Host string
	Port string
}

type Feeder

type Feeder interface {
	LoadFromSecretStoreAndFeed(act *Activation, feedPort string, ctx *CtxConfig) ([]byte, error)
	LoadFromRequestAndFeed(act *Activation, feedPort string, ctx *CtxConfig) ([]byte, error)
	Close() error
}

Feeder is an interface.

type Packer

type Packer interface {
	Marshal([]string, *[]byte) error
	Unmarshal(*[]byte, ResponseConverter, bool) ([]string, error)
}

Packer is an interface to marshal and unmarshal strings to the format specified by a given MPC runtime.

type Parcel

type Parcel struct {
	Size       []byte
	Body       []byte
	BodyBase64 string
}

Parcel is an internal representation of a message consumed by SPDZ.

type PipeWriter

type PipeWriter interface {
	Open() error
	Write(data []byte) (int, error)
	Close() error
}

PipeWriter provides methods to access and write to pipes

func DefaultPipeWriterFactory

func DefaultPipeWriterFactory(l *zap.SugaredLogger, filePath string, writeDeadline time.Duration) (PipeWriter, error)

DefaultPipeWriterFactory constructs a new PipeWriter instance

type PipeWriterFactory

type PipeWriterFactory func(l *zap.SugaredLogger, filePath string, writeDeadline time.Duration) (PipeWriter, error)

PipeWriterFactory is a factory method to create new PipeWriter.

It accepts a logger, filepath of the pipe to write to and a deadline for write operations. It either returns a PipeWriter or an error if creation failed.

type PlaintextConverter

type PlaintextConverter struct {
	Params []interface{}
}

PlaintextConverter expects plain-text response from SPDZ and converts it into a human readable base64 encoded int64 param. base64 encoding is used to comply with the format we use when storing objects in Amphora.

type ResponseConverter

type ResponseConverter interface {
	// contains filtered or unexported methods
}

ResponseConverter is an interface for a struct that mutates the response from SPDZ runtime to a required format.

type Result

type Result struct {
	Response []string `json:"response"`
}

Result contains the response from SPDZ runtime computation.

type SPDZPacker

type SPDZPacker struct {
	// maxBulkSize is the maximum size of bulk objects received as parameters.
	MaxBulkSize int32
}

SPDZPacker is an implementation of Packer interface for SPDZ runtime.

func (*SPDZPacker) Marshal

func (p *SPDZPacker) Marshal(b64 []string, dst *[]byte) (err error)

Marshal converts a base64 encoded string into a byte array consumable by SPDZ runtime.

func (*SPDZPacker) Unmarshal

func (p *SPDZPacker) Unmarshal(in *[]byte, conv ResponseConverter, bulkSecrets bool) ([]string, error)

Unmarshal converts a byte sequence to a base64 encoded secret share representation consumable by Amphora.

type SecretSharesConverter

type SecretSharesConverter struct {
	Params []interface{}
}

SecretSharesConverter is to be used for encoding base64 secret shared responses received from SPDZ runtime.

type TuplePipeWriter

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

TuplePipeWriter implements PipeWriter

func NewTuplePipeWriter

func NewTuplePipeWriter(l *zap.SugaredLogger, filePath string, writeDeadline time.Duration) (*TuplePipeWriter, error)

NewTuplePipeWriter returns a new TuplePipeWriter with the given configuration. It will create a new pipe with the given path. If a file with this path already exists, it will be deleted first.

func (*TuplePipeWriter) Close

func (tpw *TuplePipeWriter) Close() error

Close calls File.Close() on the tuple file pipe

func (*TuplePipeWriter) Open

func (tpw *TuplePipeWriter) Open() error

Open opens a file as write only pipe.

This function should be called within a go routine as opening a pipe as write-only is a blocking call until opposing side opens the file to read. This is especially important when streaming tuples to MP-SPDZ, as it does open only those tuple files that are actually required for the current computation.

func (*TuplePipeWriter) Write

func (tpw *TuplePipeWriter) Write(data []byte) (int, error)

Write writes the given data to the underlying tuple file pipe.

**Note:** Make sure to call Open() first.

type TupleStreamer

type TupleStreamer interface {
	StartStreamTuples(terminateCh chan struct{}, errCh chan error, wg *sync.WaitGroup)
}

TupleStreamer is an interface.

Jump to

Keyboard shortcuts

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