doubleratchet: Index | Files

package ratchet

import ""

Package ratchet implements the axolotl ratchet, by Trevor Perrin. See


Package Files

constants.go helpers.go ratchet.go


const (

    // MaxMissingMessages is the maximum number of missing messages that
    // we'll keep track of.
    MaxMissingMessages = 8

    // RatchetKeyMaxLifetime is the maximum lifetime of the ratchet
    RatchetKeyMaxLifetime = time.Hour * 672

    // DoubleRatchetOverhead is the number of bytes the ratchet adds in ciphertext overhead.
    DoubleRatchetOverhead = 120


var (
    ErrDuplicateOrDelayed                     = errors.New("Ratchet: duplicate message or message delayed longer than tolerance")
    ErrHandshakeAlreadyComplete               = errors.New("Ratchet: handshake already complete")
    ErrCannotDecrypt                          = errors.New("Ratchet: cannot decrypt")
    ErrIncorrectHeaderSize                    = errors.New("Ratchet: incorrect header size")
    ErrSerialisedKeyLength                    = errors.New("Ratchet: bad serialised key length")
    ErrNextEncryptedMessageWithoutRatchetFlag = errors.New("Ratchet: received message encrypted to next header key without ratchet flag set")
    ErrOldFormKeyExchange                     = errors.New("Ratchet: peer using old-form key exchange")
    ErrCorruptMessage                         = errors.New("Ratchet: corrupt message")
    ErrMessageExceedsReorderingLimit          = errors.New("Ratchet: message exceeds reordering limit")
    ErrEchoedDHValues                         = errors.New("Ratchet: peer echoed our own DH values back")
    ErrInvalidSignatureLength                 = errors.New("Ratchet: invalid signature length")
    ErrRatchetHeaderTooSmall                  = errors.New("Ratchet: header too small to be valid")
    ErrInvalidKeyExchange                     = errors.New("Ratchet: peer's key exchange is invalid")
    ErrFailedToInitializeRatchet              = errors.New("Ratchet: failed to initialize")
    ErrInvalidPubkey                          = errors.New("Ratchet: invalid public key")
    ErrInvalidPublicIdentityKey               = errors.New("Ratchet: invalid public identity key")
    ErrInvalidSignature                       = errors.New("Ratchet: invalid signature")
    ErrKeyExchangeKeysNotIsomorphicallyEqual  = errors.New("Ratchet: key exchange and identity public keys must be isomorphically equal")

func DestroyRatchet Uses

func DestroyRatchet(r *Ratchet)

DestroyRatchet destroys the ratchet

type KeyExchange Uses

type KeyExchange struct {
    PublicKey      []byte
    IdentityPublic []byte
    Dh             []byte
    Dh1            []byte

KeyExchange is structure containing the public keys

type MessageKey Uses

type MessageKey struct {
    Num          uint32
    Key          []byte
    CreationTime int64

MessageKey is structure containing the data associated with the message key

type Ratchet Uses

type Ratchet struct {
    TheirSigningPublic  *memguard.LockedBuffer // 32 bytes long
    TheirIdentityPublic *memguard.LockedBuffer // 32 bytes long

    MySigningPublic  *memguard.LockedBuffer // 32 bytes long
    MySigningPrivate *memguard.LockedBuffer // 64 bytes long

    MyIdentityPrivate *memguard.LockedBuffer // 32 bytes long
    MyIdentityPublic  *memguard.LockedBuffer // 32 bytes long

    // Now is an optional function that will be used to get the current
    // time. If nil, time.Now is used.
    Now func() time.Time
    // contains filtered or unexported fields

Ratchet stucture contains the per-contact, crypto state.

func InitRatchet Uses

func InitRatchet(rand io.Reader) (*Ratchet, error)

InitRatchet initializes a ratchet struct

func (*Ratchet) CompleteKeyExchange Uses

func (r *Ratchet) CompleteKeyExchange(kx *KeyExchange) error

CompleteKeyExchange takes a KeyExchange message from the other party and establishes the ratchet.

func (*Ratchet) CreateKeyExchange Uses

func (r *Ratchet) CreateKeyExchange() (*SignedKeyExchange, error)

CreateKeyExchange created and add the appropiate fields for the KeyExchange

func (*Ratchet) Decrypt Uses

func (r *Ratchet) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt decrypts a message

func (*Ratchet) Encrypt Uses

func (r *Ratchet) Encrypt(out, msg []byte) []byte

Encrypt acts like append() but appends an encrypted version of msg to out.

func (*Ratchet) FillKeyExchange Uses

func (r *Ratchet) FillKeyExchange(kx *KeyExchange) error

FillKeyExchange sets elements of kx with key exchange information from the ratchet.

func (*Ratchet) Marshal Uses

func (r *Ratchet) Marshal(now time.Time, lifetime time.Duration) *State

Marshal transforms the object into a stream

func (*Ratchet) MarshalBinary Uses

func (r *Ratchet) MarshalBinary() (data []byte, err error)

MarshalBinary transforms the object into a stream

func (*Ratchet) ProcessKeyExchange Uses

func (r *Ratchet) ProcessKeyExchange(signedKeyExchange *SignedKeyExchange) error

ProcessKeyExchange processes the data of a KeyExchange

func (*Ratchet) Unmarshal Uses

func (r *Ratchet) Unmarshal(s *State) error

Unmarshal transforms the stream into the object

func (*Ratchet) UnmarshalBinary Uses

func (r *Ratchet) UnmarshalBinary(data []byte) error

UnmarshalBinary transforms the stream into the object

type SavedKeys Uses

type SavedKeys struct {
    HeaderKey   []byte
    MessageKeys []*MessageKey

SavedKeys is structure containing the saved keys from delayed messages

func (*SavedKeys) MarshalBinary Uses

func (s *SavedKeys) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryUnmarshaler interface

func (*SavedKeys) UnmarshalBinary Uses

func (s *SavedKeys) UnmarshalBinary(data []byte) error

UnmarshalBinary instantiates memguard.LockedBuffer instances for each deserialized key

type SignedKeyExchange Uses

type SignedKeyExchange struct {
    Signed    []byte
    Signature []byte

SignedKeyExchange is structure containing the signature data

type State Uses

type State struct {
    TheirSigningPublic  []byte
    TheirIdentityPublic []byte
    MySigningPublic     []byte
    MySigningPrivate    []byte
    MyIdentityPrivate   []byte
    MyIdentityPublic    []byte
    SavedKeys           []*SavedKeys
    RootKey             []byte
    SendHeaderKey       []byte
    RecvHeaderKey       []byte
    NextSendHeaderKey   []byte
    NextRecvHeaderKey   []byte
    SendChainKey        []byte
    RecvChainKey        []byte
    SendRatchetPrivate  []byte
    RecvRatchetPublic   []byte
    SendCount           uint32
    RecvCount           uint32
    PrevSendCount       uint32
    Private0            []byte
    Private1            []byte
    Ratchet             bool

State constains all the data associated with a ratchet

Package ratchet imports 14 packages (graph) and is imported by 2 packages. Updated 2020-11-22. Refresh now. Tools for package owners.