sphinx

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const (
	FieldElementSize = 32
	PrivateKeySize   = FieldElementSize
	PublicKeySize    = FieldElementSize
)
View Source
const (
	// K TODO: document padding-related Sphinx parameter
	K = 16
)

Variables

This section is empty.

Functions

func AesCtr

func AesCtr(key, plaintext []byte) ([]byte, error)

AesCtr returns AES XOR ciphertext in counter mode for the given key and plaintext

func BytesToString

func BytesToString(b []byte) string

BytesToString converts the given bytes to a string.

func CompareElements

func CompareElements(e1, e2 CryptoElement) bool

func GenerateKeyPair

func GenerateKeyPair() (*PrivateKey, *PublicKey, error)

GenerateKeyPair returns public and private keypair bytes for Curve25519 elliptic curve, or an error.

func Hmac

func Hmac(key, message []byte) ([]byte, error)

Hmac computes a hash-based message authentication code for a given key and message. Returns a byte array containing the MAC checksum.

func KDF

func KDF(key []byte) ([]byte, error)

KDF returns the hash of K for a given key

func ProcessSphinxHeader

func ProcessSphinxHeader(packet Header, privKey *PrivateKey) (Hop, Commands, Header, error)

ProcessSphinxHeader unwraps one layer of encryption from the header of a sphinx packet. ProcessSphinxHeader recomputes the shared key and checks whether the message authentication code is valid. If not, the packet is dropped and error is returned. If MAC checking was passed successfully ProcessSphinxHeader performs the AES_CTR decryption, recomputes the blinding factor and updates the init public element from the header. Next, ProcessSphinxHeader extracts the routing information from the decrypted packet and returns it, together with the updated init public element. If any crypto or parsing operation failed ProcessSphinxHeader returns an error.

func ProcessSphinxPacket

func ProcessSphinxPacket(packetBytes []byte, privKey *PrivateKey) (Hop, Commands, []byte, error)

ProcessSphinxPacket processes the sphinx packet using the given private key. ProcessSphinxPacket unwraps one layer of both the header and the payload encryption. ProcessSphinxPacket returns a new packet and the routing information which should be used by the processing node. If any cryptographic or parsing operation failed ProcessSphinxPacket returns an error.

func ProcessSphinxPayload

func ProcessSphinxPayload(alpha []byte, payload []byte, privKey *PrivateKey) ([]byte, error)

ProcessSphinxPayload unwraps a single layer of the encryption from the sphinx packet payload. ProcessSphinxPayload first recomputes the shared secret which is used to perform the AES_CTR decryption. ProcessSphinxPayload returns the new packet payload or an error if the decryption failed.

func XorBytes

func XorBytes(b1, b2 []byte) []byte

XorBytes does an XOR bitflip operation on the supplied bytes parameters and returns the result

Types

type Commands

type Commands struct {
	Delay                float64  `protobuf:"fixed64,1,opt,name=Delay,json=delay,proto3" json:"Delay,omitempty"`
	Flag                 []byte   `protobuf:"bytes,2,opt,name=Flag,json=flag,proto3" json:"Flag,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Commands) Descriptor

func (*Commands) Descriptor() ([]byte, []int)

func (*Commands) GetDelay

func (m *Commands) GetDelay() float64

func (*Commands) GetFlag

func (m *Commands) GetFlag() []byte

func (*Commands) ProtoMessage

func (*Commands) ProtoMessage()

func (*Commands) Reset

func (m *Commands) Reset()

func (*Commands) String

func (m *Commands) String() string

func (*Commands) XXX_DiscardUnknown

func (m *Commands) XXX_DiscardUnknown()

func (*Commands) XXX_Marshal

func (m *Commands) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Commands) XXX_Merge

func (m *Commands) XXX_Merge(src proto.Message)

func (*Commands) XXX_Size

func (m *Commands) XXX_Size() int

func (*Commands) XXX_Unmarshal

func (m *Commands) XXX_Unmarshal(b []byte) error

type CryptoElement

type CryptoElement interface {
	Bytes() []byte
}

TODO: better name

type FieldElement

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

func BytesToFieldElement

func BytesToFieldElement(b []byte) *FieldElement

func RandomElement

func RandomElement() (*FieldElement, error)

func (*FieldElement) Bytes

func (fe *FieldElement) Bytes() []byte
type Header struct {
	Alpha                []byte   `protobuf:"bytes,1,opt,name=Alpha,json=alpha,proto3" json:"Alpha,omitempty"`
	Beta                 []byte   `protobuf:"bytes,2,opt,name=Beta,json=beta,proto3" json:"Beta,omitempty"`
	Mac                  []byte   `protobuf:"bytes,3,opt,name=Mac,json=mac,proto3" json:"Mac,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Header) Descriptor

func (*Header) Descriptor() ([]byte, []int)

func (*Header) GetAlpha

func (m *Header) GetAlpha() []byte

func (*Header) GetBeta

func (m *Header) GetBeta() []byte

func (*Header) GetMac

func (m *Header) GetMac() []byte

func (*Header) ProtoMessage

func (*Header) ProtoMessage()

func (*Header) Reset

func (m *Header) Reset()

func (*Header) String

func (m *Header) String() string

func (*Header) XXX_DiscardUnknown

func (m *Header) XXX_DiscardUnknown()

func (*Header) XXX_Marshal

func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Header) XXX_Merge

func (m *Header) XXX_Merge(src proto.Message)

func (*Header) XXX_Size

func (m *Header) XXX_Size() int

func (*Header) XXX_Unmarshal

func (m *Header) XXX_Unmarshal(b []byte) error

type HeaderInitials

type HeaderInitials struct {
	Alpha                []byte   `protobuf:"bytes,1,opt,name=Alpha,json=alpha,proto3" json:"Alpha,omitempty"`
	Secret               []byte   `protobuf:"bytes,2,opt,name=Secret,json=secret,proto3" json:"Secret,omitempty"`
	Blinder              []byte   `protobuf:"bytes,3,opt,name=Blinder,json=blinder,proto3" json:"Blinder,omitempty"`
	SecretHash           []byte   `protobuf:"bytes,4,opt,name=SecretHash,json=secretHash,proto3" json:"SecretHash,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*HeaderInitials) Descriptor

func (*HeaderInitials) Descriptor() ([]byte, []int)

func (*HeaderInitials) GetAlpha

func (m *HeaderInitials) GetAlpha() []byte

func (*HeaderInitials) GetBlinder

func (m *HeaderInitials) GetBlinder() []byte

func (*HeaderInitials) GetSecret

func (m *HeaderInitials) GetSecret() []byte

func (*HeaderInitials) GetSecretHash

func (m *HeaderInitials) GetSecretHash() []byte

func (*HeaderInitials) ProtoMessage

func (*HeaderInitials) ProtoMessage()

func (*HeaderInitials) Reset

func (m *HeaderInitials) Reset()

func (*HeaderInitials) String

func (m *HeaderInitials) String() string

func (*HeaderInitials) XXX_DiscardUnknown

func (m *HeaderInitials) XXX_DiscardUnknown()

func (*HeaderInitials) XXX_Marshal

func (m *HeaderInitials) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HeaderInitials) XXX_Merge

func (m *HeaderInitials) XXX_Merge(src proto.Message)

func (*HeaderInitials) XXX_Size

func (m *HeaderInitials) XXX_Size() int

func (*HeaderInitials) XXX_Unmarshal

func (m *HeaderInitials) XXX_Unmarshal(b []byte) error

type Hop

type Hop struct {
	Id                   string   `protobuf:"bytes,1,opt,name=Id,json=id,proto3" json:"Id,omitempty"`
	Address              string   `protobuf:"bytes,2,opt,name=Address,json=address,proto3" json:"Address,omitempty"`
	PubKey               []byte   `protobuf:"bytes,3,opt,name=PubKey,json=pubKey,proto3" json:"PubKey,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Hop) Descriptor

func (*Hop) Descriptor() ([]byte, []int)

func (*Hop) GetAddress

func (m *Hop) GetAddress() string

func (*Hop) GetId

func (m *Hop) GetId() string

func (*Hop) GetPubKey

func (m *Hop) GetPubKey() []byte

func (*Hop) ProtoMessage

func (*Hop) ProtoMessage()

func (*Hop) Reset

func (m *Hop) Reset()

func (*Hop) String

func (m *Hop) String() string

func (*Hop) XXX_DiscardUnknown

func (m *Hop) XXX_DiscardUnknown()

func (*Hop) XXX_Marshal

func (m *Hop) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Hop) XXX_Merge

func (m *Hop) XXX_Merge(src proto.Message)

func (*Hop) XXX_Size

func (m *Hop) XXX_Size() int

func (*Hop) XXX_Unmarshal

func (m *Hop) XXX_Unmarshal(b []byte) error

type PrivateKey

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

TODO: redefine private and public keys to be interfaces instead?

func BytesToPrivateKey

func BytesToPrivateKey(b []byte) *PrivateKey

func (*PrivateKey) Bytes

func (pk *PrivateKey) Bytes() []byte

func (*PrivateKey) MarshalBinary

func (pk *PrivateKey) MarshalBinary() ([]byte, error)

MarshalBinary is an implementation of a method on the BinaryMarshaler interface defined in https://golang.org/pkg/encoding/

func (*PrivateKey) ToFieldElement

func (pk *PrivateKey) ToFieldElement() *FieldElement

func (*PrivateKey) UnmarshalBinary

func (pk *PrivateKey) UnmarshalBinary(data []byte) error

UnmarshalBinary is an implementation of a method on the BinaryUnmarshaler interface defined in https://golang.org/pkg/encoding/

type PublicKey

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

func BytesToPublicKey

func BytesToPublicKey(b []byte) *PublicKey

func (*PublicKey) Bytes

func (pub *PublicKey) Bytes() []byte

func (*PublicKey) MarshalBinary

func (pub *PublicKey) MarshalBinary() ([]byte, error)

MarshalBinary is an implementation of a method on the BinaryMarshaler interface defined in https://golang.org/pkg/encoding/

func (*PublicKey) ToFieldElement

func (pub *PublicKey) ToFieldElement() *FieldElement

func (*PublicKey) UnmarshalBinary

func (pub *PublicKey) UnmarshalBinary(data []byte) error

UnmarshalBinary is an implementation of a method on the BinaryUnmarshaler interface defined in https://golang.org/pkg/encoding/

type RoutingInfo

type RoutingInfo struct {
	NextHop              *Hop      `protobuf:"bytes,1,opt,name=NextHop,json=nextHop,proto3" json:"NextHop,omitempty"`
	RoutingCommands      *Commands `protobuf:"bytes,2,opt,name=RoutingCommands,json=routingCommands,proto3" json:"RoutingCommands,omitempty"`
	NextHopMetaData      []byte    `protobuf:"bytes,3,opt,name=NextHopMetaData,json=nextHopMetaData,proto3" json:"NextHopMetaData,omitempty"`
	Mac                  []byte    `protobuf:"bytes,4,opt,name=Mac,json=mac,proto3" json:"Mac,omitempty"`
	XXX_NoUnkeyedLiteral struct{}  `json:"-"`
	XXX_unrecognized     []byte    `json:"-"`
	XXX_sizecache        int32     `json:"-"`
}

func (*RoutingInfo) Descriptor

func (*RoutingInfo) Descriptor() ([]byte, []int)

func (*RoutingInfo) GetMac

func (m *RoutingInfo) GetMac() []byte

func (*RoutingInfo) GetNextHop

func (m *RoutingInfo) GetNextHop() *Hop

func (*RoutingInfo) GetNextHopMetaData

func (m *RoutingInfo) GetNextHopMetaData() []byte

func (*RoutingInfo) GetRoutingCommands

func (m *RoutingInfo) GetRoutingCommands() *Commands

func (*RoutingInfo) ProtoMessage

func (*RoutingInfo) ProtoMessage()

func (*RoutingInfo) Reset

func (m *RoutingInfo) Reset()

func (*RoutingInfo) String

func (m *RoutingInfo) String() string

func (*RoutingInfo) XXX_DiscardUnknown

func (m *RoutingInfo) XXX_DiscardUnknown()

func (*RoutingInfo) XXX_Marshal

func (m *RoutingInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RoutingInfo) XXX_Merge

func (m *RoutingInfo) XXX_Merge(src proto.Message)

func (*RoutingInfo) XXX_Size

func (m *RoutingInfo) XXX_Size() int

func (*RoutingInfo) XXX_Unmarshal

func (m *RoutingInfo) XXX_Unmarshal(b []byte) error

type SphinxPacket

type SphinxPacket struct {
	Hdr                  *Header  `protobuf:"bytes,1,opt,name=Hdr,json=hdr,proto3" json:"Hdr,omitempty"`
	Pld                  []byte   `protobuf:"bytes,2,opt,name=Pld,json=pld,proto3" json:"Pld,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func PackForwardMessage

func PackForwardMessage(path config.E2EPath, delays []float64, message []byte) (SphinxPacket, error)

PackForwardMessage encapsulates the given message into the cryptographic Sphinx packet format. As arguments the function takes the path, consisting of the sequence of nodes the packet should traverse and the destination of the message, a set of delays and the information about the curve used to perform cryptographic operations. In order to encapsulate the message PackForwardMessage computes two parts of the packet - the header and the encrypted payload. If creating of any of the packet block failed, an error is returned. Otherwise, a Sphinx packet format is returned.

func (*SphinxPacket) Descriptor

func (*SphinxPacket) Descriptor() ([]byte, []int)

func (*SphinxPacket) GetHdr

func (m *SphinxPacket) GetHdr() *Header

func (*SphinxPacket) GetPld

func (m *SphinxPacket) GetPld() []byte

func (*SphinxPacket) ProtoMessage

func (*SphinxPacket) ProtoMessage()

func (*SphinxPacket) Reset

func (m *SphinxPacket) Reset()

func (*SphinxPacket) String

func (m *SphinxPacket) String() string

func (*SphinxPacket) XXX_DiscardUnknown

func (m *SphinxPacket) XXX_DiscardUnknown()

func (*SphinxPacket) XXX_Marshal

func (m *SphinxPacket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SphinxPacket) XXX_Merge

func (m *SphinxPacket) XXX_Merge(src proto.Message)

func (*SphinxPacket) XXX_Size

func (m *SphinxPacket) XXX_Size() int

func (*SphinxPacket) XXX_Unmarshal

func (m *SphinxPacket) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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