mls

package module
v0.0.0-...-08bd20b Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 16 Imported by: 2

README

go-mls

Go Reference

A Go library for MLS.

This library is a work-in-progress and has not yet been audited for security issues.

Contributing

Send patches on GitHub. Come and discuss in #emersion on Libera Chat.

License

MIT

Documentation

Overview

Package mls implements the Messaging Layer Security protocol.

MLS is specified in RFC 9420.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CipherSuite

type CipherSuite uint16

A CipherSuite defines the cryptographic primitives to be used in group key computations: HPKE parameters (KEM, KDF and AEAD), hash, MAC and signature.

MLS cipher suites are listed at: https://www.iana.org/assignments/mls/mls.xhtml#mls-ciphersuites

const (
	CipherSuiteMLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519        CipherSuite = 0x0001
	CipherSuiteMLS_128_DHKEMP256_AES128GCM_SHA256_P256             CipherSuite = 0x0002
	CipherSuiteMLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 CipherSuite = 0x0003
	CipherSuiteMLS_256_DHKEMX448_AES256GCM_SHA512_Ed448            CipherSuite = 0x0004
	CipherSuiteMLS_256_DHKEMP521_AES256GCM_SHA512_P521             CipherSuite = 0x0005
	CipherSuiteMLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448     CipherSuite = 0x0006
	CipherSuiteMLS_256_DHKEMP384_AES256GCM_SHA384_P384             CipherSuite = 0x0007
)

func (CipherSuite) String

func (cs CipherSuite) String() string

String returns the name of the cipher suite.

func (CipherSuite) Supported

func (cs CipherSuite) Supported() bool

Supported checks whether a cipher suite is supported by the library.

type Credential

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

A Credential holds information about a group member's identity.

func NewBasicCredential

func NewBasicCredential(identity []byte) *Credential

NewBasicCredential creates a new basic credential. identity uses an application-specific format.

type Group

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

A Group is a high-level API for an MLS group.

Example
cs := CipherSuiteMLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519

aliceCredential := NewBasicCredential([]byte("앨리스"))
aliceKeyPairPkg, err := GenerateKeyPairPackage(cs, aliceCredential)
if err != nil {
	log.Fatalf("GenerateKeyPairPackage() = %v", err)
}

bobCredential := NewBasicCredential([]byte("밥"))
bobKeyPairPkg, err := GenerateKeyPairPackage(cs, bobCredential)
if err != nil {
	log.Fatalf("GenerateKeyPairPackage() = %v", err)
}

groupID := GroupID("비밀")
aliceGroup, err := CreateGroup(groupID, aliceKeyPairPkg)
if err != nil {
	log.Fatalf("CreateGroup() = %v", err)
}

bobWelcome, addMemberMsg, err := aliceGroup.CreateWelcome([]KeyPackage{bobKeyPairPkg.Public})
if err != nil {
	log.Fatalf("CreateWelcome() = %v", err)
}

if _, err := aliceGroup.UnmarshalAndProcessMessage(addMemberMsg); err != nil {
	log.Fatalf("UnmarshalAndProcessMessage() = %v", err)
}

bobGroup, err := GroupFromWelcome(bobWelcome, bobKeyPairPkg)
if err != nil {
	log.Fatalf("GroupFromWelcome() = %v", err)
}

data := []byte("안녕하세요")
appMsg, err := aliceGroup.CreateApplicationMessage(data)
if err != nil {
	log.Fatalf("CreateApplicationMessage() = %v", err)
}

plaintext, err := bobGroup.UnmarshalAndProcessMessage(appMsg)
if err != nil {
	log.Fatalf("UnmarshalAndProcessMessage() = %v", err)
}

fmt.Println(string(plaintext))
Output:

안녕하세요

func CreateGroup

func CreateGroup(groupID GroupID, keyPairPkg *KeyPairPackage) (*Group, error)

CreateGroup creates a new group with a single member.

func GroupFromWelcome

func GroupFromWelcome(welcome *Welcome, keyPairPkg *KeyPairPackage) (*Group, error)

GroupFromWelcome creates a new group from a welcome message.

func (*Group) CreateApplicationMessage

func (group *Group) CreateApplicationMessage(data []byte) ([]byte, error)

CreateApplicationMessage creates a new encrypted application message for the group. The message contains an arbitrary application-specific payload.

func (*Group) CreateWelcome

func (group *Group) CreateWelcome(keyPkgs []KeyPackage) (*Welcome, []byte, error)

CreateWelcome creates a new welcome message, inviting new members to the group.

The welcome message should be sent to the new members. Alongside the welcome message, a raw MLS message is returned and must be consumed by all existing members of the group to add the new members.

func (*Group) UnmarshalAndProcessMessage

func (group *Group) UnmarshalAndProcessMessage(raw []byte) ([]byte, error)

UnmarshalAndProcessMessage decodes a raw MLS message intended for the group and processes it.

If the MLS message contains encrypted application data, the decrypted data is returned.

type GroupID

type GroupID []byte

GroupID is an application-specific group identifier.

func (GroupID) Equal

func (ref GroupID) Equal(other GroupID) bool

Equal checks whether two key package references are equal.

type KeyPackage

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

A KeyPackage provides some public information about a user, such as a supported protocol version and cipher suite, public keys, and credentials.

Key packages should not be used more than once.

func UnmarshalKeyPackage

func UnmarshalKeyPackage(raw []byte) (*KeyPackage, error)

UnmarshalKeyPackage reads a key package encoded as an MLS message.

func (*KeyPackage) Bytes

func (pkg *KeyPackage) Bytes() []byte

Bytes encodes the key package.

func (*KeyPackage) GenerateRef

func (pkg *KeyPackage) GenerateRef() (KeyPackageRef, error)

GenerateRef generates this key package's reference.

type KeyPackageRef

type KeyPackageRef []byte

KeyPackageRef is a hash uniquely identifying a key package.

func (KeyPackageRef) Equal

func (ref KeyPackageRef) Equal(other KeyPackageRef) bool

Equal checks whether two key package references are equal.

type KeyPairPackage

type KeyPairPackage struct {
	Public  KeyPackage
	Private PrivateKeyPackage
}

KeyPairPackage holds both public and private information about a user.

func GenerateKeyPairPackage

func GenerateKeyPairPackage(cs CipherSuite, credential *Credential) (*KeyPairPackage, error)

GenerateKeyPairPackage generates a new key pair package.

type PrivateKeyPackage

type PrivateKeyPackage struct {
	InitKey       []byte
	EncryptionKey []byte
	SignatureKey  []byte
}

PrivateKeyPackage holds private information about a user.

type Welcome

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

A Welcome message includes secret keying information necessary to join a group.

func UnmarshalWelcome

func UnmarshalWelcome(raw []byte) (*Welcome, error)

UnmarshalWelcome reads a welcome message.

func (*Welcome) Bytes

func (w *Welcome) Bytes() []byte

Bytes encodes the welcome message.

func (*Welcome) NewMembers

func (w *Welcome) NewMembers() []KeyPackageRef

NewMembers returns the list of key package references this welcome message contains secret keying information for.

Jump to

Keyboard shortcuts

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