mpctest

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mpctest provides insecure transport helpers for tests and local demos.

WARNING: This package is not a production transport. The in-memory helpers provide no authentication, no confidentiality, and no cross-process networking. Production applications should implement `mpc.Transport` with an authenticated and confidential transport such as mTLS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaliciousBehavior

type MaliciousBehavior struct {
	// DropAllSends drops all outgoing messages (simulates a network partition).
	DropAllSends bool

	// DropAllReceives fails all receive operations.
	DropAllReceives bool

	// CorruptMessages modifies message contents before sending.
	CorruptMessages bool

	// SendWrongSize sends messages with incorrect size.
	SendWrongSize bool

	// FailAfterNSends fails after N send operations.
	FailAfterNSends int

	// FailAfterNReceives fails after N receive operations.
	FailAfterNReceives int

	// SendEmptyMessages sends empty messages instead of real data.
	SendEmptyMessages bool

	// SendGarbage sends all-0xFF garbage instead of protocol messages.
	SendGarbage bool

	// ReplayFirstMessage replays the first sent message repeatedly.
	ReplayFirstMessage bool

	// FlipRandomBits flips a bit in the middle of the message.
	FlipRandomBits bool
	// contains filtered or unexported fields
}

MaliciousBehavior defines what kind of malicious action to perform.

type MaliciousTransport

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

MaliciousTransport wraps a normal transport with adversarial behavior for tests.

func NewMaliciousTransport

func NewMaliciousTransport(inner Transport, behavior MaliciousBehavior) *MaliciousTransport

NewMaliciousTransport wraps a transport with malicious behavior.

func (*MaliciousTransport) Close

func (m *MaliciousTransport) Close() error

Close implements Transport.Close.

func (*MaliciousTransport) MyIndex

func (m *MaliciousTransport) MyIndex() int

MyIndex exposes the wrapped transport's local index when available.

func (*MaliciousTransport) PartyCount

func (m *MaliciousTransport) PartyCount() int

PartyCount exposes the wrapped transport's party count when available.

func (*MaliciousTransport) Receive

func (m *MaliciousTransport) Receive(ctx context.Context, fromParty int) ([]byte, error)

Receive implements Transport.Receive with malicious behavior.

func (*MaliciousTransport) ReceiveAll

func (m *MaliciousTransport) ReceiveAll(ctx context.Context, fromParties []int) ([][]byte, error)

ReceiveAll implements Transport.ReceiveAll with malicious behavior.

func (*MaliciousTransport) Send

func (m *MaliciousTransport) Send(ctx context.Context, toParty int, msg []byte) error

Send implements Transport.Send with malicious behavior.

type MockTransport

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

MockTransport provides an in-memory transport implementation for tests and local demos. It intentionally provides no authentication or confidentiality.

func NewMockNetwork

func NewMockNetwork(nParties int) []*MockTransport

NewMockNetwork creates a complete mock network for tests and local demos. It returns a slice of MockTransport instances, one for each party.

func NewMockTransport

func NewMockTransport(myIndex int) *MockTransport

NewMockTransport creates a new MockTransport for the specified party index.

func (*MockTransport) Close

func (s *MockTransport) Close() error

Close closes the session and unblocks any waiting receives.

func (*MockTransport) MyIndex

func (s *MockTransport) MyIndex() int

MyIndex returns this party's index.

func (*MockTransport) PartyCount

func (s *MockTransport) PartyCount() int

PartyCount returns the total number of parties.

func (*MockTransport) Receive

func (s *MockTransport) Receive(ctx context.Context, fromParty int) ([]byte, error)

Receive receives a message from the specified party (blocking).

func (*MockTransport) ReceiveAll

func (s *MockTransport) ReceiveAll(ctx context.Context, fromParties []int) ([][]byte, error)

ReceiveAll receives messages from multiple parties concurrently.

func (*MockTransport) Send

func (s *MockTransport) Send(_ context.Context, toParty int, msg []byte) error

Send sends a message to the specified party.

type Transport

type Transport interface {
	io.Closer
	Send(ctx context.Context, toParty int, msg []byte) error
	Receive(ctx context.Context, fromParty int) ([]byte, error)
	ReceiveAll(ctx context.Context, fromParties []int) ([][]byte, error)
}

Transport mirrors the network contract used by interactive MPC protocols. Concrete types in this package also satisfy `mpc.Transport`.

func NewMaliciousNetwork

func NewMaliciousNetwork(nParties int, maliciousParty int, behavior MaliciousBehavior) []Transport

NewMaliciousNetwork creates a mock network where one party is malicious.

Jump to

Keyboard shortcuts

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