messages

package
v0.0.0-...-bdd61b6 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MaxShareSize = 256

MaxShareSize is the maximum size of an embedded share

View Source
const OracleMessageEncType = 0xf0
View Source
const OracleMessageEnvelopeType = 1020
View Source
const OracleMsgContainerTypeID = 1080
View Source
const OracleMsgTypeID = 1098
View Source
const OracleResponseMessageType = 1021
View Source
const SetSemaphoreMsgTypeID = 1001
View Source
const ShareMsgDecryptBufferSize = shareMsgPadTotal

ShareMsgDecryptBufferSize is the size of the decryption buffer

View Source
const ShareMsgEncryptBufferSize = shareMsgPadTotal + ShareMsgSize

ShareMsgEncryptBufferSize is the size of the encryption buffer

View Source
const ShareMsgPadSize = 512

ShareMsgPadSize is the size to which the ShareMsg will be padded

View Source
const ShareMsgSize = shareMsgPadTotal + symmetriccrypto.EncryptionOverhead

ShareMsgSize is the size of an encrypted ShareMsg

View Source
const ShareMsgTypeID = 1002

Variables

View Source
var (
	ErrTimePolicy           = errors.New("oracle: Time policy")
	ErrSignalSet            = errors.New("oracle: Signal is set")
	ErrWrongResponseKey     = errors.New("oracle: Wrong response key")
	ErrUnhandledMessageType = errors.New("oracle: Unhandled message type")
)
View Source
var ErrBufferSize = errors.New("messages: Buffer size too small")

Functions

func GenerateSemaphore

func GenerateSemaphore(longTermOraclePublicKey, semaphore *[32]byte) *[32]byte

Types

type Oracle

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

func NewOracle

func NewOracle(storage *signalstore.Store, engine memprotect.Engine, exportEngine ...memprotect.Engine) *Oracle

NewOracle

func (*Oracle) Generate

func (self *Oracle) Generate(startTime, ratchetTime, timeToExpire int64) error

Generate new oracle keys. Ratchet starts with startTime and refreshes with ratchetTime. timeToExpire determines the lifetime of the shortTermKey.

func (*Oracle) PublicKeys

func (self *Oracle) PublicKeys() (longTerm, shortTerm *[32]byte)

func (*Oracle) ReceiveMsg

func (self *Oracle) ReceiveMsg(d []byte) ([]byte, error)

ReceiveMsg receives and processes a message to the oracle.

func (*Oracle) Restore

func (self *Oracle) Restore(longTermKey, timeLockKey memprotect.Element, timeToExpire int64) error

func (*Oracle) Save

func (self *Oracle) Save() (longTermKey, timeLockKey memprotect.Element)

func (*Oracle) TimelockKeys

func (self *Oracle) TimelockKeys(count int) (*types.RatchetPublicKey, error)

type OracleFuture

type OracleFuture struct {
	Message                 []byte // The encrypted oracle message
	URL                     []byte // The URL to which the message is sent
	ShareThreshold          int32  // Reconstruction threshold
	ResponsePrivateKey      []byte // The private key required to decrypt the response
	ShareMsgKey             []byte // The symmetric key to decrypt the share message
	SingleResponsePrivatKey []byte // Single-use response decryption key.
	// contains filtered or unexported fields
}

OracleFuture contains the information required to send and receive an oraclemessage exchange.

func (*OracleFuture) Receive

func (self *OracleFuture) Receive() ([]byte, error)

type OracleMessage

type OracleMessage struct {
	OracleURL               []byte      // URL where the Oracle listens.
	LongTermOraclePublicKey [32]byte    // The long-term oracle public key.
	TimelockPublicKey       [32]byte    // Timelock key to use, ignore if all zeros.
	TestSemaphores          [3][32]byte // Test these for non-existence
	SetSemaphores           [3][32]byte // Set these
	ValidFrom               int64       // Decrypt only after
	ValidTo                 int64       // Decrypt only before

	ResponsePublicKey [32]byte // The public key to which to encrypt the response
	Share             []byte   // Share  to embed
	ShareThreshold    int32    // Reconstruction threshold
}

OracleMessage contains the data of an oracle message. Exported fields must be set.

func (*OracleMessage) Encrypt

func (self *OracleMessage) Encrypt(containerKey []byte, memEngine memprotect.Engine) (oracleContainer []byte, err error)

Encrypt an OracleMessage. It returns the encrypted container of the oracle message. It takes care of generating the correct semaphores from the given values. The container will be encrypted to containerKey.

type OracleMessageContainer

type OracleMessageContainer struct {
	ValidFrom          int64  // Message is valid from
	ValidTo            int64  // Message is valid to
	ShareThreshold     int32  // Reconstruction threshold
	OracleLongTermKey  []byte // Long Term public key of oracle
	ResponsePublicKey  []byte // Public key of message
	ResponsePrivateKey []byte // The private key required to decrypt the response
	ShareMsgKey        []byte // The symmetric key to decrypt the share message
	OracleURL          []byte // The URL to which the message is sent
	OracleMessage      []byte // The encrypted oracle message
}

OracleMessageContainer contains an oracle message.

func (*OracleMessageContainer) Decrypt

func (self *OracleMessageContainer) Decrypt(key, d []byte) (*OracleMessageContainer, error)

Decrypt an OracleMessageContainer.

func (*OracleMessageContainer) Send

func (self *OracleMessageContainer) Send(key, d []byte, stkf ShortTermKeyFactory, memEngine memprotect.Engine) (*OracleFuture, error)

Send an oracle message from a container.

type SetSemaphoreMsg

type SetSemaphoreMsg struct {
	SetFrom int64
	SetTo   int64
	Name    [32]byte // Must be 32 bytes.
}

SetSemaphoreMsg sets a semaphore between SetFrom and SetTo.

func (*SetSemaphoreMsg) Marshal

func (self *SetSemaphoreMsg) Marshal(out []byte) []byte

Marshal SetSemaphoreMsg. If out ==nil, a new output slice will be allocated.

func (*SetSemaphoreMsg) Unmarshal

func (self *SetSemaphoreMsg) Unmarshal(d []byte) (r *SetSemaphoreMsg, remainder []byte, err error)

Unmarshal SetSemaphoreMsg. If receiver is nil, a new receiver is created. Otherwise the receiver is used.

type ShareMsg

type ShareMsg struct {
	Share     []byte   // Share contents.
	OracleKey [32]byte // Long term oracle key
}

ShareMsg contains a share of the secret.

func (*ShareMsg) Decrypt

func (self *ShareMsg) Decrypt(msg, key []byte, buf []byte) (*ShareMsg, error)

Decrypt an encrypted sharemessage. buf, if not nil, will be used for buffering. To securely decrypt, the receiver should have the Share element set to a byteslice large enough to contain the share data. This will prevent allocation.

func (*ShareMsg) Encrypt

func (self *ShareMsg) Encrypt(key []byte, buf []byte) ([]byte, error)

Encrypt a sharemessage. Key is the symmetric key to encrypt to. buf is used as buffer for marshalling and buf2 for encryption if it is not nil. Otherwise a new slice will be allocated.

func (*ShareMsg) Marshal

func (self *ShareMsg) Marshal(out []byte) []byte

Marshal a ShareMsg into a byte slice. If out ==nil, a new output slice will be allocated.

func (*ShareMsg) Unmarshal

func (self *ShareMsg) Unmarshal(d []byte) (r *ShareMsg, remainder []byte, err error)

Unmarshal ShareMsg. If receiver is nil, a new receiver is created. Otherwise the receiver is used.

type ShortTermKeyFactory

type ShortTermKeyFactory func(url string) (*[32]byte, error)

ShortTermKeyFactory returns the short term key for an oracle url.

Jump to

Keyboard shortcuts

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