Documentation ¶
Overview ¶
megolm provides the ratchet used by the megolm protocol
Index ¶
- Constants
- Variables
- type Ratchet
- func (m *Ratchet) Advance()
- func (m *Ratchet) AdvanceTo(target uint32)
- func (r Ratchet) Decrypt(ciphertext []byte, signingkey *crypto.Ed25519PublicKey, ...) ([]byte, error)
- func (r *Ratchet) Encrypt(plaintext []byte, key *crypto.Ed25519KeyPair) ([]byte, error)
- func (r Ratchet) PickleAsJSON(key []byte) ([]byte, error)
- func (r Ratchet) PickleLen() int
- func (r Ratchet) PickleLibOlm(target []byte) (int, error)
- func (r Ratchet) SessionExportMessage(key crypto.Ed25519PublicKey) ([]byte, error)
- func (r Ratchet) SessionSharingMessage(key crypto.Ed25519KeyPair) ([]byte, error)
- func (r *Ratchet) UnpickleAsJSON(pickled, key []byte) error
- func (r *Ratchet) UnpickleLibOlm(unpickled []byte) (int, error)
Constants ¶
const ( RatchetParts = 4 // number of ratchet parts RatchetPartLength = 256 / 8 // length of each ratchet part in bytes )
Variables ¶
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 ¶
NewWithRandom creates a new ratchet with counter set to counter an the data filled with random values.
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 ¶
Encrypt encrypts the message in a message.GroupMessage with MAC and signature. The output is base64 encoded.
func (Ratchet) PickleAsJSON ¶
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 ¶
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 ¶
UnpickleAsJSON updates a ratchet by a base64 encrypted string using the supplied key. The unencrypted representation has to be in JSON format.