libsignalgo.mau.fi/libsignal/keys/chain Index | Files

package chain

import "go.mau.fi/libsignal/keys/chain"

Package chain provides chain keys used in double ratchet sessions.

Index

Types

type Key

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

Key is used for generating message keys. This key "ratchets" every time a message key is generated. Every time the chain key ratchets forward, its index increases by one.

func NewKey

func NewKey(kdf kdf.HKDF, key []byte, index uint32) *Key

NewKey returns a new chain key with the given kdf, key, and index

func NewKeyFromStruct

func NewKeyFromStruct(structure *KeyStructure, kdf kdf.HKDF) *Key

NewKeyFromStruct will return a chain key built from the given structure.

func (*Key) BaseMaterial

func (c *Key) BaseMaterial(seed []byte) []byte

BaseMaterial uses hmac to derive the base material used in the key derivation function for a new key.

func (*Key) Current

func (c *Key) Current() *Key

Current returns the current ChainKey struct.

func (*Key) Index

func (c *Key) Index() uint32

Index returns how many times the ChainKey has been "ratcheted" forward.

func (*Key) Key

func (c *Key) Key() []byte

Key returns the ChainKey's key material.

func (*Key) MessageKeys

func (c *Key) MessageKeys() *message.Keys

MessageKeys returns message keys, which includes the cipherkey, mac, iv, and index.

func (*Key) NextKey

func (c *Key) NextKey() *Key

NextKey uses the key derivation function to generate a new ChainKey.

func (*Key) SetIndex

func (c *Key) SetIndex(index uint32)

SetIndex sets how many times the ChainKey has been "ratcheted" forward.

func (*Key) SetKey

func (c *Key) SetKey(key []byte)

SetKey will set the ChainKey's key material.

type KeyStructure

type KeyStructure struct {
	Key   []byte
	Index uint32
}

KeyStructure is a serializeable structure for chain keys.

func NewStructFromKey

func NewStructFromKey(key *Key) *KeyStructure

NewStructFromKey will return a chain key structure for serialization.

Source Files

ChainKey.go

Version
v0.1.2 (latest)
Published
Feb 12, 2025
Platform
linux/amd64
Imports
4 packages
Last checked
1 week ago

Tools for package owners.