ratchet

package
v0.0.0-...-07f4606 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ratchet 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.

func (*Ratchet) Encrypt

func (r *Ratchet) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts the message in a message.Message with MAC.

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) PickleLibOlm

func (r Ratchet) PickleLibOlm(encoder *libolmpickle.Encoder)

PickleLibOlm pickles the ratchet into the encoder.

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(decoder *libolmpickle.Decoder, includesChainIndex bool) error

UnpickleLibOlm unpickles the unencryted value and populates the Ratchet accordingly.

Jump to

Keyboard shortcuts

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