megolm

package
v0.19.0-mod-2 Latest Latest
Warning

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

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

Documentation

Overview

megolm provides the ratchet used by the megolm protocol

Index

Constants

View Source
const (
	RatchetParts      = 4       // number of ratchet parts
	RatchetPartLength = 256 / 8 // length of each ratchet part in bytes
)

Variables

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

Functions

This section is empty.

Types

type Ratchet

type Ratchet struct {
	Data    [RatchetParts * RatchetPartLength]byte `json:"data"`
	Counter uint32                                 `json:"counter"`
}

Ratchet represents the megolm ratchet as described in

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

func New

func New(counter uint32, data [RatchetParts * RatchetPartLength]byte) (*Ratchet, error)

New creates a new ratchet with counter set to counter and the ratchet data set to data.

func NewWithRandom

func NewWithRandom(counter uint32) (*Ratchet, error)

NewWithRandom creates a new ratchet with counter set to counter an the data filled with random values.

func (*Ratchet) Advance

func (m *Ratchet) Advance()

Advance advances the ratchet one step.

func (*Ratchet) AdvanceTo

func (m *Ratchet) AdvanceTo(target uint32)

AdvanceTo advances the ratchet so that the ratchet counter = target

func (Ratchet) Decrypt

func (r Ratchet) Decrypt(ciphertext []byte, signingkey *crypto.Ed25519PublicKey, msg *message.GroupMessage) ([]byte, error)

Decrypt decrypts the ciphertext and verifies the MAC but not the signature.

func (*Ratchet) Encrypt

func (r *Ratchet) Encrypt(plaintext []byte, key *crypto.Ed25519KeyPair) ([]byte, error)

Encrypt encrypts the message in a message.GroupMessage with MAC and signature. The output is base64 encoded.

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 number of bytes the pickled ratchet will 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) SessionExportMessage

func (r Ratchet) SessionExportMessage(key crypto.Ed25519PublicKey) ([]byte, error)

SessionExportMessage creates a message in the session export format.

func (Ratchet) SessionSharingMessage

func (r Ratchet) SessionSharingMessage(key crypto.Ed25519KeyPair) ([]byte, error)

SessionSharingMessage creates a message in the session sharing format.

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(unpickled []byte) (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