olm

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

olm provides the ratchet used by the olm protocol

Index

Constants

This section is empty.

Variables

View Source
var KdfInfo = struct {
	Root    []byte
	Ratchet []byte
}{
	Root:    []byte("OLM_ROOT"),
	Ratchet: []byte("OLM_RATCHET"),
}

KdfInfo has the infos used for the kdf

View Source
var RatchetCipher = cipher.NewAESSHA256([]byte("OLM_KEYS"))

Functions

This section is empty.

Types

type Ratchet

type Ratchet struct {
	// The root key is used to generate chain keys from the ephemeral keys.
	// A new root_key is derived each time a new chain is started.
	RootKey crypto.Curve25519PublicKey `json:"root_key"`

	// The sender chain is used to send messages. Each time a new ephemeral
	// key is received from the remote server we generate a new sender chain
	// with a new ephemeral key when we next send a message.
	SenderChains senderChain `json:"sender_chain"`

	// The receiver chain is used to decrypt received messages. We store the
	// last few chains so we can decrypt any out of order messages we haven't
	// received yet.
	// New chains are prepended for easier access.
	ReceiverChains []receiverChain `json:"receiver_chains"`

	// Storing the keys of missed messages for future use.
	// The order of the elements is not important.
	SkippedMessageKeys []skippedMessageKey `json:"skipped_message_keys"`
}

Ratchet represents the olm ratchet as described in

https://gitlab.matrix.org/matrix-org/olm/-/blob/master/docs/olm.md

func New

func New() *Ratchet

New creates a new ratchet, setting the kdfInfos and cipher.

func (*Ratchet) Decrypt

func (r *Ratchet) Decrypt(input []byte) ([]byte, error)

Decrypt decrypts the ciphertext and verifies the MAC. If reader is nil, crypto/rand is used for key generations.

func (*Ratchet) Encrypt

func (r *Ratchet) Encrypt(plaintext []byte, reader io.Reader) ([]byte, error)

Encrypt encrypts the message in a message.Message with MAC. If reader is nil, crypto/rand is used for key generations.

func (*Ratchet) InitializeAsAlice

func (r *Ratchet) InitializeAsAlice(sharedSecret []byte, ourRatchetKey crypto.Curve25519KeyPair) error

InitializeAsAlice initializes this ratchet from a sending point of view (only first message).

func (*Ratchet) InitializeAsBob

func (r *Ratchet) InitializeAsBob(sharedSecret []byte, theirRatchetKey crypto.Curve25519PublicKey) error

InitializeAsBob initializes this ratchet from a receiving point of view (only first message).

func (Ratchet) PickleAsJSON

func (r Ratchet) PickleAsJSON(key []byte) ([]byte, error)

PickleAsJSON returns a ratchet as a base64 string encrypted using the supplied key. The unencrypted representation of the Account is in JSON format.

func (Ratchet) PickleLen

func (r Ratchet) PickleLen() int

PickleLen returns the actual number of bytes the pickled ratchet will have.

func (Ratchet) PickleLenMin

func (r Ratchet) PickleLenMin() int

PickleLen returns the minimum number of bytes the pickled ratchet must have.

func (Ratchet) PickleLibOlm

func (r Ratchet) PickleLibOlm(target []byte) (int, error)

PickleLibOlm encodes the ratchet into target. target has to have a size of at least PickleLen() and is written to from index 0. It returns the number of bytes written.

func (*Ratchet) UnpickleAsJSON

func (r *Ratchet) UnpickleAsJSON(pickled, key []byte) error

UnpickleAsJSON updates a ratchet by a base64 encrypted string using the supplied key. The unencrypted representation has to be in JSON format.

func (*Ratchet) UnpickleLibOlm

func (r *Ratchet) UnpickleLibOlm(value []byte, includesChainIndex bool) (int, error)

UnpickleLibOlm decodes the unencryted value and populates the Ratchet accordingly. It returns the number of bytes read.

Jump to

Keyboard shortcuts

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