ratchet

package
v0.0.0-...-97e1097 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ratchet defines the keys and parameters required to perform the Double Ratchet algorithm to send and receive encrypted messages.

Index

Constants

View Source
const (
	ChainKeySize = 32

	RootKeySize = 32
)

Variables

This section is empty.

Functions

func DeriveKeys

func DeriveKeys(secretInput []byte) (RootKey, ChainKey, error)

DeriveKeys derives a root key and chain key based on the secret input for the root KDF chain.

Types

type AliceParameters

type AliceParameters struct {
	OurIdentityKeyPair identity.KeyPair
	OurBaseKeyPair     *curve.KeyPair

	TheirIdentityKey   identity.Key
	TheirSignedPreKey  curve.PublicKey
	TheirOneTimePreKey curve.PublicKey
	TheirRatchetKey    curve.PublicKey
}

AliceParameters represents the "Alice" side of the double ratchet algorithm required to perform X3DH.

type BobParameters

type BobParameters struct {
	OurIdentityKeyPair   identity.KeyPair
	OurSignedPreKeyPair  *curve.KeyPair
	OurOneTimePreKeyPair *curve.KeyPair
	OurRatchetKeyPair    *curve.KeyPair

	TheirIdentityKey identity.Key
	TheirBaseKey     curve.PublicKey
}

BobParameters represents the "Bob" side of the double ratchet algorithm required to perform X3DH.

type ChainKey

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

ChainKey represents a sending or receiving chain key used for Symmetric-key ratchet.

func NewChainKey

func NewChainKey(key []byte, index uint32) (ChainKey, error)

NewChainKey derives a chain key from the given key and index.

func (ChainKey) Index

func (c ChainKey) Index() uint32

Index returns the index of chain key in the sending or receiving chain.

func (ChainKey) Key

func (c ChainKey) Key() []byte

Key returns an encoding of the chain key.

func (ChainKey) MessageKeys

func (c ChainKey) MessageKeys() (MessageKeys, error)

MessageKeys performs a Symmetric-key ratchet step to derive new message keys.

func (ChainKey) Next

func (c ChainKey) Next() ChainKey

Next derives the next chain key in the sending or receiving chain.

type MessageKeys

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

MessageKeys defines the keys used to encrypt messages.

func DeriveMessageKeys

func DeriveMessageKeys(inputKeyMaterial []byte, counter uint32) (MessageKeys, error)

DeriveMessageKeys derives message keys from the given input material and counter.

The input material is used as the secret for HKDF.

func NewMessageKeys

func NewMessageKeys(cipherKey, macKey, iv []byte, counter uint32) (MessageKeys, error)

NewMessageKeys derives message keys from the given inputs.

func (MessageKeys) CipherKey

func (m MessageKeys) CipherKey() []byte

CipherKey returns a block cipher key.

func (MessageKeys) Counter

func (m MessageKeys) Counter() uint32

Counter returns the corresponding index in the chain.

func (MessageKeys) IV

func (m MessageKeys) IV() []byte

IV returns an initialization vector used for encryption and decryption.

func (MessageKeys) MACKey

func (m MessageKeys) MACKey() []byte

MACKey returns a key used for a MAC function like HMAC.

type RootKey

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

RootKey is a key used for the root chain in the Double Ratchet algorithm.

func NewRootKey

func NewRootKey(key []byte) (RootKey, error)

NewRootKey derives a root key from the given bytes.

func (RootKey) Bytes

func (r RootKey) Bytes() []byte

Bytes returns an encoding of the root key.

func (RootKey) CreateChain

func (r RootKey) CreateChain(ourRatchetKey curve.PrivateKey, theirRatchetKey curve.PublicKey) (RootKey, ChainKey, error)

CreateChain performs a single Diffie-Hellman ratchet step to create a new root key and chain key.

Jump to

Keyboard shortcuts

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