ratchet

package
v0.0.0-...-c45e87f Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package ratchet implements a ratcheting algorithm to generate keypairs for curve25519, using SHA256.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidDuration signifies that a given duration was invalid, that is smaller than 1.
	ErrInvalidDuration = errors.New("ratchet: invalid duration")
	// ErrNoService signifies that attempting to send to a close service will fail.
	ErrNoService = errors.New("ratchet: ratchet fountain service stopped")
	// ErrRatchetNotFound signifies that a secret was requested that refers to a ratchet state that is not current.
	ErrRatchetNotFound = errors.New("ratchet: ratchet not found")
)

Functions

This section is empty.

Types

type Fountain

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

Fountain is a ratchet with timing information, that is: When did a ratchet start, and how often does it update.

func NewFountain

func NewFountain(duration int64, rand io.Reader) (*Fountain, error)

NewFountain returns a new Fountain for ratchets, it creates a new underlying ratchet, sets the start date to now, and sets the duration. Returns nil on error. Service MUST be started.

func (*Fountain) GetSecret

func (f *Fountain) GetSecret(expectedPubKey, peerPubKey *[32]byte) (*[32]byte, error)

GetSecret from fountain.

func (*Fountain) Marshall

func (f *Fountain) Marshall() []byte

Marshall a fountain into a byte slice. It does NOT stop the service.

func (*Fountain) StartService

func (f *Fountain) StartService()

StartService starts the ratcheting services.

func (*Fountain) Stop

func (f *Fountain) Stop() *State

Stop the fountain.

func (*Fountain) Unmarshall

func (f *Fountain) Unmarshall(d []byte) *Fountain

Unmarshall a fountain from byte slice, returns nil on error. Service MUST be started.

type PreGenerator

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

PreGenerator is a fountain pregenerator.

func NewPregeneratorFromFountain

func NewPregeneratorFromFountain(f *Fountain, pregenInterval int64) *PreGenerator

NewPregeneratorFromFountain creates a new PreGenerator from a fountain. Use only when creating a new fountain. Use UnmarshallGenerator when unmarshalling.

func (*PreGenerator) Generate

func (pg *PreGenerator) Generate() *types.RatchetList

Generate new ratchet states.

func (*PreGenerator) Marshall

func (pg *PreGenerator) Marshall() []byte

Marshall the PreGenerator.

func (*PreGenerator) Unmarshall

func (pg *PreGenerator) Unmarshall(f *Fountain, d []byte) *PreGenerator

Unmarshall a pregenerator from bytes and the fountain. Return nil on error.

type Ring

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

Ring contains three ratchets, one current, one past, one future.

func NewRatchetRing

func NewRatchetRing(ratchet *State, currentStep uint64) *Ring

NewRatchetRing returns a new, possibly filled, RatchetRing. pastStep is the expected counter value for the past value. Operates on a copy of ratchet.

func (*Ring) Current

func (rr *Ring) Current() *State

Current returns a copy of the current ratchet state for marshalling. The past state will be lost in marshalling.

func (*Ring) CurrentStep

func (rr *Ring) CurrentStep() uint64

CurrentStep returns the counter of the current ratchet.

func (*Ring) Find

func (rr *Ring) Find(expect *[32]byte) *State

Find the ratchet state that matches the expected public key and return a copy, or nil if not found.

func (*Ring) Step

func (rr *Ring) Step()

Step executes one step for the ratchets.

func (*Ring) StepTo

func (rr *Ring) StepTo(currentStep uint64)

StepTo steps to currentStep.

type SecretFunc

type SecretFunc func(expectedPubKey, peerPubKey *[32]byte) (*[32]byte, error)

SecretFunc is a function that returns a secret for a ratchet key.

type State

type State struct {
	PublicKey [32]byte // Curve25519 public key.
	// contains filtered or unexported fields
}

State contains the static and dynamic elements of the ratchet.

func NewRatchet

func NewRatchet(rand io.Reader) (*State, error)

NewRatchet creates a new ratchet state from a random source.

func (*State) Copy

func (s *State) Copy() *State

Copy a ratchet state to not share memory.

func (*State) Counter

func (s *State) Counter() uint64

Counter returns the current counter value.

func (*State) Marshall

func (s *State) Marshall() []byte

Marshall ratchet state to bytes.

func (*State) SharedSecret

func (s *State) SharedSecret(peerPubKey *[32]byte) *[32]byte

SharedSecret creates a shared secret from the RatchetKey and a curve25519 public key (in) by multiplying RatchetKey and with in, and drawing the sha256 of the result.

func (*State) Step

func (s *State) Step() *State

Step continues the ratchet by one more step.

func (*State) Unmarshall

func (s *State) Unmarshall(d []byte) *State

Unmarshall a ratchet state, returns nil on error.

Jump to

Keyboard shortcuts

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