group

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 19 Imported by: 7

Documentation

Index

Constants

View Source
const (
	KeyLen         = 32 // Group key
	KeyPreimageLen = 32 // Key preimage
)

Length of data, in bytes.

View Source
const (
	// MinMembers is the minimum number of members allowed in a Membership list.
	MinMembers = 2

	// MaxMembers is the minimum number of members allowed in a Membership list.
	MaxMembers = 11

	// MinParticipants is the minimum number of participants allowed when
	// creating a new Membership list.
	MinParticipants = MinMembers - 1

	// MaxParticipants is the maximum number of participants allowed when
	// creating a new Membership list.
	MaxParticipants = MaxMembers - 1
)
View Source
const CryptKeyLen = 32

CryptKeyLen is the length, in bytes, of the KDF key.

View Source
const IdPreimageLen = 32

IdPreimageLen is the length, in bytes, of the ID preimage.

View Source
const MessageIdLen = 32

MessageIdLen is the length, in bytes, of the message ID.

View Source
const SaltLen = 32

SaltLen is the length, in bytes, of the salt used to generate the key fingerprint.

Variables

This section is empty.

Functions

func CheckKeyFingerprint

func CheckKeyFingerprint(fingerprint format.Fingerprint, groupKey Key,
	salt [SaltLen]byte, recipientID *id.ID) bool

CheckKeyFingerprint verifies that the given fingerprint matches the provided group data.

func CheckMAC

func CheckMAC(mac []byte, key CryptKey, encryptedInternalMsg []byte,
	recipientDhKey *cyclic.Int) bool

CheckMAC verifies that the given MAC matches the provided data.

func ComputeEpoch

func ComputeEpoch(t time.Time) uint32

ComputeEpoch generates an epoch for the given time.

func Decrypt

func Decrypt(key CryptKey, keyFingerprint format.Fingerprint, encryptedInternalMsg []byte) []byte

Decrypt decrypts the encrypted internal message with XChaCha20.

func Encrypt

func Encrypt(key CryptKey, keyFingerprint format.Fingerprint, internalMsg []byte) []byte

Encrypt encrypts the internal message with XChaCha20.

func NewID

func NewID(preimage IdPreimage, membership Membership) *id.ID

NewID generates a new id.ID of type id.Group. The ID is a hash of the group Membership digest, a 256-bit preimage, and a constant.

func NewKeyFingerprint

func NewKeyFingerprint(groupKey Key, salt [32]byte, recipientID *id.ID) format.Fingerprint

NewKeyFingerprint generates a key fingerprint for the member of a group from the group key, 256-bit salt, and the member's recipient ID.

func NewMAC

func NewMAC(key CryptKey, encryptedInternalMsg []byte, recipientDhKey *cyclic.Int) []byte

NewMAC generates a MAC for the encrypted internal message and the recipient's Diffie–Hellman key.

Types

type CryptKey

type CryptKey [CryptKeyLen]byte

CryptKey is the 256-bit key used for encryption/decryption.

func NewKdfKey

func NewKdfKey(groupKey Key, epoch uint32, salt [SaltLen]byte) (CryptKey, error)

NewKdfKey produces a new 256-bit using HKDF.

func (CryptKey) Bytes

func (ck CryptKey) Bytes() []byte

Bytes returns the CryptKey as a byte slice.

func (CryptKey) String

func (ck CryptKey) String() string

String returns the CryptKey as a base 64 encoded string. This functions satisfies the fmt.Stringer interface.

type IdPreimage

type IdPreimage [IdPreimageLen]byte

IdPreimage is the 256-bit group ID preimage generated from a CRNG.

func NewIdPreimage

func NewIdPreimage(rng io.Reader) (IdPreimage, error)

NewIdPreimage generates a 256-bit preimage from a CRNG that is used for group ID generation. An error is returned if the RNG does not return the correct number of bytes.

func (IdPreimage) Bytes

func (idp IdPreimage) Bytes() []byte

Bytes returns the IdPreimage as a byte slice.

func (IdPreimage) String

func (idp IdPreimage) String() string

String returns the IdPreimage as a base 64 encoded string. This functions satisfies the fmt.Stringer interface.

type Key

type Key [KeyLen]byte

Key is the 256-bit group key.

func NewKey

func NewKey(preimage KeyPreimage, membership Membership) Key

NewKey generates a new key for a group. The key is a hash of the group Membership digest, a 256-bit preimage, and a constant. An error is returned if the preimage is not of the correct size.

func (Key) Bytes

func (k Key) Bytes() []byte

Bytes returns the Key as a byte slice.

func (Key) String

func (k Key) String() string

String returns the Key as a base 64 encoded string. This functions satisfies the fmt.Stringer interface.

type KeyPreimage

type KeyPreimage [KeyPreimageLen]byte

KeyPreimage is the 256-bit group key preimage generated from a CRNG.

func NewKeyPreimage

func NewKeyPreimage(rng io.Reader) (KeyPreimage, error)

NewKeyPreimage generates a 256-bit preimage from a CRNG that is used for group key generation. An error is returned if the RNG does not return the correct number of bytes.

func (KeyPreimage) Bytes

func (kp KeyPreimage) Bytes() []byte

Bytes returns the KeyPreimage as a byte slice.

func (KeyPreimage) String

func (kp KeyPreimage) String() string

String returns the KeyPreimage as a base 64 encoded string. This functions satisfies the fmt.Stringer interface.

type Member

type Member struct {
	ID    *id.ID      // Group member's user ID
	DhKey *cyclic.Int // Group member's public Diffie–Hellman key
}

Member describes each user in a group membership list.

func DeserializeMember

func DeserializeMember(b []byte) (Member, error)

DeserializeMember deserializes the bytes into a Member.

func (Member) DeepCopy

func (m Member) DeepCopy() Member

DeepCopy returns a deep copy of the Member.

func (Member) Equal

func (m Member) Equal(x Member) bool

Equal returns true if the two Members have the same ID and Diffie–Hellman key.

func (Member) GoString

func (m Member) GoString() string

GoString returns the member's ID and full Diffie–Hellman key as text. This functions satisfies the fmt.GoStringer interface.

func (Member) Serialize

func (m Member) Serialize() []byte

Serialize generates a byte representation of the Member for sending over the wire.

func (Member) String

func (m Member) String() string

String returns the member's ID and truncated Diffie–Hellman key as text. This functions satisfies the fmt.Stringer interface.

type Membership

type Membership []Member

Membership is a list of members in a group. The group leader is always the first in the list followed by all group members sorted by their ID smallest to largest.

func DeserializeMembership

func DeserializeMembership(b []byte) (Membership, error)

DeserializeMembership deserializes the bytes into a Membership.

func NewMembership

func NewMembership(leader contact.Contact, participants ...contact.Contact) (Membership, error)

NewMembership returns a new Membership list with the provided leader and participants.

func (Membership) DeepCopy

func (gm Membership) DeepCopy() Membership

DeepCopy returns a deep copy of the Membership.

func (Membership) Digest

func (gm Membership) Digest() []byte

Digest generates a hash of all the reception IDs and Diffie–Hellman keys of each member in the order presented in the Membership list.

func (Membership) Serialize

func (gm Membership) Serialize() []byte

Serialize generates a byte representation of the Membership for sending over the wire.

func (Membership) String

func (gm Membership) String() string

String returns a list of members as text. This functions satisfies the fmt.Stringer interface.

type MessageID

type MessageID [MessageIdLen]byte

MessageID is the 256-bit unique ID that identifies a message.

func NewMessageID

func NewMessageID(groupID *id.ID, internalFormat []byte) MessageID

NewMessageID generates an ID for a group message by hashing the group ID and the internal message format.

func (MessageID) Bytes

func (mid MessageID) Bytes() []byte

Bytes returns the MessageID as a byte slice.

func (MessageID) String

func (mid MessageID) String() string

String returns the MessageID as a base 64 encoded string. This functions satisfies the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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