ot

package
v0.0.0-...-ab9a4cd Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 11 Imported by: 1

README

Oblivious Transfer

This module implements the Oblivous Transfer with the following algorithms:

  • RSA: simple RSA encryption based OT. Each transfer requires one RSA operation.
  • Chou Orlandi OT: Diffie-Hellman - like fast OT algorithm.

Performance

Algorithm ns/op ops/s
RSA-512 252557 3960
RSA-1024 1256961 796
RSA-2048 7785958 128
CO-batch-1 170791 5855
CO-batch-2 269399 7424
CO-batch-4 468161 8544
CO-batch-8 877664 9115
CO-batch-16 1706184 9378
CO-batch-32 3273137 9777
CO-batch-64 6480310 9876
CO-batch-128 12845639 9964

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPipe

func NewPipe() (*Pipe, *Pipe)

NewPipe creates a new in-memory pipe.

func RandomData

func RandomData(size int) ([]byte, error)

RandomData creates size bytes of random data.

func ReceiveBigInt

func ReceiveBigInt(io IO) (*big.Int, error)

ReceiveBigInt receives a bit.Int from the connection.

func ReceiveString

func ReceiveString(io IO) (string, error)

ReceiveString receives a string value.

func SendString

func SendString(io IO, str string) error

SendString sends a string value.

Types

type CO

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

CO implements CO OT as the OT interface.

func NewCO

func NewCO() *CO

NewCO creates a new CO OT implementing the OT interface.

func (*CO) InitReceiver

func (co *CO) InitReceiver(io IO) error

InitReceiver initializes the OT receiver.

func (*CO) InitSender

func (co *CO) InitSender(io IO) error

InitSender initializes the OT sender.

func (*CO) Receive

func (co *CO) Receive(flags []bool, result []Label) error

Receive receives the wire labels with OT based on the flag values.

func (*CO) Send

func (co *CO) Send(wires []Wire) error

Send sends the wire labels with OT.

type COReceiver

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

COReceiver implements CO OT receiver.

func NewCOReceiver

func NewCOReceiver(curve elliptic.Curve) *COReceiver

NewCOReceiver creates a new OT receiver.

func (*COReceiver) NewTransfer

func (r *COReceiver) NewTransfer(bit uint) (*COReceiverXfer, error)

NewTransfer creates a new OT transfer for the selection bit.

type COReceiverXfer

type COReceiverXfer struct {
	Bx  *big.Int
	By  *big.Int
	Asx *big.Int
	Asy *big.Int
	// contains filtered or unexported fields
}

COReceiverXfer implements receiver OT transfer.

func (*COReceiverXfer) B

func (r *COReceiverXfer) B() (x, y []byte)

B returns receiver's selection.

func (*COReceiverXfer) ReceiveA

func (r *COReceiverXfer) ReceiveA(x, y []byte)

ReceiveA receives sender's random value.

func (*COReceiverXfer) ReceiveE

func (r *COReceiverXfer) ReceiveE(e0, e1 []byte) []byte

ReceiveE receives encrypted messages from the sender and returns the result value.

type COSender

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

COSender implements CO OT sender.

func NewCOSender

func NewCOSender() *COSender

NewCOSender creates a new CO OT sender.

func (*COSender) Curve

func (s *COSender) Curve() elliptic.Curve

Curve returns sender's elliptic curve.

func (*COSender) NewTransfer

func (s *COSender) NewTransfer(m0, m1 []byte) (*COSenderXfer, error)

NewTransfer creates a new OT transfer for the values.

type COSenderXfer

type COSenderXfer struct {
	Ax     *big.Int
	Ay     *big.Int
	AaInvx *big.Int
	AaInvy *big.Int
	// contains filtered or unexported fields
}

COSenderXfer implements sender OT transfer.

func (*COSenderXfer) A

func (s *COSenderXfer) A() (x, y []byte)

A returns sender's random value.

func (*COSenderXfer) E

func (s *COSenderXfer) E() (e0, e1 []byte)

E returns sender's encrypted messages.

func (*COSenderXfer) ReceiveB

func (s *COSenderXfer) ReceiveB(x, y []byte)

ReceiveB receives receiver's selection.

type IO

type IO interface {
	// SendByte sends a byte value.
	SendByte(val byte) error

	// SendUint32 sends an uint32 value.
	SendUint32(val int) error

	// SendData sends binary data.
	SendData(val []byte) error

	// Flush flushed any pending data in the connection.
	Flush() error

	// ReceiveByte receives a byte value.
	ReceiveByte() (byte, error)

	// ReceiveUint32 receives an uint32 value.
	ReceiveUint32() (int, error)

	// ReceiveData receives binary data.
	ReceiveData() ([]byte, error)
}

IO defines an I/O interface to communicate between peers.

type Label

type Label struct {
	D0 uint64
	D1 uint64
}

Label implements a 128 bit wire label.

func NewLabel

func NewLabel(rand io.Reader) (Label, error)

NewLabel creates a new random label.

func NewTweak

func NewTweak(tweak uint32) Label

NewTweak creates a new label from the tweak value.

func (Label) Bytes

func (l Label) Bytes(buf *LabelData) []byte

Bytes returns the label data as bytes.

func (Label) Equal

func (l Label) Equal(o Label) bool

Equal test if the labels are equal.

func (Label) GetData

func (l Label) GetData(buf *LabelData)

GetData gets the labels as label data.

func (*Label) Mul2

func (l *Label) Mul2()

Mul2 multiplies the label by 2.

func (*Label) Mul4

func (l *Label) Mul4()

Mul4 multiplies the label by 4.

func (Label) S

func (l Label) S() bool

S tests the label's S bit.

func (*Label) SetBytes

func (l *Label) SetBytes(data []byte)

SetBytes sets the label data from bytes.

func (*Label) SetData

func (l *Label) SetData(data *LabelData)

SetData sets the labels from label data.

func (*Label) SetS

func (l *Label) SetS(set bool)

SetS sets the label's S bit.

func (Label) String

func (l Label) String() string

func (*Label) Xor

func (l *Label) Xor(o Label)

Xor xors the label with the argument label.

type LabelData

type LabelData [16]byte

LabelData contains lable data as byte array.

type OT

type OT interface {
	// InitSender initializes the OT sender.
	InitSender(io IO) error

	// InitReceiver initializes the OT receiver.
	InitReceiver(io IO) error

	// Send sends the wire labels with OT.
	Send(wires []Wire) error

	// Receive receives the wire labels with OT based on the flag values.
	Receive(flags []bool, result []Label) error
}

OT defines Oblivious Transfer protocol.

type Pipe

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

Pipe implements the IO interface with in-memory io.Pipe.

func (*Pipe) Close

func (p *Pipe) Close() error

Close closes the pipe.

func (*Pipe) Drain

func (p *Pipe) Drain() error

Drain consumes all input from the pipe.

func (*Pipe) Flush

func (p *Pipe) Flush() error

Flush flushed any pending data in the connection.

func (*Pipe) ReceiveByte

func (p *Pipe) ReceiveByte() (byte, error)

ReceiveByte receives a byte value.

func (*Pipe) ReceiveData

func (p *Pipe) ReceiveData() ([]byte, error)

ReceiveData receives binary data.

func (*Pipe) ReceiveUint32

func (p *Pipe) ReceiveUint32() (int, error)

ReceiveUint32 receives an uint32 value.

func (*Pipe) SendByte

func (p *Pipe) SendByte(val byte) error

SendByte sends a byte value.

func (*Pipe) SendData

func (p *Pipe) SendData(val []byte) error

SendData sends binary data.

func (*Pipe) SendUint32

func (p *Pipe) SendUint32(val int) error

SendUint32 sends an uint32 value.

type RSA

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

RSA implements RSA OT as the OT interface.

func NewRSA

func NewRSA(keyBits int) *RSA

NewRSA creates a new RSA OT implementing the OT interface. The argument specifies the RSA key size in bits.

func (*RSA) InitReceiver

func (r *RSA) InitReceiver(io IO) error

InitReceiver initializes the OT receiver.

func (*RSA) InitSender

func (r *RSA) InitSender(io IO) error

InitSender initializes the OT sender.

func (*RSA) Receive

func (r *RSA) Receive(flags []bool, result []Label) error

Receive receives the wire labels with OT based on the flag values.

func (*RSA) Send

func (r *RSA) Send(wires []Wire) error

Send sends the wire labels with OT.

type Receiver

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

Receiver implements OT receivers.

func NewReceiver

func NewReceiver(pub *rsa.PublicKey) (*Receiver, error)

NewReceiver creates a new OT receiver.

func (*Receiver) MessageSize

func (r *Receiver) MessageSize() int

MessageSize returns the maximum OT message size.

func (*Receiver) NewTransfer

func (r *Receiver) NewTransfer(bit uint) (*ReceiverXfer, error)

NewTransfer creates a new OT receiver data transfer for the bit.

type ReceiverXfer

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

ReceiverXfer implements the OT receiver data transfer.

func (*ReceiverXfer) Message

func (r *ReceiverXfer) Message() (m []byte, bit uint)

Message returns the message and bit from the exchange.

func (*ReceiverXfer) ReceiveMessages

func (r *ReceiverXfer) ReceiveMessages(m0p, m1p []byte, err error) error

ReceiveMessages processes the received m0p and m1p messages.

func (*ReceiverXfer) ReceiveRandomMessages

func (r *ReceiverXfer) ReceiveRandomMessages(x0, x1 []byte) error

ReceiveRandomMessages receives the random messages x0 and x1.

func (*ReceiverXfer) V

func (r *ReceiverXfer) V() []byte

V returns the V of the exchange.

type Sender

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

Sender implements OT sender.

func NewSender

func NewSender(keyBits int) (*Sender, error)

NewSender creates a new OT sender for the bit.

func (*Sender) MessageSize

func (s *Sender) MessageSize() int

MessageSize returns the maximum OT message size.

func (*Sender) NewTransfer

func (s *Sender) NewTransfer(m0, m1 []byte) (*SenderXfer, error)

NewTransfer creates a new OT sender data transfer.

func (*Sender) PublicKey

func (s *Sender) PublicKey() *rsa.PublicKey

PublicKey returns the sender's public key.

type SenderXfer

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

SenderXfer implements the OT sender data transfer.

func (*SenderXfer) MessageSize

func (s *SenderXfer) MessageSize() int

MessageSize returns the maximum OT message size.

func (*SenderXfer) Messages

func (s *SenderXfer) Messages() ([]byte, []byte, error)

Messages creates the transfer messages.

func (*SenderXfer) RandomMessages

func (s *SenderXfer) RandomMessages() ([]byte, []byte)

RandomMessages creates random messages.

func (*SenderXfer) ReceiveV

func (s *SenderXfer) ReceiveV(data []byte)

ReceiveV receives the V.

type Wire

type Wire struct {
	L0 Label
	L1 Label
}

Wire implements a wire with 0 and 1 labels.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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