mixcrypt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: BSD-3-Clause Imports: 13 Imported by: 6

Documentation

Overview

Package mixcrypt implements the client-mix-client message encryption.

Index

Constants

View Source
const (
	// MessageTypeForward is a message that is forwarded to another mix
	MessageTypeForward = 1 + iota
	// MessageTypeRelay is a message that is relayed to a recipient
	MessageTypeRelay
)
View Source
const KeySize = 32

KeySize is the size of a public/private key.

Variables

View Source
var (
	// ExpireReceive is the expiration time for incoming header uniqueness checks
	ExpireReceive = int64(172800)
	// ForwardMinSize is the minimum size of a forward message
	ForwardMinSize = 1024
	// ForwardMaxSize is the maximum size of a forward message
	ForwardMaxSize = 65536
	// RelayMinSize is the minimum size of a relay message
	RelayMinSize = 4096
	// RelayMaxSize is the maximum size of a relay message
	RelayMaxSize = 65536
)
View Source
var (
	// ErrNoKeys is returned if not enough keys are known
	ErrNoKeys = errors.New("mixcrypt: keys missing")
	// ErrTooShort is returned if a message is too short
	ErrTooShort = errors.New("mixcrypt: too short")
	// ErrSize is returned if a message is too long/short
	ErrSize = errors.New("mixcrypt: message out of bounds")
	// ErrBadSystem is returned if a message for a wrong system was received
	ErrBadSystem = errors.New("mixcrypt: bad system")
)
View Source
var MuteSystemDomain = "mute.one"

MuteSystemDomain is the domain of the Mute System.

View Source
var Rand = rand.Reader

Rand is the random source of this package.

Functions

func CalculateSharedSecret

func CalculateSharedSecret(peerPublicKey, myPrivateKey, nonceIn *[KeySize]byte) (secret, nonceOut *[KeySize]byte)

CalculateSharedSecret calculates a shared secret from the given parameters. If myPrivateKey is nil, it will return only nils. If Nonce is nil, a nonce will be created

func Decrypt

func Decrypt(lookupKey KeyFunc, encryptedData []byte) ([]byte, error)

Decrypt an envelope (Client-Mix) with CURVE25519-AES-GCM

func Encrypt

func Encrypt(peerPublicKey, myPrivateKey *[KeySize]byte, cleartextData []byte) ([]byte, error)

Encrypt an envelope (Client-Mix) with CURVE25519-AES-GCM

func ExpandSecret

func ExpandSecret(nonce, key []byte) *[KeySize]byte

ExpandSecret expands a nonce/key for multi-use encryption (unique nonces, constant keys)

func GCMDecrypt

func GCMDecrypt(nonce, key, encryptedData []byte) ([]byte, error)

GCMDecrypt data with AES-GCM

func GCMEncrypt

func GCMEncrypt(nonce, key, cleartextData []byte) ([]byte, error)

GCMEncrypt data with AES-GCM

func ReceiveFromMix

func ReceiveFromMix(receiveTemplate nymaddr.AddressTemplate, MailboxAddress, msg []byte) (decMessage, Nym []byte, err error)

ReceiveFromMix decrypts a message received from the mix

Types

type ClientMixHeader

type ClientMixHeader struct {
	MessageType                    int32 // The type of the message (forward/relay). Forward does not have NymAddress/RevokeID set
	SenderMinDelay, SenderMaxDelay int32
	Token                          []byte // Payment Token
	Address                        []byte // NymAddress for relay, next mix for forward
	RevokeID                       []byte // Revokation secret
}

ClientMixHeader contains fields meant by the Client for the Mix

func (ClientMixHeader) Marshal

func (cl ClientMixHeader) Marshal() []byte

Marshal a ClientMixHeader

func (*ClientMixHeader) NewForwardMessage

func (cl *ClientMixHeader) NewForwardMessage(NextHop string, NextHopKey *[KeySize]byte, msg []byte) (message []byte, deliverAddress string, err error)

NewForwardMessage creates a new message with type MessageTypeForward. Uses ClientMixHeader SenderMinDelay,SenderMaxDelay,Token

func (*ClientMixHeader) NewRelayMessage

func (cl *ClientMixHeader) NewRelayMessage(NymAddress []byte, msg []byte) (message []byte, deliverAddress string, err error)

NewRelayMessage creates a new message with type MessageTypeRelay. Uses ClientMixHeader SenderMinDelay,SenderMaxDelay,Token. Sets revokeID

func (*ClientMixHeader) Unmarshal

func (cl *ClientMixHeader) Unmarshal(d []byte) (header *ClientMixHeader, headerlen uint16, err error)

Unmarshal a binary ClientMixHeader. Returns header length to allow working with full-message slices

type KeyFunc

type KeyFunc func(*[KeySize]byte) *[KeySize]byte

KeyFunc is a function that returns a private key for a public key, or nil.

type ReceiveStruct

type ReceiveStruct struct {
	MixHeader         *ClientMixHeader
	NymAddress        *nymaddr.Address
	NymAddressPrivate *nymaddr.AddressPrivate
	UniqueTest        []UniquenessData
	Message           []byte
}

ReceiveStruct contains data gathered from receiving a message

func ReceiveMessage

func ReceiveMessage(lookupKey KeyFunc, message []byte) (*ReceiveStruct, error)

ReceiveMessage receives a Client-Mix message

func (ReceiveStruct) Send

func (rs ReceiveStruct) Send() ([]byte, string, error)

Send processes a ReceiveStruct and creates the outgoing message for it

type UniquenessData

type UniquenessData struct {
	Hash   []byte
	Expire int64
}

UniquenessData contains the hash and expire time for a uniqueness-check

Jump to

Keyboard shortcuts

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